From 01a2c9fe1202f88f20a5acbc729b627ce0ac3c0a Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Mon, 8 May 2017 12:59:28 +0300 Subject: [PATCH] Add type specs for Module:opt_type/1 --- src/cyrsasl_digest.erl | 2 ++ src/ejabberd_app.erl | 3 +++ src/ejabberd_auth.erl | 3 +++ src/ejabberd_auth_anonymous.erl | 4 ++++ src/ejabberd_auth_external.erl | 4 ++++ src/ejabberd_auth_ldap.erl | 4 ++++ src/ejabberd_auth_pam.erl | 3 +++ src/ejabberd_c2s.erl | 29 ++++++++++++++++++++++++++++- src/ejabberd_captcha.erl | 4 ++++ src/ejabberd_commands.erl | 3 +++ src/ejabberd_config.erl | 17 +++++++++++++++++ src/ejabberd_ctl.erl | 2 ++ src/ejabberd_http.erl | 19 +++++++++++++++++++ src/ejabberd_oauth.erl | 8 ++++++++ src/ejabberd_oauth_rest.erl | 2 ++ src/ejabberd_rdbms.erl | 3 +++ src/ejabberd_receiver.erl | 3 +++ src/ejabberd_redis_sup.erl | 8 ++++++++ src/ejabberd_riak_sup.erl | 8 ++++++++ src/ejabberd_router.erl | 10 ++++++++++ src/ejabberd_s2s.erl | 14 ++++++++++++++ src/ejabberd_s2s_in.erl | 22 +++++++++++++++------- src/ejabberd_s2s_out.erl | 9 ++++++++- src/ejabberd_service.erl | 23 ++++++++++++++++++----- src/ejabberd_sm.erl | 6 ++++++ src/ejabberd_sql.erl | 14 ++++++++++++++ src/ejabberd_sql_sup.erl | 3 +++ src/ejabberd_system_monitor.erl | 3 +++ src/ejabberd_web_admin.erl | 2 ++ src/eldap_utils.erl | 23 ++++++++++++++++++----- src/ext_mod.erl | 2 ++ src/extauth.erl | 2 ++ src/gen_iq_handler.erl | 2 ++ src/gen_mod.erl | 2 ++ src/mod_metrics.erl | 6 +----- src/mod_register.erl | 2 ++ src/mod_vcard_ldap.erl | 11 +---------- src/rest.erl | 3 +++ src/shaper.erl | 2 ++ src/sql_queries.erl | 2 ++ 40 files changed, 258 insertions(+), 34 deletions(-) diff --git a/src/cyrsasl_digest.erl b/src/cyrsasl_digest.erl index 9d23271d1..5bce53a02 100644 --- a/src/cyrsasl_digest.erl +++ b/src/cyrsasl_digest.erl @@ -260,6 +260,8 @@ response(KeyVals, User, Passwd, Nonce, AuthzId, ":", (hex((erlang:md5(A2))))/binary>>, hex((erlang:md5(T))). +-spec opt_type(fqdn) -> fun((binary() | [binary()]) -> [binary()]); + (atom()) -> [atom()]. opt_type(fqdn) -> fun(FQDN) when is_binary(FQDN) -> [FQDN]; diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl index b23249aa0..b52450d24 100644 --- a/src/ejabberd_app.erl +++ b/src/ejabberd_app.erl @@ -160,6 +160,9 @@ start_apps() -> ejabberd:start_app(xmpp), ejabberd:start_app(cache_tab). +-spec opt_type(net_ticktime) -> fun((pos_integer()) -> pos_integer()); + (cluster_nodes) -> fun(([node()]) -> [node()]); + (atom()) -> atom(). opt_type(net_ticktime) -> fun (P) when is_integer(P), P > 0 -> P end; opt_type(cluster_nodes) -> diff --git a/src/ejabberd_auth.erl b/src/ejabberd_auth.erl index 756fafcf6..9751142a5 100644 --- a/src/ejabberd_auth.erl +++ b/src/ejabberd_auth.erl @@ -534,6 +534,9 @@ import(Server, {sql, _}, riak, <<"users">>, Fields) -> import(_LServer, {sql, _}, sql, <<"users">>, _) -> ok. +-spec opt_type(auth_method) -> fun((atom() | [atom()]) -> [atom()]); + (auth_password_format) -> fun((plain | scram) -> plain | scram); + (atom()) -> [atom()]. opt_type(auth_method) -> fun (V) when is_list(V) -> lists:map(fun(M) -> ejabberd_config:v_db(?MODULE, M) end, V); diff --git a/src/ejabberd_auth_anonymous.erl b/src/ejabberd_auth_anonymous.erl index a75af709e..5bb2daed7 100644 --- a/src/ejabberd_auth_anonymous.erl +++ b/src/ejabberd_auth_anonymous.erl @@ -236,6 +236,10 @@ plain_password_required() -> false. store_type() -> plain. +-spec opt_type(allow_multiple_connection) -> fun((boolean()) -> boolean()); + (anonymous_protocol) -> fun((sasl_anon | login_anon | both) -> + sasl_anon | login_anon | both); + (atom()) -> [atom()]. opt_type(allow_multiple_connections) -> fun (V) when is_boolean(V) -> V end; opt_type(anonymous_protocol) -> diff --git a/src/ejabberd_auth_external.erl b/src/ejabberd_auth_external.erl index 8ba2e2b22..5bdd704a0 100644 --- a/src/ejabberd_auth_external.erl +++ b/src/ejabberd_auth_external.erl @@ -313,6 +313,10 @@ is_configured(Host, Module) -> Os = ejabberd_config:get_option({modules, Host}, []), lists:keymember(Module, 1, Os). +-spec opt_type(extauth_cache) -> fun((false | non_neg_integer()) -> + false | non_neg_integer()); + (extauth_program) -> fun((binary()) -> string()); + (atom()) -> [atom()]. opt_type(extauth_cache) -> fun (false) -> false; (I) when is_integer(I), I >= 0 -> I diff --git a/src/ejabberd_auth_ldap.erl b/src/ejabberd_auth_ldap.erl index 53c256490..8a4532e38 100644 --- a/src/ejabberd_auth_ldap.erl +++ b/src/ejabberd_auth_ldap.erl @@ -393,6 +393,10 @@ parse_options(Host) -> sfilter = SearchFilter, lfilter = LocalFilter, dn_filter = DNFilter, dn_filter_attrs = DNFilterAttrs}. +-spec opt_type(ldap_dn_filter) -> fun(([{binary(), binary()}]) -> + [{binary(), binary()}]); + (ldap_local_filter) -> fun((any()) -> any()); + (atom()) -> [atom()]. opt_type(ldap_dn_filter) -> fun ([{DNF, DNFA}]) -> NewDNFA = case DNFA of diff --git a/src/ejabberd_auth_pam.erl b/src/ejabberd_auth_pam.erl index 974cc8e43..9d2fc819b 100644 --- a/src/ejabberd_auth_pam.erl +++ b/src/ejabberd_auth_pam.erl @@ -117,6 +117,9 @@ get_pam_service(Host) -> get_pam_userinfotype(Host) -> ejabberd_config:get_option({pam_userinfotype, Host}, username). +-spec opt_type(pam_service) -> fun((binary()) -> binary()); + (pam_userinfotype) -> fun((username | jid) -> username | jid); + (atom()) -> [atom()]. opt_type(pam_service) -> fun iolist_to_binary/1; opt_type(pam_userinfotype) -> fun (username) -> username; diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index fae75a4d2..9af58a080 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -894,6 +894,16 @@ format_reason(_, _) -> transform_listen_option(Opt, Opts) -> [Opt|Opts]. +-type resource_conflict() :: setresource | closeold | closenew | acceptnew. +-spec opt_type(c2s_certfile) -> fun((binary()) -> binary()); + (c2s_ciphers) -> fun((binary()) -> binary()); + (c2s_dhfile) -> fun((binary()) -> binary()); + (c2s_cafile) -> fun((binary()) -> binary()); + (c2s_protocol_options) -> fun(([binary()]) -> binary()); + (c2s_tls_compression) -> fun((boolean()) -> boolean()); + (resource_conflict) -> fun((resource_conflict()) -> resource_conflict()); + (disable_sasl_mechanisms) -> fun((binary() | [binary()]) -> [binary()]); + (atom()) -> [atom()]. opt_type(c2s_certfile) -> fun iolist_to_binary/1; opt_type(c2s_ciphers) -> fun iolist_to_binary/1; opt_type(c2s_dhfile) -> fun iolist_to_binary/1; @@ -920,6 +930,23 @@ opt_type(_) -> c2s_protocol_options, c2s_tls_compression, resource_conflict, disable_sasl_mechanisms]. +-spec listen_opt_type(access) -> fun((any()) -> any()); + (shaper) -> fun((any()) -> any()); + (certfile) -> fun((binary()) -> binary()); + (ciphers) -> fun((binary()) -> binary()); + (dhfile) -> fun((binary()) -> binary()); + (cafile) -> fun((binary()) -> binary()); + (protocol_options) -> fun(([binary()]) -> binary()); + (tls_compression) -> fun((boolean()) -> boolean()); + (tls) -> fun((boolean()) -> boolean()); + (starttls) -> fun((boolean()) -> boolean()); + (tls_verify) -> fun((boolean()) -> boolean()); + (zlib) -> fun((boolean()) -> boolean()); + (supervisor) -> fun((boolean()) -> boolean()); + (max_stanza_size) -> fun((timeout()) -> timeout()); + (max_fsm_queue) -> fun((timeout()) -> timeout()); + (stream_management) -> fun((boolean()) -> boolean()); + (atom()) -> [atom()]. listen_opt_type(access) -> fun acl:access_rules_validator/1; listen_opt_type(shaper) -> fun acl:shaper_rules_validator/1; listen_opt_type(certfile) -> opt_type(c2s_certfile); @@ -935,7 +962,7 @@ listen_opt_type(tls_verify) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(zlib) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(supervisor) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(max_stanza_size) -> - fun(I) when is_integer(I) -> I; + fun(I) when is_integer(I), I>0 -> I; (unlimited) -> infinity; (infinity) -> infinity end; diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl index 0a8dc0261..48e4ac1e6 100644 --- a/src/ejabberd_captcha.erl +++ b/src/ejabberd_captcha.erl @@ -528,6 +528,10 @@ clean_treap(Treap, CleanPriority) -> now_priority() -> -p1_time_compat:system_time(micro_seconds). +-spec opt_type(captcha_cmd) -> fun((binary()) -> binary()); + (captcha_host) -> fun((binary()) -> binary()); + (captcha_limit) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. opt_type(captcha_cmd) -> fun (FileName) -> F = iolist_to_binary(FileName), if F /= <<"">> -> F end diff --git a/src/ejabberd_commands.erl b/src/ejabberd_commands.erl index c8822032c..eccb0d621 100644 --- a/src/ejabberd_commands.erl +++ b/src/ejabberd_commands.erl @@ -891,6 +891,9 @@ permission_addon() -> [{access, ejabberd_config:get_option(commands_admin_access, none)}], {get_exposed_commands(), []}}}]. +-spec opt_type(commands_admin_access) -> fun((any()) -> any()); + (commands) -> fun((list()) -> list()); + (atom()) -> [atom()]. opt_type(commands_admin_access) -> fun acl:access_rules_validator/1; opt_type(commands) -> fun(V) when is_list(V) -> V end; diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index 1ad76caf7..158ef86a7 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -1362,6 +1362,23 @@ emit_deprecation_warning(Module, NewModule) -> now_to_seconds({MegaSecs, Secs, _MicroSecs}) -> MegaSecs * 1000000 + Secs. +-spec opt_type(hide_sensitive_log_data) -> fun((boolean()) -> boolean()); + (hosts) -> fun(([binary()]) -> [binary()]); + (language) -> fun((binary()) -> binary()); + (max_fsm_queue) -> fun((pos_integer()) -> pos_integer()); + (default_db) -> fun((atom()) -> atom()); + (default_ram_db) -> fun((atom()) -> atom()); + (loglevel) -> fun((0..5) -> 0..5); + (queue_dir) -> fun((binary()) -> binary()); + (queue_type) -> fun((ram | file) -> ram | file); + (use_cache) -> fun((boolean()) -> boolean()); + (cache_size) -> fun((timeout()) -> timeout()); + (cache_missed) -> fun((boolean()) -> boolean()); + (cache_life_time) -> fun((timeout()) -> timeout()); + (domain_certfile) -> fun((binary()) -> binary()); + (shared_key) -> fun((binary()) -> binary()); + (node_start) -> fun((non_neg_integer()) -> non_neg_integer()); + (atom()) -> [atom()]. opt_type(hide_sensitive_log_data) -> fun (H) when is_boolean(H) -> H end; opt_type(hosts) -> diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl index a9643386d..87f2f87f1 100644 --- a/src/ejabberd_ctl.erl +++ b/src/ejabberd_ctl.erl @@ -875,6 +875,8 @@ print(Format, Args) -> %% ["aaaa bbb ccc"]. +-spec opt_type(ejabberdctl_access_commands) -> fun((list()) -> list()); + (atom()) -> [atom()]. opt_type(ejabberdctl_access_commands) -> fun (V) when is_list(V) -> V end; opt_type(_) -> [ejabberdctl_access_commands]. diff --git a/src/ejabberd_http.erl b/src/ejabberd_http.erl index b706215a9..2dd81854e 100644 --- a/src/ejabberd_http.erl +++ b/src/ejabberd_http.erl @@ -899,11 +899,30 @@ transform_listen_option({request_handlers, Hs}, Opts) -> transform_listen_option(Opt, Opts) -> [Opt|Opts]. +-spec opt_type(trusted_proxies) -> fun((all | [binary()]) -> all | [binary()]); + (atom()) -> [atom()]. opt_type(trusted_proxies) -> fun (all) -> all; (TPs) -> [iolist_to_binary(TP) || TP <- TPs] end; opt_type(_) -> [trusted_proxies]. +-spec listen_opt_type(tls) -> fun((boolean()) -> boolean()); + (certfile) -> fun((binary()) -> binary()); + (ciphers) -> fun((binary()) -> binary()); + (dhfile) -> fun((binary()) -> binary()); + (protocol_options) -> fun(([binary()]) -> binary()); + (tls_compression) -> fun((boolean()) -> boolean()); + (captcha) -> fun((boolean()) -> boolean()); + (register) -> fun((boolean()) -> boolean()); + (web_admin) -> fun((boolean()) -> boolean()); + (http_bind) -> fun((boolean()) -> boolean()); + (xmlrpc) -> fun((boolean()) -> boolean()); + (request_handlers) -> fun(([{binary(), atom()}]) -> + [{binary(), atom()}]); + (default_host) -> fun((binary()) -> binary()); + (custom_headers) -> fun(([{binary(), binary()}]) -> + [{binary(), binary()}]); + (atom()) -> [atom()]. listen_opt_type(tls) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(certfile) -> diff --git a/src/ejabberd_oauth.erl b/src/ejabberd_oauth.erl index 455db85a5..af8680ef4 100644 --- a/src/ejabberd_oauth.erl +++ b/src/ejabberd_oauth.erl @@ -767,6 +767,14 @@ css() -> logo() -> <<"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAABACAYAAACgPErgAAAVtklEQVR42uydeXhU1d2ADzuyCcii4FZBZdEqVYtaUGqlikVwaRWsrWBRKIh8KgXcEAX9VECtoljcURAJICJWQLaKLAEjIHtBSNhC9oQkk2SW+36/52P+iIE5d5kzk4Fn3ud5H/7gIbnD3PPOveeeuVedygD9xLlQMh9yJ0D+GeokJAg1xcEWzOWYj0DBaQm0fXdaMCu8bROgpJVKksQj0+F84OXw/jRd7KVOdbbCFI6jdDNktlAnESVQNwSzOI6yhZBaV1UzAXiB4wj8CBtbqiRJXDIILtgL+zmOb8aoU5Xh0MMiEr5x6iSiAIZYROLo/aoayYMeocjbNlklSeKC9VAjBDM5IcEQfNZFnYq8AM8SkcJV6iSiCGYRkT1LVDWSA08Tkfy9MLaeOsUA2ot9xJHiW2KK+LW4Mvxnijg1/Pd9xQvFGiqJLUOhcT5kE5Etg0/VYI3TBOvbkyxYKURk2dpqDZb2gyEjC1SjUyBQdcQe4mtimujDHWXiD+Lr4g1iXZXkhISgBZBLZIa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xRLnZVDjkC54TveJAfdjEcuUzFia/h9FLoDbwifhV+3XmVxsZ6cQ5Yj0LoChVPkI0TO4q9wLoDuFW8TrxAbGr4d9WwoAVwhni6SiCA+mIzsXn4/6S2i3/bIPzvasdw++pW2r6mYi2VIAC1wtvUPLyNdZUGz8EyTyj8s78KnzK+LL4kviPOE9eJeUTP/R5f+xlgnZEIY8OC5pXGRg2VJEkSTbBOXsaoJEmSJIN1EvC0SvJ/7dSxigEAHIDxf5FisAilbNbbWGSi5OZ7BgZPcS/hAZTNwFtYSVltit2iU/c9gxv8u75ffa/wSQ4ruR+ahySHldyZJiHJYSW3pnZIcliJHekrJDmsxMM60JQqIUkJh3WhJX1SKSTpzcN60J1udKQNfdOIaiFJLwxrTwua0Zj61PtjXfqgDtWpEJL04rCetKKBM5GUeVgnGoYkJR1Wka60o0ZIUuJhVWlLzZCk5MMqUyv0r/wCSDD/4sxS1q8AAAAASUVORK5CYII=">>. +-spec opt_type(oauth_expire) -> fun((non_neg_integer()) -> non_neg_integer()); + (oauth_access) -> fun((any()) -> any()); + (oauth_db_type) -> fun((atom()) -> atom()); + (oauth_cache_life_time) -> fun((timeout()) -> timeout()); + (oauth_cache_size) -> fun((timeout()) -> timeout()); + (oauth_use_cache) -> fun((boolean()) -> boolean()); + (oauth_cache_misse) -> fun((boolean()) -> boolean()); + (atom()) -> [atom()]. opt_type(oauth_expire) -> fun(I) when is_integer(I), I >= 0 -> I end; opt_type(oauth_access) -> diff --git a/src/ejabberd_oauth_rest.erl b/src/ejabberd_oauth_rest.erl index 6c5b30523..404edd1fd 100644 --- a/src/ejabberd_oauth_rest.erl +++ b/src/ejabberd_oauth_rest.erl @@ -93,6 +93,8 @@ path(Path) -> <>. +-spec opt_type(ext_api_path_oauth) -> fun((binary()) -> binary()); + (atom()) -> [atom()]. opt_type(ext_api_path_oauth) -> fun (X) -> iolist_to_binary(X) end; opt_type(_) -> [ext_api_path_oauth]. diff --git a/src/ejabberd_rdbms.erl b/src/ejabberd_rdbms.erl index 7021c10b7..14bd968d2 100644 --- a/src/ejabberd_rdbms.erl +++ b/src/ejabberd_rdbms.erl @@ -109,6 +109,9 @@ needs_sql(Host) -> undefined -> false end. +-type sql_type() :: mysql | pgsql | sqlite | mssql | odbc. +-spec opt_type(sql_type) -> fun((sql_type()) -> sql_type()); + (atom()) -> [atom()]. opt_type(sql_type) -> fun (mysql) -> mysql; (pgsql) -> pgsql; diff --git a/src/ejabberd_receiver.erl b/src/ejabberd_receiver.erl index 38ad70eb3..24eb92fad 100644 --- a/src/ejabberd_receiver.erl +++ b/src/ejabberd_receiver.erl @@ -348,6 +348,9 @@ do_call(Pid, Msg) -> hibernate_timeout() -> ejabberd_config:get_option(receiver_hibernate, timer:seconds(90)). +-spec opt_type(receiver_hibernate) -> fun((pos_integer() | hibernate) -> + pos_integer() | hibernate); + (atom()) -> [atom()]. opt_type(receiver_hibernate) -> fun(I) when is_integer(I), I>0 -> I; (hibernate) -> hibernate diff --git a/src/ejabberd_redis_sup.erl b/src/ejabberd_redis_sup.erl index 85cfd7abb..ff1cc0e12 100644 --- a/src/ejabberd_redis_sup.erl +++ b/src/ejabberd_redis_sup.erl @@ -133,6 +133,14 @@ get_pool_size() -> iolist_to_list(IOList) -> binary_to_list(iolist_to_binary(IOList)). +-spec opt_type(redis_connect_timeout) -> fun((pos_integer()) -> pos_integer()); + (redis_db) -> fun((non_neg_integer()) -> non_neg_integer()); + (redis_password) -> fun((binary()) -> binary()); + (redis_port) -> fun((0..65535) -> 0..65535); + (redis_server) -> fun((binary()) -> binary()); + (redis_pool_size) -> fun((pos_integer()) -> pos_integer()); + (redis_queue_type) -> fun((ram | file) -> ram | file); + (atom()) -> [atom()]. opt_type(redis_connect_timeout) -> fun (I) when is_integer(I), I > 0 -> I end; opt_type(redis_db) -> diff --git a/src/ejabberd_riak_sup.erl b/src/ejabberd_riak_sup.erl index 3d754f6d6..30be65c4f 100644 --- a/src/ejabberd_riak_sup.erl +++ b/src/ejabberd_riak_sup.erl @@ -179,6 +179,14 @@ transform_options({riak_server, {S, P}}, Opts) -> transform_options(Opt, Opts) -> [Opt|Opts]. +-spec opt_type(riak_pool_size) -> fun((pos_integer()) -> pos_integer()); + (riak_port) -> fun((0..65535) -> 0..65535); + (riak_server) -> fun((binary()) -> binary()); + (riak_start_interval) -> fun((pos_integer()) -> pos_integer()); + (riak_cacertfile) -> fun((binary()) -> binary()); + (riak_username) -> fun((binary()) -> binary()); + (riak_password) -> fun((binary()) -> binary()); + (atom()) -> [atom()]. opt_type(riak_pool_size) -> fun (N) when is_integer(N), N >= 1 -> N end; opt_type(riak_port) -> diff --git a/src/ejabberd_router.erl b/src/ejabberd_router.erl index 490133d79..844651329 100644 --- a/src/ejabberd_router.erl +++ b/src/ejabberd_router.erl @@ -476,6 +476,16 @@ clean_cache(Node) -> clean_cache() -> ejabberd_cluster:eval_everywhere(?MODULE, clean_cache, [node()]). +-type domain_balancing() :: random | source | destination | + bare_source | bare_destination. +-spec opt_type(domain_balancing) -> fun((domain_balancing()) -> domain_balancing()); + (domain_balancing_component_number) -> fun((pos_integer()) -> pos_integer()); + (router_db_type) -> fun((atom()) -> atom()); + (router_use_cache) -> fun((boolean()) -> boolean()); + (router_cache_missed) -> fun((boolean()) -> boolean()); + (router_cache_size) -> fun((timeout()) -> timeout()); + (router_cache_life_time) -> fun((timeout()) -> timeout()); + (atom()) -> [atom()]. opt_type(domain_balancing) -> fun (random) -> random; (source) -> source; diff --git a/src/ejabberd_s2s.erl b/src/ejabberd_s2s.erl index b6685c12e..a447dcd67 100644 --- a/src/ejabberd_s2s.erl +++ b/src/ejabberd_s2s.erl @@ -689,6 +689,20 @@ get_s2s_state(S2sPid) -> end, [{s2s_pid, S2sPid} | Infos]. +-type use_starttls() :: boolean() | optional | required | required_trusted. +-spec opt_type(route_subdomains) -> fun((s2s | local) -> s2s | local); + (s2s_access) -> fun((any()) -> any()); + (s2s_certfile) -> fun((binary()) -> binary()); + (s2s_ciphers) -> fun((binary()) -> binary()); + (s2s_dhfile) -> fun((binary()) -> binary()); + (s2s_cafile) -> fun((binary()) -> binary()); + (s2s_protocol_options) -> fun(([binary()]) -> binary()); + (s2s_tls_compression) -> fun((boolean()) -> boolean()); + (s2s_use_starttls) -> fun((use_starttls()) -> use_starttls()); + (s2s_zlib) -> fun((boolean()) -> boolean()); + (s2s_timeout) -> fun((timeout()) -> timeout()); + (s2s_queue_type) -> fun((ram | file) -> ram | file); + (atom()) -> [atom()]. opt_type(route_subdomains) -> fun (s2s) -> s2s; (local) -> local diff --git a/src/ejabberd_s2s_in.erl b/src/ejabberd_s2s_in.erl index b1d0ae215..90e0feb27 100644 --- a/src/ejabberd_s2s_in.erl +++ b/src/ejabberd_s2s_in.erl @@ -21,13 +21,12 @@ %%%------------------------------------------------------------------- -module(ejabberd_s2s_in). -behaviour(xmpp_stream_in). --behaviour(ejabberd_config). -behaviour(ejabberd_socket). %% ejabberd_socket callbacks -export([start/2, start_link/2, socket_type/0]). -%% ejabberd_config callbacks --export([opt_type/1, listen_opt_type/1]). +%% ejabberd_listener callbacks +-export([listen_opt_type/1]). %% xmpp_stream_in callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -344,9 +343,18 @@ change_shaper(#{shaper := ShaperName, server_host := ServerHost} = State, Shaper = acl:match_rule(ServerHost, ShaperName, jid:make(RServer)), xmpp_stream_in:change_shaper(State, Shaper). -opt_type(_) -> - []. - +-spec listen_opt_type(shaper) -> fun((any()) -> any()); + (certfile) -> fun((binary()) -> binary()); + (ciphers) -> fun((binary()) -> binary()); + (dhfile) -> fun((binary()) -> binary()); + (cafile) -> fun((binary()) -> binary()); + (protocol_options) -> fun(([binary()]) -> binary()); + (tls_compression) -> fun((boolean()) -> boolean()); + (tls) -> fun((boolean()) -> boolean()); + (supervisor) -> fun((boolean()) -> boolean()); + (max_stanza_type) -> fun((timeout()) -> timeout()); + (max_fsm_queue) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. listen_opt_type(shaper) -> fun acl:shaper_rules_validator/1; listen_opt_type(certfile) -> ejabberd_s2s:opt_type(s2s_certfile); listen_opt_type(ciphers) -> ejabberd_s2s:opt_type(s2s_ciphers); @@ -357,7 +365,7 @@ listen_opt_type(tls_compression) -> ejabberd_s2s:opt_type(s2s_tls_compression); listen_opt_type(tls) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(supervisor) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(max_stanza_size) -> - fun(I) when is_integer(I) -> I; + fun(I) when is_integer(I), I>0 -> I; (unlimited) -> infinity; (infinity) -> infinity end; diff --git a/src/ejabberd_s2s_out.erl b/src/ejabberd_s2s_out.erl index deff3e5b5..bcacd8e77 100644 --- a/src/ejabberd_s2s_out.erl +++ b/src/ejabberd_s2s_out.erl @@ -439,6 +439,13 @@ maybe_report_huge_timeout(Opt, T) when is_integer(T), T >= 1000 -> maybe_report_huge_timeout(_, _) -> ok. +-spec opt_type(outgoing_s2s_families) -> fun(([ipv4|ipv6]) -> [inet|inet6]); + (outgoing_s2s_port) -> fun((0..65535) -> 0..65535); + (outgoing_s2s_timeout) -> fun((timeout()) -> timeout()); + (s2s_dns_retries) -> fun((non_neg_integer()) -> non_neg_integer()); + (s2s_dns_timeout) -> fun((timeout()) -> timeout()); + (s2s_max_retry_delay) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. opt_type(outgoing_s2s_families) -> fun(Families) -> lists:map( @@ -447,7 +454,7 @@ opt_type(outgoing_s2s_families) -> end, Families) end; opt_type(outgoing_s2s_port) -> - fun (I) when is_integer(I), I > 0, I =< 65536 -> I end; + 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 -> timer:seconds(TimeOut); diff --git a/src/ejabberd_service.erl b/src/ejabberd_service.erl index 0dcf74ab0..6fae16940 100644 --- a/src/ejabberd_service.erl +++ b/src/ejabberd_service.erl @@ -21,15 +21,14 @@ %%%------------------------------------------------------------------- -module(ejabberd_service). -behaviour(xmpp_stream_in). --behaviour(ejabberd_config). -behaviour(ejabberd_socket). -protocol({xep, 114, '1.6'}). %% ejabberd_socket callbacks -export([start/2, start_link/2, socket_type/0, close/1, close/2]). -%% ejabberd_config callbacks --export([opt_type/1, listen_opt_type/1, transform_listen_option/2]). +%% ejabberd_listener callbacks +-export([listen_opt_type/1, transform_listen_option/2]). %% xmpp_stream_in callbacks -export([init/1, handle_info/2, terminate/2, code_change/3]). -export([handle_stream_start/2, handle_auth_success/4, handle_auth_failure/4, @@ -259,8 +258,22 @@ transform_listen_option({host, Host, Os}, Opts) -> transform_listen_option(Opt, Opts) -> [Opt|Opts]. -opt_type(_) -> []. - +-spec listen_opt_type(access) -> fun((any()) -> any()); + (shaper_rule) -> fun((any()) -> any()); + (certfile) -> fun((binary()) -> binary()); + (ciphers) -> fun((binary()) -> binary()); + (dhfile) -> fun((binary()) -> binary()); + (cafile) -> fun((binary()) -> binary()); + (protocol_options) -> fun(([binary()]) -> binary()); + (tls_compression) -> fun((boolean()) -> boolean()); + (tls) -> fun((boolean()) -> boolean()); + (check_from) -> fun((boolean()) -> boolean()); + (password) -> fun((boolean()) -> boolean()); + (hosts) -> fun(([{binary(), [{password, binary()}]}]) -> + [{binary(), binary() | undefined}]); + (max_stanza_type) -> fun((timeout()) -> timeout()); + (max_fsm_queue) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. listen_opt_type(access) -> fun acl:access_rules_validator/1; listen_opt_type(shaper_rule) -> fun acl:shaper_rules_validator/1; listen_opt_type(certfile) -> fun iolist_to_binary/1; diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index ce2abfff0..92c6bb94f 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -1010,6 +1010,12 @@ kick_user(User, Server) -> make_sid() -> {p1_time_compat:unique_timestamp(), self()}. +-spec opt_type(sm_db_type) -> fun((atom()) -> atom()); + (sm_use_cache) -> fun((boolean()) -> boolean()); + (sm_cache_missed) -> fun((boolean()) -> boolean()); + (sm_cache_size) -> fun((timeout()) -> timeout()); + (sm_cache_life_time) -> fun((timeout()) -> timeout()); + (atom()) -> [atom()]. opt_type(sm_db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; opt_type(O) when O == sm_use_cache; O == sm_cache_missed -> fun(B) when is_boolean(B) -> B end; diff --git a/src/ejabberd_sql.erl b/src/ejabberd_sql.erl index 4c85b874a..dc6292ce4 100644 --- a/src/ejabberd_sql.erl +++ b/src/ejabberd_sql.erl @@ -1080,6 +1080,20 @@ check_error({error, Why} = Err, Query) -> check_error(Result, _Query) -> Result. +-spec opt_type(sql_database) -> fun((binary()) -> binary()); + (sql_keepalive_interval) -> fun((pos_integer()) -> pos_integer()); + (sql_password) -> fun((binary()) -> binary()); + (sql_port) -> fun((0..65535) -> 0..65535); + (sql_server) -> fun((binary()) -> binary()); + (sql_username) -> fun((binary()) -> binary()); + (sql_ssl) -> fun((boolean()) -> boolean()); + (sql_ssl_verify) -> fun((boolean()) -> boolean()); + (sql_ssl_certfile) -> fun((boolean()) -> boolean()); + (sql_ssl_cafile) -> fun((boolean()) -> boolean()); + (sql_query_timeout) -> fun((pos_integer()) -> pos_integer()); + (sql_connect_timeout) -> fun((pos_integer()) -> pos_integer()); + (sql_queue_type) -> fun((ram | file) -> ram | file); + (atom()) -> [atom()]. opt_type(sql_database) -> fun iolist_to_binary/1; opt_type(sql_keepalive_interval) -> fun (I) when is_integer(I), I > 0 -> I end; diff --git a/src/ejabberd_sql_sup.erl b/src/ejabberd_sql_sup.erl index 7526aedbe..f7793eb2c 100644 --- a/src/ejabberd_sql_sup.erl +++ b/src/ejabberd_sql_sup.erl @@ -218,6 +218,9 @@ read_lines(Fd, File, Acc) -> [] end. +-spec opt_type(sql_pool_size) -> fun((pos_integer()) -> pos_integer()); + (sql_start_interval) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. opt_type(sql_pool_size) -> fun (I) when is_integer(I), I > 0 -> I end; opt_type(sql_start_interval) -> diff --git a/src/ejabberd_system_monitor.erl b/src/ejabberd_system_monitor.erl index 881bfa635..773104f9e 100644 --- a/src/ejabberd_system_monitor.erl +++ b/src/ejabberd_system_monitor.erl @@ -330,6 +330,9 @@ process_remote_command([setlh, NewValue]) -> [OldLH, NewLH]); process_remote_command(_) -> throw(unknown_command). +-spec opt_type(watchdog_admins) -> fun(([binary()]) -> ljid()); + (watchdog_large_heap) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. opt_type(watchdog_admins) -> fun (JIDs) -> [jid:tolower(jid:decode(iolist_to_binary(S))) diff --git a/src/ejabberd_web_admin.erl b/src/ejabberd_web_admin.erl index 0106bb9cd..5050ac095 100644 --- a/src/ejabberd_web_admin.erl +++ b/src/ejabberd_web_admin.erl @@ -2981,6 +2981,8 @@ make_menu_item(item, 3, URI, Name, Lang) -> %%%================================== +-spec opt_type(access_readonly) -> fun((any()) -> any()); + (atom()) -> [atom()]. opt_type(access_readonly) -> fun acl:access_rules_validator/1; opt_type(_) -> [access_readonly]. diff --git a/src/eldap_utils.erl b/src/eldap_utils.erl index d15e5bc9c..52671061d 100644 --- a/src/eldap_utils.erl +++ b/src/eldap_utils.erl @@ -318,12 +318,25 @@ collect_parts_bit([{?N_BIT_STRING,<>}|Rest],Acc,Uacc) -> collect_parts_bit([],Acc,Uacc) -> list_to_binary([Uacc|lists:reverse(Acc)]). +-type deref_aliases() :: never | searching | finding | always. +-type uids() :: binary() | {binary()} | {binary(), binary()}. +-spec opt_type(deref_aliases) -> fun((deref_aliases()) -> deref_aliases()); + (ldap_backups) -> fun(([binary()]) -> [binary()]); + (ldap_base) -> fun((binary()) -> binary()); + (ldap_deref_aliases) -> fun((deref_aliases()) -> deref_aliases()); + (ldap_encrypt) -> fun((tls | starttls | none) -> tls | starttls | none); + (ldap_password) -> fun((binary()) -> binary()); + (ldap_port) -> fun((0..65535) -> 0..65535); + (ldap_rootdn) -> fun((binary()) -> binary()); + (ldap_servers) -> fun(([binary()]) -> [binary()]); + (ldap_tls_certfile) -> fun((binary()) -> string()); + (ldap_tls_depth) -> fun((non_neg_integer()) -> non_neg_integer()); + (ldap_tls_verify) -> fun((hard | soft | false) -> hard | soft | false); + (ldap_filter) -> fun((binary()) -> binary()); + (ldap_uids) -> fun((uids()) -> uids()); + (atom()) -> [atom()]. opt_type(deref_aliases) -> - fun (never) -> never; - (searching) -> searching; - (finding) -> finding; - (always) -> always - end; + opt_type(ldap_deref_aliases); opt_type(ldap_backups) -> fun (L) -> [iolist_to_binary(H) || H <- L] end; opt_type(ldap_base) -> fun iolist_to_binary/1; diff --git a/src/ext_mod.erl b/src/ext_mod.erl index 15fe8e17f..c5ce6874f 100644 --- a/src/ext_mod.erl +++ b/src/ext_mod.erl @@ -652,6 +652,8 @@ format({Key, Val}) when is_binary(Val) -> format({Key, Val}) -> % TODO: improve Yaml parsing {Key, Val}. +-spec opt_type(allow_contrib_modules) -> fun((boolean()) -> boolean()); + (atom()) -> [atom()]. opt_type(allow_contrib_modules) -> fun (false) -> false; (no) -> false; diff --git a/src/extauth.erl b/src/extauth.erl index c6f25102c..54f44953c 100644 --- a/src/extauth.erl +++ b/src/extauth.erl @@ -154,6 +154,8 @@ encode(L) -> str:join(L, <<":">>). decode([0, 0]) -> false; decode([0, 1]) -> true. +-spec opt_type(extauth_instances) -> fun((pos_integer()) -> pos_integer()); + (atom()) -> [atom()]. opt_type(extauth_instances) -> fun (V) when is_integer(V), V > 0 -> V end; opt_type(_) -> [extauth_instances]. diff --git a/src/gen_iq_handler.erl b/src/gen_iq_handler.erl index aaa7861dc..6ca706f63 100644 --- a/src/gen_iq_handler.erl +++ b/src/gen_iq_handler.erl @@ -198,6 +198,8 @@ transform_module_options(Opts) -> Opt end, Opts). +-spec opt_type(iqdisc) -> fun((type()) -> type()); + (atom()) -> [atom()]. opt_type(iqdisc) -> fun check_type/1; opt_type(_) -> [iqdisc]. diff --git a/src/gen_mod.erl b/src/gen_mod.erl index fdfd94f2a..27d241c9c 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -677,6 +677,8 @@ is_equal_opt(Opt, NewOpts, OldOpts, Default) -> true end. +-spec opt_type(modules) -> fun(([{atom(), list()}]) -> [{atom(), list()}]); + (atom()) -> [atom()]. opt_type(modules) -> fun(Mods) -> lists:map( diff --git a/src/mod_metrics.erl b/src/mod_metrics.erl index 9a3adc2d7..ecae7cd1b 100644 --- a/src/mod_metrics.erl +++ b/src/mod_metrics.erl @@ -25,7 +25,6 @@ -module(mod_metrics). --behaviour(ejabberd_config). -author('christophe.romain@process-one.net'). -behaviour(gen_mod). @@ -33,7 +32,7 @@ -include("logger.hrl"). -include("xmpp.hrl"). --export([start/2, stop/1, send_metrics/4, opt_type/1, mod_opt_type/1, +-export([start/2, stop/1, send_metrics/4, mod_opt_type/1, depends/2, reload/3]). -export([offline_message_hook/1, @@ -157,8 +156,5 @@ send_metrics(Host, Probe, Peer, Port) -> ?WARNING_MSG("can not open udp socket to grapherl: ~p", [Error]) end. -opt_type(_) -> - []. - mod_opt_type(_) -> []. diff --git a/src/mod_register.erl b/src/mod_register.erl index 893a16c7a..af4ba02f4 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -612,6 +612,8 @@ mod_opt_type(_) -> iqdisc, password_strength, registration_watchers, {welcome_message, subject}, {welcome_message, body}]. +-spec opt_type(registration_timeout) -> fun((timeout()) -> timeout()); + (atom()) -> [atom()]. opt_type(registration_timeout) -> fun (TO) when is_integer(TO), TO > 0 -> TO; (infinity) -> infinity; diff --git a/src/mod_vcard_ldap.erl b/src/mod_vcard_ldap.erl index 28dda7af6..f97eb18a9 100644 --- a/src/mod_vcard_ldap.erl +++ b/src/mod_vcard_ldap.erl @@ -24,8 +24,6 @@ -module(mod_vcard_ldap). --behaviour(ejabberd_config). - -behaviour(gen_server). -behaviour(mod_vcard). @@ -33,7 +31,7 @@ -export([start_link/2]). -export([init/2, stop/1, get_vcard/2, set_vcard/4, search/4, remove_user/2, import/3, search_fields/1, search_reported/1, - mod_opt_type/1, opt_type/1]). + mod_opt_type/1]). -export([is_search_supported/1]). %% gen_server callbacks @@ -487,10 +485,3 @@ mod_opt_type(_) -> ldap_port, ldap_rootdn, ldap_servers, ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth, ldap_tls_verify]. - -opt_type(_) -> - [deref_aliases, ldap_backups, ldap_base, - ldap_deref_aliases, ldap_encrypt, ldap_password, - ldap_port, ldap_rootdn, ldap_servers, - ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth, - ldap_tls_verify]. diff --git a/src/rest.erl b/src/rest.erl index a3fb0eef2..833a498ed 100644 --- a/src/rest.erl +++ b/src/rest.erl @@ -177,6 +177,9 @@ url(Server, Path, Params) -> Tail = iolist_to_binary([ParHead | ParTail]), binary_to_list(<>). +-spec opt_type(ext_api_http_pool_size) -> fun((pos_integer()) -> pos_integer()); + (ext_api_url) -> fun((binary()) -> binary()); + (atom()) -> [atom()]. opt_type(ext_api_http_pool_size) -> fun (X) when is_integer(X), X > 0 -> X end; opt_type(ext_api_url) -> diff --git a/src/shaper.erl b/src/shaper.erl index ac1ecc36f..803d235a0 100644 --- a/src/shaper.erl +++ b/src/shaper.erl @@ -168,5 +168,7 @@ transform_options({OptName, Name, none}, Opts) when OptName == shaper -> transform_options(Opt, Opts) -> [Opt|Opts]. +-spec opt_type(shaper) -> fun((any()) -> any()); + (atom()) -> [atom()]. opt_type(shaper) -> fun (V) -> V end; opt_type(_) -> [shaper]. diff --git a/src/sql_queries.erl b/src/sql_queries.erl index 5d5729102..83cbd7b73 100644 --- a/src/sql_queries.erl +++ b/src/sql_queries.erl @@ -632,6 +632,8 @@ set_roster_version(LUser, Version) -> ["!username=%(LUser)s", "version=%(Version)s"]). +-spec opt_type(pgsql_users_number_estimate) -> fun((boolean()) -> boolean()); + (atom()) -> [atom()]. opt_type(pgsql_users_number_estimate) -> fun (V) when is_boolean(V) -> V end; opt_type(_) -> [pgsql_users_number_estimate]. -- 2.40.0