You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2009/09/13 13:16:20 UTC

svn commit: r814302 - in /couchdb/branches/0.10.x: src/couchdb/couch_config.erl src/couchdb/couch_server.erl test/etap/082-config-register.t

Author: jan
Date: Sun Sep 13 11:16:20 2009
New Revision: 814302

URL: http://svn.apache.org/viewvc?rev=814302&view=rev
Log:
allow config callbacks to get passed the X-Couch-Persist flag

Modified:
    couchdb/branches/0.10.x/src/couchdb/couch_config.erl
    couchdb/branches/0.10.x/src/couchdb/couch_server.erl
    couchdb/branches/0.10.x/test/etap/082-config-register.t

Modified: couchdb/branches/0.10.x/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_config.erl?rev=814302&r1=814301&r2=814302&view=diff
==============================================================================
--- couchdb/branches/0.10.x/src/couchdb/couch_config.erl (original)
+++ couchdb/branches/0.10.x/src/couchdb/couch_config.erl Sun Sep 13 11:16:20 2009
@@ -128,7 +128,7 @@
         _ ->
             ok
     end,
-    [catch F(Sec, Key, Val) || {_Pid, F} <- Config#config.notify_funs],
+    [catch F(Sec, Key, Val, Persist) || {_Pid, F} <- Config#config.notify_funs],
     {reply, ok, Config};
 handle_call({delete, Sec, Key, Persist}, _From, Config) ->
     true = ets:delete(?MODULE, {Sec,Key}),
@@ -140,7 +140,7 @@
         _ ->
             ok
     end,
-    [catch F(Sec, Key, deleted) || {_Pid, F} <- Config#config.notify_funs],
+    [catch F(Sec, Key, deleted, Persist) || {_Pid, F} <- Config#config.notify_funs],
     {reply, ok, Config};
 handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) ->
     erlang:monitor(process, Pid),
@@ -148,10 +148,12 @@
     Fun2 =
     case Fun of
         _ when is_function(Fun, 1) ->
-            fun(Section, _Key, _Value) -> Fun(Section) end;
+            fun(Section, _Key, _Value, _Persist) -> Fun(Section) end;
         _ when is_function(Fun, 2) ->
-            fun(Section, Key, _Value) -> Fun(Section, Key) end;
+            fun(Section, Key, _Value, _Persist) -> Fun(Section, Key) end;
         _ when is_function(Fun, 3) ->
+            fun(Section, Key, Value, _Persist) -> Fun(Section, Key, Value) end;
+        _ when is_function(Fun, 4) ->
             Fun
     end,
     {reply, ok, Config#config{notify_funs=[{Pid, Fun2} | PidFuns]}}.

Modified: couchdb/branches/0.10.x/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_server.erl?rev=814302&r1=814301&r2=814302&view=diff
==============================================================================
--- couchdb/branches/0.10.x/src/couchdb/couch_server.erl (original)
+++ couchdb/branches/0.10.x/src/couchdb/couch_server.erl Sun Sep 13 11:16:20 2009
@@ -116,13 +116,17 @@
     filename:join([Server#server.root_dir, "./" ++ DbName ++ ".couch"]).
 
 hash_admin_passwords() ->
+    hash_admin_passwords(true).
+
+hash_admin_passwords(Persist) ->
     lists:foreach(
         fun({_User, "-hashed-" ++ _}) ->
             ok; % already hashed
         ({User, ClearPassword}) ->
             Salt = ?b2l(couch_util:new_uuid()),
             Hashed = couch_util:to_hex(crypto:sha(ClearPassword ++ Salt)),
-            couch_config:set("admins", User, "-hashed-" ++ Hashed ++ "," ++ Salt)
+            couch_config:set("admins", 
+                User, "-hashed-" ++ Hashed ++ "," ++ Salt, Persist)
         end, couch_config:get("admins")).
 
 init([]) ->
@@ -146,10 +150,10 @@
         end),
     hash_admin_passwords(),
     ok = couch_config:register(
-        fun("admins") ->
+        fun("admins", _Key, _Value, Persist) ->
             % spawn here so couch_config doesn't try to call itself
-            spawn(fun() -> hash_admin_passwords() end)
-        end),
+            spawn(fun() -> hash_admin_passwords(Persist) end)
+        end, false),
     {ok, RegExp} = re:compile("^[a-z][a-z0-9\\_\\$()\\+\\-\\/]*$"),
     ets:new(couch_dbs_by_name, [set, private, named_table]),
     ets:new(couch_dbs_by_pid, [set, private, named_table]),

Modified: couchdb/branches/0.10.x/test/etap/082-config-register.t
URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/test/etap/082-config-register.t?rev=814302&r1=814301&r2=814302&view=diff
==============================================================================
--- couchdb/branches/0.10.x/test/etap/082-config-register.t (original)
+++ couchdb/branches/0.10.x/test/etap/082-config-register.t Sun Sep 13 11:16:20 2009
@@ -84,4 +84,11 @@
         "Implicitly test that the function got de-registered"
     ),
 
+    % test passing of Persist flag
+    couch_config:register(
+        fun("httpd", _, _, Persist) ->
+            etap:is(Persist, false)
+        end),
+    ok = couch_config:set("httpd", "port", "80", false),
+
     ok.