pres_timestamp,
pres_invis = false,
privacy_list = none,
+ ip,
lang}).
%-define(DBGFSM, true).
TLSOpts = lists:filter(fun({certfile, _}) -> true;
(_) -> false
end, Opts),
+ IP = peerip(SockMod, Socket),
Socket1 =
if
TLSEnabled ->
tls_options = TLSOpts,
streamid = new_id(),
access = Access,
- shaper = Shaper}}.
+ shaper = Shaper,
+ ip = IP}}.
%%----------------------------------------------------------------------
[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),
[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),
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,
StateData#state.server,
StateData#state.resource,
Priority,
- Packet).
+ Packet,
+ StateData#state.ip).
get_priority_from_presence(PresencePacket) ->
case xml:get_subtag(PresencePacket, "priority") of
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.
%% 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,
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
-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
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,
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;
[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]).
%%% 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).
[usr, us, pid] ->
mnesia:delete_table(session);
[sid, usr, us, priority] ->
+ mnesia:delete_table(session);
+ [sid, usr, us, priority, info] ->
ok;
{'EXIT', _} ->
ok