From 3aa242e2c7f89e44fbe2d16e7fabf2855758ebc3 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Sun, 6 Dec 2009 23:18:17 +0000 Subject: [PATCH] prevent sending duplicated last items if several resources online (EJAB-1116) SVN Revision: 2786 --- src/mod_pubsub/mod_pubsub.erl | 6 +++ src/mod_pubsub/mod_pubsub_odbc.erl | 6 +++ src/mod_pubsub/pubsub_odbc.patch | 76 +++++++++++++++--------------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 0c713dd3d..1e9d72913 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -718,10 +718,16 @@ disco_sm_items(Acc, From, To, SNode, _Lang) -> presence_probe(#jid{luser = User, lserver = Server, lresource = Resource} = JID, JID, Pid) -> Proc = gen_mod:get_module_proc(Server, ?PROCNAME), + %%?DEBUG("presence probe self ~s@~s/~s ~s@~s/~s",[User,Server,Resource,element(2,JID),element(3,JID),element(4,JID)]), gen_server:cast(Proc, {presence, JID, Pid}), gen_server:cast(Proc, {presence, User, Server, [Resource], JID}); +presence_probe(#jid{luser = User, lserver = Server}, #jid{luser = User, lserver = Server}, _Pid) -> + %% ignore presence_probe from other ressources for the current user + %% this way, we do not send duplicated last items if user already connected with other clients + ok; presence_probe(#jid{luser = User, lserver = Server, lresource = Resource}, #jid{lserver = Host} = JID, _Pid) -> Proc = gen_mod:get_module_proc(Host, ?PROCNAME), + %%?DEBUG("presence probe peer ~s@~s/~s ~s@~s/~s",[User,Server,Resource,element(2,JID),element(3,JID),element(4,JID)]), gen_server:cast(Proc, {presence, User, Server, [Resource], JID}). %% ------- diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index bafd7503d..bbc8e7b85 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -521,10 +521,16 @@ disco_sm_items(Acc, From, To, SNode, _Lang) -> presence_probe(#jid{luser = User, lserver = Server, lresource = Resource} = JID, JID, Pid) -> Proc = gen_mod:get_module_proc(Server, ?PROCNAME), + %%?DEBUG("presence probe self ~s@~s/~s ~s@~s/~s",[User,Server,Resource,element(2,JID),element(3,JID),element(4,JID)]), gen_server:cast(Proc, {presence, JID, Pid}), gen_server:cast(Proc, {presence, User, Server, [Resource], JID}); +presence_probe(#jid{luser = User, lserver = Server}, #jid{luser = User, lserver = Server}, _Pid) -> + %% ignore presence_probe from other ressources for the current user + %% this way, we do not send duplicated last items if user already connected with other clients + ok; presence_probe(#jid{luser = User, lserver = Server, lresource = Resource}, #jid{lserver = Host} = JID, _Pid) -> Proc = gen_mod:get_module_proc(Host, ?PROCNAME), + %%?DEBUG("presence probe peer ~s@~s/~s ~s@~s/~s",[User,Server,Resource,element(2,JID),element(3,JID),element(4,JID)]), gen_server:cast(Proc, {presence, User, Server, [Resource], JID}). %% ------- diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index a7847ef37..e4a3f18bc 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2009-11-06 12:01:44.000000000 +0100 -+++ mod_pubsub_odbc.erl 2009-11-06 12:01:53.000000000 +0100 +--- mod_pubsub.erl 2009-12-07 00:17:20.000000000 +0100 ++++ mod_pubsub_odbc.erl 2009-12-07 00:17:59.000000000 +0100 @@ -42,7 +42,7 @@ %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% XEP-0060 section 12.18. @@ -284,7 +284,7 @@ true -> % resource not concerned about that subscription ok -@@ -825,10 +628,10 @@ +@@ -831,10 +634,10 @@ {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), lists:foreach(fun ({Node, subscribed, _, JID}) -> @@ -297,7 +297,7 @@ true -> node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); false -> -@@ -943,7 +746,8 @@ +@@ -949,7 +752,8 @@ sub_el = SubEl} = IQ -> {xmlelement, _, QAttrs, _} = SubEl, Node = xml:get_attr_s("node", QAttrs), @@ -307,7 +307,7 @@ {result, IQRes} -> jlib:iq_to_xml( IQ#iq{type = result, -@@ -1060,7 +864,7 @@ +@@ -1066,7 +870,7 @@ [] -> ["leaf"]; %% No sub-nodes: it's a leaf node _ -> @@ -316,7 +316,7 @@ {result, []} -> ["collection"]; {result, _} -> ["leaf", "collection"]; _ -> [] -@@ -1076,8 +880,9 @@ +@@ -1082,8 +886,9 @@ []; true -> [{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} | @@ -328,7 +328,7 @@ end, features(Type))] end, %% TODO: add meta-data info (spec section 5.4) -@@ -1106,8 +911,9 @@ +@@ -1112,8 +917,9 @@ {xmlelement, "feature", [{"var", ?NS_PUBSUB}], []}, {xmlelement, "feature", [{"var", ?NS_COMMANDS}], []}, {xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++ @@ -340,7 +340,7 @@ end, features(Host, Node))}; <> -> command_disco_info(Host, Node, From); -@@ -1117,7 +923,7 @@ +@@ -1123,7 +929,7 @@ node_disco_info(Host, Node, From) end. @@ -349,7 +349,7 @@ case tree_action(Host, get_subnodes, [Host, <<>>, From]) of Nodes when is_list(Nodes) -> {result, lists:map( -@@ -1129,14 +935,14 @@ +@@ -1135,14 +941,14 @@ Other -> Other end; @@ -367,7 +367,7 @@ case string:tokens(Item, "!") of [_SNode, _ItemID] -> {result, []}; -@@ -1144,10 +950,10 @@ +@@ -1150,10 +956,10 @@ Node = string_to_node(SNode), Action = fun(#pubsub_node{type = Type, id = NodeId}) -> @@ -381,7 +381,7 @@ end, Nodes = lists:map( fun(#pubsub_node{nodeid = {_, SubNode}}) -> -@@ -1160,7 +966,7 @@ +@@ -1166,7 +972,7 @@ {result, Name} = node_call(Type, get_item_name, [Host, Node, RN]), {xmlelement, "item", [{"jid", Host}, {"name", Name}], []} end, NodeItems), @@ -390,7 +390,7 @@ end, case transaction(Host, Node, Action, sync_dirty) of {result, {_, Result}} -> {result, Result}; -@@ -1289,7 +1095,8 @@ +@@ -1295,7 +1101,8 @@ (_, Acc) -> Acc end, [], xml:remove_cdata(Els)), @@ -400,7 +400,7 @@ {get, "subscriptions"} -> get_subscriptions(Host, Node, From, Plugins); {get, "affiliations"} -> -@@ -1312,7 +1119,9 @@ +@@ -1318,7 +1125,9 @@ iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> {xmlelement, _, _, SubEls} = SubEl, @@ -411,7 +411,7 @@ case Action of [{xmlelement, Name, Attrs, Els}] -> Node = string_to_node(xml:get_attr_s("node", Attrs)), -@@ -1442,7 +1251,8 @@ +@@ -1448,7 +1257,8 @@ _ -> [] end end, @@ -421,7 +421,7 @@ sync_dirty) of {result, Res} -> Res; Err -> Err -@@ -1481,7 +1291,7 @@ +@@ -1487,7 +1297,7 @@ %%% authorization handling @@ -430,7 +430,7 @@ Lang = "en", %% TODO fix Stanza = {xmlelement, "message", [], -@@ -1510,7 +1320,7 @@ +@@ -1516,7 +1326,7 @@ [{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]}, lists:foreach(fun(Owner) -> ejabberd_router:route(service_jid(Host), jlib:make_jid(Owner), Stanza) @@ -439,7 +439,7 @@ find_authorization_response(Packet) -> {xmlelement, _Name, _Attrs, Els} = Packet, -@@ -1574,8 +1384,8 @@ +@@ -1580,8 +1390,8 @@ "true" -> true; _ -> false end, @@ -450,7 +450,7 @@ {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), if not IsApprover -> -@@ -1766,7 +1576,7 @@ +@@ -1772,7 +1582,7 @@ Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "create", nodeAttr(Node), []}]}], @@ -459,7 +459,7 @@ {result, {Result, broadcast}} -> %%Lang = "en", %% TODO: fix %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), -@@ -1874,7 +1684,7 @@ +@@ -1880,7 +1690,7 @@ %%
  • The node does not exist.
  • %% subscribe_node(Host, Node, From, JID, Configuration) -> @@ -468,7 +468,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -1882,7 +1692,7 @@ +@@ -1888,7 +1698,7 @@ error -> {"", "", ""}; J -> jlib:jid_tolower(J) end, @@ -477,7 +477,7 @@ Features = features(Type), SubscribeFeature = lists:member("subscribe", Features), OptionsFeature = lists:member("subscription-options", Features), -@@ -1901,9 +1711,13 @@ +@@ -1907,9 +1717,13 @@ {"", "", ""} -> {false, false}; _ -> @@ -494,7 +494,7 @@ end end, if -@@ -2234,7 +2048,7 @@ +@@ -2240,7 +2054,7 @@ %%

    The permission are not checked in this function.

    %% @todo We probably need to check that the user doing the query has the right %% to read the items. @@ -503,7 +503,7 @@ MaxItems = if SMaxItems == "" -> get_max_items_node(Host); -@@ -2273,11 +2087,11 @@ +@@ -2279,11 +2093,11 @@ node_call(Type, get_items, [NodeId, From, AccessModel, PresenceSubscription, RosterGroup, @@ -517,7 +517,7 @@ SendItems = case ItemIDs of [] -> Items; -@@ -2290,7 +2104,8 @@ +@@ -2296,7 +2110,8 @@ %% number of items sent to MaxItems: {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "items", nodeAttr(Node), @@ -527,7 +527,7 @@ Error -> Error end -@@ -2322,16 +2137,27 @@ +@@ -2328,16 +2143,27 @@ %% @doc

    Resend the items of a node to the user.

    %% @todo use cache-last-item feature send_items(Host, Node, NodeId, Type, LJID, last) -> @@ -561,7 +561,7 @@ send_items(Host, Node, NodeId, Type, LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of {result, []} -> -@@ -2457,29 +2283,12 @@ +@@ -2463,29 +2289,12 @@ error -> {error, ?ERR_BAD_REQUEST}; _ -> @@ -594,7 +594,7 @@ end, Entities), {result, []}; _ -> -@@ -2532,11 +2341,11 @@ +@@ -2538,11 +2347,11 @@ end. read_sub(Subscriber, Node, NodeID, SubID, Lang) -> @@ -608,7 +608,7 @@ OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)}, {"subid", SubID}|nodeAttr(Node)], [XdataEl]}, -@@ -2562,7 +2371,7 @@ +@@ -2568,7 +2377,7 @@ end. set_options_helper(Configuration, JID, NodeID, SubID, Type) -> @@ -617,7 +617,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -2591,7 +2400,7 @@ +@@ -2597,7 +2406,7 @@ write_sub(_Subscriber, _NodeID, _SubID, invalid) -> {error, extended_error(?ERR_BAD_REQUEST, "invalid-options")}; write_sub(Subscriber, NodeID, SubID, Options) -> @@ -626,7 +626,7 @@ {error, notfound} -> {error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {result, _} -> -@@ -2759,8 +2568,8 @@ +@@ -2765,8 +2574,8 @@ {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]}, ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza) end, @@ -637,7 +637,7 @@ true -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> -@@ -3044,7 +2853,7 @@ +@@ -3050,7 +2859,7 @@ {Depth, [{N, get_node_subs(N)} || N <- Nodes]} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, @@ -646,7 +646,7 @@ {result, CollSubs} -> CollSubs; _ -> [] end. -@@ -3058,9 +2867,9 @@ +@@ -3064,9 +2873,9 @@ get_options_for_subs(NodeID, Subs) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) -> @@ -658,7 +658,7 @@ _ -> Acc end; (_, Acc) -> -@@ -3258,6 +3067,30 @@ +@@ -3264,6 +3073,30 @@ Result end. @@ -689,7 +689,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3644,7 +3477,13 @@ +@@ -3650,7 +3483,13 @@ tree_action(Host, Function, Args) -> ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), Fun = fun() -> tree_call(Host, Function, Args) end, @@ -704,7 +704,7 @@ %% @doc

    node plugin call.

    node_call(Type, Function, Args) -> -@@ -3664,13 +3503,13 @@ +@@ -3670,13 +3509,13 @@ node_action(Host, Type, Function, Args) -> ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), @@ -720,7 +720,7 @@ case tree_call(Host, get_node, [Host, Node]) of N when is_record(N, pubsub_node) -> case Action(N) of -@@ -3683,8 +3522,14 @@ +@@ -3689,8 +3528,14 @@ end end, Trans). @@ -737,7 +737,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3692,6 +3537,15 @@ +@@ -3698,6 +3543,15 @@ {aborted, Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), {error, ?ERR_INTERNAL_SERVER_ERROR}; @@ -753,7 +753,7 @@ {'EXIT', Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), {error, ?ERR_INTERNAL_SERVER_ERROR}; -@@ -3700,6 +3554,17 @@ +@@ -3706,6 +3560,17 @@ {error, ?ERR_INTERNAL_SERVER_ERROR} end.