From b3bf437dd163515aeb8f6de317289deee82a1ea1 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Thu, 10 Jan 2008 15:02:54 +0000 Subject: [PATCH] Send last published PEP event now checks the correct peer caps (EJAB-491) SVN Revision: 1143 --- ChangeLog | 8 ++++++++ src/ejabberd_c2s.erl | 6 +++++- src/mod_pubsub/mod_pubsub.erl | 17 +++++++++-------- src/mod_pubsub/nodetree_default.erl | 12 ++++++------ 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index db6df403a..4d893eea3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-01-10 Christophe Romain + + * src/mod_pubsub/nodetree_default: Force PEP parent node to be [] + + * src/mod_pubsub/mod_pubsub.erl: Send last published PEP event now checks + the correct peer caps (EJAB-491) + * src/ejabberd_c2s.erl: Likewise + 2008-01-09 Badlop * src/mod_muc/mod_muc_room.erl: MUC kicks a participant if sends a diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 7d1561c41..c491b5717 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -1403,7 +1403,11 @@ process_presence_probe(From, To, StateData) -> deny -> ok; allow -> - ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Packet]), + Caps = case ?DICT:find(jlib:jid_tolower(To), StateData#state.pres_available) of + {ok, Value} -> Value; + _ -> mod_caps:read_caps(element(4, Packet)) % This is From=To case, so we can read Caps from Packet + end, + ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Caps]), ejabberd_router:route(To, From, Packet) end; Cond2 -> diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index cc9400df2..e5567dc96 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -396,9 +396,9 @@ disco_sm_items(Acc, _From, To, Node, _Lang) -> %% presence hooks handling functions %% -presence_probe(#jid{lserver = Host} = From, To, Packet) -> +presence_probe(#jid{lserver = Host} = From, To, Caps) -> Proc = gen_mod:get_module_proc(Host, ?PROCNAME), - gen_server:cast(Proc, {presence, From, To, Packet}). + gen_server:cast(Proc, {presence, From, To, Caps}). %% ------- %% user remove hook handling function @@ -437,9 +437,9 @@ handle_call(stop, _From, State) -> %% Description: Handling cast messages %%-------------------------------------------------------------------- %% @private -handle_cast({presence, From, To, Packet}, State) -> +handle_cast({presence, From, To, Caps}, State) -> %% A new resource is available. send last published items - JID = jlib:jid_tolower(From), + LFrom = jlib:jid_tolower(From), Host = State#state.host, ServerHost = State#state.server_host, if From == To -> @@ -453,7 +453,7 @@ handle_cast({presence, From, To, Packet}, State) -> #pubsub_node{options = Options} -> case get_option(Options, send_last_published_item) of on_sub_and_presence -> - send_last_item(Host, Node, JID); + send_last_item(Host, Node, LFrom); _ -> ok end; @@ -468,8 +468,8 @@ handle_cast({presence, From, To, Packet}, State) -> ok end, %% and send to From last PEP events published by To + ?DEBUG("got presence probe from ~s to ~s",[jlib:jid_to_string(From),jlib:jid_to_string(To)]), PepKey = jlib:jid_tolower(jlib:jid_remove_resource(To)), - Caps = mod_caps:read_caps(element(4, Packet)), lists:foreach(fun(#pubsub_node{nodeid = {_, Node}, options = Options}) -> case get_option(Options, send_last_published_item) of on_sub_and_presence -> @@ -482,10 +482,11 @@ handle_cast({presence, From, To, Packet}, State) -> authorize -> false; % likewise roster -> Grps = get_option(Options, roster_groups_allowed), - element(2, get_roster_info(To#jid.luser, To#jid.lserver, JID, Grps)) + element(2, get_roster_info(To#jid.luser, To#jid.lserver, LFrom, Grps)) end, if Subscribed -> - send_last_item(PepKey, Node, JID); + ?DEBUG("send ~s's ~s event to ~s",[jlib:jid_to_string(PepKey),Node,jlib:jid_to_string(From)]), + send_last_item(PepKey, Node, LFrom); true -> ok end; diff --git a/src/mod_pubsub/nodetree_default.erl b/src/mod_pubsub/nodetree_default.erl index abbf8d44b..a7360bc21 100644 --- a/src/mod_pubsub/nodetree_default.erl +++ b/src/mod_pubsub/nodetree_default.erl @@ -136,18 +136,18 @@ create_node(Key, Node, Type, Owner, Options) -> OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), case mnesia:read({pubsub_node, {Key, Node}}) of [] -> - Parent = lists:sublist(Node, length(Node) - 1), - ParentExists = + {ParentNode, ParentExists} = case Key of {_U, _S, _R} -> %% This is special case for PEP handling %% PEP does not uses hierarchy - true; + {[], true}; _ -> + Parent = lists:sublist(Node, length(Node) - 1), (Parent == []) orelse case mnesia:read({pubsub_node, {Key, Parent}}) of - [] -> false; - _ -> true + [] -> {Parent, false}; + _ -> {Parent, true} end end, case ParentExists of @@ -155,7 +155,7 @@ create_node(Key, Node, Type, Owner, Options) -> %% Service requires registration %%{error, ?ERR_REGISTRATION_REQUIRED}; mnesia:write(#pubsub_node{nodeid = {Key, Node}, - parentid = {Key, Parent}, + parentid = {Key, ParentNode}, type = Type, owners = [OwnerKey], options = Options});