mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
*** empty log message ***
SVN Revision: 17
This commit is contained in:
parent
496c041b28
commit
10f47ce78d
@ -95,11 +95,10 @@ terminate(Reason, State) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
% TODO: lowercase user name
|
|
||||||
|
|
||||||
check_password(User, Password) ->
|
check_password(User, Password) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
case mnesia:read({passwd, User}) of
|
case mnesia:read({passwd, LUser}) of
|
||||||
[E] ->
|
[E] ->
|
||||||
E#passwd.password
|
E#passwd.password
|
||||||
end
|
end
|
||||||
@ -113,16 +112,19 @@ check_password(User, Password) ->
|
|||||||
|
|
||||||
|
|
||||||
set_password(User, Password) ->
|
set_password(User, Password) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:write(#passwd{user = User, password = Password})
|
mnesia:write(#passwd{user = LUser, password = Password})
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
try_register(User, Password) ->
|
try_register(User, Password) ->
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
case mnesia:read({passwd, User}) of
|
case mnesia:read({passwd, LUser}) of
|
||||||
[] ->
|
[] ->
|
||||||
mnesia:write(#passwd{user = User, password = Password}),
|
mnesia:write(#passwd{user = LUser,
|
||||||
|
password = Password}),
|
||||||
ok;
|
ok;
|
||||||
[E] ->
|
[E] ->
|
||||||
exists
|
exists
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
-author('alexey@sevcom.net').
|
-author('alexey@sevcom.net').
|
||||||
-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]).
|
||||||
|
|
||||||
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
@ -240,3 +241,20 @@ do_route(From, To, Packet) ->
|
|||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
get_user_resources(User) ->
|
||||||
|
F = fun() ->
|
||||||
|
mnemosyne:eval(query [X.resource || X <- table(user_resource),
|
||||||
|
X.user = User]
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
case mnesia:transaction(F) of
|
||||||
|
{atomic, Rs} ->
|
||||||
|
Rs;
|
||||||
|
{aborted, Reason} ->
|
||||||
|
?DEBUG("delivery failed: ~p~n", [Reason]),
|
||||||
|
[]
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,13 +78,16 @@ process_iq(From, To, IQ) ->
|
|||||||
|
|
||||||
process_iq_get(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
process_iq_get(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
||||||
{User, _, _} = From,
|
{User, _, _} = From,
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:read({roster, User})
|
mnesia:read({roster, LUser})
|
||||||
end,
|
end,
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
{atomic, Items} ->
|
{atomic, Items} ->
|
||||||
XItems = lists:map(fun item_to_xml/1, Items),
|
XItems = lists:map(fun item_to_xml/1, Items),
|
||||||
{iq, ID, result, XMLNS, XItems};
|
{iq, ID, result, XMLNS, [{xmlelement, "query",
|
||||||
|
[{"xmlns", "jabber:iq:roster"}],
|
||||||
|
XItems}]};
|
||||||
_ ->
|
_ ->
|
||||||
{iq, ID, error, XMLNS,
|
{iq, ID, error, XMLNS,
|
||||||
[SubEl, jlib:make_error_element("500",
|
[SubEl, jlib:make_error_element("500",
|
||||||
@ -102,6 +105,8 @@ item_to_xml(Item) ->
|
|||||||
Attrs3 = case Item#roster.subscription of
|
Attrs3 = case Item#roster.subscription of
|
||||||
none ->
|
none ->
|
||||||
[{"subscription", "none"} | Attrs2];
|
[{"subscription", "none"} | Attrs2];
|
||||||
|
remove ->
|
||||||
|
[{"subscription", "remove"} | Attrs2];
|
||||||
_ ->
|
_ ->
|
||||||
% TODO
|
% TODO
|
||||||
Attrs2
|
Attrs2
|
||||||
@ -124,36 +129,45 @@ process_item_set(User, To, XItem) ->
|
|||||||
{xmlelement, Name, Attrs, Els} = XItem,
|
{xmlelement, Name, Attrs, Els} = XItem,
|
||||||
% TODO: load existing item
|
% TODO: load existing item
|
||||||
JID = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
|
JID = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
case JID of
|
case JID of
|
||||||
error ->
|
error ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
Res = mnemosyne:eval(query [X || X <- table(roster),
|
Res = mnemosyne:eval(query [X || X <- table(roster),
|
||||||
X.user = User,
|
X.user = LUser,
|
||||||
X.jid = JID]
|
X.jid = JID]
|
||||||
end),
|
end),
|
||||||
Item = case Res of
|
Item = case Res of
|
||||||
[] ->
|
[] ->
|
||||||
#roster{user = User,
|
#roster{user = LUser,
|
||||||
jid = JID,
|
jid = JID,
|
||||||
groups = [],
|
groups = [],
|
||||||
xattrs = [],
|
xattrs = [],
|
||||||
xs = []};
|
xs = []};
|
||||||
[I] ->
|
[I] ->
|
||||||
mnesia:delete_object(I),
|
mnesia:delete_object(I),
|
||||||
I
|
I#roster{groups = [],
|
||||||
|
xattrs = [],
|
||||||
|
xs = []}
|
||||||
end,
|
end,
|
||||||
Item1 = process_item_attrs(Item, Attrs),
|
Item1 = process_item_attrs(Item, Attrs),
|
||||||
Item2 = process_item_els(Item1, Els),
|
Item2 = process_item_els(Item1, Els),
|
||||||
mnesia:write(Item2),
|
case Item2#roster.subscription of
|
||||||
|
remove ->
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
mnesia:write(Item2)
|
||||||
|
end,
|
||||||
Item2
|
Item2
|
||||||
end,
|
end,
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
{atomic, Item} ->
|
{atomic, Item} ->
|
||||||
io:format("ROSTER: push for user ~p: ~p~n", [User, Item]),
|
push_item(User, To, Item),
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
E ->
|
||||||
|
?DEBUG("ROSTER: roster item set error: ~p~n", [E]),
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
@ -163,26 +177,26 @@ process_item_attrs(Item, [{Attr, Val} | Attrs]) ->
|
|||||||
"jid" ->
|
"jid" ->
|
||||||
case jlib:string_to_jid(Val) of
|
case jlib:string_to_jid(Val) of
|
||||||
error ->
|
error ->
|
||||||
process_item_attrs(Item, [Attrs]);
|
process_item_attrs(Item, Attrs);
|
||||||
JID ->
|
JID ->
|
||||||
process_item_attrs(Item#roster{jid = JID}, [Attrs])
|
process_item_attrs(Item#roster{jid = JID}, Attrs)
|
||||||
end;
|
end;
|
||||||
"name" ->
|
"name" ->
|
||||||
process_item_attrs(Item#roster{name = Val}, [Attrs]);
|
process_item_attrs(Item#roster{name = Val}, Attrs);
|
||||||
"subscription" ->
|
"subscription" ->
|
||||||
case Val of
|
case Val of
|
||||||
"remove" ->
|
"remove" ->
|
||||||
process_item_attrs(Item#roster{subscription = remove},
|
process_item_attrs(Item#roster{subscription = remove},
|
||||||
[Attrs]);
|
Attrs);
|
||||||
_ ->
|
_ ->
|
||||||
process_item_attrs(Item, [Attrs])
|
process_item_attrs(Item, Attrs)
|
||||||
end;
|
end;
|
||||||
"ask" ->
|
"ask" ->
|
||||||
process_item_attrs(Item, [Attrs]);
|
process_item_attrs(Item, Attrs);
|
||||||
_ ->
|
_ ->
|
||||||
XAttrs = Item#roster.xattrs,
|
XAttrs = Item#roster.xattrs,
|
||||||
process_item_attrs(Item#roster{xattrs = [{Attr, Val} | XAttrs]},
|
process_item_attrs(Item#roster{xattrs = [{Attr, Val} | XAttrs]},
|
||||||
[Attrs])
|
Attrs)
|
||||||
end;
|
end;
|
||||||
process_item_attrs(Item, []) ->
|
process_item_attrs(Item, []) ->
|
||||||
Item.
|
Item.
|
||||||
@ -207,3 +221,22 @@ process_item_els(Item, [{xmlcdata, _} | Els]) ->
|
|||||||
process_item_els(Item, Els);
|
process_item_els(Item, Els);
|
||||||
process_item_els(Item, []) ->
|
process_item_els(Item, []) ->
|
||||||
Item.
|
Item.
|
||||||
|
|
||||||
|
|
||||||
|
push_item(User, From, Item) ->
|
||||||
|
lists:foreach(fun(Resource) ->
|
||||||
|
push_item(User, Resource, From, Item)
|
||||||
|
end, ejabberd_sm:get_user_resources(User)).
|
||||||
|
|
||||||
|
% TODO: don't push to those who not load roster
|
||||||
|
push_item(User, Resource, From, Item) ->
|
||||||
|
ResIQ = {iq, "", set, "jabber:iq:roster",
|
||||||
|
[{xmlelement, "query",
|
||||||
|
[{"xmlns", "jabber:iq:roster"}],
|
||||||
|
[item_to_xml(Item)]}]},
|
||||||
|
ejabberd_router ! {route,
|
||||||
|
From,
|
||||||
|
{User, ?MYNAME, Resource},
|
||||||
|
jlib:iq_to_xml(ResIQ)}.
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user