mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01:00
different hooks should be called for session migration and session close
This commit is contained in:
parent
b0c79c57b0
commit
191cd2af3c
@ -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;
|
||||
|
@ -1613,10 +1613,10 @@ 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,
|
||||
StateData#state.user,
|
||||
StateData#state.server,
|
||||
StateData#state.resource);
|
||||
ejabberd_sm:close_migrated_session(StateData#state.sid,
|
||||
StateData#state.user,
|
||||
StateData#state.server,
|
||||
StateData#state.resource);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user