s/couch_config/config

Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/7c0ed516
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/7c0ed516
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/7c0ed516

Branch: refs/heads/import
Commit: 7c0ed5166c0b2116e28898e57dfdae75aa5e0143
Parents: 52efee8
Author: Robert Newson <[email protected]>
Authored: Tue Mar 5 16:55:20 2013 -0600
Committer: Robert Newson <[email protected]>
Committed: Tue Mar 5 20:18:20 2013 -0600

----------------------------------------------------------------------
 src/chttpd.app.src     |  2 +-
 src/chttpd.erl         | 57 +++++++++++++++++++++++----------------------
 src/chttpd_db.erl      |  6 ++---
 src/chttpd_misc.erl    | 20 ++++++++--------
 src/chttpd_rewrite.erl |  2 +-
 5 files changed, 44 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7c0ed516/src/chttpd.app.src
----------------------------------------------------------------------
diff --git a/src/chttpd.app.src b/src/chttpd.app.src
index 893939c..b2cfb99 100644
--- a/src/chttpd.app.src
+++ b/src/chttpd.app.src
@@ -2,6 +2,6 @@
     {description, "HTTP interface for CouchDB cluster"},
     {vsn, git},
     {registered, [chttpd_sup, chttpd]},
-    {applications, [kernel, stdlib, twig, couch, fabric]},
+    {applications, [kernel, stdlib, twig, config, couch, fabric]},
     {mod, {chttpd_app,[]}}
 ]}.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7c0ed516/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index c9d07ab..267a992 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -12,9 +12,10 @@
 
 -module(chttpd).
 -include_lib("couch/include/couch_db.hrl").
+-behaviour(config_listener).
 
 -export([start_link/0, start_link/1, start_link/2,
-    stop/0, handle_request/1, config_change/2,
+    stop/0, handle_request/1, handle_config_change/5,
     primary_header_value/2, header_value/2, header_value/3, qs_value/2,
     qs_value/3, qs/1, qs_json_value/3, path/1, absolute_uri/2, body_length/1,
     verify_is_server_admin/1, unquote/1, quote/1, recv/2, recv_chunked/4,
@@ -45,29 +46,29 @@
 start_link() ->
     start_link(http).
 start_link(http) ->
-    Port = couch_config:get("chttpd", "port", "5984"),
+    Port = config:get("chttpd", "port", "5984"),
     start_link(?MODULE, [{port, Port}]);
 
 start_link(https) ->
-    Port = couch_config:get("chttps", "port", "6984"),
-    CertFile = couch_config:get("chttps", "cert_file", nil),
-    KeyFile = couch_config:get("chttps", "key_file", nil),
+    Port = config:get("chttps", "port", "6984"),
+    CertFile = config:get("chttps", "cert_file", nil),
+    KeyFile = config:get("chttps", "key_file", nil),
     Options = case CertFile /= nil andalso KeyFile /= nil of
         true ->
             SslOpts = [{certfile, CertFile}, {keyfile, KeyFile}],
 
             %% set password if one is needed for the cert
-            SslOpts1 = case couch_config:get("chttps", "password", nil) of
+            SslOpts1 = case config:get("chttps", "password", nil) of
                 nil -> SslOpts;
                 Password ->
                     SslOpts ++ [{password, Password}]
             end,
             % do we verify certificates ?
-            FinalSslOpts = case couch_config:get("chttps",
+            FinalSslOpts = case config:get("chttps",
                     "verify_ssl_certificates", "false") of
                 "false" -> SslOpts1;
                 "true" ->
-                    case couch_config:get("chttps",
+                    case config:get("chttps",
                             "cacert_file", nil) of
                         nil ->
                             io:format("Verify SSL certificate "
@@ -76,7 +77,7 @@ start_link(https) ->
                                 ++"missing", []),
                             throw({error, missing_cacerts});
                         CaCertFile ->
-                            Depth = list_to_integer(couch_config:get("chttps",
+                            Depth = list_to_integer(config:get("chttps",
                                     "ssl_certificate_max_depth",
                                     "1")),
                             FinalOpts = [
@@ -84,7 +85,7 @@ start_link(https) ->
                                 {depth, Depth},
                                 {verify, verify_peer}],
                             % allows custom verify fun.
-                            case couch_config:get("chttps",
+                            case config:get("chttps",
                                     "verify_fun", nil) of
                                 nil -> FinalOpts;
                                 SpecStr ->
@@ -107,27 +108,27 @@ start_link(Name, Options) ->
     Options1 = Options ++ [
         {loop, fun ?MODULE:handle_request/1},
         {name, Name},
-        {ip, couch_config:get("chttpd", "bind_address", any)}
+        {ip, config:get("chttpd", "bind_address", any)}
     ],
-    ServerOptsCfg = couch_config:get("chttpd", "server_options", "[]"),
+    ServerOptsCfg = config:get("chttpd", "server_options", "[]"),
     {ok, ServerOpts} = couch_util:parse_term(ServerOptsCfg),
     Options2 = lists:keymerge(1, lists:sort(Options1), lists:sort(ServerOpts)),
     case mochiweb_http:start(Options2) of
     {ok, Pid} ->
-        ok = couch_config:register(fun ?MODULE:config_change/2, Pid),
+        ok = config:listen_for_changes(?MODULE, nil),
         {ok, Pid};
     {error, Reason} ->
         io:format("Failure to start Mochiweb: ~s~n", [Reason]),
         {error, Reason}
     end.
 
-config_change("chttpd", "bind_address") ->
+handle_config_change("chttpd", "bind_address", _, _, _) ->
     ?MODULE:stop();
-config_change("chttpd", "port") ->
+handle_config_change("chttpd", "port", _, _, _) ->
     ?MODULE:stop();
-config_change("chttpd", "backlog") ->
+handle_config_change("chttpd", "backlog", _, _, _) ->
     ?MODULE:stop();
-config_change("chttpd", "server_options") ->
+handle_config_change("chttpd", "server_options", _, _, _) ->
     ?MODULE:stop().
 
 stop() ->
@@ -137,7 +138,7 @@ stop() ->
 handle_request(MochiReq) ->
     Begin = now(),
 
-    case couch_config:get("chttpd", "socket_options") of
+    case config:get("chttpd", "socket_options") of
     undefined ->
         ok;
     SocketOptsCfg ->
@@ -300,8 +301,8 @@ is_http(_) ->
     false.
 
 make_uri(Req, Raw) ->
-    Url = list_to_binary(["http://";, couch_config:get("httpd", "bind_address"),
-                         ":", couch_config:get("chttpd", "port"), "/", Raw]),
+    Url = list_to_binary(["http://";, config:get("httpd", "bind_address"),
+                         ":", config:get("chttpd", "port"), "/", Raw]),
     Headers = [
         {<<"authorization">>, ?l2b(header_value(Req,"authorization",""))},
         {<<"cookie">>, ?l2b(header_value(Req,"cookie",""))}
@@ -316,11 +317,11 @@ authenticate_request(#httpd{user_ctx=#user_ctx{}} = Req, 
_AuthFuns) ->
 authenticate_request(#httpd{} = Req, [AuthFun|Rest]) ->
     authenticate_request(AuthFun(Req), Rest);
 authenticate_request(#httpd{} = Req, []) ->
-    case couch_config:get("chttpd", "require_valid_user", "false") of
+    case config:get("chttpd", "require_valid_user", "false") of
     "true" ->
         throw({unauthorized, <<"Authentication required.">>});
     "false" ->
-        case couch_config:get("admins") of
+        case config:get("admins") of
         [] ->
             Ctx = #user_ctx{roles=[<<"_reader">>, <<"_writer">>, 
<<"_admin">>]},
             Req#httpd{user_ctx = Ctx};
@@ -411,7 +412,7 @@ path(#httpd{mochi_req=MochiReq}) ->
     MochiReq:get(path).
 
 absolute_uri(#httpd{mochi_req=MochiReq}, Path) ->
-    XHost = couch_config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"),
+    XHost = config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"),
     Host = case MochiReq:get_header_value(XHost) of
         undefined ->
             case MochiReq:get_header_value("Host") of
@@ -423,11 +424,11 @@ absolute_uri(#httpd{mochi_req=MochiReq}, Path) ->
             end;
         Value -> Value
     end,
-    XSsl = couch_config:get("httpd", "x_forwarded_ssl", "X-Forwarded-Ssl"),
+    XSsl = config:get("httpd", "x_forwarded_ssl", "X-Forwarded-Ssl"),
     Scheme = case MochiReq:get_header_value(XSsl) of
         "on" -> "https";
         _ ->
-            XProto = couch_config:get("httpd", "x_forwarded_proto",
+            XProto = config:get("httpd", "x_forwarded_proto",
                 "X-Forwarded-Proto"),
             case MochiReq:get_header_value(XProto) of
                 % Restrict to "https" and "http" schemes only
@@ -706,16 +707,16 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, 401=Code, 
ErrorStr, ReasonStr) ->
     % this is where the basic auth popup is triggered
     case MochiReq:get_header_value("X-CouchDB-WWW-Authenticate") of
     undefined ->
-        case couch_config:get("httpd", "WWW-Authenticate", nil) of
+        case config:get("httpd", "WWW-Authenticate", nil) of
         nil ->
             % If the client is a browser and the basic auth popup isn't turned 
on
             % redirect to the session page.
             case ErrorStr of
             <<"unauthorized">> ->
-                case couch_config:get("couch_httpd_auth", 
"authentication_redirect", nil) of
+                case config:get("couch_httpd_auth", "authentication_redirect", 
nil) of
                 nil -> {Code, []};
                 AuthRedirect ->
-                    case couch_config:get("couch_httpd_auth", 
"require_valid_user", "false") of
+                    case config:get("couch_httpd_auth", "require_valid_user", 
"false") of
                     "true" ->
                         % send the browser popup header no matter what if we 
are require_valid_user
                         {Code, [{"WWW-Authenticate", "Basic 
realm=\"server\""}]};

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7c0ed516/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 97b0d4d..a50cacf 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -173,9 +173,9 @@ handle_design_info_req(Req, _Db, _DDoc) ->
 
 create_db_req(#httpd{}=Req, DbName) ->
     couch_httpd:verify_is_server_admin(Req),
-    N = couch_httpd:qs_value(Req, "n", couch_config:get("cluster", "n", "3")),
-    Q = couch_httpd:qs_value(Req, "q", couch_config:get("cluster", "q", "8")),
-    P = couch_httpd:qs_value(Req, "placement", couch_config:get("cluster", 
"placement")),
+    N = couch_httpd:qs_value(Req, "n", config:get("cluster", "n", "3")),
+    Q = couch_httpd:qs_value(Req, "q", config:get("cluster", "q", "8")),
+    P = couch_httpd:qs_value(Req, "placement", config:get("cluster", 
"placement")),
     DocUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)),
     case fabric:create_db(DbName, [{n,N}, {q,Q}, {placement,P}]) of
     ok ->

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7c0ed516/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index e743d31..994cd1c 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -56,7 +56,7 @@ get_version() ->
     list_to_binary(Version).
 
 handle_favicon_req(Req) ->
-    handle_favicon_req(Req, couch_config:get("chttpd", "docroot")).
+    handle_favicon_req(Req, config:get("chttpd", "docroot")).
 
 handle_favicon_req(#httpd{method='GET'}=Req, DocumentRoot) ->
     chttpd:serve_file(Req, "favicon.ico", DocumentRoot);
@@ -64,7 +64,7 @@ handle_favicon_req(Req, _) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 handle_utils_dir_req(Req) ->
-    handle_utils_dir_req(Req, couch_config:get("chttpd", "docroot")).
+    handle_utils_dir_req(Req, config:get("chttpd", "docroot")).
 
 handle_utils_dir_req(#httpd{method='GET'}=Req, DocumentRoot) ->
     "/" ++ UrlPath = chttpd:path(Req),
@@ -88,7 +88,7 @@ handle_sleep_req(Req) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 handle_all_dbs_req(#httpd{method='GET'}=Req) ->
-    ShardDbName = couch_config:get("mem3", "shard_db", "dbs"),
+    ShardDbName = config:get("mem3", "shard_db", "dbs"),
     %% shard_db is not sharded but mem3:shards treats it as an edge case
     %% so it can be pushed thru fabric
     {ok, Info} = fabric:get_db_info(ShardDbName),
@@ -202,7 +202,7 @@ handle_config_req(#httpd{method='GET', path_parts=[_]}=Req) 
->
         false ->
             dict:store(Section, [{list_to_binary(Key), 
list_to_binary(Value)}], Acc)
         end
-    end, dict:new(), couch_config:all()),
+    end, dict:new(), config:all()),
     KVs = dict:fold(fun(Section, Values, Acc) ->
         [{list_to_binary(Section), {Values}} | Acc]
     end, [], Grouped),
@@ -210,19 +210,19 @@ handle_config_req(#httpd{method='GET', 
path_parts=[_]}=Req) ->
 % GET /_config/Section
 handle_config_req(#httpd{method='GET', path_parts=[_,Section]}=Req) ->
     KVs = [{list_to_binary(Key), list_to_binary(Value)}
-            || {Key, Value} <- couch_config:get(Section)],
+            || {Key, Value} <- config:get(Section)],
     send_json(Req, 200, {KVs});
 % PUT /_config/Section/Key
 % "value"
 handle_config_req(#httpd{method='PUT', path_parts=[_, Section, Key]}=Req) ->
     Value = chttpd:json_body(Req),
     Persist = chttpd:header_value(Req, "X-Couch-Persist") /= "false",
-    OldValue = couch_config:get(Section, Key, ""),
-    ok = couch_config:set(Section, Key, ?b2l(Value), Persist),
+    OldValue = config:get(Section, Key, ""),
+    ok = config:set(Section, Key, ?b2l(Value), Persist),
     send_json(Req, 200, list_to_binary(OldValue));
 % GET /_config/Section/Key
 handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req) ->
-    case couch_config:get(Section, Key, null) of
+    case config:get(Section, Key, null) of
     null ->
         throw({not_found, unknown_config_value});
     Value ->
@@ -231,11 +231,11 @@ handle_config_req(#httpd{method='GET', path_parts=[_, 
Section, Key]}=Req) ->
 % DELETE /_config/Section/Key
 handle_config_req(#httpd{method='DELETE',path_parts=[_,Section,Key]}=Req) ->
     Persist = chttpd:header_value(Req, "X-Couch-Persist") /= "false",
-    case couch_config:get(Section, Key, null) of
+    case config:get(Section, Key, null) of
     null ->
         throw({not_found, unknown_config_value});
     OldValue ->
-        couch_config:delete(Section, Key, Persist),
+        config:delete(Section, Key, Persist),
         send_json(Req, 200, list_to_binary(OldValue))
     end;
 handle_config_req(Req) ->

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7c0ed516/src/chttpd_rewrite.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_rewrite.erl b/src/chttpd_rewrite.erl
index a878d09..a18fa00 100644
--- a/src/chttpd_rewrite.erl
+++ b/src/chttpd_rewrite.erl
@@ -411,7 +411,7 @@ path_to_list([<<>>|R], Acc, DotDotCount) ->
 path_to_list([<<"*">>|R], Acc, DotDotCount) ->
     path_to_list(R, [?MATCH_ALL|Acc], DotDotCount);
 path_to_list([<<"..">>|R], Acc, DotDotCount) when DotDotCount == 2 ->
-    case couch_config:get("httpd", "secure_rewrites", "true") of
+    case config:get("httpd", "secure_rewrites", "true") of
     "false" ->
         path_to_list(R, [<<"..">>|Acc], DotDotCount+1);
     _Else ->

Reply via email to