25
1
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:
Emilio Bustos 2010-04-29 00:38:25 -03:00
parent f01dd3e942
commit 4548f2faf0
3 changed files with 75 additions and 36 deletions

View File

@ -279,8 +279,17 @@ process_sm_iq_items(From, To, #iq{type = get, payload = SubEl,
<<>> -> []; <<>> -> [];
_ -> [?XMLATTR('node', Node)] _ -> [?XMLATTR('node', Node)]
end, 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', Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query',
attrs = ANode, children = Items}, attrs = ANode, children = AItems},
exmpp_iq:result(IQ_Rec, Result); exmpp_iq:result(IQ_Rec, Result);
{error, Error} -> {error, Error} ->
exmpp_iq:error(IQ_Rec, 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) -> process_sm_iq_items(_From, _To, #iq{type = set, payload = _SubEl} = IQ_Rec) ->
exmpp_iq:error(IQ_Rec, 'not-allowed'). 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) -> get_sm_items({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
Acc; Acc;
get_sm_items(Acc, From, To, <<>>, _Lang) -> 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 Items = case Acc of
{result, Its} -> Its; {result, Its} -> Its;
empty -> [] empty -> []
end, end,
Items1 = case {LFrom, LSFrom} of Items1 = case is_presence_subscribed(From, To) of
{LTo, LSTo} -> get_user_resources(To); true ->
_ -> [] get_user_resources(To);
_ ->
[]
end, end,
{result, Items ++ Items1}; {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, process_sm_iq_info(From, To, #iq{type = get, payload = SubEl,
lang = Lang} = IQ_Rec) -> lang = Lang} = IQ_Rec) ->
case is_presence_subscribed(From, To) of
true ->
Node = exmpp_xml:get_attribute_as_binary(SubEl, 'node', <<>>), Node = exmpp_xml:get_attribute_as_binary(SubEl, 'node', <<>>),
Identity = ejabberd_hooks:run_fold(disco_sm_identity, Identity = ejabberd_hooks:run_fold(disco_sm_identity,
exmpp_jid:prep_domain(To), exmpp_jid:prep_domain(To),
@ -346,13 +371,26 @@ process_sm_iq_info(From, To, #iq{type = get, payload = SubEl,
{error, Error} -> {error, Error} ->
exmpp_iq:error(IQ_Rec, Error) exmpp_iq:error(IQ_Rec, Error)
end; end;
false ->
exmpp_iq:error(IQ_Rec, 'service-unavailable')
end;
process_sm_iq_info(_From, _To, #iq{type = set} = IQ_Rec) -> process_sm_iq_info(_From, _To, #iq{type = set} = IQ_Rec) ->
exmpp_iq:error(IQ_Rec, 'not-allowed'). exmpp_iq:error(IQ_Rec, 'not-allowed').
get_sm_identity(Acc, _From, _To, _Node, _Lang) -> get_sm_identity(Acc, _From, To, _Node, _Lang) ->
Acc. 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) -> get_sm_features(empty, From, To, _Node, _Lang) ->
?DEBUG("DISCO: ~p~n", [empty]),
LFrom = exmpp_jid:prep_node_as_list(From), LFrom = exmpp_jid:prep_node_as_list(From),
LSFrom = exmpp_jid:prep_domain_as_list(From), LSFrom = exmpp_jid:prep_domain_as_list(From),
LTo = exmpp_jid:prep_node_as_list(To), LTo = exmpp_jid:prep_node_as_list(To),
@ -365,6 +403,7 @@ get_sm_features(empty, From, To, _Node, _Lang) ->
end; end;
get_sm_features(Acc, _From, _To, _Node, _Lang) -> get_sm_features(Acc, _From, _To, _Node, _Lang) ->
?DEBUG("DISCO: ~p~n", [Acc]),
Acc. Acc.
get_user_resources(JID) -> get_user_resources(JID) ->

View File

@ -170,7 +170,7 @@ stop(Host) ->
exit(whereis(Proc), stop), exit(whereis(Proc), stop),
{wait, Proc}. {wait, Proc}.
get_sm_features(Acc, _From, _To, "", _Lang) -> get_sm_features(Acc, _From, _To, <<>>, _Lang) ->
Feats = case Acc of Feats = case Acc of
{result, I} -> I; {result, I} -> I;
_ -> [] _ -> []
@ -181,7 +181,7 @@ get_sm_features(_Acc, _From, _To, ?NS_MSGOFFLINE, _Lang) ->
%% override all lesser features... %% override all lesser features...
{result, []}; {result, []};
get_sm_features(Acc, _From, _To, _Node, _Lang) -> get_sm_features(Acc, _From, _To, Node, _Lang) ->
Acc. Acc.

View File

@ -140,7 +140,7 @@ get_sm_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
get_sm_features(Acc, _From, _To, Node, _Lang) -> get_sm_features(Acc, _From, _To, Node, _Lang) ->
case Node of case Node of
[] -> <<>> ->
case Acc of case Acc of
{result, Features} -> {result, Features} ->
{result, [?NS_DISCO_INFO_s, ?NS_VCARD_s | Features]}; {result, [?NS_DISCO_INFO_s, ?NS_VCARD_s | Features]};