mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +01:00
Forward IQ vCard queries of room occupants to bare JID, not full (EJAB-1045)
SVN Revision: 2770
This commit is contained in:
parent
f7b5afec51
commit
3173d9167f
@ -484,9 +484,10 @@ normal_state({route, From, ToNick,
|
|||||||
#xmlel{name = 'iq'} = Packet},
|
#xmlel{name = 'iq'} = Packet},
|
||||||
StateData) ->
|
StateData) ->
|
||||||
Lang = exmpp_stanza:get_lang(Packet),
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
|
StanzaId = get_stanza_id(Packet),
|
||||||
case {(StateData#state.config)#config.allow_query_users,
|
case {(StateData#state.config)#config.allow_query_users,
|
||||||
is_user_online(From, StateData)} of
|
is_user_online_iq(StanzaId, From, StateData)} of
|
||||||
{true, true} ->
|
{true, {true, NewId, FromFull}} ->
|
||||||
case find_jid_by_nick(ToNick, StateData) of
|
case find_jid_by_nick(ToNick, StateData) of
|
||||||
false ->
|
false ->
|
||||||
case exmpp_iq:get_type(Packet) of
|
case exmpp_iq:get_type(Packet) of
|
||||||
@ -506,13 +507,15 @@ normal_state({route, From, ToNick,
|
|||||||
end;
|
end;
|
||||||
ToJID ->
|
ToJID ->
|
||||||
{ok, #user{nick = FromNick}} =
|
{ok, #user{nick = FromNick}} =
|
||||||
?DICT:find(jlib:short_prepd_jid(From),
|
?DICT:find(jlib:short_prepd_jid(FromFull),
|
||||||
StateData#state.users),
|
StateData#state.users),
|
||||||
|
{ToJID2, Packet2} = handle_iq_vcard(FromFull, ToJID,
|
||||||
|
StanzaId, NewId,Packet),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
jid_replace_resource(StateData#state.jid, FromNick),
|
jid_replace_resource(StateData#state.jid, FromNick),
|
||||||
ToJID, Packet)
|
ToJID2, Packet2)
|
||||||
end;
|
end;
|
||||||
{_, false} ->
|
{_, {false, _, _}} ->
|
||||||
case exmpp_iq:get_type(Packet) of
|
case exmpp_iq:get_type(Packet) of
|
||||||
result ->
|
result ->
|
||||||
ok;
|
ok;
|
||||||
@ -856,7 +859,6 @@ process_groupchat_message(From, #xmlel{name = 'message'} = Packet,
|
|||||||
{next_state, normal_state, StateData}
|
{next_state, normal_state, StateData}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
%% @doc Check if this non participant can send message to room.
|
%% @doc Check if this non participant can send message to room.
|
||||||
%%
|
%%
|
||||||
%% XEP-0045 v1.23:
|
%% XEP-0045 v1.23:
|
||||||
@ -996,6 +998,59 @@ is_user_online(JID, StateData) ->
|
|||||||
LJID = jlib:short_prepd_jid(JID),
|
LJID = jlib:short_prepd_jid(JID),
|
||||||
?DICT:is_key(LJID, StateData#state.users).
|
?DICT:is_key(LJID, StateData#state.users).
|
||||||
|
|
||||||
|
%%%
|
||||||
|
%%% Handle IQ queries of vCard
|
||||||
|
%%%
|
||||||
|
get_stanza_id(Packet) ->
|
||||||
|
case exmpp_stanza:get_id(Packet) of
|
||||||
|
Id when is_binary(Id) -> binary_to_list(Id);
|
||||||
|
undefined -> ""
|
||||||
|
end.
|
||||||
|
|
||||||
|
is_user_online_iq(StanzaId, JID, StateData) ->
|
||||||
|
case exmpp_jid:resource(JID) of
|
||||||
|
undefined -> is_user_online_iq2(StanzaId, JID, StateData);
|
||||||
|
_ -> {is_user_online(JID, StateData), StanzaId, JID}
|
||||||
|
end.
|
||||||
|
|
||||||
|
is_user_online_iq2(StanzaId, JID, StateData) ->
|
||||||
|
try stanzaid_unpack(StanzaId) of
|
||||||
|
{OriginalId, Resource} ->
|
||||||
|
JIDWithResource = jid_replace_resource(JID, Resource),
|
||||||
|
{is_user_online(JIDWithResource, StateData),
|
||||||
|
OriginalId, JIDWithResource}
|
||||||
|
catch
|
||||||
|
_:_ ->
|
||||||
|
{is_user_online(JID, StateData), StanzaId, JID}
|
||||||
|
end.
|
||||||
|
|
||||||
|
handle_iq_vcard(FromFull, ToJID, StanzaId, NewId, Packet) ->
|
||||||
|
ToBareJID = exmpp_jid:bare(ToJID),
|
||||||
|
IsToJIDBare = exmpp_jid:full_compare(ToJID, ToBareJID),
|
||||||
|
IQ = exmpp_iq:xmlel_to_iq(Packet),
|
||||||
|
handle_iq_vcard2(FromFull, ToJID, ToBareJID, IsToJIDBare, StanzaId, NewId, IQ, Packet).
|
||||||
|
handle_iq_vcard2(_FromFull, ToJID, ToBareJID, IsToJIDBare, StanzaId, _NewId,
|
||||||
|
#iq{type = get, ns = ?NS_VCARD}, Packet)
|
||||||
|
when IsToJIDBare == false ->
|
||||||
|
{ToBareJID, change_stanzaid(StanzaId, ToJID, Packet)};
|
||||||
|
handle_iq_vcard2(_FromFull, ToJID, _ToBareJID, _IsToJIDBare, _StanzaId, NewId, _IQ, Packet) ->
|
||||||
|
{ToJID, change_stanzaid(NewId, Packet)}.
|
||||||
|
|
||||||
|
stanzaid_pack(OriginalId, Resource) ->
|
||||||
|
"berd"++base64:encode_to_string("ejab\0" ++ OriginalId ++ "\0" ++ Resource).
|
||||||
|
stanzaid_unpack("berd"++StanzaIdBase64) ->
|
||||||
|
StanzaId = base64:decode_to_string(StanzaIdBase64),
|
||||||
|
["ejab", OriginalId, Resource] = string:tokens(StanzaId, "\0"),
|
||||||
|
{OriginalId, Resource}.
|
||||||
|
|
||||||
|
change_stanzaid(NewId, Packet) ->
|
||||||
|
exmpp_stanza:set_id(Packet, NewId).
|
||||||
|
change_stanzaid(PreviousId, ToJID, Packet) ->
|
||||||
|
NewId = stanzaid_pack(PreviousId, exmpp_jid:resource_as_list(ToJID)),
|
||||||
|
change_stanzaid(NewId, Packet).
|
||||||
|
%%%
|
||||||
|
%%%
|
||||||
|
|
||||||
role_to_binary(Role) ->
|
role_to_binary(Role) ->
|
||||||
case Role of
|
case Role of
|
||||||
moderator -> <<"moderator">>;
|
moderator -> <<"moderator">>;
|
||||||
|
Loading…
Reference in New Issue
Block a user