25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Fixed Bugs handling Service Discovery to contacts.

Resolves [#EJAB-1207]
This commit is contained in:
Emilio Bustos 2010-04-22 10:29:20 -03:00
parent 2ff291899d
commit 55dbdf5dba

View File

@ -263,6 +263,8 @@ process_sm_iq_items(From, To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ
set -> set ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
get -> get ->
case is_presence_subscribed(From, To) of
true ->
Host = To#jid.lserver, Host = To#jid.lserver,
Node = xml:get_tag_attr_s("node", SubEl), Node = xml:get_tag_attr_s("node", SubEl),
case ejabberd_hooks:run_fold(disco_sm_items, case ejabberd_hooks:run_fold(disco_sm_items,
@ -281,23 +283,27 @@ process_sm_iq_items(From, To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ
}]}; }]};
{error, Error} -> {error, Error} ->
IQ#iq{type = error, sub_el = [SubEl, Error]} IQ#iq{type = error, sub_el = [SubEl, Error]}
end;
false ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]}
end end
end. end.
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, get_sm_items(Acc, From,
#jid{luser = LFrom, lserver = LSFrom}, #jid{user = User, server = Server} = To,
#jid{user = User, server = Server, luser = LTo, lserver = LSTo} = _To,
[], _Lang) -> [], _Lang) ->
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(User, Server); true ->
_ -> [] get_user_resources(User, Server);
_ ->
[]
end, end,
{result, Items ++ Items1}; {result, Items ++ Items1};
@ -314,11 +320,25 @@ get_sm_items(empty, From, To, _Node, _Lang) ->
{error, ?ERR_NOT_ALLOWED} {error, ?ERR_NOT_ALLOWED}
end. end.
is_presence_subscribed(#jid{luser=User, lserver=Server}, #jid{luser=LUser, lserver=LServer}) ->
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.
process_sm_iq_info(From, To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) -> process_sm_iq_info(From, To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
case Type of case Type of
set -> set ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
get -> get ->
case is_presence_subscribed(From, To) of
true ->
Host = To#jid.lserver, Host = To#jid.lserver,
Node = xml:get_tag_attr_s("node", SubEl), Node = xml:get_tag_attr_s("node", SubEl),
Identity = ejabberd_hooks:run_fold(disco_sm_identity, Identity = ejabberd_hooks:run_fold(disco_sm_identity,
@ -342,11 +362,21 @@ process_sm_iq_info(From, To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ)
}]}; }]};
{error, Error} -> {error, Error} ->
IQ#iq{type = error, sub_el = [SubEl, Error]} IQ#iq{type = error, sub_el = [SubEl, Error]}
end;
false ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]}
end end
end. end.
get_sm_identity(Acc, _From, _To, _Node, _Lang) -> get_sm_identity(Acc, _From, #jid{luser = LUser, lserver=LServer}, _Node, _Lang) ->
Acc. 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) ->
#jid{luser = LFrom, lserver = LSFrom} = From, #jid{luser = LFrom, lserver = LSFrom} = From,