Eldap_ID = misc:atom_to_binary(gen_mod:get_module_proc(Host, ?MODULE)),
Bind_Eldap_ID = misc:atom_to_binary(
gen_mod:get_module_proc(Host, bind_ejabberd_auth_ldap)),
- UIDsTemp = gen_mod:get_opt(
- {ldap_uids, Host}, [],
- 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, [{<<"uid">>, <<"%u">>}]),
+ UIDsTemp = ejabberd_config:get_option(
+ {ldap_uids, Host}, [{<<"uid">>, <<"%u">>}]),
UIDs = eldap_utils:uids_domain_subst(Host, UIDsTemp),
SubFilter = eldap_utils:generate_subfilter(UIDs),
- UserFilter = case gen_mod:get_opt(
- {ldap_filter, Host}, [],
- fun eldap_utils:check_filter/1, <<"">>) of
+ UserFilter = case ejabberd_config:get_option({ldap_filter, Host}, <<"">>) of
<<"">> ->
SubFilter;
F ->
SearchFilter = eldap_filter:do_sub(UserFilter,
[{<<"%u">>, <<"*">>}]),
{DNFilter, DNFilterAttrs} =
- gen_mod:get_opt({ldap_dn_filter, Host}, [],
- fun([{DNF, DNFA}]) ->
- NewDNFA = case DNFA of
- undefined ->
- [];
- _ ->
- [iolist_to_binary(A)
- || A <- DNFA]
- end,
- NewDNF = eldap_utils:check_filter(DNF),
- {NewDNF, NewDNFA}
- end, {undefined, []}),
- LocalFilter = gen_mod:get_opt(
- {ldap_local_filter, Host}, [], fun(V) -> V end),
+ ejabberd_config:get_option({ldap_dn_filter, Host}, {undefined, []}),
+ LocalFilter = ejabberd_config:get_option({ldap_local_filter, Host}),
#state{host = Host, eldap_id = Eldap_ID,
bind_eldap_id = Bind_Eldap_ID,
servers = Cfg#eldap_config.servers,
XMPPVer = get_attr('xmpp:version', Attrs),
XMPPDomain = get_attr(to, Attrs),
{InBuf, Opts} = case gen_mod:get_module_opt(
- XMPPDomain,
- mod_bosh, prebind,
- fun(B) when is_boolean(B) -> B end,
- false) of
+ XMPPDomain, mod_bosh, prebind, false) of
true ->
JID = make_random_jid(XMPPDomain),
{buf_new(XMPPDomain), [{jid, JID} | Opts2]};
Opts),
Inactivity = gen_mod:get_module_opt(XMPPDomain,
mod_bosh, max_inactivity,
- fun(I) when is_integer(I), I>0 -> I end,
?DEFAULT_INACTIVITY),
MaxConcat = gen_mod:get_module_opt(XMPPDomain, mod_bosh, max_concat,
- fun(unlimited) -> unlimited;
- (N) when is_integer(N), N>0 -> N
- end, unlimited),
+ unlimited),
ShapedReceivers = buf_new(XMPPDomain, ?MAX_SHAPED_REQUESTS_QUEUE_LEN),
State = #state{host = XMPPDomain, sid = SID, ip = IP,
xmpp_ver = XMPPVer, el_ibuf = InBuf,
end,
MaxPause = gen_mod:get_module_opt(State#state.host,
mod_bosh, max_pause,
- fun(I) when is_integer(I), I>0 -> I end,
?DEFAULT_MAXPAUSE),
Resp = #body{attrs =
[{sid, State#state.sid}, {wait, Wait},
buf_new(Host, unlimited).
buf_new(Host, Limit) ->
- QueueType = case gen_mod:get_module_opt(
- Host, mod_bosh, queue_type,
- mod_bosh:mod_opt_type(queue_type)) of
- undefined -> ejabberd_config:default_queue_type(Host);
- T -> T
- end,
+ QueueType = gen_mod:get_module_opt(
+ Host, mod_bosh, queue_type,
+ ejabberd_config:default_queue_type(Host)),
p1_queue:new(QueueType, Limit).
buf_in(Xs, Buf) ->
%% ejabberd_socket callbacks
-export([start/2, start_link/2, socket_type/0]).
%% ejabberd_config callbacks
--export([opt_type/1, transform_listen_option/2]).
+-export([opt_type/1, listen_opt_type/1, transform_listen_option/2]).
%% xmpp_stream_in callbacks
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
ejabberd_hooks:run_fold(c2s_handle_send, LServer, State, [Pkt, Result]).
init([State, Opts]) ->
- Access = gen_mod:get_opt(access, Opts, fun acl:access_rules_validator/1, all),
- Shaper = gen_mod:get_opt(shaper, Opts, fun acl:shaper_rules_validator/1, none),
+ Access = gen_mod:get_opt(access, Opts, all),
+ Shaper = gen_mod:get_opt(shaper, Opts, none),
TLSOpts1 = lists:filter(
fun({certfile, _}) -> true;
({ciphers, _}) -> true;
({dhfile, _}) -> true;
({cafile, _}) -> true;
+ ({protocol_options, _}) -> true;
(_) -> false
end, Opts),
- TLSOpts2 = case lists:keyfind(protocol_options, 1, Opts) of
- false -> TLSOpts1;
- {_, OptString} ->
- ProtoOpts = str:join(OptString, <<$|>>),
- [{protocol_options, ProtoOpts}|TLSOpts1]
- end,
- TLSOpts3 = case proplists:get_bool(tls_compression, Opts) of
- false -> [compression_none | TLSOpts2];
- true -> TLSOpts2
+ TLSOpts2 = case proplists:get_bool(tls_compression, Opts) of
+ false -> [compression_none | TLSOpts1];
+ true -> TLSOpts1
end,
TLSEnabled = proplists:get_bool(starttls, Opts),
TLSRequired = proplists:get_bool(starttls_required, Opts),
TLSVerify = proplists:get_bool(tls_verify, Opts),
Zlib = proplists:get_bool(zlib, Opts),
- State1 = State#{tls_options => TLSOpts3,
+ State1 = State#{tls_options => TLSOpts2,
tls_required => TLSRequired,
tls_enabled => TLSEnabled,
tls_verify => TLSVerify,
send_error(State, Pres, Err);
allow when Type == subscribe; Type == subscribed;
Type == unsubscribe; Type == unsubscribed ->
- Access = gen_mod:get_module_opt(LServer, mod_roster, access,
- fun(A) when is_atom(A) -> A end,
- all),
+ Access = gen_mod:get_module_opt(LServer, mod_roster, access, all),
MyBareJID = jid:remove_resource(JID),
case acl:match_rule(LServer, Access, MyBareJID) of
deny ->
[c2s_certfile, c2s_ciphers, c2s_cafile,
c2s_protocol_options, c2s_tls_compression, resource_conflict,
disable_sasl_mechanisms].
+
+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);
+listen_opt_type(ciphers) -> opt_type(c2s_ciphers);
+listen_opt_type(dhfile) -> opt_type(c2s_dhfile);
+listen_opt_type(cafile) -> opt_type(c2s_cafile);
+listen_opt_type(protocol_options) -> opt_type(c2s_protocol_options);
+listen_opt_type(tls_compression) -> opt_type(c2s_tls_compression);
+listen_opt_type(tls) -> fun(B) when is_boolean(B) -> B end;
+listen_opt_type(starttls) -> fun(B) when is_boolean(B) -> B end;
+listen_opt_type(starttls_required) -> fun(B) when is_boolean(B) -> B end;
+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;
+ (unlimited) -> infinity;
+ (infinity) -> infinity
+ end;
+listen_opt_type(max_fsm_queue) ->
+ fun(I) when is_integer(I), I>0 -> I end;
+listen_opt_type(O) ->
+ %% This hack should be removed in future releases: it is intended
+ %% for backward compatibility with ejabberd 17.01 or older
+ case mod_stream_mgmt:mod_opt_type(O) of
+ L when is_list(L) ->
+ [access, shaper, certfile, ciphers, dhfile, cafile,
+ protocol_options, tls, tls_compression, starttls,
+ starttls_required, tls_verify, zlib, max_fsm_queue] ++ L;
+ VFun ->
+ VFun
+ end.
execute_check_access(FromJID, #ejabberd_commands{access = AccessRefs} = Command, Arguments) ->
%% TODO Review: Do we have smarter / better way to check rule on other Host than global ?
Host = global,
- Rules = lists:map(fun({Mod, AccessName, Default}) ->
- gen_mod:get_module_opt(Host, Mod,
- AccessName, fun(A) -> A end, Default);
- (Default) ->
- Default
- end, AccessRefs),
+ Rules = lists:map(
+ fun({Mod, AccessName, Default}) ->
+ gen_mod:get_module_opt(Host, Mod, AccessName, Default);
+ (Default) ->
+ Default
+ end, AccessRefs),
case acl:any_rules_allowed(Host, Rules, FromJID) of
true ->
do_execute_command(Command, Arguments);
%% External exports
-export([start/2, start_link/2, become_controller/1,
socket_type/0, receive_headers/1, url_encode/1,
- transform_listen_option/2]).
+ transform_listen_option/2, listen_opt_type/1]).
-export([init/2, opt_type/1]).
TLSOpts1 = lists:filter(fun ({certfile, _}) -> true;
({ciphers, _}) -> true;
({dhfile, _}) -> true;
+ ({protocol_options, _}) -> true;
(_) -> false
end,
Opts),
- TLSOpts2 = case lists:keysearch(protocol_options, 1, Opts) of
- {value, {_, O}} ->
- [_|ProtocolOptions] = lists:foldl(
- fun(X, Acc) -> X ++ Acc end, [],
- [["|" | binary_to_list(Opt)] || Opt <- O, is_binary(Opt)]
- ),
- [{protocol_options, iolist_to_binary(ProtocolOptions)} | TLSOpts1];
- _ -> TLSOpts1
+ TLSOpts2 = case proplists:get_bool(tls_compression, Opts) of
+ false -> [compression_none | TLSOpts1];
+ true -> TLSOpts1
end,
- TLSOpts3 = case proplists:get_bool(tls_compression, Opts) of
- false -> [compression_none | TLSOpts2];
- true -> TLSOpts2
- end,
- TLSOpts = [verify_none | TLSOpts3],
+ TLSOpts = [verify_none | TLSOpts2],
{SockMod1, Socket1} = if TLSEnabled ->
inet:setopts(Socket, [{recbuf, 8192}]),
{ok, TLSSocket} = fast_tls:tcp_to_tls(Socket,
true -> [{[], ejabberd_xmlrpc}];
false -> []
end,
- DefinedHandlers = gen_mod:get_opt(
- request_handlers, Opts,
- fun(Hs) ->
- Hs1 = lists:map(fun
- ({Mod, Path}) when is_atom(Mod) -> {Path, Mod};
- ({Path, Mod}) -> {Path, Mod}
- end, Hs),
-
- Hs2 = [{str:tokens(
- iolist_to_binary(Path), <<"/">>),
- Mod} || {Path, Mod} <- Hs1],
- [{Path,
- case Mod of
- mod_http_bind -> mod_bosh;
- _ -> Mod
- end} || {Path, Mod} <- Hs2]
- end, []),
+ DefinedHandlers = gen_mod:get_opt(request_handlers, Opts, []),
RequestHandlers = DefinedHandlers ++ Captcha ++ Register ++
Admin ++ Bind ++ XMLRPC,
?DEBUG("S: ~p~n", [RequestHandlers]),
- DefaultHost = gen_mod:get_opt(default_host, Opts, fun(A) -> A end, undefined),
+ DefaultHost = gen_mod:get_opt(default_host, Opts, undefined),
{ok, RE} = re:compile(<<"^(?:\\[(.*?)\\]|(.*?))(?::(\\d+))?$">>),
- CustomHeaders = gen_mod:get_opt(custom_headers, Opts,
- fun expand_custom_headers/1,
- []),
+ CustomHeaders = gen_mod:get_opt(custom_headers, Opts, []),
?INFO_MSG("started: ~p", [{SockMod1, Socket1}]),
State = #state{sockmod = SockMod1,
fun (all) -> all;
(TPs) -> [iolist_to_binary(TP) || TP <- TPs] end;
opt_type(_) -> [trusted_proxies].
+
+listen_opt_type(tls) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(certfile) ->
+ fun iolist_to_binary/1;
+listen_opt_type(ciphers) ->
+ fun iolist_to_binary/1;
+listen_opt_type(dhfile) ->
+ fun iolist_to_binary/1;
+listen_opt_type(protocol_options) ->
+ fun(Options) -> str:join(Options, <<"|">>) end;
+listen_opt_type(tls_compression) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(captcha) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(register) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(web_admin) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(http_bind) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(xmlrpc) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(request_handlers) ->
+ fun(Hs) ->
+ Hs1 = lists:map(fun
+ ({Mod, Path}) when is_atom(Mod) -> {Path, Mod};
+ ({Path, Mod}) -> {Path, Mod}
+ end, Hs),
+ Hs2 = [{str:tokens(
+ iolist_to_binary(Path), <<"/">>),
+ Mod} || {Path, Mod} <- Hs1],
+ [{Path,
+ case Mod of
+ mod_http_bind -> mod_bosh;
+ _ -> Mod
+ end} || {Path, Mod} <- Hs2]
+ end;
+listen_opt_type(default_host) ->
+ fun(A) -> A end;
+listen_opt_type(custom_headers) ->
+ fun expand_custom_headers/1;
+listen_opt_type(_) ->
+ %% TODO
+ fun(A) -> A end.
Ls = ejabberd_config:get_option(listen, []),
Specs = lists:map(
fun({Port, Module, Opts}) ->
- maybe_start_sip(Module),
ets:insert(?MODULE, {Port, Module, Opts}),
{Port,
{?MODULE, start, [Port, Module, Opts]},
end.
start(Port, Module, Opts) ->
+ NewOpts = validate_module_options(Module, Opts),
%% Check if the module is an ejabberd listener or an independent listener
case Module:socket_type() of
- independent -> Module:start_listener(Port, Opts);
- _ -> start_dependent(Port, Module, Opts)
+ independent -> Module:start_listener(Port, NewOpts);
+ _ -> start_dependent(Port, Module, NewOpts)
end.
%% @spec(Port, Module, Opts) -> {ok, Pid} | {error, ErrorMessage}
%% It is only required to start the supervisor in some cases.
%% But it doesn't hurt to attempt to start it for any listener.
%% So, it's normal (and harmless) that in most cases this call returns: {error, {already_started, pid()}}
- maybe_start_sip(Module),
start_listener_sup(Port, Module, Opts).
start_module_sup(_Port, Module) ->
PortIP1 = {Port, IPT, Proto},
stop_listener(PortIP1, Module).
-
-maybe_start_sip(esip_socket) ->
- ejabberd:start_app(esip);
-maybe_start_sip(_) ->
- ok.
-
config_reloaded() ->
New = ejabberd_config:get_option(listen, []),
Old = ets:tab2list(?MODULE),
transform_options(Opt, Opts) ->
[Opt|Opts].
+-spec validate_module_options(module(), [{atom(), any()}]) -> [{atom(), any()}].
+validate_module_options(Module, Opts) ->
+ try Module:listen_opt_type('') of
+ _ ->
+ lists:filtermap(
+ fun({Opt, Val}) ->
+ case validate_module_option(Module, Opt, Val) of
+ {ok, NewVal} -> {true, {Opt, NewVal}};
+ error -> false
+ end
+ end, Opts)
+ catch _:undef ->
+ ?WARNING_MSG("module '~s' doesn't export listen_opt_type/1",
+ [Module]),
+ Opts
+ end.
+
+-spec validate_module_option(module(), atom(), any()) -> {ok, any()} | error.
+validate_module_option(Module, Opt, Val) ->
+ case Module:listen_opt_type(Opt) of
+ VFun when is_function(VFun) ->
+ try VFun(Val) of
+ NewVal -> {ok, NewVal}
+ catch {invalid_syntax, Error} ->
+ ?ERROR_MSG("ignoring listen option '~s' with "
+ "invalid value: ~p: ~s",
+ [Opt, Val, Error]),
+ error;
+ _:_ ->
+ ?ERROR_MSG("ignoring listen option '~s' with "
+ "invalid value: ~p",
+ [Opt, Val]),
+ error
+ end;
+ KnownOpts when is_list(KnownOpts) ->
+ ?ERROR_MSG("unknown listen option '~s' for '~s' will be likely "
+ "ignored, available options are: ~s",
+ [Opt, Module, misc:join_atoms(KnownOpts, <<", ">>)]),
+ {ok, Val}
+ end.
+
-type transport() :: udp | tcp.
-type port_ip_transport() :: inet:port_number() |
{inet:port_number(), transport()} |
true = ?IS_TRANSPORT(T),
{{Port, IP, T}, Mod, Opts};
({module, Mod}, {Port, _, Opts}) ->
- {Port, prepare_mod(Mod), Opts};
+ {Port, Mod, Opts};
(Opt, {Port, Mod, Opts}) ->
{Port, Mod, [Opt|Opts]}
end, {{5222, all_zero_ip(LOpts), tcp}, ejabberd_c2s, []}, LOpts)
prepare_ip(IP) when is_binary(IP) ->
prepare_ip(binary_to_list(IP)).
-prepare_mod(ejabberd_sip) ->
- prepare_mod(sip);
-prepare_mod(sip) ->
- esip_socket;
-prepare_mod(Mod) when is_atom(Mod) ->
- Mod.
-
all_zero_ip(Opts) ->
case proplists:get_bool(inet6, Opts) of
true -> {0,0,0,0,0,0,0,0};
%% ejabberd_socket callbacks
-export([start/2, start_link/2, socket_type/0]).
%% ejabberd_config callbacks
--export([opt_type/1]).
+-export([opt_type/1, 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]).
State, [Pkt, Result]).
init([State, Opts]) ->
- Shaper = gen_mod:get_opt(shaper, Opts, fun acl:shaper_rules_validator/1, none),
+ Shaper = gen_mod:get_opt(shaper, Opts, none),
TLSOpts1 = lists:filter(
fun({certfile, _}) -> true;
({ciphers, _}) -> true;
({dhfile, _}) -> true;
({cafile, _}) -> true;
+ ({protocol_options, _}) -> true;
(_) -> false
end, Opts),
- TLSOpts2 = case lists:keyfind(protocol_options, 1, Opts) of
- false -> TLSOpts1;
- {_, OptString} ->
- ProtoOpts = str:join(OptString, <<$|>>),
- [{protocol_options, ProtoOpts}|TLSOpts1]
- end,
- TLSOpts3 = case proplists:get_bool(tls_compression, Opts) of
- false -> [compression_none | TLSOpts2];
- true -> TLSOpts2
+ TLSOpts2 = case proplists:get_bool(tls_compression, Opts) of
+ false -> [compression_none | TLSOpts1];
+ true -> TLSOpts1
end,
- State1 = State#{tls_options => TLSOpts3,
+ State1 = State#{tls_options => TLSOpts2,
auth_domains => sets:new(),
xmlns => ?NS_SERVER,
lang => ?MYLANG,
opt_type(_) ->
[].
+
+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);
+listen_opt_type(dhfile) -> ejabberd_s2s:opt_type(s2s_dhfile);
+listen_opt_type(cafile) -> ejabberd_s2s:opt_type(s2s_cafile);
+listen_opt_type(protocol_options) -> ejabberd_s2s:opt_type(s2s_protocol_options);
+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;
+ (unlimited) -> infinity;
+ (infinity) -> infinity
+ end;
+listen_opt_type(max_fsm_queue) ->
+ fun(I) when is_integer(I), I>0 -> I end;
+listen_opt_type(_) ->
+ [shaper, certfile, ciphers, dhfile, cafile, protocol_options,
+ tls_compression, tls, max_fsm_queue].
%% ejabberd_socket callbacks
-export([start/2, start_link/2, socket_type/0, close/1, close/2]).
%% ejabberd_config callbacks
--export([opt_type/1, transform_listen_option/2]).
+-export([opt_type/1, 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,
TLSOptions.
init([State, Opts]) ->
- Access = gen_mod:get_opt(access, Opts, fun acl:access_rules_validator/1, all),
- Shaper = gen_mod:get_opt(shaper_rule, Opts, fun acl:shaper_rules_validator/1, none),
- HostOpts = case lists:keyfind(hosts, 1, Opts) of
- {hosts, HOpts} ->
- lists:foldl(
- fun({H, Os}, D) ->
- P = proplists:get_value(
- password, Os,
- str:sha(randoms:bytes(20))),
- dict:store(H, P, D)
- end, dict:new(), HOpts);
- false ->
- Pass = proplists:get_value(
- password, Opts,
- str:sha(randoms:bytes(20))),
- dict:from_list([{global, Pass}])
- end,
- CheckFrom = gen_mod:get_opt(check_from, Opts,
- fun(Flag) when is_boolean(Flag) -> Flag end,
- true),
+ Access = gen_mod:get_opt(access, Opts, all),
+ Shaper = gen_mod:get_opt(shaper_rule, Opts, none),
+ GlobalPassword = gen_mod:get_opt(password, Opts, random_password()),
+ HostOpts = gen_mod:get_opt(hosts, Opts, [{global, GlobalPassword}]),
+ HostOpts1 = lists:map(
+ fun({Host, undefined}) -> {Host, GlobalPassword};
+ ({Host, Password}) -> {Host, Password}
+ end, HostOpts),
+ CheckFrom = gen_mod:get_opt(check_from, Opts, true),
TLSOpts1 = lists:filter(
fun({certfile, _}) -> true;
({ciphers, _}) -> true;
({dhfile, _}) -> true;
({cafile, _}) -> true;
+ ({protocol_options, _}) -> true;
(_) -> false
end, Opts),
- TLSOpts2 = case lists:keyfind(protocol_options, 1, Opts) of
- false -> TLSOpts1;
- {_, OptString} ->
- ProtoOpts = str:join(OptString, <<$|>>),
- [{protocol_options, ProtoOpts}|TLSOpts1]
- end,
TLSOpts = case proplists:get_bool(tls_compression, Opts) of
- false -> [compression_none | TLSOpts2];
- true -> TLSOpts2
+ false -> [compression_none | TLSOpts1];
+ true -> TLSOpts1
end,
xmpp_stream_in:change_shaper(State, Shaper),
State1 = State#{access => Access,
xmlns => ?NS_COMPONENT,
lang => ?MYLANG,
server => ?MYNAME,
- host_opts => HostOpts,
+ host_opts => dict:from_list(HostOpts1),
stream_version => undefined,
tls_options => TLSOpts,
check_from => CheckFrom},
Server = From#jid.lserver,
dict:is_key(Server, HostOpts).
+random_password() ->
+ str:sha(randoms:bytes(20)).
+
transform_listen_option({hosts, Hosts, O}, Opts) ->
case lists:keyfind(hosts, 1, Opts) of
{_, PrevHostOpts} ->
[Opt|Opts].
opt_type(_) -> [].
+
+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;
+listen_opt_type(ciphers) -> fun iolist_to_binary/1;
+listen_opt_type(dhfile) -> fun iolist_to_binary/1;
+listen_opt_type(cafile) -> fun iolist_to_binary/1;
+listen_opt_type(protocol_options) ->
+ fun(Options) -> str:join(Options, <<"|">>) end;
+listen_opt_type(tls_compression) -> fun(B) when is_boolean(B) -> B end;
+listen_opt_type(tls) -> fun(B) when is_boolean(B) -> B end;
+listen_opt_type(check_from) -> fun(B) when is_boolean(B) -> B end;
+listen_opt_type(password) -> fun iolist_to_binary/1;
+listen_opt_type(hosts) ->
+ fun(HostOpts) ->
+ lists:map(
+ fun({Host, Opts}) ->
+ Password = case proplists:get_value(password, Opts) of
+ undefined -> undefined;
+ P -> iolist_to_binary(P)
+ end,
+ {iolist_to_binary(Host), Password}
+ end, HostOpts)
+ end;
+listen_opt_type(max_stanza_size) ->
+ fun(I) when is_integer(I) -> I;
+ (unlimited) -> infinity;
+ (infinity) -> infinity
+ end;
+listen_opt_type(max_fsm_queue) ->
+ fun(I) when is_integer(I), I>0 -> I end;
+listen_opt_type(_) ->
+ [access, shaper_rule, certfile, ciphers, dhfile, cafile, tls,
+ protocol_options, tls_compression, password, hosts, check_from,
+ max_fsm_queue].
--- /dev/null
+%%%-------------------------------------------------------------------
+%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
+%%% Created : 30 Apr 2017 by Evgeny Khramtsov <ekhramtsov@process-one.net>
+%%%
+%%%
+%%% ejabberd, Copyright (C) 2013-2017 ProcessOne
+%%%
+%%% This program is free software; you can redistribute it and/or
+%%% modify it under the terms of the GNU General Public License as
+%%% published by the Free Software Foundation; either version 2 of the
+%%% License, or (at your option) any later version.
+%%%
+%%% This program is distributed in the hope that it will be useful,
+%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% 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.
+%%%
+%%%-------------------------------------------------------------------
+-module(ejabberd_sip).
+
+%% API
+-export([tcp_init/2, udp_init/2, udp_recv/5, start/2,
+ socket_type/0, listen_opt_type/1]).
+
+%%%===================================================================
+%%% API
+%%%===================================================================
+tcp_init(Socket, Opts) ->
+ ejabberd:start_app(esip),
+ esip_socket:tcp_init(Socket, Opts).
+
+udp_init(Socket, Opts) ->
+ ejabberd:start_app(esip),
+ esip_socket:udp_init(Socket, Opts).
+
+udp_recv(Sock, Addr, Port, Data, Opts) ->
+ esip_socket:udp_recv(Sock, Addr, Port, Data, Opts).
+
+start(Opaque, Opts) ->
+ esip_socket:start(Opaque, Opts).
+
+socket_type() ->
+ raw.
+
+listen_opt_type(certfile) ->
+ fun iolist_to_binary/1;
+listen_opt_type(tls) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(_) ->
+ [tls, certfile].
+
+%%%===================================================================
+%%% Internal functions
+%%%===================================================================
-protocol({xep, 176, '1.0'}).
-export([tcp_init/2, udp_init/2, udp_recv/5, start/2,
- socket_type/0]).
+ socket_type/0, listen_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
ok
end,
AuthFun = fun ejabberd_auth:get_password_s/2,
- Shaper = gen_mod:get_opt(shaper, Opts,
- fun(S) when is_atom(S) -> S end,
- none),
- AuthType = gen_mod:get_opt(auth_type, Opts,
- fun(anonymous) -> anonymous;
- (user) -> user
- end, user),
- Realm = case gen_mod:get_opt(auth_realm, Opts, fun iolist_to_binary/1) of
+ Shaper = gen_mod:get_opt(shaper, Opts, none),
+ AuthType = gen_mod:get_opt(auth_type, Opts, user),
+ Realm = case gen_mod:get_opt(auth_realm, Opts) of
undefined when AuthType == user ->
if NumberOfMyHosts > 1 ->
?WARNING_MSG("you have several virtual "
MaxRate = shaper:get_max_rate(Shaper),
Realm ++ [{auth_fun, AuthFun},{shaper, MaxRate} |
lists:keydelete(shaper, 1, Opts)].
+
+listen_opt_type(use_turn) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(turn_ip) ->
+ fun(S) ->
+ {ok, Addr} = inet_parse:ipv4_address(binary_to_list(S)),
+ Addr
+ end;
+listen_opt_type(shaper) ->
+ fun acl:shaper_rules_validator/1;
+listen_opt_type(auth_type) ->
+ fun(anonymous) -> anonymous;
+ (user) -> user
+ end;
+listen_opt_type(auth_realm) ->
+ fun iolist_to_binary/1;
+listen_opt_type(tls) ->
+ fun(B) when is_boolean(B) -> B end;
+listen_opt_type(certfile) ->
+ fun iolist_to_binary/1;
+listen_opt_type(turn_min_port) ->
+ fun(P) when is_integer(P), P > 0, P =< 65535 -> P end;
+listen_opt_type(turn_max_port) ->
+ fun(P) when is_integer(P), P > 0, P =< 65535 -> P end;
+listen_opt_type(turn_max_allocations) ->
+ fun(I) when is_integer(I), I>0 -> I;
+ (unlimited) -> infinity;
+ (infinity) -> infinity
+ end;
+listen_opt_type(turn_max_permissions) ->
+ fun(I) when is_integer(I), I>0 -> I;
+ (unlimited) -> infinity;
+ (infinity) -> infinity
+ end;
+listen_opt_type(server_name) ->
+ fun iolist_to_binary/1;
+listen_opt_type(_) ->
+ [shaper, auth_type, auth_realm, tls, certfile, turn_min_port,
+ turn_max_port, turn_max_allocations, turn_max_permissions,
+ server_name].
get_acl_rule([<<"server">>, VHost | _RPath], Method)
when Method =:= 'GET' orelse Method =:= 'HEAD' ->
AC = gen_mod:get_module_opt(VHost, ejabberd_web_admin,
- access, fun(A) -> A end, configure),
+ access, configure),
ACR = gen_mod:get_module_opt(VHost, ejabberd_web_admin,
- access_readonly, fun(A) -> A end, webadmin_view),
+ access_readonly, webadmin_view),
{VHost, [AC, ACR]};
get_acl_rule([<<"server">>, VHost | _RPath], 'POST') ->
AC = gen_mod:get_module_opt(VHost, ejabberd_web_admin,
- access, fun(A) -> A end, configure),
+ access, configure),
{VHost, [AC]};
%% Default rule: only global admins can access any other random page
get_acl_rule(_RPath, Method)
when Method =:= 'GET' orelse Method =:= 'HEAD' ->
AC = gen_mod:get_module_opt(global, ejabberd_web_admin,
- access, fun(A) -> A end, configure),
+ access, configure),
ACR = gen_mod:get_module_opt(global, ejabberd_web_admin,
- access_readonly, fun(A) -> A end, webadmin_view),
+ access_readonly, webadmin_view),
{global, [AC, ACR]};
get_acl_rule(_RPath, 'POST') ->
AC = gen_mod:get_module_opt(global, ejabberd_web_admin,
- access, fun(A) -> A end, configure),
+ access, configure),
{global, [AC]}.
%%%==================================
-author('badlop@process-one.net').
-export([start/2, handler/2, process/2, socket_type/0,
- transform_listen_option/2]).
+ transform_listen_option/2, listen_opt_type/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
%% HTTP interface
%% -----------------------------
process(_, #request{method = 'POST', data = Data, opts = Opts, ip = {IP, _}}) ->
- AccessCommandsOpts = gen_mod:get_opt(access_commands, Opts,
- fun(L) when is_list(L) -> L end,
- undefined),
- AccessCommands =
- case AccessCommandsOpts of
- undefined -> undefined;
- _ ->
- lists:flatmap(
- fun({Ac, AcOpts}) ->
- Commands = gen_mod:get_opt(
- commands, lists:flatten(AcOpts),
- fun(A) when is_atom(A) ->
- A;
- (L) when is_list(L) ->
- true = lists:all(
- fun is_atom/1,
- L),
- L
- end, all),
- %% CommOpts = gen_mod:get_opt(
- %% options, AcOpts,
- %% fun(L) when is_list(L) -> L end,
- %% []),
- [{<<"ejabberd_xmlrpc compatibility shim">>, {[?MODULE], [{access, Ac}], Commands}}];
- (Wrong) ->
- ?WARNING_MSG("wrong options format for ~p: ~p",
- [?MODULE, Wrong]),
- []
- end, lists:flatten(AccessCommandsOpts))
- end,
+ AccessCommands = gen_mod:get_opt(access_commands, Opts),
GetAuth = true,
State = #state{access_commands = AccessCommands, get_auth = GetAuth, ip = IP},
case fxml_stream:parse_element(Data) of
[{access_commands, NewACOpts}|Opts];
transform_listen_option(Opt, Opts) ->
[Opt|Opts].
+
+listen_opt_type(access_commands) ->
+ fun(Opts) ->
+ lists:map(
+ fun({Ac, AcOpts}) ->
+ Commands = case proplists:get_value(
+ commands, lists:flatten(AcOpts), all) of
+ Cmd when is_atom(Cmd) -> Cmd;
+ Cmds when is_list(Cmds) ->
+ true = lists:all(fun is_atom/1, Cmds),
+ Cmds
+ end,
+ {<<"ejabberd_xmlrpc compatibility shim">>,
+ {[?MODULE], [{access, Ac}], Commands}}
+ end, lists:flatten(Opts))
+ end;
+listen_opt_type(maxsessions) ->
+ fun(I) when is_integer(I), I>0 -> I end;
+listen_opt_type(timeout) ->
+ fun(I) when is_integer(I), I>0 -> I end;
+listen_opt_type(_) ->
+ [access_commands, maxsessions, timeout].
%% process.
%%----------------------------------------------------------------------
init([Hosts, Port, Rootdn, Passwd, Opts]) ->
- Encrypt = case gen_mod:get_opt(encrypt, Opts,
- fun(tls) -> tls;
- (starttls) -> starttls;
- (none) -> none
- end) of
+ Encrypt = case gen_mod:get_opt(encrypt, Opts) of
tls -> tls;
_ -> none
end,
end;
PT -> PT
end,
- CacertOpts = case gen_mod:get_opt(
- tls_cacertfile, Opts,
- fun(S) when is_binary(S) ->
- binary_to_list(S);
- (undefined) ->
- undefined
- end) of
+ CacertOpts = case gen_mod:get_opt(tls_cacertfile, Opts) of
undefined ->
[];
Path ->
[{cacertfile, Path}]
end,
- DepthOpts = case gen_mod:get_opt(
- tls_depth, Opts,
- fun(I) when is_integer(I), I>=0 ->
- I;
- (undefined) ->
- undefined
- end) of
+ DepthOpts = case gen_mod:get_opt(tls_depth, Opts) of
undefined ->
[];
Depth ->
[{depth, Depth}]
end,
- Verify = gen_mod:get_opt(tls_verify, Opts,
- fun(hard) -> hard;
- (soft) -> soft;
- (false) -> false
- end, false),
+ Verify = gen_mod:get_opt(tls_verify, Opts, false),
TLSOpts = if (Verify == hard orelse Verify == soft)
andalso CacertOpts == [] ->
?WARNING_MSG("TLS verification is enabled but no CA "
-spec get_config(binary(), list()) -> eldap_config().
get_config(Host, Opts) ->
- Servers = gen_mod:get_opt({ldap_servers, Host}, Opts,
- fun(L) ->
- [iolist_to_binary(H) || H <- L]
- end, [<<"localhost">>]),
- Backups = gen_mod:get_opt({ldap_backups, Host}, Opts,
- fun(L) ->
- [iolist_to_binary(H) || H <- L]
- end, []),
- Encrypt = gen_mod:get_opt({ldap_encrypt, Host}, Opts,
- fun(tls) -> tls;
- (starttls) -> starttls;
- (none) -> none
- end, none),
- TLSVerify = gen_mod:get_opt({ldap_tls_verify, Host}, Opts,
- fun(hard) -> hard;
- (soft) -> soft;
- (false) -> false
- end, false),
- TLSCAFile = gen_mod:get_opt({ldap_tls_cacertfile, Host}, Opts,
- fun iolist_to_binary/1),
- TLSDepth = gen_mod:get_opt({ldap_tls_depth, Host}, Opts,
- fun(I) when is_integer(I), I>=0 -> I end),
+ Servers = gen_mod:get_opt({ldap_servers, Host}, Opts, [<<"localhost">>]),
+ Backups = gen_mod:get_opt({ldap_backups, Host}, Opts, []),
+ Encrypt = gen_mod:get_opt({ldap_encrypt, Host}, Opts, none),
+ TLSVerify = gen_mod:get_opt({ldap_tls_verify, Host}, Opts, false),
+ TLSCAFile = gen_mod:get_opt({ldap_tls_cacertfile, Host}, Opts),
+ TLSDepth = gen_mod:get_opt({ldap_tls_depth, Host}, Opts),
Port = gen_mod:get_opt({ldap_port, Host}, Opts,
- fun(I) when is_integer(I), I>0 -> I end,
- case Encrypt of
- tls -> ?LDAPS_PORT;
- starttls -> ?LDAP_PORT;
- _ -> ?LDAP_PORT
- end),
- RootDN = gen_mod:get_opt({ldap_rootdn, Host}, Opts,
- fun iolist_to_binary/1,
- <<"">>),
- Password = gen_mod:get_opt({ldap_password, Host}, Opts,
- fun iolist_to_binary/1,
- <<"">>),
- Base = gen_mod:get_opt({ldap_base, Host}, Opts,
- fun iolist_to_binary/1,
- <<"">>),
- OldDerefAliases = gen_mod:get_opt({deref_aliases, Host}, Opts,
- fun(never) -> never;
- (searching) -> searching;
- (finding) -> finding;
- (always) -> always
- end, unspecified),
+ case Encrypt of
+ tls -> ?LDAPS_PORT;
+ starttls -> ?LDAP_PORT;
+ _ -> ?LDAP_PORT
+ end),
+ RootDN = gen_mod:get_opt({ldap_rootdn, Host}, Opts, <<"">>),
+ Password = gen_mod:get_opt({ldap_password, Host}, Opts, <<"">>),
+ Base = gen_mod:get_opt({ldap_base, Host}, Opts, <<"">>),
+ OldDerefAliases = gen_mod:get_opt({deref_aliases, Host}, Opts, unspecified),
DerefAliases =
if OldDerefAliases == unspecified ->
- gen_mod:get_opt({ldap_deref_aliases, Host}, Opts,
- fun(never) -> never;
- (searching) -> searching;
- (finding) -> finding;
- (always) -> always
- end, never);
+ gen_mod:get_opt({ldap_deref_aliases, Host}, Opts, never);
true ->
?WARNING_MSG("Option 'deref_aliases' is deprecated. "
"The option is still supported "
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_cacertfile) ->
+ fun(S) -> binary_to_list(iolist_to_binary(S)) end;
opt_type(ldap_tls_depth) ->
fun (I) when is_integer(I), I >= 0 -> I end;
opt_type(ldap_tls_verify) ->
-export([init/1, start_link/0, start_child/3, start_child/4,
stop_child/1, stop_child/2, config_reloaded/0]).
-export([start_module/2, start_module/3,
- stop_module/2, stop_module_keep_config/2, get_opt/3,
- get_opt/4, get_opt_host/3, opt_type/1, is_equal_opt/5,
- get_module_opt/4, get_module_opt/5, get_module_opt_host/3,
+ stop_module/2, stop_module_keep_config/2,
+ get_opt/2, get_opt/3, get_opt_host/3, opt_type/1, is_equal_opt/4,
+ get_module_opt/3, get_module_opt/4, get_module_opt_host/3,
loaded_modules/1, loaded_modules_with_opts/1,
get_hosts/2, get_module_proc/2, is_loaded/2, is_loaded_elsewhere/2,
start_modules/0, start_modules/1, stop_modules/0, stop_modules/1,
db_mod/2, db_mod/3, ram_db_mod/2, ram_db_mod/3,
db_type/2, db_type/3, ram_db_type/2, ram_db_type/3]).
-%%-export([behaviour_info/1]).
+%% Deprecated functions
+-export([get_opt/4, get_module_opt/5]).
+-deprecated([{get_opt, 4}, {get_module_opt, 5}]).
-include("ejabberd.hrl").
-include("logger.hrl").
start_link() ->
case supervisor:start_link({local, ejabberd_gen_mod_sup}, ?MODULE, []) of
{ok, Pid} ->
- gen_mod:start_modules(),
+ start_modules(),
{ok, Pid};
Err ->
Err
Modules = get_modules_options(Host),
lists:foreach(
fun({Module, _Args}) ->
- gen_mod:stop_module_keep_config(Host, Module)
+ stop_module_keep_config(Host, Module)
end, Modules).
-spec stop_module(binary(), atom()) -> error | {aborted, any()} | {atomic, any()}.
-type check_fun() :: fun((any()) -> any()) | {module(), atom()}.
--spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun()) -> any().
+-spec get_opt(atom() | {atom(), binary() | global}, opts()) -> any().
+get_opt(Opt, Opts) ->
+ get_opt(Opt, Opts, undefined).
-get_opt(Opt, Opts, F) ->
- get_opt(Opt, Opts, F, undefined).
+-spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun() | any()) -> any().
--spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun(), any()) -> any().
-
-get_opt({Opt, Host}, Opts, F, Default) ->
- case lists:keysearch(Opt, 1, Opts) of
+get_opt(Opt, Opts, F) when is_function(F) ->
+ get_opt(Opt, Opts, undefined);
+get_opt({Opt, Host}, Opts, Default) ->
+ case lists:keyfind(Opt, 1, Opts) of
false ->
ejabberd_config:get_option({Opt, Host}, Default);
- {value, {_, Val}} ->
- ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
+ {_, Val} ->
+ Val
end;
-get_opt(Opt, Opts, F, Default) ->
- case lists:keysearch(Opt, 1, Opts) of
+get_opt(Opt, Opts, Default) ->
+ case lists:keyfind(Opt, 1, Opts) of
false ->
Default;
- {value, {_, Val}} ->
- ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
+ {_, Val} ->
+ Val
end.
--spec get_module_opt(global | binary(), atom(), atom(), check_fun()) -> any().
+-spec get_opt(atom() | {atom(), binary()}, opts(), check_fun(), any()) -> any().
+get_opt(Opt, Opts, _, Default) ->
+ get_opt(Opt, Opts, Default).
-get_module_opt(Host, Module, Opt, F) ->
- get_module_opt(Host, Module, Opt, F, undefined).
+-spec get_module_opt(global | binary(), atom(), atom()) -> any().
--spec get_module_opt(global | binary(), atom(), atom(), check_fun(), any()) -> any().
+get_module_opt(Host, Module, Opt) ->
+ get_module_opt(Host, Module, Opt, undefined).
+
+-spec get_module_opt(global | binary(), atom(), atom(), any()) -> any().
-get_module_opt(global, Module, Opt, F, Default) ->
+get_module_opt(Host, Module, Opt, F) when is_function(F) ->
+ get_module_opt(Host, Module, Opt, undefined);
+get_module_opt(global, Module, Opt, Default) ->
Hosts = (?MYHOSTS),
[Value | Values] = lists:map(fun (Host) ->
get_module_opt(Host, Module, Opt,
- F, Default)
+ Default)
end,
Hosts),
Same_all = lists:all(fun (Other_value) ->
true -> Value;
false -> Default
end;
-get_module_opt(Host, Module, Opt, F, Default) ->
+get_module_opt(Host, Module, Opt, Default) ->
OptsList = ets:lookup(ejabberd_modules, {Module, Host}),
case OptsList of
[] -> Default;
[#ejabberd_module{opts = Opts} | _] ->
- get_opt(Opt, Opts, F, Default)
+ get_opt(Opt, Opts, Default)
end.
+-spec get_module_opt(global | binary(), atom(), atom(), check_fun(), any()) -> any().
+get_module_opt(Host, Module, Opt, _, Default) ->
+ get_module_opt(Host, Module, Opt, Default).
+
-spec get_module_opt_host(global | binary(), atom(), binary()) -> binary().
get_module_opt_host(Host, Module, Default) ->
- Val = get_module_opt(Host, Module, host,
- fun iolist_to_binary/1,
- Default),
+ Val = get_module_opt(Host, Module, host, Default),
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
-spec get_opt_host(binary(), opts(), binary()) -> binary().
get_opt_host(Host, Opts, Default) ->
- Val = get_opt(host, Opts, fun iolist_to_binary/1, Default),
+ Val = get_opt(host, Opts, Default),
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
throw({'EXIT', {undef, mod_opt_type}});
{[], Args, _} -> Args;
{Funs, _, _} ->
- fun(Val) ->
- lists:any(fun(F) ->
- try F(Val) of
- _ ->
- true
- catch {replace_with, _NewVal} = E ->
- throw(E);
- {invalid_syntax, _Error} = E2 ->
- throw(E2);
- _:_ ->
- false
- end
- end, Funs)
- end
+ fun(Val) -> try_mod_opt_type(Funs, Val) end
end
end.
+try_mod_opt_type([Fun|Funs], Val) ->
+ try Fun(Val) of
+ NewVal -> NewVal
+ catch {invalid_syntax, _Error} = E2 ->
+ throw(E2);
+ _:_ ->
+ try_mod_opt_type(Funs, Val)
+ end.
+
validate_opts(Module, Opts) ->
ModOptFun = get_module_mod_opt_type_fun(Module),
lists:filtermap(
case catch ModOptFun(Opt) of
VFun when is_function(VFun) ->
try VFun(Val) of
- _ ->
- true
- catch {replace_with, NewVal} ->
- {true, {Opt, NewVal}};
- {invalid_syntax, Error} ->
+ NewVal ->
+ {true, {Opt, NewVal}}
+ catch {invalid_syntax, Error} ->
?ERROR_MSG("ignoring invalid value '~p' for "
"option '~s' of module '~s': ~s",
[Val, Opt, Module, Error]),
db_type(Opts, Module) when is_list(Opts) ->
db_type(global, Opts, Module);
db_type(Host, Module) when is_atom(Module) ->
- case catch Module:mod_opt_type(db_type) of
- F when is_function(F) ->
- case get_module_opt(Host, Module, db_type, F) of
- undefined -> ejabberd_config:default_db(Host, Module);
- Type -> Type
- end;
- _ ->
- undefined
+ case get_module_opt(Host, Module, db_type) of
+ undefined ->
+ ejabberd_config:default_db(Host, Module);
+ Type ->
+ Type
end.
-spec db_type(binary() | global, opts(), module()) -> db_type().
db_type(Host, Opts, Module) ->
- case catch Module:mod_opt_type(db_type) of
- F when is_function(F) ->
- case get_opt(db_type, Opts, F) of
- undefined -> ejabberd_config:default_db(Host, Module);
- Type -> Type
- end;
- _ ->
- undefined
+ case get_opt(db_type, Opts) of
+ undefined ->
+ ejabberd_config:default_db(Host, Module);
+ Type ->
+ Type
end.
-spec db_mod(binary() | global | db_type(), module()) -> module().
ram_db_type(Opts, Module) when is_list(Opts) ->
ram_db_type(global, Opts, Module);
ram_db_type(Host, Module) when is_atom(Module) ->
- case catch Module:mod_opt_type(ram_db_type) of
- F when is_function(F) ->
- case get_module_opt(Host, Module, ram_db_type, F) of
- undefined -> ejabberd_config:default_ram_db(Host, Module);
- Type -> Type
- end;
- _ ->
- undefined
+ case get_module_opt(Host, Module, ram_db_type) of
+ undefined ->
+ ejabberd_config:default_ram_db(Host, Module);
+ Type ->
+ Type
end.
-spec ram_db_type(binary() | global, opts(), module()) -> db_type().
ram_db_type(Host, Opts, Module) ->
- case catch Module:mod_opt_type(ram_db_type) of
- F when is_function(F) ->
- case get_opt(ram_db_type, Opts, F) of
- undefined -> ejabberd_config:default_ram_db(Host, Module);
- Type -> Type
- end;
- _ ->
- undefined
+ case get_opt(ram_db_type, Opts) of
+ undefined ->
+ ejabberd_config:default_ram_db(Host, Module);
+ Type ->
+ Type
end.
-spec ram_db_mod(binary() | global | db_type(), module()) -> module().
-spec get_hosts(opts(), binary()) -> [binary()].
get_hosts(Opts, Prefix) ->
- case get_opt(hosts, Opts,
- fun(Hs) -> [iolist_to_binary(H) || H <- Hs] end) of
+ case get_opt(hosts, Opts) of
undefined ->
- case get_opt(host, Opts,
- fun iolist_to_binary/1) of
+ case get_opt(host, Opts) of
undefined ->
[<<Prefix/binary, Host/binary>> || Host <- ?MYHOSTS];
Host ->
reload_modules(Host)
end, ?MYHOSTS).
--spec is_equal_opt(atom(), opts(), opts(), check_fun(), any()) ->
+-spec is_equal_opt(atom(), opts(), opts(), any()) ->
true | {false, any(), any()}.
-is_equal_opt(Opt, NewOpts, OldOpts, VFun, Default) ->
- NewVal = get_opt(Opt, NewOpts, VFun, Default),
- OldVal = get_opt(Opt, OldOpts, VFun, Default),
+is_equal_opt(Opt, NewOpts, OldOpts, Default) ->
+ NewVal = get_opt(Opt, NewOpts, Default),
+ OldVal = get_opt(Opt, OldOpts, Default),
if NewVal /= OldVal ->
{false, NewVal, OldVal};
true ->
hex_to_bin/1, hex_to_base64/1, expand_keyword/3,
atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1,
l2i/1, i2l/1, i2l/2, expr_to_term/1, term_to_expr/1,
- encode_pid/1, decode_pid/2, compile_exprs/2]).
+ encode_pid/1, decode_pid/2, compile_exprs/2, join_atoms/2]).
%%%===================================================================
%%% API
{error, compile_failed}
end.
+-spec join_atoms([atom()], binary()) -> binary().
+join_atoms(Atoms, Sep) ->
+ str:join([io_lib:format("~p", [A]) || A <- Atoms], Sep).
+
%%%===================================================================
%%% Internal functions
%%%===================================================================
-include("xmpp.hrl").
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_COMMANDS, ?MODULE, process_local_iq,
IQDisc),
?NS_COMMANDS).
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_COMMANDS,
?MODULE, process_local_iq, IQDisc),
Lang) ->
Display = gen_mod:get_module_opt(LServer, ?MODULE,
report_commands_node,
- fun(B) when is_boolean(B) -> B end,
false),
case Display of
false -> Acc;
#jid{lserver = LServer} = To, <<"">>, Lang) ->
Display = gen_mod:get_module_opt(LServer, ?MODULE,
report_commands_node,
- fun(B) when is_boolean(B) -> B end,
false),
case Display of
false -> Acc;
-spec get_access(global | binary()) -> atom().
get_access(Host) ->
- gen_mod:get_module_opt(Host, ?MODULE, access,
- fun(A) -> A end,
- none).
+ gen_mod:get_module_opt(Host, ?MODULE, access, none).
-spec add_store_hint(stanza()) -> stanza().
add_store_hint(El) ->
Acc;
false ->
#{lserver := LServer} = State,
- Drop =
- gen_mod:get_module_opt(LServer, ?MODULE, drop,
- fun(B) when is_boolean(B) -> B end,
- true),
- Log =
- gen_mod:get_module_opt(LServer, ?MODULE, log,
- fun(B) when is_boolean(B) -> B end,
- false),
+ Drop = gen_mod:get_module_opt(LServer, ?MODULE, drop, true),
+ Log = gen_mod:get_module_opt(LServer, ?MODULE, log, false),
if
Log ->
?INFO_MSG("Drop packet: ~s",
-type block_event() :: {block, [jid()]} | {unblock, [jid()]} | unblock_all.
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE, disco_features, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_BLOCKING, ?MODULE, process_iq, IQDisc).
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_BLOCKING).
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_BLOCKING,
?MODULE, process_iq, IQDisc);
%%% Internal functions
%%%===================================================================
start_jiffy(Opts) ->
- case gen_mod:get_opt(json, Opts,
- fun(false) -> false;
- (true) -> true
- end, false) of
+ case gen_mod:get_opt(json, Opts, false) of
false ->
ok;
true ->
true -> Mod:use_cache();
false ->
gen_mod:get_module_opt(
- global, ?MODULE, use_cache, mod_opt_type(use_cache),
+ global, ?MODULE, use_cache,
ejabberd_config:use_cache(global))
end.
cache_opts() ->
MaxSize = gen_mod:get_module_opt(
global, ?MODULE, cache_size,
- mod_opt_type(cache_size),
ejabberd_config:cache_size(global)),
CacheMissed = gen_mod:get_module_opt(
global, ?MODULE, cache_missed,
- mod_opt_type(cache_missed),
ejabberd_config:cache_missed(global)),
LifeTime = case gen_mod:get_module_opt(
global, ?MODULE, cache_life_time,
- mod_opt_type(cache_life_time),
ejabberd_config:cache_life_time(global)) of
infinity -> infinity;
I -> timer:seconds(I)
ok
end,
case gen_mod:is_equal_opt(cache_size, NewOpts, OldOpts,
- fun(I) when is_integer(I), I>0 -> I end,
- 1000) of
+ ejabberd_config:cache_size(Host)) of
{false, MaxSize, _} ->
ets_cache:setopts(caps_features_cache, [{max_size, MaxSize}]),
ets_cache:setopts(caps_requests_cache, [{max_size, MaxSize}]);
ok
end,
case gen_mod:is_equal_opt(cache_life_time, NewOpts, OldOpts,
- fun(I) when is_integer(I), I>0 -> I end,
- timer:hours(24) div 1000) of
- {false, LifeTime, _} ->
+ ejabberd_config:cache_life_time(Host)) of
+ {false, Time, _} ->
+ LifeTime = case Time of
+ infinity -> infinity;
+ _ -> timer:seconds(Time)
+ end,
ets_cache:setopts(caps_features_cache, [{life_time, LifeTime}]);
true ->
ok
{life_time, timer:seconds(?BAD_HASH_LIFETIME)}]).
use_cache(Host, Opts) ->
- gen_mod:get_opt(use_cache, Opts, mod_opt_type(use_cache),
- ejabberd_config:use_cache(Host)).
+ gen_mod:get_opt(use_cache, Opts, ejabberd_config:use_cache(Host)).
cache_opts(Host, Opts) ->
MaxSize = gen_mod:get_opt(cache_size, Opts,
- mod_opt_type(cache_size),
ejabberd_config:cache_size(Host)),
CacheMissed = gen_mod:get_opt(cache_missed, Opts,
- mod_opt_type(cache_missed),
ejabberd_config:cache_missed(Host)),
LifeTime = case gen_mod:get_opt(cache_life_time, Opts,
- mod_opt_type(cache_life_time),
ejabberd_config:cache_life_time(Host)) of
infinity -> infinity;
I -> timer:seconds(I)
false.
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts,fun gen_iq_handler:check_type/1, one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE, disco_features, 50),
Mod = gen_mod:ram_db_mod(Host, ?MODULE),
init_cache(Mod, Host, Opts),
false ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2,
?MODULE, iq_handler, IQDisc);
-spec cache_opts(binary(), gen_mod:opts()) -> [proplists:property()].
cache_opts(Host, Opts) ->
MaxSize = gen_mod:get_opt(
- cache_size, Opts, mod_opt_type(cache_size),
+ cache_size, Opts,
ejabberd_config:cache_size(Host)),
CacheMissed = gen_mod:get_opt(
- cache_missed, Opts, mod_opt_type(cache_missed),
+ cache_missed, Opts,
ejabberd_config:cache_missed(Host)),
LifeTime = case gen_mod:get_opt(
- cache_life_time, Opts, mod_opt_type(cache_life_time),
+ cache_life_time, Opts,
ejabberd_config:cache_life_time(Host)) of
infinity -> infinity;
I -> timer:seconds(I)
true -> Mod:use_cache(Host);
false ->
gen_mod:get_module_opt(
- Host, ?MODULE, use_cache, mod_opt_type(use_cache),
+ Host, ?MODULE, use_cache,
ejabberd_config:use_cache(Host))
end.
%%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> ok.
start(Host, Opts) ->
- QueuePresence =
- gen_mod:get_opt(queue_presence, Opts,
- fun(B) when is_boolean(B) -> B end,
- true),
- QueueChatStates =
- gen_mod:get_opt(queue_chat_states, Opts,
- fun(B) when is_boolean(B) -> B end,
- true),
- QueuePEP =
- gen_mod:get_opt(queue_pep, Opts,
- fun(B) when is_boolean(B) -> B end,
- true),
+ QueuePresence = gen_mod:get_opt(queue_presence, Opts, true),
+ QueueChatStates = gen_mod:get_opt(queue_chat_states, Opts, true),
+ QueuePEP = gen_mod:get_opt(queue_pep, Opts, true),
if QueuePresence; QueueChatStates; QueuePEP ->
register_hooks(Host),
if QueuePresence ->
-spec stop(binary()) -> ok.
stop(Host) ->
- QueuePresence =
- gen_mod:get_module_opt(Host, ?MODULE, queue_presence,
- fun(B) when is_boolean(B) -> B end,
- true),
- QueueChatStates =
- gen_mod:get_module_opt(Host, ?MODULE, queue_chat_states,
- fun(B) when is_boolean(B) -> B end,
- true),
- QueuePEP =
- gen_mod:get_module_opt(Host, ?MODULE, queue_pep,
- fun(B) when is_boolean(B) -> B end,
- true),
+ QueuePresence = gen_mod:get_module_opt(Host, ?MODULE, queue_presence, true),
+ QueueChatStates = gen_mod:get_module_opt(Host, ?MODULE, queue_chat_states, true),
+ QueuePEP = gen_mod:get_module_opt(Host, ?MODULE, queue_pep, true),
if QueuePresence; QueueChatStates; QueuePEP ->
unregister_hooks(Host),
if QueuePresence ->
-spec reload(binary(), gen_mod:opts(), gen_mod:opts()) -> ok.
reload(Host, NewOpts, _OldOpts) ->
- QueuePresence = gen_mod:get_opt(queue_presence, NewOpts,
- fun(B) when is_boolean(B) -> B end,
- true),
- QueueChatStates = gen_mod:get_opt(queue_chat_states, NewOpts,
- fun(B) when is_boolean(B) -> B end,
- true),
- QueuePEP = gen_mod:get_opt(queue_pep, NewOpts,
- fun(B) when is_boolean(B) -> B end,
- true),
+ QueuePresence = gen_mod:get_opt(queue_presence, NewOpts, true),
+ QueueChatStates = gen_mod:get_opt(queue_chat_states, NewOpts, true),
+ QueuePEP = gen_mod:get_opt(queue_pep, NewOpts, true),
if QueuePresence; QueueChatStates; QueuePEP ->
register_hooks(Host);
true ->
ok.
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
-mod_opt_type(namespaces) -> validate_fun();
+mod_opt_type(namespaces) ->
+ fun(L) ->
+ lists:map(
+ fun({NS, Opts}) ->
+ Attrs = proplists:get_value(filtering, Opts, []),
+ Access = proplists:get_value(access, Opts, none),
+ {NS, Attrs, Access}
+ end, L)
+ end;
mod_opt_type(_) ->
[namespaces, iqdisc].
ServerHost = State#state.server_host,
To = jid:make(Host),
NSAttrsAccessList = gen_mod:get_module_opt(
- ServerHost, ?MODULE, namespaces,
- validate_fun(), []),
+ ServerHost, ?MODULE, namespaces, []),
lists:foreach(
fun({NS, _Attrs, Access}) ->
case acl:match_rule(ServerHost, Access, To) of
my_features(ejabberd_local) -> [?NS_DELEGATION];
my_features(ejabberd_sm) -> [].
-
-validate_fun() ->
- fun(L) ->
- lists:map(
- fun({NS, Opts}) ->
- Attrs = proplists:get_value(filtering, Opts, []),
- Access = proplists:get_value(access, Opts, none),
- {NS, Attrs, Access}
- end, L)
- end.
-type items_acc() :: {error, stanza_error()} | {result, [disco_item()]} | empty.
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_ITEMS, ?MODULE,
process_local_iq_items, IQDisc),
catch ets:new(disco_extra_domains,
[named_table, ordered_set, public,
{heir, erlang:group_leader(), none}]),
- ExtraDomains = gen_mod:get_opt(extra_domains, Opts,
- fun(Hs) ->
- [iolist_to_binary(H) || H <- Hs]
- end, []),
+ ExtraDomains = gen_mod:get_opt(extra_domains, Opts, []),
lists:foreach(fun (Domain) ->
register_extra_domain(Host, Domain)
end,
ok.
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(extra_domains, NewOpts, OldOpts,
- fun(Hs) ->
- [iolist_to_binary(H) || H <- Hs]
- end, []) of
+ case gen_mod:is_equal_opt(extra_domains, NewOpts, OldOpts, []) of
{false, NewDomains, OldDomains} ->
lists:foreach(
fun(Domain) ->
true ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_ITEMS, ?MODULE,
-spec get_fields(binary(), module()) -> [xdata_field()].
get_fields(Host, Module) ->
- Fields = gen_mod:get_module_opt(
- Host, ?MODULE, 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, []),
+ Fields = gen_mod:get_module_opt(Host, ?MODULE, server_info, []),
Fields1 = lists:filter(fun ({Modules, _, _}) ->
case Modules of
all -> true;
false ->
BanLifetime = gen_mod:get_module_opt(
LServer, ?MODULE, c2s_auth_ban_lifetime,
- fun(T) when is_integer(T), T > 0 -> T end,
?C2S_AUTH_BAN_LIFETIME),
MaxFailures = gen_mod:get_module_opt(
LServer, ?MODULE, c2s_max_auth_failures,
- fun(I) when is_integer(I), I > 0 -> I end,
?C2S_MAX_AUTH_FAILURES),
UnbanTS = p1_time_compat:system_time(seconds) + BanLifetime,
Attempts = case ets:lookup(failed_auth, Addr) of
{stop, ejabberd_c2s:send(State, Err)}.
is_whitelisted(Host, Addr) ->
- Access = gen_mod:get_module_opt(Host, ?MODULE, access,
- fun(A) -> A end,
- none),
+ Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
acl:match_rule(Host, Access, Addr) == allow.
seconds_to_now(Secs) ->
?INFO_MSG("API call ~s ~p (~p)", [Call, Args, IP]).
permission_addon() ->
- Access = gen_mod:get_module_opt(global, ?MODULE, admin_ip_access,
- fun(V) -> V end,
- none),
+ Access = gen_mod:get_module_opt(global, ?MODULE, admin_ip_access, none),
Rules = acl:resolve_access(Access, global),
R = case Rules of
all ->
end.
initialize(Host, Opts) ->
- DocRoot = gen_mod:get_opt(docroot, Opts, fun(A) -> A end, undefined),
+ DocRoot = gen_mod:get_opt(docroot, Opts),
check_docroot_defined(DocRoot, Host),
DRInfo = check_docroot_exists(DocRoot),
check_docroot_is_dir(DRInfo, DocRoot),
check_docroot_is_readable(DRInfo, DocRoot),
- AccessLog = gen_mod:get_opt(accesslog, Opts,
- fun iolist_to_binary/1,
- undefined),
+ AccessLog = gen_mod:get_opt(accesslog, Opts),
AccessLogFD = try_open_log(AccessLog, Host),
- DirectoryIndices = gen_mod:get_opt(directory_indices, Opts,
- fun(L) when is_list(L) -> L end,
- []),
- CustomHeaders = gen_mod:get_opt(custom_headers, Opts,
- fun(L) when is_list(L) -> L end,
- []),
+ DirectoryIndices = gen_mod:get_opt(directory_indices, Opts, []),
+ CustomHeaders = gen_mod:get_opt(custom_headers, Opts, []),
DefaultContentType = gen_mod:get_opt(default_content_type, Opts,
- fun iolist_to_binary/1,
?DEFAULT_CONTENT_TYPE),
- UserAccess0 = gen_mod:get_opt(must_authenticate_with, Opts,
- mod_opt_type(must_authenticate_with),
- []),
+ UserAccess0 = gen_mod:get_opt(must_authenticate_with, Opts, []),
UserAccess = case UserAccess0 of
[] -> none;
_ ->
dict:from_list(UserAccess0)
end,
ContentTypes = build_list_content_types(
- gen_mod:get_opt(content_types, Opts,
- fun(L) when is_list(L) ->
- lists:map(
- fun({K, V}) ->
- {iolist_to_binary(K),
- iolist_to_binary(V)}
- end, L)
- end, []),
+ gen_mod:get_opt(content_types, Opts, []),
?DEFAULT_CONTENT_TYPES),
?DEBUG("known content types: ~s",
[str:join([[$*, K, " -> ", V] || {K, V} <- ContentTypes],
mod_opt_type(accesslog) -> fun iolist_to_binary/1;
mod_opt_type(content_types) ->
- fun (L) when is_list(L) -> L end;
+ fun(L) when is_list(L) ->
+ lists:map(
+ fun({K, V}) ->
+ {iolist_to_binary(K),
+ iolist_to_binary(V)}
+ end, L)
+ end;
mod_opt_type(custom_headers) ->
fun (L) when is_list(L) -> L end;
mod_opt_type(default_content_type) ->
-spec start(binary(), gen_mod:opts()) -> {ok, pid()}.
start(ServerHost, Opts) ->
- case gen_mod:get_opt(rm_on_unregister, Opts,
- fun(B) when is_boolean(B) -> B end,
- true) of
+ case gen_mod:get_opt(rm_on_unregister, Opts, true) of
true ->
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE,
remove_user, 50);
-spec stop(binary()) -> ok | {error, any()}.
stop(ServerHost) ->
- case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister,
- fun(B) when is_boolean(B) -> B end,
- true) of
+ case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister, true) of
true ->
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE,
remove_user, 50);
init([ServerHost, Opts]) ->
process_flag(trap_exit, true),
Host = gen_mod:get_opt_host(ServerHost, Opts, <<"upload.@HOST@">>),
- Name = gen_mod:get_opt(name, Opts,
- fun iolist_to_binary/1,
- <<"HTTP File Upload">>),
- Access = gen_mod:get_opt(access, Opts,
- fun acl:access_rules_validator/1,
- local),
- MaxSize = gen_mod:get_opt(max_size, Opts,
- fun(I) when is_integer(I), I > 0 -> I;
- (infinity) -> infinity
- end,
- 104857600),
- SecretLength = gen_mod:get_opt(secret_length, Opts,
- fun(I) when is_integer(I), I >= 8 -> I end,
- 40),
- JIDinURL = gen_mod:get_opt(jid_in_url, Opts,
- fun(sha1) -> sha1;
- (node) -> node
- end,
- sha1),
- DocRoot = gen_mod:get_opt(docroot, Opts,
- fun iolist_to_binary/1,
- <<"@HOME@/upload">>),
- FileMode = gen_mod:get_opt(file_mode, Opts,
- fun(Mode) -> ?STR_TO_INT(Mode, 8) end),
- DirMode = gen_mod:get_opt(dir_mode, Opts,
- fun(Mode) -> ?STR_TO_INT(Mode, 8) end),
- PutURL = gen_mod:get_opt(put_url, Opts,
- fun(<<"http://", _/binary>> = URL) -> URL;
- (<<"https://", _/binary>> = URL) -> URL
- end,
- <<"http://@HOST@:5444">>),
- GetURL = gen_mod:get_opt(get_url, Opts,
- fun(<<"http://", _/binary>> = URL) -> URL;
- (<<"https://", _/binary>> = URL) -> URL
- end,
- PutURL),
- ServiceURL = gen_mod:get_opt(service_url, Opts,
- fun(<<"http://", _/binary>> = URL) -> URL;
- (<<"https://", _/binary>> = URL) -> URL
- end),
- Thumbnail = gen_mod:get_opt(thumbnail, Opts,
- fun(B) when is_boolean(B) -> B end,
- true),
+ Name = gen_mod:get_opt(name, Opts, <<"HTTP File Upload">>),
+ Access = gen_mod:get_opt(access, Opts, local),
+ MaxSize = gen_mod:get_opt(max_size, Opts, 104857600),
+ SecretLength = gen_mod:get_opt(secret_length, Opts, 40),
+ JIDinURL = gen_mod:get_opt(jid_in_url, Opts, sha1),
+ DocRoot = gen_mod:get_opt(docroot, Opts, <<"@HOME@/upload">>),
+ FileMode = gen_mod:get_opt(file_mode, Opts),
+ DirMode = gen_mod:get_opt(dir_mode, Opts),
+ PutURL = gen_mod:get_opt(put_url, Opts, <<"http://@HOST@:5444">>),
+ GetURL = gen_mod:get_opt(get_url, Opts, PutURL),
+ ServiceURL = gen_mod:get_opt(service_url, Opts),
+ Thumbnail = gen_mod:get_opt(thumbnail, Opts, true),
DocRoot1 = expand_home(str:strip(DocRoot, right, $/)),
DocRoot2 = expand_host(DocRoot1, ServerHost),
case DirMode of
get_proc_name(ServerHost, ModuleName) ->
PutURL = gen_mod:get_module_opt(ServerHost, ?MODULE, put_url,
- fun(<<"http://", _/binary>> = URL) -> URL;
- (<<"https://", _/binary>> = URL) -> URL;
- (_) -> <<"http://@HOST@">>
- end,
<<"http://@HOST@">>),
{ok, {_Scheme, _UserInfo, Host, _Port, Path, _Query}} =
http_uri:parse(binary_to_list(expand_host(PutURL, ServerHost))),
-spec iq_disco_info(binary(), binary(), binary(), [xdata()]) -> disco_info().
iq_disco_info(Host, Lang, Name, AddInfo) ->
- Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size,
- fun(I) when is_integer(I), I > 0 -> I;
- (infinity) -> infinity
- end,
- 104857600) of
+ Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size, 104857600) of
infinity ->
AddInfo;
MaxSize ->
-> {pos_integer(), [{binary(), binary()}], binary()}.
http_response(Host, Code, ExtraHeaders, Body) ->
- CustomHeaders =
- gen_mod:get_module_opt(Host, ?MODULE, custom_headers,
- fun(Headers) ->
- lists:map(fun({K, V}) ->
- {iolist_to_binary(K),
- iolist_to_binary(V)}
- end, Headers)
- end,
- []),
+ CustomHeaders = gen_mod:get_module_opt(Host, ?MODULE, custom_headers, []),
Headers = case proplists:is_defined(<<"Content-Type">>, ExtraHeaders) of
true ->
ExtraHeaders;
remove_user(User, Server) ->
ServerHost = jid:nameprep(Server),
DocRoot = gen_mod:get_module_opt(ServerHost, ?MODULE, docroot,
- fun iolist_to_binary/1,
<<"@HOME@/upload">>),
- JIDinURL = gen_mod:get_module_opt(ServerHost, ?MODULE, jid_in_url,
- fun(sha1) -> sha1;
- (node) -> node
- end,
- sha1),
+ JIDinURL = gen_mod:get_module_opt(ServerHost, ?MODULE, jid_in_url, sha1),
DocRoot1 = expand_host(expand_home(DocRoot), ServerHost),
UserStr = make_user_string(jid:make(User, Server), JIDinURL),
UserDir = str:join([DocRoot1, UserStr], <<$/>>),
init([ServerHost, Opts]) ->
process_flag(trap_exit, true),
AccessSoftQuota = gen_mod:get_opt(access_soft_quota, Opts,
- fun acl:shaper_rules_validator/1,
soft_upload_quota),
AccessHardQuota = gen_mod:get_opt(access_hard_quota, Opts,
- fun acl:shaper_rules_validator/1,
hard_upload_quota),
- MaxDays = gen_mod:get_opt(max_days, Opts,
- fun(I) when is_integer(I), I > 0 -> I;
- (infinity) -> infinity
- end,
- infinity),
+ MaxDays = gen_mod:get_opt(max_days, Opts, infinity),
DocRoot1 = gen_mod:get_module_opt(ServerHost, mod_http_upload, docroot,
- fun iolist_to_binary/1,
<<"@HOME@/upload">>),
DocRoot2 = mod_http_upload:expand_home(str:strip(DocRoot1, right, $/)),
DocRoot3 = mod_http_upload:expand_host(DocRoot2, ServerHost),
<<"irc.@HOST@">>),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
- Access = gen_mod:get_opt(access, Opts,
- fun acl:access_rules_validator/1,
- all),
+ Access = gen_mod:get_opt(access, Opts, all),
catch ets:new(irc_connection,
[named_table, public,
{keypos, #irc_connection.jid_server_host}]),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
register_hooks(MyHost, IQDisc),
ejabberd_router:register_route(MyHost, Host),
{ok,
handle_cast({reload, ServerHost, NewOpts, OldOpts}, State) ->
NewHost = gen_mod:get_opt_host(ServerHost, NewOpts, <<"irc.@HOST@">>),
OldHost = gen_mod:get_opt_host(ServerHost, OldOpts, <<"irc.@HOST@">>),
- NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts,
- fun gen_iq_handler:check_type/1,
- one_queue),
- OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue),
+ NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts, one_queue),
+ OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts, one_queue),
NewMod = gen_mod:db_mod(ServerHost, NewOpts, ?MODULE),
OldMod = gen_mod:db_mod(ServerHost, OldOpts, ?MODULE),
- Access = gen_mod:get_opt(access, NewOpts,
- fun acl:access_rules_validator/1,
- all),
+ Access = gen_mod:get_opt(access, NewOpts, all),
if NewMod /= OldMod ->
NewMod:init(ServerHost, NewOpts);
true ->
true ->
ok
end,
- Access = gen_mod:get_opt(access, NewOpts,
- fun acl:access_rules_validator/1,
- all),
+ Access = gen_mod:get_opt(access, NewOpts, all),
{noreply, State#state{host = NewHost, access = Access}};
handle_cast(Msg, State) ->
?WARNING_MSG("unexpected cast: ~p", [Msg]),
get_default_encoding(ServerHost) ->
Result = gen_mod:get_module_opt(ServerHost, ?MODULE, default_encoding,
- fun iolist_to_binary/1,
?DEFAULT_IRC_ENCODING),
?INFO_MSG("The default_encoding configured for "
"host ~p is: ~p~n",
Result.
get_realname(ServerHost) ->
- gen_mod:get_module_opt(ServerHost, ?MODULE, realname, fun iolist_to_binary/1, ?DEFAULT_REALNAME).
+ gen_mod:get_module_opt(ServerHost, ?MODULE, realname, ?DEFAULT_REALNAME).
get_webirc_password(ServerHost) ->
- gen_mod:get_module_opt(ServerHost, ?MODULE, webirc_password, fun iolist_to_binary/1, ?DEFAULT_WEBIRC_PASSWORD).
+ gen_mod:get_module_opt(ServerHost, ?MODULE, webirc_password, ?DEFAULT_WEBIRC_PASSWORD).
get_connection_params(Host, ServerHost, From,
IRCServer) ->
-callback remove_user(binary(), binary()) -> any().
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
true ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_LAST,
?MODULE, process_local_iq, IQDisc),
%%% API
%%%===================================================================
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Host, Opts),
get_room_config, 50),
ejabberd_hooks:add(set_room_option, Host, ?MODULE,
set_room_option, 50),
- case gen_mod:get_opt(assume_mam_usage, Opts,
- fun(B) when is_boolean(B) -> B end, false) of
+ case gen_mod:get_opt(assume_mam_usage, Opts, false) of
true ->
ejabberd_hooks:add(message_is_archived, Host, ?MODULE,
message_is_archived, 50);
true -> Mod:use_cache(Host, Opts);
false ->
gen_mod:get_opt(use_cache, Opts,
- mod_opt_type(use_cache),
ejabberd_config:use_cache(Host))
end.
cache_opts(Host, Opts) ->
MaxSize = gen_mod:get_opt(cache_size, Opts,
- mod_opt_type(cache_size),
ejabberd_config:cache_size(Host)),
CacheMissed = gen_mod:get_opt(cache_missed, Opts,
- mod_opt_type(cache_missed),
ejabberd_config:cache_missed(Host)),
LifeTime = case gen_mod:get_opt(cache_life_time, Opts,
- mod_opt_type(cache_life_time),
ejabberd_config:cache_life_time(Host)) of
infinity -> infinity;
I -> timer:seconds(I)
get_room_config, 50),
ejabberd_hooks:delete(set_room_option, Host, ?MODULE,
set_room_option, 50),
- case gen_mod:get_module_opt(Host, ?MODULE, assume_mam_usage,
- fun(B) when is_boolean(B) -> B end, false) of
+ case gen_mod:get_module_opt(Host, ?MODULE, assume_mam_usage, false) of
true ->
ejabberd_hooks:delete(message_is_archived, Host, ?MODULE,
message_is_archived, 50);
ok
end,
ets_cache:setopts(archive_prefs_cache, NewOpts),
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
register_iq_handlers(Host, IQDisc);
true ->
ok
end,
- case gen_mod:is_equal_opt(assume_mam_usage, NewOpts, OldOpts,
- fun(B) when is_boolean(B) -> B end, false) of
+ case gen_mod:is_equal_opt(assume_mam_usage, NewOpts, OldOpts, false) of
{false, true, _} ->
ejabberd_hooks:add(message_is_archived, Host, ?MODULE,
message_is_archived, 50);
message_is_archived(false, #{jid := JID} = C2SState, Pkt) ->
#jid{luser = LUser, lserver = LServer} = JID,
Peer = xmpp:get_from(Pkt),
- case gen_mod:get_module_opt(LServer, ?MODULE, assume_mam_usage,
- fun(B) when is_boolean(B) -> B end, false) of
+ case gen_mod:get_module_opt(LServer, ?MODULE, assume_mam_usage, false) of
true ->
should_archive(strip_my_archived_tag(Pkt, LServer), LServer)
andalso should_archive_peer(C2SState, LUser, LServer,
Prefs;
error ->
ActivateOpt = gen_mod:get_module_opt(
- LServer, ?MODULE, request_activates_archiving,
- fun(B) when is_boolean(B) -> B end, false),
+ LServer, ?MODULE,
+ request_activates_archiving, false),
case ActivateOpt of
true ->
#archive_prefs{us = {LUser, LServer}, default = never};
false ->
Default = gen_mod:get_module_opt(
- LServer, ?MODULE, default,
- fun(always) -> always;
- (never) -> never;
- (roster) -> roster
- end, never),
+ LServer, ?MODULE, default, never),
#archive_prefs{us = {LUser, LServer}, default = Default}
end
end.
xmlns = NS}.
maybe_activate_mam(LUser, LServer) ->
- ActivateOpt = gen_mod:get_module_opt(LServer, ?MODULE,
- request_activates_archiving,
- fun(B) when is_boolean(B) -> B end,
- false),
+ ActivateOpt = gen_mod:get_module_opt(
+ LServer, ?MODULE, request_activates_archiving, false),
case ActivateOpt of
true ->
Mod = gen_mod:db_mod(LServer, ?MODULE),
{ok, _Prefs} ->
ok;
error ->
- Default = gen_mod:get_module_opt(LServer, ?MODULE, default,
- fun(always) -> always;
- (never) -> never;
- (roster) -> roster
- end, never),
+ Default = gen_mod:get_module_opt(
+ LServer, ?MODULE, default, never),
write_prefs(LUser, LServer, LServer, Default, [], [])
end;
false ->
init([ServerHost, Opts]) ->
process_flag(trap_exit, true),
Host = gen_mod:get_opt_host(ServerHost, Opts, <<"mix.@HOST@">>),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
ConfigTab = gen_mod:get_module_proc(Host, config),
ets:new(ConfigTab, [named_table]),
ets:insert(ConfigTab, {plugins, [<<"mix">>]}),
init([Host, Opts]) ->
process_flag(trap_exit, true),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
#state{access = Access, host = MyHost,
history_size = HistorySize, queue_type = QueueType,
room_shaper = RoomShaper} = State = init_state(Host, Opts),
{reply, ok, State}.
handle_cast({reload, ServerHost, NewOpts, OldOpts}, #state{host = OldHost}) ->
- NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts,
- fun gen_iq_handler:check_type/1,
- one_queue),
- OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue),
+ NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts, one_queue),
+ OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts, one_queue),
NewMod = gen_mod:db_mod(ServerHost, NewOpts, ?MODULE),
NewRMod = gen_mod:ram_db_mod(ServerHost, NewOpts, ?MODULE),
OldMod = gen_mod:db_mod(ServerHost, OldOpts, ?MODULE),
init_state(Host, Opts) ->
MyHost = gen_mod:get_opt_host(Host, Opts,
<<"conference.@HOST@">>),
- Access = gen_mod:get_opt(access, Opts,
- fun acl:access_rules_validator/1, all),
- AccessCreate = gen_mod:get_opt(access_create, Opts,
- fun acl:access_rules_validator/1, all),
- AccessAdmin = gen_mod:get_opt(access_admin, Opts,
- fun acl:access_rules_validator/1,
- none),
- AccessPersistent = gen_mod:get_opt(access_persistent, Opts,
- fun acl:access_rules_validator/1,
- all),
- HistorySize = gen_mod:get_opt(history_size, Opts,
- fun(I) when is_integer(I), I>=0 -> I end,
- 20),
- MaxRoomsDiscoItems = gen_mod:get_opt(max_rooms_discoitems, Opts,
- fun(I) when is_integer(I), I>=0 -> I end,
- 100),
- DefRoomOpts1 = gen_mod:get_opt(default_room_options, Opts,
- fun(L) when is_list(L) -> L end,
- []),
- QueueType = case gen_mod:get_opt(queue_type, Opts,
- mod_opt_type(queue_type)) of
- undefined ->
- ejabberd_config:default_queue_type(Host);
- Type ->
- Type
- end,
+ Access = gen_mod:get_opt(access, Opts, all),
+ AccessCreate = gen_mod:get_opt(access_create, Opts, all),
+ AccessAdmin = gen_mod:get_opt(access_admin, Opts, none),
+ AccessPersistent = gen_mod:get_opt(access_persistent, Opts, all),
+ HistorySize = gen_mod:get_opt(history_size, Opts, 20),
+ MaxRoomsDiscoItems = gen_mod:get_opt(max_rooms_discoitems, Opts, 100),
+ DefRoomOpts1 = gen_mod:get_opt(default_room_options, Opts, []),
+ QueueType = gen_mod:get_opt(queue_type, Opts,
+ ejabberd_config:default_queue_type(Host)),
DefRoomOpts =
lists:flatmap(
fun({Opt, Val}) ->
[Opt, Val]),
fun(_) -> undefined end
end,
- case gen_mod:get_opt(Opt, [{Opt, Val}], VFun) of
+ case ejabberd_config:prepare_opt_val(Opt, Val, VFun, undefined) of
undefined -> [];
NewVal -> [{Opt, NewVal}]
end
end, DefRoomOpts1),
- RoomShaper = gen_mod:get_opt(room_shaper, Opts,
- fun(A) when is_atom(A) -> A end,
- none),
+ RoomShaper = gen_mod:get_opt(room_shaper, Opts, none),
#state{host = MyHost,
server_host = Host,
access = {Access, AccessCreate, AccessAdmin, AccessPersistent},
ServerHost = ejabberd_router:host_of_route(Host),
MaxRoomsDiscoItems = gen_mod:get_module_opt(
ServerHost, ?MODULE, max_rooms_discoitems,
- fun(I) when is_integer(I), I>=0 -> I end,
100),
case iq_disco_items(ServerHost, Host, From, Lang,
MaxRoomsDiscoItems, Node, RSM) of
end.
check_create_roomid(ServerHost, RoomID) ->
- Max = gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id,
- fun(infinity) -> infinity;
- (I) when is_integer(I), I>0 -> I
- end, infinity),
- Regexp = gen_mod:get_module_opt(ServerHost, ?MODULE, regexp_room_id,
- fun iolist_to_binary/1, ""),
+ Max = gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id, infinity),
+ Regexp = gen_mod:get_module_opt(ServerHost, ?MODULE, regexp_room_id, ""),
(byte_size(RoomID) =< Max) and
(re:run(RoomID, Regexp, [unicode, {capture, none}]) == match).
mod_opt_type(max_users_presence) ->
fun (MUP) when is_integer(MUP) -> MUP end;
mod_opt_type(min_message_interval) ->
- fun (MMI) when is_number(MMI) -> MMI end;
+ fun (MMI) when is_number(MMI), MMI >= 0 -> MMI end;
mod_opt_type(min_presence_interval) ->
fun (I) when is_number(I), I >= 0 -> I end;
mod_opt_type(room_shaper) ->
%% Get the default room options from the muc configuration
DefRoomOpts = gen_mod:get_module_opt(ServerHost, mod_muc,
- default_room_options, fun(X) -> X end, []),
+ default_room_options, []),
%% Change default room options as required
FormattedRoomOpts = [format_room_option(Opt, Val) || {Opt, Val}<-CustomRoomOpts],
RoomOpts = lists:ukeymerge(1,
mod_muc:store_room(ServerHost, Host, Name, RoomOpts),
%% Get all remaining mod_muc parameters that might be utilized
- Access = gen_mod:get_module_opt(ServerHost, mod_muc, access, fun(X) -> X end, all),
- AcCreate = gen_mod:get_module_opt(ServerHost, mod_muc, access_create, fun(X) -> X end, all),
- AcAdmin = gen_mod:get_module_opt(ServerHost, mod_muc, access_admin, fun(X) -> X end, none),
- AcPer = gen_mod:get_module_opt(ServerHost, mod_muc, access_persistent, fun(X) -> X end, all),
- HistorySize = gen_mod:get_module_opt(ServerHost, mod_muc, history_size, fun(X) -> X end, 20),
- RoomShaper = gen_mod:get_module_opt(ServerHost, mod_muc, room_shaper, fun(X) -> X end, none),
- QueueType = gen_mod:get_module_opt(ServerHost, mod_muc, queue_type, fun(X) -> X end,
+ Access = gen_mod:get_module_opt(ServerHost, mod_muc, access, all),
+ AcCreate = gen_mod:get_module_opt(ServerHost, mod_muc, access_create, all),
+ AcAdmin = gen_mod:get_module_opt(ServerHost, mod_muc, access_admin, none),
+ AcPer = gen_mod:get_module_opt(ServerHost, mod_muc, access_persistent, all),
+ HistorySize = gen_mod:get_module_opt(ServerHost, mod_muc, history_size, 20),
+ RoomShaper = gen_mod:get_module_opt(ServerHost, mod_muc, room_shaper, none),
+ QueueType = gen_mod:get_module_opt(ServerHost, mod_muc, queue_type,
ejabberd_config:default_queue_type(ServerHost)),
%% If the room does not exist yet in the muc_online_room
file:close(F),
%% Read the default room options defined for the first virtual host
DefRoomOpts = gen_mod:get_module_opt(?MYNAME, mod_muc,
- default_room_options,
- fun(L) when is_list(L) -> L end, []),
+ default_room_options, []),
[muc_create_room(?MYNAME, A, DefRoomOpts) || A <- Rooms],
ok.
%%% Internal functions
%%--------------------------------------------------------------------
init_state(Host, Opts) ->
- OutDir = gen_mod:get_opt(outdir, Opts,
- fun iolist_to_binary/1,
- <<"www/muc">>),
- DirType = gen_mod:get_opt(dirtype, Opts,
- fun(subdirs) -> subdirs;
- (plain) -> plain
- end, subdirs),
- DirName = gen_mod:get_opt(dirname, Opts,
- fun(room_jid) -> room_jid;
- (room_name) -> room_name
- end, room_jid),
- FileFormat = gen_mod:get_opt(file_format, Opts,
- fun(html) -> html;
- (plaintext) -> plaintext
- end, html),
- FilePermissions = gen_mod:get_opt(file_permissions, Opts,
- fun(SubOpts) ->
- F = fun({mode, Mode}, {_M, G}) ->
- {Mode, G};
- ({group, Group}, {M, _G}) ->
- {M, Group}
- end,
- lists:foldl(F, {644, 33}, SubOpts)
- end, {644, 33}),
- CSSFile = gen_mod:get_opt(cssfile, Opts,
- fun iolist_to_binary/1,
- false),
- AccessLog = gen_mod:get_opt(access_log, Opts,
- fun acl:access_rules_validator/1,
- muc_admin),
- Timezone = gen_mod:get_opt(timezone, Opts,
- fun(local) -> local;
- (universal) -> universal
- end, local),
- Top_link = gen_mod:get_opt(top_link, Opts,
- fun([{S1, S2}]) ->
- {iolist_to_binary(S1),
- iolist_to_binary(S2)}
- end, {<<"/">>, <<"Home">>}),
- NoFollow = gen_mod:get_opt(spam_prevention, Opts,
- fun(B) when is_boolean(B) -> B end,
- true),
+ OutDir = gen_mod:get_opt(outdir, Opts, <<"www/muc">>),
+ DirType = gen_mod:get_opt(dirtype, Opts, subdirs),
+ DirName = gen_mod:get_opt(dirname, Opts, room_jid),
+ FileFormat = gen_mod:get_opt(file_format, Opts, html),
+ FilePermissions = gen_mod:get_opt(file_permissions, Opts, {644, 33}),
+ CSSFile = gen_mod:get_opt(cssfile, Opts, false),
+ AccessLog = gen_mod:get_opt(access_log, Opts, muc_admin),
+ Timezone = gen_mod:get_opt(timezone, Opts, local),
+ Top_link = gen_mod:get_opt(top_link, Opts, {<<"/">>, <<"Home">>}),
+ NoFollow = gen_mod:get_opt(spam_prevention, Opts, true),
Lang = ejabberd_config:get_lang(Host),
#logstate{host = Host, out_dir = OutDir,
dir_type = DirType, dir_name = DirName,
xmpp:has_subtag(Packet, #hint{type = 'no-permanent-storage'}).
mod_opt_type(access_log) ->
- fun (A) when is_atom(A) -> A end;
+ fun acl:access_rules_validator/1;
mod_opt_type(cssfile) -> fun iolist_to_binary/1;
mod_opt_type(dirname) ->
fun (room_jid) -> room_jid;
MinMessageInterval = trunc(gen_mod:get_module_opt(
StateData#state.server_host,
mod_muc, min_message_interval,
- fun(MMI) when is_number(MMI) -> MMI end, 0)
- * 1000000),
+ 0) * 1000000),
Size = element_size(Packet),
{MessageShaper, MessageShaperInterval} =
shaper:update(Activity#activity.message_shaper, Size),
MinPresenceInterval =
trunc(gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, min_presence_interval,
- fun(I) when is_number(I), I>=0 ->
- I
- end, 0)
- * 1000000),
+ 0) * 1000000),
if (Now >= Activity#activity.presence_time + MinPresenceInterval)
and (Activity#activity.presence == undefined) ->
NewActivity = Activity#activity{presence_time = Now},
get_service_max_users(StateData) ->
gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, max_users,
- fun(I) when is_integer(I), I>0 -> I end,
?MAX_USERS_DEFAULT).
-spec get_max_users_admin_threshold(state()) -> pos_integer().
get_max_users_admin_threshold(StateData) ->
gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, max_users_admin_threshold,
- fun(I) when is_integer(I), I>0 -> I end,
5).
-spec room_queue_new(binary(), shaper:shaper(), _) -> p1_queue:queue().
HaveRoomShaper = Shaper /= none,
HaveMessageShaper = gen_mod:get_module_opt(
ServerHost, mod_muc, user_message_shaper,
- fun(A) when is_atom(A) -> A end,
none) /= none,
HavePresenceShaper = gen_mod:get_module_opt(
ServerHost, mod_muc, user_presence_shaper,
- fun(A) when is_atom(A) -> A end,
none) /= none,
HaveMinMessageInterval = gen_mod:get_module_opt(
ServerHost, mod_muc, min_message_interval,
- fun(I) when is_number(I), I>=0 -> I end,
0) /= 0,
HaveMinPresenceInterval = gen_mod:get_module_opt(
ServerHost, mod_muc, min_presence_interval,
- fun(I) when is_number(I), I>=0 -> I end,
0) /= 0,
if HaveRoomShaper or HaveMessageShaper or HavePresenceShaper
or HaveMinMessageInterval or HaveMinPresenceInterval ->
MessageShaper =
shaper:new(gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, user_message_shaper,
- fun(A) when is_atom(A) -> A end,
none)),
PresenceShaper =
shaper:new(gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, user_presence_shaper,
- fun(A) when is_atom(A) -> A end,
none)),
#activity{message_shaper = MessageShaper,
presence_shaper = PresenceShaper}
MinMessageInterval =
trunc(gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, min_message_interval,
- fun(I) when is_number(I), I>=0 -> I end,
- 0)
- * 1000),
+ 0) * 1000),
MinPresenceInterval =
trunc(gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, min_presence_interval,
- fun(I) when is_number(I), I>=0 -> I end,
- 0)
- * 1000),
+ 0) * 1000),
Key = jid:tolower(JID),
Now = p1_time_compat:system_time(micro_seconds),
Activity1 = clean_treap(StateData#state.activity,
MaxConferences =
gen_mod:get_module_opt(StateData#state.server_host,
mod_muc, max_user_conferences,
- fun(I) when is_integer(I), I>0 -> I end,
10),
Collision = nick_collision(From, Nick, StateData),
IsSubscribeRequest = not is_record(Packet, presence),
-spec is_room_overcrowded(state()) -> boolean().
is_room_overcrowded(StateData) ->
- MaxUsersPresence = gen_mod:get_module_opt(StateData#state.server_host,
- mod_muc, max_users_presence,
- fun(MUP) when is_integer(MUP) -> MUP end,
- ?DEFAULT_MAX_USERS_PRESENCE),
+ MaxUsersPresence = gen_mod:get_module_opt(
+ StateData#state.server_host,
+ mod_muc, max_users_presence,
+ ?DEFAULT_MAX_USERS_PRESENCE),
(?DICT):size(StateData#state.users) > MaxUsersPresence.
-spec presence_broadcast_allowed(jid(), state()) -> boolean().
MaxRoomName = gen_mod:get_module_opt(
StateData#state.server_host,
mod_muc, max_room_name,
- fun(infinity) -> infinity;
- (I) when is_integer(I),
- I>0 -> I
- end, infinity),
+ infinity),
MaxRoomDesc = gen_mod:get_module_opt(
StateData#state.server_host,
mod_muc, max_room_desc,
- fun(infinity) -> infinity;
- (I) when is_integer(I),
- I>0 ->
- I
- end, infinity),
+ infinity),
(byte_size(RoomName) =< MaxRoomName)
andalso (byte_size(RoomDesc) =< MaxRoomDesc).
DefRoomOpts =
gen_mod:get_module_opt(RoomState#state.server_host,
mod_muc, default_room_options,
- fun(L) when is_list(L) -> L end,
[]),
RoomState2 = set_opts(DefRoomOpts, RoomState),
(RoomState2#state.config)#config.max_users.
process_flag(trap_exit, true),
LServiceS = gen_mod:get_opt_host(LServerS, Opts,
<<"multicast.@HOST@">>),
- Access = gen_mod:get_opt(access, Opts,
- fun acl:access_rules_validator/1, all),
- SLimits =
- build_service_limit_record(gen_mod:get_opt(limits, Opts,
- fun (A) when is_list(A) ->
- A
- end,
- [])),
+ Access = gen_mod:get_opt(access, Opts, all),
+ SLimits = build_service_limit_record(gen_mod:get_opt(limits, Opts, [])),
create_cache(),
try_start_loop(),
create_pool(),
handle_cast({reload, NewOpts, NewOpts},
#state{lserver = LServerS, lservice = OldLServiceS} = State) ->
- Access = gen_mod:get_opt(access, NewOpts,
- fun acl:access_rules_validator/1, all),
- SLimits =
- build_service_limit_record(gen_mod:get_opt(limits, NewOpts,
- fun (A) when is_list(A) ->
- A
- end,
- [])),
+ Access = gen_mod:get_opt(access, NewOpts, all),
+ SLimits = build_service_limit_record(gen_mod:get_opt(limits, NewOpts, [])),
NewLServiceS = gen_mod:get_opt_host(LServerS, NewOpts,
<<"multicast.@HOST@">>),
if NewLServiceS /= OldLServiceS ->
process_flag(trap_exit, true),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- no_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, no_queue),
ejabberd_hooks:add(offline_message_hook, Host, ?MODULE,
store_packet, 50),
ejabberd_hooks:add(c2s_self_presence, Host, ?MODULE, c2s_self_presence, 50),
?MODULE, handle_offline_query, IQDisc),
AccessMaxOfflineMsgs =
gen_mod:get_opt(access_max_user_messages, Opts,
- fun acl:shaper_rules_validator/1,
max_user_offline_messages),
{ok,
#state{host = Host,
true ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_FLEX_OFFLINE,
?MODULE, handle_offline_query, IQDisc);
ok
end,
case gen_mod:is_equal_opt(access_max_user_messages, NewOpts, OldOpts,
- fun acl:shaper_rules_validator/1,
max_user_offline_messages) of
{false, AccessMaxOfflineMsgs, _} ->
{noreply,
none ->
case gen_mod:get_module_opt(
LServer, ?MODULE, store_empty_body,
- fun(V) when is_boolean(V) -> V;
- (unless_chat_state) -> unless_chat_state
- end,
unless_chat_state) of
true ->
true;
get_messages_subset(User, Host, MsgsAll) ->
Access = gen_mod:get_module_opt(Host, ?MODULE, access_max_user_messages,
- fun(A) when is_atom(A) -> A end,
max_user_offline_messages),
MaxOfflineMsgs = case get_max_user_messages(Access,
User, Host)
init([Host, Opts]) ->
process_flag(trap_exit, true),
State = init_state(Host, Opts),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- no_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, no_queue),
register_iq_handlers(Host, IQDisc),
case State#state.send_pings of
true -> register_hooks(Host);
handle_cast({reload, Host, NewOpts, OldOpts},
#state{timers = Timers} = OldState) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} -> register_iq_handlers(Host, IQDisc);
true -> ok
end,
%% Internal functions
%%====================================================================
init_state(Host, Opts) ->
- SendPings = gen_mod:get_opt(send_pings, Opts,
- fun(B) when is_boolean(B) -> B end,
- ?DEFAULT_SEND_PINGS),
- PingInterval = gen_mod:get_opt(ping_interval, Opts,
- fun(I) when is_integer(I), I>0 -> I end,
- ?DEFAULT_PING_INTERVAL),
- PingAckTimeout = gen_mod:get_opt(ping_ack_timeout, Opts,
- fun(I) when is_integer(I), I>0 -> I * 1000 end,
- undefined),
- TimeoutAction = gen_mod:get_opt(timeout_action, Opts,
- fun(none) -> none;
- (kill) -> kill
- end, none),
+ SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS),
+ PingInterval = gen_mod:get_opt(ping_interval, Opts, ?DEFAULT_PING_INTERVAL),
+ PingAckTimeout = gen_mod:get_opt(ping_ack_timeout, Opts),
+ TimeoutAction = gen_mod:get_opt(timeout_action, Opts, none),
#state{host = Host,
send_pings = SendPings,
ping_interval = PingInterval,
mod_opt_type(ping_interval) ->
fun (I) when is_integer(I), I > 0 -> I end;
mod_opt_type(ping_ack_timeout) ->
- fun (I) when is_integer(I), I > 0 -> I end;
+ fun(I) when is_integer(I), I>0 -> timer:seconds(I) end;
mod_opt_type(send_pings) ->
fun (B) when is_boolean(B) -> B end;
mod_opt_type(timeout_action) ->
Acc.
update(Server, JID, Dir) ->
- StormCount = gen_mod:get_module_opt(Server, ?MODULE, count,
- fun(I) when is_integer(I), I>0 -> I end,
- 5),
- TimeInterval = gen_mod:get_module_opt(Server, ?MODULE, interval,
- fun(I) when is_integer(I), I>0 -> I end,
- 60),
+ StormCount = gen_mod:get_module_opt(Server, ?MODULE, count, 5),
+ TimeInterval = gen_mod:get_module_opt(Server, ?MODULE, interval, 60),
TimeStamp = p1_time_compat:system_time(seconds),
case read(Dir) of
undefined ->
-callback remove_user(binary(), binary()) -> any().
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
true ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY,
?MODULE, process_iq, IQDisc);
-callback remove_user(binary(), binary()) -> any().
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
ejabberd_hooks:add(remove_user, Host, ?MODULE,
true ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PRIVATE,
?MODULE, process_sm_iq, IQDisc);
reload(_Host, _NewOpts, _OldOpts) ->
ok.
-mod_opt_type(roster) -> v_roster();
-mod_opt_type(message) -> v_message();
-mod_opt_type(presence) -> v_presence();
+mod_opt_type(roster) ->
+ fun(Props) ->
+ lists:map(
+ fun({both, ACL}) -> {both, acl:access_rules_validator(ACL)};
+ ({get, ACL}) -> {get, acl:access_rules_validator(ACL)};
+ ({set, ACL}) -> {set, acl:access_rules_validator(ACL)}
+ end, Props)
+ end;
+mod_opt_type(message) ->
+ fun(Props) ->
+ lists:map(
+ fun({outgoing, ACL}) -> {outgoing, acl:access_rules_validator(ACL)}
+ end, Props)
+ end;
+mod_opt_type(presence) ->
+ fun(Props) ->
+ lists:map(
+ fun({managed_entity, ACL}) ->
+ {managed_entity, acl:access_rules_validator(ACL)};
+ ({roster, ACL}) ->
+ {roster, acl:access_rules_validator(ACL)}
+ end, Props)
+ end;
mod_opt_type(_) ->
[roster, message, presence].
end.
get_roster_permission(ServerHost, Host) ->
- Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, roster,
- v_roster(), []),
+ Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, roster, []),
case match_rule(ServerHost, Host, Perms, both) of
allow ->
both;
end.
get_message_permission(ServerHost, Host) ->
- Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, message,
- v_message(), []),
+ Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, message, []),
case match_rule(ServerHost, Host, Perms, outgoing) of
allow -> outgoing;
deny -> none
end.
get_presence_permission(ServerHost, Host) ->
- Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, presence,
- v_presence(), []),
+ Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, presence, []),
case match_rule(ServerHost, Host, Perms, roster) of
allow ->
roster;
match_rule(ServerHost, Host, Perms, Type) ->
Access = proplists:get_value(Type, Perms, none),
acl:match_rule(ServerHost, Access, jid:make(Host)).
-
-v_roster() ->
- fun(Props) ->
- lists:map(
- fun({both, ACL}) -> {both, acl:access_rules_validator(ACL)};
- ({get, ACL}) -> {get, acl:access_rules_validator(ACL)};
- ({set, ACL}) -> {set, acl:access_rules_validator(ACL)}
- end, Props)
- end.
-
-v_message() ->
- fun(Props) ->
- lists:map(
- fun({outgoing, ACL}) -> {outgoing, acl:access_rules_validator(ACL)}
- end, Props)
- end.
-
-v_presence() ->
- fun(Props) ->
- lists:map(
- fun({managed_entity, ACL}) ->
- {managed_entity, acl:access_rules_validator(ACL)};
- ({roster, ACL}) ->
- {roster, acl:access_rules_validator(ACL)}
- end, Props)
- end.
ok | {error, limit | conflict | notfound | term()}.
start(Host, Opts) ->
- case mod_proxy65_service:add_listener(Host, Opts) of
+ {ListenOpts, ModOpts} = lists:partition(
+ fun({auth_type, _}) -> true;
+ ({recbuf, _}) -> true;
+ ({sndbuf, _}) -> true;
+ ({shaper, _}) -> true;
+ (_) -> false
+ end, Opts),
+ case mod_proxy65_service:add_listener(Host, ListenOpts) of
{error, _} = Err ->
Err;
_ ->
Mod = gen_mod:ram_db_mod(global, ?MODULE),
Mod:init(),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
- ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
+ ChildSpec = {Proc, {?MODULE, start_link, [Host, ModOpts]},
transient, infinity, supervisor, [?MODULE]},
supervisor:start_child(ejabberd_gen_mod_sup, ChildSpec)
end.
depends(_Host, _Opts) ->
[].
-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 acl:shaper_rules_validator/1;
-mod_opt_type(sndbuf) ->
- fun (I) when is_integer(I), I > 0 -> I end;
mod_opt_type(access) -> fun acl:access_rules_validator/1;
mod_opt_type(host) -> fun iolist_to_binary/1;
mod_opt_type(hostname) -> fun iolist_to_binary/1;
end;
mod_opt_type(ram_db_type) ->
fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
-mod_opt_type(_) ->
- [auth_type, recbuf, shaper, sndbuf,
- access, host, hostname, ip, name, port,
- max_connections, ram_db_type].
+mod_opt_type(Opt) ->
+ case mod_proxy65_stream:listen_opt_type(Opt) of
+ Opts when is_list(Opts) ->
+ [access, host, hostname, ip, name, port,
+ max_connections, ram_db_type] ++ Opts;
+ Fun ->
+ Fun
+ end.
init([Host, Opts]) ->
process_flag(trap_exit, true),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
MyHost = gen_mod:get_opt_host(Host, Opts, <<"proxy.@HOST@">>),
gen_iq_handler:add_iq_handler(ejabberd_local, MyHost, ?NS_DISCO_INFO,
?MODULE, process_disco_info, IQDisc),
handle_cast({reload, ServerHost, NewOpts, OldOpts}, State) ->
NewHost = gen_mod:get_opt_host(ServerHost, NewOpts, <<"proxy.@HOST@">>),
OldHost = gen_mod:get_opt_host(ServerHost, OldOpts, <<"proxy.@HOST@">>),
- NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts,
- fun gen_iq_handler:check_type/1,
- one_queue),
- OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue),
+ NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts, one_queue),
+ OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts, one_queue),
if (NewIQDisc /= OldIQDisc) or (NewHost /= OldHost) ->
gen_iq_handler:add_iq_handler(ejabberd_local, NewHost, ?NS_DISCO_INFO,
?MODULE, process_disco_info, NewIQDisc),
%%%------------------------
add_listener(Host, Opts) ->
- NewOpts = [Host | Opts],
+ NewOpts = [{server_host, Host} | Opts],
ejabberd_listener:add_listener(get_port_ip(Host),
mod_proxy65_stream, NewOpts).
process_disco_info(#iq{type = get, to = To, lang = Lang} = IQ) ->
Host = ejabberd_router:host_of_route(To#jid.lserver),
Name = gen_mod:get_module_opt(Host, mod_proxy65, name,
- fun iolist_to_binary/1,
<<"SOCKS5 Bytestreams">>),
Info = ejabberd_hooks:run_fold(disco_info, Host,
[], [Host, ?MODULE, <<"">>, <<"">>]),
process_bytestreams(#iq{type = get, from = JID, to = To, lang = Lang} = IQ) ->
Host = To#jid.lserver,
ServerHost = ejabberd_router:host_of_route(Host),
- ACL = gen_mod:get_module_opt(ServerHost, mod_proxy65, access,
- fun acl:access_rules_validator/1,
- all),
+ ACL = gen_mod:get_module_opt(ServerHost, mod_proxy65, access, all),
case acl:match_rule(ServerHost, ACL, JID) of
allow ->
StreamHost = get_streamhost(Host, ServerHost),
sub_els = [#bytestreams{activate = TargetJID,
sid = SID}]} = IQ) ->
ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
- ACL = gen_mod:get_module_opt(ServerHost, mod_proxy65, access,
- fun acl:access_rules_validator/1,
- all),
+ ACL = gen_mod:get_module_opt(ServerHost, mod_proxy65, access, all),
case acl:match_rule(ServerHost, ACL, InitiatorJID) of
allow ->
Node = ejabberd_cluster:get_node_by_id(To#jid.lresource),
get_streamhost(Host, ServerHost) ->
{Port, IP} = get_port_ip(ServerHost),
HostName = gen_mod:get_module_opt(ServerHost, mod_proxy65, hostname,
- fun iolist_to_binary/1,
misc:ip_to_list(IP)),
Resource = ejabberd_cluster:node_id(),
#streamhost{jid = jid:make(<<"">>, Host, Resource),
-spec get_port_ip(binary()) -> {pos_integer(), inet:ip_address()}.
get_port_ip(Host) ->
- Port = gen_mod:get_module_opt(Host, mod_proxy65, port,
- fun(P) when is_integer(P), P>0, P<65536 ->
- P
- end,
- 7777),
- IP = gen_mod:get_module_opt(Host, mod_proxy65, ip,
- fun(S) ->
- {ok, Addr} = inet_parse:address(
- binary_to_list(
- iolist_to_binary(S))),
- Addr
- end, get_my_ip()),
+ Port = gen_mod:get_module_opt(Host, mod_proxy65, port, 7777),
+ IP = gen_mod:get_module_opt(Host, mod_proxy65, ip, get_my_ip()),
{Port, IP}.
-spec get_my_ip() -> inet:ip_address().
end.
max_connections(ServerHost) ->
- gen_mod:get_module_opt(ServerHost, mod_proxy65, max_connections,
- fun(I) when is_integer(I), I>0 -> I;
- (infinity) -> infinity
- end, infinity).
+ gen_mod:get_module_opt(ServerHost, mod_proxy65, max_connections, infinity).
stream_established/2]).
-export([start/2, stop/1, start_link/3, activate/2,
- relay/3, socket_type/0]).
+ relay/3, socket_type/0, listen_opt_type/1]).
-include("mod_proxy65.hrl").
%%-------------------------------
start({gen_tcp, Socket}, Opts1) ->
- {[Host], Opts} = lists:partition(fun (O) -> is_binary(O)
- end,
- Opts1),
+ {[{server_host, Host}], Opts} = lists:partition(
+ fun({server_host, _}) -> true;
+ (_) -> false
+ end, Opts1),
Supervisor = gen_mod:get_module_proc(Host,
ejabberd_mod_proxy65_sup),
supervisor:start_child(Supervisor,
init([Socket, Host, Opts]) ->
process_flag(trap_exit, true),
- AuthType = gen_mod:get_opt(auth_type, Opts,
- fun(plain) -> plain;
- (anonymous) -> anonymous
- end, anonymous),
- Shaper = gen_mod:get_opt(shaper, Opts,
- fun acl:shaper_rules_validator/1,
- none),
- RecvBuf = gen_mod:get_opt(recbuf, Opts,
- fun(I) when is_integer(I), I>0 -> I end,
- 8192),
- SendBuf = gen_mod:get_opt(sndbuf, Opts,
- fun(I) when is_integer(I), I>0 -> I end,
- 8192),
+ AuthType = gen_mod:get_opt(auth_type, Opts, anonymous),
+ Shaper = gen_mod:get_opt(shaper, Opts, none),
+ RecvBuf = gen_mod:get_opt(recbuf, Opts, 8192),
+ SendBuf = gen_mod:get_opt(sndbuf, Opts, 8192),
TRef = erlang:send_after(?WAIT_TIMEOUT, self(), stop),
inet:setopts(Socket,
[{active, true}, {recbuf, RecvBuf}, {sndbuf, SendBuf}]),
if MaxRate1 == none; MaxRate2 == none -> none;
true -> lists:max([MaxRate1, MaxRate2])
end.
+
+listen_opt_type(server_host) ->
+ fun iolist_to_binary/1;
+listen_opt_type(auth_type) ->
+ fun (plain) -> plain;
+ (anonymous) -> anonymous
+ end;
+listen_opt_type(recbuf) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+listen_opt_type(shaper) -> fun acl:shaper_rules_validator/1;
+listen_opt_type(sndbuf) ->
+ fun (I) when is_integer(I), I > 0 -> I end;
+listen_opt_type(_) ->
+ [auth_type, recbuf, sndbuf, shaper].
?DEBUG("pubsub init ~p ~p", [ServerHost, Opts]),
Host = gen_mod:get_opt_host(ServerHost, Opts, <<"pubsub.@HOST@">>),
ejabberd_router:register_route(Host, ServerHost),
- Access = gen_mod:get_opt(access_createnode, Opts,
- fun acl:access_rules_validator/1, all),
- PepOffline = gen_mod:get_opt(ignore_pep_from_offline, Opts,
- fun(A) when is_boolean(A) -> A end, true),
- IQDisc = gen_mod:get_opt(iqdisc, Opts,
- fun gen_iq_handler:check_type/1, one_queue),
- LastItemCache = gen_mod:get_opt(last_item_cache, Opts,
- fun(A) when is_boolean(A) -> A end, false),
- MaxItemsNode = gen_mod:get_opt(max_items_node, Opts,
- fun(A) when is_integer(A) andalso A >= 0 -> A end, ?MAXITEMS),
- MaxSubsNode = gen_mod:get_opt(max_subscriptions_node, Opts,
- fun(A) when is_integer(A) andalso A >= 0 -> A end, undefined),
+ Access = gen_mod:get_opt(access_createnode, Opts, all),
+ PepOffline = gen_mod:get_opt(ignore_pep_from_offline, Opts, true),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
+ LastItemCache = gen_mod:get_opt(last_item_cache, Opts, false),
+ MaxItemsNode = gen_mod:get_opt(max_items_node, Opts, ?MAXITEMS),
+ MaxSubsNode = gen_mod:get_opt(max_subscriptions_node, Opts),
case gen_mod:db_type(ServerHost, ?MODULE) of
mnesia -> pubsub_index:init(Host, ServerHost, Opts);
_ -> ok
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
DefaultModule = plugin(Host, hd(Plugins)),
BaseOptions = DefaultModule:options(),
- DefaultNodeCfg = gen_mod:get_opt(default_node_config, Opts,
- fun(A) when is_list(A) -> filter_node_options(A, BaseOptions) end, []),
+ DefaultNodeCfg = filter_node_options(
+ gen_mod:get_opt(default_node_config, Opts, []),
+ BaseOptions),
ejabberd_mnesia:create(?MODULE, pubsub_last_item,
[{ram_copies, [node()]},
{attributes, record_info(fields, pubsub_last_item)}]),
depends(ServerHost, Opts) ->
Host = gen_mod:get_opt_host(ServerHost, Opts, <<"pubsub.@HOST@">>),
- Plugins = gen_mod:get_opt(plugins, Opts,
- fun(A) when is_list(A) -> A end, [?STDNODE]),
+ Plugins = gen_mod:get_opt(plugins, Opts, [?STDNODE]),
lists:flatmap(
fun(Name) ->
Plugin = plugin(ServerHost, Name),
%% <em>node_plugin</em>. The 'node_' prefix is mandatory.</p>
%% <p>See {@link node_hometree:init/1} for an example implementation.</p>
init_plugins(Host, ServerHost, Opts) ->
- TreePlugin = tree(Host, gen_mod:get_opt(nodetree, Opts,
- fun(A) when is_binary(A) -> A end,
- ?STDTREE)),
+ TreePlugin = tree(Host, gen_mod:get_opt(nodetree, Opts, ?STDTREE)),
?DEBUG("** tree plugin is ~p", [TreePlugin]),
TreePlugin:init(Host, ServerHost, Opts),
- Plugins = gen_mod:get_opt(plugins, Opts,
- fun(A) when is_list(A) -> A end, [?STDNODE]),
- PepMapping = gen_mod:get_opt(pep_mapping, Opts,
- fun(A) when is_list(A) -> A end, []),
+ Plugins = gen_mod:get_opt(plugins, Opts, [?STDNODE]),
+ PepMapping = gen_mod:get_opt(pep_mapping, Opts, []),
?DEBUG("** PEP Mapping : ~p~n", [PepMapping]),
PluginsOK = lists:foldl(
fun (Name, Acc) ->
-include("xmpp.hrl").
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_REGISTER, ?MODULE, process_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_REGISTER).
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_REGISTER,
?MODULE, process_iq, IQDisc),
-spec stream_feature_register([xmpp_element()], binary()) -> [xmpp_element()].
stream_feature_register(Acc, Host) ->
- AF = gen_mod:get_module_opt(Host, ?MODULE, access_from,
- fun(A) -> A end,
- all),
+ AF = gen_mod:get_module_opt(Host, ?MODULE, access_from, all),
case (AF /= none) of
true ->
[#feature_register{}|Acc];
process_iq(#iq{from = From, to = To} = IQ, Source) ->
IsCaptchaEnabled =
case gen_mod:get_module_opt(To#jid.lserver, ?MODULE,
- captcha_protected,
- fun(B) when is_boolean(B) -> B end,
- false) of
+ captcha_protected, false) of
true -> true;
false -> false
end,
Server = To#jid.lserver,
- Access = gen_mod:get_module_opt(Server, ?MODULE, access,
- fun(A) -> A end, all),
+ Access = gen_mod:get_module_opt(Server, ?MODULE, access, all),
AllowRemove = allow == acl:match_rule(Server, Access, From),
process_iq(IQ, Source, IsCaptchaEnabled, AllowRemove).
false -> {error, xmpp:err_bad_request(<<"Malformed username">>, Lang)};
_ ->
JID = jid:make(User, Server),
- Access = gen_mod:get_module_opt(Server, ?MODULE, access,
- fun(A) -> A end,
- all),
+ Access = gen_mod:get_module_opt(Server, ?MODULE, access, all),
IPAccess = get_ip_access(Server),
case {acl:match_rule(Server, Access, JID),
check_ip_access(SourceRaw, IPAccess)}
send_welcome_message(JID) ->
Host = JID#jid.lserver,
case gen_mod:get_module_opt(Host, ?MODULE, 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, {<<"">>, <<"">>})
- of
+ {<<"">>, <<"">>}) of
{<<"">>, <<"">>} -> ok;
{Subj, Body} ->
ejabberd_router:route(
send_registration_notifications(Mod, UJID, Source) ->
Host = UJID#jid.lserver,
- case gen_mod:get_module_opt(
- Host, Mod, registration_watchers,
- fun(Ss) ->
- [jid:decode(iolist_to_binary(S)) || S <- Ss]
- end, []) of
+ case gen_mod:get_module_opt(Host, Mod, registration_watchers, []) of
[] -> ok;
JIDs when is_list(JIDs) ->
Body =
_Server) ->
allow;
check_from(JID, Server) ->
- Access = gen_mod:get_module_opt(Server, ?MODULE, access_from,
- fun(A) -> A end,
- none),
+ Access = gen_mod:get_module_opt(Server, ?MODULE, access_from, none),
acl:match_rule(Server, Access, JID).
check_timeout(undefined) -> true;
is_strong_password2(Server, Password) ->
LServer = jid:nameprep(Server),
- case gen_mod:get_module_opt(LServer, ?MODULE, password_strength,
- fun(N) when is_number(N), N>=0 -> N end,
- 0) of
+ case gen_mod:get_module_opt(LServer, ?MODULE, password_strength, 0) of
0 ->
true;
Entropy ->
may_remove_resource(From) -> From.
get_ip_access(Host) ->
- gen_mod:get_module_opt(Host, ?MODULE, ip_access,
- fun(A) when is_atom(A) -> A end,
- all).
+ gen_mod:get_module_opt(Host, ?MODULE, ip_access, all).
check_ip_access({User, Server, Resource}, IPAccess) ->
case ejabberd_sm:get_user_ip(User, Server, Resource) of
%% {error, not_allowed} |
%% {error, invalid_jid}
register_account(Username, Host, Password) ->
- Access = gen_mod:get_module_opt(Host, mod_register, access,
- fun(A) -> A end,
- all),
+ Access = gen_mod:get_module_opt(Host, mod_register, access, all),
case jid:make(Username, Host) of
error -> {error, invalid_jid};
JID ->
{subscription(), [binary()]}.
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
ejabberd_hooks:add(roster_get, Host, ?MODULE,
true ->
ok
end,
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ROSTER,
?MODULE, process_iq, IQDisc);
xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
false ->
#jid{server = Server} = From,
- Access = gen_mod:get_module_opt(Server, ?MODULE,
- access, fun(A) -> A end, all),
+ Access = gen_mod:get_module_opt(Server, ?MODULE, access, all),
case acl:match_rule(Server, Access, From) of
deny ->
Txt = <<"Denied by ACL">>,
<- Items]))).
roster_versioning_enabled(Host) ->
- gen_mod:get_module_opt(Host, ?MODULE, versioning,
- fun(B) when is_boolean(B) -> B end,
- false).
+ gen_mod:get_module_opt(Host, ?MODULE, versioning, false).
roster_version_on_db(Host) ->
- gen_mod:get_module_opt(Host, ?MODULE, store_current_id,
- fun(B) when is_boolean(B) -> B end,
- false).
+ gen_mod:get_module_opt(Host, ?MODULE, store_current_id, false).
%% Returns a list that may contain an xmlelement with the XEP-237 feature if it's enabled.
-spec get_versioning_feature([xmpp_element()], binary()) -> [xmpp_element()].
-spec log_packet(stanza(), binary()) -> ok.
log_packet(Packet, Host) ->
- Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers,
- mod_opt_type(loggers), []),
+ Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []),
ForwardedMsg = #message{from = jid:make(Host),
id = randoms:get_string(),
sub_els = [#forwarded{
parse_options(Host, Opts) ->
Eldap_ID = misc:atom_to_binary(gen_mod:get_module_proc(Host, ?MODULE)),
Cfg = eldap_utils:get_config(Host, Opts),
- GroupAttr = gen_mod:get_opt(ldap_groupattr, Opts,
- fun iolist_to_binary/1,
- <<"cn">>),
- GroupDesc = gen_mod:get_opt(ldap_groupdesc, Opts,
- fun iolist_to_binary/1,
- GroupAttr),
- UserDesc = gen_mod:get_opt(ldap_userdesc, Opts,
- fun iolist_to_binary/1,
- <<"cn">>),
- UserUID = gen_mod:get_opt(ldap_useruid, Opts,
- fun iolist_to_binary/1,
- <<"cn">>),
- UIDAttr = gen_mod:get_opt(ldap_memberattr, Opts,
- fun iolist_to_binary/1,
- <<"memberUid">>),
- UIDAttrFormat = gen_mod:get_opt(ldap_memberattr_format, Opts,
- fun iolist_to_binary/1,
- <<"%u">>),
- UIDAttrFormatRe = gen_mod:get_opt(ldap_memberattr_format_re, Opts,
- fun(S) ->
- Re = iolist_to_binary(S),
- {ok, MP} = re:compile(Re),
- MP
- end, <<"">>),
- AuthCheck = gen_mod:get_opt(ldap_auth_check, Opts,
- fun(on) -> true;
- (off) -> false;
- (false) -> false;
- (true) -> true
- end, true),
- ConfigFilter = gen_mod:get_opt({ldap_filter, Host}, Opts,
- fun eldap_utils:check_filter/1, <<"">>),
- ConfigUserFilter = gen_mod:get_opt({ldap_ufilter, Host}, Opts,
- fun eldap_utils:check_filter/1, <<"">>),
- ConfigGroupFilter = gen_mod:get_opt({ldap_gfilter, Host}, Opts,
- fun eldap_utils:check_filter/1, <<"">>),
- RosterFilter = gen_mod:get_opt({ldap_rfilter, Host}, Opts,
- fun eldap_utils:check_filter/1, <<"">>),
+ GroupAttr = gen_mod:get_opt(ldap_groupattr, Opts, <<"cn">>),
+ GroupDesc = gen_mod:get_opt(ldap_groupdesc, Opts, GroupAttr),
+ UserDesc = gen_mod:get_opt(ldap_userdesc, Opts, <<"cn">>),
+ UserUID = gen_mod:get_opt(ldap_useruid, Opts, <<"cn">>),
+ UIDAttr = gen_mod:get_opt(ldap_memberattr, Opts, <<"memberUid">>),
+ UIDAttrFormat = gen_mod:get_opt(ldap_memberattr_format, Opts, <<"%u">>),
+ UIDAttrFormatRe = gen_mod:get_opt(ldap_memberattr_format_re, Opts, <<"">>),
+ AuthCheck = gen_mod:get_opt(ldap_auth_check, Opts, true),
+ ConfigFilter = gen_mod:get_opt({ldap_filter, Host}, Opts, <<"">>),
+ ConfigUserFilter = gen_mod:get_opt({ldap_ufilter, Host}, Opts, <<"">>),
+ ConfigGroupFilter = gen_mod:get_opt({ldap_gfilter, Host}, Opts, <<"">>),
+ RosterFilter = gen_mod:get_opt({ldap_rfilter, Host}, Opts, <<"">>),
SubFilter = <<"(&(", UIDAttr/binary, "=",
UIDAttrFormat/binary, ")(", GroupAttr/binary, "=%g))">>,
UserSubFilter = case ConfigUserFilter of
UseCache.
use_cache(Host, Opts) ->
- gen_mod:get_opt(use_cache, Opts, mod_opt_type(use_cache),
- ejabberd_config:use_cache(Host)).
+ gen_mod:get_opt(use_cache, Opts, ejabberd_config:use_cache(Host)).
cache_opts(Host, Opts) ->
MaxSize = gen_mod:get_opt(cache_size, Opts,
- mod_opt_type(cache_size),
ejabberd_config:cache_size(Host)),
CacheMissed = gen_mod:get_opt(cache_missed, Opts,
- mod_opt_type(cache_missed),
ejabberd_config:cache_missed(Host)),
LifeTime = case gen_mod:get_opt(cache_life_time, Opts,
- mod_opt_type(cache_life_time),
ejabberd_config:cache_life_time(Host)) of
infinity -> infinity;
I -> timer:seconds(I)
-include("xmpp.hrl").
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_0,
?MODULE, process_local_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_SIC_0,
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_SIC_1).
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_0,
?MODULE, process_local_iq, IQDisc),
esip:has_param(<<"tag">>, Params).
need_record_route(LServer) ->
- gen_mod:get_module_opt(
- LServer, mod_sip, always_record_route,
- fun(true) -> true;
- (false) -> false
- end, true).
+ gen_mod:get_module_opt(LServer, mod_sip, always_record_route, true).
make_sign(TS, Hdrs) ->
{_, #uri{user = FUser, host = FServer}, FParams} = esip:get_hdr('from', Hdrs),
end.
get_configured_vias(LServer) ->
- gen_mod:get_module_opt(
- LServer, mod_sip, 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, []).
+ gen_mod:get_module_opt(LServer, mod_sip, via, []).
get_configured_record_route(LServer) ->
gen_mod:get_module_opt(
LServer, mod_sip, record_route,
- fun(IOList) ->
- S = iolist_to_binary(IOList),
- #uri{} = esip:decode_uri(S)
- end, #uri{host = LServer, params = [{<<"lr">>, <<"">>}]}).
+ #uri{host = LServer, params = [{<<"lr">>, <<"">>}]}).
get_configured_routes(LServer) ->
gen_mod:get_module_opt(
LServer, mod_sip, routes,
- fun(L) ->
- lists:map(
- fun(IOList) ->
- S = iolist_to_binary(IOList),
- #uri{} = esip:decode_uri(S)
- end, L)
- end, [#uri{host = LServer, params = [{<<"lr">>, <<"">>}]}]).
+ [#uri{host = LServer, params = [{<<"lr">>, <<"">>}]}]).
mark_transaction_as_complete(TrID, State) ->
NewTrIDs = lists:delete(TrID, State#state.tr_ids),
udp ->
gen_mod:get_module_opt(
LServer, mod_sip, flow_timeout_udp,
- fun(I) when is_integer(I), I>0 -> I end,
?FLOW_TIMEOUT_UDP);
_ ->
gen_mod:get_module_opt(
LServer, mod_sip, flow_timeout_tcp,
- fun(I) when is_integer(I), I>0 -> I end,
?FLOW_TIMEOUT_TCP)
end.
-include("xmpp.hrl").
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_STATS,
?MODULE, process_iq, IQDisc).
%%% Configuration processing
%%%===================================================================
get_max_ack_queue(Host, Opts) ->
- VFun = mod_opt_type(max_ack_queue),
- case gen_mod:get_module_opt(Host, ?MODULE, max_ack_queue, VFun) of
- undefined -> gen_mod:get_opt(max_ack_queue, Opts, VFun, 1000);
- Limit -> Limit
- end.
+ gen_mod:get_module_opt(Host, ?MODULE, max_ack_queue,
+ gen_mod:get_opt(max_ack_queue, Opts, 1000)).
get_resume_timeout(Host, Opts) ->
- VFun = mod_opt_type(resume_timeout),
- case gen_mod:get_module_opt(Host, ?MODULE, resume_timeout, VFun) of
- undefined -> gen_mod:get_opt(resume_timeout, Opts, VFun, 300);
- Timeout -> Timeout
- end.
+ gen_mod:get_module_opt(Host, ?MODULE, resume_timeout,
+ gen_mod:get_opt(resume_timeout, Opts, 300)).
get_max_resume_timeout(Host, Opts, ResumeTimeout) ->
- VFun = mod_opt_type(max_resume_timeout),
- case gen_mod:get_module_opt(Host, ?MODULE, max_resume_timeout, VFun) of
- undefined ->
- case gen_mod:get_opt(max_resume_timeout, Opts, VFun) of
- undefined -> ResumeTimeout;
- Max when Max >= ResumeTimeout -> Max;
- _ -> ResumeTimeout
- end;
+ case gen_mod:get_module_opt(Host, ?MODULE, max_resume_timeout,
+ gen_mod:get_opt(max_resume_timeout, Opts)) of
+ undefined -> ResumeTimeout;
Max when Max >= ResumeTimeout -> Max;
_ -> ResumeTimeout
end.
get_ack_timeout(Host, Opts) ->
- VFun = mod_opt_type(ack_timeout),
- T = case gen_mod:get_module_opt(Host, ?MODULE, ack_timeout, VFun) of
- undefined -> gen_mod:get_opt(ack_timeout, Opts, VFun, 60);
- AckTimeout -> AckTimeout
- end,
- case T of
+ case gen_mod:get_module_opt(Host, ?MODULE, ack_timeout,
+ gen_mod:get_opt(ack_timeout, Opts, 60)) of
infinity -> infinity;
- _ -> timer:seconds(T)
+ T -> timer:seconds(T)
end.
get_resend_on_timeout(Host, Opts) ->
- VFun = mod_opt_type(resend_on_timeout),
- case gen_mod:get_module_opt(Host, ?MODULE, resend_on_timeout, VFun) of
- undefined -> gen_mod:get_opt(resend_on_timeout, Opts, VFun, false);
- Resend -> Resend
- end.
+ gen_mod:get_module_opt(Host, ?MODULE, resend_on_timeout,
+ gen_mod:get_opt(resend_on_timeout, Opts, false)).
get_queue_type(Host, Opts) ->
- VFun = mod_opt_type(queue_type),
- case gen_mod:get_module_opt(Host, ?MODULE, queue_type, VFun) of
- undefined ->
- case gen_mod:get_opt(queue_type, Opts, VFun) of
- undefined -> ejabberd_config:default_queue_type(Host);
- Type -> Type
- end;
+ case gen_mod:get_module_opt(Host, ?MODULE, queue_type,
+ gen_mod:get_opt(queue_type, Opts)) of
+ undefined -> ejabberd_config:default_queue_type(Host);
Type -> Type
end.
fun(B) when is_boolean(B) -> B;
(if_offline) -> if_offline
end;
+mod_opt_type(stream_management) ->
+ fun(B) when is_boolean(B) -> B end;
mod_opt_type(queue_type) ->
fun(ram) -> ram; (file) -> file end;
mod_opt_type(_) ->
-include("xmpp.hrl").
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_TIME, ?MODULE, process_local_iq, IQDisc).
?NS_TIME).
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_TIME,
?MODULE, process_local_iq, IQDisc);
Mod:init(Host, Opts),
ejabberd_hooks:add(remove_user, Host, ?MODULE,
remove_user, 50),
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_VCARD, ?MODULE, process_local_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 50),
MyHost = gen_mod:get_opt_host(Host, Opts, <<"vjud.@HOST@">>),
- Search = gen_mod:get_opt(search, Opts,
- fun(B) when is_boolean(B) -> B end,
- false),
+ Search = gen_mod:get_opt(search, Opts, false),
if Search ->
ejabberd_hooks:add(
disco_local_items, MyHost, ?MODULE, disco_items, 100),
Data = [{Var, Vals} || #xdata_field{var = Var, values = Vals} <- XFields],
Mod = gen_mod:db_mod(LServer, ?MODULE),
AllowReturnAll = gen_mod:get_module_opt(LServer, ?MODULE, allow_return_all,
- fun(B) when is_boolean(B) -> B end,
false),
- MaxMatch = gen_mod:get_module_opt(LServer, ?MODULE, matches,
- fun(infinity) -> infinity;
- (I) when is_integer(I),
- I>0 ->
- I
- end, ?JUD_MATCHES),
+ MaxMatch = gen_mod:get_module_opt(LServer, ?MODULE, matches, ?JUD_MATCHES),
Mod:search(LServer, Data, AllowReturnAll, MaxMatch).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
parse_options(Host, Opts) ->
MyHost = gen_mod:get_opt_host(Host, Opts,
<<"vjud.@HOST@">>),
- Search = gen_mod:get_opt(search, Opts,
- fun(B) when is_boolean(B) -> B end,
- false),
- Matches = gen_mod:get_opt(matches, Opts,
- fun(infinity) -> 0;
- (I) when is_integer(I), I>0 -> I
- end, 30),
+ Search = gen_mod:get_opt(search, Opts, false),
+ Matches = gen_mod:get_opt(matches, Opts, 30),
Eldap_ID = misc:atom_to_binary(gen_mod:get_module_proc(Host, ?PROCNAME)),
Cfg = eldap_utils:get_config(Host, Opts),
- UIDsTemp = gen_mod:get_opt(
- {ldap_uids, Host}, Opts,
- fun(Us) ->
- lists:map(
- fun({U, P}) ->
- {iolist_to_binary(U),
- iolist_to_binary(P)};
- ({U}) ->
- {iolist_to_binary(U)}
- end, Us)
- end, [{<<"uid">>, <<"%u">>}]),
+ UIDsTemp = gen_mod:get_opt({ldap_uids, Host}, Opts,
+ [{<<"uid">>, <<"%u">>}]),
UIDs = eldap_utils:uids_domain_subst(Host, UIDsTemp),
SubFilter = eldap_utils:generate_subfilter(UIDs),
- UserFilter = case gen_mod:get_opt(
- {ldap_filter, Host}, Opts,
- fun eldap_utils:check_filter/1, <<"">>) of
+ UserFilter = case gen_mod:get_opt({ldap_filter, Host}, Opts, <<"">>) of
<<"">> ->
SubFilter;
F ->
{ok, SearchFilter} =
eldap_filter:parse(eldap_filter:do_sub(UserFilter,
[{<<"%u">>, <<"*">>}])),
- VCardMap = gen_mod:get_opt(ldap_vcard_map, Opts,
- 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, default_vcard_map()),
+ VCardMap = gen_mod:get_opt(ldap_vcard_map, Opts, default_vcard_map()),
SearchFields = gen_mod:get_opt(ldap_search_fields, Opts,
- fun(Ls) ->
- [{iolist_to_binary(S),
- iolist_to_binary(P)}
- || {S, P} <- Ls]
- end, default_search_fields()),
+ default_search_fields()),
SearchReported = gen_mod:get_opt(ldap_search_reported, Opts,
- fun(Ls) ->
- [{iolist_to_binary(S),
- iolist_to_binary(P)}
- || {S, P} <- Ls]
- end, default_search_reported()),
+ default_search_reported()),
UIDAttrs = [UAttr || {UAttr, _} <- UIDs],
VCardMapAttrs = lists:usort(lists:append([A
|| {_, _, A} <- VCardMap])
<<"user">> ->
case gen_mod:get_module_opt(LServer, ?MODULE,
search_all_hosts,
- fun(B) when is_boolean(B) ->
- B
- end, true) of
+ true) of
true -> Match#vcard_search{luser = make_val(LVal)};
false ->
Host = find_my_host(LServer),
-include("xmpp.hrl").
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_VERSION, ?MODULE, process_local_iq,
IQDisc).
?NS_VERSION).
reload(Host, NewOpts, OldOpts) ->
- case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts,
- fun gen_iq_handler:check_type/1,
- one_queue) of
+ case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VERSION,
?MODULE, process_local_iq, IQDisc);
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
process_local_iq(#iq{type = get, to = To} = IQ) ->
Host = To#jid.lserver,
- OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os,
- fun(B) when is_boolean(B) -> B end,
- true) of
+ OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os, true) of
true -> get_os();
false -> undefined
end,
%%% API
%%%===================================================================
start(Host, Opts) ->
- IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
- one_queue),
+ IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_EVENT,
?MODULE, process_iq, IQDisc).
MyNick = ?config(nick, Config),
MyNickJID = jid:replace_resource(Room, MyNick),
PeerNickJID = peer_muc_jid(Config),
- Size = gen_mod:get_module_opt(ServerHost, mod_muc, history_size,
- fun(I) when is_integer(I), I>=0 -> I end,
- 20),
+ Size = gen_mod:get_module_opt(ServerHost, mod_muc, history_size, 20),
ok = join_new(Config),
ct:comment("Putting ~p+1 messages in the history", [Size]),
%% Only Size messages will be stored
PeerNick = ?config(peer_nick, Config),
PeerNickJID = jid:replace_resource(Room, PeerNick),
ServerHost = ?config(server_host, Config),
- Size = gen_mod:get_module_opt(ServerHost, mod_muc, history_size,
- fun(I) when is_integer(I), I>=0 -> I end,
- 20),
+ Size = gen_mod:get_module_opt(ServerHost, mod_muc, history_size, 20),
ct:comment("Waiting for 'join' command from the master"),
join = get_event(Config),
{History, _, _} = join(Config),