mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Remove handle_event/1 callback
This commit is contained in:
parent
64997d9961
commit
65d352d5de
@ -65,7 +65,6 @@
|
|||||||
-callback is_my_route(binary()) -> boolean().
|
-callback is_my_route(binary()) -> boolean().
|
||||||
-callback is_my_host(binary()) -> boolean().
|
-callback is_my_host(binary()) -> boolean().
|
||||||
-callback get_all_routes() -> [binary()].
|
-callback get_all_routes() -> [binary()].
|
||||||
-callback handle_event(term()) -> any().
|
|
||||||
|
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
|
||||||
@ -251,9 +250,8 @@ handle_info({route, From, To, Packet}, State) ->
|
|||||||
_ -> ok
|
_ -> ok
|
||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info(Event, State) ->
|
handle_info(Info, State) ->
|
||||||
Mod = get_backend(),
|
?ERROR_MSG("unexpected info: ~p", [Info]),
|
||||||
Mod:handle_event(Event),
|
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
terminate(_Reason, _State) ->
|
terminate(_Reason, _State) ->
|
||||||
|
@ -8,32 +8,32 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(ejabberd_router_mnesia).
|
-module(ejabberd_router_mnesia).
|
||||||
-behaviour(ejabberd_router).
|
-behaviour(ejabberd_router).
|
||||||
|
-behaviour(gen_server).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([init/0, register_route/4, unregister_route/2, find_routes/1,
|
-export([init/0, register_route/4, unregister_route/2, find_routes/1,
|
||||||
host_of_route/1, is_my_route/1, is_my_host/1, get_all_routes/0,
|
host_of_route/1, is_my_route/1, is_my_host/1, get_all_routes/0]).
|
||||||
handle_event/1]).
|
%% gen_server callbacks
|
||||||
|
-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
|
||||||
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("ejabberd_router.hrl").
|
-include("ejabberd_router.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
-include_lib("stdlib/include/ms_transform.hrl").
|
-include_lib("stdlib/include/ms_transform.hrl").
|
||||||
|
|
||||||
|
-record(state, {}).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
init() ->
|
init() ->
|
||||||
update_tables(),
|
case gen_server:start_link({local, ?MODULE}, ?MODULE, [], []) of
|
||||||
ejabberd_mnesia:create(?MODULE, route,
|
{ok, _Pid} ->
|
||||||
[{ram_copies, [node()]},
|
ok;
|
||||||
{type, bag},
|
Err ->
|
||||||
{attributes, record_info(fields, route)}]),
|
Err
|
||||||
mnesia:add_table_copy(route, node(), ram_copies),
|
end.
|
||||||
mnesia:subscribe({table, route, simple}),
|
|
||||||
lists:foreach(
|
|
||||||
fun (Pid) -> erlang:monitor(process, Pid) end,
|
|
||||||
mnesia:dirty_select(route,
|
|
||||||
[{{route, '_', '$1', '_'}, [], ['$1']}])).
|
|
||||||
|
|
||||||
register_route(Domain, ServerHost, LocalHint, undefined) ->
|
register_route(Domain, ServerHost, LocalHint, undefined) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
@ -135,10 +135,35 @@ get_all_routes() ->
|
|||||||
when Domain /= ServerHost -> Domain
|
when Domain /= ServerHost -> Domain
|
||||||
end)).
|
end)).
|
||||||
|
|
||||||
handle_event({mnesia_table_event,
|
%%%===================================================================
|
||||||
{write, #route{pid = Pid}, _ActivityId}}) ->
|
%%% gen_server callbacks
|
||||||
erlang:monitor(process, Pid);
|
%%%===================================================================
|
||||||
handle_event({'DOWN', _Ref, _Type, Pid, _Info}) ->
|
init([]) ->
|
||||||
|
update_tables(),
|
||||||
|
ejabberd_mnesia:create(?MODULE, route,
|
||||||
|
[{ram_copies, [node()]},
|
||||||
|
{type, bag},
|
||||||
|
{attributes, record_info(fields, route)}]),
|
||||||
|
mnesia:add_table_copy(route, node(), ram_copies),
|
||||||
|
mnesia:subscribe({table, route, simple}),
|
||||||
|
lists:foreach(
|
||||||
|
fun (Pid) -> erlang:monitor(process, Pid) end,
|
||||||
|
mnesia:dirty_select(route,
|
||||||
|
[{{route, '_', '$1', '_'}, [], ['$1']}])),
|
||||||
|
{ok, #state{}}.
|
||||||
|
|
||||||
|
handle_call(_Request, _From, State) ->
|
||||||
|
Reply = ok,
|
||||||
|
{reply, Reply, State}.
|
||||||
|
|
||||||
|
handle_cast(_Msg, State) ->
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
handle_info({mnesia_table_event,
|
||||||
|
{write, #route{pid = Pid}, _ActivityId}}, State) ->
|
||||||
|
erlang:monitor(process, Pid),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info({'DOWN', _Ref, _Type, Pid, _Info}, State) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
Es = mnesia:select(route,
|
Es = mnesia:select(route,
|
||||||
[{#route{pid = Pid, _ = '_'}, [], ['$_']}]),
|
[{#route{pid = Pid, _ = '_'}, [], ['$_']}]),
|
||||||
@ -158,10 +183,18 @@ handle_event({'DOWN', _Ref, _Type, Pid, _Info}) ->
|
|||||||
end
|
end
|
||||||
end, Es)
|
end, Es)
|
||||||
end,
|
end,
|
||||||
transaction(F);
|
transaction(F),
|
||||||
handle_event(_Event) ->
|
{noreply, State};
|
||||||
|
handle_info(Info, State) ->
|
||||||
|
?ERROR_MSG("unexpected info: ~p", [Info]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
terminate(_Reason, _State) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
@ -105,7 +105,6 @@
|
|||||||
-callback unregister_online_user(ljid(), binary(), binary()) -> any().
|
-callback unregister_online_user(ljid(), binary(), binary()) -> any().
|
||||||
-callback count_online_rooms_by_user(binary(), binary()) -> non_neg_integer().
|
-callback count_online_rooms_by_user(binary(), binary()) -> non_neg_integer().
|
||||||
-callback get_online_rooms_by_user(binary(), binary()) -> [{binary(), binary()}].
|
-callback get_online_rooms_by_user(binary(), binary()) -> [{binary(), binary()}].
|
||||||
-callback handle_event(term()) -> any().
|
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% API
|
%% API
|
||||||
@ -377,9 +376,8 @@ handle_info({room_destroyed, {Room, Host}, Pid}, State) ->
|
|||||||
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
||||||
RMod:unregister_online_room(Room, Host, Pid),
|
RMod:unregister_online_room(Room, Host, Pid),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info(Event, #state{server_host = LServer} = State) ->
|
handle_info(Info, State) ->
|
||||||
RMod = gen_mod:ram_db_mod(LServer, ?MODULE),
|
?ERROR_MSG("unexpected info: ~p", [Info]),
|
||||||
RMod:handle_event(Event),
|
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
terminate(_Reason, #state{host = MyHost}) ->
|
terminate(_Reason, #state{host = MyHost}) ->
|
||||||
|
@ -17,51 +17,29 @@
|
|||||||
-export([register_online_room/3, unregister_online_room/3, find_online_room/2,
|
-export([register_online_room/3, unregister_online_room/3, find_online_room/2,
|
||||||
get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
|
get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
|
||||||
register_online_user/3, unregister_online_user/3,
|
register_online_user/3, unregister_online_user/3,
|
||||||
count_online_rooms_by_user/2, get_online_rooms_by_user/2,
|
count_online_rooms_by_user/2, get_online_rooms_by_user/2]).
|
||||||
handle_event/1]).
|
|
||||||
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
|
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
|
||||||
get_affiliations/3, search_affiliation/4]).
|
get_affiliations/3, search_affiliation/4]).
|
||||||
|
%% gen_server callbacks
|
||||||
|
-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
|
||||||
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
-include("mod_muc.hrl").
|
-include("mod_muc.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include_lib("stdlib/include/ms_transform.hrl").
|
-include_lib("stdlib/include/ms_transform.hrl").
|
||||||
|
|
||||||
|
-record(state, {}).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
init(Host, Opts) ->
|
init(Host, Opts) ->
|
||||||
MyHost = proplists:get_value(host, Opts),
|
case gen_server:start_link({local, ?MODULE}, ?MODULE, [Host, Opts], []) of
|
||||||
case gen_mod:db_mod(Host, Opts, mod_muc) of
|
{ok, _Pid} ->
|
||||||
?MODULE ->
|
ok;
|
||||||
ejabberd_mnesia:create(?MODULE, muc_room,
|
Err ->
|
||||||
[{disc_copies, [node()]},
|
Err
|
||||||
{attributes,
|
|
||||||
record_info(fields, muc_room)}]),
|
|
||||||
ejabberd_mnesia:create(?MODULE, muc_registered,
|
|
||||||
[{disc_copies, [node()]},
|
|
||||||
{attributes,
|
|
||||||
record_info(fields, muc_registered)}]),
|
|
||||||
update_tables(MyHost),
|
|
||||||
mnesia:add_table_index(muc_registered, nick);
|
|
||||||
_ ->
|
|
||||||
ok
|
|
||||||
end,
|
|
||||||
case gen_mod:ram_db_mod(Host, Opts, mod_muc) of
|
|
||||||
?MODULE ->
|
|
||||||
update_muc_online_table(),
|
|
||||||
ejabberd_mnesia:create(?MODULE, muc_online_room,
|
|
||||||
[{ram_copies, [node()]},
|
|
||||||
{type, ordered_set},
|
|
||||||
{attributes,
|
|
||||||
record_info(fields, muc_online_room)}]),
|
|
||||||
mnesia:add_table_copy(muc_online_room, node(), ram_copies),
|
|
||||||
catch ets:new(muc_online_users,
|
|
||||||
[bag, named_table, public, {keypos, 2}]),
|
|
||||||
clean_table_from_bad_node(node(), MyHost),
|
|
||||||
mnesia:subscribe(system);
|
|
||||||
_ ->
|
|
||||||
ok
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
store_room(_LServer, Host, Name, Opts) ->
|
store_room(_LServer, Host, Name, Opts) ->
|
||||||
@ -247,11 +225,6 @@ get_online_rooms(Action, Key, Host, Count, Max, Items) ->
|
|||||||
Items
|
Items
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle_event({mnesia_system_event, {mnesia_down, Node}}) ->
|
|
||||||
clean_table_from_bad_node(Node);
|
|
||||||
handle_event(_) ->
|
|
||||||
ok.
|
|
||||||
|
|
||||||
rsm_supported() ->
|
rsm_supported() ->
|
||||||
true.
|
true.
|
||||||
|
|
||||||
@ -294,6 +267,64 @@ import(_LServer, <<"muc_registered">>,
|
|||||||
#muc_registered{us_host = {{U, S}, RoomHost},
|
#muc_registered{us_host = {{U, S}, RoomHost},
|
||||||
nick = Nick}).
|
nick = Nick}).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% gen_server callbacks
|
||||||
|
%%%===================================================================
|
||||||
|
init([Host, Opts]) ->
|
||||||
|
MyHost = proplists:get_value(host, Opts),
|
||||||
|
case gen_mod:db_mod(Host, Opts, mod_muc) of
|
||||||
|
?MODULE ->
|
||||||
|
ejabberd_mnesia:create(?MODULE, muc_room,
|
||||||
|
[{disc_copies, [node()]},
|
||||||
|
{attributes,
|
||||||
|
record_info(fields, muc_room)}]),
|
||||||
|
ejabberd_mnesia:create(?MODULE, muc_registered,
|
||||||
|
[{disc_copies, [node()]},
|
||||||
|
{attributes,
|
||||||
|
record_info(fields, muc_registered)}]),
|
||||||
|
update_tables(MyHost),
|
||||||
|
mnesia:add_table_index(muc_registered, nick);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
case gen_mod:ram_db_mod(Host, Opts, mod_muc) of
|
||||||
|
?MODULE ->
|
||||||
|
update_muc_online_table(),
|
||||||
|
ejabberd_mnesia:create(?MODULE, muc_online_room,
|
||||||
|
[{ram_copies, [node()]},
|
||||||
|
{type, ordered_set},
|
||||||
|
{attributes,
|
||||||
|
record_info(fields, muc_online_room)}]),
|
||||||
|
mnesia:add_table_copy(muc_online_room, node(), ram_copies),
|
||||||
|
catch ets:new(muc_online_users,
|
||||||
|
[bag, named_table, public, {keypos, 2}]),
|
||||||
|
clean_table_from_bad_node(node(), MyHost),
|
||||||
|
mnesia:subscribe(system);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
{ok, #state{}}.
|
||||||
|
|
||||||
|
handle_call(_Request, _From, State) ->
|
||||||
|
Reply = ok,
|
||||||
|
{reply, Reply, State}.
|
||||||
|
|
||||||
|
handle_cast(_Msg, State) ->
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
|
||||||
|
clean_table_from_bad_node(Node),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info(Info, State) ->
|
||||||
|
?ERROR_MSG("unexpected info: ~p", [Info]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
terminate(_Reason, _State) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
-export([register_online_room/3, unregister_online_room/3, find_online_room/2,
|
-export([register_online_room/3, unregister_online_room/3, find_online_room/2,
|
||||||
get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
|
get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
|
||||||
register_online_user/3, unregister_online_user/3,
|
register_online_user/3, unregister_online_user/3,
|
||||||
count_online_rooms_by_user/2, get_online_rooms_by_user/2,
|
count_online_rooms_by_user/2, get_online_rooms_by_user/2]).
|
||||||
handle_event/1]).
|
|
||||||
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
|
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
|
||||||
get_affiliations/3, search_affiliation/4]).
|
get_affiliations/3, search_affiliation/4]).
|
||||||
|
|
||||||
@ -140,9 +139,6 @@ count_online_rooms(_) ->
|
|||||||
get_online_rooms(_, _) ->
|
get_online_rooms(_, _) ->
|
||||||
erlang:error(not_implemented).
|
erlang:error(not_implemented).
|
||||||
|
|
||||||
handle_event(_) ->
|
|
||||||
ok.
|
|
||||||
|
|
||||||
rsm_supported() ->
|
rsm_supported() ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
-export([register_online_room/3, unregister_online_room/3, find_online_room/2,
|
-export([register_online_room/3, unregister_online_room/3, find_online_room/2,
|
||||||
get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
|
get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
|
||||||
register_online_user/3, unregister_online_user/3,
|
register_online_user/3, unregister_online_user/3,
|
||||||
count_online_rooms_by_user/2, get_online_rooms_by_user/2,
|
count_online_rooms_by_user/2, get_online_rooms_by_user/2]).
|
||||||
handle_event/1]).
|
|
||||||
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
|
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
|
||||||
get_affiliations/3, search_affiliation/4]).
|
get_affiliations/3, search_affiliation/4]).
|
||||||
|
|
||||||
@ -165,9 +164,6 @@ count_online_rooms(_) ->
|
|||||||
get_online_rooms(_, _) ->
|
get_online_rooms(_, _) ->
|
||||||
erlang:error(not_implemented).
|
erlang:error(not_implemented).
|
||||||
|
|
||||||
handle_event(_) ->
|
|
||||||
ok.
|
|
||||||
|
|
||||||
rsm_supported() ->
|
rsm_supported() ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user