]> granicus.if.org Git - ejabberd/commitdiff
Don't validate an option in ejabberd_config:get_option() functions
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 29 Apr 2017 08:39:40 +0000 (11:39 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 29 Apr 2017 08:39:40 +0000 (11:39 +0300)
The commit introduces the following changes:
* Now there is no need to pass validating function in
  ejabberd_config:get_option() functions, because the configuration
  keeps already validated values.
* New function ejabberd_config:get_option/1 is introduced
* Function ejabberd_config:get_option/3 is deprecated. If the function
  is still called, the second argument (validating function) is simply
  ignored.
* The second argument for ejabberd_config:get_option/2 is now
  a default value, not a validating function.

43 files changed:
src/acl.erl
src/cyrsasl_digest.erl
src/ejabberd_access_permissions.erl
src/ejabberd_app.erl
src/ejabberd_auth.erl
src/ejabberd_auth_anonymous.erl
src/ejabberd_auth_external.erl
src/ejabberd_auth_pam.erl
src/ejabberd_c2s.erl
src/ejabberd_c2s_config.erl
src/ejabberd_captcha.erl
src/ejabberd_commands.erl
src/ejabberd_config.erl
src/ejabberd_ctl.erl
src/ejabberd_http.erl
src/ejabberd_http_ws.erl
src/ejabberd_listener.erl
src/ejabberd_oauth.erl
src/ejabberd_oauth_rest.erl
src/ejabberd_rdbms.erl
src/ejabberd_receiver.erl
src/ejabberd_redis.erl
src/ejabberd_redis_sup.erl
src/ejabberd_riak_sup.erl
src/ejabberd_router.erl
src/ejabberd_s2s.erl
src/ejabberd_s2s_out.erl
src/ejabberd_sm.erl
src/ejabberd_sql.erl
src/ejabberd_sql_sup.erl
src/ejabberd_system_monitor.erl
src/ejabberd_web_admin.erl
src/ext_mod.erl
src/extauth.erl
src/gen_mod.erl
src/mod_last.erl
src/mod_mam_sql.erl
src/mod_register.erl
src/mod_s2s_dialback.erl
src/mod_sip_proxy.erl
src/rest.erl
src/shaper.erl
src/sql_queries.erl

index 0cdd7daa65a379c19b67aa99fec4a082cdc4d3e1..3e0617f5565bcefd16dcb155d3967c55355b9071 100644 (file)
@@ -199,13 +199,13 @@ load_from_config() ->
     lists:foreach(
       fun(Host) ->
               ACLs = ejabberd_config:get_option(
-                       {acl, Host}, fun(V) -> V end, []),
+                       {acl, Host}, []),
               AccessRules = ejabberd_config:get_option(
-                              {access, Host}, fun(V) -> V end, []),
+                              {access, Host}, []),
               AccessRulesNew = ejabberd_config:get_option(
-                                {access_rules, Host}, fun(V) -> V end, []),
+                                {access_rules, Host}, []),
               ShaperRules = ejabberd_config:get_option(
-                                {shaper_rules, Host}, fun(V) -> V end, []),
+                                {shaper_rules, Host}, []),
               lists:foreach(
                 fun({ACLName, SpecList}) ->
                         lists:foreach(
@@ -605,7 +605,7 @@ access_rules_validator(Rules0) ->
                                          (deny) -> true;
                                          (_) -> false
                                       end),
-    throw({replace_with, Rules}).
+    Rules.
 
 
 shaper_rules_validator(Name) when is_atom(Name) ->
@@ -616,7 +616,7 @@ shaper_rules_validator(Rules0) ->
                                          (V2) when is_integer(V2) -> true;
                                          (_) -> false
                                       end),
-    throw({replace_with, Rules}).
+    Rules.
 
 access_shaper_rules_validator([{Type, Acls} = Rule | Rest], RuleTypeCheck) ->
     case RuleTypeCheck(Type) of
index eedb5366c8bb2f9ca62a16667634bd11f7d7c013..9d23271d187dd4199e98a5736e607c7bcad5253c 100644 (file)
@@ -55,7 +55,7 @@
                 check_password :: check_password_fun(),
                 auth_module :: atom(),
                 host = <<"">> :: binary(),
-                hostfqdn = <<"">> :: binary() | [binary()]}).
+                hostfqdn = [] :: [binary()]}).
 
 start(_Opts) ->
     Fqdn = get_local_fqdn(),
@@ -204,8 +204,6 @@ is_digesturi_valid(DigestURICase, JabberDomain,
            false
     end.
 
-is_host_fqdn(Host, Fqdn) when is_binary(Fqdn) ->
-    Host == Fqdn;
 is_host_fqdn(_Host, []) ->
     false;
 is_host_fqdn(Host, [Fqdn | _FqdnTail]) when Host == Fqdn ->
@@ -214,26 +212,13 @@ is_host_fqdn(Host, [Fqdn | FqdnTail]) when Host /= Fqdn ->
     is_host_fqdn(Host, FqdnTail).
 
 get_local_fqdn() ->
-    case catch get_local_fqdn2() of
-      Str when is_binary(Str) -> Str;
-      List when is_list(List) -> List;
-      _ ->
-         <<"unknown-fqdn, please configure fqdn "
-           "option in ejabberd.yml!">>
-    end.
-
-get_local_fqdn2() ->
-    case ejabberd_config:get_option(
-           fqdn, fun(X) -> X end) of
-        ConfiguredFqdn when is_binary(ConfiguredFqdn) ->
-            ConfiguredFqdn;
-        [A | _] = ConfiguredFqdns when is_binary(A) ->
-            ConfiguredFqdns;
-        undefined ->
-            {ok, Hostname} = inet:gethostname(),
-            {ok, {hostent, Fqdn, _, _, _, _}} =
-            inet:gethostbyname(Hostname),
-            list_to_binary(Fqdn)
+    case ejabberd_config:get_option(fqdn) of
+       undefined ->
+           {ok, Hostname} = inet:gethostname(),
+           {ok, {hostent, Fqdn, _, _, _, _}} = inet:gethostbyname(Hostname),
+           [list_to_binary(Fqdn)];
+       Fqdn ->
+           Fqdn
     end.
 
 hex(S) ->
@@ -275,5 +260,10 @@ response(KeyVals, User, Passwd, Nonce, AuthzId,
          ":", (hex((erlang:md5(A2))))/binary>>,
     hex((erlang:md5(T))).
 
-opt_type(fqdn) -> fun iolist_to_binary/1;
+opt_type(fqdn) ->
+    fun(FQDN) when is_binary(FQDN) ->
+           [FQDN];
+       (FQDNs) when is_list(FQDNs) ->
+           [iolist_to_binary(FQDN) || FQDN <- FQDNs]
+    end;
 opt_type(_) -> [fqdn].
index 244b2c121c5d1f0cc0cdb6d20bbc955355804e9d..b27d176831907adbca1cf9ab90d11a9df0368729 100644 (file)
@@ -239,8 +239,7 @@ get_definitions(#state{definitions = none, fragments_generators = Gens} = State)
                        [{acl,{acl,admin}},
                         {oauth,[<<"ejabberd:admin">>],[{acl,{acl,admin}}]}],
                        {all, [start, stop]}}}],
-    ApiPerms = ejabberd_config:get_option(api_permissions, fun(A) -> A end,
-                                         DefaultOptions),
+    ApiPerms = ejabberd_config:get_option(api_permissions, DefaultOptions),
     AllCommands = ejabberd_commands:get_commands_definition(),
     Frags = lists:foldl(
              fun({_Name, Generator}, Acc) ->
@@ -334,7 +333,7 @@ command_matches_patterns(C, [_ | Tail]) ->
 %%%===================================================================
 
 parse_api_permissions(Data) when is_list(Data) ->
-    throw({replace_with, [parse_api_permission(Name, Args) || {Name, Args} <- Data]}).
+    [parse_api_permission(Name, Args) || {Name, Args} <- Data].
 
 parse_api_permission(Name, Args0) ->
     Args = lists:flatten(Args0),
@@ -374,8 +373,6 @@ parse_who(Name, Defs, ParseOauth) when is_list(Defs) ->
                throw:{invalid_syntax, Msg} ->
                    report_error(<<"Invalid access rule: '~s' used inside 'who' section for api_permission '~s'">>,
                                 [Msg, Name]);
-               throw:{replace_with, NVal} ->
-                   {access, NVal};
                error:_ ->
                    report_error(<<"Invalid access rule '~p' used inside 'who' section for api_permission '~s'">>,
                                 [Val, Name])
index c96cd95f656acb02587f370cea5a1dc0dbef05f4..b23249aa006e4d949ae4f6ee6f90400d30eacd86 100644 (file)
@@ -89,12 +89,7 @@ stop(_State) ->
 %%%
 
 connect_nodes() ->
-    Nodes = ejabberd_config:get_option(
-              cluster_nodes,
-              fun(Ns) ->
-                      true = lists:all(fun is_atom/1, Ns),
-                      Ns
-              end, []),
+    Nodes = ejabberd_config:get_option(cluster_nodes, []),
     lists:foreach(fun(Node) ->
                           net_kernel:connect_node(Node)
                   end, Nodes).
@@ -142,10 +137,7 @@ delete_pid_file() ->
     end.
 
 set_settings_from_config() ->
-    Ticktime = ejabberd_config:get_option(
-                 net_ticktime,
-                 opt_type(net_ticktime),
-                 60),
+    Ticktime = ejabberd_config:get_option(net_ticktime, 60),
     net_kernel:set_net_ticktime(Ticktime).
 
 file_queue_init() ->
index 8839cf89a68e11188c0de7a2084850d4b00dbc33..756fafcf67747a48c33d88f9fc66a77fac117b5c 100644 (file)
@@ -498,9 +498,7 @@ backend_type(Mod) ->
     end.
 
 password_format(LServer) ->
-    ejabberd_config:get_option({auth_password_format, LServer},
-                              opt_type(auth_password_format),
-                              plain).
+    ejabberd_config:get_option({auth_password_format, LServer}, plain).
 
 %%%----------------------------------------------------------------------
 %%% Internal functions
@@ -513,8 +511,7 @@ auth_modules() ->
 auth_modules(Server) ->
     LServer = jid:nameprep(Server),
     Default = ejabberd_config:default_db(LServer, ?MODULE),
-    Methods = ejabberd_config:get_option(
-                {auth_method, LServer}, opt_type(auth_method), [Default]),
+    Methods = ejabberd_config:get_option({auth_method, LServer}, [Default]),
     [misc:binary_to_atom(<<"ejabberd_auth_",
                           (misc:atom_to_binary(M))/binary>>)
      || M <- Methods].
index 51eab74b7f81a4f6dc415a721c5c5cc6e3e73506..a75af709ed6c49387ef24d6c6da4db5b35e80c80 100644 (file)
 -module(ejabberd_auth_anonymous).
 
 -behaviour(ejabberd_config).
+-behaviour(ejabberd_auth).
 -author('mickael.remond@process-one.net').
 
 -export([start/1,
+        stop/1,
         allow_anonymous/1,
         is_sasl_anonymous_enabled/1,
         is_login_anonymous_enabled/1,
@@ -59,6 +61,12 @@ start(Host) ->
                       ?MODULE, unregister_connection, 100),
     ok.
 
+stop(Host) ->
+    ejabberd_hooks:delete(sm_register_connection_hook, Host,
+                         ?MODULE, register_connection, 100),
+    ejabberd_hooks:delete(sm_remove_connection_hook, Host,
+                         ?MODULE, unregister_connection, 100).
+
 %% Return true if anonymous is allowed for host or false otherwise
 allow_anonymous(Host) ->
     lists:member(?MODULE, ejabberd_auth:auth_modules(Host)).
@@ -93,21 +101,12 @@ is_login_anonymous_enabled(Host) ->
 %% Return the anonymous protocol to use: sasl_anon|login_anon|both
 %% defaults to login_anon
 anonymous_protocol(Host) ->
-    ejabberd_config:get_option(
-      {anonymous_protocol, Host},
-      fun(sasl_anon) -> sasl_anon;
-         (login_anon) -> login_anon;
-         (both) -> both
-      end,
-      sasl_anon).
+    ejabberd_config:get_option({anonymous_protocol, Host}, sasl_anon).
 
 %% Return true if multiple connections have been allowed in the config file
 %% defaults to false
 allow_multiple_connections(Host) ->
-    ejabberd_config:get_option(
-      {allow_multiple_connections, Host},
-      fun(V) when is_boolean(V) -> V end,
-      false).
+    ejabberd_config:get_option({allow_multiple_connections, Host}, false).
 
 anonymous_user_exist(User, Server) ->
     lists:any(
index 4ba76cd99e093af2c3940e9fb511a4372855db97..8ba2e2b221a0287f050008c2c19d0bcddab5b691 100644 (file)
 %%% API
 %%%----------------------------------------------------------------------
 start(Host) ->
-    Cmd = ejabberd_config:get_option(
-            {extauth_program, Host},
-            fun(V) ->
-                    binary_to_list(iolist_to_binary(V))
-            end,
-            "extauth"),
+    Cmd = ejabberd_config:get_option({extauth_program, Host}, "extauth"),
     extauth:start(Host, Cmd),
     check_cache_last_options(Host),
     ejabberd_auth_mnesia:start(Host).
@@ -179,12 +174,8 @@ remove_user(User, Server, Password) ->
 
 %% @spec (Host::string()) -> false | {true, CacheTime::integer()}
 get_cache_option(Host) ->
-    case ejabberd_config:get_option(
-           {extauth_cache, Host},
-           fun(false) -> undefined;
-              (I) when is_integer(I), I >= 0 -> I
-           end) of
-        undefined -> false;
+    case ejabberd_config:get_option({extauth_cache, Host}, false) of
+        false -> false;
         CacheTime -> {true, CacheTime}
     end.
 
@@ -319,12 +310,11 @@ get_mod_last_configured(Server) ->
     end.
 
 is_configured(Host, Module) ->
-    Os = ejabberd_config:get_option({modules, Host},
-                                         fun(M) when is_list(M) -> M end),
+    Os = ejabberd_config:get_option({modules, Host}, []),
     lists:keymember(Module, 1, Os).
 
 opt_type(extauth_cache) ->
-    fun (false) -> undefined;
+    fun (false) -> false;
        (I) when is_integer(I), I >= 0 -> I
     end;
 opt_type(extauth_program) ->
index 51ad3a8815e7bb8ad5142d81d16ea33b41f458ce..974cc8e43c107e41baf22c3675aa7f7b4794c4ad 100644 (file)
@@ -112,18 +112,10 @@ store_type() -> external.
 %% Internal functions
 %%====================================================================
 get_pam_service(Host) ->
-    ejabberd_config:get_option(
-      {pam_service, Host},
-      fun iolist_to_binary/1,
-      <<"ejabberd">>).
+    ejabberd_config:get_option({pam_service, Host}, <<"ejabberd">>).
 
 get_pam_userinfotype(Host) ->
-    ejabberd_config:get_option(
-      {pam_userinfotype, Host},
-      fun(username) -> username;
-         (jid) -> jid
-      end,
-      username).
+    ejabberd_config:get_option({pam_userinfotype, Host}, username).
 
 opt_type(pam_service) -> fun iolist_to_binary/1;
 opt_type(pam_userinfotype) ->
index 6dee111ff48663173ebf37ac17c699c5b69aaf54..acbc659c786365ef8baa63b70fe8f7adaebbb33b 100644 (file)
@@ -293,45 +293,37 @@ process_terminated(State, _Reason) ->
 tls_options(#{lserver := LServer, tls_options := DefaultOpts}) ->
     TLSOpts1 = case ejabberd_config:get_option(
                      {c2s_certfile, LServer},
-                     fun iolist_to_binary/1,
                      ejabberd_config:get_option(
-                       {domain_certfile, LServer},
-                       fun iolist_to_binary/1)) of
+                       {domain_certfile, LServer})) of
                   undefined -> DefaultOpts;
                   CertFile -> lists:keystore(certfile, 1, DefaultOpts,
                                              {certfile, CertFile})
               end,
     TLSOpts2 = case ejabberd_config:get_option(
-                      {c2s_ciphers, LServer},
-                     fun iolist_to_binary/1) of
+                      {c2s_ciphers, LServer}) of
                    undefined -> TLSOpts1;
                    Ciphers -> lists:keystore(ciphers, 1, TLSOpts1,
                                             {ciphers, Ciphers})
                end,
     TLSOpts3 = case ejabberd_config:get_option(
-                      {c2s_protocol_options, LServer},
-                      fun (Options) -> str:join(Options, <<$|>>) end) of
+                      {c2s_protocol_options, LServer}) of
                    undefined -> TLSOpts2;
                    ProtoOpts -> lists:keystore(protocol_options, 1, TLSOpts2,
                                               {protocol_options, ProtoOpts})
                end,
     TLSOpts4 = case ejabberd_config:get_option(
-                      {c2s_dhfile, LServer},
-                     fun iolist_to_binary/1) of
+                      {c2s_dhfile, LServer}) of
                    undefined -> TLSOpts3;
                    DHFile -> lists:keystore(dhfile, 1, TLSOpts3,
                                            {dhfile, DHFile})
                end,
     TLSOpts5 = case ejabberd_config:get_option(
-                     {c2s_cafile, LServer},
-                     fun iolist_to_binary/1) of
+                     {c2s_cafile, LServer}) of
                   undefined -> TLSOpts4;
                   CAFile -> lists:keystore(cafile, 1, TLSOpts4,
                                            {cafile, CAFile})
               end,
-    case ejabberd_config:get_option(
-          {c2s_tls_compression, LServer},
-          fun(B) when is_boolean(B) -> B end) of
+    case ejabberd_config:get_option({c2s_tls_compression, LServer}) of
        undefined -> TLSOpts5;
        false -> [compression_none | TLSOpts5];
        true -> lists:delete(compression_none, TLSOpts5)
@@ -360,13 +352,7 @@ authenticated_stream_features(#{lserver := LServer}) ->
     ejabberd_hooks:run_fold(c2s_post_auth_features, LServer, [], [LServer]).
 
 sasl_mechanisms(Mechs, #{lserver := LServer}) ->
-    Mechs1 = ejabberd_config:get_option(
-              {disable_sasl_mechanisms, LServer},
-              fun(V) when is_list(V) ->
-                      lists:map(fun(M) -> str:to_upper(M) end, V);
-                 (V) ->
-                      [str:to_upper(V)]
-              end, []),
+    Mechs1 = ejabberd_config:get_option({disable_sasl_mechanisms, LServer}, []),
     Mechs2 = case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(LServer) of
                 true -> Mechs1;
                 false -> [<<"ANONYMOUS">>|Mechs1]
@@ -805,22 +791,15 @@ resource_conflict_action(U, S, R) ->
     OptionRaw = case ejabberd_sm:is_existing_resource(U, S, R) of
                    true ->
                        ejabberd_config:get_option(
-                         {resource_conflict, S},
-                         fun(setresource) -> setresource;
-                            (closeold) -> closeold;
-                            (closenew) -> closenew;
-                            (acceptnew) -> acceptnew
-                         end);
+                         {resource_conflict, S}, acceptnew);
                    false ->
                        acceptnew
                end,
     Option = case OptionRaw of
                 setresource -> setresource;
-                closeold ->
-                    acceptnew; %% ejabberd_sm will close old session
+                closeold -> acceptnew; %% ejabberd_sm will close old session
                 closenew -> closenew;
-                acceptnew -> acceptnew;
-                _ -> acceptnew %% default ejabberd behavior
+                acceptnew -> acceptnew
             end,
     case Option of
        acceptnew -> {accept_resource, R};
index 0f0a2a875af9a08ce1a0428ce70ea298eac868eb..b94bbdc52eb7b2f7f6a8f37f7557fbea84b4678d 100644 (file)
@@ -33,8 +33,7 @@
 %% Get first c2s configuration limitations to apply it to other c2s
 %% connectors.
 get_c2s_limits() ->
-    C2SFirstListen = ejabberd_config:get_option(
-                      listen, fun ejabberd_listener:validate_cfg/1, []),
+    C2SFirstListen = ejabberd_config:get_option(listen, []),
     case lists:keysearch(ejabberd_c2s, 2, C2SFirstListen) of
        false -> [];
        {value, {_Port, ejabberd_c2s, Opts}} ->
index 3c42fa094d42ef5b0b9556e256c9dc5ad43eb289..0a8dc0261c6b74946c9b7d68a021e3d3b2ea84ed 100644 (file)
@@ -350,12 +350,7 @@ do_create_image(Key) ->
     end.
 
 get_prog_name() ->
-    case ejabberd_config:get_option(
-           captcha_cmd,
-           fun(FileName) ->
-                   F = iolist_to_binary(FileName),
-                   if F /= <<"">> -> F end
-           end) of
+    case ejabberd_config:get_option(captcha_cmd) of
         undefined ->
             ?DEBUG("The option captcha_cmd is not configured, "
                    "but some module wants to use the CAPTCHA "
@@ -367,10 +362,7 @@ get_prog_name() ->
     end.
 
 get_url(Str) ->
-    CaptchaHost = ejabberd_config:get_option(
-                    captcha_host,
-                    fun iolist_to_binary/1,
-                    <<"">>),
+    CaptchaHost = ejabberd_config:get_option(captcha_host, <<"">>),
     case str:tokens(CaptchaHost, <<":">>) of
       [Host] ->
          <<"http://", Host/binary, "/captcha/", Str/binary>>;
@@ -395,8 +387,7 @@ get_transfer_protocol(PortString) ->
     get_captcha_transfer_protocol(PortListeners).
 
 get_port_listeners(PortNumber) ->
-    AllListeners = ejabberd_config:get_option(
-                    listen, fun ejabberd_listener:validate_cfg/1, []),
+    AllListeners = ejabberd_config:get_option(listen, []),
     lists:filter(fun (Listener) when is_list(Listener) ->
                         case proplists:get_value(port, Listener) of
                           PortNumber -> true;
@@ -426,9 +417,7 @@ get_captcha_transfer_protocol([_ | Listeners]) ->
 
 is_limited(undefined) -> false;
 is_limited(Limiter) ->
-    case ejabberd_config:get_option(
-           captcha_limit,
-           fun(I) when is_integer(I), I > 0 -> I end) of
+    case ejabberd_config:get_option(captcha_limit) of
       undefined -> false;
       Int ->
          case catch gen_server:call(?MODULE,
index df0ce91233240eb6f346c7304311afc9ece0de18..3a6f6db1f7ae78db0716a94cadc65e9089de912f 100644 (file)
 -author('badlop@process-one.net').
 
 -behaviour(gen_server).
+-behaviour(ejabberd_config).
 
 -define(DEFAULT_VERSION, 1000000).
 
@@ -822,10 +823,7 @@ get_access_commands(AccessCommands, _Version) ->
 get_exposed_commands() ->
     get_exposed_commands(?DEFAULT_VERSION).
 get_exposed_commands(Version) ->
-    Opts0 = ejabberd_config:get_option(
-             commands,
-             fun(V) when is_list(V) -> V end,
-              []),
+    Opts0 = ejabberd_config:get_option(commands, []),
     Opts = lists:map(fun(V) when is_tuple(V) -> [V]; (V) -> V end, Opts0),
     CommandsList = list_commands_policy(Version),
     OpenCmds = [N || {N, _, _, open} <- CommandsList],
@@ -876,10 +874,7 @@ is_admin(Name, Auth, Extra) ->
                            _ ->
                                {Extra, global}
              end,
-    AdminAccess = ejabberd_config:get_option(
-                    commands_admin_access,
-                   fun(V) -> V end,
-                    none),
+    AdminAccess = ejabberd_config:get_option(commands_admin_access, none),
     case acl:access_matches(AdminAccess, ACLInfo, Server) of
         allow ->
             case catch check_auth(get_command_definition(Name), Auth) of
@@ -893,9 +888,7 @@ is_admin(Name, Auth, Extra) ->
 permission_addon() ->
     [{<<"'commands' option compatibility shim">>,
      {[],
-      [{access, ejabberd_config:get_option(commands_admin_access,
-                                          fun(V) -> V end,
-                                          none)}],
+      [{access, ejabberd_config:get_option(commands_admin_access, none)}],
       {get_exposed_commands(), []}}}].
 
 opt_type(commands_admin_access) -> fun acl:access_rules_validator/1;
index 5aa9a1d2bd9ad15d8f62d2bf624b746bbb9a2a7e..6cbaa4453972dd4d5a92ccdb9e3df3e940a004e9 100644 (file)
@@ -27,7 +27,7 @@
 -author('alexey@process-one.net').
 
 -export([start/0, load_file/1, reload_file/0, read_file/1,
-        get_option/2, get_option/3, add_option/2, has_option/1,
+        get_option/1, get_option/2, add_option/2, has_option/1,
         get_vh_by_auth_method/1, is_file_readable/1,
         get_version/0, get_myhosts/0, get_mylang/0, get_lang/1,
         get_ejabberd_config_path/0, is_using_elixir_config/0,
 %% The following functions are deprecated.
 -export([add_global_option/2, add_local_option/2,
         get_global_option/2, get_local_option/2,
-        get_global_option/3, get_local_option/3]).
+        get_global_option/3, get_local_option/3,
+        get_option/3]).
 
 -deprecated([{add_global_option, 2}, {add_local_option, 2},
             {get_global_option, 2}, {get_local_option, 2},
-            {get_global_option, 3}, {get_local_option, 3}]).
+            {get_global_option, 3}, {get_local_option, 3},
+            {get_option, 3}]).
 
 -include("ejabberd.hrl").
 -include("logger.hrl").
@@ -764,10 +766,7 @@ set_opts(State) ->
     set_log_level().
 
 set_log_level() ->
-    Level = get_option(
-              loglevel,
-              fun(P) when P>=0, P=<5 -> P end,
-              4),
+    Level = get_option(loglevel, 4),
     ejabberd_logger:set(Level).
 
 add_global_option(Opt, Val) ->
@@ -817,34 +816,38 @@ prepare_opt_val(Opt, Val, F, Default) ->
 
 -spec get_global_option(any(), check_fun()) -> any().
 
-get_global_option(Opt, F) ->
-    get_option(Opt, F, undefined).
+get_global_option(Opt, _) ->
+    get_option(Opt, undefined).
 
 -spec get_global_option(any(), check_fun(), any()) -> any().
 
-get_global_option(Opt, F, Default) ->
-    get_option(Opt, F, Default).
+get_global_option(Opt, _, Default) ->
+    get_option(Opt, Default).
 
 -spec get_local_option(any(), check_fun()) -> any().
 
-get_local_option(Opt, F) ->
-    get_option(Opt, F, undefined).
+get_local_option(Opt, _) ->
+    get_option(Opt, undefined).
 
 -spec get_local_option(any(), check_fun(), any()) -> any().
 
-get_local_option(Opt, F, Default) ->
-    get_option(Opt, F, Default).
+get_local_option(Opt, _, Default) ->
+    get_option(Opt, Default).
 
--spec get_option(any(), check_fun()) -> any().
-
-get_option(Opt, F) ->
-    get_option(Opt, F, undefined).
+-spec get_option(any()) -> any().
+get_option(Opt) ->
+    get_option(Opt, undefined).
 
 -spec get_option(any(), check_fun(), any()) -> any().
-
-get_option(Opt, F, Default) when is_atom(Opt) ->
-    get_option({Opt, global}, F, Default);
-get_option(Opt, F, Default) ->
+get_option(Opt, _, Default) ->
+    get_option(Opt, Default).
+
+-spec get_option(any(), check_fun() | any()) -> any().
+get_option(Opt, F) when is_function(F) ->
+    get_option(Opt, undefined);
+get_option(Opt, Default) when is_atom(Opt) ->
+    get_option({Opt, global}, Default);
+get_option(Opt, Default) ->
     {Key, Host} = case Opt of
                      {O, global} when is_atom(O) -> Opt;
                      {O, H} when is_atom(O), is_binary(H) -> Opt;
@@ -856,7 +859,7 @@ get_option(Opt, F, Default) ->
     case ejabberd_options:is_known(Key) of
        true ->
            case ejabberd_options:Key(Host) of
-               {ok, Val} -> prepare_opt_val(Opt, Val, F, Default);
+               {ok, Val} -> Val;
                undefined -> Default
            end;
        false ->
@@ -865,7 +868,7 @@ get_option(Opt, F, Default) ->
 
 -spec has_option(atom() | {atom(), global | binary()}) -> any().
 has_option(Opt) ->
-    get_option(Opt, fun(_) -> true end, false).
+    get_option(Opt) /= undefined.
 
 init_module_db_table(Modules) ->
     %% Dirty hack for mod_pubsub
@@ -952,7 +955,7 @@ default_ram_db(Host, Module) ->
 
 -spec default_db(default_db | default_ram_db, binary() | global, module()) -> atom().
 default_db(Opt, Host, Module) ->
-    case get_option({Opt, Host}, fun(T) when is_atom(T) -> T end) of
+    case get_option({Opt, Host}) of
        undefined ->
            mnesia;
        DBType ->
@@ -997,11 +1000,9 @@ validate_opts(#state{opts = Opts} = State) ->
                            {ok, [Mod|_]} ->
                                VFun = Mod:opt_type(Opt),
                                try VFun(Val) of
-                                   _ ->
-                                       true
-                               catch {replace_with, NewVal} ->
-                                       {true, In#local_config{value = NewVal}};
-                                     {invalid_syntax, Error} ->
+                                   NewVal ->
+                                       {true, In#local_config{value = NewVal}}
+                               catch {invalid_syntax, Error} ->
                                        ?ERROR_MSG("ignoring option '~s' with "
                                                   "invalid value: ~p: ~s",
                                                   [Opt, Val, Error]),
@@ -1028,7 +1029,7 @@ get_vh_by_auth_method(AuthMethod) ->
     get_vh_by_auth_method(AuthMethod, Hosts, []).
 
 get_vh_by_auth_method(Method, [Host|Hosts], Result) ->
-    Methods = get_option({auth_method, Host}, fun(Ms) -> Ms end, []),
+    Methods = get_option({auth_method, Host}, []),
     case lists:member(Method, Methods) of
        true when Host == global ->
            get_myhosts();
@@ -1062,7 +1063,7 @@ get_version() ->
 -spec get_myhosts() -> [binary()].
 
 get_myhosts() ->
-    get_option(hosts, fun(V) -> V end).
+    get_option(hosts).
 
 -spec get_mylang() -> binary().
 
@@ -1071,10 +1072,7 @@ get_mylang() ->
 
 -spec get_lang(global | binary()) -> binary().
 get_lang(Host) ->
-    get_option(
-      {language, Host},
-      fun iolist_to_binary/1,
-      <<"en">>).
+    get_option({language, Host}, <<"en">>).
 
 replace_module(mod_announce_odbc) -> {mod_announce, sql};
 replace_module(mod_blocking_odbc) -> {mod_blocking, sql};
@@ -1365,11 +1363,8 @@ now_to_seconds({MegaSecs, Secs, _MicroSecs}) ->
 opt_type(hide_sensitive_log_data) ->
     fun (H) when is_boolean(H) -> H end;
 opt_type(hosts) ->
-    fun(L) when is_list(L) ->
-           lists:map(
-             fun(H) ->
-                     iolist_to_binary(H)
-             end, L)
+    fun(L) ->
+           [iolist_to_binary(H) || H <- L]
     end;
 opt_type(language) ->
     fun iolist_to_binary/1;
@@ -1404,7 +1399,7 @@ opt_type(domain_certfile) ->
 opt_type(shared_key) ->
     fun iolist_to_binary/1;
 opt_type(node_start) ->
-    fun(I) when is_integer(I), I>0 -> I end;
+    fun(I) when is_integer(I), I>=0 -> I end;
 opt_type(_) ->
     [hide_sensitive_log_data, hosts, language, max_fsm_queue,
      default_db, default_ram_db, queue_type, queue_dir, loglevel,
@@ -1413,12 +1408,7 @@ opt_type(_) ->
 
 -spec may_hide_data(any()) -> any().
 may_hide_data(Data) ->
-    case get_option(
-       hide_sensitive_log_data,
-           fun(false) -> false;
-              (true) -> true
-           end,
-        false) of
+    case get_option(hide_sensitive_log_data, false) of
        false ->
            Data;
        true ->
@@ -1431,9 +1421,7 @@ fsm_limit_opts(Opts) ->
        {_, I} when is_integer(I), I>0 ->
            [{max_queue, I}];
        false ->
-           case get_option(
-                  max_fsm_queue,
-                  fun(I) when is_integer(I), I>0 -> I end) of
+           case get_option(max_fsm_queue) of
                undefined -> [];
                N -> [{max_queue, N}]
            end
@@ -1441,25 +1429,25 @@ fsm_limit_opts(Opts) ->
 
 -spec queue_dir() -> binary() | undefined.
 queue_dir() ->
-    get_option(queue_dir, opt_type(queue_dir)).
+    get_option(queue_dir).
 
 -spec default_queue_type(binary()) -> ram | file.
 default_queue_type(Host) ->
-    get_option({queue_type, Host}, opt_type(queue_type), ram).
+    get_option({queue_type, Host}, ram).
 
 -spec use_cache(binary() | global) -> boolean().
 use_cache(Host) ->
-    get_option({use_cache, Host}, opt_type(use_cache), true).
+    get_option({use_cache, Host}, true).
 
 -spec cache_size(binary() | global) -> pos_integer() | infinity.
 cache_size(Host) ->
-    get_option({cache_size, Host}, opt_type(cache_size), 1000).
+    get_option({cache_size, Host}, 1000).
 
 -spec cache_missed(binary() | global) -> boolean().
 cache_missed(Host) ->
-    get_option({cache_missed, Host}, opt_type(cache_missed), true).
+    get_option({cache_missed, Host}, true).
 
 -spec cache_life_time(binary() | global) -> pos_integer() | infinity.
 %% NOTE: the integer value returned is in *seconds*
 cache_life_time(Host) ->
-    get_option({cache_life_time, Host}, opt_type(cache_life_time), 3600).
+    get_option({cache_life_time, Host}, 3600).
index f006ad5c1a4ac827c2bd8375531a791117a5260d..a9643386d254bc61079f39a134d650712f898d89 100644 (file)
@@ -289,8 +289,7 @@ process2(Args, AccessCommands, Auth, Version) ->
     end.
 
 get_accesscommands() ->
-    ejabberd_config:get_option(ejabberdctl_access_commands,
-                                     fun(V) when is_list(V) -> V end, []).
+    ejabberd_config:get_option(ejabberdctl_access_commands, []).
 
 %%-----------------------------
 %% Command calling
index 5c591386d64644f83e70d817d3d13f6462f2dce7..7072c49fd484022d0d5bdf18be79ae25fef494bc 100644 (file)
@@ -521,12 +521,7 @@ analyze_ip_xff(IP, [], _Host) -> IP;
 analyze_ip_xff({IPLast, Port}, XFF, Host) ->
     [ClientIP | ProxiesIPs] = str:tokens(XFF, <<", ">>) ++
                                [misc:ip_to_list(IPLast)],
-    TrustedProxies = ejabberd_config:get_option(
-                       {trusted_proxies, Host},
-                       fun(all) -> all;
-                          (TPs) ->
-                               [iolist_to_binary(TP) || TP <- TPs]
-                       end, []),
+    TrustedProxies = ejabberd_config:get_option({trusted_proxies, Host}, []),
     IPClient = case is_ipchain_trusted(ProxiesIPs,
                                       TrustedProxies)
                   of
index 5231d7ab1aec859eab4f86975b20dc0e972aca9a..18ba071dd324604e5a5f4d4ae3870ddc56d6e80c 100644 (file)
@@ -123,11 +123,9 @@ init([{#ws{ip = IP, http_opts = HOpts}, _} = WS]) ->
     Opts = ejabberd_c2s_config:get_c2s_limits() ++ SOpts,
     PingInterval = ejabberd_config:get_option(
                      {websocket_ping_interval, ?MYNAME},
-                     fun(I) when is_integer(I), I>=0 -> I end,
                      ?PING_INTERVAL) * 1000,
     WSTimeout = ejabberd_config:get_option(
                   {websocket_timeout, ?MYNAME},
-                  fun(I) when is_integer(I), I>0 -> I end,
                   ?WEBSOCKET_TIMEOUT) * 1000,
     Socket = {http_ws, self(), IP},
     ?DEBUG("Client connected through websocket ~p",
index 7d3c53574e66e7b5c5b91e21b0156089182e1f98..64e7f83b0767616b3af0693ec5ebd056b9d61fb0 100644 (file)
@@ -49,24 +49,20 @@ init(_) ->
     {ok, {{one_for_one, 10, 1}, listeners_childspec()}}.
 
 listeners_childspec() ->
-    case ejabberd_config:get_option(listen, fun validate_cfg/1) of
-       undefined ->
-           [];
-       Ls ->
-           Specs = lists:map(
-                     fun({Port, Module, Opts}) ->
-                             maybe_start_sip(Module),
-                             ets:insert(?MODULE, {Port, Module, Opts}),
-                             {Port,
-                              {?MODULE, start, [Port, Module, Opts]},
-                              transient,
-                              brutal_kill,
-                              worker,
-                              [?MODULE]}
-                     end, Ls),
-           report_duplicated_portips(Ls),
-           Specs
-    end.
+    Ls = ejabberd_config:get_option(listen, []),
+    Specs = lists:map(
+             fun({Port, Module, Opts}) ->
+                     maybe_start_sip(Module),
+                     ets:insert(?MODULE, {Port, Module, Opts}),
+                     {Port,
+                      {?MODULE, start, [Port, Module, Opts]},
+                      transient,
+                      brutal_kill,
+                      worker,
+                      [?MODULE]}
+             end, Ls),
+    report_duplicated_portips(Ls),
+    Specs.
 
 start_listeners() ->
     lists:foreach(
@@ -384,7 +380,7 @@ start_listener_sup(Port, Module, Opts) ->
     supervisor:start_child(?MODULE, ChildSpec).
 
 stop_listeners() ->
-    Ports = ejabberd_config:get_option(listen, fun validate_cfg/1),
+    Ports = ejabberd_config:get_option(listen, []),
     lists:foreach(
       fun({PortIpNetp, Module, _Opts}) ->
              delete_listener(PortIpNetp, Module)
@@ -438,10 +434,7 @@ maybe_start_sip(_) ->
     ok.
 
 config_reloaded() ->
-    New = case ejabberd_config:get_option(listen, fun validate_cfg/1) of
-             undefined -> [];
-             Ls -> Ls
-         end,
+    New = ejabberd_config:get_option(listen, []),
     Old = ets:tab2list(?MODULE),
     lists:foreach(
       fun({PortIP, Module, _Opts}) ->
index 8527c9271a3a952bc905479f49986fdeb0a3f705..455db85a5e7255b2a0a4541f63028abe5297ebf2 100644 (file)
@@ -27,6 +27,7 @@
 -module(ejabberd_oauth).
 
 -behaviour(gen_server).
+-behaviour(ejabberd_config).
 
 -compile(export_all).
 
@@ -199,7 +200,6 @@ authenticate_user({User, Server}, Ctx) ->
             Access =
                 ejabberd_config:get_option(
                   {oauth_access, JID#jid.lserver},
-                 fun(A) -> A end,
                   none),
             case acl:match_rule(JID#jid.lserver, Access, JID) of
                 allow ->
@@ -402,22 +402,19 @@ use_cache(DBMod) ->
        true -> DBMod:use_cache();
        false ->
            ejabberd_config:get_option(
-             oauth_use_cache, opt_type(oauth_use_cache),
+             oauth_use_cache,
              ejabberd_config:use_cache(global))
     end.
 
 cache_opts() ->
     MaxSize = ejabberd_config:get_option(
                oauth_cache_size,
-               opt_type(oauth_cache_size),
                ejabberd_config:cache_size(global)),
     CacheMissed = ejabberd_config:get_option(
                    oauth_cache_missed,
-                   opt_type(oauth_cache_missed),
                    ejabberd_config:cache_missed(global)),
     LifeTime = case ejabberd_config:get_option(
                      oauth_cache_life_time,
-                     opt_type(oauth_cache_life_time),
                      ejabberd_config:cache_life_time(global)) of
                   infinity -> infinity;
                   I -> timer:seconds(I)
@@ -425,10 +422,7 @@ cache_opts() ->
     [{max_size, MaxSize}, {life_time, LifeTime}, {cache_missed, CacheMissed}].
 
 expire() ->
-    ejabberd_config:get_option(
-      oauth_expire,
-      fun(I) when is_integer(I) -> I end,
-      ?EXPIRE).
+    ejabberd_config:get_option(oauth_expire, ?EXPIRE).
 
 -define(DIV(Class, Els),
        ?XAE(<<"div">>, [{<<"class">>, Class}], Els)).
@@ -623,9 +617,8 @@ process(_Handlers, _Request) ->
 
 get_db_backend() ->
     DBType = ejabberd_config:get_option(
-               oauth_db_type,
-               fun(T) -> ejabberd_config:v_db(?MODULE, T) end,
-               mnesia),
+              oauth_db_type,
+              ejabberd_config:default_db(?MODULE)),
     list_to_atom("ejabberd_oauth_" ++ atom_to_list(DBType)).
 
 
index 15e118a0bccc99e6972d9b141f76f2daf9b833dd..6c5b3052315eab7da21c11f21ac6d52e616f98d8 100644 (file)
@@ -26,6 +26,8 @@
 
 -module(ejabberd_oauth_rest).
 
+-behaviour(ejabberd_config).
+
 -export([init/0,
          store/1,
          lookup/1,
@@ -87,9 +89,7 @@ clean(_TS) ->
     ok.
 
 path(Path) ->
-    Base = ejabberd_config:get_option(ext_api_path_oauth,
-                                      fun(X) -> iolist_to_binary(X) end,
-                                      <<"/oauth">>),
+    Base = ejabberd_config:get_option(ext_api_path_oauth, <<"/oauth">>),
     <<Base/binary, "/", Path/binary>>.
 
 
index 0f89e333ed38bba41f753ef231c3bf51ab7dbbda..7021c10b741b13645f0406d4159b484328fbfad5 100644 (file)
@@ -100,13 +100,7 @@ stop_host(Host) ->
 %% Returns {true, App} if we have configured sql for the given host
 needs_sql(Host) ->
     LHost = jid:nameprep(Host),
-    case ejabberd_config:get_option({sql_type, LHost},
-                                    fun(mysql) -> mysql;
-                                       (pgsql) -> pgsql;
-                                       (sqlite) -> sqlite;
-                                      (mssql) -> mssql;
-                                       (odbc) -> odbc
-                                    end, undefined) of
+    case ejabberd_config:get_option({sql_type, LHost}, undefined) of
         mysql -> {true, p1_mysql};
         pgsql -> {true, p1_pgsql};
         sqlite -> {true, sqlite3};
index 6152f7eb2d033b5cdf5b626519ca067348cb992b..38ad70eb33ca8ad7ca430966f21cd382bb35e292 100644 (file)
@@ -346,9 +346,7 @@ do_call(Pid, Msg) ->
     end.
 
 hibernate_timeout() ->
-    ejabberd_config:get_option(receiver_hibernate,
-                              opt_type(receiver_hibernate),
-                              timer:seconds(90)).
+    ejabberd_config:get_option(receiver_hibernate, timer:seconds(90)).
 
 opt_type(receiver_hibernate) ->
     fun(I) when is_integer(I), I>0 -> I;
index 7757c6df3599e42d78b7533c126fc8fcae983480..56948ec83432f2efa78552b11074efbdaccf6e53 100644 (file)
@@ -421,26 +421,13 @@ code_change(_OldVsn, State, _Extra) ->
 %%%===================================================================
 -spec connect(state()) -> {ok, pid()} | {error, any()}.
 connect(#state{num = Num}) ->
-    Server = ejabberd_config:get_option(redis_server,
-                                       fun iolist_to_list/1,
-                                       "localhost"),
-    Port = ejabberd_config:get_option(redis_port,
-                                     fun(P) when is_integer(P),
-                                                 P>0, P<65536 ->
-                                             P
-                                     end, 6379),
-    DB = ejabberd_config:get_option(redis_db,
-                                   fun(I) when is_integer(I), I >= 0 ->
-                                           I
-                                   end, 0),
-    Pass = ejabberd_config:get_option(redis_password,
-                                     fun iolist_to_list/1,
-                                     ""),
+    Server = ejabberd_config:get_option(redis_server, "localhost"),
+    Port = ejabberd_config:get_option(redis_port, 6379),
+    DB = ejabberd_config:get_option(redis_db, 0),
+    Pass = ejabberd_config:get_option(redis_password, ""),
     ConnTimeout = timer:seconds(
                    ejabberd_config:get_option(
-                     redis_connect_timeout,
-                     fun(I) when is_integer(I), I>0 -> I end,
-                     1)),
+                     redis_connect_timeout, 1)),
     try case do_connect(Num, Server, Port, Pass, DB, ConnTimeout) of
            {ok, Client} ->
                ?DEBUG("Connection #~p established to Redis at ~s:~p",
@@ -552,10 +539,6 @@ reply(Val) ->
        _ -> queued
     end.
 
--spec iolist_to_list(iodata()) -> string().
-iolist_to_list(IOList) ->
-    binary_to_list(iolist_to_binary(IOList)).
-
 -spec max_fsm_queue() -> pos_integer().
 max_fsm_queue() ->
     proplists:get_value(max_queue, fsm_limit_opts(), ?DEFAULT_MAX_QUEUE).
@@ -564,14 +547,9 @@ fsm_limit_opts() ->
     ejabberd_config:fsm_limit_opts([]).
 
 get_queue_type() ->
-    case ejabberd_config:get_option(
-          redis_queue_type,
-          ejabberd_redis_sup:opt_type(redis_queue_type)) of
-       undefined ->
-           ejabberd_config:default_queue_type(global);
-       Type ->
-           Type
-    end.
+    ejabberd_config:get_option(
+      redis_queue_type,
+      ejabberd_config:default_queue_type(global)).
 
 -spec flush_queue(p1_queue:queue()) -> p1_queue:queue().
 flush_queue(Q) ->
index da9fe37cf7440f0ba97c1279cc43cab97925520a..85cfd7abbe91239cbf1acce984298073be419b79 100644 (file)
@@ -108,15 +108,9 @@ is_redis_configured(Host) ->
     PoolSize = ejabberd_config:has_option({redis_pool_size, Host}),
     ConnTimeoutConfigured = ejabberd_config:has_option(
                              {redis_connect_timeout, Host}),
-    Modules = ejabberd_config:get_option(
-               {modules, Host},
-               fun(L) when is_list(L) -> L end, []),
-    SMConfigured = ejabberd_config:get_option(
-                    {sm_db_type, Host},
-                    fun(V) -> V end) == redis,
-    RouterConfigured = ejabberd_config:get_option(
-                        {router_db_type, Host},
-                        fun(V) -> V end) == redis,
+    Modules = ejabberd_config:get_option({modules, Host}, []),
+    SMConfigured = ejabberd_config:get_option({sm_db_type, Host}) == redis,
+    RouterConfigured = ejabberd_config:get_option({router_db_type, Host}) == redis,
     ModuleWithRedisDBConfigured =
        lists:any(
          fun({Module, Opts}) ->
@@ -134,10 +128,7 @@ get_specs() ->
       end, lists:seq(1, get_pool_size())).
 
 get_pool_size() ->
-    ejabberd_config:get_option(
-      redis_pool_size,
-      fun(N) when is_integer(N), N >= 1 -> N end,
-      ?DEFAULT_POOL_SIZE) + 1.
+    ejabberd_config:get_option(redis_pool_size, ?DEFAULT_POOL_SIZE) + 1.
 
 iolist_to_list(IOList) ->
     binary_to_list(iolist_to_binary(IOList)).
index ad7c8619c7a23f03bda68d1a2cded9f0968188cc..3d754f6d6e218e57d4d6ee45d58fba172d4b6b6b 100644 (file)
@@ -87,15 +87,9 @@ is_riak_configured(Host) ->
     AuthConfigured = lists:member(
                       ejabberd_auth_riak,
                       ejabberd_auth:auth_modules(Host)),
-    SMConfigured = ejabberd_config:get_option(
-                    {sm_db_type, Host},
-                    ejabberd_sm:opt_type(sm_db_type)) == riak,
-    RouterConfigured = ejabberd_config:get_option(
-                        {router_db_type, Host},
-                        ejabberd_router:opt_type(router_db_type)) == riak,
-    Modules = ejabberd_config:get_option(
-               {modules, Host},
-               fun(L) when is_list(L) -> L end, []),
+    SMConfigured = ejabberd_config:get_option({sm_db_type, Host}) == riak,
+    RouterConfigured = ejabberd_config:get_option({router_db_type, Host}) == riak,
+    Modules = ejabberd_config:get_option({modules, Host}, []),
     ModuleWithRiakDBConfigured = lists:any(
                                   fun({Module, Opts}) ->
                                           gen_mod:db_type(Host, Opts, Module) == riak
@@ -150,50 +144,25 @@ get_specs() ->
       end, lists:seq(1, PoolSize)).
 
 get_start_interval() ->
-    ejabberd_config:get_option(
-      riak_start_interval,
-      fun(N) when is_integer(N), N >= 1 -> N end,
-      ?DEFAULT_RIAK_START_INTERVAL).
+    ejabberd_config:get_option(riak_start_interval, ?DEFAULT_RIAK_START_INTERVAL).
 
 get_pool_size() ->
-    ejabberd_config:get_option(
-      riak_pool_size,
-      fun(N) when is_integer(N), N >= 1 -> N end,
-      ?DEFAULT_POOL_SIZE).
+    ejabberd_config:get_option(riak_pool_size, ?DEFAULT_POOL_SIZE).
 
 get_riak_server() ->
-    ejabberd_config:get_option(
-      riak_server,
-      fun(S) ->
-             binary_to_list(iolist_to_binary(S))
-      end, ?DEFAULT_RIAK_HOST).
+    ejabberd_config:get_option(riak_server, ?DEFAULT_RIAK_HOST).
 
 get_riak_cacertfile() ->
-    ejabberd_config:get_option(
-      riak_cacertfile,
-      fun(S) ->
-             binary_to_list(iolist_to_binary(S))
-      end, nil).
+    ejabberd_config:get_option(riak_cacertfile, nil).
 
 get_riak_username() ->
-    ejabberd_config:get_option(
-      riak_username,
-      fun(S) ->
-             binary_to_list(iolist_to_binary(S))
-      end, nil).
+    ejabberd_config:get_option(riak_username, nil).
 
 get_riak_password() ->
-    ejabberd_config:get_option(
-      riak_password,
-      fun(S) ->
-             binary_to_list(iolist_to_binary(S))
-      end, nil).
+    ejabberd_config:get_option(riak_password, nil).
 
 get_riak_port() ->
-    ejabberd_config:get_option(
-      riak_port,
-      fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
-      ?DEFAULT_RIAK_PORT).
+    ejabberd_config:get_option(riak_port, ?DEFAULT_RIAK_PORT).
 
 get_pids() ->
     [ejabberd_riak:get_proc(I) || I <- lists:seq(1, get_pool_size())].
@@ -212,13 +181,18 @@ transform_options(Opt, Opts) ->
 
 opt_type(riak_pool_size) ->
     fun (N) when is_integer(N), N >= 1 -> N end;
-opt_type(riak_port) -> fun (_) -> true end;
-opt_type(riak_server) -> fun (_) -> true end;
+opt_type(riak_port) ->
+    fun(P) when is_integer(P), P > 0, P < 65536 -> P end;
+opt_type(riak_server) ->
+    fun(S) -> binary_to_list(iolist_to_binary(S)) end;
 opt_type(riak_start_interval) ->
     fun (N) when is_integer(N), N >= 1 -> N end;
-opt_type(riak_cacertfile) -> fun iolist_to_binary/1;
-opt_type(riak_username) -> fun iolist_to_binary/1;
-opt_type(riak_password) -> fun iolist_to_binary/1;
+opt_type(riak_cacertfile) ->
+    fun(S) -> binary_to_list(iolist_to_binary(S)) end;
+opt_type(riak_username) ->
+    fun(S) -> binary_to_list(iolist_to_binary(S)) end;
+opt_type(riak_password) ->
+    fun(S) -> binary_to_list(iolist_to_binary(S)) end;
 opt_type(_) ->
     [riak_pool_size, riak_port, riak_server,
      riak_start_interval, riak_cacertfile, riak_username, riak_password].
index 5951cbeca606b968973757712381fb1313221f8a..490133d792b3f9143dc3f643b958eab673d418a5 100644 (file)
@@ -385,15 +385,11 @@ balancing_route(From, To, Packet, Rs) ->
 
 -spec get_component_number(binary()) -> pos_integer() | undefined.
 get_component_number(LDomain) ->
-    ejabberd_config:get_option(
-      {domain_balancing_component_number, LDomain},
-      fun(N) when is_integer(N), N > 1 -> N end,
-      undefined).
+    ejabberd_config:get_option({domain_balancing_component_number, LDomain}).
 
 -spec get_domain_balancing(jid(), jid(), binary()) -> any().
 get_domain_balancing(From, To, LDomain) ->
-    case ejabberd_config:get_option(
-          {domain_balancing, LDomain}, fun(D) when is_atom(D) -> D end) of
+    case ejabberd_config:get_option({domain_balancing, LDomain}) of
        undefined -> p1_time_compat:system_time();
        random -> p1_time_compat:system_time();
        source -> jid:tolower(From);
@@ -404,14 +400,9 @@ get_domain_balancing(From, To, LDomain) ->
 
 -spec get_backend() -> module().
 get_backend() ->
-    DBType = case ejabberd_config:get_option(
-                   router_db_type,
-                   fun(T) -> ejabberd_config:v_db(?MODULE, T) end) of
-                undefined ->
-                    ejabberd_config:default_ram_db(?MODULE);
-                T ->
-                    T
-            end,
+    DBType = ejabberd_config:get_option(
+              router_db_type,
+              ejabberd_config:default_ram_db(?MODULE)),
     list_to_atom("ejabberd_router_" ++ atom_to_list(DBType)).
 
 -spec cache_nodes(module()) -> [node()].
@@ -427,7 +418,7 @@ use_cache(Mod) ->
        true -> Mod:use_cache();
        false ->
            ejabberd_config:get_option(
-             router_use_cache, opt_type(router_use_cache),
+             router_use_cache,
              ejabberd_config:use_cache(global))
     end.
 
@@ -454,15 +445,12 @@ init_cache(Mod) ->
 cache_opts() ->
     MaxSize = ejabberd_config:get_option(
                router_cache_size,
-               opt_type(router_cache_size),
                ejabberd_config:cache_size(global)),
     CacheMissed = ejabberd_config:get_option(
                    router_cache_missed,
-                   opt_type(router_cache_missed),
                    ejabberd_config:cache_missed(global)),
     LifeTime = case ejabberd_config:get_option(
                      router_cache_life_time,
-                     opt_type(router_cache_life_time),
                      ejabberd_config:cache_life_time(global)) of
                   infinity -> infinity;
                   I -> timer:seconds(I)
index 674fd7c50aa5a71b6cd67439afdffd7adbb4adf2..b6685c12eb5eb3d032b6672ef926930bb18acd74 100644 (file)
@@ -200,45 +200,37 @@ dirty_get_connections() ->
 tls_options(LServer, DefaultOpts) ->
     TLSOpts1 = case ejabberd_config:get_option(
                      {s2s_certfile, LServer},
-                     fun iolist_to_binary/1,
                      ejabberd_config:get_option(
-                       {domain_certfile, LServer},
-                       fun iolist_to_binary/1)) of
+                       {domain_certfile, LServer})) of
                   undefined -> DefaultOpts;
                   CertFile -> lists:keystore(certfile, 1, DefaultOpts,
                                              {certfile, CertFile})
               end,
     TLSOpts2 = case ejabberd_config:get_option(
-                      {s2s_ciphers, LServer},
-                     fun iolist_to_binary/1) of
+                     {s2s_ciphers, LServer}) of
                    undefined -> TLSOpts1;
                    Ciphers -> lists:keystore(ciphers, 1, TLSOpts1,
                                             {ciphers, Ciphers})
                end,
     TLSOpts3 = case ejabberd_config:get_option(
-                      {s2s_protocol_options, LServer},
-                      fun (Options) -> str:join(Options, <<$|>>) end) of
+                      {s2s_protocol_options, LServer}) of
                    undefined -> TLSOpts2;
                    ProtoOpts -> lists:keystore(protocol_options, 1, TLSOpts2,
                                               {protocol_options, ProtoOpts})
                end,
     TLSOpts4 = case ejabberd_config:get_option(
-                      {s2s_dhfile, LServer},
-                     fun iolist_to_binary/1) of
+                     {s2s_dhfile, LServer}) of
                    undefined -> TLSOpts3;
                    DHFile -> lists:keystore(dhfile, 1, TLSOpts3,
                                            {dhfile, DHFile})
                end,
     TLSOpts5 = case ejabberd_config:get_option(
-                     {s2s_cafile, LServer},
-                     fun iolist_to_binary/1) of
+                     {s2s_cafile, LServer}) of
                   undefined -> TLSOpts4;
                   CAFile -> lists:keystore(cafile, 1, TLSOpts4,
                                            {cafile, CAFile})
               end,
-    case ejabberd_config:get_option(
-          {s2s_tls_compression, LServer},
-          fun(B) when is_boolean(B) -> B end) of
+    case ejabberd_config:get_option({s2s_tls_compression, LServer}) of
        undefined -> TLSOpts5;
        false -> [compression_none | TLSOpts5];
        true -> lists:delete(compression_none, TLSOpts5)
@@ -261,37 +253,21 @@ tls_enabled(LServer) ->
 
 -spec zlib_enabled(binary()) -> boolean().
 zlib_enabled(LServer) ->
-    ejabberd_config:get_option(
-      {s2s_zlib, LServer},
-      fun(B) when is_boolean(B) -> B end,
-      false).
+    ejabberd_config:get_option({s2s_zlib, LServer}, false).
 
 -spec use_starttls(binary()) -> boolean() | optional | required | required_trusted.
 use_starttls(LServer) ->
-    ejabberd_config:get_option(
-      {s2s_use_starttls, LServer},
-      fun(true) -> true;
-        (false) -> false;
-        (optional) -> optional;
-        (required) -> required;
-        (required_trusted) -> required_trusted
-      end, false).
+    ejabberd_config:get_option({s2s_use_starttls, LServer}, false).
 
 -spec get_idle_timeout(binary()) -> non_neg_integer() | infinity.
 get_idle_timeout(LServer) ->
-    ejabberd_config:get_option(
-      {s2s_timeout, LServer},
-      fun(I) when is_integer(I), I >= 0 -> timer:seconds(I);
-        (infinity) -> infinity
-      end, timer:minutes(10)).
+    ejabberd_config:get_option({s2s_timeout, LServer}, timer:minutes(10)).
 
 -spec queue_type(binary()) -> ram | file.
 queue_type(LServer) ->
-    case ejabberd_config:get_option(
-          {s2s_queue_type, LServer}, opt_type(s2s_queue_type)) of
-       undefined -> ejabberd_config:default_queue_type(LServer);
-       Type -> Type
-    end.
+    ejabberd_config:get_option(
+      {s2s_queue_type, LServer},
+      ejabberd_config:default_queue_type(LServer)).
 
 %%====================================================================
 %% gen_server callbacks
@@ -543,9 +519,7 @@ needed_connections_number(Ls, MaxS2SConnectionsNumber,
 -spec is_service(jid(), jid()) -> boolean().
 is_service(From, To) ->
     LFromDomain = From#jid.lserver,
-    case ejabberd_config:get_option(
-           {route_subdomains, LFromDomain},
-           fun(s2s) -> s2s; (local) -> local end, local) of
+    case ejabberd_config:get_option({route_subdomains, LFromDomain}, local) of
       s2s -> % bypass RFC 3920 10.3
          false;
       local ->
@@ -645,10 +619,7 @@ allow_host(MyServer, S2SHost) ->
       not is_temporarly_blocked(S2SHost).
 
 allow_host1(MyHost, S2SHost) ->
-    Rule = ejabberd_config:get_option(
-             {s2s_access, MyHost},
-             fun acl:access_rules_validator/1,
-             all),
+    Rule = ejabberd_config:get_option({s2s_access, MyHost}, all),
     JID = jid:make(S2SHost),
     case acl:match_rule(MyHost, Rule, JID) of
         deny -> false;
@@ -744,8 +715,9 @@ opt_type(s2s_use_starttls) ->
 opt_type(s2s_zlib) ->
     fun(B) when is_boolean(B) -> B end;
 opt_type(s2s_timeout) ->
-    fun(I) when is_integer(I), I>=0 -> I;
-       (infinity) -> infinity
+    fun(I) when is_integer(I), I >= 0 -> timer:seconds(I);
+       (infinity) -> infinity;
+       (unlimited) -> infinity
     end;
 opt_type(s2s_queue_type) ->
     fun(ram) -> ram; (file) -> file end;
index 3c9e1a1c9834e75744dd87e48aea0966935c1e44..deff3e5b569c5efa0565acfa518c75d3db6e7575 100644 (file)
@@ -191,42 +191,21 @@ tls_enabled(#{server := LServer}) ->
 connect_timeout(#{server := LServer}) ->
     ejabberd_config:get_option(
       {outgoing_s2s_timeout, LServer},
-      fun(TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
-              timer:seconds(TimeOut);
-         (infinity) ->
-              infinity
-      end, timer:seconds(10)).
+      timer:seconds(10)).
 
 default_port(#{server := LServer}) ->
-    ejabberd_config:get_option(
-      {outgoing_s2s_port, LServer},
-      fun(I) when is_integer(I), I > 0, I =< 65536 -> I end,
-      5269).
+    ejabberd_config:get_option({outgoing_s2s_port, LServer}, 5269).
 
 address_families(#{server := LServer}) ->
     ejabberd_config:get_option(
       {outgoing_s2s_families, LServer},
-      fun(Families) ->
-             lists:map(
-               fun(ipv4) -> inet;
-                  (ipv6) -> inet6
-               end, Families)
-      end, [inet, inet6]).
+      [inet, inet6]).
 
 dns_retries(#{server := LServer}) ->
-    ejabberd_config:get_option(
-      {s2s_dns_retries, LServer},
-      fun(I) when is_integer(I), I>=0 -> I end,
-      2).
+    ejabberd_config:get_option({s2s_dns_retries, LServer}, 2).
 
 dns_timeout(#{server := LServer}) ->
-    ejabberd_config:get_option(
-      {s2s_dns_timeout, LServer},
-      fun(I) when is_integer(I), I>=0 ->
-             timer:seconds(I);
-        (infinity) ->
-             infinity
-      end, timer:seconds(10)).
+    ejabberd_config:get_option({s2s_dns_timeout, LServer}, timer:seconds(10)).
 
 handle_auth_success(Mech, #{sockmod := SockMod,
                            socket := Socket, ip := IP,
@@ -391,10 +370,7 @@ mk_bounce_error(_Lang, _State) ->
 
 -spec get_delay() -> non_neg_integer().
 get_delay() ->
-    MaxDelay = ejabberd_config:get_option(
-                s2s_max_retry_delay,
-                fun(I) when is_integer(I), I > 0 -> I end,
-                300),
+    MaxDelay = ejabberd_config:get_option(s2s_max_retry_delay, 300),
     crypto:rand_uniform(1, MaxDelay).
 
 -spec set_idle_timeout(state()) -> state().
@@ -464,26 +440,28 @@ maybe_report_huge_timeout(_, _) ->
     ok.
 
 opt_type(outgoing_s2s_families) ->
-    fun (Families) ->
-           true = lists:all(fun (ipv4) -> true;
-                                (ipv6) -> true
-                            end,
-                            Families),
-           Families
+    fun(Families) ->
+           lists:map(
+             fun(ipv4) -> inet;
+                (ipv6) -> inet6
+             end, Families)
     end;
 opt_type(outgoing_s2s_port) ->
     fun (I) when is_integer(I), I > 0, I =< 65536 -> I end;
 opt_type(outgoing_s2s_timeout) ->
-    fun (TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
-           TimeOut;
-       (infinity) -> infinity
+    fun(TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
+           timer:seconds(TimeOut);
+       (unlimited) ->
+           infinity;
+       (infinity) ->
+           infinity
     end;
 opt_type(s2s_dns_retries) ->
     fun (I) when is_integer(I), I >= 0 -> I end;
 opt_type(s2s_dns_timeout) ->
-    fun (TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
-           TimeOut;
-       (infinity) -> infinity
+    fun(I) when is_integer(I), I>=0 -> timer:seconds(I);
+       (infinity) -> infinity;
+       (unlimited) -> infinity
     end;
 opt_type(s2s_max_retry_delay) ->
     fun (I) when is_integer(I), I > 0 -> I end;
index 20614a58d61c574ea5623fcf7c884bb4fbe40764..ce2abfff0620b0fd2806537fe727e4e1abdbc6a0 100644 (file)
@@ -865,14 +865,9 @@ force_update_presence({LUser, LServer}) ->
 -spec get_sm_backend(binary()) -> module().
 
 get_sm_backend(Host) ->
-    DBType = case ejabberd_config:get_option(
+    DBType = ejabberd_config:get_option(
               {sm_db_type, Host},
-                   fun(T) -> ejabberd_config:v_db(?MODULE, T) end) of
-                undefined ->
-                    ejabberd_config:default_ram_db(Host, ?MODULE);
-                T ->
-                    T
-            end,
+              ejabberd_config:default_ram_db(Host, ?MODULE)),
     list_to_atom("ejabberd_sm_" ++ atom_to_list(DBType)).
 
 -spec get_sm_backends() -> [module()].
@@ -904,15 +899,12 @@ init_cache() ->
 cache_opts() ->
     MaxSize = ejabberd_config:get_option(
                sm_cache_size,
-               opt_type(sm_cache_size),
                ejabberd_config:cache_size(global)),
     CacheMissed = ejabberd_config:get_option(
                    sm_cache_missed,
-                   opt_type(sm_cache_missed),
                    ejabberd_config:cache_missed(global)),
     LifeTime = case ejabberd_config:get_option(
                      sm_cache_life_time,
-                     opt_type(sm_cache_life_time),
                      ejabberd_config:cache_life_time(global)) of
                   infinity -> infinity;
                   I -> timer:seconds(I)
@@ -943,7 +935,6 @@ use_cache(Mod, LServer) ->
        false ->
            ejabberd_config:get_option(
              {sm_use_cache, LServer},
-             ejabberd_sm:opt_type(sm_use_cache),
              ejabberd_config:use_cache(LServer))
     end.
 
index 93cfa0288bb48c884c491f9cc76bf57269eaff12..0dddcb03e7db046b0b87e69a0ef9be26dce144a3 100644 (file)
@@ -252,8 +252,7 @@ sqlite_db(Host) ->
 
 -spec sqlite_file(binary()) -> string().
 sqlite_file(Host) ->
-    case ejabberd_config:get_option({sql_database, Host},
-                                   fun iolist_to_binary/1) of
+    case ejabberd_config:get_option({sql_database, Host}) of
        undefined ->
            {ok, Cwd} = file:get_cwd(),
            filename:join([Cwd, "sqlite", atom_to_list(node()),
@@ -266,9 +265,7 @@ sqlite_file(Host) ->
 %%% Callback functions from gen_fsm
 %%%----------------------------------------------------------------------
 init([Host, StartInterval]) ->
-    case ejabberd_config:get_option(
-           {sql_keepalive_interval, Host},
-           fun(I) when is_integer(I), I>0 -> I end) of
+    case ejabberd_config:get_option({sql_keepalive_interval, Host}) of
         undefined ->
             ok;
         KeepaliveInterval ->
@@ -278,8 +275,7 @@ init([Host, StartInterval]) ->
     [DBType | _] = db_opts(Host),
     (?GEN_FSM):send_event(self(), connect),
     ejabberd_sql_sup:add_pid(Host, self()),
-    QueueType = case ejabberd_config:get_option(
-                      {sql_queue_type, Host}, opt_type(sql_queue_type)) of
+    QueueType = case ejabberd_config:get_option({sql_queue_type, Host}) of
                    undefined ->
                        ejabberd_config:default_queue_type(Host);
                    Type ->
@@ -927,20 +923,9 @@ log(Level, Format, Args) ->
     end.
 
 db_opts(Host) ->
-    Type = ejabberd_config:get_option({sql_type, Host},
-                                      fun(mysql) -> mysql;
-                                         (pgsql) -> pgsql;
-                                         (sqlite) -> sqlite;
-                                        (mssql) -> mssql;
-                                         (odbc) -> odbc
-                                      end, odbc),
-    Server = ejabberd_config:get_option({sql_server, Host},
-                                        fun iolist_to_binary/1,
-                                        <<"localhost">>),
-    Transport = case ejabberd_config:get_option(
-                      {sql_ssl, Host},
-                      fun(B) when is_boolean(B) -> B end,
-                      false) of
+    Type = ejabberd_config:get_option({sql_type, Host}, odbc),
+    Server = ejabberd_config:get_option({sql_server, Host}, <<"localhost">>),
+    Transport = case ejabberd_config:get_option({sql_ssl, Host}, false) of
                    false -> tcp;
                    true -> ssl
                end,
@@ -953,20 +938,16 @@ db_opts(Host) ->
         _ ->
             Port = ejabberd_config:get_option(
                      {sql_port, Host},
-                     fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
                      case Type of
                         mssql -> ?MSSQL_PORT;
                          mysql -> ?MYSQL_PORT;
                          pgsql -> ?PGSQL_PORT
                      end),
             DB = ejabberd_config:get_option({sql_database, Host},
-                                            fun iolist_to_binary/1,
                                             <<"ejabberd">>),
             User = ejabberd_config:get_option({sql_username, Host},
-                                              fun iolist_to_binary/1,
                                               <<"ejabberd">>),
             Pass = ejabberd_config:get_option({sql_password, Host},
-                                              fun iolist_to_binary/1,
                                               <<"">>),
            SSLOpts = get_ssl_opts(Transport, Host),
            case Type of
@@ -986,19 +967,15 @@ warn_if_ssl_unsupported(ssl, Type) ->
     ?WARNING_MSG("SSL connection is not supported for ~s", [Type]).
 
 get_ssl_opts(ssl, Host) ->
-    Opts1 = case ejabberd_config:get_option({sql_ssl_certfile, Host},
-                                           fun iolist_to_binary/1) of
+    Opts1 = case ejabberd_config:get_option({sql_ssl_certfile, Host}) of
                undefined -> [];
                CertFile -> [{certfile, CertFile}]
            end,
-    Opts2 = case ejabberd_config:get_option({sql_ssl_cafile, Host},
-                                           fun iolist_to_binary/1) of
+    Opts2 = case ejabberd_config:get_option({sql_ssl_cafile, Host}) of
                undefined -> Opts1;
                CAFile -> [{cacertfile, CAFile}|Opts1]
            end,
-    case ejabberd_config:get_option({sql_ssl_verify, Host},
-                                   fun(B) when is_boolean(B) -> B end,
-                                   false) of
+    case ejabberd_config:get_option({sql_ssl_verify, Host}, false) of
        true ->
            case lists:keymember(cacertfile, 1, Opts2) of
                true ->
@@ -1017,16 +994,9 @@ get_ssl_opts(tcp, _) ->
     [].
 
 init_mssql(Host) ->
-    Server = ejabberd_config:get_option({sql_server, Host},
-                                        fun iolist_to_binary/1,
-                                        <<"localhost">>),
-    Port = ejabberd_config:get_option(
-            {sql_port, Host},
-            fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
-            ?MSSQL_PORT),
-    DB = ejabberd_config:get_option({sql_database, Host},
-                                   fun iolist_to_binary/1,
-                                   <<"ejabberd">>),
+    Server = ejabberd_config:get_option({sql_server, Host}, <<"localhost">>),
+    Port = ejabberd_config:get_option({sql_port, Host}, ?MSSQL_PORT),
+    DB = ejabberd_config:get_option({sql_database, Host}, <<"ejabberd">>),
     FreeTDS = io_lib:fwrite("[~s]~n"
                            "\thost = ~s~n"
                            "\tport = ~p~n"
index 59360a9f93ca229bce4d87aa29d81f34a8d3090a..7526aedbe4152f9607d9c56ecf0bdd58346be0d4 100644 (file)
@@ -62,15 +62,8 @@ start_link(Host) ->
 init([Host]) ->
     StartInterval = ejabberd_config:get_option(
                       {sql_start_interval, Host},
-                      fun(I) when is_integer(I), I>0 -> I end,
                       ?DEFAULT_SQL_START_INTERVAL),
-    Type = ejabberd_config:get_option({sql_type, Host},
-                                      fun(mysql) -> mysql;
-                                         (pgsql) -> pgsql;
-                                         (sqlite) -> sqlite;
-                                        (mssql) -> mssql;
-                                         (odbc) -> odbc
-                                      end, odbc),
+    Type = ejabberd_config:get_option({sql_type, Host}, odbc),
     PoolSize = get_pool_size(Type, Host),
     case Type of
         sqlite ->
@@ -119,7 +112,6 @@ remove_pid(Host, Pid) ->
 get_pool_size(SQLType, Host) ->
     PoolSize = ejabberd_config:get_option(
                  {sql_pool_size, Host},
-                 fun(I) when is_integer(I), I>0 -> I end,
                 case SQLType of
                     sqlite -> 1;
                     _ -> ?DEFAULT_POOL_SIZE
index e5b924c1e8d9dd815293a5161514b6cf389cc46b..881bfa635967ca73a5e4dc34ce5abdd3a2bacc6a 100644 (file)
 %% Description: Starts the server
 %%--------------------------------------------------------------------
 start_link() ->
-    LH = ejabberd_config:get_option(
-           watchdog_large_heap,
-           fun(I) when is_integer(I), I > 0 -> I end,
-          1000000),
+    LH = ejabberd_config:get_option(watchdog_large_heap, 1000000),
     Opts = [{large_heap, LH}],
     gen_server:start_link({local, ?MODULE}, ?MODULE, Opts,
                          []).
@@ -205,13 +202,7 @@ send_message(From, To, Body, ExtraEls) ->
                                   sub_els = ExtraEls}).
 
 get_admin_jids() ->
-    ejabberd_config:get_option(
-      watchdog_admins,
-      fun(JIDs) ->
-              [jid:tolower(
-                 jid:decode(
-                   iolist_to_binary(S))) || S <- JIDs]
-      end, []).
+    ejabberd_config:get_option(watchdog_admins, []).
 
 detailed_info(Pid) ->
     case process_info(Pid, dictionary) of
index 5547ab783352c6752cf056a15402ec8d8f7d56f1..57b679a2e92d751fb4be965f343e193929438887 100644 (file)
@@ -920,12 +920,7 @@ process_admin(Host,
                end;
            _ -> nothing
          end,
-    Rules = case ejabberd_config:get_option(
-                   {access, Name, Host}, fun(V) -> V end)
-               of
-             undefined -> [];
-             Rs1 -> Rs1
-           end,
+    Rules = ejabberd_config:get_option({access, Name, Host}, []),
     make_xhtml([?XC(<<"h1">>,
                    (str:format(
                                      ?T(<<"~s access rule configuration">>),
index 6ca218c2ade1ba3ca8f567437b35895449affbc0..15fe8e17f32182c01c12e9ed052cc0229b6726d1 100644 (file)
@@ -439,11 +439,7 @@ short_spec({Module, Attrs}) when is_atom(Module), is_list(Attrs) ->
     {Module, proplists:get_value(summary, Attrs, "")}.
 
 is_contrib_allowed() ->
-    ejabberd_config:get_option(allow_contrib_modules,
-               fun(false) -> false;
-                  (no) -> false;
-                  (_) -> true
-            end, true).
+    ejabberd_config:get_option(allow_contrib_modules, true).
 
 %% -- build functions
 
index 6ec7e77604daf350e0347979783d436fab90a3b8..c6f25102cbcb7cae16edd7e4dfcc91545b5cdd02 100644 (file)
@@ -105,11 +105,7 @@ random_instance(MaxNum) ->
     randoms:uniform(MaxNum) - 1.
 
 get_instances(Server) ->
-    ejabberd_config:get_option(
-      {extauth_instances, Server},
-      fun(V) when is_integer(V), V > 0 ->
-              V
-      end, 1).
+    ejabberd_config:get_option({extauth_instances, Server}, 1).
 
 loop(Port, Timeout, ProcessName, ExtPrg) ->
     receive
index 4b845a386204753d4012931a96630ef6a2db0610..c39b5153cf90d2233bde3b2d44ee7fd7dcace122 100644 (file)
@@ -119,14 +119,7 @@ start_modules() ->
        end, ?MYHOSTS).
 
 get_modules_options(Host) ->
-    ejabberd_config:get_option(
-      {modules, Host},
-      fun(Mods) ->
-             lists:map(
-               fun({M, A}) when is_atom(M), is_list(A) ->
-                       {M, A}
-               end, Mods)
-      end, []).
+    ejabberd_config:get_option({modules, Host}, []).
 
 sort_modules(Host, ModOpts) ->
     G = digraph:new([acyclic]),
@@ -211,8 +204,7 @@ start_module(Host, Module, Opts0) ->
 
 -spec reload_modules(binary()) -> ok.
 reload_modules(Host) ->
-    NewMods = ejabberd_config:get_option(
-               {modules, Host}, opt_type(modules), []),
+    NewMods = ejabberd_config:get_option({modules, Host}, []),
     OldMods = ets:select(
                ejabberd_modules,
                ets:fun2ms(
@@ -369,7 +361,7 @@ get_opt(Opt, Opts, F) ->
 get_opt({Opt, Host}, Opts, F, Default) ->
     case lists:keysearch(Opt, 1, Opts) of
         false ->
-            ejabberd_config:get_option({Opt, Host}, F, Default);
+            ejabberd_config:get_option({Opt, Host}, Default);
         {value, {_, Val}} ->
             ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
     end;
index fd216f936455fdf05d7ae90cd3a76a0070edfa1a..da16200ece37565077e0b14d503c8b7d885c989f 100644 (file)
@@ -119,9 +119,7 @@ process_local_iq(#iq{type = get} = IQ) ->
 %% @doc Get the uptime of the ejabberd node, expressed in seconds.
 %% When ejabberd is starting, ejabberd_config:start/0 stores the datetime.
 get_node_uptime() ->
-    case ejabberd_config:get_option(
-           node_start,
-           fun(S) when is_integer(S), S >= 0 -> S end) of
+    case ejabberd_config:get_option(node_start) of
         undefined ->
             trunc(element(1, erlang:statistics(wall_clock)) / 1000);
         Now ->
index 93bf2f2f2139264d85ad9adaeb3ac3d1876a5987..d2fd48a9fff6c80543aced38c0ccb7aaf671639a 100644 (file)
@@ -200,9 +200,7 @@ make_sql_query(User, LServer, MAMQuery, RSM) ->
     With = proplists:get_value(with, MAMQuery),
     WithText = proplists:get_value(withtext, MAMQuery),
     {Max, Direction, ID} = get_max_direction_id(RSM),
-    ODBCType = ejabberd_config:get_option(
-                {sql_type, LServer},
-                ejabberd_sql:opt_type(sql_type)),
+    ODBCType = ejabberd_config:get_option({sql_type, LServer}),
     Escape =
         case ODBCType of
             mssql -> fun ejabberd_sql:standard_escape/1;
index e15165f7792c0c1bdf24e9561adb5adbc79b391f..63f7708b1f753da56355a754321efe8d53cc463f 100644 (file)
@@ -435,15 +435,7 @@ check_from(JID, Server) ->
 
 check_timeout(undefined) -> true;
 check_timeout(Source) ->
-    Timeout = ejabberd_config:get_option(
-                registration_timeout,
-                fun(TO) when is_integer(TO), TO > 0 ->
-                        TO;
-                   (infinity) ->
-                        infinity;
-                   (unlimited) ->
-                        infinity
-                end, 600),
+    Timeout = ejabberd_config:get_option(registration_timeout, 600),
     if is_integer(Timeout) ->
           Priority = -p1_time_compat:system_time(seconds),
           CleanPriority = Priority + Timeout,
@@ -488,15 +480,7 @@ clean_treap(Treap, CleanPriority) ->
 
 remove_timeout(undefined) -> true;
 remove_timeout(Source) ->
-    Timeout = ejabberd_config:get_option(
-                registration_timeout,
-                fun(TO) when is_integer(TO), TO > 0 ->
-                        TO;
-                   (infinity) ->
-                        infinity;
-                   (unlimited) ->
-                        infinity
-                end, 600),
+    Timeout = ejabberd_config:get_option(registration_timeout, 600),
     if is_integer(Timeout) ->
           F = fun () ->
                       Treap = case mnesia:read(mod_register_ip, treap, write)
index 00730f327897f58aeec51f104be2f3a3d7e1dff1..ab33597a5c3921239774794edc14e424716efe0d 100644 (file)
@@ -265,7 +265,7 @@ s2s_out_packet(State, _) ->
 %%%===================================================================
 -spec make_key(binary(), binary(), binary()) -> binary().
 make_key(From, To, StreamID) ->
-    Secret = ejabberd_config:get_option(shared_key, fun(V) -> V end),
+    Secret = ejabberd_config:get_option(shared_key),
     str:to_hexlist(
       crypto:hmac(sha256, str:to_hexlist(crypto:hash(sha256, Secret)),
                  [To, " ", From, " ", StreamID])).
index b3ac825392422b5eb9949c924ab07a76123daec2..3042099d58da2d565840f771142031afc2cc597f 100644 (file)
@@ -267,8 +267,7 @@ cancel_pending_transactions(State) ->
     lists:foreach(fun esip:cancel/1, State#state.tr_ids).
 
 add_certfile(LServer, Opts) ->
-    case ejabberd_config:get_option({domain_certfile, LServer},
-                                   fun iolist_to_binary/1) of
+    case ejabberd_config:get_option({domain_certfile, LServer}) of
        CertFile when is_binary(CertFile), CertFile /= <<"">> ->
            [{certfile, CertFile}|Opts];
        _ ->
@@ -329,7 +328,7 @@ make_sign(TS, Hdrs) ->
     LTServer = safe_nameprep(TServer),
     FromTag = esip:get_param(<<"tag">>, FParams),
     CallID = esip:get_hdr('call-id', Hdrs),
-    SharedKey = ejabberd_config:get_option(shared_key, fun(V) -> V end),
+    SharedKey = ejabberd_config:get_option(shared_key),
     str:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
                FromTag, CallID, TS]).
 
index 34e72a67464ad14e76b983077171fd84aefab1c3..a3fb0eef23b3c3c40caa6732b6c26a0e175c5eb9 100644 (file)
 
 start(Host) ->
     p1_http:start(),
-    Pool_size =
-       ejabberd_config:get_option({ext_api_http_pool_size, Host},
-                                  fun(X) when is_integer(X), X > 0->
-                                          X
-                                  end,
-                                  100),
+    Pool_size = ejabberd_config:get_option({ext_api_http_pool_size, Host}, 100),
     p1_http:set_pool_size(Pool_size).
 
 stop(_Host) ->
@@ -167,9 +162,6 @@ base_url(Server, Path) ->
         <<"http", _Url/binary>> -> Tail;
         _ ->
             Base = ejabberd_config:get_option({ext_api_url, Server},
-                                              fun(X) ->
-                                                     iolist_to_binary(X)
-                                             end,
                                               <<"http://localhost/api">>),
             <<Base/binary, "/", Tail/binary>>
     end.
index b4db645867228a1c8772988264e2d8fa37d640f3..ac1ecc36f6f1348f42dde85135b8ece0a87b214d 100644 (file)
@@ -85,8 +85,7 @@ code_change(_OldVsn, State, _Extra) ->
 -spec load_from_config() -> ok | {error, any()}.
 
 load_from_config() ->
-    Shapers = ejabberd_config:get_option(
-                shaper, fun(V) -> V end, []),
+    Shapers = ejabberd_config:get_option(shaper, []),
     case mnesia:transaction(
            fun() ->
                    lists:foreach(
index 813f5d695146bc432fc524fa2bc335632cad772f..5d57291029491bbb227e3db7c1b8d2c306f250db 100644 (file)
@@ -246,9 +246,7 @@ users_number(LServer) ->
       fun(pgsql, _) ->
               case
                   ejabberd_config:get_option(
-                    {pgsql_users_number_estimate, LServer},
-                    fun(V) when is_boolean(V) -> V end,
-                    false) of
+                    {pgsql_users_number_estimate, LServer}, false) of
                   true ->
                       ejabberd_sql:sql_query_t(
                         ?SQL("select @(reltuples :: bigint)d from pg_class"