25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Do not fetch disco#info multiple times

This commit is contained in:
Evgeniy Khramtsov 2013-06-26 03:32:08 +10:00
parent 1b0c02cb2e
commit 167f02ab72
4 changed files with 61 additions and 49 deletions

View File

@ -660,7 +660,8 @@ stats(Config) ->
disconnect(Config). disconnect(Config).
pubsub(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" %% Publish <presence/> element within node "presence"
ItemID = randoms:get_string(), ItemID = randoms:get_string(),
Node = <<"presence">>, Node = <<"presence">>,
@ -684,7 +685,7 @@ pubsub(Config) ->
#message{sub_els = [#pubsub_event{}, #delay{}]}, #message{sub_els = [#pubsub_event{}, #delay{}]},
#iq{type = result, id = I1}), #iq{type = result, id = I1}),
%% Get subscriptions %% Get subscriptions
true = is_feature_advertised(Config, ?PUBSUB("retrieve-subscriptions")), true = lists:member(?PUBSUB("retrieve-subscriptions"), Features),
#iq{type = result, #iq{type = result,
sub_els = sub_els =
[#pubsub{subscriptions = [#pubsub{subscriptions =
@ -692,7 +693,7 @@ pubsub(Config) ->
send_recv(Config, #iq{type = get, to = pubsub_jid(Config), send_recv(Config, #iq{type = get, to = pubsub_jid(Config),
sub_els = [#pubsub{subscriptions = {none, []}}]}), sub_els = [#pubsub{subscriptions = {none, []}}]}),
%% Get affiliations %% Get affiliations
true = is_feature_advertised(Config, ?PUBSUB("retrieve-affiliations")), true = lists:member(?PUBSUB("retrieve-affiliations"), Features),
#iq{type = result, #iq{type = result,
sub_els = [#pubsub{ sub_els = [#pubsub{
affiliations = affiliations =
@ -700,7 +701,7 @@ pubsub(Config) ->
send_recv(Config, #iq{type = get, to = pubsub_jid(Config), send_recv(Config, #iq{type = get, to = pubsub_jid(Config),
sub_els = [#pubsub{affiliations = []}]}), sub_els = [#pubsub{affiliations = []}]}),
%% Get subscription options %% 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{ #iq{type = result, sub_els = [#pubsub{options = #pubsub_options{
node = Node}}]} = node = Node}}]} =
send_recv(Config, send_recv(Config,
@ -717,7 +718,7 @@ pubsub(Config) ->
#iq{type = get, to = pubsub_jid(Config), #iq{type = get, to = pubsub_jid(Config),
sub_els = [#pubsub{items = #pubsub_items{node = Node}}]}), sub_els = [#pubsub{items = #pubsub_items{node = Node}}]}),
%% Deleting the item from the 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, I2 = send(Config,
#iq{type = set, to = pubsub_jid(Config), #iq{type = set, to = pubsub_jid(Config),
sub_els = [#pubsub{retract = #pubsub_retract{ sub_els = [#pubsub{retract = #pubsub_retract{
@ -1227,13 +1228,19 @@ id(undefined) ->
id(ID) -> id(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) ->
is_feature_advertised(Config, Feature, server_jid(Config)). is_feature_advertised(Config, Feature, server_jid(Config)).
is_feature_advertised(Config, Feature, To) -> is_feature_advertised(Config, Feature, To) ->
ID = send(Config, #iq{type = get, sub_els = [#disco_info{}], to = To}), Features = get_features(Config, To),
#iq{type = result, id = ID,
sub_els = [#disco_info{feature = Features}]} = recv(),
lists:member(Feature, Features). lists:member(Feature, Features).
bookmark_conference() -> bookmark_conference() ->

View File

@ -1038,7 +1038,8 @@ pp(block, 1) -> [items];
pp(unblock, 1) -> [items]; pp(unblock, 1) -> [items];
pp(block_list, 0) -> []; pp(block_list, 0) -> [];
pp(identity, 4) -> [category, type, lang, name]; 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_item, 3) -> [jid, name, node];
pp(disco_items, 2) -> [node, items]; pp(disco_items, 2) -> [node, items];
pp(private, 1) -> [sub_els]; pp(private, 1) -> [sub_els];
@ -12856,54 +12857,56 @@ encode_disco_item_attr_node(_val, _acc) ->
[{<<"node">>, _val} | _acc]. [{<<"node">>, _val} | _acc].
decode_disco_info({xmlel, <<"query">>, _attrs, _els}) -> 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), 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) -> decode_disco_info_els([], Xdata, Features,
{lists:reverse(Xdata), lists:reverse(Feature), Identities) ->
lists:reverse(Identity)}; {lists:reverse(Xdata), lists:reverse(Features),
lists:reverse(Identities)};
decode_disco_info_els([{xmlel, <<"identity">>, _attrs, decode_disco_info_els([{xmlel, <<"identity">>, _attrs,
_} = _} =
_el _el
| _els], | _els],
Xdata, Feature, Identity) -> Xdata, Features, Identities) ->
_xmlns = xml:get_attr_s(<<"xmlns">>, _attrs), _xmlns = xml:get_attr_s(<<"xmlns">>, _attrs),
if _xmlns == <<>>; if _xmlns == <<>>;
_xmlns == <<"http://jabber.org/protocol/disco#info">> -> _xmlns == <<"http://jabber.org/protocol/disco#info">> ->
decode_disco_info_els(_els, Xdata, Feature, decode_disco_info_els(_els, Xdata, Features,
[decode_disco_identity(_el) | Identity]); [decode_disco_identity(_el) | Identities]);
true -> true ->
decode_disco_info_els(_els, Xdata, Feature, Identity) decode_disco_info_els(_els, Xdata, Features, Identities)
end; end;
decode_disco_info_els([{xmlel, <<"feature">>, _attrs, decode_disco_info_els([{xmlel, <<"feature">>, _attrs,
_} = _} =
_el _el
| _els], | _els],
Xdata, Feature, Identity) -> Xdata, Features, Identities) ->
_xmlns = xml:get_attr_s(<<"xmlns">>, _attrs), _xmlns = xml:get_attr_s(<<"xmlns">>, _attrs),
if _xmlns == <<>>; if _xmlns == <<>>;
_xmlns == <<"http://jabber.org/protocol/disco#info">> -> _xmlns == <<"http://jabber.org/protocol/disco#info">> ->
decode_disco_info_els(_els, Xdata, decode_disco_info_els(_els, Xdata,
[decode_disco_feature(_el) | Feature], [decode_disco_feature(_el) | Features],
Identity); Identities);
true -> true ->
decode_disco_info_els(_els, Xdata, Feature, Identity) decode_disco_info_els(_els, Xdata, Features, Identities)
end; end;
decode_disco_info_els([{xmlel, <<"x">>, _attrs, _} = _el decode_disco_info_els([{xmlel, <<"x">>, _attrs, _} = _el
| _els], | _els],
Xdata, Feature, Identity) -> Xdata, Features, Identities) ->
_xmlns = xml:get_attr_s(<<"xmlns">>, _attrs), _xmlns = xml:get_attr_s(<<"xmlns">>, _attrs),
if _xmlns == <<"jabber:x:data">> -> if _xmlns == <<"jabber:x:data">> ->
decode_disco_info_els(_els, [decode_xdata(_el) | Xdata], decode_disco_info_els(_els, [decode_xdata(_el) | Xdata],
Feature, Identity); Features, Identities);
true -> true ->
decode_disco_info_els(_els, Xdata, Feature, Identity) decode_disco_info_els(_els, Xdata, Features, Identities)
end; end;
decode_disco_info_els([_ | _els], Xdata, Feature, decode_disco_info_els([_ | _els], Xdata, Features,
Identity) -> Identities) ->
decode_disco_info_els(_els, Xdata, Feature, Identity). decode_disco_info_els(_els, Xdata, Features,
Identities).
decode_disco_info_attrs([{<<"node">>, _val} | _attrs], decode_disco_info_attrs([{<<"node">>, _val} | _attrs],
_Node) -> _Node) ->
@ -12913,13 +12916,13 @@ decode_disco_info_attrs([_ | _attrs], Node) ->
decode_disco_info_attrs([], Node) -> decode_disco_info_attrs([], Node) ->
decode_disco_info_attr_node(Node). decode_disco_info_attr_node(Node).
encode_disco_info({disco_info, Node, Identity, Feature, encode_disco_info({disco_info, Node, Identities,
Xdata}, Features, Xdata},
_xmlns_attrs) -> _xmlns_attrs) ->
_els = 'encode_disco_info_$identity'(Identity, _els = 'encode_disco_info_$identities'(Identities,
'encode_disco_info_$feature'(Feature, 'encode_disco_info_$features'(Features,
'encode_disco_info_$xdata'(Xdata, 'encode_disco_info_$xdata'(Xdata,
[]))), []))),
_attrs = encode_disco_info_attr_node(Node, _attrs = encode_disco_info_attr_node(Node,
_xmlns_attrs), _xmlns_attrs),
{xmlel, <<"query">>, _attrs, _els}. {xmlel, <<"query">>, _attrs, _els}.
@ -12932,16 +12935,18 @@ encode_disco_info({disco_info, Node, Identity, Feature,
<<"jabber:x:data">>}]) <<"jabber:x:data">>}])
| _acc]). | _acc]).
'encode_disco_info_$feature'([], _acc) -> _acc; 'encode_disco_info_$features'([], _acc) -> _acc;
'encode_disco_info_$feature'([Feature | _els], _acc) -> 'encode_disco_info_$features'([Features | _els],
'encode_disco_info_$feature'(_els,
[encode_disco_feature(Feature, []) | _acc]).
'encode_disco_info_$identity'([], _acc) -> _acc;
'encode_disco_info_$identity'([Identity | _els],
_acc) -> _acc) ->
'encode_disco_info_$identity'(_els, 'encode_disco_info_$features'(_els,
[encode_disco_identity(Identity, []) | _acc]). [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(undefined) -> undefined;
decode_disco_info_attr_node(_val) -> _val. decode_disco_info_attr_node(_val) -> _val.

View File

@ -337,8 +337,8 @@
retract :: #pubsub_retract{}}). retract :: #pubsub_retract{}}).
-record(disco_info, {node :: binary(), -record(disco_info, {node :: binary(),
identity = [] :: [#identity{}], identities = [] :: [#identity{}],
feature = [] :: [binary()], features = [] :: [binary()],
xdata = [] :: [#xdata{}]}). xdata = [] :: [#xdata{}]}).
-record(sasl_mechanisms, {list = [] :: [binary()]}). -record(sasl_mechanisms, {list = [] :: [binary()]}).

View File

@ -196,12 +196,12 @@
{disco_info, {disco_info,
#elem{name = <<"query">>, #elem{name = <<"query">>,
xmlns = <<"http://jabber.org/protocol/disco#info">>, 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">>}], attrs = [#attr{name = <<"node">>}],
refs = [#ref{name = disco_identity, refs = [#ref{name = disco_identity,
label = '$identity'}, label = '$identities'},
#ref{name = disco_feature, #ref{name = disco_feature,
label = '$feature'}, label = '$features'},
#ref{name = xdata, #ref{name = xdata,
label = '$xdata'}]}}. label = '$xdata'}]}}.