25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

* src/ejabberd_sm.erl: Updated the session table to store

additional session info
* src/ejabberd_c2s.erl: Report IP address to ejabberd_sm (thanks
to Christophe Romain)

SVN Revision: 772
This commit is contained in:
Alexey Shchepin 2007-05-21 03:21:34 +00:00
parent 06320f429a
commit 9a6e8e3c55
3 changed files with 61 additions and 19 deletions

View File

@ -1,3 +1,10 @@
2007-05-21 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_sm.erl: Updated the session table to store
additional session info
* src/ejabberd_c2s.erl: Report IP address to ejabberd_sm (thanks
to Christophe Romain)
2007-05-18 Alexey Shchepin <alexey@sevcom.net>
* src/msgs/zh.msg: New chinese translation (thanks to Shelley

View File

@ -64,6 +64,7 @@
pres_timestamp,
pres_invis = false,
privacy_list = none,
ip,
lang}).
%-define(DBGFSM, true).
@ -136,6 +137,7 @@ init([{SockMod, Socket}, Opts]) ->
TLSOpts = lists:filter(fun({certfile, _}) -> true;
(_) -> false
end, Opts),
IP = peerip(SockMod, Socket),
Socket1 =
if
TLSEnabled ->
@ -154,7 +156,8 @@ init([{SockMod, Socket}, Opts]) ->
tls_options = TLSOpts,
streamid = new_id(),
access = Access,
shaper = Shaper}}.
shaper = Shaper,
ip = IP}}.
%%----------------------------------------------------------------------
@ -386,8 +389,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
[StateData#state.socket,
jlib:jid_to_string(JID)]),
SID = {now(), self()},
IP = StateData#state.ip,
ejabberd_sm:open_session(
SID, U, StateData#state.server, R),
SID, U, StateData#state.server, R, IP),
Res1 = jlib:make_result_iq_reply(El),
Res = setelement(4, Res1, []),
send_element(StateData, Res),
@ -717,8 +721,9 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
[StateData#state.socket,
jlib:jid_to_string(JID)]),
SID = {now(), self()},
IP = StateData#state.ip,
ejabberd_sm:open_session(
SID, U, StateData#state.server, R),
SID, U, StateData#state.server, R, IP),
Res = jlib:make_result_iq_reply(El),
send_element(StateData, Res),
change_shaper(StateData, JID),
@ -1323,7 +1328,8 @@ presence_update(From, Packet, StateData) ->
StateData#state.user,
StateData#state.server,
StateData#state.resource,
Status),
Status,
StateData#state.ip),
presence_broadcast(StateData, From, StateData#state.pres_a, Packet),
presence_broadcast(StateData, From, StateData#state.pres_i, Packet),
StateData#state{pres_last = undefined,
@ -1654,7 +1660,8 @@ update_priority(Priority, Packet, StateData) ->
StateData#state.server,
StateData#state.resource,
Priority,
Packet).
Packet,
StateData#state.ip).
get_priority_from_presence(PresencePacket) ->
case xml:get_subtag(PresencePacket, "priority") of
@ -1795,3 +1802,12 @@ process_unauthenticated_stanza(StateData, El) ->
ok
end.
peerip(SockMod, Socket) ->
IP = case SockMod of
gen_tcp -> inet:peername(Socket);
_ -> SockMod:peername(Socket)
end,
case IP of
{ok, IPOK} -> IPOK;
_ -> undefined
end.

View File

@ -14,13 +14,13 @@
%% API
-export([start_link/0,
route/3,
open_session/4, close_session/4,
open_session/5, close_session/4,
check_in_subscription/6,
bounce_offline_message/3,
disconnect_removed_user/2,
get_user_resources/2,
set_presence/6,
unset_presence/5,
set_presence/7,
unset_presence/6,
close_session_unset_presence/5,
dirty_get_sessions_list/0,
dirty_get_my_sessions_list/0,
@ -28,7 +28,8 @@
register_iq_handler/4,
register_iq_handler/5,
unregister_iq_handler/2,
ctl_process/2
ctl_process/2,
get_user_ip/3
]).
%% gen_server callbacks
@ -39,7 +40,7 @@
-include("jlib.hrl").
-include("ejabberd_ctl.hrl").
-record(session, {sid, usr, us, priority}).
-record(session, {sid, usr, us, priority, info}).
-record(state, {}).
%% default value for the maximum number of user connections
@ -64,8 +65,8 @@ route(From, To, Packet) ->
ok
end.
open_session(SID, User, Server, Resource) ->
set_session(SID, User, Server, Resource, undefined),
open_session(SID, User, Server, Resource, IP) ->
set_session(SID, User, Server, Resource, undefined, IP),
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,
@ -80,7 +81,7 @@ close_session(SID, User, Server, Resource) ->
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.lserver,
[SID, JID]).
check_in_subscription(Acc, User, Server, JID, Type, Reason) ->
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
case ejabberd_auth:is_user_exists(User, Server) of
true ->
Acc;
@ -110,13 +111,27 @@ get_user_resources(User, Server) ->
[element(3, S#session.usr) || S <- clean_session_list(Ss)]
end.
set_presence(SID, User, Server, Resource, Priority, Presence) ->
set_session(SID, User, Server, Resource, Priority),
get_user_ip(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
[] ->
undefined;
Ss ->
Session = lists:max(Ss),
proplists:get_value(ip, Session#session.info)
end.
set_presence(SID, User, Server, Resource, Priority, Presence, IP) ->
set_session(SID, User, Server, Resource, Priority, IP),
ejabberd_hooks:run(set_presence_hook, jlib:nameprep(Server),
[User, Server, Resource, Presence]).
unset_presence(SID, User, Server, Resource, Status) ->
set_session(SID, User, Server, Resource, undefined),
unset_presence(SID, User, Server, Resource, Status, IP) ->
set_session(SID, User, Server, Resource, undefined, IP),
ejabberd_hooks:run(unset_presence_hook, jlib:nameprep(Server),
[User, Server, Resource, Status]).
@ -275,17 +290,19 @@ code_change(_OldVsn, State, _Extra) ->
%%% Internal functions
%%--------------------------------------------------------------------
set_session(SID, User, Server, Resource, Priority) ->
set_session(SID, User, Server, Resource, Priority, IP) ->
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,
us = US,
priority = Priority})
priority = Priority,
info = Info})
end,
mnesia:sync_dirty(F).
@ -617,6 +634,8 @@ update_tables() ->
[usr, us, pid] ->
mnesia:delete_table(session);
[sid, usr, us, priority] ->
mnesia:delete_table(session);
[sid, usr, us, priority, info] ->
ok;
{'EXIT', _} ->
ok