mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01:00
Do not fetch disco#info multiple times
This commit is contained in:
parent
1b0c02cb2e
commit
167f02ab72
@ -660,7 +660,8 @@ stats(Config) ->
|
||||
disconnect(Config).
|
||||
|
||||
pubsub(Config) ->
|
||||
true = is_feature_advertised(Config, ?NS_PUBSUB),
|
||||
Features = get_features(Config, pubsub_jid(Config)),
|
||||
true = lists:member(?NS_PUBSUB, Features),
|
||||
%% Publish <presence/> element within node "presence"
|
||||
ItemID = randoms:get_string(),
|
||||
Node = <<"presence">>,
|
||||
@ -684,7 +685,7 @@ pubsub(Config) ->
|
||||
#message{sub_els = [#pubsub_event{}, #delay{}]},
|
||||
#iq{type = result, id = I1}),
|
||||
%% Get subscriptions
|
||||
true = is_feature_advertised(Config, ?PUBSUB("retrieve-subscriptions")),
|
||||
true = lists:member(?PUBSUB("retrieve-subscriptions"), Features),
|
||||
#iq{type = result,
|
||||
sub_els =
|
||||
[#pubsub{subscriptions =
|
||||
@ -692,7 +693,7 @@ pubsub(Config) ->
|
||||
send_recv(Config, #iq{type = get, to = pubsub_jid(Config),
|
||||
sub_els = [#pubsub{subscriptions = {none, []}}]}),
|
||||
%% Get affiliations
|
||||
true = is_feature_advertised(Config, ?PUBSUB("retrieve-affiliations")),
|
||||
true = lists:member(?PUBSUB("retrieve-affiliations"), Features),
|
||||
#iq{type = result,
|
||||
sub_els = [#pubsub{
|
||||
affiliations =
|
||||
@ -700,7 +701,7 @@ pubsub(Config) ->
|
||||
send_recv(Config, #iq{type = get, to = pubsub_jid(Config),
|
||||
sub_els = [#pubsub{affiliations = []}]}),
|
||||
%% Get subscription options
|
||||
true = is_feature_advertised(Config, ?PUBSUB("subscription-options")),
|
||||
true = lists:member(?PUBSUB("subscription-options"), Features),
|
||||
#iq{type = result, sub_els = [#pubsub{options = #pubsub_options{
|
||||
node = Node}}]} =
|
||||
send_recv(Config,
|
||||
@ -717,7 +718,7 @@ pubsub(Config) ->
|
||||
#iq{type = get, to = pubsub_jid(Config),
|
||||
sub_els = [#pubsub{items = #pubsub_items{node = Node}}]}),
|
||||
%% Deleting the item from the node
|
||||
true = is_feature_advertised(Config, ?PUBSUB("delete-items")),
|
||||
true = lists:member(?PUBSUB("delete-items"), Features),
|
||||
I2 = send(Config,
|
||||
#iq{type = set, to = pubsub_jid(Config),
|
||||
sub_els = [#pubsub{retract = #pubsub_retract{
|
||||
@ -1227,13 +1228,19 @@ id(undefined) ->
|
||||
id(ID) ->
|
||||
ID.
|
||||
|
||||
get_features(Config) ->
|
||||
get_features(Config, server_jid(Config)).
|
||||
|
||||
get_features(Config, To) ->
|
||||
#iq{type = result, sub_els = [#disco_info{features = Features}]} =
|
||||
send_recv(Config, #iq{type = get, sub_els = [#disco_info{}], to = To}),
|
||||
Features.
|
||||
|
||||
is_feature_advertised(Config, Feature) ->
|
||||
is_feature_advertised(Config, Feature, server_jid(Config)).
|
||||
|
||||
is_feature_advertised(Config, Feature, To) ->
|
||||
ID = send(Config, #iq{type = get, sub_els = [#disco_info{}], to = To}),
|
||||
#iq{type = result, id = ID,
|
||||
sub_els = [#disco_info{feature = Features}]} = recv(),
|
||||
Features = get_features(Config, To),
|
||||
lists:member(Feature, Features).
|
||||
|
||||
bookmark_conference() ->
|
||||
|
@ -1038,7 +1038,8 @@ pp(block, 1) -> [items];
|
||||
pp(unblock, 1) -> [items];
|
||||
pp(block_list, 0) -> [];
|
||||
pp(identity, 4) -> [category, type, lang, name];
|
||||
pp(disco_info, 4) -> [node, identity, feature, xdata];
|
||||
pp(disco_info, 4) ->
|
||||
[node, identities, features, xdata];
|
||||
pp(disco_item, 3) -> [jid, name, node];
|
||||
pp(disco_items, 2) -> [node, items];
|
||||
pp(private, 1) -> [sub_els];
|
||||
@ -12856,54 +12857,56 @@ encode_disco_item_attr_node(_val, _acc) ->
|
||||
[{<<"node">>, _val} | _acc].
|
||||
|
||||
decode_disco_info({xmlel, <<"query">>, _attrs, _els}) ->
|
||||
{Xdata, Feature, Identity} = decode_disco_info_els(_els,
|
||||
[], [], []),
|
||||
{Xdata, Features, Identities} =
|
||||
decode_disco_info_els(_els, [], [], []),
|
||||
Node = decode_disco_info_attrs(_attrs, undefined),
|
||||
{disco_info, Node, Identity, Feature, Xdata}.
|
||||
{disco_info, Node, Identities, Features, Xdata}.
|
||||
|
||||
decode_disco_info_els([], Xdata, Feature, Identity) ->
|
||||
{lists:reverse(Xdata), lists:reverse(Feature),
|
||||
lists:reverse(Identity)};
|
||||
decode_disco_info_els([], Xdata, Features,
|
||||
Identities) ->
|
||||
{lists:reverse(Xdata), lists:reverse(Features),
|
||||
lists:reverse(Identities)};
|
||||
decode_disco_info_els([{xmlel, <<"identity">>, _attrs,
|
||||
_} =
|
||||
_el
|
||||
| _els],
|
||||
Xdata, Feature, Identity) ->
|
||||
Xdata, Features, Identities) ->
|
||||
_xmlns = xml:get_attr_s(<<"xmlns">>, _attrs),
|
||||
if _xmlns == <<>>;
|
||||
_xmlns == <<"http://jabber.org/protocol/disco#info">> ->
|
||||
decode_disco_info_els(_els, Xdata, Feature,
|
||||
[decode_disco_identity(_el) | Identity]);
|
||||
decode_disco_info_els(_els, Xdata, Features,
|
||||
[decode_disco_identity(_el) | Identities]);
|
||||
true ->
|
||||
decode_disco_info_els(_els, Xdata, Feature, Identity)
|
||||
decode_disco_info_els(_els, Xdata, Features, Identities)
|
||||
end;
|
||||
decode_disco_info_els([{xmlel, <<"feature">>, _attrs,
|
||||
_} =
|
||||
_el
|
||||
| _els],
|
||||
Xdata, Feature, Identity) ->
|
||||
Xdata, Features, Identities) ->
|
||||
_xmlns = xml:get_attr_s(<<"xmlns">>, _attrs),
|
||||
if _xmlns == <<>>;
|
||||
_xmlns == <<"http://jabber.org/protocol/disco#info">> ->
|
||||
decode_disco_info_els(_els, Xdata,
|
||||
[decode_disco_feature(_el) | Feature],
|
||||
Identity);
|
||||
[decode_disco_feature(_el) | Features],
|
||||
Identities);
|
||||
true ->
|
||||
decode_disco_info_els(_els, Xdata, Feature, Identity)
|
||||
decode_disco_info_els(_els, Xdata, Features, Identities)
|
||||
end;
|
||||
decode_disco_info_els([{xmlel, <<"x">>, _attrs, _} = _el
|
||||
| _els],
|
||||
Xdata, Feature, Identity) ->
|
||||
Xdata, Features, Identities) ->
|
||||
_xmlns = xml:get_attr_s(<<"xmlns">>, _attrs),
|
||||
if _xmlns == <<"jabber:x:data">> ->
|
||||
decode_disco_info_els(_els, [decode_xdata(_el) | Xdata],
|
||||
Feature, Identity);
|
||||
Features, Identities);
|
||||
true ->
|
||||
decode_disco_info_els(_els, Xdata, Feature, Identity)
|
||||
decode_disco_info_els(_els, Xdata, Features, Identities)
|
||||
end;
|
||||
decode_disco_info_els([_ | _els], Xdata, Feature,
|
||||
Identity) ->
|
||||
decode_disco_info_els(_els, Xdata, Feature, Identity).
|
||||
decode_disco_info_els([_ | _els], Xdata, Features,
|
||||
Identities) ->
|
||||
decode_disco_info_els(_els, Xdata, Features,
|
||||
Identities).
|
||||
|
||||
decode_disco_info_attrs([{<<"node">>, _val} | _attrs],
|
||||
_Node) ->
|
||||
@ -12913,13 +12916,13 @@ decode_disco_info_attrs([_ | _attrs], Node) ->
|
||||
decode_disco_info_attrs([], Node) ->
|
||||
decode_disco_info_attr_node(Node).
|
||||
|
||||
encode_disco_info({disco_info, Node, Identity, Feature,
|
||||
Xdata},
|
||||
encode_disco_info({disco_info, Node, Identities,
|
||||
Features, Xdata},
|
||||
_xmlns_attrs) ->
|
||||
_els = 'encode_disco_info_$identity'(Identity,
|
||||
'encode_disco_info_$feature'(Feature,
|
||||
'encode_disco_info_$xdata'(Xdata,
|
||||
[]))),
|
||||
_els = 'encode_disco_info_$identities'(Identities,
|
||||
'encode_disco_info_$features'(Features,
|
||||
'encode_disco_info_$xdata'(Xdata,
|
||||
[]))),
|
||||
_attrs = encode_disco_info_attr_node(Node,
|
||||
_xmlns_attrs),
|
||||
{xmlel, <<"query">>, _attrs, _els}.
|
||||
@ -12932,16 +12935,18 @@ encode_disco_info({disco_info, Node, Identity, Feature,
|
||||
<<"jabber:x:data">>}])
|
||||
| _acc]).
|
||||
|
||||
'encode_disco_info_$feature'([], _acc) -> _acc;
|
||||
'encode_disco_info_$feature'([Feature | _els], _acc) ->
|
||||
'encode_disco_info_$feature'(_els,
|
||||
[encode_disco_feature(Feature, []) | _acc]).
|
||||
|
||||
'encode_disco_info_$identity'([], _acc) -> _acc;
|
||||
'encode_disco_info_$identity'([Identity | _els],
|
||||
'encode_disco_info_$features'([], _acc) -> _acc;
|
||||
'encode_disco_info_$features'([Features | _els],
|
||||
_acc) ->
|
||||
'encode_disco_info_$identity'(_els,
|
||||
[encode_disco_identity(Identity, []) | _acc]).
|
||||
'encode_disco_info_$features'(_els,
|
||||
[encode_disco_feature(Features, []) | _acc]).
|
||||
|
||||
'encode_disco_info_$identities'([], _acc) -> _acc;
|
||||
'encode_disco_info_$identities'([Identities | _els],
|
||||
_acc) ->
|
||||
'encode_disco_info_$identities'(_els,
|
||||
[encode_disco_identity(Identities, [])
|
||||
| _acc]).
|
||||
|
||||
decode_disco_info_attr_node(undefined) -> undefined;
|
||||
decode_disco_info_attr_node(_val) -> _val.
|
||||
|
@ -337,8 +337,8 @@
|
||||
retract :: #pubsub_retract{}}).
|
||||
|
||||
-record(disco_info, {node :: binary(),
|
||||
identity = [] :: [#identity{}],
|
||||
feature = [] :: [binary()],
|
||||
identities = [] :: [#identity{}],
|
||||
features = [] :: [binary()],
|
||||
xdata = [] :: [#xdata{}]}).
|
||||
|
||||
-record(sasl_mechanisms, {list = [] :: [binary()]}).
|
||||
|
@ -196,12 +196,12 @@
|
||||
{disco_info,
|
||||
#elem{name = <<"query">>,
|
||||
xmlns = <<"http://jabber.org/protocol/disco#info">>,
|
||||
result = {disco_info, '$node', '$identity', '$feature', '$xdata'},
|
||||
result = {disco_info, '$node', '$identities', '$features', '$xdata'},
|
||||
attrs = [#attr{name = <<"node">>}],
|
||||
refs = [#ref{name = disco_identity,
|
||||
label = '$identity'},
|
||||
label = '$identities'},
|
||||
#ref{name = disco_feature,
|
||||
label = '$feature'},
|
||||
label = '$features'},
|
||||
#ref{name = xdata,
|
||||
label = '$xdata'}]}}.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user