diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index cb16e8f75..0580f7592 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2009-10-13 18:39:11.000000000 +0200 -+++ mod_pubsub_odbc.erl 2009-10-13 18:40:32.000000000 +0200 +--- mod_pubsub.erl 2009-10-21 10:28:28.000000000 +0200 ++++ mod_pubsub_odbc.erl 2009-10-21 10:28:28.000000000 +0200 @@ -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. @@ -49,7 +49,18 @@ init_nodes(Host, ServerHost, NodeTree, Plugins), State = #state{host = Host, server_host = ServerHost, -@@ -286,177 +284,7 @@ +@@ -278,206 +276,15 @@ + + init_nodes(Host, ServerHost, _NodeTree, Plugins) -> + %% TODO, this call should be done plugin side +- case lists:member("hometree", Plugins) of ++ case lists:member("hometree_odbc", Plugins) of + true -> +- create_node(Host, ServerHost, string_to_node("/home"), service_jid(Host), "hometree"), +- create_node(Host, ServerHost, string_to_node("/home" ++ ServerHost), service_jid(Host), "hometree"); ++ create_node(Host, ServerHost, string_to_node("/home"), service_jid(Host), "hometree_odbc"), ++ create_node(Host, ServerHost, string_to_node("/home/" ++ ServerHost), service_jid(Host), "hometree_odbc"); + false -> ok end. @@ -179,8 +190,29 @@ - rename_default_nodeplugin(); - _ -> - ok -- end. - +- end, +- mnesia:transaction(fun() -> +- case catch mnesia:first(pubsub_node) of +- {_, L} when is_list(L) -> +- lists:foreach( +- fun({H, N}) when is_list(N) -> +- [Node] = mnesia:read({pubsub_node, {H, N}}), +- Type = Node#pubsub_node.type, +- BN = element(2, node_call(Type, path_to_node, [N])), +- BP = case [element(2, node_call(Type, path_to_node, [P])) || P <- Node#pubsub_node.parents] of +- [<<>>] -> []; +- Parents -> Parents +- end, +- mnesia:write(Node#pubsub_node{nodeid={H, BN}, parents=BP}), +- mnesia:delete({pubsub_node, {H, N}}); +- (_) -> +- ok +- end, mnesia:all_keys(pubsub_node)); +- _ -> +- ok +- end +- end). +- -rename_default_nodeplugin() -> - lists:foreach(fun(Node) -> - mnesia:dirty_write(Node#pubsub_node{type = "hometree"}) @@ -224,10 +256,11 @@ - _ -> - ok - end. ++ send_queue(State, Msg) -> Pid = State#state.send_loop, -@@ -480,17 +308,15 @@ +@@ -501,17 +308,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) -> @@ -251,7 +284,17 @@ true -> % resource not concerned about that subscription ok -@@ -821,10 +647,10 @@ +@@ -692,8 +497,7 @@ + end; + + disco_sm_items(Acc, From, To, NodeB, _Lang) -> +- SNode = binary_to_list(NodeB), +- Node = string_to_node(SNode), ++ Node = string_to_node(binary_to_list(NodeB)), + %% TODO, use iq_disco_items(Host, Node, From) + Host = exmpp_jid:prep_domain_as_list(To), + LJID = jlib:short_prepd_bare_jid(To), +@@ -841,10 +645,10 @@ {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), lists:foreach(fun ({Node, subscribed, _, JID}) -> @@ -264,7 +307,7 @@ true -> node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); false -> -@@ -943,11 +769,12 @@ +@@ -963,11 +767,12 @@ end, ejabberd_router:route(To, From, Res); #iq{type = get, ns = ?NS_DISCO_ITEMS, @@ -279,7 +322,7 @@ {result, IQRes} -> Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query', attrs = QAttrs, -@@ -1050,7 +877,7 @@ +@@ -1070,7 +875,7 @@ [] -> ["leaf"]; %% No sub-nodes: it's a leaf node _ -> @@ -288,7 +331,7 @@ {result, []} -> ["collection"]; {result, _} -> ["leaf", "collection"]; _ -> [] -@@ -1066,8 +893,9 @@ +@@ -1086,8 +891,9 @@ []; true -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} | @@ -300,7 +343,7 @@ end, features(Type))] end, %% TODO: add meta-data info (spec section 5.4) -@@ -1095,14 +923,15 @@ +@@ -1115,22 +921,23 @@ #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_DISCO_ITEMS_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++ @@ -317,19 +360,23 @@ -iq_disco_items(Host, [], From) -> +iq_disco_items(Host, [], From, _RSM) -> {result, lists:map( - fun(#pubsub_node{nodeid = {_, SubNode}}) -> - SN = node_to_string(SubNode), -@@ -1112,7 +941,7 @@ - ?XMLATTR('node', SN), - ?XMLATTR('name', RN)]} - end, tree_action(Host, get_subnodes, [Host, [], From]))}; + fun(#pubsub_node{nodeid = {_, SubNode}, type = Type}) -> +- {result, Path} = node_call(Type, node_to_path, [SubNode]), +- [Name | _] = lists:reverse(Path), ++ {result, Path} = node_call(Type, node_path, [SubNode]), ++ [Name | _] = lists:reverse(Path), + #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), +- ?XMLATTR('name', Name) | nodeAttr(SubNode)]} +- end, tree_action(Host, get_subnodes, [Host, [], From]))}; -iq_disco_items(Host, Item, From) -> ++ ?XMLATTR('name', Name) | nodeAttr(SubNode)]} ++ end, tree_action(Host, get_subnodes, [Host, <<>>, From]))}; +iq_disco_items(Host, Item, From, RSM) -> case string:tokens(Item, "!") of [_SNode, _ItemID] -> {result, []}; -@@ -1124,10 +953,10 @@ - %% TODO That is, remove name attribute (or node?, please check for 2.1) +@@ -1138,10 +945,10 @@ + Node = string_to_node(SNode), Action = fun(#pubsub_node{type = Type, id = NodeId}) -> - % TODO call get_items/6 instead for access control (EJAB-1033) @@ -342,16 +389,29 @@ end, Nodes = lists:map( fun(#pubsub_node{nodeid = {_, SubNode}}) -> -@@ -1143,7 +972,7 @@ - #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('node', SN), - ?XMLATTR('name', Name)]} +@@ -1150,9 +957,10 @@ + Items = lists:map( + fun(#pubsub_item{itemid = {RN, _}}) -> + {result, Name} = node_call(Type, get_item_name, [Host, Node, RN]), +- #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name)]} ++ #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ++ ?XMLATTR('name', Name)]} end, NodeItems), - {result, Nodes ++ Items} + {result, Nodes ++ Items ++ jlib:rsm_encode(RsmOut)} end, case transaction(Host, Node, Action, sync_dirty) of {result, {_, Result}} -> {result, Result}; -@@ -1277,7 +1106,8 @@ +@@ -1208,7 +1016,7 @@ + iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) -> + case exmpp_xml:remove_cdata_from_list(SubEl#xmlel.children) of + [#xmlel{name = Name, attrs = Attrs, children = Els} | Rest] -> +- Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(attrs, 'node', false)), ++ Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', false)), + case {IQType, Name} of + {set, 'create'} -> + Config = case Rest of +@@ -1283,7 +1091,8 @@ (_, Acc) -> Acc end, [], exmpp_xml:remove_cdata_from_list(Els)), @@ -361,7 +421,7 @@ {get, 'subscriptions'} -> get_subscriptions(Host, Node, From, Plugins); {get, 'affiliations'} -> -@@ -1299,8 +1129,9 @@ +@@ -1305,8 +1114,9 @@ end. iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> @@ -372,8 +432,8 @@ + end, exmpp_xml:get_child_elements(SubEl)), case Action of [#xmlel{name = Name, attrs = Attrs, children = Els}] -> - Node = case Host of -@@ -1430,7 +1261,8 @@ + Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")), +@@ -1433,7 +1243,8 @@ _ -> [] end end, @@ -383,7 +443,7 @@ sync_dirty) of {result, Res} -> Res; Err -> Err -@@ -1475,7 +1307,7 @@ +@@ -1478,7 +1289,7 @@ %%% authorization handling @@ -392,7 +452,7 @@ Lang = "en", %% TODO fix {U, S, R} = Subscriber, Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children = -@@ -1505,7 +1337,7 @@ +@@ -1508,7 +1319,7 @@ lists:foreach(fun(Owner) -> {U, S, R} = Owner, ejabberd_router ! {route, service_jid(Host), exmpp_jid:make(U, S, R), Stanza} @@ -401,7 +461,23 @@ find_authorization_response(Packet) -> Els = Packet#xmlel.children, -@@ -1568,8 +1400,8 @@ +@@ -1550,7 +1361,7 @@ + end, + Stanza = event_stanza( + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs = +- [ ?XMLATTR('jid', exmpp_jid:to_binary(JID)) | nodeAttr(SNode)] ++ SubAttrs ++ [?XMLATTR('jid', exmpp_jid:to_binary(JID)) | nodeAttr(SNode)] ++ SubAttrs + }]), + ejabberd_router ! {route, service_jid(Host), JID, Stanza}. + +@@ -1561,14 +1372,14 @@ + {{value, {_, [SNode]}}, {value, {_, [SSubscriber]}}, + {value, {_, [SAllow]}}} -> + Node = string_to_node(SNode), +- Subscriber = exmpp_jid:parse(SSubscriber), ++ Subscriber = exmpp_jid:parse(SSubscriber), + Allow = case SAllow of + "1" -> true; "true" -> true; _ -> false end, @@ -412,7 +488,7 @@ {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), if not IsApprover -> -@@ -1759,7 +1591,7 @@ +@@ -1763,7 +1574,7 @@ end, Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}, @@ -421,7 +497,7 @@ {result, {Result, broadcast}} -> %%Lang = "en", %% TODO: fix %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), -@@ -1868,7 +1700,7 @@ +@@ -1872,7 +1683,7 @@ %%
  • The node does not exist.
  • %% subscribe_node(Host, Node, From, JID, Configuration) -> @@ -430,7 +506,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -1879,7 +1711,7 @@ +@@ -1883,7 +1694,7 @@ {undefined, undefined, undefined} end, SubId = uniqid(), @@ -439,7 +515,7 @@ Features = features(Type), SubscribeFeature = lists:member("subscribe", Features), OptionsFeature = lists:member("subscription-options", Features), -@@ -1898,9 +1730,13 @@ +@@ -1902,9 +1713,13 @@ {"", "", ""} -> {false, false}; _ -> @@ -456,7 +532,7 @@ end end, if -@@ -2233,7 +2069,7 @@ +@@ -2237,7 +2052,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. @@ -465,7 +541,7 @@ MaxItems = if SMaxItems == "" -> get_max_items_node(Host); -@@ -2272,11 +2108,11 @@ +@@ -2276,11 +2091,11 @@ node_call(Type, get_items, [NodeId, From, AccessModel, PresenceSubscription, RosterGroup, @@ -479,7 +555,7 @@ SendItems = case ItemIDs of [] -> Items; -@@ -2289,7 +2125,7 @@ +@@ -2293,7 +2108,7 @@ %% number of items sent to MaxItems: {result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children = @@ -488,7 +564,7 @@ Error -> Error end -@@ -2321,17 +2157,29 @@ +@@ -2325,17 +2140,29 @@ %% @doc

    Resend the items of a node to the user.

    %% @todo use cache-last-item feature send_items(Host, Node, NodeId, Type, LJID, last) -> @@ -525,7 +601,7 @@ send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of {result, []} -> -@@ -2460,29 +2308,12 @@ +@@ -2464,29 +2291,12 @@ error -> {error, 'bad-request'}; _ -> @@ -558,7 +634,7 @@ end, Entities), {result, []}; _ -> -@@ -2537,11 +2368,11 @@ +@@ -2541,11 +2351,11 @@ end. read_sub(Subscriber, Node, NodeID, SubID, Lang) -> @@ -570,9 +646,9 @@ - {result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options), + {result, XdataEl} = pubsub_subscription_odbc:get_options_xform(Lang, Options), OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options', - attrs = [?XMLATTR('node', node_to_string(Node)), - ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), -@@ -2569,7 +2400,7 @@ + attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), + ?XMLATTR('Subid', SubID) | nodeAttr(Node)], +@@ -2572,7 +2382,7 @@ end. set_options_helper(Configuration, JID, NodeID, SubID, Type) -> @@ -581,7 +657,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -2599,7 +2430,7 @@ +@@ -2602,7 +2412,7 @@ write_sub(_Subscriber, _NodeID, _SubID, invalid) -> {error, extended_error('bad-request', "invalid-options")}; write_sub(Subscriber, NodeID, SubID, Options) -> @@ -590,7 +666,7 @@ {error, notfound} -> {error, extended_error('not-acceptable', "invalid-subid")}; {result, _} -> -@@ -2772,8 +2603,8 @@ +@@ -2775,8 +2585,8 @@ ?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]}, ejabberd_router ! {route, service_jid(Host), JID, Stanza} end, @@ -601,7 +677,7 @@ true -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> -@@ -3069,7 +2900,7 @@ +@@ -3066,7 +2876,7 @@ {Depth, [{N, get_node_subs(N)} || N <- Nodes]} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, @@ -610,7 +686,7 @@ {result, CollSubs} -> CollSubs; _ -> [] end. -@@ -3083,9 +2914,9 @@ +@@ -3080,9 +2890,9 @@ get_options_for_subs(NodeID, Subs) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) -> @@ -622,7 +698,16 @@ _ -> Acc end; (_, Acc) -> -@@ -3284,6 +3115,30 @@ +@@ -3090,7 +2900,7 @@ + end, [], Subs). + + % TODO: merge broadcast code that way +-% TODO: pablo: Why is this commented? Seems to be present on trunk. ++% TODO: pablo: why is this commented? + %broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) -> + % case (get_option(NodeOptions, Feature) or Force) of + % true -> +@@ -3282,6 +3092,30 @@ Result end. @@ -653,7 +738,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3673,7 +3528,13 @@ +@@ -3671,7 +3505,13 @@ tree_action(Host, Function, Args) -> ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), Fun = fun() -> tree_call(Host, Function, Args) end, @@ -668,7 +753,7 @@ %% @doc

    node plugin call.

    node_call(Type, Function, Args) -> -@@ -3693,13 +3554,13 @@ +@@ -3691,13 +3531,13 @@ node_action(Host, Type, Function, Args) -> ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), @@ -684,7 +769,7 @@ case tree_call(Host, get_node, [Host, Node]) of N when is_record(N, pubsub_node) -> case Action(N) of -@@ -3712,8 +3573,15 @@ +@@ -3710,8 +3550,15 @@ end end, Trans). @@ -702,7 +787,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3721,6 +3589,15 @@ +@@ -3719,6 +3566,15 @@ {aborted, Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), {error, 'internal-server-error'}; @@ -718,7 +803,7 @@ {'EXIT', Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), {error, 'internal-server-error'}; -@@ -3729,6 +3606,16 @@ +@@ -3727,6 +3583,16 @@ {error, 'internal-server-error'} end.