]> granicus.if.org Git - ejabberd/commitdiff
added function to rename old default nodes to hometree
authorChristophe Romain <christophe.romain@process-one.net>
Tue, 25 Aug 2009 14:13:26 +0000 (14:13 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Tue, 25 Aug 2009 14:13:26 +0000 (14:13 +0000)
SVN Revision: 2529

src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/pubsub_odbc.patch

index 6fea31d0d78607aa2fb51aa0c165ab521185fb2b..38c9ccac4760063a51ba0347e1c26b291a9e33c5 100644 (file)
         string_to_subscription/1,
         string_to_affiliation/1,
         extended_error/2,
-        extended_error/3
+        extended_error/3,
+        rename_default_nodeplugin/0
        ]).
 
 %% API and gen_server callbacks
@@ -334,11 +335,9 @@ update_node_database(Host, ServerHost) ->
                   end,
            case mnesia:transaction(FNew) of
                {atomic, Result} ->
-                   ?INFO_MSG("Pubsub node tables updated correctly: ~p",
-                             [Result]);
+                   ?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
                {aborted, Reason} ->
-                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p",
-                              [Reason])
+                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p", [Reason])
            end;
        [nodeid, parentid, type, owners, options] ->
            F = fun({pubsub_node, NodeId, {_, Parent}, Type, Owners, Options}) ->
@@ -377,11 +376,10 @@ update_node_database(Host, ServerHost) ->
                end,
            case mnesia:transaction(FNew) of
                {atomic, Result} ->
-                   ?INFO_MSG("Pubsub node tables updated correctly: ~p",
-                             [Result]);
+                   rename_default_nodeplugin(),
+                   ?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
                {aborted, Reason} ->
-                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p",
-                              [Reason])
+                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p", [Reason])
            end;
        [nodeid, id, parent, type, owners, options] ->
            F = fun({pubsub_node, NodeId, Id, Parent, Type, Owners, Options}) ->
@@ -393,11 +391,17 @@ update_node_database(Host, ServerHost) ->
                        owners = Owners,
                        options = Options}
                end,
-           mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]);
+           mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]),
+           rename_default_nodeplugin();
        _ ->
            ok
     end.
 
+rename_default_nodeplugin() ->
+    lists:foreach(fun(Node) ->
+       mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
+    end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
+
 update_state_database(_Host, _ServerHost) ->
     case catch mnesia:table_info(pubsub_state, attributes) of
        [stateid, items, affiliation, subscription] ->
index 8d5f7d4b5605998e654b400138fcce6665e237aa..a072cfd2142d0d80532f6fb4208d3298be958bab 100644 (file)
         string_to_affiliation/1,
         extended_error/2,
         extended_error/3,
-        escape/1
+        escape/1,
+        rename_default_nodeplugin/0
        ]).
 
 %% API and gen_server callbacks
@@ -333,11 +334,9 @@ update_node_database(Host, ServerHost) ->
                   end,
            case mnesia:transaction(FNew) of
                {atomic, Result} ->
-                   ?INFO_MSG("Pubsub node tables updated correctly: ~p",
-                             [Result]);
+                   ?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
                {aborted, Reason} ->
-                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p",
-                              [Reason])
+                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p", [Reason])
            end;
        [nodeid, parentid, type, owners, options] ->
            F = fun({pubsub_node, NodeId, {_, Parent}, Type, Owners, Options}) ->
@@ -376,11 +375,10 @@ update_node_database(Host, ServerHost) ->
                end,
            case mnesia:transaction(FNew) of
                {atomic, Result} ->
-                   ?INFO_MSG("Pubsub node tables updated correctly: ~p",
-                             [Result]);
+                   rename_default_nodeplugin(),
+                   ?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
                {aborted, Reason} ->
-                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p",
-                              [Reason])
+                   ?ERROR_MSG("Problem updating Pubsub node tables:~n~p", [Reason])
            end;
        [nodeid, id, parent, type, owners, options] ->
            F = fun({pubsub_node, NodeId, Id, Parent, Type, Owners, Options}) ->
@@ -392,11 +390,18 @@ update_node_database(Host, ServerHost) ->
                        owners = Owners,
                        options = Options}
                end,
-           mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]);
+           mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]),
+           rename_default_nodeplugin();
        _ ->
            ok
     end.
 
+rename_default_nodeplugin() ->
+%    lists:foreach(fun(Node) ->
+%      mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
+%    end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
+    ok.
+
 update_state_database(_Host, _ServerHost) ->
     case catch mnesia:table_info(pubsub_state, attributes) of
        [stateid, items, affiliation, subscription] ->
@@ -2669,16 +2674,23 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
            {error, ?ERR_BAD_REQUEST};
        _ ->
            Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
-                            case lists:member(Owner, node_owners_call(Type, NodeId)) of
-                                true ->
-                                    lists:foreach(fun({JID, Subscription, SubId}) ->
-                                                          node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
-                                                  end, Entities),
-                                    {result, []};
-                                _ ->
-                                    {error, ?ERR_FORBIDDEN}
-                            end
-                    end,
+                           case lists:member(Owner, node_owners_call(Type, NodeId)) of
+                               true ->
+                                   Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
+
+                                                   case node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) of
+                                                       {error, Err} -> [{error, Err} | Acc];
+                                                       _ -> Acc
+                                                   end
+                                               end, [], Entities),
+                                   case Result of
+                                       [] -> {result, []};
+                                       _ -> {error, ?ERR_NOT_ACCEPTABLE}
+                                   end;
+                               _ ->
+                                   {error, ?ERR_FORBIDDEN}
+                           end
+                   end,
            case transaction(Host, Node, Action, sync_dirty) of
                {result, {_, Result}} -> {result, Result};
                Other -> Other
index a2b00cda80034297fd35bd67fe384045262d0eec..88f976b8f36da7dfff395d870acb13e2a14014f1 100644 (file)
@@ -1,5 +1,5 @@
---- mod_pubsub.erl     2009-08-20 17:49:22.000000000 +0200
-+++ mod_pubsub_odbc.erl        2009-08-21 13:53:33.000000000 +0200
+--- mod_pubsub.erl     2009-08-25 16:10:58.000000000 +0200
++++ mod_pubsub_odbc.erl        2009-08-25 16:12:30.000000000 +0200
 @@ -45,7 +45,7 @@
  %%% TODO
  %%% plugin: generate Reply (do not use broadcast atom anymore)
  
  %% exports for hooks
  -export([presence_probe/3,
-@@ -104,7 +104,8 @@
-        string_to_subscription/1,
+@@ -105,6 +105,7 @@
         string_to_affiliation/1,
         extended_error/2,
--       extended_error/3
-+       extended_error/3,
-+       escape/1
+        extended_error/3,
++       escape/1,
+        rename_default_nodeplugin/0
        ]).
  
- %% API and gen_server callbacks
-@@ -123,7 +124,7 @@
+@@ -124,7 +125,7 @@
  -export([send_loop/1
        ]).
  
@@ -41,7 +39,7 @@
  -define(PLUGIN_PREFIX, "node_").
  -define(TREE_PREFIX, "nodetree_").
  
-@@ -212,8 +213,6 @@
+@@ -213,8 +214,6 @@
            ok
      end,
      ejabberd_router:register_route(Host),
      init_nodes(Host, ServerHost),
      State = #state{host = Host,
                server_host = ServerHost,
-@@ -459,17 +458,15 @@
+@@ -398,9 +397,10 @@
+     end.
+ rename_default_nodeplugin() ->
+-    lists:foreach(fun(Node) ->
+-      mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
+-    end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
++%    lists:foreach(fun(Node) ->
++%     mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
++%    end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
++    ok.
+ update_state_database(_Host, _ServerHost) ->
+     case catch mnesia:table_info(pubsub_state, attributes) of
+@@ -463,17 +463,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) ->
@@ -74,7 +86,7 @@
                    true ->
                        % resource not concerned about that subscription
                        ok
-@@ -792,10 +789,10 @@
+@@ -796,10 +794,10 @@
        {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
        lists:foreach(fun
            ({Node, subscribed, _, JID}) ->
@@ -87,7 +99,7 @@
                            true ->
                                node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
                            false ->
-@@ -909,7 +906,8 @@
+@@ -913,7 +911,8 @@
                            sub_el = SubEl} = IQ ->
                            {xmlelement, _, QAttrs, _} = SubEl,
                            Node = xml:get_attr_s("node", QAttrs),
                                      {result, IQRes} ->
                                          jlib:iq_to_xml(
                                            IQ#iq{type = result,
-@@ -1014,7 +1012,7 @@
+@@ -1018,7 +1017,7 @@
                                    [] ->
                                        ["leaf"]; %% No sub-nodes: it's a leaf node
                                    _ ->
                                            {result, []} -> ["collection"];
                                            {result, _} -> ["leaf", "collection"];
                                            _ -> []
-@@ -1030,8 +1028,9 @@
+@@ -1034,8 +1033,9 @@
                            [];
                        true ->
                            [{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
                                       end, features(Type))]
                    end,
                %% TODO: add meta-data info (spec section 5.4)
-@@ -1059,14 +1058,15 @@
+@@ -1063,14 +1063,15 @@
                {xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []},
                {xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
                {xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
      {result, lists:map(
               fun(#pubsub_node{nodeid = {_, SubNode}}) ->
                       SN = node_to_string(SubNode),
-@@ -1076,7 +1076,7 @@
+@@ -1080,7 +1081,7 @@
                                             {"node", SN},
                                             {"name", RN}], []}
               end, tree_action(Host, get_subnodes, [Host, [], From]))};
      case string:tokens(Item, "!") of
        [_SNode, _ItemID] ->
            {result, []};
-@@ -1088,9 +1088,9 @@
+@@ -1092,9 +1093,9 @@
            %% TODO That is, remove name attribute (or node?, please check for 2.1)
            Action =
                fun(#pubsub_node{type = Type, id = NodeId}) ->
                                    end,
                        Nodes = lists:map(
                                  fun(#pubsub_node{nodeid = {_, SubNode}}) ->
-@@ -1106,7 +1106,7 @@
+@@ -1110,7 +1111,7 @@
                                          {xmlelement, "item", [{"jid", Host}, {"node", SN},
                                                                {"name", Name}], []}
                                  end, NodeItems),
                end,
            case transaction(Host, Node, Action, sync_dirty) of
                {result, {_, Result}} -> {result, Result};
-@@ -1238,7 +1238,8 @@
+@@ -1242,7 +1243,8 @@
                        (_, Acc) ->
                            Acc
                        end, [], xml:remove_cdata(Els)),
                {get, "subscriptions"} ->
                    get_subscriptions(Host, Node, From, Plugins);
                {get, "affiliations"} ->
-@@ -1261,7 +1262,10 @@
+@@ -1265,7 +1267,10 @@
  
  iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
      {xmlelement, _, _, SubEls} = SubEl,
      case Action of
        [{xmlelement, Name, Attrs, Els}] ->
            Node = case Host of
-@@ -1387,7 +1391,8 @@
+@@ -1391,7 +1396,8 @@
                    _          -> []
                end
        end,
                     sync_dirty) of
        {result, Res} -> Res;
        Err        -> Err
-@@ -1431,7 +1436,7 @@
+@@ -1435,7 +1441,7 @@
  
  %%% authorization handling
  
      Lang = "en", %% TODO fix
      Stanza = {xmlelement, "message",
              [],
-@@ -1460,7 +1465,7 @@
+@@ -1464,7 +1470,7 @@
                  [{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
      lists:foreach(fun(Owner) ->
        ejabberd_router ! {route, service_jid(Host), jlib:make_jid(Owner), Stanza}
  
  find_authorization_response(Packet) ->
      {xmlelement, _Name, _Attrs, Els} = Packet,
-@@ -1527,8 +1532,8 @@
+@@ -1531,8 +1537,8 @@
                        "true" -> true;
                        _ -> false
                    end,
                             {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
                             if
                                 not IsApprover ->
-@@ -1714,7 +1719,7 @@
+@@ -1718,7 +1724,7 @@
            Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
                      [{xmlelement, "create", nodeAttr(Node),
                        []}]}],
                {result, {Result, broadcast}} ->
                    %%Lang = "en", %% TODO: fix
                    %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
-@@ -1826,7 +1831,7 @@
+@@ -1830,7 +1836,7 @@
                     error -> {"", "", ""};
                     J -> jlib:jid_tolower(J)
                 end,
                    Features = features(Type),
                    SubscribeFeature = lists:member("subscribe", Features),
                    OptionsFeature = lists:member("subscription-options", Features),
-@@ -1845,9 +1850,13 @@
+@@ -1849,9 +1855,13 @@
                                    {"", "", ""} ->
                                        {false, false};
                                    _ ->
                                end
                        end,
                    if
-@@ -2170,7 +2179,7 @@
+@@ -2174,7 +2184,7 @@
  %% <p>The permission are not checked in this function.</p>
  %% @todo We probably need to check that the user doing the query has the right
  %% to read the items.
      MaxItems =
        if
            SMaxItems == "" -> ?MAXITEMS;
-@@ -2209,11 +2218,11 @@
+@@ -2213,11 +2223,11 @@
                             node_call(Type, get_items,
                                       [NodeId, From,
                                        AccessModel, PresenceSubscription, RosterGroup,
                    SendItems = case ItemIDs of
                        [] -> 
                            Items;
-@@ -2226,7 +2235,8 @@
+@@ -2230,7 +2240,8 @@
                    %% number of items sent to MaxItems:
                    {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
                                [{xmlelement, "items", nodeAttr(Node),
                Error ->
                    Error
            end
-@@ -2258,15 +2268,22 @@
+@@ -2262,15 +2273,22 @@
  %% @doc <p>Resend the items of a node to the user.</p>
  %% @todo use cache-last-item feature
  send_items(Host, Node, NodeId, Type, LJID, last) ->
  send_items(Host, Node, NodeId, Type, LJID, Number) ->
      ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
        {result, []} -> 
-@@ -2384,29 +2401,12 @@
+@@ -2388,29 +2406,12 @@
        error ->
            {error, ?ERR_BAD_REQUEST};
        _ ->
                                    end, Entities),
                                {result, []};
                            _ ->
-@@ -2668,8 +2668,8 @@
+@@ -2672,8 +2673,8 @@
        error ->
            {error, ?ERR_BAD_REQUEST};
        _ ->
 -          Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
--                           case lists:member(Owner, Owners) of
+-                          case lists:member(Owner, Owners) of
 +          Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
-+                           case lists:member(Owner, node_owners_call(Type, NodeId)) of
-                                true ->
-                                    lists:foreach(fun({JID, Subscription, SubId}) ->
-                                                          node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
-@@ -3159,6 +3159,30 @@
++                          case lists:member(Owner, node_owners_call(Type, NodeId)) of
+                               true ->
+                                   Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
+@@ -3170,6 +3171,30 @@
            Result
      end.
  
  %% @spec (Host, Options) -> MaxItems
  %%     Host = host()
  %%     Options = [Option]
-@@ -3532,7 +3556,13 @@
+@@ -3543,7 +3568,13 @@
  tree_action(Host, Function, Args) ->
      ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
      Fun = fun() -> tree_call(Host, Function, Args) end,
  
  %% @doc <p>node plugin call.</p>
  node_call(Type, Function, Args) ->
-@@ -3552,13 +3582,13 @@
+@@ -3563,13 +3594,13 @@
  
  node_action(Host, Type, Function, Args) ->
      ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
                        case tree_call(Host, get_node, [Host, Node]) of
                            N when is_record(N, pubsub_node) ->
                                case Action(N) of
-@@ -3571,8 +3601,14 @@
+@@ -3582,8 +3613,14 @@
                        end
                end, Trans).
  
        {result, Result} -> {result, Result};
        {error, Error} -> {error, Error};
        {atomic, {result, Result}} -> {result, Result};
-@@ -3580,6 +3616,15 @@
+@@ -3591,6 +3628,15 @@
        {aborted, Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
            {error, ?ERR_INTERNAL_SERVER_ERROR};
        {'EXIT', Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
            {error, ?ERR_INTERNAL_SERVER_ERROR};
-@@ -3588,6 +3633,17 @@
+@@ -3599,6 +3645,17 @@
            {error, ?ERR_INTERNAL_SERVER_ERROR}
      end.