mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Fixed Bugs handling Service Discovery to contacts (EJAB-1207)
This commit is contained in:
parent
f01dd3e942
commit
4548f2faf0
@ -279,8 +279,17 @@ process_sm_iq_items(From, To, #iq{type = get, payload = SubEl,
|
||||
<<>> -> [];
|
||||
_ -> [?XMLATTR('node', Node)]
|
||||
end,
|
||||
AItems = case Node of
|
||||
<<>> ->
|
||||
case is_presence_subscribed(From, To) of
|
||||
true -> Items;
|
||||
false -> []
|
||||
end;
|
||||
_ ->
|
||||
[]
|
||||
end,
|
||||
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query',
|
||||
attrs = ANode, children = Items},
|
||||
attrs = ANode, children = AItems},
|
||||
exmpp_iq:result(IQ_Rec, Result);
|
||||
{error, Error} ->
|
||||
exmpp_iq:error(IQ_Rec, Error)
|
||||
@ -288,22 +297,36 @@ process_sm_iq_items(From, To, #iq{type = get, payload = SubEl,
|
||||
process_sm_iq_items(_From, _To, #iq{type = set, payload = _SubEl} = IQ_Rec) ->
|
||||
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||
|
||||
is_presence_subscribed(From, To) ->
|
||||
User = exmpp_jid:prep_node(From),
|
||||
Server = exmpp_jid:prep_domain(From),
|
||||
LUser = exmpp_jid:prep_node(To),
|
||||
LServer = exmpp_jid:prep_domain(To),
|
||||
lists:any(fun({roster, _, _, {TUser, TServer, _}, _, S, _, _, _, _}) ->
|
||||
if
|
||||
LUser == TUser, LServer == TServer, S/=none ->
|
||||
true;
|
||||
true ->
|
||||
false
|
||||
end
|
||||
end,
|
||||
ejabberd_hooks:run_fold(roster_get, Server, [], [{User, Server}]))
|
||||
orelse User == LUser andalso Server == LServer.
|
||||
|
||||
|
||||
get_sm_items({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
|
||||
Acc;
|
||||
|
||||
get_sm_items(Acc, From, To, <<>>, _Lang) ->
|
||||
LFrom = exmpp_jid:prep_node_as_list(From),
|
||||
LSFrom = exmpp_jid:prep_domain_as_list(From),
|
||||
LTo = exmpp_jid:prep_node_as_list(To),
|
||||
LSTo = exmpp_jid:prep_domain_as_list(To),
|
||||
|
||||
Items = case Acc of
|
||||
{result, Its} -> Its;
|
||||
empty -> []
|
||||
end,
|
||||
Items1 = case {LFrom, LSFrom} of
|
||||
{LTo, LSTo} -> get_user_resources(To);
|
||||
_ -> []
|
||||
Items1 = case is_presence_subscribed(From, To) of
|
||||
true ->
|
||||
get_user_resources(To);
|
||||
_ ->
|
||||
[]
|
||||
end,
|
||||
{result, Items ++ Items1};
|
||||
|
||||
@ -324,6 +347,8 @@ get_sm_items(empty, From, To, _Node, _Lang) ->
|
||||
|
||||
process_sm_iq_info(From, To, #iq{type = get, payload = SubEl,
|
||||
lang = Lang} = IQ_Rec) ->
|
||||
case is_presence_subscribed(From, To) of
|
||||
true ->
|
||||
Node = exmpp_xml:get_attribute_as_binary(SubEl, 'node', <<>>),
|
||||
Identity = ejabberd_hooks:run_fold(disco_sm_identity,
|
||||
exmpp_jid:prep_domain(To),
|
||||
@ -346,13 +371,26 @@ process_sm_iq_info(From, To, #iq{type = get, payload = SubEl,
|
||||
{error, Error} ->
|
||||
exmpp_iq:error(IQ_Rec, Error)
|
||||
end;
|
||||
false ->
|
||||
exmpp_iq:error(IQ_Rec, 'service-unavailable')
|
||||
end;
|
||||
|
||||
process_sm_iq_info(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||
|
||||
get_sm_identity(Acc, _From, _To, _Node, _Lang) ->
|
||||
Acc.
|
||||
get_sm_identity(Acc, _From, To, _Node, _Lang) ->
|
||||
LUser = exmpp_jid:prep_node_as_list(To),
|
||||
LServer = exmpp_jid:prep_domain_as_list(To),
|
||||
Acc ++ case ejabberd_auth:is_user_exists(LUser, LServer) of
|
||||
true ->
|
||||
[{xmlelement, "identity", [{"category", "account"},
|
||||
{"type", "registered"}], []}];
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
get_sm_features(empty, From, To, _Node, _Lang) ->
|
||||
?DEBUG("DISCO: ~p~n", [empty]),
|
||||
LFrom = exmpp_jid:prep_node_as_list(From),
|
||||
LSFrom = exmpp_jid:prep_domain_as_list(From),
|
||||
LTo = exmpp_jid:prep_node_as_list(To),
|
||||
@ -365,6 +403,7 @@ get_sm_features(empty, From, To, _Node, _Lang) ->
|
||||
end;
|
||||
|
||||
get_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
||||
?DEBUG("DISCO: ~p~n", [Acc]),
|
||||
Acc.
|
||||
|
||||
get_user_resources(JID) ->
|
||||
|
@ -170,7 +170,7 @@ stop(Host) ->
|
||||
exit(whereis(Proc), stop),
|
||||
{wait, Proc}.
|
||||
|
||||
get_sm_features(Acc, _From, _To, "", _Lang) ->
|
||||
get_sm_features(Acc, _From, _To, <<>>, _Lang) ->
|
||||
Feats = case Acc of
|
||||
{result, I} -> I;
|
||||
_ -> []
|
||||
@ -181,7 +181,7 @@ get_sm_features(_Acc, _From, _To, ?NS_MSGOFFLINE, _Lang) ->
|
||||
%% override all lesser features...
|
||||
{result, []};
|
||||
|
||||
get_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
||||
get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
||||
Acc.
|
||||
|
||||
|
||||
|
@ -140,7 +140,7 @@ get_sm_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
|
||||
|
||||
get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
||||
case Node of
|
||||
[] ->
|
||||
<<>> ->
|
||||
case Acc of
|
||||
{result, Features} ->
|
||||
{result, [?NS_DISCO_INFO_s, ?NS_VCARD_s | Features]};
|
||||
|
Loading…
Reference in New Issue
Block a user