From e5373de2b9d580d84f543aa53777f89d100e9012 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Tue, 12 Jan 2010 15:14:47 +0000 Subject: [PATCH] avoid calling gen_server on internal events (EJAB-1156) SVN Revision: 2886 --- src/mod_pubsub/mod_pubsub.erl | 144 ++++++++++++----------------- src/mod_pubsub/mod_pubsub_odbc.erl | 144 ++++++++++++----------------- src/mod_pubsub/pubsub_odbc.patch | 102 ++++++++++---------- 3 files changed, 171 insertions(+), 219 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 56dcf3e33..70d2bac50 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -122,6 +122,7 @@ ]). -define(PROCNAME, ejabberd_mod_pubsub). +-define(LOOPNAME, ejabberd_mod_pubsub_loop). -define(PLUGIN_PREFIX, "node_"). -define(TREE_PREFIX, "nodetree_"). @@ -194,6 +195,7 @@ init([ServerHost, Opts]) -> ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}), + ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}), ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75), ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75), ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75), @@ -227,7 +229,8 @@ init([ServerHost, Opts]) -> max_items_node = MaxItemsNode, nodetree = NodeTree, plugins = Plugins}, - SendLoop = spawn(?MODULE, send_loop, [State]), + SendLoop = spawn(?MODULE, send_loop, [State]), %% TODO put this in supervision + register(gen_mod:get_module_proc(ServerHost, ?LOOPNAME), SendLoop), {ok, State#state{send_loop = SendLoop}}. %% @spec (Host, ServerHost, Opts) -> Plugins @@ -470,18 +473,6 @@ update_state_database(_Host, _ServerHost) -> ok end. -send_queue(State, Msg) -> - Pid = State#state.send_loop, - case is_process_alive(Pid) of - true -> - Pid ! Msg, - State; - false -> - SendLoop = spawn(?MODULE, send_loop, [State]), - SendLoop ! Msg, - State#state{send_loop = SendLoop} - end. - send_loop(State) -> receive {presence, JID, Pid} -> @@ -717,18 +708,20 @@ 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(Server, {presence, JID, Pid}), + presence(Server, {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}). + presence(Host, {presence, User, Server, [Resource], JID}). + +presence(ServerHost, Presence) -> + Proc = gen_mod:get_module_proc(ServerHost, ?LOOPNAME), + Proc ! Presence. %% ------- %% subscription hooks handling functions @@ -741,17 +734,39 @@ out_subscription(User, Server, JID, subscribed) -> [] -> user_resources(PUser, PServer); _ -> [PResource] end, - Proc = gen_mod:get_module_proc(Server, ?PROCNAME), - gen_server:cast(Proc, {presence, PUser, PServer, PResources, Owner}); + presence(Server, {presence, PUser, PServer, PResources, Owner}); out_subscription(_,_,_,_) -> ok. in_subscription(_, User, Server, Owner, unsubscribed, _) -> - Subscriber = jlib:make_jid(User, Server, ""), - Proc = gen_mod:get_module_proc(Server, ?PROCNAME), - gen_server:cast(Proc, {unsubscribe, Subscriber, Owner}); + unsubscribe_user(jlib:make_jid(User, Server, ""), Owner); in_subscription(_, _, _, _, _, _) -> ok. +unsubscribe_user(Entity, Owner) -> + BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), + Host = host(element(2, BJID)), + spawn(fun() -> + lists:foreach(fun(PType) -> + {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), + lists:foreach(fun + ({#pubsub_node{options = Options, owners = Owners, id = NodeId}, subscribed, _, JID}) -> + case get_option(Options, access_model) of + presence -> + case lists:member(BJID, Owners) of + true -> + node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]); + false -> + {result, ok} + end; + _ -> + {result, ok} + end; + (_) -> + ok + end, Subscriptions) + end, plugins(Host)) + end). + %% ------- %% user remove hook handling function %% @@ -759,8 +774,22 @@ in_subscription(_, _, _, _, _, _) -> remove_user(User, Server) -> LUser = jlib:nodeprep(User), LServer = jlib:nameprep(Server), - Proc = gen_mod:get_module_proc(Server, ?PROCNAME), - gen_server:cast(Proc, {remove_user, LUser, LServer}). + Entity = jlib:make_jid(LUser, LServer, ""), + Host = host(LServer), + spawn(fun() -> + lists:foreach(fun(PType) -> + {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), + lists:foreach(fun + ({#pubsub_node{id = NodeId}, subscribed, _, JID}) -> node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]); + (_) -> ok + end, Subscriptions), + {result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Entity]), + lists:foreach(fun + ({#pubsub_node{nodeid = {H, N}}, owner}) -> delete_node(H, N, Entity); + ({#pubsub_node{id = NodeId}, _}) -> node_action(Host, PType, set_affiliation, [NodeId, Entity, none]) + end, Affiliations) + end, plugins(Host)) + end). %%-------------------------------------------------------------------- %% Function: @@ -791,65 +820,6 @@ handle_call(stop, _From, State) -> %% Description: Handling cast messages %%-------------------------------------------------------------------- %% @private -handle_cast({presence, JID, Pid}, State) -> - %% A new resource is available. send last published items - {noreply, send_queue(State, {presence, JID, Pid})}; - -handle_cast({presence, User, Server, Resources, JID}, State) -> - %% A new resource is available. send last published PEP items - {noreply, send_queue(State, {presence, User, Server, Resources, JID})}; - -handle_cast({remove_user, LUser, LServer}, State) -> - spawn(fun() -> - Host = State#state.host, - Owner = jlib:make_jid(LUser, LServer, ""), - %% remove user's subscriptions - lists:foreach(fun(PType) -> - {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Owner]), - lists:foreach(fun - ({#pubsub_node{nodeid = {H, N}}, subscribed, _, JID}) -> - unsubscribe_node(H, N, Owner, JID, all); - (_) -> - ok - end, Subscriptions), - {result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Owner]), - lists:foreach(fun - ({#pubsub_node{nodeid = {H, N}}, owner}) -> - delete_node(H, N, Owner); - (_) -> - ok - end, Affiliations) - end, State#state.plugins) - end), - {noreply, State}; - -handle_cast({unsubscribe, Subscriber, Owner}, State) -> - spawn(fun() -> - Host = State#state.host, - BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - lists:foreach(fun(PType) -> - {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), - lists:foreach(fun - ({Node, subscribed, _, JID}) -> - #pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId} = Node, - case get_option(Options, access_model) of - presence -> - case lists:member(BJID, Owners) of - true -> - node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); - false -> - {result, ok} - end; - _ -> - {result, ok} - end; - (_) -> - ok - end, Subscriptions) - end, State#state.plugins) - end), - {noreply, State}; - handle_cast(_Msg, State) -> {noreply, State}. @@ -3580,6 +3550,12 @@ get_cached_item(Host, NodeId) -> %%%% plugin handling +host(ServerHost) -> + case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), host) of + [{host, Host}] -> Host; + _ -> "pubsub."++ServerHost + end. + plugins(Host) -> case catch ets:lookup(gen_mod:get_module_proc(Host, config), plugins) of [{plugins, []}] -> [?STDNODE]; diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index 7d13bded3..340b965b4 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -122,6 +122,7 @@ ]). -define(PROCNAME, ejabberd_mod_pubsub_odbc). +-define(LOOPNAME, ejabberd_mod_pubsub_loop). -define(PLUGIN_PREFIX, "node_"). -define(TREE_PREFIX, "nodetree_"). @@ -194,6 +195,7 @@ init([ServerHost, Opts]) -> ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}), + ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}), ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75), ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75), ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75), @@ -225,7 +227,8 @@ init([ServerHost, Opts]) -> max_items_node = MaxItemsNode, nodetree = NodeTree, plugins = Plugins}, - SendLoop = spawn(?MODULE, send_loop, [State]), + SendLoop = spawn(?MODULE, send_loop, [State]), %% TODO put this in supervision + register(gen_mod:get_module_proc(ServerHost, ?LOOPNAME), SendLoop), {ok, State#state{send_loop = SendLoop}}. %% @spec (Host, ServerHost, Opts) -> Plugins @@ -275,18 +278,6 @@ init_nodes(Host, ServerHost, _NodeTree, Plugins) -> ok end. -send_queue(State, Msg) -> - Pid = State#state.send_loop, - case is_process_alive(Pid) of - true -> - Pid ! Msg, - State; - false -> - SendLoop = spawn(?MODULE, send_loop, [State]), - SendLoop ! Msg, - State#state{send_loop = SendLoop} - end. - send_loop(State) -> receive {presence, JID, Pid} -> @@ -520,18 +511,20 @@ 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(Server, {presence, JID, Pid}), + presence(Server, {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}). + presence(Host, {presence, User, Server, [Resource], JID}). + +presence(ServerHost, Presence) -> + Proc = gen_mod:get_module_proc(ServerHost, ?LOOPNAME), + Proc ! Presence. %% ------- %% subscription hooks handling functions @@ -544,17 +537,39 @@ out_subscription(User, Server, JID, subscribed) -> [] -> user_resources(PUser, PServer); _ -> [PResource] end, - Proc = gen_mod:get_module_proc(Server, ?PROCNAME), - gen_server:cast(Proc, {presence, PUser, PServer, PResources, Owner}); + presence(Server, {presence, PUser, PServer, PResources, Owner}); out_subscription(_,_,_,_) -> ok. in_subscription(_, User, Server, Owner, unsubscribed, _) -> - Subscriber = jlib:make_jid(User, Server, ""), - Proc = gen_mod:get_module_proc(Server, ?PROCNAME), - gen_server:cast(Proc, {unsubscribe, Subscriber, Owner}); + unsubscribe_user(jlib:make_jid(User, Server, ""), Owner); in_subscription(_, _, _, _, _, _) -> ok. +unsubscribe_user(Entity, Owner) -> + BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), + Host = host(element(2, BJID)), + spawn(fun() -> + lists:foreach(fun(PType) -> + {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), + lists:foreach(fun + ({#pubsub_node{options = Options, id = NodeId}, subscribed, _, JID}) -> + case get_option(Options, access_model) of + presence -> + case lists:member(BJID, node_owners(Host, PType, NodeId)) of + true -> + node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]); + false -> + {result, ok} + end; + _ -> + {result, ok} + end; + (_) -> + ok + end, Subscriptions) + end, plugins(Host)) + end). + %% ------- %% user remove hook handling function %% @@ -562,8 +577,22 @@ in_subscription(_, _, _, _, _, _) -> remove_user(User, Server) -> LUser = jlib:nodeprep(User), LServer = jlib:nameprep(Server), - Proc = gen_mod:get_module_proc(Server, ?PROCNAME), - gen_server:cast(Proc, {remove_user, LUser, LServer}). + Entity = jlib:make_jid(LUser, LServer, ""), + Host = host(LServer), + spawn(fun() -> + lists:foreach(fun(PType) -> + {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), + lists:foreach(fun + ({#pubsub_node{id = NodeId}, subscribed, _, JID}) -> node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]); + (_) -> ok + end, Subscriptions), + {result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Entity]), + lists:foreach(fun + ({#pubsub_node{nodeid = {H, N}}, owner}) -> delete_node(H, N, Entity); + ({#pubsub_node{id = NodeId}, _}) -> node_action(Host, PType, set_affiliation, [NodeId, Entity, none]) + end, Affiliations) + end, plugins(Host)) + end). %%-------------------------------------------------------------------- %% Function: @@ -594,65 +623,6 @@ handle_call(stop, _From, State) -> %% Description: Handling cast messages %%-------------------------------------------------------------------- %% @private -handle_cast({presence, JID, Pid}, State) -> - %% A new resource is available. send last published items - {noreply, send_queue(State, {presence, JID, Pid})}; - -handle_cast({presence, User, Server, Resources, JID}, State) -> - %% A new resource is available. send last published PEP items - {noreply, send_queue(State, {presence, User, Server, Resources, JID})}; - -handle_cast({remove_user, LUser, LServer}, State) -> - spawn(fun() -> - Host = State#state.host, - Owner = jlib:make_jid(LUser, LServer, ""), - %% remove user's subscriptions - lists:foreach(fun(PType) -> - {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Owner]), - lists:foreach(fun - ({#pubsub_node{nodeid = {H, N}}, subscribed, _, JID}) -> - unsubscribe_node(H, N, Owner, JID, all); - (_) -> - ok - end, Subscriptions), - {result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Owner]), - lists:foreach(fun - ({#pubsub_node{nodeid = {H, N}}, owner}) -> - delete_node(H, N, Owner); - (_) -> - ok - end, Affiliations) - end, State#state.plugins) - end), - {noreply, State}; - -handle_cast({unsubscribe, Subscriber, Owner}, State) -> - spawn(fun() -> - Host = State#state.host, - BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - lists:foreach(fun(PType) -> - {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), - lists:foreach(fun - ({Node, subscribed, _, JID}) -> - #pubsub_node{options = Options, type = Type, id = NodeId} = Node, - case get_option(Options, access_model) of - presence -> - case lists:member(BJID, node_owners(Host, Type, NodeId)) of - true -> - node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); - false -> - {result, ok} - end; - _ -> - {result, ok} - end; - (_) -> - ok - end, Subscriptions) - end, State#state.plugins) - end), - {noreply, State}; - handle_cast(_Msg, State) -> {noreply, State}. @@ -3413,6 +3383,12 @@ get_cached_item(Host, NodeId) -> %%%% plugin handling +host(ServerHost) -> + case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), host) of + [{host, Host}] -> Host; + _ -> "pubsub."++ServerHost + end. + plugins(Host) -> case catch ets:lookup(gen_mod:get_module_proc(Host, config), plugins) of [{plugins, []}] -> [?STDNODE]; diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index 79518b72c..402fa0feb 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2010-01-12 14:25:24.809994066 +0100 -+++ mod_pubsub_odbc.erl 2010-01-12 14:26:04.098050300 +0100 +--- mod_pubsub.erl 2010-01-12 16:09:01.000000000 +0100 ++++ mod_pubsub_odbc.erl 2010-01-12 16:09:09.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. @@ -37,10 +37,10 @@ --define(PROCNAME, ejabberd_mod_pubsub). +-define(PROCNAME, ejabberd_mod_pubsub_odbc). + -define(LOOPNAME, ejabberd_mod_pubsub_loop). -define(PLUGIN_PREFIX, "node_"). -define(TREE_PREFIX, "nodetree_"). - -@@ -215,8 +215,6 @@ +@@ -217,8 +217,6 @@ ok end, ejabberd_router:register_route(Host), @@ -49,7 +49,7 @@ init_nodes(Host, ServerHost, NodeTree, Plugins), State = #state{host = Host, server_host = ServerHost, -@@ -269,207 +267,14 @@ +@@ -272,207 +270,14 @@ init_nodes(Host, ServerHost, _NodeTree, Plugins) -> %% TODO, this call should be done plugin side @@ -257,10 +257,10 @@ - ok - end. - - send_queue(State, Msg) -> - Pid = State#state.send_loop, - case is_process_alive(Pid) of -@@ -492,17 +297,15 @@ + send_loop(State) -> + receive + {presence, JID, Pid} -> +@@ -483,17 +288,15 @@ %% for each node From is subscribed to %% and if the node is so configured, send the last published item to From lists:foreach(fun(PType) -> @@ -284,20 +284,20 @@ true -> % resource not concerned about that subscription ok -@@ -831,10 +634,10 @@ - {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), +@@ -749,10 +552,10 @@ + lists:foreach(fun(PType) -> + {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), lists:foreach(fun - ({Node, subscribed, _, JID}) -> -- #pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId} = Node, -+ #pubsub_node{options = Options, type = Type, id = NodeId} = Node, +- ({#pubsub_node{options = Options, owners = Owners, id = NodeId}, subscribed, _, JID}) -> ++ ({#pubsub_node{options = Options, id = NodeId}, subscribed, _, JID}) -> case get_option(Options, access_model) of presence -> - case lists:member(BJID, Owners) of -+ case lists:member(BJID, node_owners(Host, Type, NodeId)) of ++ case lists:member(BJID, node_owners(Host, PType, NodeId)) of true -> - node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); + node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]); false -> -@@ -949,7 +752,8 @@ +@@ -919,7 +722,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, -@@ -1066,7 +870,7 @@ +@@ -1036,7 +840,7 @@ [] -> ["leaf"]; %% No sub-nodes: it's a leaf node _ -> @@ -316,7 +316,7 @@ {result, []} -> ["collection"]; {result, _} -> ["leaf", "collection"]; _ -> [] -@@ -1082,8 +886,9 @@ +@@ -1052,8 +856,9 @@ []; true -> [{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} | @@ -328,7 +328,7 @@ end, features(Type))] end, %% TODO: add meta-data info (spec section 5.4) -@@ -1112,8 +917,9 @@ +@@ -1082,8 +887,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); -@@ -1123,7 +929,7 @@ +@@ -1093,7 +899,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( -@@ -1135,14 +941,14 @@ +@@ -1105,14 +911,14 @@ Other -> Other end; @@ -367,7 +367,7 @@ case string:tokens(Item, "!") of [_SNode, _ItemID] -> {result, []}; -@@ -1150,10 +956,10 @@ +@@ -1120,10 +926,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}}) -> -@@ -1166,7 +972,7 @@ +@@ -1136,7 +942,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}; -@@ -1295,7 +1101,8 @@ +@@ -1265,7 +1071,8 @@ (_, Acc) -> Acc end, [], xml:remove_cdata(Els)), @@ -400,7 +400,7 @@ {get, "subscriptions"} -> get_subscriptions(Host, Node, From, Plugins); {get, "affiliations"} -> -@@ -1318,7 +1125,9 @@ +@@ -1288,7 +1095,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)), -@@ -1448,7 +1257,8 @@ +@@ -1418,7 +1227,8 @@ _ -> [] end end, @@ -421,7 +421,7 @@ sync_dirty) of {result, Res} -> Res; Err -> Err -@@ -1487,7 +1297,7 @@ +@@ -1457,7 +1267,7 @@ %%% authorization handling @@ -430,7 +430,7 @@ Lang = "en", %% TODO fix Stanza = {xmlelement, "message", [], -@@ -1516,7 +1326,7 @@ +@@ -1486,7 +1296,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, -@@ -1580,8 +1390,8 @@ +@@ -1550,8 +1360,8 @@ "true" -> true; _ -> false end, @@ -450,7 +450,7 @@ {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), if not IsApprover -> -@@ -1772,7 +1582,7 @@ +@@ -1742,7 +1552,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)), -@@ -1880,7 +1690,7 @@ +@@ -1850,7 +1660,7 @@ %%
  • The node does not exist.
  • %% subscribe_node(Host, Node, From, JID, Configuration) -> @@ -468,7 +468,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -1888,7 +1698,7 @@ +@@ -1858,7 +1668,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), -@@ -1907,9 +1717,13 @@ +@@ -1877,9 +1687,13 @@ {"", "", ""} -> {false, false}; _ -> @@ -494,7 +494,7 @@ end end, if -@@ -2240,7 +2054,7 @@ +@@ -2210,7 +2024,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); -@@ -2279,11 +2093,11 @@ +@@ -2249,11 +2063,11 @@ node_call(Type, get_items, [NodeId, From, AccessModel, PresenceSubscription, RosterGroup, @@ -517,7 +517,7 @@ SendItems = case ItemIDs of [] -> Items; -@@ -2296,7 +2110,8 @@ +@@ -2266,7 +2080,8 @@ %% number of items sent to MaxItems: {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "items", nodeAttr(Node), @@ -527,7 +527,7 @@ Error -> Error end -@@ -2328,16 +2143,27 @@ +@@ -2298,16 +2113,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, []} -> -@@ -2463,29 +2289,12 @@ +@@ -2433,29 +2259,12 @@ error -> {error, ?ERR_BAD_REQUEST}; _ -> @@ -594,7 +594,7 @@ end, Entities), {result, []}; _ -> -@@ -2538,11 +2347,11 @@ +@@ -2508,11 +2317,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]}, -@@ -2568,7 +2377,7 @@ +@@ -2538,7 +2347,7 @@ end. set_options_helper(Configuration, JID, NodeID, SubID, Type) -> @@ -617,7 +617,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -2597,7 +2406,7 @@ +@@ -2567,7 +2376,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, _} -> -@@ -2765,8 +2574,8 @@ +@@ -2735,8 +2544,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) -> -@@ -3050,7 +2859,7 @@ +@@ -3020,7 +2829,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. -@@ -3064,9 +2873,9 @@ +@@ -3034,9 +2843,9 @@ get_options_for_subs(NodeID, Subs) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) -> @@ -658,7 +658,7 @@ _ -> Acc end; (_, Acc) -> -@@ -3294,6 +3103,30 @@ +@@ -3264,6 +3073,30 @@ Result end. @@ -689,7 +689,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3680,7 +3513,13 @@ +@@ -3656,7 +3489,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) -> -@@ -3700,13 +3539,13 @@ +@@ -3676,13 +3515,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 -@@ -3719,8 +3558,14 @@ +@@ -3695,8 +3534,14 @@ end end, Trans). @@ -737,7 +737,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3728,6 +3573,15 @@ +@@ -3704,6 +3549,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}; -@@ -3736,6 +3590,17 @@ +@@ -3712,6 +3566,17 @@ {error, ?ERR_INTERNAL_SERVER_ERROR} end.