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:
parent
2ff291899d
commit
55dbdf5dba
@ -263,42 +263,48 @@ 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 ->
|
||||||
Host = To#jid.lserver,
|
case is_presence_subscribed(From, To) of
|
||||||
Node = xml:get_tag_attr_s("node", SubEl),
|
true ->
|
||||||
case ejabberd_hooks:run_fold(disco_sm_items,
|
Host = To#jid.lserver,
|
||||||
Host,
|
Node = xml:get_tag_attr_s("node", SubEl),
|
||||||
empty,
|
case ejabberd_hooks:run_fold(disco_sm_items,
|
||||||
[From, To, Node, Lang]) of
|
Host,
|
||||||
{result, Items} ->
|
empty,
|
||||||
ANode = case Node of
|
[From, To, Node, Lang]) of
|
||||||
"" -> [];
|
{result, Items} ->
|
||||||
_ -> [{"node", Node}]
|
ANode = case Node of
|
||||||
end,
|
"" -> [];
|
||||||
IQ#iq{type = result,
|
_ -> [{"node", Node}]
|
||||||
sub_el = [{xmlelement, "query",
|
end,
|
||||||
[{"xmlns", ?NS_DISCO_ITEMS} | ANode],
|
IQ#iq{type = result,
|
||||||
Items
|
sub_el = [{xmlelement, "query",
|
||||||
}]};
|
[{"xmlns", ?NS_DISCO_ITEMS} | ANode],
|
||||||
{error, Error} ->
|
Items
|
||||||
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
}]};
|
||||||
end
|
{error, Error} ->
|
||||||
|
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
||||||
|
end;
|
||||||
|
false ->
|
||||||
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]}
|
||||||
|
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};
|
||||||
|
|
||||||
get_sm_items({result, _} = Acc, _From, _To, _Node, _Lang) ->
|
get_sm_items({result, _} = Acc, _From, _To, _Node, _Lang) ->
|
||||||
@ -314,39 +320,63 @@ 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 ->
|
||||||
Host = To#jid.lserver,
|
case is_presence_subscribed(From, To) of
|
||||||
Node = xml:get_tag_attr_s("node", SubEl),
|
true ->
|
||||||
Identity = ejabberd_hooks:run_fold(disco_sm_identity,
|
Host = To#jid.lserver,
|
||||||
Host,
|
Node = xml:get_tag_attr_s("node", SubEl),
|
||||||
[],
|
Identity = ejabberd_hooks:run_fold(disco_sm_identity,
|
||||||
[From, To, Node, Lang]),
|
Host,
|
||||||
case ejabberd_hooks:run_fold(disco_sm_features,
|
[],
|
||||||
Host,
|
[From, To, Node, Lang]),
|
||||||
empty,
|
case ejabberd_hooks:run_fold(disco_sm_features,
|
||||||
[From, To, Node, Lang]) of
|
Host,
|
||||||
{result, Features} ->
|
empty,
|
||||||
ANode = case Node of
|
[From, To, Node, Lang]) of
|
||||||
"" -> [];
|
{result, Features} ->
|
||||||
_ -> [{"node", Node}]
|
ANode = case Node of
|
||||||
end,
|
"" -> [];
|
||||||
IQ#iq{type = result,
|
_ -> [{"node", Node}]
|
||||||
sub_el = [{xmlelement, "query",
|
end,
|
||||||
[{"xmlns", ?NS_DISCO_INFO} | ANode],
|
IQ#iq{type = result,
|
||||||
Identity ++
|
sub_el = [{xmlelement, "query",
|
||||||
lists:map(fun feature_to_xml/1, Features)
|
[{"xmlns", ?NS_DISCO_INFO} | ANode],
|
||||||
}]};
|
Identity ++
|
||||||
{error, Error} ->
|
lists:map(fun feature_to_xml/1, Features)
|
||||||
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
}]};
|
||||||
end
|
{error, Error} ->
|
||||||
|
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
||||||
|
end;
|
||||||
|
false ->
|
||||||
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]}
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_sm_identity(Acc, _From, #jid{luser = LUser, lserver=LServer}, _Node, _Lang) ->
|
||||||
|
Acc ++ case ejabberd_auth:is_user_exists(LUser, LServer) of
|
||||||
|
true ->
|
||||||
|
[{xmlelement, "identity", [{"category", "account"},
|
||||||
|
{"type", "registered"}], []}];
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_sm_identity(Acc, _From, _To, _Node, _Lang) ->
|
|
||||||
Acc.
|
|
||||||
|
|
||||||
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user