mirror of
https://github.com/processone/ejabberd.git
synced 2024-10-03 14:45:16 +02:00
Retreive connection type in sm_register_connection_hook
SVN Revision: 1194
This commit is contained in:
parent
def7b0ff90
commit
04d688c1ba
@ -1,3 +1,10 @@
|
||||
2008-02-15 Christophe Romain <christophe.romain@process-one.net>
|
||||
|
||||
* src/ejabberd_sm.erl: Retreive connection type in
|
||||
sm_register_connection_hook
|
||||
* src/ejabberd_c2s.erl: Likewise
|
||||
* src/ejabberd_auth_anonymous.erl: Likewise
|
||||
|
||||
2008-02-14 Badlop <badlop@process-one.net>
|
||||
|
||||
* src/mod_muc/mod_muc_room.erl: Allow unmoderated rooms (EJAB-437)
|
||||
|
@ -33,8 +33,8 @@
|
||||
is_login_anonymous_enabled/1,
|
||||
anonymous_user_exist/2,
|
||||
allow_multiple_connections/1,
|
||||
register_connection/2,
|
||||
unregister_connection/2
|
||||
register_connection/3,
|
||||
unregister_connection/3
|
||||
]).
|
||||
|
||||
|
||||
@ -141,14 +141,14 @@ remove_connection(SID, LUser, LServer) ->
|
||||
mnesia:transaction(F).
|
||||
|
||||
%% Register connection
|
||||
register_connection(SID, #jid{luser = LUser, lserver = LServer}) ->
|
||||
register_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
|
||||
US = {LUser, LServer},
|
||||
mnesia:sync_dirty(
|
||||
fun() -> mnesia:write(#anonymous{us = US, sid=SID})
|
||||
end).
|
||||
|
||||
%% Remove an anonymous user from the anonymous users table
|
||||
unregister_connection(SID, #jid{luser = LUser, lserver = LServer}) ->
|
||||
unregister_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
|
||||
purge_hook(anonymous_user_exist(LUser, LServer),
|
||||
LUser, LServer),
|
||||
remove_connection(SID, LUser, LServer).
|
||||
|
@ -85,6 +85,7 @@
|
||||
pres_timestamp,
|
||||
pres_invis = false,
|
||||
privacy_list = none,
|
||||
conn = unknown,
|
||||
ip,
|
||||
lang}).
|
||||
|
||||
@ -437,9 +438,10 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
||||
[StateData#state.socket,
|
||||
jlib:jid_to_string(JID)]),
|
||||
SID = {now(), self()},
|
||||
IP = StateData#state.ip,
|
||||
Conn = get_conn_type(StateData),
|
||||
Info = [{ip, StateData#state.ip}, {conn, Conn}],
|
||||
ejabberd_sm:open_session(
|
||||
SID, U, StateData#state.server, R, IP),
|
||||
SID, U, StateData#state.server, R, Info),
|
||||
Res1 = jlib:make_result_iq_reply(El),
|
||||
Res = setelement(4, Res1, []),
|
||||
send_element(StateData, Res),
|
||||
@ -464,6 +466,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
||||
resource = R,
|
||||
jid = JID,
|
||||
sid = SID,
|
||||
conn = Conn,
|
||||
pres_f = ?SETS:from_list(Fs1),
|
||||
pres_t = ?SETS:from_list(Ts1),
|
||||
privacy_list = PrivList});
|
||||
@ -785,9 +788,10 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
|
||||
[StateData#state.socket,
|
||||
jlib:jid_to_string(JID)]),
|
||||
SID = {now(), self()},
|
||||
IP = StateData#state.ip,
|
||||
Conn = get_conn_type(StateData),
|
||||
Info = [{ip, StateData#state.ip}, {conn, Conn}],
|
||||
ejabberd_sm:open_session(
|
||||
SID, U, StateData#state.server, R, IP),
|
||||
SID, U, StateData#state.server, R, Info),
|
||||
Res = jlib:make_result_iq_reply(El),
|
||||
send_element(StateData, Res),
|
||||
change_shaper(StateData, JID),
|
||||
@ -807,6 +811,7 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
|
||||
fsm_next_state(session_established,
|
||||
StateData#state{
|
||||
sid = SID,
|
||||
conn = Conn,
|
||||
pres_f = ?SETS:from_list(Fs1),
|
||||
pres_t = ?SETS:from_list(Ts1),
|
||||
privacy_list = PrivList});
|
||||
@ -1368,6 +1373,17 @@ get_auth_tags([_ | L], U, P, D, R) ->
|
||||
get_auth_tags([], U, P, D, R) ->
|
||||
{U, P, D, R}.
|
||||
|
||||
get_conn_type(StateData) ->
|
||||
case StateData#state.sockmod of
|
||||
ejabberd_http_poll -> http_poll;
|
||||
ejabberd_http_bind -> http_bind;
|
||||
_ ->
|
||||
case (StateData#state.sockmod):get_sockmod(StateData#state.socket) of
|
||||
ejabberd_zlib -> c2s_compressed;
|
||||
tls -> c2s_tls;
|
||||
gen_tcp -> c2s
|
||||
end
|
||||
end.
|
||||
|
||||
process_presence_probe(From, To, StateData) ->
|
||||
LFrom = jlib:jid_tolower(From),
|
||||
@ -1427,12 +1443,13 @@ presence_update(From, Packet, StateData) ->
|
||||
StatusTag ->
|
||||
xml:get_tag_cdata(StatusTag)
|
||||
end,
|
||||
Info = [{ip, StateData#state.ip},{conn, StateData#state.conn}],
|
||||
ejabberd_sm:unset_presence(StateData#state.sid,
|
||||
StateData#state.user,
|
||||
StateData#state.server,
|
||||
StateData#state.resource,
|
||||
Status,
|
||||
StateData#state.ip),
|
||||
Info),
|
||||
presence_broadcast(StateData, From, StateData#state.pres_a, Packet),
|
||||
presence_broadcast(StateData, From, StateData#state.pres_i, Packet),
|
||||
StateData#state{pres_last = undefined,
|
||||
@ -1758,13 +1775,14 @@ roster_change(IJID, ISubscription, StateData) ->
|
||||
|
||||
|
||||
update_priority(Priority, Packet, StateData) ->
|
||||
Info = [{ip, StateData#state.ip},{conn, StateData#state.conn}],
|
||||
ejabberd_sm:set_presence(StateData#state.sid,
|
||||
StateData#state.user,
|
||||
StateData#state.server,
|
||||
StateData#state.resource,
|
||||
Priority,
|
||||
Packet,
|
||||
StateData#state.ip).
|
||||
Info).
|
||||
|
||||
get_priority_from_presence(PresencePacket) ->
|
||||
case xml:get_subtag(PresencePacket, "priority") of
|
||||
|
@ -48,6 +48,7 @@
|
||||
unregister_iq_handler/2,
|
||||
ctl_process/2,
|
||||
get_session_pid/3,
|
||||
get_user_info/3,
|
||||
get_user_ip/3
|
||||
]).
|
||||
|
||||
@ -84,21 +85,25 @@ route(From, To, Packet) ->
|
||||
ok
|
||||
end.
|
||||
|
||||
open_session(SID, User, Server, Resource, IP) ->
|
||||
set_session(SID, User, Server, Resource, undefined, IP),
|
||||
open_session(SID, User, Server, Resource, Info) ->
|
||||
set_session(SID, User, Server, Resource, undefined, Info),
|
||||
check_for_sessions_to_replace(User, Server, Resource),
|
||||
JID = jlib:make_jid(User, Server, Resource),
|
||||
ejabberd_hooks:run(sm_register_connection_hook, JID#jid.lserver,
|
||||
[SID, JID]).
|
||||
[SID, JID, Info]).
|
||||
|
||||
close_session(SID, User, Server, Resource) ->
|
||||
Info = case mnesia:dirty_read({session, SID}) of
|
||||
[] -> [];
|
||||
[#session{info=I}] -> I
|
||||
end,
|
||||
F = fun() ->
|
||||
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]).
|
||||
[SID, JID, Info]).
|
||||
|
||||
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
|
||||
case ejabberd_auth:is_user_exists(User, Server) of
|
||||
@ -143,14 +148,29 @@ get_user_ip(User, Server, Resource) ->
|
||||
proplists:get_value(ip, Session#session.info)
|
||||
end.
|
||||
|
||||
get_user_info(User, Server, Resource) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
USR = {LUser, LServer, LResource},
|
||||
case mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||
[] ->
|
||||
offline;
|
||||
Ss ->
|
||||
Session = lists:max(Ss),
|
||||
Node = node(element(2, Session#session.sid)),
|
||||
Conn = proplists:get_value(conn, Session#session.info),
|
||||
IP = proplists:get_value(ip, Session#session.info),
|
||||
[{node, Node}, {conn, Conn}, {ip, IP}]
|
||||
end.
|
||||
|
||||
set_presence(SID, User, Server, Resource, Priority, Presence, IP) ->
|
||||
set_session(SID, User, Server, Resource, Priority, IP),
|
||||
set_presence(SID, User, Server, Resource, Priority, Presence, Info) ->
|
||||
set_session(SID, User, Server, Resource, Priority, Info),
|
||||
ejabberd_hooks:run(set_presence_hook, jlib:nameprep(Server),
|
||||
[User, Server, Resource, Presence]).
|
||||
|
||||
unset_presence(SID, User, Server, Resource, Status, IP) ->
|
||||
set_session(SID, User, Server, Resource, undefined, IP),
|
||||
unset_presence(SID, User, Server, Resource, Status, Info) ->
|
||||
set_session(SID, User, Server, Resource, undefined, Info),
|
||||
ejabberd_hooks:run(unset_presence_hook, jlib:nameprep(Server),
|
||||
[User, Server, Resource, Status]).
|
||||
|
||||
@ -318,13 +338,12 @@ code_change(_OldVsn, State, _Extra) ->
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
set_session(SID, User, Server, Resource, Priority, IP) ->
|
||||
set_session(SID, User, Server, Resource, Priority, Info) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
US = {LUser, LServer},
|
||||
USR = {LUser, LServer, LResource},
|
||||
Info = [{ip, IP}],
|
||||
F = fun() ->
|
||||
mnesia:write(#session{sid = SID,
|
||||
usr = USR,
|
||||
@ -349,7 +368,6 @@ clean_table_from_bad_node(Node) ->
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
do_route(From, To, Packet) ->
|
||||
?DEBUG("session manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||
[From, To, Packet, 8]),
|
||||
|
Loading…
Reference in New Issue
Block a user