mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Improve ejabberd's broadcast stanzas to satisfy #xmlel type
This commit is contained in:
parent
4fd7ec27f5
commit
67da88f0bd
@ -1198,19 +1198,25 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
|
||||
{false, Attrs, StateData}
|
||||
end
|
||||
end;
|
||||
#xmlel{name = 'broadcast', attrs = Attrs} ->
|
||||
#xmlel{name = broadcast, attrs = Attrs} ->
|
||||
?DEBUG("broadcast~n~p~n", [Packet#xmlel.children]),
|
||||
case Packet#xmlel.children of
|
||||
[{item, {U, S, R} = _IJIDShort, ISubscription}] ->
|
||||
IJID = exmpp_jid:make(U,
|
||||
S,
|
||||
R),
|
||||
case Packet#xmlel.ns of
|
||||
roster_item ->
|
||||
IJID = exmpp_jid:make(exmpp_xml:get_attribute(Packet, u, <<"">>),
|
||||
exmpp_xml:get_attribute(Packet, s, <<"">>),
|
||||
exmpp_xml:get_attribute(Packet, r, <<"">>)),
|
||||
ISubscription = exmpp_xml:get_attribute(Packet, subs, <<"none">>),
|
||||
{false, Attrs,
|
||||
roster_change(IJID, ISubscription,
|
||||
StateData)};
|
||||
[{exit, Reason}] ->
|
||||
roster_change(IJID, ISubscription, StateData)};
|
||||
exit ->
|
||||
Reason = exmpp_xml:get_attribute_as_list(Packet, reason, "Unknown reason"),
|
||||
{exit, Attrs, Reason};
|
||||
[{privacy_list, PrivList, PrivListName}] ->
|
||||
privacy_list ->
|
||||
PrivListName = exmpp_xml:get_attribute_as_list(Packet, list_name, "Unknown list name"),
|
||||
CDataString = exmpp_xml:get_cdata_as_list(Packet),
|
||||
{ok, A2, _} = erl_scan:string(CDataString),
|
||||
{_, W} = erl_parse:parse_exprs(A2),
|
||||
{value, PrivList, []} = erl_eval:exprs(W, []),
|
||||
case ejabberd_hooks:run_fold(
|
||||
privacy_updated_list, StateData#state.server,
|
||||
false,
|
||||
|
@ -155,8 +155,8 @@ disconnect_removed_user(User, Server) ->
|
||||
ejabberd_sm:route(exmpp_jid:make(),
|
||||
exmpp_jid:make(User,
|
||||
Server),
|
||||
#xmlel{name = 'broadcast',
|
||||
children = [{exit, "User removed"}]}).
|
||||
#xmlel{name = 'broadcast', ns = exit,
|
||||
attrs = [exmpp_xml:attribute(reason, "User removed")]}).
|
||||
|
||||
get_user_resources(User, Server)
|
||||
when is_binary(User), is_binary(Server) ->
|
||||
|
@ -362,13 +362,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
||||
{atomic, {error, _} = Error} ->
|
||||
Error;
|
||||
{atomic, {result, _} = Res} ->
|
||||
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = []}])),
|
||||
ejabberd_router:route(
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
#xmlel{name = 'broadcast',
|
||||
children=[{privacy_list,
|
||||
#userlist{name = Name, list = []},
|
||||
Name}]}),
|
||||
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||
children = [exmpp_xml:cdata(ListString)]}),
|
||||
Res;
|
||||
_ ->
|
||||
{error, 'internal-server-error'}
|
||||
@ -393,13 +393,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
||||
{atomic, {error, _} = Error} ->
|
||||
Error;
|
||||
{atomic, {result, _} = Res} ->
|
||||
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = List}])),
|
||||
ejabberd_router:route(
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
#xmlel{name = 'broadcast',
|
||||
children=[{privacy_list,
|
||||
#userlist{name = Name, list = List},
|
||||
Name}]}),
|
||||
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||
children = [exmpp_xml:cdata(ListString)]}),
|
||||
Res;
|
||||
_ ->
|
||||
{error, 'internal_server_error'}
|
||||
|
@ -362,13 +362,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
||||
{atomic, {error, _} = Error} ->
|
||||
Error;
|
||||
{atomic, {result, _} = Res} ->
|
||||
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = []}])),
|
||||
ejabberd_router:route(
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
#xmlel{name = 'broadcast',
|
||||
children=[{privacy_list,
|
||||
#userlist{name = Name, list = []},
|
||||
Name}]}),
|
||||
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||
children = [exmpp_xml:cdata(ListString)]}),
|
||||
Res;
|
||||
_ ->
|
||||
{error, 'internal-server-error'}
|
||||
@ -394,13 +394,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
||||
{atomic, {error, _} = Error} ->
|
||||
Error;
|
||||
{atomic, {result, _} = Res} ->
|
||||
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = List}])),
|
||||
ejabberd_router:route(
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
exmpp_jid:make(LUser, LServer),
|
||||
#xmlel{name = 'broadcast',
|
||||
children=[{privacy_list,
|
||||
#userlist{name = Name, list = List},
|
||||
Name}]}),
|
||||
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||
children = [exmpp_xml:cdata(ListString)]}),
|
||||
Res;
|
||||
_ ->
|
||||
{error, 'internal_server_error'}
|
||||
|
@ -490,12 +490,14 @@ process_item_els(Item, []) ->
|
||||
|
||||
push_item(User, Server, From, Item)
|
||||
when is_binary(User), is_binary(Server), ?IS_JID(From) ->
|
||||
{U, S, R} = Item#roster.jid,
|
||||
ejabberd_sm:route(exmpp_jid:make(),
|
||||
exmpp_jid:make(User, Server),
|
||||
#xmlel{name = 'broadcast', children =
|
||||
[{item,
|
||||
Item#roster.jid,
|
||||
Item#roster.subscription}]}),
|
||||
#xmlel{name = 'broadcast', ns = roster_item, attrs =
|
||||
[exmpp_xml:attribute(u, U),
|
||||
exmpp_xml:attribute(s, S),
|
||||
exmpp_xml:attribute(r, R),
|
||||
exmpp_xml:attribute(subs, Item#roster.subscription)]}),
|
||||
|
||||
case roster_versioning_enabled(Server) of
|
||||
true ->
|
||||
|
@ -450,12 +450,14 @@ process_item_els(Item, []) ->
|
||||
|
||||
|
||||
push_item(User, Server, From, Item) when is_binary(User), is_binary(Server) ->
|
||||
{U, S, R} = Item#roster.jid,
|
||||
ejabberd_sm:route(exmpp_jid:make(),
|
||||
exmpp_jid:make(User, Server),
|
||||
#xmlel{name = 'broadcast', children =
|
||||
[{item,
|
||||
Item#roster.jid,
|
||||
Item#roster.subscription}]}),
|
||||
#xmlel{name = 'broadcast', ns = roster_item, attrs =
|
||||
[exmpp_xml:attribute(u, U),
|
||||
exmpp_xml:attribute(s, S),
|
||||
exmpp_xml:attribute(r, R),
|
||||
exmpp_xml:attribute(subs, Item#roster.subscription)]}),
|
||||
case roster_versioning_enabled(Server) of
|
||||
true ->
|
||||
push_item_version(Server, User, From, Item, roster_version(Server, User));
|
||||
|
@ -735,11 +735,13 @@ push_item(User, Server, From, Item) ->
|
||||
%% ejabberd_sm:route(jlib:make_jid("", "", ""),
|
||||
%% jlib:make_jid(User, Server, "")
|
||||
%% why?
|
||||
{U, S, R} = Item#roster.jid,
|
||||
ejabberd_sm:route(From, exmpp_jid:make(User, Server),
|
||||
#xmlel{name = 'broadcast', children =
|
||||
[{item,
|
||||
Item#roster.jid,
|
||||
Item#roster.subscription}]}),
|
||||
#xmlel{name = 'broadcast', ns = roster_item, attrs =
|
||||
[exmpp_xml:attribute(u, U),
|
||||
exmpp_xml:attribute(s, S),
|
||||
exmpp_xml:attribute(r, R),
|
||||
exmpp_xml:attribute(subs, Item#roster.subscription)]}),
|
||||
Request = #xmlel{ns = ?NS_ROSTER, name = 'query',
|
||||
children = [item_to_xml(Item)]},
|
||||
Stanza = exmpp_iq:set(?NS_JABBER_CLIENT, Request,
|
||||
|
Loading…
Reference in New Issue
Block a user