mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-12 21:52:07 +02:00
Support static_modules in mod_caps, ping, privacy, private, roster, stats and time
This commit is contained in:
parent
12d6f3364b
commit
ff8bd0c2ec
|
@ -92,11 +92,13 @@ start_link(Host, Opts) ->
|
|||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
|
||||
|
||||
start(Host, Opts) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(HostB, Opts) ->
|
||||
Proc = gen_mod:get_module_proc(HostB, ?PROCNAME),
|
||||
ChildSpec =
|
||||
{Proc,
|
||||
{?MODULE, start_link, [Host, Opts]},
|
||||
{?MODULE, start_link, [HostB, Opts]},
|
||||
transient,
|
||||
1000,
|
||||
worker,
|
||||
|
@ -284,7 +286,7 @@ c2s_broadcast_recipients(Acc, _, _, _, _) ->
|
|||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
init([Host, Opts]) ->
|
||||
init([HostB, Opts]) ->
|
||||
case catch mnesia:table_info(caps_features, storage_type) of
|
||||
{'EXIT', _} ->
|
||||
ok;
|
||||
|
@ -301,7 +303,6 @@ init([Host, Opts]) ->
|
|||
MaxSize = gen_mod:get_opt(cache_size, Opts, 1000),
|
||||
LifeTime = gen_mod:get_opt(cache_life_time, Opts, timer:hours(24) div 1000),
|
||||
cache_tab:new(caps_features, [{max_size, MaxSize}, {life_time, LifeTime}]),
|
||||
HostB = list_to_binary(Host),
|
||||
ejabberd_hooks:add(c2s_presence_in, HostB,
|
||||
?MODULE, c2s_presence_in, 75),
|
||||
ejabberd_hooks:add(c2s_broadcast_recipients, HostB,
|
||||
|
@ -320,7 +321,7 @@ init([Host, Opts]) ->
|
|||
?MODULE, disco_identity, 75),
|
||||
ejabberd_hooks:add(disco_info, HostB,
|
||||
?MODULE, disco_info, 75),
|
||||
{ok, #state{host = Host}}.
|
||||
{ok, #state{host = HostB}}.
|
||||
|
||||
handle_call(stop, _From, State) ->
|
||||
{stop, normal, ok, State};
|
||||
|
@ -334,7 +335,7 @@ handle_info(_Info, State) ->
|
|||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, State) ->
|
||||
HostB = list_to_binary(State#state.host),
|
||||
HostB = State#state.host,
|
||||
ejabberd_hooks:delete(c2s_presence_in, HostB,
|
||||
?MODULE, c2s_presence_in, 75),
|
||||
ejabberd_hooks:delete(c2s_broadcast_recipients, HostB,
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
%% Hook callbacks
|
||||
-export([iq_ping/3, user_online/3, user_offline/3, user_send/3]).
|
||||
|
||||
-record(state, {host = "",
|
||||
-record(state, {host, % binary() | global
|
||||
send_pings = ?DEFAULT_SEND_PINGS,
|
||||
ping_interval = ?DEFAULT_PING_INTERVAL,
|
||||
timeout_action = none,
|
||||
|
@ -66,16 +66,18 @@ start_link(Host, Opts) ->
|
|||
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
|
||||
|
||||
start_ping(Host, JID) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
Proc = gen_mod:get_module_proc_existing(Host, ?MODULE),
|
||||
gen_server:cast(Proc, {start_ping, JID}).
|
||||
|
||||
stop_ping(Host, JID) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
Proc = gen_mod:get_module_proc_existing(Host, ?MODULE),
|
||||
gen_server:cast(Proc, {stop_ping, JID}).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_mod callbacks
|
||||
%%====================================================================
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(Host, Opts) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
PingSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
|
||||
|
@ -90,8 +92,7 @@ stop(Host) ->
|
|||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
init([Host, Opts]) ->
|
||||
HostB = list_to_binary(Host),
|
||||
init([HostB, Opts]) ->
|
||||
SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS),
|
||||
PingInterval = gen_mod:get_opt(ping_interval, Opts, ?DEFAULT_PING_INTERVAL),
|
||||
TimeoutAction = gen_mod:get_opt(timeout_action, Opts, none),
|
||||
|
@ -112,14 +113,13 @@ init([Host, Opts]) ->
|
|||
_ ->
|
||||
ok
|
||||
end,
|
||||
{ok, #state{host = Host,
|
||||
{ok, #state{host = HostB,
|
||||
send_pings = SendPings,
|
||||
ping_interval = PingInterval,
|
||||
timeout_action = TimeoutAction,
|
||||
timers = ?DICT:new()}}.
|
||||
|
||||
terminate(_Reason, #state{host = Host}) ->
|
||||
HostB = list_to_binary(Host),
|
||||
terminate(_Reason, #state{host = HostB}) ->
|
||||
ejabberd_hooks:delete(sm_remove_connection_hook, HostB,
|
||||
?MODULE, user_offline, 100),
|
||||
ejabberd_hooks:delete(sm_register_connection_hook, HostB,
|
||||
|
@ -143,7 +143,8 @@ handle_cast({stop_ping, JID}, State) ->
|
|||
{noreply, State#state{timers = Timers}};
|
||||
handle_cast({iq_pong, JID, timeout}, State) ->
|
||||
Timers = del_timer(JID, State#state.timers),
|
||||
ejabberd_hooks:run(user_ping_timeout, list_to_binary(State#state.host), [JID]),
|
||||
Host = exmpp_jid:domain(JID),
|
||||
ejabberd_hooks:run(user_ping_timeout, Host, [JID]),
|
||||
case State#state.timeout_action of
|
||||
kill ->
|
||||
case ejabberd_sm:get_session_pid(JID) of
|
||||
|
@ -171,7 +172,7 @@ handle_info({timeout, _TRef, {ping, JID}}, State) ->
|
|||
F = fun(Response) ->
|
||||
gen_server:cast(Pid, {iq_pong, JID, Response})
|
||||
end,
|
||||
From = exmpp_jid:make(State#state.host),
|
||||
From = exmpp_jid:make(exmpp_jid:domain(JID)),
|
||||
ejabberd_local:route_iq(From, JID, IQ, F),
|
||||
Timers = add_timer(JID, State#state.ping_interval, State#state.timers),
|
||||
{noreply, State#state{timers = Timers}};
|
||||
|
|
|
@ -118,24 +118,25 @@
|
|||
-include("ejabberd.hrl").
|
||||
-include("mod_privacy.hrl").
|
||||
|
||||
start(Host, Opts) ->
|
||||
HostB = list_to_binary(Host),
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(HostB, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
Backend = gen_mod:get_opt(backend, Opts, mnesia),
|
||||
gen_storage:create_table(Backend, HostB, privacy_list,
|
||||
[{disc_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{odbc_host, HostB},
|
||||
{type, bag},
|
||||
{attributes, record_info(fields, privacy_list)},
|
||||
{types, [{user_host, {text, text}}]}]),
|
||||
gen_storage:create_table(Backend, HostB, privacy_default_list,
|
||||
[{disc_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{odbc_host, HostB},
|
||||
{attributes, record_info(fields, privacy_default_list)},
|
||||
{types, [{user_host, {text, text}}]}]),
|
||||
gen_storage:create_table(Backend, HostB, privacy_list_data,
|
||||
[{disc_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{odbc_host, HostB},
|
||||
{type, bag},
|
||||
{attributes, record_info(fields, privacy_list_data)},
|
||||
{types, [{user_host, {text, text}},
|
||||
|
@ -149,7 +150,7 @@ start(Host, Opts) ->
|
|||
{match_presence_in, atom},
|
||||
{match_presence_out, atom}
|
||||
]}]),
|
||||
update_tables(Host, Backend),
|
||||
update_tables(HostB, Backend),
|
||||
gen_storage:add_table_index(HostB, privacy_list, name),
|
||||
gen_storage:add_table_index(HostB, privacy_list_data, name),
|
||||
ejabberd_hooks:add(privacy_iq_get, HostB,
|
||||
|
@ -807,10 +808,12 @@ updated_list(_,
|
|||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
update_tables(Host, mnesia) ->
|
||||
HostB = list_to_binary(Host),
|
||||
update_tables(global, Storage) ->
|
||||
[update_tables(HostB, Storage) || HostB <- ejabberd_hosts:get_hosts(ejabberd)];
|
||||
|
||||
update_tables(HostB, mnesia) ->
|
||||
gen_storage_migration:migrate_mnesia(
|
||||
Host, privacy_default_list,
|
||||
HostB, privacy_default_list,
|
||||
[{privacy, [us, default, lists],
|
||||
fun({privacy, {U, S}, Default, Lists}) ->
|
||||
US = {list_to_binary(U), list_to_binary(S)},
|
||||
|
|
|
@ -69,16 +69,17 @@
|
|||
%% TODO: usns instead of user_host_ns requires no migration
|
||||
-record(private_storage, {user_host_ns, xml}).
|
||||
|
||||
start(Host, Opts) ->
|
||||
HostB = list_to_binary(Host),
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(HostB, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
Backend = gen_mod:get_opt(backend, Opts, mnesia),
|
||||
gen_storage:create_table(Backend, HostB, private_storage,
|
||||
[{disc_only_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{odbc_host, HostB},
|
||||
{attributes, record_info(fields, private_storage)},
|
||||
{types, [{user_host_ns, {binary, binary, atom}}, {xml, xmlel}]}]),
|
||||
update_table(Host, Backend),
|
||||
update_table(HostB, Backend),
|
||||
ejabberd_hooks:add(remove_user, HostB,
|
||||
?MODULE, remove_user, 50),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, HostB, ?NS_PRIVATE,
|
||||
|
@ -218,6 +219,9 @@ remove_user(User, Server)
|
|||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
update_table(global, Storage) ->
|
||||
[update_table(HostB, Storage) || HostB <- ejabberd_hosts:get_hosts(ejabberd)];
|
||||
|
||||
update_table(Host, mnesia) ->
|
||||
gen_storage_migration:migrate_mnesia(
|
||||
Host, private_storage,
|
||||
|
|
|
@ -134,26 +134,27 @@
|
|||
%% Opts = list()
|
||||
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
HostB = list_to_binary(Host),
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(HostB, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
|
||||
Backend = gen_mod:get_opt(backend, Opts, mnesia),
|
||||
gen_storage:create_table(Backend, HostB,
|
||||
rosteritem, [{disc_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{odbc_host, HostB},
|
||||
{attributes, record_info(fields, rosteritem)},
|
||||
{types, [{user_host_jid, {text, text, ljid}},
|
||||
{subscription, atom},
|
||||
{ask, atom}]}]),
|
||||
gen_storage:create_table(Backend, HostB,
|
||||
rostergroup, [{disc_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{odbc_host, HostB},
|
||||
{type, bag},
|
||||
{attributes, record_info(fields, rostergroup)},
|
||||
{types, [{user_host_jid, {text, text, ljid}}]}]),
|
||||
mnesia:create_table(roster_version, [{disc_copies, [node()]},
|
||||
{attributes, record_info(fields, roster_version)}]),
|
||||
update_table(Host, Backend),
|
||||
update_table(HostB, Backend),
|
||||
mnesia:add_table_index(roster, us),
|
||||
mnesia:add_table_index(roster_version, us),
|
||||
ejabberd_hooks:add(roster_get, HostB,
|
||||
|
@ -1228,10 +1229,12 @@ get_jid_info(_, User, Server, JID)
|
|||
|
||||
%% Only supports migration from ejabberd 1.1.2 or higher.
|
||||
|
||||
update_table(Host, mnesia) ->
|
||||
HostB = list_to_binary(Host),
|
||||
update_table(global, Storage) ->
|
||||
[update_table(HostB, Storage) || HostB <- ejabberd_hosts:get_hosts(ejabberd)];
|
||||
|
||||
update_table(HostB, mnesia) ->
|
||||
gen_storage_migration:migrate_mnesia(
|
||||
Host, rosteritem,
|
||||
HostB, rosteritem,
|
||||
[{roster, [usj, us, jid, name, subscription, ask, groups, askmessage, xs],
|
||||
fun({roster, USJ, _, _, Name, Subscription, Ask, Groups, AskMessage, _Xs}) ->
|
||||
%% Convert "" to undefined in JIDs and string() to binary().
|
||||
|
|
|
@ -35,9 +35,11 @@
|
|||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
start(Host, Opts) ->
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(HostB, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, list_to_binary(Host), ?NS_STATS_s,
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, HostB, ?NS_STATS_s,
|
||||
?MODULE, process_local_iq, IQDisc).
|
||||
|
||||
stop(Host) ->
|
||||
|
|
|
@ -39,12 +39,14 @@
|
|||
-include("ejabberd.hrl").
|
||||
|
||||
|
||||
start(Host, Opts) ->
|
||||
start(Host, Opts) when is_list(Host) ->
|
||||
start(list_to_binary(Host), Opts);
|
||||
start(HostB, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
%% TODO: Remove the next two lines once XEP-0090 is Obsolete
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, list_to_binary(Host), ?NS_TIME_OLD,
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, HostB, ?NS_TIME_OLD,
|
||||
?MODULE, process_local_iq90, IQDisc),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, list_to_binary(Host), ?NS_TIME,
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, HostB, ?NS_TIME,
|
||||
?MODULE, process_local_iq, IQDisc).
|
||||
|
||||
stop(Host) ->
|
||||
|
|
Loading…
Reference in New Issue
Block a user