do not create hometree base when hometree not configured as plugin
authorChristophe Romain <christophe.romain@process-one.net>
Fri, 25 Sep 2009 13:12:29 +0000 (13:12 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Fri, 25 Sep 2009 13:12:29 +0000 (13:12 +0000)
SVN Revision: 2634

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

index 6b21f45851ecd36858cd81aeb976277b5ccb7285..2ea343023eec8477621d0c9849d6022d5fec3d8f 100644 (file)
@@ -218,7 +218,7 @@ init([ServerHost, Opts]) ->
     ejabberd_router:register_route(Host),
     update_node_database(Host, ServerHost),
     update_state_database(Host, ServerHost),
-    init_nodes(Host, ServerHost),
+    init_nodes(Host, ServerHost, NodeTree, Plugins),
     State = #state{host = Host,
                server_host = ServerHost,
                access = Access,
@@ -268,10 +268,15 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
     TreePlugin:terminate(Host, ServerHost),
     ok.
 
-init_nodes(Host, ServerHost) ->
-    create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
-    create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
-    ok.
+init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
+    %% TODO, this call should be done PLugin side
+    case lists:member("hometree", Plugins) of
+    true ->
+       create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
+       create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree");
+    false ->
+       ok
+    end.
 
 update_node_database(Host, ServerHost) ->
     mnesia:del_table_index(pubsub_node, type),
index 0e8c3c3fe38010db7fe06d1474151ba3e2d416f6..4ae6a0374372892cf95092712fc0a4d610475329 100644 (file)
@@ -216,7 +216,7 @@ init([ServerHost, Opts]) ->
            ok
     end,
     ejabberd_router:register_route(Host),
-    init_nodes(Host, ServerHost),
+    init_nodes(Host, ServerHost, NodeTree, Plugins),
     State = #state{host = Host,
                server_host = ServerHost,
                access = Access,
@@ -266,10 +266,15 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
     TreePlugin:terminate(Host, ServerHost),
     ok.
 
-init_nodes(Host, ServerHost) ->
-    create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
-    create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
-    ok.
+init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
+    %% TODO, this call should be done PLugin side
+    case lists:member("hometree", Plugins) of
+    true ->
+       create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
+       create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree");
+    false ->
+       ok
+    end.
 
 send_queue(State, Msg) ->
     Pid = State#state.send_loop,
index 400ec948bd550715401088805c95d9de23ed8b97..1d9ca18a765c92b61ca9b1947888b5f4f3b2ede1 100644 (file)
@@ -1,5 +1,5 @@
---- mod_pubsub.erl     2009-09-24 18:34:03.471785103 +0200
-+++ mod_pubsub_odbc.erl        2009-09-24 18:35:20.256479455 +0200
+--- mod_pubsub.erl     2009-09-25 15:10:12.000000000 +0200
++++ mod_pubsub_odbc.erl        2009-09-25 15:11:41.000000000 +0200
 @@ -45,7 +45,7 @@
  %%% TODO
  %%% plugin: generate Reply (do not use broadcast atom anymore)
      ejabberd_router:register_route(Host),
 -    update_node_database(Host, ServerHost),
 -    update_state_database(Host, ServerHost),
-     init_nodes(Host, ServerHost),
+     init_nodes(Host, ServerHost, NodeTree, Plugins),
      State = #state{host = Host,
                server_host = ServerHost,
-@@ -273,178 +271,6 @@
-     create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
-     ok.
+@@ -278,178 +276,6 @@
+       ok
+     end.
  
 -update_node_database(Host, ServerHost) ->
 -    mnesia:del_table_index(pubsub_node, type),
  send_queue(State, Msg) ->
      Pid = State#state.send_loop,
      case is_process_alive(Pid) of
-@@ -467,17 +293,15 @@
+@@ -472,17 +298,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) ->
                    true ->
                        % resource not concerned about that subscription
                        ok
-@@ -801,10 +625,10 @@
+@@ -806,10 +630,10 @@
        {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
        lists:foreach(fun
            ({Node, subscribed, _, JID}) ->
                            true ->
                                node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
                            false ->
-@@ -918,7 +742,8 @@
+@@ -923,7 +747,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,
-@@ -1023,7 +848,7 @@
+@@ -1028,7 +853,7 @@
                                    [] ->
                                        ["leaf"]; %% No sub-nodes: it's a leaf node
                                    _ ->
                                            {result, []} -> ["collection"];
                                            {result, _} -> ["leaf", "collection"];
                                            _ -> []
-@@ -1039,8 +864,9 @@
+@@ -1044,8 +869,9 @@
                            [];
                        true ->
                            [{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
                                       end, features(Type))]
                    end,
                %% TODO: add meta-data info (spec section 5.4)
-@@ -1068,14 +894,15 @@
+@@ -1073,14 +899,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),
-@@ -1085,7 +912,7 @@
+@@ -1090,7 +917,7 @@
                                             {"node", SN},
                                             {"name", RN}], []}
               end, tree_action(Host, get_subnodes, [Host, [], From]))};
      case string:tokens(Item, "!") of
        [_SNode, _ItemID] ->
            {result, []};
-@@ -1097,10 +924,10 @@
+@@ -1102,10 +929,10 @@
            %% 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}}) ->
-@@ -1116,7 +943,7 @@
+@@ -1121,7 +948,7 @@
                                          {xmlelement, "item", [{"jid", Host}, {"node", SN},
                                                                {"name", Name}], []}
                                  end, NodeItems),
                end,
            case transaction(Host, Node, Action, sync_dirty) of
                {result, {_, Result}} -> {result, Result};
-@@ -1248,7 +1075,8 @@
+@@ -1253,7 +1080,8 @@
                        (_, Acc) ->
                            Acc
                        end, [], xml:remove_cdata(Els)),
                {get, "subscriptions"} ->
                    get_subscriptions(Host, Node, From, Plugins);
                {get, "affiliations"} ->
-@@ -1271,7 +1099,9 @@
+@@ -1276,7 +1104,9 @@
  
  iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
      {xmlelement, _, _, SubEls} = SubEl,
      case Action of
        [{xmlelement, Name, Attrs, Els}] ->
            Node = case Host of
-@@ -1397,7 +1227,8 @@
+@@ -1402,7 +1232,8 @@
                    _          -> []
                end
        end,
                     sync_dirty) of
        {result, Res} -> Res;
        Err        -> Err
-@@ -1437,7 +1268,7 @@
+@@ -1442,7 +1273,7 @@
  
  %%% authorization handling
  
      Lang = "en", %% TODO fix
      Stanza = {xmlelement, "message",
              [],
-@@ -1466,7 +1297,7 @@
+@@ -1471,7 +1302,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,
-@@ -1533,8 +1364,8 @@
+@@ -1538,8 +1369,8 @@
                        "true" -> true;
                        _ -> false
                    end,
                             {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
                             if
                                 not IsApprover ->
-@@ -1720,7 +1551,7 @@
+@@ -1725,7 +1556,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)),
-@@ -1828,12 +1659,12 @@
+@@ -1833,12 +1664,12 @@
  %%<li>The node does not exist.</li>
  %%</ul>
  subscribe_node(Host, Node, From, JID, Configuration) ->
                    Features = features(Type),
                    SubscribeFeature = lists:member("subscribe", Features),
                    OptionsFeature = lists:member("subscription-options", Features),
-@@ -1852,9 +1683,13 @@
+@@ -1857,9 +1688,13 @@
                                    {"", "", ""} ->
                                        {false, false};
                                    _ ->
                                end
                        end,
                    if
-@@ -2177,7 +2012,7 @@
+@@ -2182,7 +2017,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 == "" -> get_max_items_node(Host);
-@@ -2216,11 +2051,11 @@
+@@ -2221,11 +2056,11 @@
                             node_call(Type, get_items,
                                       [NodeId, From,
                                        AccessModel, PresenceSubscription, RosterGroup,
                    SendItems = case ItemIDs of
                        [] -> 
                            Items;
-@@ -2233,7 +2068,8 @@
+@@ -2238,7 +2073,8 @@
                    %% number of items sent to MaxItems:
                    {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
                                [{xmlelement, "items", nodeAttr(Node),
                Error ->
                    Error
            end
-@@ -2265,16 +2101,27 @@
+@@ -2270,16 +2106,27 @@
  %% @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, []} -> 
-@@ -2400,29 +2247,12 @@
+@@ -2405,29 +2252,12 @@
        error ->
            {error, ?ERR_BAD_REQUEST};
        _ ->
                                    end, Entities),
                                {result, []};
                            _ ->
-@@ -2475,11 +2305,11 @@
+@@ -2480,11 +2310,11 @@
      end.
  
  read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
            OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)},
                                                 {"jid", jlib:jid_to_string(Subscriber)},
                                                 {"subid", SubID}],
-@@ -2510,7 +2340,7 @@
+@@ -2515,7 +2345,7 @@
                     error -> {"", "", ""};
                     J -> jlib:jid_tolower(J)
                 end,
      {result, Subs} = node_call(Type, get_subscriptions,
                               [NodeID, Subscriber]),
      SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
-@@ -2530,7 +2360,7 @@
+@@ -2535,7 +2365,7 @@
      end.
  
  write_sub(Subscriber, NodeID, SubID, Options) ->
        {error, notfound} ->
            {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
        {result, _} ->
-@@ -2698,8 +2528,8 @@
+@@ -2703,8 +2533,8 @@
                                     {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
                ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
            end,
                                true ->
                                    Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
  
-@@ -2989,7 +2819,7 @@
+@@ -2994,7 +2824,7 @@
                        {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
            end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
        end,
        {result, CollSubs} -> CollSubs;
        _ -> []
      end.
-@@ -3003,9 +2833,9 @@
+@@ -3008,9 +2838,9 @@
  
  get_options_for_subs(NodeID, Subs) ->
      lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
                            _ -> Acc
                        end;
                    (_, Acc) ->
-@@ -3203,6 +3033,30 @@
+@@ -3208,6 +3038,30 @@
            Result
      end.
  
  %% @spec (Host, Options) -> MaxItems
  %%     Host = host()
  %%     Options = [Option]
-@@ -3589,7 +3443,13 @@
+@@ -3594,7 +3448,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) ->
-@@ -3609,13 +3469,13 @@
+@@ -3614,13 +3474,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
-@@ -3628,8 +3488,14 @@
+@@ -3633,8 +3493,14 @@
                        end
                end, Trans).
  
        {result, Result} -> {result, Result};
        {error, Error} -> {error, Error};
        {atomic, {result, Result}} -> {result, Result};
-@@ -3637,6 +3503,15 @@
+@@ -3642,6 +3508,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};
-@@ -3645,6 +3520,17 @@
+@@ -3650,6 +3525,17 @@
            {error, ?ERR_INTERNAL_SERVER_ERROR}
      end.