25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

different hooks should be called for session migration and session close

This commit is contained in:
Evgeniy Khramtsov 2010-09-21 03:17:52 +10:00
parent b0c79c57b0
commit 191cd2af3c
4 changed files with 29 additions and 7 deletions

View File

@ -34,6 +34,7 @@
anonymous_user_exist/2,
allow_multiple_connections/1,
register_connection/3,
unregister_migrated_connection/3,
unregister_connection/3
]).
@ -69,6 +70,8 @@ start(Host) ->
%% The hooks are needed to add / remove users from the anonymous tables
ejabberd_hooks:add(sm_register_connection_hook, Host,
?MODULE, register_connection, 100),
ejabberd_hooks:add(sm_remove_migrated_connection_hook, Host,
?MODULE, unregister_migrated_connection, 100),
ejabberd_hooks:add(sm_remove_connection_hook, Host,
?MODULE, unregister_connection, 100),
ok.
@ -159,6 +162,10 @@ unregister_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
LUser, LServer),
remove_connection(SID, LUser, LServer).
%% Remove an anonymous user from the anonymous users table
unregister_migrated_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
remove_connection(SID, LUser, LServer).
%% Launch the hook to purge user data only for anonymous users
purge_hook(false, _LUser, _LServer) ->
ok;

View File

@ -1613,7 +1613,7 @@ terminate({migrated, ClonePid}, StateName, StateData) ->
[StateData#state.socket,
jlib:jid_to_string(StateData#state.jid),
ClonePid, node(ClonePid)]),
ejabberd_sm:close_session(StateData#state.sid,
ejabberd_sm:close_migrated_session(StateData#state.sid,
StateData#state.user,
StateData#state.server,
StateData#state.resource);

View File

@ -36,6 +36,7 @@
open_session/5,
open_session/6,
close_session/4,
close_migrated_session/4,
check_in_subscription/6,
bounce_offline_message/3,
disconnect_removed_user/2,
@ -106,6 +107,18 @@ open_session(SID, User, Server, Resource, Priority, Info) ->
[SID, JID, Info]).
close_session(SID, User, Server, Resource) ->
Info = do_close_session(SID, User, Server, Resource),
JID = jlib:make_jid(User, Server, Resource),
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.lserver,
[SID, JID, Info]).
close_migrated_session(SID, User, Server, Resource) ->
Info = do_close_session(SID, User, Server, Resource),
JID = jlib:make_jid(User, Server, Resource),
ejabberd_hooks:run(sm_remove_migrated_connection_hook, JID#jid.lserver,
[SID, JID, Info]).
do_close_session(SID, User, Server, Resource) ->
Info = case mnesia:dirty_read({session, SID}) of
[] -> [];
[#session{info=I}] -> I
@ -114,9 +127,7 @@ close_session(SID, User, Server, Resource) ->
mnesia:delete({session, SID})
end,
mnesia:sync_dirty(F),
JID = jlib:make_jid(User, Server, Resource),
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.lserver,
[SID, JID, Info]).
Info.
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
case ejabberd_auth:is_user_exists(User, Server) of

View File

@ -107,6 +107,8 @@ init([Host, Opts]) ->
?MODULE, user_online, 100),
ejabberd_hooks:add(sm_remove_connection_hook, Host,
?MODULE, user_offline, 100),
ejabberd_hooks:add(sm_remove_migrated_connection_hook, Host,
?MODULE, user_offline, 100),
ejabberd_hooks:add(user_send_packet, Host,
?MODULE, user_send, 100);
_ ->
@ -121,6 +123,8 @@ init([Host, Opts]) ->
terminate(_Reason, #state{host = Host}) ->
ejabberd_hooks:delete(sm_remove_connection_hook, Host,
?MODULE, user_offline, 100),
ejabberd_hooks:delete(sm_remove_migrated_connection_hook, Host,
?MODULE, user_offline, 100),
ejabberd_hooks:delete(sm_register_connection_hook, Host,
?MODULE, user_online, 100),
ejabberd_hooks:delete(user_send_packet, Host,