-module(acl).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-export([start/0, to_record/3, add/3, add_list/3,
- add_local/3, add_list_local/3, load_from_config/0,
- match_rule/3, match_acl/3, transform_options/1]).
+ add_local/3, add_list_local/3, load_from_config/0,
+ match_rule/3, match_acl/3, transform_options/1,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{access, [{Name, NewRules}]}|Opts];
transform_options(Opt, Opts) ->
[Opt|Opts].
+
+opt_type(access) -> fun (V) -> V end;
+opt_type(acl) -> fun (V) -> V end;
+opt_type(_) -> [access, acl].
-module(cyrsasl).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-export([start/0, register_mechanism/3, listmech/1,
- server_new/7, server_start/3, server_step/2]).
+ server_new/7, server_start/3, server_step/2,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[str:to_upper(V)]
end, []),
lists:member(Mechanism, Disabled).
+
+opt_type(disable_sasl_mechanisms) ->
+ fun (V) when is_list(V) ->
+ lists:map(fun (M) -> str:to_upper(M) end, V);
+ (V) -> [str:to_upper(V)]
+ end;
+opt_type(_) -> [disable_sasl_mechanisms].
-module(cyrsasl_digest).
+-behaviour(ejabberd_config).
+
-author('alexey@sevcom.net').
--export([start/1, stop/0, mech_new/4, mech_step/2, parse/1]).
+-export([start/1, stop/0, mech_new/4, mech_step/2,
+ parse/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
":", NC/binary, ":", CNonce/binary, ":", QOP/binary,
":", (hex((erlang:md5(A2))))/binary>>,
hex((erlang:md5(T))).
+
+opt_type(fqdn) -> fun iolist_to_binary/1;
+opt_type(_) -> [fqdn].
%%%----------------------------------------------------------------------
-module(ejabberd_app).
+
+-behaviour(ejabberd_config).
-author('alexey@process-one.net').
-behaviour(application).
--export([start_modules/0,start/2, prep_stop/1, stop/1, init/0]).
+-export([start_modules/0, start/2, prep_stop/1, stop/1,
+ init/0, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ejabberd:start_app(p1_stringprep),
ejabberd:start_app(p1_zlib),
ejabberd:start_app(p1_cache_tab).
+
+opt_type(cluster_nodes) ->
+ fun (Ns) -> true = lists:all(fun is_atom/1, Ns), Ns end;
+opt_type(loglevel) ->
+ fun (P) when P >= 0, P =< 5 -> P end;
+opt_type(modules) ->
+ fun (Mods) ->
+ lists:map(fun ({M, A}) when is_atom(M), is_list(A) ->
+ {M, A}
+ end,
+ Mods)
+ end;
+opt_type(_) -> [cluster_nodes, loglevel, modules].
-module(ejabberd_auth).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
%% External exports
remove_user/2, remove_user/3, plain_password_required/1,
store_type/1, entropy/1]).
--export([auth_modules/1]).
+-export([auth_modules/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ejabberd_auth_riak:import(Server, riak, Passwd);
import(_, _, _) ->
pass.
+
+opt_type(auth_method) ->
+ fun (V) when is_list(V) ->
+ true = lists:all(fun is_atom/1, V), V;
+ (V) when is_atom(V) -> [V]
+ end;
+opt_type(_) -> [auth_method].
%%%----------------------------------------------------------------------
-module(ejabberd_auth_anonymous).
+
+-behaviour(ejabberd_config).
-author('mickael.remond@process-one.net').
-export([start/1,
unregister_connection/3
]).
-
-%% Function used by ejabberd_auth:
-export([login/2, set_password/3, check_password/3,
check_password/5, try_register/3,
dirty_get_registered_users/0, get_vh_registered_users/1,
- get_vh_registered_users/2, get_vh_registered_users_number/1,
- get_vh_registered_users_number/2, get_password_s/2,
+ get_vh_registered_users/2,
+ get_vh_registered_users_number/1,
+ get_vh_registered_users_number/2, get_password_s/2,
get_password/2, get_password/3, is_user_exists/2,
remove_user/2, remove_user/3, store_type/0,
- plain_password_required/0]).
+ plain_password_required/0, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
store_type() ->
plain.
+
+opt_type(allow_multiple_connections) ->
+ fun (V) when is_boolean(V) -> V end;
+opt_type(anonymous_protocol) ->
+ fun (sasl_anon) -> sasl_anon;
+ (login_anon) -> login_anon;
+ (both) -> both
+ end;
+opt_type(_) ->
+ [allow_multiple_connections, anonymous_protocol].
-module(ejabberd_auth_external).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(ejabberd_auth).
-%% External exports
-export([start/1, set_password/3, check_password/3,
check_password/5, try_register/3,
dirty_get_registered_users/0, get_vh_registered_users/1,
get_vh_registered_users_number/1,
get_vh_registered_users_number/2, get_password/2,
get_password_s/2, is_user_exists/2, remove_user/2,
- remove_user/3, store_type/0,
- plain_password_required/0]).
+ remove_user/3, store_type/0, plain_password_required/0,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
is_configured(Host, Module) ->
gen_mod:is_loaded(Host, Module).
+
+opt_type(extauth_cache) ->
+ fun (false) -> undefined;
+ (I) when is_integer(I), I >= 0 -> I
+ end;
+opt_type(extauth_program) ->
+ fun (V) -> binary_to_list(iolist_to_binary(V)) end;
+opt_type(_) -> [extauth_cache, extauth_program].
-module(ejabberd_auth_internal).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(ejabberd_auth).
-%% External exports
-export([start/1, set_password/3, check_password/3,
check_password/5, try_register/3,
dirty_get_registered_users/0, get_vh_registered_users/1,
get_vh_registered_users_number/2, get_password/2,
get_password_s/2, is_user_exists/2, remove_user/2,
remove_user/3, store_type/0, export/1, import/1,
- import/3, plain_password_required/0]).
+ import/3, plain_password_required/0, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
mnesia:dirty_write(P);
import(_, _, _) ->
pass.
+
+opt_type(auth_password_format) -> fun (V) -> V end;
+opt_type(_) -> [auth_password_format].
-module(ejabberd_auth_ldap).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
-export([init/1, handle_info/2, handle_call/3,
handle_cast/2, terminate/2, code_change/3]).
-%% External exports
-export([start/1, stop/1, start_link/1, set_password/3,
check_password/3, check_password/5, try_register/3,
dirty_get_registered_users/0, get_vh_registered_users/1,
- get_vh_registered_users/2,
- get_vh_registered_users_number/1,
+ get_vh_registered_users/2,
+ get_vh_registered_users_number/1,
get_vh_registered_users_number/2, get_password/2,
get_password_s/2, is_user_exists/2, remove_user/2,
- remove_user/3, store_type/0,
- plain_password_required/0]).
+ remove_user/3, store_type/0, plain_password_required/0,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
NewF = iolist_to_binary(F),
{ok, _} = eldap_filter:parse(NewF),
NewF.
+
+mod_opt_type(deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+mod_opt_type(ldap_backups) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+mod_opt_type(ldap_base) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+mod_opt_type(ldap_encrypt) ->
+ fun (tls) -> tls;
+ (starttls) -> starttls;
+ (none) -> none
+ end;
+mod_opt_type(ldap_password) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_port) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_rootdn) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_servers) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+mod_opt_type(ldap_tls_cacertfile) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_tls_certfile) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_tls_depth) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+mod_opt_type(ldap_tls_verify) ->
+ fun (hard) -> hard;
+ (soft) -> soft;
+ (false) -> false
+ end;
+mod_opt_type(ldap_dn_filter) ->
+ fun ([{DNF, DNFA}]) ->
+ NewDNFA = case DNFA of
+ undefined -> [];
+ _ -> [iolist_to_binary(A) || A <- DNFA]
+ end,
+ NewDNF = check_filter(DNF),
+ {NewDNF, NewDNFA}
+ end;
+mod_opt_type(ldap_filter) -> fun check_filter/1;
+mod_opt_type(ldap_local_filter) -> fun (V) -> V end;
+mod_opt_type(ldap_uids) ->
+ fun (Us) ->
+ lists:map(fun ({U, P}) ->
+ {iolist_to_binary(U), iolist_to_binary(P)};
+ ({U}) -> {iolist_to_binary(U)};
+ (U) -> {iolist_to_binary(U)}
+ end,
+ lists:flatten(Us))
+ end;
+mod_opt_type(_) ->
+ [ldap_dn_filter, ldap_filter, ldap_local_filter,
+ ldap_uids, 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].
+
+opt_type(ldap_dn_filter) ->
+ fun ([{DNF, DNFA}]) ->
+ NewDNFA = case DNFA of
+ undefined -> [];
+ _ -> [iolist_to_binary(A) || A <- DNFA]
+ end,
+ NewDNF = check_filter(DNF),
+ {NewDNF, NewDNFA}
+ end;
+opt_type(ldap_filter) -> fun check_filter/1;
+opt_type(ldap_local_filter) -> fun (V) -> V end;
+opt_type(ldap_uids) ->
+ fun (Us) ->
+ lists:map(fun ({U, P}) ->
+ {iolist_to_binary(U), iolist_to_binary(P)};
+ ({U}) -> {iolist_to_binary(U)};
+ (U) -> {iolist_to_binary(U)}
+ end,
+ lists:flatten(Us))
+ end;
+opt_type(_) ->
+ [ldap_dn_filter, ldap_filter, ldap_local_filter,
+ ldap_uids].
-module(ejabberd_auth_odbc).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(ejabberd_auth).
-%% External exports
-export([start/1, set_password/3, check_password/3,
check_password/5, try_register/3,
dirty_get_registered_users/0, get_vh_registered_users/1,
get_vh_registered_users_number/1,
get_vh_registered_users_number/2, get_password/2,
get_password_s/2, is_user_exists/2, remove_user/2,
- remove_user/3, store_type/0,
- plain_password_required/0,
- convert_to_scram/1]).
+ remove_user/3, store_type/0, plain_password_required/0,
+ convert_to_scram/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
Error -> Error
end
end.
+
+opt_type(auth_password_format) -> fun (V) -> V end;
+opt_type(_) -> [auth_password_format].
%%%-------------------------------------------------------------------
-module(ejabberd_auth_pam).
+-behaviour(ejabberd_config).
+
-author('xram@jabber.ru').
-behaviour(ejabberd_auth).
-%% External exports
-%%====================================================================
-%% API
-%%====================================================================
-export([start/1, set_password/3, check_password/3,
check_password/5, try_register/3,
dirty_get_registered_users/0, get_vh_registered_users/1,
- get_vh_registered_users/2, get_vh_registered_users_number/1,
- get_vh_registered_users_number/2,
- get_password/2, get_password_s/2, is_user_exists/2,
- remove_user/2, remove_user/3, store_type/0,
- plain_password_required/0]).
+ get_vh_registered_users/2,
+ get_vh_registered_users_number/1,
+ get_vh_registered_users_number/2, get_password/2,
+ get_password_s/2, is_user_exists/2, remove_user/2,
+ remove_user/3, store_type/0, plain_password_required/0,
+ opt_type/1]).
start(_Host) ->
ejabberd:start_app(p1_pam).
(jid) -> jid
end,
username).
+
+opt_type(pam_service) -> fun iolist_to_binary/1;
+opt_type(pam_userinfotype) ->
+ fun (username) -> username;
+ (jid) -> jid
+ end;
+opt_type(_) -> [pam_service, pam_userinfotype].
-module(ejabberd_c2s).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-protocol({xep, 78, '2.5'}).
get_subscribed/1,
transform_listen_option/2]).
-%% gen_fsm callbacks
--export([init/1,
- wait_for_stream/2,
- wait_for_auth/2,
- wait_for_feature_request/2,
- wait_for_bind/2,
- wait_for_session/2,
- wait_for_sasl_response/2,
- wait_for_resume/2,
- session_established/2,
- handle_event/3,
- handle_sync_event/4,
- code_change/4,
- handle_info/3,
- terminate/3,
- print_state/1
- ]).
+-export([init/1, wait_for_stream/2, wait_for_auth/2,
+ wait_for_feature_request/2, wait_for_bind/2,
+ wait_for_session/2, wait_for_sasl_response/2,
+ wait_for_resume/2, session_established/2,
+ handle_event/3, handle_sync_event/4, code_change/4,
+ handle_info/3, terminate/3, print_state/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
transform_listen_option(Opt, Opts) ->
[Opt|Opts].
+
+opt_type(domain_certfile) -> fun iolist_to_binary/1;
+opt_type(max_fsm_queue) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(resource_conflict) ->
+ fun (setresource) -> setresource;
+ (closeold) -> closeold;
+ (closenew) -> closenew;
+ (acceptnew) -> acceptnew
+ end;
+opt_type(_) ->
+ [domain_certfile, max_fsm_queue, resource_conflict].
-module(ejabberd_c2s_config).
+-behaviour(ejabberd_config).
+
-author('mremond@process-one.net').
--export([get_c2s_limits/0]).
+-export([get_c2s_limits/0, opt_type/1]).
%% Get first c2s configuration limitations to apply it to other c2s
%% connectors.
[{max_stanza_size, Value} | SelectedValues]);
select_opts_values([_Opt | Opts], SelectedValues) ->
select_opts_values(Opts, SelectedValues).
+
+opt_type(listen) -> fun (V) -> V end;
+opt_type(_) -> [listen].
-module(ejabberd_captcha).
+-behaviour(ejabberd_config).
+
-protocol({xep, 158, '1.0'}).
-behaviour(gen_server).
-export([create_captcha/6, build_captcha_html/2,
check_captcha/2, process_reply/1, process/2,
is_feature_available/0, create_captcha_x/5,
- create_captcha_x/6]).
+ create_captcha_x/6, opt_type/1]).
-include("jlib.hrl").
now_priority() ->
{MSec, Sec, USec} = now(),
-((MSec * 1000000 + Sec) * 1000000 + USec).
+
+opt_type(captcha_cmd) ->
+ fun (FileName) ->
+ F = iolist_to_binary(FileName), if F /= <<"">> -> F end
+ end;
+opt_type(captcha_host) -> fun iolist_to_binary/1;
+opt_type(captcha_limit) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(listen) -> fun (V) -> V end;
+opt_type(_) ->
+ [captcha_cmd, captcha_host, captcha_limit, listen].
prepare_opt_val/4, convert_table_to_binary/5,
transform_options/1, collect_options/1,
convert_to_yaml/1, convert_to_yaml/2,
- env_binary_to_list/2]).
+ env_binary_to_list/2, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("ejabberd_config.hrl").
-include_lib("kernel/include/file.hrl").
+-callback opt_type(atom()) -> function() | [atom()].
%% @type macro() = {macro_key(), macro_value()}
{attributes, record_info(fields, local_config)}]),
mnesia:add_table_copy(local_config, node(), ram_copies),
Config = get_ejabberd_config_path(),
- State = read_file(Config),
+ State0 = read_file(Config),
+ State = validate_opts(State0),
%% This start time is used by mod_last:
{MegaSecs, Secs, _} = now(),
UnixTime = MegaSecs*1000000 + Secs,
end
end.
+get_modules_with_options() ->
+ {ok, Mods} = application:get_key(ejabberd, modules),
+ lists:foldl(
+ fun(Mod, D) ->
+ Attrs = Mod:module_info(attributes),
+ Behavs = proplists:get_value(behaviour, Attrs, []),
+ case lists:member(ejabberd_config, Behavs) or (Mod == ?MODULE) of
+ true ->
+ Opts = Mod:opt_type(''),
+ lists:foldl(
+ fun(Opt, Acc) ->
+ dict:append(Opt, Mod, Acc)
+ end, D, Opts);
+ false ->
+ D
+ end
+ end, dict:new(), [?MODULE|Mods]).
+
+validate_opts(#state{opts = Opts} = State) ->
+ ModOpts = get_modules_with_options(),
+ NewOpts = lists:filter(
+ fun(#local_config{key = {Opt, _Host}, value = Val}) ->
+ case dict:find(Opt, ModOpts) of
+ {ok, [Mod|_]} ->
+ VFun = Mod:opt_type(Opt),
+ case catch VFun(Val) of
+ {'EXIT', _} ->
+ ?ERROR_MSG("ignoring option '~s' with "
+ "invalid value: ~p",
+ [Opt, Val]),
+ false;
+ _ ->
+ true
+ end;
+ _ ->
+ ?ERROR_MSG("ignoring uknown option '~s'", [Opt]),
+ false
+ end
+ end, Opts),
+ State#state{opts = NewOpts}.
+
-spec get_vh_by_auth_method(atom()) -> [binary()].
%% Return the list of hosts handled by a given module
?WARNING_MSG("Module ~s is deprecated, use ~s instead",
[Module, NewModule])
end.
+
+opt_type(hosts) ->
+ fun(L) when is_list(L) ->
+ lists:map(
+ fun(H) ->
+ iolist_to_binary(H)
+ end, L)
+ end;
+opt_type(language) ->
+ fun iolist_to_binary/1;
+opt_type(_) ->
+ [hosts, language].
-module(ejabberd_ctl).
+
+-behaviour(ejabberd_config).
-author('alexey@process-one.net').
--export([start/0,
- init/0,
- process/1,
- process2/2,
- register_commands/3,
- unregister_commands/3]).
+-export([start/0, init/0, process/1, process2/2,
+ register_commands/3, unregister_commands/3,
+ opt_type/1]).
-include("ejabberd_ctl.hrl").
-include("ejabberd_commands.hrl").
%%format_usage_xmlrpc(ArgsDef, ResultDef) ->
%% ["aaaa bbb ccc"].
+
+opt_type(ejabberdctl_access_commands) ->
+ fun (V) when is_list(V) -> V end;
+opt_type(_) -> [ejabberdctl_access_commands].
-module(ejabberd_http).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
%% External exports
socket_type/0, receive_headers/1, url_encode/1,
transform_listen_option/2]).
-%% Callbacks
--export([init/2]).
+-export([init/2, mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{request_handlers, Hs1} | Opts];
transform_listen_option(Opt, Opts) ->
[Opt|Opts].
+
+mod_opt_type(default_host) -> fun (A) -> A end;
+mod_opt_type(request_handlers) ->
+ fun (Hs) ->
+ [{str:tokens(iolist_to_binary(Path), <<"/">>), Mod}
+ || {Path, Mod} <- Hs]
+ end;
+mod_opt_type(_) -> [default_host, request_handlers].
+
+opt_type(trusted_proxies) ->
+ fun (TPs) -> [iolist_to_binary(TP) || TP <- TPs] end;
+opt_type(_) -> [trusted_proxies].
%%%----------------------------------------------------------------------
-module(ejabberd_http_ws).
+-behaviour(ejabberd_config).
+
-author('ecestari@process-one.net').
-behaviour(gen_fsm).
-% External exports
-export([start/1, start_link/1, init/1, handle_event/3,
handle_sync_event/4, code_change/4, handle_info/3,
- terminate/3, send_xml/2, setopts/2, sockname/1, peername/1,
- controlling_process/2, become_controller/2, close/1,
- socket_handoff/6]).
+ terminate/3, send_xml/2, setopts/2, sockname/1,
+ peername/1, controlling_process/2, become_controller/2,
+ close/1, socket_handoff/6, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
after 0 ->
lists:reverse(List)
end.
+
+opt_type(websocket_ping_interval) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+opt_type(websocket_timeout) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(_) ->
+ [websocket_ping_interval, websocket_timeout].
%%%----------------------------------------------------------------------
-module(ejabberd_listener).
+
+-behaviour(ejabberd_config).
-author('alexey@process-one.net').
--export([start_link/0, init/1, start/3,
- init/3,
- start_listeners/0,
- start_listener/3,
- stop_listeners/0,
- stop_listener/2,
- parse_listener_portip/2,
- add_listener/3,
- delete_listener/2,
- transform_options/1,
- validate_cfg/1
- ]).
+-export([start_link/0, init/1, start/3, init/3,
+ start_listeners/0, start_listener/3, stop_listeners/0,
+ stop_listener/2, parse_listener_portip/2,
+ add_listener/3, delete_listener/2, transform_options/1,
+ validate_cfg/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
esip_socket;
prepare_mod(Mod) when is_atom(Mod) ->
Mod.
+
+opt_type(listen) -> fun validate_cfg/1;
+opt_type(_) -> [listen].
%%%----------------------------------------------------------------------
-module(ejabberd_node_groups).
+
+-behaviour(ejabberd_config).
-author('alexey@process-one.net').
-behaviour(gen_server).
get_members/1,
get_closest_node/1]).
-%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3]).
+-export([init/1, handle_call/3, handle_cast/2,
+ handle_info/2, terminate/2, code_change/3, opt_type/1]).
-define(PG2, pg2).
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
+
+opt_type(node_type) ->
+ fun (frontend) -> frontend;
+ (backend) -> backend;
+ (generic) -> generic
+ end;
+opt_type(_) -> [node_type].
-module(ejabberd_odbc).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-define(GEN_FSM, p1_fsm).
handle_info/3, terminate/3, print_state/1,
code_change/4]).
-%% gen_fsm states
-export([connecting/2, connecting/3,
- session_established/2, session_established/3]).
+ session_established/2, session_established/3,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
N when is_integer(N) -> [{max_queue, N}];
_ -> []
end.
+
+opt_type(max_fsm_queue) ->
+ fun (N) when is_integer(N), N > 0 -> N end;
+opt_type(odbc_database) -> fun iolist_to_binary/1;
+opt_type(odbc_keepalive_interval) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(odbc_password) -> fun iolist_to_binary/1;
+opt_type(odbc_port) ->
+ fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
+opt_type(odbc_server) -> fun iolist_to_binary/1;
+opt_type(odbc_type) ->
+ fun (mysql) -> mysql;
+ (pgsql) -> pgsql;
+ (sqlite) -> sqlite;
+ (odbc) -> odbc
+ end;
+opt_type(odbc_username) -> fun iolist_to_binary/1;
+opt_type(_) ->
+ [max_fsm_queue, odbc_database, odbc_keepalive_interval,
+ odbc_password, odbc_port, odbc_server, odbc_type,
+ odbc_username].
-module(ejabberd_odbc_sup).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-%% API
-export([start_link/1, init/1, add_pid/2, remove_pid/2,
- get_pids/1, get_random_pid/1, transform_options/1]).
+ get_pids/1, get_random_pid/1, transform_options/1,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
?ERROR_MSG("Failed read from lite.sql, reason: ~p", [Err]),
[]
end.
+
+opt_type(odbc_pool_size) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(odbc_start_interval) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(odbc_type) ->
+ fun (mysql) -> mysql;
+ (pgsql) -> pgsql;
+ (sqlite) -> sqlite;
+ (odbc) -> odbc
+ end;
+opt_type(_) ->
+ [odbc_pool_size, odbc_start_interval, odbc_type].
-module(ejabberd_piefxis).
+-behaviour(ejabberd_config).
+
-protocol({xep, 227, '1.0'}).
-%% API
--export([import_file/1, export_server/1, export_host/2]).
+-export([import_file/1, export_server/1, export_host/2,
+ opt_type/1]).
-define(CHUNK_SIZE, 1024*20). %20k
%%%==================================
%%% vim: set filetype=erlang tabstop=8 foldmarker=%%%%,%%%= foldmethod=marker:
file:write(Fd, String).
+
+opt_type(auth_password_format) -> fun (X) -> X end;
+opt_type(_) -> [auth_password_format].
-module(ejabberd_rdbms).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
--export([start/0]).
+-export([start/0, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
odbc -> {true, odbc};
undefined -> false
end.
+
+opt_type(odbc_type) ->
+ fun (mysql) -> mysql;
+ (pgsql) -> pgsql;
+ (sqlite) -> sqlite;
+ (odbc) -> odbc
+ end;
+opt_type(_) -> [odbc_type].
%%%----------------------------------------------------------------------
-module(ejabberd_riak_sup).
+
+-behaviour(ejabberd_config).
-author('alexey@process-one.net').
-%% API
--export([start/0,
- start_link/0,
- init/1,
- get_pids/0,
- transform_options/1,
- get_random_pid/0,
- get_random_pid/1
- ]).
+-export([start/0, start_link/0, init/1, get_pids/0,
+ transform_options/1, get_random_pid/0, get_random_pid/1,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{riak_server, S}, {riak_port, P}|Opts];
transform_options(Opt, Opts) ->
[Opt|Opts].
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(_) -> [db_type].
+
+opt_type(modules) -> fun (L) when is_list(L) -> L end;
+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_start_interval) ->
+ fun (N) when is_integer(N), N >= 1 -> N end;
+opt_type(_) ->
+ [modules, riak_pool_size, riak_port, riak_server,
+ riak_start_interval].
-module(ejabberd_router).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
-export([start_link/0]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
false -> ok
end.
+
+opt_type(domain_balancing_component_number) ->
+ fun (N) when is_integer(N), N > 1 -> N end;
+opt_type(_) -> [domain_balancing_component_number].
-module(ejabberd_s2s).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-%% ejabberd API
--export([get_info_s2s_connections/1, transform_options/1]).
+-export([get_info_s2s_connections/1,
+ transform_options/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
end;
false -> false
end.
+
+opt_type(route_subdomains) ->
+ fun (s2s) -> s2s;
+ (local) -> local
+ end;
+opt_type(s2s_access) ->
+ fun (A) when is_atom(A) -> A end;
+opt_type(_) -> [route_subdomains, s2s_access].
-module(ejabberd_s2s_in).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(p1_fsm).
%% External exports
-export([start/2, start_link/2, socket_type/0]).
-%% gen_fsm callbacks
-export([init/1, wait_for_stream/2,
wait_for_feature_request/2, stream_established/2,
handle_event/3, handle_sync_event/4, code_change/4,
- handle_info/3, print_state/1, terminate/3]).
+ handle_info/3, print_state/1, terminate/3, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
N -> [{max_queue, N}]
end
end.
+
+opt_type(domain_certfile) -> fun iolist_to_binary/1;
+opt_type(max_fsm_queue) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(s2s_certfile) -> fun iolist_to_binary/1;
+opt_type(s2s_ciphers) -> fun iolist_to_binary/1;
+opt_type(s2s_protocol_options) ->
+ fun (Options) ->
+ [_ | O] = lists:foldl(fun (X, Acc) -> X ++ Acc end, [],
+ [["|" | binary_to_list(Opt)]
+ || Opt <- Options, is_binary(Opt)]),
+ iolist_to_binary(O)
+ end;
+opt_type(s2s_tls_compression) ->
+ fun (true) -> true;
+ (false) -> false
+ end;
+opt_type(s2s_use_starttls) ->
+ fun (false) -> false;
+ (true) -> true;
+ (optional) -> optional;
+ (required) -> required;
+ (required_trusted) -> required_trusted
+ end;
+opt_type(_) ->
+ [domain_certfile, max_fsm_queue, s2s_certfile,
+ s2s_ciphers, s2s_protocol_options, s2s_tls_compression,
+ s2s_use_starttls].
-module(ejabberd_s2s_out).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(p1_fsm).
stop_connection/1,
transform_options/1]).
-%% p1_fsm callbacks (same as gen_fsm)
--export([init/1,
- open_socket/2,
- wait_for_stream/2,
- wait_for_validation/2,
- wait_for_features/2,
- wait_for_auth_result/2,
- wait_for_starttls_proceed/2,
- relay_to_bridge/2,
- reopen_socket/2,
- wait_before_retry/2,
- stream_established/2,
- handle_event/3,
- handle_sync_event/4,
- handle_info/3,
- terminate/3,
- print_state/1,
- code_change/4,
- test_get_addr_port/1,
- get_addr_port/1]).
+-export([init/1, open_socket/2, wait_for_stream/2,
+ wait_for_validation/2, wait_for_features/2,
+ wait_for_auth_result/2, wait_for_starttls_proceed/2,
+ relay_to_bridge/2, reopen_socket/2, wait_before_retry/2,
+ stream_established/2, handle_event/3,
+ handle_sync_event/4, handle_info/3, terminate/3,
+ print_state/1, code_change/4, test_get_addr_port/1,
+ get_addr_port/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
undefined -> [];
N -> [{max_queue, N}]
end.
+
+opt_type(domain_certfile) -> fun iolist_to_binary/1;
+opt_type(max_fsm_queue) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(outgoing_s2s_families) ->
+ fun (Families) ->
+ true = lists:all(fun (ipv4) -> true;
+ (ipv6) -> true
+ end,
+ Families),
+ 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
+ end;
+opt_type(s2s_certfile) -> fun iolist_to_binary/1;
+opt_type(s2s_ciphers) -> fun iolist_to_binary/1;
+opt_type(s2s_dns_retries) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+opt_type(s2s_dns_timeout) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+opt_type(s2s_max_retry_delay) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(s2s_protocol_options) ->
+ fun (Options) ->
+ [_ | O] = lists:foldl(fun (X, Acc) -> X ++ Acc end, [],
+ [["|" | binary_to_list(Opt)]
+ || Opt <- Options, is_binary(Opt)]),
+ iolist_to_binary(O)
+ end;
+opt_type(s2s_tls_compression) ->
+ fun (true) -> true;
+ (false) -> false
+ end;
+opt_type(s2s_use_starttls) ->
+ fun (true) -> true;
+ (false) -> false;
+ (optional) -> optional;
+ (required) -> required;
+ (required_trusted) -> required_trusted
+ end;
+opt_type(_) ->
+ [domain_certfile, max_fsm_queue, outgoing_s2s_families,
+ outgoing_s2s_port, outgoing_s2s_timeout, s2s_certfile,
+ s2s_ciphers, s2s_dns_retries, s2s_dns_timeout,
+ s2s_max_retry_delay, s2s_protocol_options,
+ s2s_tls_compression, s2s_use_starttls].
-module(ejabberd_service).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-protocol({xep, 114, '1.6'}).
-export([start/2, start_link/2, send_text/2,
send_element/2, socket_type/0, transform_listen_option/2]).
-%% gen_fsm callbacks
-export([init/1, wait_for_stream/2,
wait_for_handshake/2, stream_established/2,
handle_event/3, handle_sync_event/4, code_change/4,
- handle_info/3, terminate/3, print_state/1]).
+ handle_info/3, terminate/3, print_state/1,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
N -> [{max_queue, N}]
end
end.
+
+mod_opt_type(password) -> fun iolist_to_binary/1;
+mod_opt_type(_) -> [password].
+
+opt_type(max_fsm_queue) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(_) -> [max_fsm_queue].
-module(ejabberd_sm).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
is_existing_resource/3
]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
PID ! kick
end, Resources),
length(Resources).
+
+opt_type(sm_db_type) ->
+ fun (mnesia) -> mnesia;
+ (internal) -> mnesia;
+ (odbc) -> odbc;
+ (redis) -> redis
+ end;
+opt_type(_) -> [sm_db_type].
%%%-------------------------------------------------------------------
-module(ejabberd_sm_redis).
+-behaviour(ejabberd_config).
+
-behaviour(ejabberd_sm).
-%% API
--export([init/0,
- set_session/1,
- delete_session/4,
- get_sessions/0,
- get_sessions/1,
- get_sessions/2,
- get_sessions/3]).
+-export([init/0, set_session/1, delete_session/4,
+ get_sessions/0, get_sessions/1, get_sessions/2,
+ get_sessions/3, opt_type/1]).
-include("ejabberd.hrl").
-include("ejabberd_sm.hrl").
"server ~s: ~p", [LServer, Err])
end
end, ?MYHOSTS).
+
+opt_type(redis_connect_timeout) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(redis_db) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+opt_type(redis_password) -> fun iolist_to_list/1;
+opt_type(redis_port) ->
+ fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
+opt_type(redis_reconnect_timeout) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(redis_server) -> fun iolist_to_list/1;
+opt_type(_) ->
+ [redis_connect_timeout, redis_db, redis_password,
+ redis_port, redis_reconnect_timeout, redis_server].
-protocol({rfc, 5766}).
-%% API
--export([tcp_init/2, udp_init/2, udp_recv/5, start/2, socket_type/0]).
+-export([tcp_init/2, udp_init/2, udp_recv/5, start/2,
+ socket_type/0, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
MaxRate = shaper:get_max_rate(Shaper),
Realm ++ [{auth_fun, AuthFun},{shaper, MaxRate} |
lists:keydelete(shaper, 1, Opts)].
+
+mod_opt_type(auth_realm) -> fun iolist_to_binary/1;
+mod_opt_type(auth_type) ->
+ fun (anonymous) -> anonymous;
+ (user) -> user
+ end;
+mod_opt_type(shaper) ->
+ fun (S) when is_atom(S) -> S end;
+mod_opt_type(_) -> [auth_realm, auth_type, shaper].
-module(ejabberd_system_monitor).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
-export([start_link/0, process_command/3,
process_remote_command/1]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
io_lib:format("Result of set large heap: ~p --> ~p",
[OldLH, NewLH]);
process_remote_command(_) -> throw(unknown_command).
+
+opt_type(watchdog_admins) ->
+ fun (JIDs) ->
+ [jlib:jid_tolower(jlib:string_to_jid(iolist_to_binary(S)))
+ || S <- JIDs]
+ end;
+opt_type(watchdog_large_heap) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(_) -> [watchdog_admins, watchdog_large_heap].
-module(ejabberd_web_admin).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-%% External exports
-export([process/2, list_users/4,
list_users_in_diapason/4, pretty_print_xml/1,
- term_to_id/1]).
+ term_to_id/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
%%%==================================
%%% vim: set foldmethod=marker foldmarker=%%%%,%%%=:
+
+opt_type(access) -> fun (V) -> V end;
+opt_type(_) -> [access].
-author('badlop@process-one.net').
-export([start/2, handler/2, process/2, socket_type/0,
- transform_listen_option/2]).
+ transform_listen_option/2, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{access_commands, NewACOpts}|Opts];
transform_listen_option(Opt, Opts) ->
[Opt|Opts].
+
+mod_opt_type(access_commands) ->
+ fun (L) when is_list(L) -> L end;
+mod_opt_type(commands) ->
+ fun (A) when is_atom(A) -> A;
+ (L) when is_list(L) ->
+ true = lists:all(fun is_atom/1, L), L
+ end;
+mod_opt_type(options) ->
+ fun (L) when is_list(L) -> L end;
+mod_opt_type(_) -> [access_commands, commands, options].
-include("logger.hrl").
--export([export/2, export/3, import_file/2, import/2, import/3]).
+-export([export/2, export/3, import_file/2, import/2,
+ import/3, mod_opt_type/1]).
-define(MAX_RECORDS_PER_TRANSACTION, 100).
flatten1(T, [[H, $\n]|Acc]);
flatten1([], Acc) ->
Acc.
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(_) -> [db_type].
-export([get_status/1]).
-%% gen_fsm callbacks
-export([init/1, connecting/2, connecting/3,
wait_bind_response/3, active/3, active_bind/3,
handle_event/3, handle_sync_event/4, handle_info/3,
- terminate/3, code_change/4]).
+ terminate/3, code_change/4, mod_opt_type/1]).
-export_type([filter/0]).
when Id > (?MAX_TRANSACTION_ID) ->
?MIN_TRANSACTION_ID;
bump_id(#eldap{id = Id}) -> Id + 1.
+
+mod_opt_type(encrypt) ->
+ fun (tls) -> tls;
+ (starttls) -> starttls;
+ (none) -> none
+ end;
+mod_opt_type(tls_cacertfile) ->
+ fun (S) when is_binary(S) -> binary_to_list(S);
+ (undefined) -> undefined
+ end;
+mod_opt_type(tls_depth) ->
+ fun (I) when is_integer(I), I >= 0 -> I;
+ (undefined) -> undefined
+ end;
+mod_opt_type(tls_verify) ->
+ fun (hard) -> hard;
+ (soft) -> soft;
+ (false) -> false
+ end;
+mod_opt_type(_) ->
+ [encrypt, tls_cacertfile, tls_depth, tls_verify].
%%%----------------------------------------------------------------------
-module(eldap_utils).
+
+-behaviour(ejabberd_config).
-author('mremond@process-one.net').
--export([generate_subfilter/1,
- find_ldap_attrs/2,
- get_ldap_attr/2,
- get_user_part/2,
- make_filter/2,
- get_state/2,
- case_insensitive_match/2,
- get_config/2,
- decode_octet_string/3,
- uids_domain_subst/2]).
+-export([generate_subfilter/1, find_ldap_attrs/2,
+ get_ldap_attr/2, get_user_part/2, make_filter/2,
+ get_state/2, case_insensitive_match/2, get_config/2,
+ decode_octet_string/3, uids_domain_subst/2, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
collect_parts_bit(Rest,[Bits|Acc],Unused+Uacc);
collect_parts_bit([],Acc,Uacc) ->
list_to_binary([Uacc|lists:reverse(Acc)]).
+
+opt_type(deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+opt_type(ldap_backups) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+opt_type(ldap_base) -> fun iolist_to_binary/1;
+opt_type(ldap_deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+opt_type(ldap_encrypt) ->
+ fun (tls) -> tls;
+ (starttls) -> starttls;
+ (none) -> none
+ end;
+opt_type(ldap_password) -> fun iolist_to_binary/1;
+opt_type(ldap_port) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(ldap_rootdn) -> fun iolist_to_binary/1;
+opt_type(ldap_servers) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+opt_type(ldap_tls_cacertfile) -> fun iolist_to_binary/1;
+opt_type(ldap_tls_depth) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+opt_type(ldap_tls_verify) ->
+ fun (hard) -> hard;
+ (soft) -> soft;
+ (false) -> false
+ end;
+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_depth, ldap_tls_verify].
%%%----------------------------------------------------------------------
-module(ext_mod).
+
+-behaviour(ejabberd_config).
-author("Christophe Romain <christophe.romain@process-one.net>").
-%% Packaging service
-export([start/0, stop/0, update/0, check/1,
- available_command/0, available/0, available/1,
- installed_command/0, installed/0, installed/1,
- install/1, uninstall/1,
- upgrade/0, upgrade/1,
- add_sources/2, del_sources/1,
- modules_dir/0]).
+ available_command/0, available/0, available/1,
+ installed_command/0, installed/0, installed/1,
+ install/1, uninstall/1, upgrade/0, upgrade/1,
+ add_sources/2, del_sources/1, modules_dir/0,
+ opt_type/1]).
-include("ejabberd_commands.hrl").
{Key, binary_to_list(Val)};
format({Key, Val}) -> % TODO: improve Yaml parsing
{Key, Val}.
+
+opt_type(allow_contrib_modules) ->
+ fun (false) -> false;
+ (no) -> false;
+ (_) -> true
+ end;
+opt_type(_) -> [allow_contrib_modules].
-module(extauth).
+-behaviour(ejabberd_config).
+
-author('leifj@it.su.se').
-export([start/2, stop/1, init/2, check_password/3,
set_password/3, try_register/3, remove_user/2,
- remove_user/3, is_user_exists/2]).
+ remove_user/3, is_user_exists/2, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
decode([0, 0]) -> false;
decode([0, 1]) -> true.
+
+opt_type(extauth_instances) ->
+ fun (V) when is_integer(V), V > 0 -> V end;
+opt_type(_) -> [extauth_instances].
%%%----------------------------------------------------------------------
%%% File : gen_mod.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
-%%% Purpose :
%%% Purpose :
%%% Created : 24 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
%%%
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
-%%% You should have received a copy of the GNU General Public License along
-%%% with this program; if not, write to the Free Software Foundation, Inc.,
-%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+%%% You should have received a copy of the GNU General Public License
+%%% along with this program; if not, write to the Free Software
+%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-module(gen_mod).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
--export([start/0, start_module/2, start_module/3, stop_module/2,
- stop_module_keep_config/2, get_opt/3, get_opt/4,
- get_opt_host/3, db_type/1, db_type/2, get_module_opt/5,
- get_module_opt_host/3, loaded_modules/1,
- loaded_modules_with_opts/1, get_hosts/2,
- get_module_proc/2, is_loaded/2, default_db/1]).
+-export([start/0, start_module/2, start_module/3,
+ stop_module/2, stop_module_keep_config/2, get_opt/3,
+ get_opt/4, get_opt_host/3, db_type/1, db_type/2,
+ get_module_opt/4, get_module_opt/5, get_module_opt_host/3,
+ loaded_modules/1, loaded_modules_with_opts/1,
+ get_hosts/2, get_module_proc/2, is_loaded/2,
+ start_modules/1, default_db/1, v_db/1, opt_type/1]).
%%-export([behaviour_info/1]).
opts = [] :: opts() | '_' | '$2'}).
-type opts() :: [{atom(), any()}].
+-type db_type() :: odbc | mnesia | riak.
-callback start(binary(), opts()) -> any().
-callback stop(binary()) -> any().
-export_type([opts/0]).
+-export_type([db_type/0]).
%%behaviour_info(callbacks) -> [{start, 2}, {stop, 1}];
%%behaviour_info(_Other) -> undefined.
{keypos, #ejabberd_module.module_host}]),
ok.
+-spec start_modules(binary()) -> any().
+
+start_modules(Host) ->
+ Modules = ejabberd_config:get_option(
+ {modules, Host},
+ fun(L) when is_list(L) -> L end, []),
+ lists:foreach(
+ fun({Module, Opts}) ->
+ start_module(Host, Module, Opts)
+ end, Modules).
+
-spec start_module(binary(), atom()) -> any().
start_module(Host, Module) ->
-spec start_module(binary(), atom(), opts()) -> any().
-start_module(Host, Module, Opts) ->
+start_module(Host, Module, Opts0) ->
+ Opts = validate_opts(Module, Opts0),
ets:insert(ejabberd_modules,
#ejabberd_module{module_host = {Module, Host},
opts = Opts}),
-spec stop_module(binary(), atom()) -> error | {aborted, any()} | {atomic, any()}.
-%% @doc Stop the module in a host, and forget its configuration.
stop_module(Host, Module) ->
case stop_module_keep_config(Host, Module) of
error -> error;
ok -> ok
end.
-%% @doc Stop the module in a host, but keep its configuration.
-%% As the module configuration is kept in the Mnesia local_config table,
-%% when ejabberd is restarted the module will be started again.
-%% This function is useful when ejabberd is being stopped
-%% and it stops all modules.
-spec stop_module_keep_config(binary(), atom()) -> error | ok.
stop_module_keep_config(Host, Module) ->
ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
end.
+-spec get_module_opt(global | binary(), atom(), atom(), check_fun()) -> any().
+
+get_module_opt(Host, Module, Opt, F) ->
+ get_module_opt(Host, Module, Opt, F, undefined).
+
-spec get_module_opt(global | binary(), atom(), atom(), check_fun(), any()) -> any().
get_module_opt(global, Module, Opt, F, Default) ->
Val = get_opt(host, Opts, fun iolist_to_binary/1, Default),
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
--spec v_db(odbc | mnesia | riak | internal) -> odbc | mnesia | riak.
+validate_opts(Module, Opts) ->
+ lists:filter(
+ fun({Opt, Val}) ->
+ case catch Module:mod_opt_type(Opt) of
+ VFun when is_function(VFun) ->
+ case catch VFun(Val) of
+ {'EXIT', _} ->
+ ?ERROR_MSG("ignoring invalid value '~p' for "
+ "option '~s' of module '~s'",
+ [Val, Opt, Module]),
+ false;
+ _ ->
+ true
+ end;
+ L when is_list(L) ->
+ SOpts = str:join([[$', atom_to_list(A), $'] || A <- L], <<", ">>),
+ ?ERROR_MSG("ignoring unknown option '~s' for module '~s',"
+ " available options are: ~s", [Opt, Module, SOpts]),
+ false;
+ {'EXIT', {undef, _}} ->
+ ?WARNING_MSG("module '~s' doesn't export mod_opt_type/1",
+ [Module]),
+ true
+ end;
+ (Junk) ->
+ ?ERROR_MSG("failed to understand option ~p for module '~s'",
+ [Junk, Module]),
+ false
+ end, Opts).
+
+-spec v_db(db_type() | internal) -> db_type().
v_db(odbc) -> odbc;
v_db(internal) -> mnesia;
v_db(mnesia) -> mnesia;
v_db(riak) -> riak.
--spec db_type(opts()) -> odbc | mnesia | riak.
+-spec db_type(opts()) -> db_type().
db_type(Opts) ->
db_type(global, Opts).
--spec db_type(binary() | global, atom() | opts()) -> odbc | mnesia | riak.
+-spec db_type(binary() | global, atom() | opts()) -> db_type().
db_type(Host, Module) when is_atom(Module) ->
get_module_opt(Host, Module, db_type, fun v_db/1, default_db(Host));
db_type(Host, Opts) when is_list(Opts) ->
get_opt(db_type, Opts, fun v_db/1, default_db(Host)).
--spec default_db(binary() | global) -> odbc | mnesia | riak.
+-spec default_db(binary() | global) -> db_type().
default_db(Host) ->
ejabberd_config:get_option({default_db, Host}, fun v_db/1, mnesia).
is_loaded(Host, Module) ->
ets:member(ejabberd_modules, {Module, Host}).
+
+opt_type(default_db) -> fun v_db/1;
+opt_type(modules) -> fun (L) when is_list(L) -> L end;
+opt_type(_) -> [default_db, modules].
process_sm_iq/3, get_local_commands/5,
get_local_identity/5, get_local_features/5,
get_sm_commands/5, get_sm_identity/5, get_sm_features/5,
- ping_item/4, ping_command/4]).
+ ping_item/4, ping_command/4, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
true -> {error, ?ERR_BAD_REQUEST}
end;
ping_command(Acc, _From, _To, _Request) -> Acc.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(report_commands_node) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(_) -> [iqdisc, report_commands_node].
-include("logger.hrl").
--export([start/2, stop/1,
- %% Node
- compile/1,
- get_cookie/0,
- remove_node/1,
- export2odbc/2,
- %% Accounts
- set_password/3,
- check_password_hash/4,
- delete_old_users/1,
- delete_old_users_vhost/2,
- ban_account/3,
- num_active_users/2,
- %% Sessions
- num_resources/2,
- resource_num/3,
- kick_session/4,
- status_num/2, status_num/1,
- status_list/2, status_list/1,
- connected_users_info/0,
- connected_users_vhost/1,
- set_presence/7,
- user_sessions_info/2,
- %% Vcard
- set_nickname/3,
- get_vcard/3,
- get_vcard/4,
- get_vcard_multi/4,
- set_vcard/4,
- set_vcard/5,
- %% Roster
- add_rosteritem/7,
- delete_rosteritem/4,
- process_rosteritems/5,
- get_roster/2,
- push_roster/3,
- push_roster_all/1,
- push_alltoall/2,
- %% mod_last
- get_last/2,
- %% mod_private
- private_get/4,
- private_set/3,
- %% mod_shared_roster
- srg_create/5,
- srg_delete/2,
- srg_list/1,
- srg_get_info/2,
- srg_get_members/2,
- srg_user_add/4,
- srg_user_del/4,
- %% Stanza
- send_message/5,
- send_stanza_c2s/4,
- privacy_set/3,
- %% Stats
- stats/1, stats/2
- ]).
+-export([start/2, stop/1, compile/1, get_cookie/0,
+ remove_node/1, export2odbc/2, set_password/3,
+ check_password_hash/4, delete_old_users/1,
+ delete_old_users_vhost/2, ban_account/3,
+ num_active_users/2, num_resources/2, resource_num/3,
+ kick_session/4, status_num/2, status_num/1,
+ status_list/2, status_list/1, connected_users_info/0,
+ connected_users_vhost/1, set_presence/7,
+ user_sessions_info/2, set_nickname/3, get_vcard/3,
+ get_vcard/4, get_vcard_multi/4, set_vcard/4,
+ set_vcard/5, add_rosteritem/7, delete_rosteritem/4,
+ process_rosteritems/5, get_roster/2, push_roster/3,
+ push_roster_all/1, push_alltoall/2, get_last/2,
+ private_get/4, private_set/3, srg_create/5,
+ srg_delete/2, srg_list/1, srg_get_info/2,
+ srg_get_members/2, srg_user_add/4, srg_user_del/4,
+ send_message/5, send_stanza_c2s/4, privacy_set/3,
+ stats/1, stats/2, mod_opt_type/1]).
-include("ejabberd.hrl").
not is_regexp_match(String, ejabberd_regexp:sh_to_awk(Glob));
is_glob_match(String, Glob) ->
is_regexp_match(String, ejabberd_regexp:sh_to_awk(Glob)).
+
+mod_opt_type(module_resource) -> fun (A) -> A end;
+mod_opt_type(_) -> [module_resource].
-behaviour(gen_mod).
--export([start/2,
- init/0,
- stop/1,
- export/1,
- import/1,
- import/3,
- announce/3,
- send_motd/1,
- disco_identity/5,
- disco_features/5,
- disco_items/5,
- send_announcement_to_all/3,
- announce_commands/4,
- announce_items/4]).
+-export([start/2, init/0, stop/1, export/1, import/1,
+ import/3, announce/3, send_motd/1, disco_identity/5,
+ disco_features/5, disco_items/5,
+ send_announcement_to_all/3, announce_commands/4,
+ announce_items/4, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{'2i', [{<<"server">>, S}]}]);
import(_, _, _) ->
pass.
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(_) -> [access, db_type].
-protocol({xep, 191, '1.2'}).
-export([start/2, stop/1, process_iq/3,
- process_iq_set/4, process_iq_get/5]).
+ process_iq_set/4, process_iq_get/5, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
end;
{'EXIT', _} -> error
end.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [iqdisc].
-export([init/1, handle_info/2, handle_call/3,
handle_cast/2, terminate/2, code_change/3]).
-%% hook handlers
-export([user_send_packet/3, user_receive_packet/4,
c2s_presence_in/2, c2s_filter_packet/6,
- c2s_broadcast_recipients/6]).
+ c2s_broadcast_recipients/6, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ok
end,
import_next(LServer, DBType, ets:next(caps_features_tmp, NodePair)).
+
+mod_opt_type(cache_life_time) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(cache_size) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(_) ->
+ [cache_life_time, cache_size, db_type].
-export([start/2,
stop/1]).
-%% Hooks:
--export([user_send_packet/3,
- user_receive_packet/4,
- iq_handler2/3,
- iq_handler1/3,
- remove_connection/4,
- is_carbon_copy/1]).
+-export([user_send_packet/3, user_receive_packet/4,
+ iq_handler2/3, iq_handler1/3, remove_connection/4,
+ is_carbon_copy/1, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
list(User, Server)->
mnesia:dirty_select(?TABLE, [{#carboncopy{us = {User, Server}, resource = '$2', version = '$3'}, [], [{{'$2','$3'}}]}]).
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [iqdisc].
-behavior(gen_mod).
--export([start/2, stop/1, add_stream_feature/2, filter_presence/2,
- filter_chat_states/2]).
+-export([start/2, stop/1, add_stream_feature/2,
+ filter_presence/2, filter_chat_states/2,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
{stop, send}
end;
filter_chat_states(Action, _Stanza) -> Action.
+
+mod_opt_type(drop_chat_states) ->
+ fun (true) -> true;
+ (false) -> false
+ end;
+mod_opt_type(queue_presence) ->
+ fun (true) -> true;
+ (false) -> false
+ end;
+mod_opt_type(_) -> [drop_chat_states, queue_presence].
get_local_features/5, get_local_items/5,
adhoc_local_items/4, adhoc_local_commands/4,
get_sm_identity/5, get_sm_features/5, get_sm_items/5,
- adhoc_sm_items/4, adhoc_sm_commands/4]).
+ adhoc_sm_items/4, adhoc_sm_commands/4, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
end;
set_sm_form(_User, _Server, _Node, _Request, _Fields) ->
{error, ?ERR_SERVICE_UNAVAILABLE}.
+
+mod_opt_type(_) -> [].
-module(mod_configure2).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_mod).
--export([start/2, stop/1, process_local_iq/3]).
+-export([start/2, stop/1, process_local_iq/3,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
%%process_get({xmlelement, Name, Attrs, SubEls}) ->
%% {result, };
process_get(_) -> {error, ?ERR_BAD_REQUEST}.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [iqdisc].
+
+opt_type(registration_watchers) ->
+ fun (JIDs) when is_list(JIDs) ->
+ lists:map(fun (J) ->
+ #xmlel{name = <<"jid">>, attrs = [],
+ children =
+ [{xmlcdata, iolist_to_binary(J)}]}
+ end,
+ JIDs)
+ end;
+opt_type(welcome_message) ->
+ fun ({Subj, Body}) ->
+ {iolist_to_binary(Subj), iolist_to_binary(Body)}
+ end;
+opt_type(_) -> [registration_watchers, welcome_message].
get_sm_identity/5, get_sm_features/5, get_sm_items/5,
get_info/5, register_feature/2, unregister_feature/2,
register_extra_domain/2, unregister_extra_domain/2,
- transform_module_options/1]).
+ transform_module_options/1, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
children = [{xmlcdata, Value}]}
end,
Values).
+
+mod_opt_type(extra_domains) ->
+ fun (Hs) -> [iolist_to_binary(H) || H <- Hs] end;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(server_info) ->
+ fun (L) ->
+ lists:map(fun (Opts) ->
+ Mods = proplists:get_value(modules, Opts, all),
+ Name = proplists:get_value(name, Opts, <<>>),
+ URLs = proplists:get_value(urls, Opts, []),
+ {Mods, Name, URLs}
+ end,
+ L)
+ end;
+mod_opt_type(_) -> [extra_domains, iqdisc, server_info].
-export([start_link/2, start/2, stop/1,
do_client_version/3]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
Values_string2 = iolist_to_binary(Values_string1),
?INFO_MSG("Information of the client: ~s~s",
[ToS, Values_string2]).
+
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(_) -> [host].
%% API
-export([start_link/2, start/2, stop/1, c2s_auth_result/4, check_bl_c2s/3]).
-%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3]).
+-export([init/1, handle_call/3, handle_cast/2,
+ handle_info/2, terminate/2, code_change/3,
+ mod_opt_type/1]).
-include_lib("stdlib/include/ms_transform.hrl").
-include("ejabberd.hrl").
format_date({{Year, Month, Day}, {Hour, Minute, Second}}) ->
io_lib:format("~2..0w:~2..0w:~2..0w ~2..0w.~2..0w.~4..0w",
[Hour, Minute, Second, Day, Month, Year]).
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(c2s_auth_ban_lifetime) ->
+ fun (T) when is_integer(T), T > 0 -> T end;
+mod_opt_type(c2s_max_auth_failures) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(_) ->
+ [access, c2s_auth_ban_lifetime, c2s_max_auth_failures].
-behaviour(gen_mod).
--export([start/2, stop/1, process/2]).
+-export([start/2, stop/1, process/2, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
%% of actually migrating data, let's just destroy the table
mnesia:delete_table(http_bind)
end.
+
+mod_opt_type(max_inactivity) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(max_pause) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(_) -> [max_inactivity, max_pause].
%% request_handlers callbacks
-export([process/2]).
-%% ejabberd_hooks callbacks
--export([reopen_log/1]).
+-export([reopen_log/1, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ip_to_string(Address) when size(Address) == 8 ->
Parts = lists:map(fun (Int) -> io_lib:format("~.16B", [Int]) end, tuple_to_list(Address)),
string:to_lower(lists:flatten(join(Parts, ":"))).
+
+mod_opt_type(accesslog) -> fun iolist_to_binary/1;
+mod_opt_type(content_types) ->
+ fun (L) when is_list(L) -> L end;
+mod_opt_type(custom_headers) ->
+ fun (L) when is_list(L) -> L end;
+mod_opt_type(default_content_type) ->
+ fun iolist_to_binary/1;
+mod_opt_type(directory_indices) ->
+ fun (L) when is_list(L) -> L end;
+mod_opt_type(docroot) -> fun (A) -> A end;
+mod_opt_type(_) ->
+ [accesslog, content_types, custom_headers,
+ default_content_type, directory_indices, docroot].
-export([update_bl_c2s/0]).
-%% Hooks:
--export([is_ip_in_c2s_blacklist/3]).
+-export([is_ip_in_c2s_blacklist/3, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
%% - For now, we do not kick user already logged on a given IP after
%% we update the blacklist.
+
+mod_opt_type(_) -> [].
-export([start_link/2, start/2, stop/1, export/1, import/1,
import/3, closed_connection/3, get_connection_params/3]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ejabberd_riak:put(R, irc_custom_schema());
import(_, _, _) ->
pass.
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(default_encoding) ->
+ fun iolist_to_binary/1;
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(_) ->
+ [access, db_type, default_encoding, host].
-module(mod_last).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-protocol({xep, 12, '2.0'}).
-behaviour(gen_mod).
-export([start/2, stop/1, process_local_iq/3, export/1,
- process_sm_iq/3, on_presence_update/4, import/1, import/3,
- store_last_info/4, get_last_info/2, remove_user/2,
- transform_options/1]).
+ process_sm_iq/3, on_presence_update/4, import/1,
+ import/3, store_last_info/4, get_last_info/2,
+ remove_user/2, transform_options/1, mod_opt_type/1,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{node_start, now_to_seconds(Now)}|Opts];
transform_options(Opt, Opts) ->
[Opt|Opts].
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [db_type, iqdisc].
+
+opt_type(node_start) ->
+ fun (S) when is_integer(S), S >= 0 -> S end;
+opt_type(_) -> [node_start].
import/3,
can_use_nick/4]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{'2i', [{<<"nick_host">>, {Nick, Host}}]}]);
import(_, _, _) ->
pass.
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(access_admin) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(access_create) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(access_persistent) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(default_room_options) ->
+ fun (L) when is_list(L) -> L end;
+mod_opt_type(history_size) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(max_room_id) ->
+ fun (infinity) -> infinity;
+ (I) when is_integer(I), I > 0 -> I
+ end;
+mod_opt_type(persist_history) -> fun (X) -> X end;
+mod_opt_type(room_shaper) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(_) ->
+ [access, access_admin, access_create, access_persistent,
+ db_type, default_room_options, history_size, host,
+ max_room_id, persist_history, room_shaper].
-behaviour(gen_mod).
--export([
- start/2, stop/1, % gen_mod API
- muc_online_rooms/1,
- muc_unregister_nick/1,
- create_room/3, destroy_room/3,
+-export([start/2, stop/1, muc_online_rooms/1,
+ muc_unregister_nick/1, create_room/3, destroy_room/3,
create_rooms_file/1, destroy_rooms_file/1,
rooms_unused_list/2, rooms_unused_destroy/2,
- get_user_rooms/2,
- get_room_occupants/2,
- get_room_occupants_number/2,
- send_direct_invitation/4,
- change_room_option/4,
- get_room_options/2,
- set_room_affiliation/4,
- get_room_affiliations/2,
- web_menu_main/2, web_page_main/2, % Web Admin API
- web_menu_host/3, web_page_host/3
- ]).
+ get_user_rooms/2, get_room_occupants/2,
+ get_room_occupants_number/2, send_direct_invitation/4,
+ change_room_option/4, get_room_options/2,
+ set_room_affiliation/4, get_room_affiliations/2,
+ web_menu_main/2, web_page_main/2, web_menu_host/3,
+ web_page_host/3, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
find_host(list_to_binary(ServerHost));
find_host(ServerHost) ->
gen_mod:get_module_opt_host(ServerHost, mod_muc, <<"conference.@HOST@">>).
+
+mod_opt_type(_) -> [].
-module(mod_muc_log).
+-behaviour(ejabberd_config).
+
-author('badlop@process-one.net').
-behaviour(gen_server).
-export([start_link/2, start/2, stop/1, transform_module_options/1,
check_access_log/2, add_to_log/5]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
fjoin(FileList) ->
list_to_binary(filename:join([binary_to_list(File) || File <- FileList])).
+
+mod_opt_type(access_log) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(cssfile) -> fun iolist_to_binary/1;
+mod_opt_type(dirname) ->
+ fun (room_jid) -> room_jid;
+ (room_name) -> room_name
+ end;
+mod_opt_type(dirtype) ->
+ fun (subdirs) -> subdirs;
+ (plain) -> plain
+ end;
+mod_opt_type(file_format) ->
+ fun (html) -> html;
+ (plaintext) -> plaintext
+ end;
+mod_opt_type(file_permissions) ->
+ fun (SubOpts) ->
+ F = fun ({mode, Mode}, {_M, G}) -> {Mode, G};
+ ({group, Group}, {M, _G}) -> {M, Group}
+ end,
+ lists:foldl(F, {644, 33}, SubOpts)
+ end;
+mod_opt_type(outdir) -> fun iolist_to_binary/1;
+mod_opt_type(spam_prevention) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(timezone) ->
+ fun (local) -> local;
+ (universal) -> universal
+ end;
+mod_opt_type(top_link) ->
+ fun ([{S1, S2}]) ->
+ {iolist_to_binary(S1), iolist_to_binary(S2)}
+ end;
+mod_opt_type(_) ->
+ [access_log, cssfile, dirname, dirtype, file_format,
+ file_permissions, outdir, spam_prevention, timezone,
+ top_link].
+
+opt_type(language) -> fun iolist_to_binary/1;
+opt_type(_) -> [language].
-export([init/1, handle_info/2, handle_call/3,
handle_cast/2, terminate/2, code_change/3]).
--export([purge_loop/1]).
+-export([purge_loop/1, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
stj(String) -> jlib:string_to_jid(String).
jts(String) -> jlib:jid_to_string(String).
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(limits) ->
+ fun (A) when is_list(A) -> A end;
+mod_opt_type(_) -> [access, host, limits].
webadmin_user/4,
webadmin_user_parse_query/5]).
-%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
- handle_info/2, terminate/2, code_change/3]).
+ handle_info/2, terminate/2, code_change/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{i, TS}, {'2i', [{<<"us">>, US}]}]);
import(_, _, _) ->
pass.
+
+mod_opt_type(access_max_user_messages) ->
+ fun (A) -> A end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(store_empty_body) ->
+ fun (V) when is_boolean(V) -> V end;
+mod_opt_type(_) ->
+ [access_max_user_messages, db_type, store_empty_body].
-export([init/1, terminate/2, handle_call/3,
handle_cast/2, handle_info/2, code_change/3]).
-%% Hook callbacks
-export([iq_ping/3, user_online/3, user_offline/3,
- user_send/3]).
+ user_send/3, mod_opt_type/1]).
-record(state,
{host = <<"">>,
receive {timeout, TRef, _} -> ok after 0 -> ok end;
_ -> ok
end.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(ping_interval) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(send_pings) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(timeout_action) ->
+ fun (none) -> none;
+ (kill) -> kill
+ end;
+mod_opt_type(_) ->
+ [iqdisc, ping_interval, send_pings, timeout_action].
-behavior(gen_mod).
--export([start/2, stop/1, check_packet/6]).
+-export([start/2, stop/1, check_packet/6,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
read(K) -> get({pres_counter, K}).
write(K, V) -> put({pres_counter, K}, V).
+
+mod_opt_type(count) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(interval) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(_) -> [count, interval].
raw_to_item/1, is_list_needdb/1, updated_list/3,
item_to_xml/1, get_user_lists/2, import/3]).
-%% For mod_blocking
-export([sql_add_privacy_list/2,
sql_get_default_privacy_list/2,
sql_get_default_privacy_list_t/1,
sql_get_privacy_list_data/3,
sql_get_privacy_list_data_by_id_t/1,
sql_get_privacy_list_id_t/2,
- sql_set_default_privacy_list/2,
- sql_set_privacy_list/2, privacy_schema/0]).
+ sql_set_default_privacy_list/2, sql_set_privacy_list/2,
+ privacy_schema/0, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ejabberd_riak:put(P, privacy_schema());
import(_, _, _) ->
pass.
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [db_type, iqdisc].
-behaviour(gen_mod).
-export([start/2, stop/1, process_sm_iq/3, import/3,
- remove_user/2, get_data/2, export/1, import/1]).
+ remove_user/2, get_data/2, export/1, import/1,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[{'2i', [{<<"us">>, {LUser, LServer}}]}]);
import(_, _, _) ->
pass.
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [db_type, iqdisc].
%% supervisor callbacks.
-export([init/1]).
-%% API.
--export([start_link/2]).
+-export([start_link/2, mod_opt_type/1]).
-define(PROCNAME, ejabberd_mod_proxy65).
{ok,
{{one_for_one, 10, 1},
[StreamManager, StreamSupervisor, Service]}}.
+
+mod_opt_type(_) -> [].
-export([init/1, handle_info/2, handle_call/3,
handle_cast/2, terminate/2, code_change/3]).
-%% API.
--export([start_link/2, add_listener/2, transform_module_options/1,
- delete_listener/1]).
+-export([start_link/2, add_listener/2,
+ transform_module_options/1, delete_listener/1,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
{ok, Addr} -> Addr;
{error, _} -> {127, 0, 0, 1}
end.
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(hostname) -> fun iolist_to_binary/1;
+mod_opt_type(ip) ->
+ fun (S) ->
+ {ok, Addr} =
+ inet_parse:address(binary_to_list(iolist_to_binary(S))),
+ Addr
+ end;
+mod_opt_type(name) -> fun iolist_to_binary/1;
+mod_opt_type(port) ->
+ fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
+mod_opt_type(_) ->
+ [access, host, hostname, ip, name, port].
-export([init/1, handle_info/2, handle_call/3,
handle_cast/2, terminate/2, code_change/3]).
-%% API.
-export([start_link/2, register_stream/1,
- unregister_stream/1, activate_stream/4]).
+ unregister_stream/1, activate_stream/4,
+ mod_opt_type/1]).
-record(state, {max_connections = infinity :: non_neg_integer() | infinity}).
{atomic, false} -> false;
_ -> error
end.
+
+mod_opt_type(max_connections) ->
+ fun (I) when is_integer(I), I > 0 -> I;
+ (infinity) -> infinity
+ end;
+mod_opt_type(_) -> [max_connections].
wait_for_request/2, wait_for_activation/2,
stream_established/2]).
-%% API.
-export([start/2, stop/1, start_link/3, activate/2,
- relay/3, socket_type/0]).
+ relay/3, socket_type/0, mod_opt_type/1]).
-include("mod_proxy65.hrl").
if MaxRate1 == none; MaxRate2 == none -> none;
true -> lists:max([MaxRate1, MaxRate2])
end.
+
+mod_opt_type(auth_type) ->
+ fun (plain) -> plain;
+ (anonymous) -> anonymous
+ end;
+mod_opt_type(recbuf) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(shaper) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(sndbuf) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(_) -> [auth_type, recbuf, shaper, sndbuf].
handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-%% calls for parallel sending of last items
--export([send_loop/1]).
+-export([send_loop/1, mod_opt_type/1]).
-define(PROCNAME, ejabberd_mod_pubsub).
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
Error ->
Error
end.
+
+mod_opt_type(access_createnode) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(ignore_pep_from_offline) ->
+ fun (A) when is_boolean(A) -> A end;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(last_item_cache) ->
+ fun (A) when is_boolean(A) -> A end;
+mod_opt_type(max_items_node) ->
+ fun (A) when is_integer(A) andalso A >= 0 -> A end;
+mod_opt_type(nodetree) ->
+ fun (A) when is_binary(A) -> A end;
+mod_opt_type(pep_mapping) ->
+ fun (A) when is_list(A) -> A end;
+mod_opt_type(plugins) ->
+ fun (A) when is_list(A) -> A end;
+mod_opt_type(_) ->
+ [access_createnode, db_type, host,
+ ignore_pep_from_offline, iqdisc, last_item_cache,
+ max_items_node, nodetree, pep_mapping, plugins].
-module(mod_register).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-protocol({xep, 77, '2.4'}).
-export([start/2, stop/1, stream_feature_register/2,
unauthenticated_iq_register/4, try_register/5,
process_iq/3, send_registration_notifications/3,
- transform_options/1, transform_module_options/1]).
+ transform_options/1, transform_module_options/1,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
deny;
check_ip_access(IPAddress, IPAccess) ->
acl:match_rule(global, IPAccess, IPAddress).
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(access_from) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(captcha_protected) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(ip_access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(password_strength) ->
+ fun (N) when is_number(N), N >= 0 -> N end;
+mod_opt_type(registration_watchers) ->
+ fun (Ss) ->
+ [#jid{} = jlib:string_to_jid(iolist_to_binary(S))
+ || S <- Ss]
+ end;
+mod_opt_type(welcome_message) ->
+ fun (Opts) ->
+ S = proplists:get_value(subject, Opts, <<>>),
+ B = proplists:get_value(body, Opts, <<>>),
+ {iolist_to_binary(S), iolist_to_binary(B)}
+ end;
+mod_opt_type(_) ->
+ [access, access_from, captcha_protected, ip_access,
+ iqdisc, password_strength, registration_watchers,
+ welcome_message].
+
+opt_type(registration_timeout) ->
+ fun (TO) when is_integer(TO), TO > 0 -> TO;
+ (infinity) -> infinity;
+ (unlimited) -> infinity
+ end;
+opt_type(_) -> [registration_timeout].
-behaviour(gen_mod).
--export([start/2, stop/1, process/2]).
+-export([start/2, stop/1, process/2, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
<<"The passwords are different">>;
get_error_text({error, wrong_parameters}) ->
<<"Wrong parameters in the web formulary">>.
+
+mod_opt_type(_) -> [].
-behaviour(gen_mod).
--export([start/2, stop/1, process_iq/3, export/1, import/1,
- process_local_iq/3, get_user_roster/2, import/3,
- get_subscription_lists/3, get_roster/2,
+-export([start/2, stop/1, process_iq/3, export/1,
+ import/1, process_local_iq/3, get_user_roster/2,
+ import/3, get_subscription_lists/3, get_roster/2,
get_in_pending_subscriptions/3, in_subscription/6,
out_subscription/4, set_items/3, remove_user/2,
get_jid_info/4, item_to_xml/1, webadmin_page/3,
webadmin_user/4, get_versioning_feature/2,
roster_versioning_enabled/1, roster_version/2,
- record_to_string/1, groups_to_string/1]).
+ record_to_string/1, groups_to_string/1,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ejabberd_riak:put(RV, roster_version_schema());
import(_, _, _) ->
pass.
+
+mod_opt_type(access) ->
+ fun (A) when is_atom(A) -> A end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(managers) ->
+ fun (B) when is_list(B) -> B end;
+mod_opt_type(store_current_id) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(versioning) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(_) ->
+ [access, db_type, iqdisc, managers, store_current_id,
+ versioning].
-behaviour(gen_mod).
--export([start/2,
- stop/1,
- log_user_send/3,
- log_user_receive/4]).
+-export([start/2, stop/1, log_user_send/3,
+ log_user_receive/4, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
[FixedPacket]})
end,
Loggers).
+
+mod_opt_type(loggers) ->
+ fun (L) ->
+ lists:map(fun (S) ->
+ B = iolist_to_binary(S),
+ N = jlib:nameprep(B),
+ if N /= error -> N end
+ end,
+ L)
+ end;
+mod_opt_type(_) -> [loggers].
-behaviour(gen_mod).
--export([start/2, stop/1, item_to_xml/1, export/1, import/1,
- webadmin_menu/3, webadmin_page/3, get_user_roster/2,
- get_subscription_lists/3, get_jid_info/4, import/3,
- process_item/2, in_subscription/6, out_subscription/4,
- user_available/1, unset_presence/4, register_user/2,
- remove_user/2, list_groups/1, create_group/2,
- create_group/3, delete_group/2, get_group_opts/2,
- set_group_opts/3, get_group_users/2,
- get_group_explicit_users/2, is_user_in_group/3,
- add_user_to_group/3, remove_user_from_group/3]).
+-export([start/2, stop/1, item_to_xml/1, export/1,
+ import/1, webadmin_menu/3, webadmin_page/3,
+ get_user_roster/2, get_subscription_lists/3,
+ get_jid_info/4, import/3, process_item/2,
+ in_subscription/6, out_subscription/4, user_available/1,
+ unset_presence/4, register_user/2, remove_user/2,
+ list_groups/1, create_group/2, create_group/3,
+ delete_group/2, get_group_opts/2, set_group_opts/3,
+ get_group_users/2, get_group_explicit_users/2,
+ is_user_in_group/3, add_user_to_group/3,
+ remove_user_from_group/3, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
{<<"group_host">>, {Group, Host}}]}]);
import(_, _, _) ->
pass.
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(_) -> [db_type].
%%%-------------------------------------------------------------------
-module(mod_shared_roster_ldap).
+-behaviour(ejabberd_config).
+
-behaviour(gen_server).
-behaviour(gen_mod).
-export([get_user_roster/2, get_subscription_lists/3,
get_jid_info/4, process_item/2, in_subscription/6,
- out_subscription/4]).
+ out_subscription/4, mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
NewF = iolist_to_binary(F),
{ok, _} = eldap_filter:parse(NewF),
NewF.
+
+mod_opt_type(deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+mod_opt_type(ldap_backups) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+mod_opt_type(ldap_base) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+mod_opt_type(ldap_encrypt) ->
+ fun (tls) -> tls;
+ (starttls) -> starttls;
+ (none) -> none
+ end;
+mod_opt_type(ldap_password) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_port) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_rootdn) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_servers) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+mod_opt_type(ldap_tls_cacertfile) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_tls_certfile) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_tls_depth) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+mod_opt_type(ldap_tls_verify) ->
+ fun (hard) -> hard;
+ (soft) -> soft;
+ (false) -> false
+ end;
+mod_opt_type(ldap_auth_check) ->
+ fun (on) -> true;
+ (off) -> false;
+ (false) -> false;
+ (true) -> true
+ end;
+mod_opt_type(ldap_filter) -> fun check_filter/1;
+mod_opt_type(ldap_gfilter) -> fun check_filter/1;
+mod_opt_type(ldap_group_cache_size) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_group_cache_validity) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_groupattr) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_groupdesc) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_memberattr) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_memberattr_format) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_memberattr_format_re) ->
+ fun (S) ->
+ Re = iolist_to_binary(S), {ok, MP} = re:compile(Re), MP
+ end;
+mod_opt_type(ldap_rfilter) -> fun check_filter/1;
+mod_opt_type(ldap_ufilter) -> fun check_filter/1;
+mod_opt_type(ldap_user_cache_size) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_user_cache_validity) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_userdesc) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_useruid) -> fun iolist_to_binary/1;
+mod_opt_type(_) ->
+ [ldap_auth_check, ldap_filter, ldap_gfilter,
+ ldap_group_cache_size, ldap_group_cache_validity,
+ ldap_groupattr, ldap_groupdesc, ldap_memberattr,
+ ldap_memberattr_format, ldap_memberattr_format_re,
+ ldap_rfilter, ldap_ufilter, ldap_user_cache_size,
+ ldap_user_cache_validity, ldap_userdesc, ldap_useruid,
+ 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].
+
+opt_type(ldap_filter) -> fun check_filter/1;
+opt_type(ldap_gfilter) -> fun check_filter/1;
+opt_type(ldap_group_cache_size) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(ldap_group_cache_validity) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(ldap_rfilter) -> fun check_filter/1;
+opt_type(ldap_ufilter) -> fun check_filter/1;
+opt_type(ldap_user_cache_size) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(ldap_user_cache_validity) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+opt_type(_) ->
+ [ldap_filter, ldap_gfilter, ldap_group_cache_size,
+ ldap_group_cache_validity, ldap_rfilter, ldap_ufilter,
+ ldap_user_cache_size, ldap_user_cache_validity].
-behaviour(gen_mod).
-export([start/2, stop/1, process_local_iq/3,
- process_sm_iq/3]).
+ process_sm_iq/3, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
end.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [iqdisc].
%% API
-export([start/2, stop/1, make_response/2, is_my_host/1, at_my_host/1]).
-%% esip_callbacks
--export([data_in/2, data_out/2, message_in/2, message_out/2,
- request/2, request/3, response/2, locate/1]).
+-export([data_in/2, data_out/2, message_in/2,
+ message_out/2, request/2, request/3, response/2,
+ locate/1, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
is_my_host(LServer) ->
gen_mod:is_loaded(LServer, ?MODULE).
+
+mod_opt_type(always_record_route) ->
+ fun (true) -> true;
+ (false) -> false
+ end;
+mod_opt_type(flow_timeout_tcp) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(flow_timeout_udp) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(record_route) ->
+ fun (IOList) ->
+ S = iolist_to_binary(IOList),
+ #uri{} = esip:decode_uri(S)
+ end;
+mod_opt_type(routes) ->
+ fun (L) ->
+ lists:map(fun (IOList) ->
+ S = iolist_to_binary(IOList),
+ #uri{} = esip:decode_uri(S)
+ end,
+ L)
+ end;
+mod_opt_type(via) ->
+ fun (L) ->
+ lists:map(fun (Opts) ->
+ Type = proplists:get_value(type, Opts),
+ Host = proplists:get_value(host, Opts),
+ Port = proplists:get_value(port, Opts),
+ true = (Type == tcp) or (Type == tls) or
+ (Type == udp),
+ true = is_binary(Host) and (Host /= <<"">>),
+ true = is_integer(Port) and (Port > 0) and
+ (Port < 65536)
+ or (Port == undefined),
+ {Type, {Host, Port}}
+ end,
+ L)
+ end;
+mod_opt_type(_) ->
+ [always_record_route, flow_timeout_tcp,
+ flow_timeout_udp, record_route, routes, via].
%%%-------------------------------------------------------------------
-module(mod_sip_proxy).
+-behaviour(ejabberd_config).
+
-define(GEN_FSM, p1_fsm).
-behaviour(?GEN_FSM).
%% API
-export([start/2, start_link/2, route/3, route/4]).
-%% gen_fsm callbacks
--export([init/1, wait_for_request/2, wait_for_response/2,
- handle_event/3, handle_sync_event/4,
- handle_info/3, terminate/3, code_change/4]).
+-export([init/1, wait_for_request/2,
+ wait_for_response/2, handle_event/3,
+ handle_sync_event/4, handle_info/3, terminate/3,
+ code_change/4, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
error -> S;
S1 -> S1
end.
+
+opt_type(domain_certfile) -> fun iolist_to_binary/1;
+opt_type(shared_key) -> fun (V) -> V end;
+opt_type(_) -> [domain_certfile, shared_key].
-behaviour(gen_mod).
--export([start/2, stop/1, process_local_iq/3]).
+-export([start/2, stop/1, process_local_iq/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
SNode -> Node;
_ -> search_running_node(SNode, Nodes)
end.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [iqdisc].
-behaviour(gen_mod).
--export([start/2, stop/1, process_local_iq/3]).
+-export([start/2, stop/1, process_local_iq/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
sign(N) when N < 0 -> <<"-">>;
sign(_) -> <<"+">>.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(_) -> [iqdisc].
-export([start/2, init/3, stop/1, get_sm_features/5,
process_local_iq/3, process_sm_iq/3, reindex_vcards/0,
- remove_user/2, export/1, import/1, import/3]).
+ remove_user/2, export/1, import/1, import/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ok;
import(_, _, _) ->
pass.
+
+mod_opt_type(allow_return_all) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(matches) ->
+ fun (infinity) -> infinity;
+ (I) when is_integer(I), I > 0 -> I
+ end;
+mod_opt_type(search) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(search_all_hosts) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(_) ->
+ [allow_return_all, db_type, host, iqdisc, matches,
+ search, search_all_hosts].
-module(mod_vcard_ldap).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
-behaviour(gen_server).
-export([start/2, start_link/2, stop/1,
get_sm_features/5, process_local_iq/3, process_sm_iq/3,
- remove_user/1, route/4, transform_module_options/1]).
+ remove_user/1, route/4, transform_module_options/1,
+ mod_opt_type/1, opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
NewF = iolist_to_binary(F),
{ok, _} = eldap_filter:parse(NewF),
NewF.
+
+mod_opt_type(host) -> fun iolist_to_binary/1;
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(ldap_filter) -> fun check_filter/1;
+mod_opt_type(ldap_search_fields) ->
+ fun (Ls) ->
+ [{iolist_to_binary(S), iolist_to_binary(P)}
+ || {S, P} <- Ls]
+ end;
+mod_opt_type(ldap_search_reported) ->
+ fun (Ls) ->
+ [{iolist_to_binary(S), iolist_to_binary(P)}
+ || {S, P} <- Ls]
+ end;
+mod_opt_type(ldap_uids) ->
+ fun (Us) ->
+ lists:map(fun ({U, P}) ->
+ {iolist_to_binary(U), iolist_to_binary(P)};
+ ({U}) -> {iolist_to_binary(U)}
+ end,
+ Us)
+ end;
+mod_opt_type(ldap_vcard_map) ->
+ fun (Ls) ->
+ lists:map(fun ({S, [{P, L}]}) ->
+ {iolist_to_binary(S), iolist_to_binary(P),
+ [iolist_to_binary(E) || E <- L]}
+ end,
+ Ls)
+ end;
+mod_opt_type(matches) ->
+ fun (infinity) -> 0;
+ (I) when is_integer(I), I > 0 -> I
+ end;
+mod_opt_type(search) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+mod_opt_type(ldap_backups) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+mod_opt_type(ldap_base) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_deref_aliases) ->
+ fun (never) -> never;
+ (searching) -> searching;
+ (finding) -> finding;
+ (always) -> always
+ end;
+mod_opt_type(ldap_encrypt) ->
+ fun (tls) -> tls;
+ (starttls) -> starttls;
+ (none) -> none
+ end;
+mod_opt_type(ldap_password) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_port) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+mod_opt_type(ldap_rootdn) -> fun iolist_to_binary/1;
+mod_opt_type(ldap_servers) ->
+ fun (L) -> [iolist_to_binary(H) || H <- L] end;
+mod_opt_type(ldap_tls_cacertfile) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_tls_certfile) ->
+ fun iolist_to_binary/1;
+mod_opt_type(ldap_tls_depth) ->
+ fun (I) when is_integer(I), I >= 0 -> I end;
+mod_opt_type(ldap_tls_verify) ->
+ fun (hard) -> hard;
+ (soft) -> soft;
+ (false) -> false
+ end;
+mod_opt_type(_) ->
+ [host, iqdisc, ldap_filter, ldap_search_fields,
+ ldap_search_reported, ldap_uids, ldap_vcard_map,
+ matches, search, 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].
+
+opt_type(ldap_filter) -> fun check_filter/1;
+opt_type(ldap_uids) ->
+ fun (Us) ->
+ lists:map(fun ({U, P}) ->
+ {iolist_to_binary(U), iolist_to_binary(P)};
+ ({U}) -> {iolist_to_binary(U)}
+ end,
+ Us)
+ end;
+opt_type(_) ->
+ [ldap_filter, ldap_uids, 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].
%% gen_mod callbacks
-export([start/2, stop/1]).
-%% hooks
--export([update_presence/3, vcard_set/3, export/1, import/1, import/3]).
+-export([update_presence/3, vcard_set/3, export/1,
+ import/1, import/3, mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ejabberd_riak:put(R, vcard_xupdate_schema());
import(_, _, _) ->
pass.
+
+mod_opt_type(db_type) -> fun gen_mod:v_db/1;
+mod_opt_type(_) -> [db_type].
-behaviour(gen_mod).
--export([start/2, stop/1, process_local_iq/3]).
+-export([start/2, stop/1, process_local_iq/3,
+ mod_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
OS = <<OSType/binary, " ", OSVersion/binary>>,
#xmlel{name = <<"os">>, attrs = [],
children = [{xmlcdata, OS}]}.
+
+mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
+mod_opt_type(show_os) ->
+ fun (B) when is_boolean(B) -> B end;
+mod_opt_type(_) -> [iqdisc, show_os].
-module(odbc_queries).
+-behaviour(ejabberd_config).
+
-author("mremond@process-one.net").
--export([get_db_type/0, update/5, update_t/4, sql_transaction/2,
- get_last/2, set_last_t/4, del_last/2,
- get_password/2, get_password_scram/2,
- set_password_t/3, set_password_scram_t/6,
- add_user/3, add_user_scram/6, del_user/2,
- del_user_return_password/3, list_users/1, list_users/2,
- users_number/1, users_number/2, add_spool_sql/2,
- add_spool/2, get_and_del_spool_msg_t/2, del_spool_msg/2,
- get_roster/2, get_roster_jid_groups/2,
+-export([get_db_type/0, update/5, update_t/4,
+ sql_transaction/2, get_last/2, set_last_t/4, del_last/2,
+ get_password/2, get_password_scram/2, set_password_t/3,
+ set_password_scram_t/6, add_user/3, add_user_scram/6,
+ del_user/2, del_user_return_password/3, list_users/1,
+ list_users/2, users_number/1, users_number/2,
+ add_spool_sql/2, add_spool/2, get_and_del_spool_msg_t/2,
+ del_spool_msg/2, get_roster/2, get_roster_jid_groups/2,
get_roster_groups/3, del_user_roster_t/2,
get_roster_by_jid/3, get_rostergroup_by_jid/3,
del_roster/3, del_roster_sql/2, update_roster/5,
update_roster_sql/4, roster_subscribe/4,
get_subscription/3, set_private_data/4,
- set_private_data_sql/3, get_private_data/3, get_private_data/2,
- del_user_private_storage/2, get_default_privacy_list/2,
+ set_private_data_sql/3, get_private_data/3,
+ get_private_data/2, del_user_private_storage/2,
+ get_default_privacy_list/2,
get_default_privacy_list_t/1, get_privacy_list_names/2,
get_privacy_list_names_t/1, get_privacy_list_id/3,
get_privacy_list_id_t/2, get_privacy_list_data/3,
- get_privacy_list_data_by_id/2, get_privacy_list_data_t/2,
+ get_privacy_list_data_by_id/2,
+ get_privacy_list_data_t/2,
get_privacy_list_data_by_id_t/1,
set_default_privacy_list/2,
- unset_default_privacy_list/2,
- remove_privacy_list/2,
- add_privacy_list/2,
- set_privacy_list/2,
- del_privacy_lists/3,
- set_vcard/26,
- get_vcard/2,
- escape/1,
- count_records_where/3,
- get_roster_version/2,
- set_roster_version/2]).
+ unset_default_privacy_list/2, remove_privacy_list/2,
+ add_privacy_list/2, set_privacy_list/2,
+ del_privacy_lists/3, set_vcard/26, get_vcard/2,
+ escape/1, count_records_where/3, get_roster_version/2,
+ set_roster_version/2, opt_type/1]).
%% We have only two compile time options for db queries:
%-define(generic, true).
<<"', '">>, Version, <<"'">>]).
-endif.
+
+opt_type(odbc_type) ->
+ fun (pgsql) -> pgsql;
+ (mysql) -> mysql;
+ (sqlite) -> sqlite;
+ (odbc) -> odbc
+ end;
+opt_type(pgsql_users_number_estimate) ->
+ fun (V) when is_boolean(V) -> V end;
+opt_type(_) -> [odbc_type, pgsql_users_number_estimate].
-module(shaper).
+-behaviour(ejabberd_config).
+
-author('alexey@process-one.net').
--export([start/0, new/1, new1/1, update/2, get_max_rate/1,
- transform_options/1, load_from_config/0]).
+-export([start/0, new/1, new1/1, update/2,
+ get_max_rate/1, transform_options/1, load_from_config/0,
+ opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
now_to_usec({MSec, Sec, USec}) ->
(MSec * 1000000 + Sec) * 1000000 + USec.
+
+opt_type(shaper) -> fun (V) -> V end;
+opt_type(_) -> [shaper].