]> granicus.if.org Git - ejabberd/commitdiff
auto-create pe node bugfix
authorChristophe Romain <christophe.romain@process-one.net>
Mon, 10 Dec 2007 14:09:31 +0000 (14:09 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Mon, 10 Dec 2007 14:09:31 +0000 (14:09 +0000)
SVN Revision: 1060

ChangeLog
src/mod_pubsub/mod_pubsub.erl

index 576701528291a98555aea77b00a41238963e9248..17984670e5629a89777de59e48f38ea57f905d05 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2007-12-10  Christophe Romain <christophe.romain@process-one.net>
 
        * src/mod_pubsub/mod_pubsub.erl: database upgrade bugfix
+       * src/mod_pubsub/mod_pubsub.erl: auto-create pep node bugfix
 
 2007-12-09  Mickael Remond  <mremond@process-one.net>
 
index e48c2a6d47b467de7eb91bb8cd3c7c2818bf95f7..1ad0d745f559d8d0a00d23ddca310cbad6dbe542 100644 (file)
@@ -37,6 +37,7 @@
 
 -define(STDTREE, "default").
 -define(STDNODE, "default").
+-define(PEPNODE, "pep").
 
 %% exports for hooks
 -export([set_presence/4,
@@ -198,9 +199,9 @@ init_plugins(Host, ServerHost, Opts) ->
                              gen_mod:get_opt(nodetree, Opts, ?STDTREE)),
     ?INFO_MSG("** tree plugin is ~p",[TreePlugin]),
     TreePlugin:init(Host, ServerHost, Opts),
-    Plugins = lists:usort(gen_mod:get_opt(plugins, Opts, []) ++ [?STDNODE]),
+    Plugins = lists:usort(gen_mod:get_opt(plugins, Opts, []) ++ [?STDNODE,?PEPNODE]),
     lists:foreach(fun(Name) ->
-                         ?INFO_MSG("** init ~s plugin~n",[Name]),
+                         ?INFO_MSG("** init ~s plugin",[Name]),
                          Plugin = list_to_atom(?PLUGIN_PREFIX ++ Name),
                          Plugin:init(Host, ServerHost, Opts)
                  end, Plugins),
@@ -208,7 +209,7 @@ init_plugins(Host, ServerHost, Opts) ->
 
 terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
     lists:foreach(fun(Name) ->
-                         ?INFO_MSG("** terminate ~s plugin~n",[Name]),
+                         ?INFO_MSG("** terminate ~s plugin",[Name]),
                          Plugin = list_to_atom(?PLUGIN_PREFIX++Name),
                          Plugin:terminate(Host, ServerHost)
                  end, Plugins),
@@ -1193,7 +1194,7 @@ create_node(Host, ServerHost, [], Owner, Type, Access, Configuration) ->
     end;
 create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
     Type = case Host of
-              {_User, _Server, _Resource} -> "pep";
+              {_User, _Server, _Resource} -> ?PEPNODE;
               _ -> GivenType
           end,
     Parent = lists:sublist(Node, length(Node) - 1),
@@ -1498,28 +1499,21 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
        {error, ?ERR_ITEM_NOT_FOUND} ->
            %% handles auto-create feature
            %% for automatic node creation. we'll take the default node type:
-           %% first listed into the plugins configuration option
-           Type = case ets:lookup(gen_mod:get_module_proc(ServerHost, pubsub_state), plugins) of
-                      [{plugins, PL}] -> hd(PL);
-                      _ -> ?STDNODE
-                  end,
+           %% first listed into the plugins configuration option, or pep
+           Type = case Host of
+               {_User, _Server, _Resource} -> 
+                   ?PEPNODE;
+               _ -> 
+                   case ets:lookup(gen_mod:get_module_proc(ServerHost, pubsub_state), plugins) of
+                       [{plugins, PL}] -> hd(PL);
+                       _ -> ?STDNODE
+                   end
+           end,
            case lists:member("auto-create", features(Type)) of
                true ->
                    case create_node(Host, ServerHost, Node, Publisher, Type) of
-                       {result, [CreateRes]} ->
-                           %% Ugly hack
-                           SNewNode = xml:get_path_s(
-                                        CreateRes,
-                                        [{elem, "create"},
-                                         {attr, "node"}]),
-                           NewNode = string_to_node(SNewNode),
-                           if
-                               NewNode /= Node ->
-                                   publish_item(Host, ServerHost, NewNode,
-                                                Publisher, ItemId, Payload);
-                               true ->
-                                   {error, ?ERR_ITEM_NOT_FOUND}
-                           end;
+                       {result, _} ->
+                           publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload);
                        _ ->
                            {error, ?ERR_ITEM_NOT_FOUND}
                    end;