25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Remove 'iqdisc' option

Since we got rid of all bottle-neck processes and we have
a connection pool for every database, the option is no longer
needed and in fact is detrimental: in practice what you get
is just a bunch of overloaded processes in the IQ handlers pool
no matter how much you increase the `iqdisc` value.

Given that there are close to zero operators understanding
the meaning of the option and, hence, not using it all,
it's not simply deprecated but completely removed.

The commit also deprecates the following functions:
- gen_iq_handler:add_iq_handler/6
- gen_iq_handler:handle/5
- gen_iq_handler:iqdisc/1
This commit is contained in:
Evgeniy Khramtsov 2018-02-11 12:54:15 +03:00
parent 11a58f8dff
commit 66fc1bf3b6
33 changed files with 198 additions and 540 deletions

View File

@ -283,9 +283,8 @@ process(_Handlers, _Request) ->
ejabberd_web:error(not_found).
host_up(Host) ->
IQDisc = gen_iq_handler:iqdisc(Host),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CAPTCHA,
?MODULE, process_iq, IQDisc).
?MODULE, process_iq).
host_down(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CAPTCHA).

View File

@ -34,7 +34,7 @@
-export([route/1, process_iq/1,
get_features/1,
register_iq_handler/5,
register_iq_handler/4,
unregister_iq_handler/2,
bounce_resource_packet/1,
host_up/1, host_down/1]).
@ -78,8 +78,8 @@ process_iq(#iq{to = To, type = T, lang = Lang, sub_els = [El]} = Packet)
XMLNS = xmpp:get_ns(El),
Host = To#jid.lserver,
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts, Packet);
[{_, Module, Function}] ->
gen_iq_handler:handle(Host, Module, Function, Packet);
[] ->
Txt = <<"No module is handling this query">>,
Err = xmpp:err_service_unavailable(Txt, Lang),
@ -112,11 +112,10 @@ route_iq(IQ, Fun) ->
route_iq(IQ, Fun, Timeout) ->
ejabberd_router:route_iq(IQ, Fun, undefined, Timeout).
-spec register_iq_handler(binary(), binary(), module(), function(),
gen_iq_handler:opts()) -> ok.
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
-spec register_iq_handler(binary(), binary(), module(), function()) -> ok.
register_iq_handler(Host, XMLNS, Module, Fun) ->
gen_server:cast(?MODULE,
{register_iq_handler, Host, XMLNS, Module, Fun, Opts}).
{register_iq_handler, Host, XMLNS, Module, Fun}).
-spec unregister_iq_handler(binary(), binary()) -> ok.
unregister_iq_handler(Host, XMLNS) ->
@ -160,19 +159,13 @@ init([]) ->
handle_call(_Request, _From, State) ->
Reply = ok, {reply, Reply, State}.
handle_cast({register_iq_handler, Host, XMLNS, Module,
Function, Opts},
handle_cast({register_iq_handler, Host, XMLNS, Module, Function},
State) ->
ets:insert(?IQTABLE,
{{Host, XMLNS}, Module, Function, Opts}),
{{Host, XMLNS}, Module, Function}),
{noreply, State};
handle_cast({unregister_iq_handler, Host, XMLNS},
State) ->
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
[{_, Module, Function, Opts}] ->
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
_ -> ok
end,
ets:delete(?IQTABLE, {Host, XMLNS}),
{noreply, State};
handle_cast(_Msg, State) -> {noreply, State}.

View File

@ -58,7 +58,7 @@
get_vh_session_list/1,
get_vh_session_number/1,
get_vh_by_backend/1,
register_iq_handler/5,
register_iq_handler/4,
unregister_iq_handler/2,
force_update_presence/1,
connected_users/0,
@ -397,11 +397,11 @@ get_vh_session_number(Server) ->
Mod = get_sm_backend(LServer),
length(online(get_sessions(Mod, LServer))).
-spec register_iq_handler(binary(), binary(), atom(), atom(), list()) -> ok.
-spec register_iq_handler(binary(), binary(), atom(), atom()) -> ok.
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
register_iq_handler(Host, XMLNS, Module, Fun) ->
?GEN_SERVER:cast(?MODULE,
{register_iq_handler, Host, XMLNS, Module, Fun, Opts}).
{register_iq_handler, Host, XMLNS, Module, Fun}).
-spec unregister_iq_handler(binary(), binary()) -> ok.
@ -448,19 +448,13 @@ init([]) ->
handle_call(_Request, _From, State) ->
Reply = ok, {reply, Reply, State}.
handle_cast({register_iq_handler, Host, XMLNS, Module,
Function, Opts},
handle_cast({register_iq_handler, Host, XMLNS, Module, Function},
State) ->
ets:insert(sm_iqtable,
{{Host, XMLNS}, Module, Function, Opts}),
{{Host, XMLNS}, Module, Function}),
{noreply, State};
handle_cast({unregister_iq_handler, Host, XMLNS},
State) ->
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
[{_, Module, Function, Opts}] ->
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
_ -> ok
end,
ets:delete(sm_iqtable, {Host, XMLNS}),
{noreply, State};
handle_cast(_Msg, State) -> {noreply, State}.
@ -862,8 +856,8 @@ process_iq(#iq{to = To, type = T, lang = Lang, sub_els = [El]} = Packet)
XMLNS = xmpp:get_ns(El),
Host = To#jid.lserver,
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts, Packet);
[{_, Module, Function}] ->
gen_iq_handler:handle(Host, Module, Function, Packet);
[] ->
Txt = <<"No module is handling this query">>,
Err = xmpp:err_service_unavailable(Txt, Lang),

View File

@ -92,14 +92,6 @@ init([]) ->
infinity,
supervisor,
[ejabberd_tmp_sup]},
IQSupervisor =
{ejabberd_iq_sup,
{ejabberd_tmp_sup, start_link,
[ejabberd_iq_sup, gen_iq_handler]},
permanent,
infinity,
supervisor,
[ejabberd_tmp_sup]},
BackendSupervisor = {ejabberd_backend_sup,
{ejabberd_backend_sup, start_link, []},
permanent, infinity, supervisor,
@ -169,7 +161,6 @@ init([]) ->
S2SInSupervisor,
S2SOutSupervisor,
ServiceSupervisor,
IQSupervisor,
ACL,
Shaper,
BackendSupervisor,

View File

@ -27,110 +27,38 @@
-author('alexey@process-one.net').
-ifndef(GEN_SERVER).
-define(GEN_SERVER, gen_server).
-endif.
-behaviour(?GEN_SERVER).
-behaviour(ejabberd_config).
%% API
-export([start_link/3, add_iq_handler/6,
remove_iq_handler/3, stop_iq_handler/3, handle/5,
-export([add_iq_handler/5, remove_iq_handler/3, handle/4,
process_iq/4, check_type/1, transform_module_options/1,
opt_type/1, iqdisc/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
opt_type/1]).
%% Deprecated functions
-export([add_iq_handler/6, handle/5, iqdisc/1]).
-deprecated([{add_iq_handler, 6}, {handle, 5}, {iqdisc, 1}]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
-record(state, {host, module, function}).
-type component() :: ejabberd_sm | ejabberd_local.
-type type() :: no_queue | one_queue | pos_integer() | parallel.
-type opts() :: no_queue | {one_queue, pid()} | {queues, [pid()]} | parallel.
-export_type([opts/0, type/0]).
%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
%% Description: Starts the server
%%--------------------------------------------------------------------
start_link(Host, Module, Function) ->
?GEN_SERVER:start_link(?MODULE, [Host, Module, Function],
[]).
-spec add_iq_handler(module(), binary(), binary(), module(), atom(), type()) -> ok.
add_iq_handler(Component, Host, NS, Module, Function,
Type) ->
case Type of
no_queue ->
Component:register_iq_handler(Host, NS, Module,
Function, no_queue);
one_queue ->
{ok, Pid} = supervisor:start_child(ejabberd_iq_sup,
[Host, Module, Function]),
Component:register_iq_handler(Host, NS, Module,
Function, {one_queue, Pid});
N when is_integer(N) ->
Pids = lists:map(fun (_) ->
{ok, Pid} =
supervisor:start_child(ejabberd_iq_sup,
[Host, Module,
Function]),
Pid
end,
lists:seq(1, N)),
Component:register_iq_handler(Host, NS, Module,
Function, {queues, Pids});
parallel ->
Component:register_iq_handler(Host, NS, Module,
Function, parallel)
end.
-spec add_iq_handler(module(), binary(), binary(), module(), atom()) -> ok.
add_iq_handler(Component, Host, NS, Module, Function) ->
Component:register_iq_handler(Host, NS, Module, Function).
-spec remove_iq_handler(component(), binary(), binary()) -> ok.
remove_iq_handler(Component, Host, NS) ->
Component:unregister_iq_handler(Host, NS).
-spec stop_iq_handler(atom(), atom(), [pid()]) -> any().
stop_iq_handler(_Module, _Function, Opts) ->
case Opts of
{one_queue, Pid} -> ?GEN_SERVER:call(Pid, stop);
{queues, Pids} ->
lists:foreach(fun (Pid) ->
catch ?GEN_SERVER:call(Pid, stop)
end,
Pids);
_ -> ok
end.
-spec handle(binary(), atom(), atom(), opts(), iq()) -> any().
handle(Host, Module, Function, Opts, IQ) ->
case Opts of
no_queue ->
process_iq(Host, Module, Function, IQ);
{one_queue, Pid} ->
Pid ! {process_iq, IQ};
{queues, Pids} ->
Pid = lists:nth(erlang:phash(p1_time_compat:unique_integer(),
length(Pids)), Pids),
Pid ! {process_iq, IQ};
parallel ->
spawn(?MODULE, process_iq, [Host, Module, Function, IQ]);
_ -> todo
end.
-spec handle(binary(), atom(), atom(), iq()) -> any().
handle(Host, Module, Function, IQ) ->
process_iq(Host, Module, Function, IQ).
-spec process_iq(binary(), atom(), atom(), iq()) -> any().
process_iq(_Host, Module, Function, IQ) ->
try
ResIQ = case erlang:function_exported(Module, Function, 1) of
@ -178,15 +106,14 @@ process_iq(Module, Function, From, To, IQ) ->
To, From)
end.
-spec check_type(type()) -> type().
-spec check_type(any()) -> no_queue.
check_type(_Type) ->
?WARNING_MSG("Option 'iqdisc' is deprecated and has no effect anymore", []),
no_queue.
check_type(no_queue) -> no_queue;
check_type(one_queue) -> one_queue;
check_type(N) when is_integer(N), N>0 -> N;
check_type(parallel) -> parallel.
iqdisc(Host) ->
ejabberd_config:get_option({iqdisc, Host}, no_queue).
-spec iqdisc(binary() | global) -> no_queue.
iqdisc(_Host) ->
no_queue.
-spec transform_module_options([{atom(), any()}]) -> [{atom(), any()}].
@ -198,37 +125,18 @@ transform_module_options(Opts) ->
Opt
end, Opts).
-spec opt_type(iqdisc) -> fun((type()) -> type());
-spec opt_type(iqdisc) -> fun((any()) -> no_queue);
(atom()) -> [atom()].
opt_type(iqdisc) -> fun check_type/1;
opt_type(_) -> [iqdisc].
%%====================================================================
%% gen_server callbacks
%% Deprecated API
%%====================================================================
-spec add_iq_handler(module(), binary(), binary(), module(), atom(), any()) -> ok.
add_iq_handler(Component, Host, NS, Module, Function, _Type) ->
add_iq_handler(Component, Host, NS, Module, Function).
init([Host, Module, Function]) ->
{ok,
#state{host = Host, module = Module,
function = Function}}.
handle_call(stop, _From, State) ->
Reply = ok, {stop, normal, Reply, State}.
handle_cast(_Msg, State) -> {noreply, State}.
handle_info({process_iq, IQ},
#state{host = Host, module = Module,
function = Function} =
State) ->
process_iq(Host, Module, Function, IQ),
{noreply, State};
handle_info(_Info, State) -> {noreply, State}.
terminate(_Reason, _State) -> ok.
code_change(_OldVsn, State, _Extra) -> {ok, State}.
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
-spec handle(binary(), atom(), atom(), any(), iq()) -> any().
handle(Host, Module, Function, _Opts, IQ) ->
handle(Host, Module, Function, IQ).

View File

@ -42,13 +42,11 @@
-include("logger.hrl").
-include("xmpp.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_COMMANDS, ?MODULE, process_local_iq,
IQDisc),
?NS_COMMANDS, ?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_COMMANDS, ?MODULE, process_sm_iq, IQDisc),
?NS_COMMANDS, ?MODULE, process_sm_iq),
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE,
get_local_identity, 99),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
@ -88,16 +86,8 @@ stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
?NS_COMMANDS).
reload(Host, NewOpts, OldOpts) ->
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_COMMANDS,
?MODULE, process_local_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_COMMANDS,
?MODULE, process_sm_iq, IQDisc);
true ->
ok
end.
reload(_Host, _NewOpts, _OldOpts) ->
ok.
%-------------------------------------------------------------------------
@ -280,10 +270,8 @@ ping_command(Acc, _From, _To, _Request) -> Acc.
depends(_Host, _Opts) ->
[].
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(report_commands_node) ->
fun (B) when is_boolean(B) -> B end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{report_commands_node, false}].
mod_options(_Host) ->
[{report_commands_node, false}].

View File

@ -29,7 +29,7 @@
-protocol({xep, 191, '1.2'}).
-export([start/2, stop/1, reload/3, process_iq/1, mod_opt_type/1, depends/2,
-export([start/2, stop/1, reload/3, process_iq/1, depends/2,
disco_features/5, mod_options/1]).
-include("ejabberd.hrl").
@ -39,24 +39,17 @@
-include("mod_privacy.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
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).
?NS_BLOCKING, ?MODULE, process_iq).
stop(Host) ->
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, disco_features, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_BLOCKING).
reload(Host, NewOpts, OldOpts) ->
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_BLOCKING,
?MODULE, process_iq, IQDisc);
true ->
ok
end.
reload(_Host, _NewOpts, _OldOpts) ->
ok.
depends(_Host, _Opts) ->
[{mod_privacy, hard}].
@ -267,7 +260,5 @@ err_db_failure(#iq{lang = Lang} = IQ) ->
Txt = <<"Database failure">>,
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang)).
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)}].
mod_options(_Host) ->
[].

View File

@ -62,7 +62,6 @@ is_carbon_copy(_) ->
false.
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE, disco_features, 50),
Mod = gen_mod:ram_db_mod(Host, ?MODULE),
init_cache(Mod, Host, Opts),
@ -72,7 +71,7 @@ start(Host, Opts) ->
%% why priority 89: to define clearly that we must run BEFORE mod_logdb hook (90)
ejabberd_hooks:add(user_send_packet,Host, ?MODULE, user_send_packet, 89),
ejabberd_hooks:add(user_receive_packet,Host, ?MODULE, user_receive_packet, 89),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2, ?MODULE, iq_handler, IQDisc).
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2, ?MODULE, iq_handler).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2),
@ -95,13 +94,6 @@ reload(Host, NewOpts, OldOpts) ->
ets_cache:new(?CARBONCOPY_CACHE, cache_opts(NewOpts));
false ->
ok
end,
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2,
?MODULE, iq_handler, IQDisc);
true ->
ok
end.
-spec disco_features({error, stanza_error()} | {result, [binary()]} | empty,
@ -378,7 +370,6 @@ delete_cache(Mod, User, Server) ->
depends(_Host, _Opts) ->
[].
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(ram_db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(O) when O == use_cache; O == cache_missed ->
fun(B) when is_boolean(B) -> B end;
@ -389,8 +380,7 @@ mod_opt_type(O) when O == cache_size; O == cache_life_time ->
end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
[{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},
{cache_missed, ejabberd_config:cache_missed(Host)},

View File

@ -61,7 +61,6 @@ stop(Host) ->
reload(_Host, _NewOpts, _OldOpts) ->
ok.
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(namespaces) ->
fun(L) ->
lists:map(
@ -72,9 +71,8 @@ mod_opt_type(namespaces) ->
end, L)
end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{namespaces, []}].
mod_options(_Host) ->
[{namespaces, []}].
depends(_, _) ->
[].
@ -295,7 +293,7 @@ process_disco_info(State, Type, Host, NS, Info) ->
sub_els = [#delegation{delegated = [#delegated{ns = NS}]}]},
Delegations = dict:store({NS, Type}, {Host, Info}, State#state.delegations),
gen_iq_handler:add_iq_handler(Type, State#state.server_host, NS,
?MODULE, Type, gen_iq_handler:iqdisc(Host)),
?MODULE, Type),
ejabberd_router:route(Msg),
?INFO_MSG("Namespace '~s' is delegated to external component '~s'",
[NS, Host]),

View File

@ -51,19 +51,16 @@
-type items_acc() :: {error, stanza_error()} | {result, [disco_item()]} | empty.
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_ITEMS, ?MODULE,
process_local_iq_items, IQDisc),
process_local_iq_items),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_INFO, ?MODULE,
process_local_iq_info, IQDisc),
process_local_iq_info),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_DISCO_ITEMS, ?MODULE, process_sm_iq_items,
IQDisc),
?NS_DISCO_ITEMS, ?MODULE, process_sm_iq_items),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_DISCO_INFO, ?MODULE, process_sm_iq_info,
IQDisc),
?NS_DISCO_INFO, ?MODULE, process_sm_iq_info),
catch ets:new(disco_extra_domains,
[named_table, ordered_set, public,
{heir, erlang:group_leader(), none}]),
@ -128,23 +125,6 @@ reload(Host, NewOpts, OldOpts) ->
end, OldDomains -- NewDomains);
true ->
ok
end,
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_ITEMS, ?MODULE,
process_local_iq_items, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_INFO, ?MODULE,
process_local_iq_info, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_DISCO_ITEMS, ?MODULE, process_sm_iq_items,
IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_DISCO_INFO, ?MODULE, process_sm_iq_info,
IQDisc);
true ->
ok
end.
-spec register_extra_domain(binary(), binary()) -> true.
@ -458,7 +438,6 @@ depends(_Host, _Opts) ->
mod_opt_type(extra_domains) ->
fun (Hs) -> [iolist_to_binary(H) || H <- Hs] end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(name) -> fun iolist_to_binary/1;
mod_opt_type(server_info) ->
fun (L) ->
@ -471,8 +450,7 @@ mod_opt_type(server_info) ->
L)
end.
mod_options(Host) ->
mod_options(_Host) ->
[{extra_domains, []},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{server_info, []},
{name, ?T("ejabberd")}].

View File

@ -101,10 +101,9 @@ init([Host, Opts]) ->
catch ets:new(irc_connection,
[named_table, public,
{keypos, #irc_connection.jid_server_host}]),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
lists:foreach(
fun(MyHost) ->
register_hooks(MyHost, IQDisc),
register_hooks(MyHost),
ejabberd_router:register_route(MyHost, Host)
end, MyHosts),
{ok,
@ -132,8 +131,6 @@ handle_call(stop, _From, State) ->
handle_cast({reload, ServerHost, NewOpts, OldOpts}, State) ->
NewHosts = gen_mod:get_opt_hosts(ServerHost, NewOpts),
OldHosts = gen_mod:get_opt_hosts(ServerHost, OldOpts),
NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts),
OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts),
NewMod = gen_mod:db_mod(ServerHost, NewOpts, ?MODULE),
OldMod = gen_mod:db_mod(ServerHost, OldOpts, ?MODULE),
Access = gen_mod:get_opt(access, NewOpts),
@ -142,18 +139,10 @@ handle_cast({reload, ServerHost, NewOpts, OldOpts}, State) ->
true ->
ok
end,
if (NewIQDisc /= OldIQDisc) ->
lists:foreach(
fun(NewHost) ->
register_hooks(NewHost, NewIQDisc)
end, NewHosts -- (NewHosts -- OldHosts));
true ->
ok
end,
lists:foreach(
fun(NewHost) ->
ejabberd_router:register_route(NewHost, ServerHost),
register_hooks(NewHost, NewIQDisc)
register_hooks(NewHost)
end, NewHosts -- OldHosts),
lists:foreach(
fun(OldHost) ->
@ -207,17 +196,17 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
register_hooks(Host, IQDisc) ->
register_hooks(Host) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
?MODULE, process_disco_info, IQDisc),
?MODULE, process_disco_info),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
?MODULE, process_disco_items, IQDisc),
?MODULE, process_disco_items),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_REGISTER,
?MODULE, process_register, IQDisc),
?MODULE, process_register),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
?MODULE, process_vcard, IQDisc),
?MODULE, process_vcard),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_COMMANDS,
?MODULE, process_command, IQDisc).
?MODULE, process_command).
unregister_hooks(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO),
@ -989,13 +978,11 @@ mod_opt_type(hosts) ->
mod_opt_type(realname) ->
fun iolist_to_binary/1;
mod_opt_type(webirc_password) ->
fun iolist_to_binary/1;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
fun iolist_to_binary/1.
mod_options(Host) ->
[{access, all},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{default_encoding, <<"iso8859-15">>},
{host, <<"irc.@HOST@">>},
{hosts, []},

View File

@ -59,14 +59,13 @@
-optional_callbacks([use_cache/1, cache_nodes/1]).
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Mod, Host, Opts),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_LAST, ?MODULE, process_local_iq, IQDisc),
?NS_LAST, ?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_LAST, ?MODULE, process_sm_iq, IQDisc),
?NS_LAST, ?MODULE, process_sm_iq),
ejabberd_hooks:add(privacy_check_packet, Host, ?MODULE,
privacy_check_packet, 30),
ejabberd_hooks:add(register_user, Host, ?MODULE,
@ -98,16 +97,7 @@ reload(Host, NewOpts, OldOpts) ->
true ->
ok
end,
init_cache(NewMod, Host, NewOpts),
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_LAST,
?MODULE, process_local_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_LAST,
?MODULE, process_sm_iq, IQDisc);
true ->
ok
end.
init_cache(NewMod, Host, NewOpts).
%%%
%%% Uptime of ejabberd node
@ -331,7 +321,6 @@ depends(_Host, _Opts) ->
[].
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(O) when O == cache_life_time; O == cache_size ->
fun (I) when is_integer(I), I > 0 -> I;
(infinity) -> infinity
@ -340,8 +329,7 @@ mod_opt_type(O) when O == use_cache; O == cache_missed ->
fun (B) when is_boolean(B) -> B end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},
{cache_missed, ejabberd_config:cache_missed(Host)},

View File

@ -75,11 +75,10 @@
%%% API
%%%===================================================================
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Host, Opts),
register_iq_handlers(Host, IQDisc),
register_iq_handlers(Host),
ejabberd_hooks:add(sm_receive_packet, Host, ?MODULE,
sm_receive_packet, 50),
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE,
@ -187,12 +186,6 @@ reload(Host, NewOpts, OldOpts) ->
ok
end,
ets_cache:setopts(archive_prefs_cache, cache_opts(NewOpts)),
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
register_iq_handlers(Host, IQDisc);
true ->
ok
end,
case gen_mod:is_equal_opt(assume_mam_usage, NewOpts, OldOpts) of
{false, true, _} ->
ejabberd_hooks:add(message_is_archived, Host, ?MODULE,
@ -207,24 +200,24 @@ reload(Host, NewOpts, OldOpts) ->
depends(_Host, _Opts) ->
[].
-spec register_iq_handlers(binary(), gen_iq_handler:type()) -> ok.
register_iq_handlers(Host, IQDisc) ->
-spec register_iq_handlers(binary()) -> ok.
register_iq_handlers(Host) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_TMP,
?MODULE, process_iq_v0_2, IQDisc),
?MODULE, process_iq_v0_2),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_TMP,
?MODULE, process_iq_v0_2, IQDisc),
?MODULE, process_iq_v0_2),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_0,
?MODULE, process_iq_v0_3, IQDisc),
?MODULE, process_iq_v0_3),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_0, ?MODULE,
process_iq_v0_3, IQDisc),
process_iq_v0_3),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_1,
?MODULE, process_iq_v0_3, IQDisc),
?MODULE, process_iq_v0_3),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_1,
?MODULE, process_iq_v0_3, IQDisc),
?MODULE, process_iq_v0_3),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_2,
?MODULE, process_iq_v0_3, IQDisc),
?MODULE, process_iq_v0_3),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_2,
?MODULE, process_iq_v0_3, IQDisc).
?MODULE, process_iq_v0_3).
-spec unregister_iq_handlers(binary()) -> ok.
unregister_iq_handlers(Host) ->
@ -1076,7 +1069,6 @@ mod_opt_type(default) ->
(never) -> never;
(roster) -> roster
end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(request_activates_archiving) ->
fun (B) when is_boolean(B) -> B end.
@ -1084,7 +1076,6 @@ mod_options(Host) ->
[{assume_mam_usage, false},
{default, never},
{request_activates_archiving, false},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},

View File

@ -125,7 +125,6 @@ process_iq(#iq{lang = Lang} = IQ) ->
init([ServerHost, Opts]) ->
process_flag(trap_exit, true),
Hosts = gen_mod:get_opt_hosts(ServerHost, Opts),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
lists:foreach(
fun(Host) ->
ConfigTab = gen_mod:get_module_proc(Host, config),
@ -140,20 +139,20 @@ init([ServerHost, Opts]) ->
ejabberd_hooks:add(disco_info, Host, ?MODULE, disco_info, 100),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_ITEMS, mod_disco,
process_local_iq_items, IQDisc),
process_local_iq_items),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_DISCO_INFO, mod_disco,
process_local_iq_info, IQDisc),
process_local_iq_info),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_DISCO_ITEMS, mod_disco,
process_local_iq_items, IQDisc),
process_local_iq_items),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_DISCO_INFO, mod_disco,
process_local_iq_info, IQDisc),
process_local_iq_info),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_PUBSUB, mod_pubsub, iq_sm, IQDisc),
?NS_PUBSUB, mod_pubsub, iq_sm),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_MIX_0, ?MODULE, process_iq, IQDisc),
?NS_MIX_0, ?MODULE, process_iq),
ejabberd_router:register_route(Host, ServerHost)
end, Hosts),
{ok, #state{server_host = ServerHost, hosts = Hosts}}.
@ -316,12 +315,10 @@ is_not_subscribed({error, StanzaError}) ->
depends(_Host, _Opts) ->
[{mod_pubsub, hard}].
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(host) -> fun iolist_to_binary/1;
mod_opt_type(hosts) ->
fun (L) -> lists:map(fun iolist_to_binary/1, L) end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{host, <<"mix.@HOST@">>},
mod_options(_Host) ->
[{host, <<"mix.@HOST@">>},
{hosts, []}].

View File

@ -233,7 +233,6 @@ get_online_rooms_by_user(ServerHost, LUser, LServer) ->
init([Host, Opts]) ->
process_flag(trap_exit, true),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
#state{access = Access, hosts = MyHosts,
history_size = HistorySize, queue_type = QueueType,
room_shaper = RoomShaper} = State = init_state(Host, Opts),
@ -243,7 +242,7 @@ init([Host, Opts]) ->
RMod:init(Host, [{hosts, MyHosts}|Opts]),
lists:foreach(
fun(MyHost) ->
register_iq_handlers(MyHost, IQDisc),
register_iq_handlers(MyHost),
ejabberd_router:register_route(MyHost, Host),
load_permanent_rooms(MyHost, Host, Access, HistorySize,
RoomShaper, QueueType)
@ -273,8 +272,6 @@ handle_call({create, Room, Host, From, Nick, Opts}, _From,
{reply, ok, State}.
handle_cast({reload, ServerHost, NewOpts, OldOpts}, #state{hosts = OldHosts}) ->
NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts),
OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts),
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),
@ -290,18 +287,10 @@ handle_cast({reload, ServerHost, NewOpts, OldOpts}, #state{hosts = OldHosts}) ->
true ->
ok
end,
if (NewIQDisc /= OldIQDisc) ->
lists:foreach(
fun(NewHost) ->
register_iq_handlers(NewHost, NewIQDisc)
end, NewHosts -- (NewHosts -- OldHosts));
true ->
ok
end,
lists:foreach(
fun(NewHost) ->
ejabberd_router:register_route(NewHost, ServerHost),
register_iq_handlers(NewHost, NewIQDisc)
register_iq_handlers(NewHost)
end, NewHosts -- OldHosts),
lists:foreach(
fun(OldHost) ->
@ -372,19 +361,19 @@ init_state(Host, Opts) ->
max_rooms_discoitems = MaxRoomsDiscoItems,
room_shaper = RoomShaper}.
register_iq_handlers(Host, IQDisc) ->
register_iq_handlers(Host) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_REGISTER,
?MODULE, process_register, IQDisc),
?MODULE, process_register),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
?MODULE, process_vcard, IQDisc),
?MODULE, process_vcard),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MUCSUB,
?MODULE, process_mucsub, IQDisc),
?MODULE, process_mucsub),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MUC_UNIQUE,
?MODULE, process_muc_unique, IQDisc),
?MODULE, process_muc_unique),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
?MODULE, process_disco_info, IQDisc),
?MODULE, process_disco_info),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
?MODULE, process_disco_items, IQDisc).
?MODULE, process_disco_items).
unregister_iq_handlers(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_REGISTER),
@ -972,8 +961,7 @@ mod_opt_type({default_room_options, presence_broadcast}) ->
(participant) -> participant;
(visitor) -> visitor
end, L)
end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
end.
mod_options(Host) ->
[{access, all},
@ -982,7 +970,6 @@ mod_options(Host) ->
{access_persistent, all},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{history_size, 20},
{host, <<"conference.@HOST@">>},
{hosts, []},

View File

@ -108,7 +108,6 @@ depends(_Host, _Opts) ->
start(Host, Opts) ->
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
ejabberd_hooks:add(offline_message_hook, Host, ?MODULE,
store_packet, 50),
ejabberd_hooks:add(c2s_self_presence, Host, ?MODULE, c2s_self_presence, 50),
@ -132,7 +131,7 @@ start(Host, Opts) ->
ejabberd_hooks:add(webadmin_user_parse_query, Host,
?MODULE, webadmin_user_parse_query, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_FLEX_OFFLINE,
?MODULE, handle_offline_query, IQDisc).
?MODULE, handle_offline_query).
stop(Host) ->
ejabberd_hooks:delete(offline_message_hook, Host,
@ -162,13 +161,6 @@ reload(Host, NewOpts, OldOpts) ->
NewMod:init(Host, NewOpts);
true ->
ok
end,
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_FLEX_OFFLINE,
?MODULE, handle_offline_query, IQDisc);
true ->
ok
end.
-spec store_offline_msg(#offline_msg{}) -> ok | {error, full | any()}.
@ -849,11 +841,9 @@ mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(store_empty_body) ->
fun (V) when is_boolean(V) -> V;
(unless_chat_state) -> unless_chat_state
end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
end.
mod_options(Host) ->
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{access_max_user_messages, max_user_offline_messages},
{store_empty_body, unless_chat_state}].

View File

@ -91,8 +91,7 @@ reload(Host, NewOpts, OldOpts) ->
init([Host, Opts]) ->
process_flag(trap_exit, true),
State = init_state(Host, Opts),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
register_iq_handlers(Host, IQDisc),
register_iq_handlers(Host),
case State#state.send_pings of
true -> register_hooks(Host);
false -> ok
@ -108,12 +107,8 @@ handle_call(stop, _From, State) ->
handle_call(_Req, _From, State) ->
{reply, {error, badarg}, State}.
handle_cast({reload, Host, NewOpts, OldOpts},
handle_cast({reload, Host, NewOpts, _OldOpts},
#state{timers = Timers} = OldState) ->
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} -> register_iq_handlers(Host, IQDisc);
true -> ok
end,
NewState = init_state(Host, NewOpts),
case {NewState#state.send_pings, OldState#state.send_pings} of
{true, false} -> register_hooks(Host);
@ -219,11 +214,11 @@ unregister_hooks(Host) ->
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
user_send, 100).
register_iq_handlers(Host, IQDisc) ->
register_iq_handlers(Host) ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PING,
?MODULE, iq_ping, IQDisc),
?MODULE, iq_ping),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_PING,
?MODULE, iq_ping, IQDisc).
?MODULE, iq_ping).
unregister_iq_handlers(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_PING),
@ -263,7 +258,6 @@ cancel_timer(TRef) ->
depends(_Host, _Opts) ->
[].
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(ping_interval) ->
fun (I) when is_integer(I), I > 0 -> I end;
mod_opt_type(ping_ack_timeout) ->
@ -277,9 +271,8 @@ mod_opt_type(timeout_action) ->
(kill) -> kill
end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{ping_interval, 60},
mod_options(_Host) ->
[{ping_interval, 60},
{ping_ack_timeout, undefined},
{send_pings, false},
{timeout_action, none}].

View File

@ -70,7 +70,6 @@
-optional_callbacks([use_cache/1, cache_nodes/1]).
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Mod, Host, Opts),
@ -87,7 +86,7 @@ start(Host, Opts) ->
ejabberd_hooks:add(remove_user, Host, ?MODULE,
remove_user, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_PRIVACY, ?MODULE, process_iq, IQDisc).
?NS_PRIVACY, ?MODULE, process_iq).
stop(Host) ->
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE,
@ -113,14 +112,7 @@ reload(Host, NewOpts, OldOpts) ->
true ->
ok
end,
init_cache(NewMod, Host, NewOpts),
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY,
?MODULE, process_iq, IQDisc);
true ->
ok
end.
init_cache(NewMod, Host, NewOpts).
-spec disco_features({error, stanza_error()} | {result, [binary()]} | empty,
jid(), jid(), binary(), binary()) ->
@ -837,7 +829,6 @@ depends(_Host, _Opts) ->
[].
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(O) when O == cache_life_time; O == cache_size ->
fun (I) when is_integer(I), I > 0 -> I;
(infinity) -> infinity
@ -846,8 +837,7 @@ mod_opt_type(O) when O == use_cache; O == cache_missed ->
fun (B) when is_boolean(B) -> B end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},
{cache_missed, ejabberd_config:cache_missed(Host)},

View File

@ -55,14 +55,13 @@
-optional_callbacks([use_cache/1, cache_nodes/1]).
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Mod, Host, Opts),
ejabberd_hooks:add(remove_user, Host, ?MODULE,
remove_user, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_PRIVATE, ?MODULE, process_sm_iq, IQDisc).
?NS_PRIVATE, ?MODULE, process_sm_iq).
stop(Host) ->
ejabberd_hooks:delete(remove_user, Host, ?MODULE,
@ -78,14 +77,7 @@ reload(Host, NewOpts, OldOpts) ->
true ->
ok
end,
init_cache(NewMod, Host, NewOpts),
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PRIVATE,
?MODULE, process_sm_iq, IQDisc);
true ->
ok
end.
init_cache(NewMod, Host, NewOpts).
-spec process_sm_iq(iq()) -> iq().
process_sm_iq(#iq{type = Type, lang = Lang,
@ -258,7 +250,6 @@ depends(_Host, _Opts) ->
[].
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(O) when O == cache_life_time; O == cache_size ->
fun (I) when is_integer(I), I > 0 -> I;
(infinity) -> infinity
@ -267,8 +258,7 @@ mod_opt_type(O) when O == use_cache; O == cache_missed ->
fun (B) when is_boolean(B) -> B end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},
{cache_missed, ejabberd_config:cache_missed(Host)},

View File

@ -137,14 +137,11 @@ mod_opt_type(max_connections) ->
end;
mod_opt_type(ram_db_type) ->
fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(iqdisc) ->
fun gen_iq_handler:check_type/1;
mod_opt_type(Opt) ->
mod_proxy65_stream:listen_opt_type(Opt).
mod_options(Host) ->
[{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{access, all},
{host, <<"proxy.@HOST@">>},
{hosts, []},

View File

@ -61,18 +61,17 @@ reload(Host, NewOpts, OldOpts) ->
init([Host, Opts]) ->
process_flag(trap_exit, true),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
MyHosts = gen_mod:get_opt_hosts(Host, Opts),
lists:foreach(
fun(MyHost) ->
gen_iq_handler:add_iq_handler(ejabberd_local, MyHost, ?NS_DISCO_INFO,
?MODULE, process_disco_info, IQDisc),
?MODULE, process_disco_info),
gen_iq_handler:add_iq_handler(ejabberd_local, MyHost, ?NS_DISCO_ITEMS,
?MODULE, process_disco_items, IQDisc),
?MODULE, process_disco_items),
gen_iq_handler:add_iq_handler(ejabberd_local, MyHost, ?NS_VCARD,
?MODULE, process_vcard, IQDisc),
?MODULE, process_vcard),
gen_iq_handler:add_iq_handler(ejabberd_local, MyHost, ?NS_BYTESTREAMS,
?MODULE, process_bytestreams, IQDisc),
?MODULE, process_bytestreams),
ejabberd_router:register_route(MyHost, Host)
end, MyHosts),
{ok, #state{myhosts = MyHosts}}.
@ -95,20 +94,10 @@ handle_call(_Request, _From, State) ->
handle_cast({reload, ServerHost, NewOpts, OldOpts}, State) ->
NewHosts = gen_mod:get_opt_hosts(ServerHost, NewOpts),
OldHosts = gen_mod:get_opt_hosts(ServerHost, OldOpts),
NewIQDisc = gen_mod:get_opt(iqdisc, NewOpts),
OldIQDisc = gen_mod:get_opt(iqdisc, OldOpts),
if (NewIQDisc /= OldIQDisc) ->
lists:foreach(
fun(NewHost) ->
register_handlers(NewHost, NewIQDisc)
end, NewHosts -- (NewHosts -- OldHosts));
true ->
ok
end,
lists:foreach(
fun(NewHost) ->
ejabberd_router:register_route(NewHost, ServerHost),
register_handlers(NewHost, NewIQDisc)
register_handlers(NewHost)
end, NewHosts -- OldHosts),
lists:foreach(
fun(OldHost) ->
@ -282,15 +271,15 @@ get_my_ip() ->
max_connections(ServerHost) ->
gen_mod:get_module_opt(ServerHost, mod_proxy65, max_connections).
register_handlers(Host, IQDisc) ->
register_handlers(Host) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
?MODULE, process_disco_info, IQDisc),
?MODULE, process_disco_info),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
?MODULE, process_disco_items, IQDisc),
?MODULE, process_disco_items),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
?MODULE, process_vcard, IQDisc),
?MODULE, process_vcard),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_BYTESTREAMS,
?MODULE, process_bytestreams, IQDisc).
?MODULE, process_bytestreams).
unregister_handlers(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO),

View File

@ -244,7 +244,6 @@ init([ServerHost, Opts]) ->
Hosts = gen_mod:get_opt_hosts(ServerHost, Opts),
Access = gen_mod:get_opt(access_createnode, Opts),
PepOffline = gen_mod:get_opt(ignore_pep_from_offline, Opts),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
LastItemCache = gen_mod:get_opt(last_item_cache, Opts),
MaxItemsNode = gen_mod:get_opt(max_items_node, Opts),
MaxSubsNode = gen_mod:get_opt(max_subscriptions_node, Opts),
@ -284,17 +283,17 @@ init([ServerHost, Opts]) ->
end
end, [Host, ServerHost]),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
?MODULE, process_disco_info, IQDisc),
?MODULE, process_disco_info),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
?MODULE, process_disco_items, IQDisc),
?MODULE, process_disco_items),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_PUBSUB,
?MODULE, process_pubsub, IQDisc),
?MODULE, process_pubsub),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_PUBSUB_OWNER,
?MODULE, process_pubsub_owner, IQDisc),
?MODULE, process_pubsub_owner),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
?MODULE, process_vcard, IQDisc),
?MODULE, process_vcard),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_COMMANDS,
?MODULE, process_commands, IQDisc),
?MODULE, process_commands),
Plugins
end, Hosts),
ejabberd_hooks:add(c2s_self_presence, ServerHost,
@ -330,9 +329,9 @@ init([ServerHost, Opts]) ->
ejabberd_hooks:add(disco_sm_items, ServerHost,
?MODULE, disco_sm_items, 75),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost,
?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
?NS_PUBSUB, ?MODULE, iq_sm),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost,
?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc);
?NS_PUBSUB_OWNER, ?MODULE, iq_sm);
false ->
ok
end,
@ -3856,7 +3855,6 @@ mod_opt_type(hosts) ->
fun (L) -> lists:map(fun iolist_to_binary/1, L) end;
mod_opt_type(ignore_pep_from_offline) ->
fun (A) when is_boolean(A) -> A end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(last_item_cache) ->
fun (A) when is_boolean(A) -> A end;
mod_opt_type(max_items_node) ->
@ -3881,7 +3879,6 @@ mod_options(Host) ->
{hosts, []},
{name, ?T("Publish-Subscribe")},
{ignore_pep_from_offline, true},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{last_item_cache, false},
{max_items_node, ?MAXITEMS},
{nodetree, ?STDTREE},

View File

@ -92,11 +92,10 @@
%%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> ok.
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Mod, Host, Opts),
register_iq_handlers(Host, IQDisc),
register_iq_handlers(Host),
register_hooks(Host),
ejabberd_commands:register_commands(get_commands_spec()).
@ -119,12 +118,6 @@ reload(Host, NewOpts, OldOpts) ->
NewMod:init(Host, NewOpts);
true ->
ok
end,
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
register_iq_handlers(Host, IQDisc);
true ->
ok
end.
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
@ -139,13 +132,10 @@ mod_opt_type(O) when O == cache_life_time; O == cache_size ->
(infinity) -> infinity
end;
mod_opt_type(O) when O == use_cache; O == cache_missed ->
fun (B) when is_boolean(B) -> B end;
mod_opt_type(iqdisc) ->
fun gen_iq_handler:check_type/1.
fun (B) when is_boolean(B) -> B end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},
{cache_missed, ejabberd_config:cache_missed(Host)},
@ -249,10 +239,10 @@ disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
%%--------------------------------------------------------------------
%% IQ handlers.
%%--------------------------------------------------------------------
-spec register_iq_handlers(binary(), gen_iq_handler:type()) -> ok.
register_iq_handlers(Host, IQDisc) ->
-spec register_iq_handlers(binary()) -> ok.
register_iq_handlers(Host) ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PUSH_0,
?MODULE, process_iq, IQDisc).
?MODULE, process_iq).
-spec unregister_iq_handlers(binary()) -> ok.
unregister_iq_handlers(Host) ->

View File

@ -43,12 +43,11 @@
-include("logger.hrl").
-include("xmpp.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_REGISTER, ?MODULE, process_iq, IQDisc),
?NS_REGISTER, ?MODULE, process_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_REGISTER, ?MODULE, process_iq, IQDisc),
?NS_REGISTER, ?MODULE, process_iq),
ejabberd_hooks:add(c2s_pre_auth_features, Host, ?MODULE,
stream_feature_register, 50),
ejabberd_hooks:add(c2s_unauthenticated_packet, Host,
@ -68,16 +67,8 @@ stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
?NS_REGISTER).
reload(Host, NewOpts, OldOpts) ->
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
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,
?MODULE, process_iq, IQDisc);
true ->
ok
end.
reload(_Host, _NewOpts, _OldOpts) ->
ok.
depends(_Host, _Opts) ->
[].
@ -608,7 +599,6 @@ mod_opt_type(access_remove) -> fun acl:access_rules_validator/1;
mod_opt_type(captcha_protected) ->
fun (B) when is_boolean(B) -> B end;
mod_opt_type(ip_access) -> fun acl:access_rules_validator/1;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(password_strength) ->
fun (N) when is_number(N), N >= 0 -> N end;
mod_opt_type(registration_watchers) ->
@ -627,13 +617,12 @@ mod_opt_type({welcome_message, body}) ->
mod_opt_type(redirect_url) ->
fun iolist_to_binary/1.
mod_options(Host) ->
mod_options(_Host) ->
[{access, all},
{access_from, none},
{access_remove, all},
{captcha_protected, false},
{ip_access, all},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{password_strength, 0},
{registration_watchers, []},
{redirect_url, <<"">>},

View File

@ -88,7 +88,6 @@
-optional_callbacks([use_cache/2, cache_nodes/1]).
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Mod, Host, Opts),
@ -111,7 +110,7 @@ start(Host, Opts) ->
ejabberd_hooks:add(webadmin_user, Host, ?MODULE,
webadmin_user, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_ROSTER, ?MODULE, process_iq, IQDisc).
?NS_ROSTER, ?MODULE, process_iq).
stop(Host) ->
ejabberd_hooks:delete(roster_get, Host, ?MODULE,
@ -142,13 +141,6 @@ reload(Host, NewOpts, OldOpts) ->
NewMod:init(Host, NewOpts);
true ->
ok
end,
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ROSTER,
?MODULE, process_iq, IQDisc);
true ->
ok
end.
depends(_Host, _Opts) ->
@ -1205,7 +1197,6 @@ import(LServer, {sql, _}, DBType, <<"roster_version">>, [LUser, Ver]) ->
mod_opt_type(access) ->
fun acl:access_rules_validator/1;
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(store_current_id) ->
fun (B) when is_boolean(B) -> B end;
mod_opt_type(versioning) ->
@ -1221,7 +1212,6 @@ mod_options(Host) ->
[{access, all},
{store_current_id, false},
{versioning, false},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},

View File

@ -32,22 +32,21 @@
-behaviour(gen_mod).
-export([start/2, stop/1, reload/3, process_local_iq/1,
process_sm_iq/1, mod_opt_type/1, mod_options/1, depends/2]).
process_sm_iq/1, mod_options/1, depends/2]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_0,
?MODULE, process_local_iq, IQDisc),
?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_SIC_0,
?MODULE, process_sm_iq, IQDisc),
?MODULE, process_sm_iq),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_1,
?MODULE, process_local_iq, IQDisc),
?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_SIC_1,
?MODULE, process_sm_iq, IQDisc).
?MODULE, process_sm_iq).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_SIC_0),
@ -55,20 +54,8 @@ stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_SIC_1),
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) of
{false, IQDisc, _} ->
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,
?MODULE, process_sm_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_SIC_1,
?MODULE, process_local_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_SIC_1,
?MODULE, process_sm_iq, IQDisc);
true ->
ok
end.
reload(_Host, _NewOpts, _OldOpts) ->
ok.
depends(_Host, _Opts) ->
[].
@ -107,7 +94,5 @@ get_ip({User, Server, Resource},
xmpp:make_error(IQ, xmpp:err_item_not_found(Txt, Lang))
end.
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)}].
mod_options(_Host) ->
[].

View File

@ -31,17 +31,16 @@
-behaviour(gen_mod).
-export([start/2, stop/1, reload/3, process_iq/1, mod_opt_type/1,
-export([start/2, stop/1, reload/3, process_iq/1,
mod_options/1, depends/2]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_STATS,
?MODULE, process_iq, IQDisc).
?MODULE, process_iq).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_STATS).
@ -234,7 +233,5 @@ search_running_node(SNode, [Node | Nodes]) ->
_ -> search_running_node(SNode, Nodes)
end.
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)}].
mod_options(_Host) ->
[].

View File

@ -33,30 +33,23 @@
-behaviour(gen_mod).
-export([start/2, stop/1, reload/3, process_local_iq/1,
mod_opt_type/1, mod_options/1, depends/2]).
mod_options/1, depends/2]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_TIME, ?MODULE, process_local_iq, IQDisc).
?NS_TIME, ?MODULE, process_local_iq).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
?NS_TIME).
reload(Host, NewOpts, OldOpts) ->
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_TIME,
?MODULE, process_local_iq, IQDisc);
true ->
ok
end.
reload(_Host, _NewOpts, _OldOpts) ->
ok.
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
@ -74,7 +67,5 @@ process_local_iq(#iq{type = get} = IQ) ->
depends(_Host, _Opts) ->
[].
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)}].
mod_options(_Host) ->
[].

View File

@ -88,11 +88,10 @@ init([Host, Opts]) ->
init_cache(Mod, Host, Opts),
ejabberd_hooks:add(remove_user, Host, ?MODULE,
remove_user, 50),
IQDisc = gen_mod:get_opt(iqdisc, Opts),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_VCARD, ?MODULE, process_local_iq, IQDisc),
?NS_VCARD, ?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_VCARD, ?MODULE, process_sm_iq, IQDisc),
?NS_VCARD, ?MODULE, process_sm_iq),
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 50),
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50),
@ -108,15 +107,15 @@ init([Host, Opts]) ->
ejabberd_hooks:add(
disco_local_identity, MyHost, ?MODULE, disco_identity, 100),
gen_iq_handler:add_iq_handler(
ejabberd_local, MyHost, ?NS_SEARCH, ?MODULE, process_search, IQDisc),
ejabberd_local, MyHost, ?NS_SEARCH, ?MODULE, process_search),
gen_iq_handler:add_iq_handler(
ejabberd_local, MyHost, ?NS_VCARD, ?MODULE, process_vcard, IQDisc),
ejabberd_local, MyHost, ?NS_VCARD, ?MODULE, process_vcard),
gen_iq_handler:add_iq_handler(
ejabberd_local, MyHost, ?NS_DISCO_ITEMS, mod_disco,
process_local_iq_items, IQDisc),
process_local_iq_items),
gen_iq_handler:add_iq_handler(
ejabberd_local, MyHost, ?NS_DISCO_INFO, mod_disco,
process_local_iq_info, IQDisc),
process_local_iq_info),
case Mod:is_search_supported(Host) of
false ->
?WARNING_MSG("vcard search functionality is "
@ -538,7 +537,6 @@ mod_opt_type(name) -> fun iolist_to_binary/1;
mod_opt_type(host) -> fun iolist_to_binary/1;
mod_opt_type(hosts) ->
fun (L) -> lists:map(fun iolist_to_binary/1, L) end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(matches) ->
fun (infinity) -> infinity;
(I) when is_integer(I), I > 0 -> I
@ -559,7 +557,6 @@ mod_options(Host) ->
{matches, 30},
{search, false},
{name, ?T("vCard User Search")},
{iqdisc, gen_iq_handler:iqdisc(Host)},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_config:use_cache(Host)},
{cache_size, ejabberd_config:cache_size(Host)},

View File

@ -39,24 +39,16 @@
-include("xmpp.hrl").
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_VERSION, ?MODULE, process_local_iq,
IQDisc).
?NS_VERSION, ?MODULE, process_local_iq).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
?NS_VERSION).
reload(Host, NewOpts, OldOpts) ->
case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts) of
{false, IQDisc, _} ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VERSION,
?MODULE, process_local_iq, IQDisc);
true ->
ok
end.
reload(_Host, _NewOpts, _OldOpts) ->
ok.
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
@ -85,10 +77,8 @@ get_os() ->
depends(_Host, _Opts) ->
[].
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(show_os) ->
fun (B) when is_boolean(B) -> B end.
mod_options(Host) ->
[{iqdisc, gen_iq_handler:iqdisc(Host)},
{show_os, true}].
mod_options(_Host) ->
[{show_os, true}].

View File

@ -31,10 +31,9 @@
%%%===================================================================
%%% API
%%%===================================================================
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_EVENT,
?MODULE, process_iq, IQDisc).
?MODULE, process_iq).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?MODULE).
@ -45,6 +44,9 @@ mod_opt_type(_) ->
depends(_, _) ->
[].
mod_options(_) ->
[].
%%%===================================================================
%%% Internal functions
%%%===================================================================

View File

@ -62,7 +62,7 @@ defmodule ModRosterMock do
roster_mock0 = :moka.start(:mod_roster)
:moka.replace(roster_mock0, :gen_iq_handler, :add_iq_handler,
fn (_module, _host, _ns, _m, _f, _iqdisc) ->
fn (_module, _host, _ns, _m, _f) ->
:ok
end)

View File

@ -34,7 +34,8 @@ main([Dir]) ->
{ejabberd_hooks, {add, N}}
when N == 4; N == 5 ->
analyze_run_fun(Form, Acc);
{gen_iq_handler, {add_iq_handler, 6}} ->
{gen_iq_handler, {add_iq_handler, N}}
when N == 5; N == 6 ->
analyze_iq_handler(Form, Acc);
_ ->
Acc
@ -136,7 +137,7 @@ analyze_run_fun(Form, State) ->
end.
analyze_iq_handler(Form, State) ->
[_Component, _Host, _NS, Module, Function, _IQDisc] =
[_Component, _Host, _NS, Module, Function|_] =
erl_syntax:application_arguments(Form),
Mod = module_name(Module, State),
Fun = atom_value(Function, State),