mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +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}
|
{false, Attrs, StateData}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
#xmlel{name = 'broadcast', attrs = Attrs} ->
|
#xmlel{name = broadcast, attrs = Attrs} ->
|
||||||
?DEBUG("broadcast~n~p~n", [Packet#xmlel.children]),
|
?DEBUG("broadcast~n~p~n", [Packet#xmlel.children]),
|
||||||
case Packet#xmlel.children of
|
case Packet#xmlel.ns of
|
||||||
[{item, {U, S, R} = _IJIDShort, ISubscription}] ->
|
roster_item ->
|
||||||
IJID = exmpp_jid:make(U,
|
IJID = exmpp_jid:make(exmpp_xml:get_attribute(Packet, u, <<"">>),
|
||||||
S,
|
exmpp_xml:get_attribute(Packet, s, <<"">>),
|
||||||
R),
|
exmpp_xml:get_attribute(Packet, r, <<"">>)),
|
||||||
|
ISubscription = exmpp_xml:get_attribute(Packet, subs, <<"none">>),
|
||||||
{false, Attrs,
|
{false, Attrs,
|
||||||
roster_change(IJID, ISubscription,
|
roster_change(IJID, ISubscription, StateData)};
|
||||||
StateData)};
|
exit ->
|
||||||
[{exit, Reason}] ->
|
Reason = exmpp_xml:get_attribute_as_list(Packet, reason, "Unknown reason"),
|
||||||
{exit, Attrs, 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(
|
case ejabberd_hooks:run_fold(
|
||||||
privacy_updated_list, StateData#state.server,
|
privacy_updated_list, StateData#state.server,
|
||||||
false,
|
false,
|
||||||
|
@ -155,8 +155,8 @@ disconnect_removed_user(User, Server) ->
|
|||||||
ejabberd_sm:route(exmpp_jid:make(),
|
ejabberd_sm:route(exmpp_jid:make(),
|
||||||
exmpp_jid:make(User,
|
exmpp_jid:make(User,
|
||||||
Server),
|
Server),
|
||||||
#xmlel{name = 'broadcast',
|
#xmlel{name = 'broadcast', ns = exit,
|
||||||
children = [{exit, "User removed"}]}).
|
attrs = [exmpp_xml:attribute(reason, "User removed")]}).
|
||||||
|
|
||||||
get_user_resources(User, Server)
|
get_user_resources(User, Server)
|
||||||
when is_binary(User), is_binary(Server) ->
|
when is_binary(User), is_binary(Server) ->
|
||||||
|
@ -362,13 +362,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
|||||||
{atomic, {error, _} = Error} ->
|
{atomic, {error, _} = Error} ->
|
||||||
Error;
|
Error;
|
||||||
{atomic, {result, _} = Res} ->
|
{atomic, {result, _} = Res} ->
|
||||||
|
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = []}])),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
#xmlel{name = 'broadcast',
|
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||||
children=[{privacy_list,
|
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||||
#userlist{name = Name, list = []},
|
children = [exmpp_xml:cdata(ListString)]}),
|
||||||
Name}]}),
|
|
||||||
Res;
|
Res;
|
||||||
_ ->
|
_ ->
|
||||||
{error, 'internal-server-error'}
|
{error, 'internal-server-error'}
|
||||||
@ -393,13 +393,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
|||||||
{atomic, {error, _} = Error} ->
|
{atomic, {error, _} = Error} ->
|
||||||
Error;
|
Error;
|
||||||
{atomic, {result, _} = Res} ->
|
{atomic, {result, _} = Res} ->
|
||||||
|
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = List}])),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
#xmlel{name = 'broadcast',
|
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||||
children=[{privacy_list,
|
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||||
#userlist{name = Name, list = List},
|
children = [exmpp_xml:cdata(ListString)]}),
|
||||||
Name}]}),
|
|
||||||
Res;
|
Res;
|
||||||
_ ->
|
_ ->
|
||||||
{error, 'internal_server_error'}
|
{error, 'internal_server_error'}
|
||||||
|
@ -362,13 +362,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
|||||||
{atomic, {error, _} = Error} ->
|
{atomic, {error, _} = Error} ->
|
||||||
Error;
|
Error;
|
||||||
{atomic, {result, _} = Res} ->
|
{atomic, {result, _} = Res} ->
|
||||||
|
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = []}])),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
#xmlel{name = 'broadcast',
|
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||||
children=[{privacy_list,
|
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||||
#userlist{name = Name, list = []},
|
children = [exmpp_xml:cdata(ListString)]}),
|
||||||
Name}]}),
|
|
||||||
Res;
|
Res;
|
||||||
_ ->
|
_ ->
|
||||||
{error, 'internal-server-error'}
|
{error, 'internal-server-error'}
|
||||||
@ -394,13 +394,13 @@ process_list_set(LUser, LServer, Name, Els) ->
|
|||||||
{atomic, {error, _} = Error} ->
|
{atomic, {error, _} = Error} ->
|
||||||
Error;
|
Error;
|
||||||
{atomic, {result, _} = Res} ->
|
{atomic, {result, _} = Res} ->
|
||||||
|
ListString = lists:flatten(io_lib:format("~p.", [#userlist{name = Name, list = List}])),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
exmpp_jid:make(LUser, LServer),
|
exmpp_jid:make(LUser, LServer),
|
||||||
#xmlel{name = 'broadcast',
|
#xmlel{name = 'broadcast', ns = privacy_list,
|
||||||
children=[{privacy_list,
|
attrs = [exmpp_xml:attribute(list_name, Name)],
|
||||||
#userlist{name = Name, list = List},
|
children = [exmpp_xml:cdata(ListString)]}),
|
||||||
Name}]}),
|
|
||||||
Res;
|
Res;
|
||||||
_ ->
|
_ ->
|
||||||
{error, 'internal_server_error'}
|
{error, 'internal_server_error'}
|
||||||
|
@ -490,12 +490,14 @@ process_item_els(Item, []) ->
|
|||||||
|
|
||||||
push_item(User, Server, From, Item)
|
push_item(User, Server, From, Item)
|
||||||
when is_binary(User), is_binary(Server), ?IS_JID(From) ->
|
when is_binary(User), is_binary(Server), ?IS_JID(From) ->
|
||||||
|
{U, S, R} = Item#roster.jid,
|
||||||
ejabberd_sm:route(exmpp_jid:make(),
|
ejabberd_sm:route(exmpp_jid:make(),
|
||||||
exmpp_jid:make(User, Server),
|
exmpp_jid:make(User, Server),
|
||||||
#xmlel{name = 'broadcast', children =
|
#xmlel{name = 'broadcast', ns = roster_item, attrs =
|
||||||
[{item,
|
[exmpp_xml:attribute(u, U),
|
||||||
Item#roster.jid,
|
exmpp_xml:attribute(s, S),
|
||||||
Item#roster.subscription}]}),
|
exmpp_xml:attribute(r, R),
|
||||||
|
exmpp_xml:attribute(subs, Item#roster.subscription)]}),
|
||||||
|
|
||||||
case roster_versioning_enabled(Server) of
|
case roster_versioning_enabled(Server) of
|
||||||
true ->
|
true ->
|
||||||
|
@ -450,12 +450,14 @@ process_item_els(Item, []) ->
|
|||||||
|
|
||||||
|
|
||||||
push_item(User, Server, From, Item) when is_binary(User), is_binary(Server) ->
|
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(),
|
ejabberd_sm:route(exmpp_jid:make(),
|
||||||
exmpp_jid:make(User, Server),
|
exmpp_jid:make(User, Server),
|
||||||
#xmlel{name = 'broadcast', children =
|
#xmlel{name = 'broadcast', ns = roster_item, attrs =
|
||||||
[{item,
|
[exmpp_xml:attribute(u, U),
|
||||||
Item#roster.jid,
|
exmpp_xml:attribute(s, S),
|
||||||
Item#roster.subscription}]}),
|
exmpp_xml:attribute(r, R),
|
||||||
|
exmpp_xml:attribute(subs, Item#roster.subscription)]}),
|
||||||
case roster_versioning_enabled(Server) of
|
case roster_versioning_enabled(Server) of
|
||||||
true ->
|
true ->
|
||||||
push_item_version(Server, User, From, Item, roster_version(Server, User));
|
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("", "", ""),
|
%% ejabberd_sm:route(jlib:make_jid("", "", ""),
|
||||||
%% jlib:make_jid(User, Server, "")
|
%% jlib:make_jid(User, Server, "")
|
||||||
%% why?
|
%% why?
|
||||||
|
{U, S, R} = Item#roster.jid,
|
||||||
ejabberd_sm:route(From, exmpp_jid:make(User, Server),
|
ejabberd_sm:route(From, exmpp_jid:make(User, Server),
|
||||||
#xmlel{name = 'broadcast', children =
|
#xmlel{name = 'broadcast', ns = roster_item, attrs =
|
||||||
[{item,
|
[exmpp_xml:attribute(u, U),
|
||||||
Item#roster.jid,
|
exmpp_xml:attribute(s, S),
|
||||||
Item#roster.subscription}]}),
|
exmpp_xml:attribute(r, R),
|
||||||
|
exmpp_xml:attribute(subs, Item#roster.subscription)]}),
|
||||||
Request = #xmlel{ns = ?NS_ROSTER, name = 'query',
|
Request = #xmlel{ns = ?NS_ROSTER, name = 'query',
|
||||||
children = [item_to_xml(Item)]},
|
children = [item_to_xml(Item)]},
|
||||||
Stanza = exmpp_iq:set(?NS_JABBER_CLIENT, Request,
|
Stanza = exmpp_iq:set(?NS_JABBER_CLIENT, Request,
|
||||||
|
Loading…
Reference in New Issue
Block a user