mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
*** empty log message ***
SVN Revision: 23
This commit is contained in:
parent
8e2a94b71d
commit
72d2cf7a4b
4
TODO
4
TODO
@ -1,5 +1,3 @@
|
|||||||
presence
|
|
||||||
iq:register
|
|
||||||
S2S timeouts
|
S2S timeouts
|
||||||
...
|
...
|
||||||
iq:browse
|
iq:browse
|
||||||
@ -7,4 +5,4 @@ iq:disco
|
|||||||
...
|
...
|
||||||
services support
|
services support
|
||||||
JUD
|
JUD
|
||||||
|
SVR DNS records
|
||||||
|
@ -427,6 +427,8 @@ presence_update(From, Packet, StateData) ->
|
|||||||
{xmlelement, Name, Attrs, Els} = Packet,
|
{xmlelement, Name, Attrs, Els} = Packet,
|
||||||
case xml:get_attr_s("type", Attrs) of
|
case xml:get_attr_s("type", Attrs) of
|
||||||
"unavailable" ->
|
"unavailable" ->
|
||||||
|
ejabberd_sm:unset_presence(StateData#state.user,
|
||||||
|
StateData#state.resource),
|
||||||
presence_broadcast(From, StateData#state.pres_a, Packet),
|
presence_broadcast(From, StateData#state.pres_a, Packet),
|
||||||
presence_broadcast(From, StateData#state.pres_i, Packet),
|
presence_broadcast(From, StateData#state.pres_i, Packet),
|
||||||
StateData#state{pres_last = undefined,
|
StateData#state{pres_last = undefined,
|
||||||
@ -461,6 +463,7 @@ presence_update(From, Packet, StateData) ->
|
|||||||
"unsubscribed" ->
|
"unsubscribed" ->
|
||||||
StateData;
|
StateData;
|
||||||
_ ->
|
_ ->
|
||||||
|
update_priority(jlib:get_subtag(Packet, "priority"), StateData),
|
||||||
FromUnavail = (StateData#state.pres_last == undefined) or
|
FromUnavail = (StateData#state.pres_last == undefined) or
|
||||||
StateData#state.pres_invis,
|
StateData#state.pres_invis,
|
||||||
?DEBUG("from unavail = ~p~n", [FromUnavail]),
|
?DEBUG("from unavail = ~p~n", [FromUnavail]),
|
||||||
@ -612,3 +615,19 @@ roster_change(IJID, ISubscription, StateData) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
update_priority(El, StateData) ->
|
||||||
|
Pri = case El of
|
||||||
|
false ->
|
||||||
|
0;
|
||||||
|
_ ->
|
||||||
|
case catch list_to_integer(xml:get_tag_cdata(El)) of
|
||||||
|
P when is_integer(P) ->
|
||||||
|
P;
|
||||||
|
_ ->
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
ejabberd_sm:set_presence(StateData#state.user,
|
||||||
|
StateData#state.resource,
|
||||||
|
Pri).
|
||||||
|
|
||||||
|
@ -11,13 +11,16 @@
|
|||||||
-vsn('$Revision$ ').
|
-vsn('$Revision$ ').
|
||||||
|
|
||||||
-export([start/0, init/0, open_session/2, close_session/2,
|
-export([start/0, init/0, open_session/2, close_session/2,
|
||||||
get_user_resources/1]).
|
get_user_resources/1,
|
||||||
|
set_presence/3,
|
||||||
|
unset_presence/2]).
|
||||||
|
|
||||||
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
|
|
||||||
-record(session, {ur, user, node}).
|
-record(session, {ur, user, node}).
|
||||||
-record(mysession, {ur, pid}).
|
-record(mysession, {ur, pid}).
|
||||||
|
-record(presence, {ur, user, priority}).
|
||||||
|
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
@ -25,14 +28,18 @@ start() ->
|
|||||||
|
|
||||||
init() ->
|
init() ->
|
||||||
register(ejabberd_sm, self()),
|
register(ejabberd_sm, self()),
|
||||||
mnesia:create_table(session,[{ram_copies, [node()]},
|
mnesia:create_table(session, [{ram_copies, [node()]},
|
||||||
{attributes, record_info(fields, session)}]),
|
{attributes, record_info(fields, session)}]),
|
||||||
mnesia:add_table_index(session, user),
|
mnesia:add_table_index(session, user),
|
||||||
mnesia:add_table_index(session, node),
|
mnesia:add_table_index(session, node),
|
||||||
mnesia:create_table(mysession,
|
mnesia:create_table(mysession,
|
||||||
[{ram_copies, [node()]},
|
[{ram_copies, [node()]},
|
||||||
{local_content, true},
|
{local_content, true},
|
||||||
{attributes, record_info(fields, mysession)}]),
|
{attributes, record_info(fields, mysession)}]),
|
||||||
|
mnesia:create_table(presence,
|
||||||
|
[{ram_copies, [node()]},
|
||||||
|
{attributes, record_info(fields, presence)}]),
|
||||||
|
mnesia:add_table_index(presence, user),
|
||||||
mnesia:subscribe(system),
|
mnesia:subscribe(system),
|
||||||
loop().
|
loop().
|
||||||
|
|
||||||
@ -66,10 +73,11 @@ close_session(User, Resource) ->
|
|||||||
ejabberd_sm ! {close_session, User, Resource}.
|
ejabberd_sm ! {close_session, User, Resource}.
|
||||||
|
|
||||||
replace_alien_connection(User, Resource) ->
|
replace_alien_connection(User, Resource) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
UR = {User, Resource},
|
UR = {LUser, Resource},
|
||||||
Es = mnesia:read({session, UR}),
|
Es = mnesia:read({session, UR}),
|
||||||
mnesia:write(#session{ur = UR, user = User, node = node()}),
|
mnesia:write(#session{ur = UR, user = LUser, node = node()}),
|
||||||
Es
|
Es
|
||||||
end,
|
end,
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
@ -89,8 +97,9 @@ replace_alien_connection(User, Resource) ->
|
|||||||
|
|
||||||
|
|
||||||
replace_my_connection(User, Resource) ->
|
replace_my_connection(User, Resource) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
UR = {User, Resource},
|
UR = {LUser, Resource},
|
||||||
Es = mnesia:read({mysession, UR}),
|
Es = mnesia:read({mysession, UR}),
|
||||||
mnesia:delete({mysession, UR}),
|
mnesia:delete({mysession, UR}),
|
||||||
Es
|
Es
|
||||||
@ -106,16 +115,18 @@ replace_my_connection(User, Resource) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
remove_connection(User, Resource) ->
|
remove_connection(User, Resource) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
UR = {User, Resource},
|
UR = {LUser, Resource},
|
||||||
mnesia:delete({mysession, UR}),
|
mnesia:delete({mysession, UR}),
|
||||||
mnesia:delete({session, UR})
|
mnesia:delete({session, UR})
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
replace_and_register_my_connection(User, Resource, Pid) ->
|
replace_and_register_my_connection(User, Resource, Pid) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
UR = {User, Resource},
|
UR = {LUser, Resource},
|
||||||
Es = mnesia:read({mysession, UR}),
|
Es = mnesia:read({mysession, UR}),
|
||||||
mnesia:write(#mysession{ur = UR, pid = Pid}),
|
mnesia:write(#mysession{ur = UR, pid = Pid}),
|
||||||
Es
|
Es
|
||||||
@ -209,8 +220,16 @@ do_route(From, To, Packet) ->
|
|||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
"message" ->
|
"message" ->
|
||||||
% TODO
|
case catch lists:max(get_user_present_resources(User)) of
|
||||||
ok;
|
{'EXIT', _} ->
|
||||||
|
% TODO
|
||||||
|
ok;
|
||||||
|
{_, R} ->
|
||||||
|
ejabberd_sm ! {route,
|
||||||
|
From,
|
||||||
|
{User, Server, R},
|
||||||
|
Packet}
|
||||||
|
end;
|
||||||
"iq" ->
|
"iq" ->
|
||||||
% TODO
|
% TODO
|
||||||
ok;
|
ok;
|
||||||
@ -248,17 +267,49 @@ do_route(From, To, Packet) ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
get_user_resources(User) ->
|
get_user_resources(User) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnemosyne:eval(query [X.ur || X <- table(session),
|
mnemosyne:eval(query [X.ur || X <- table(session),
|
||||||
X.user = User]
|
X.user = LUser]
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
{atomic, Rs} ->
|
{atomic, Rs} ->
|
||||||
lists:map(fun(R) -> element(2, R) end, Rs);
|
lists:map(fun(R) -> element(2, R) end, Rs);
|
||||||
{aborted, Reason} ->
|
{aborted, Reason} ->
|
||||||
?DEBUG("delivery failed: ~p~n", [Reason]),
|
|
||||||
[]
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
set_presence(User, Resource, Priority) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
|
F = fun() ->
|
||||||
|
UR = {User, Resource},
|
||||||
|
mnesia:write(#presence{ur = UR, user = LUser,
|
||||||
|
priority = Priority})
|
||||||
|
end,
|
||||||
|
mnesia:transaction(F).
|
||||||
|
|
||||||
|
unset_presence(User, Resource) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
|
F = fun() ->
|
||||||
|
UR = {User, Resource},
|
||||||
|
mnesia:delete({presence, UR})
|
||||||
|
end,
|
||||||
|
mnesia:transaction(F).
|
||||||
|
|
||||||
|
get_user_present_resources(User) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
|
F = fun() ->
|
||||||
|
mnesia:index_read(presence, LUser, #presence.user)
|
||||||
|
end,
|
||||||
|
case mnesia:transaction(F) of
|
||||||
|
{atomic, Rs} ->
|
||||||
|
lists:map(fun(R) ->
|
||||||
|
{R#presence.priority, element(2, R#presence.ur)}
|
||||||
|
end, Rs);
|
||||||
|
{aborted, Reason} ->
|
||||||
|
[]
|
||||||
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user