ejabberd - Comments for "New hooks for mod_pubsub" https://www.ejabberd.im/node/4772 en I am seeing a curious https://www.ejabberd.im/node/4772#comment-57506 <p>I am seeing a curious behaviour and wanted to check. I made the changes to mod_pubsub.erl to fire pubsub_create_node and pubsub_delete_node events and tried it out with a test module. For example the create event is handled as:</p> <div class="codeblock"><code>create_node(ServerHost, Host, Node, NodeOptions) -&gt;<br />&nbsp; ?DEBUG(&quot;mod_sequence: Node created at ~p, ~p is ~p with ~n~p&quot;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ServerHost, Host, Node, NodeOptions]),<br />&nbsp; ok.</code></div> <p>I am seeing two entries in the log right after each other for each create event. Example:</p> <div class="codeblock"><code>=INFO REPORT==== 2011-06-15 09:56:18 ===<br />D(&lt;0.357.0&gt;:mod_sequence:67) : mod_sequence: Node created at &lt;&lt;&quot;localhost&quot;&gt;&gt;, &lt;&lt;&quot;pubsub.localhost&quot;&gt;&gt; is &lt;&lt;&quot;test1&quot;&gt;&gt; with<br />[{deliver_payloads,true},<br /> {notify_config,false},<br /> {notify_delete,false},<br /> {notify_retract,true},<br /> {notify_sub,false},<br /> {purge_offline,false},<br /> {persist_items,true},<br /> {max_items,10},<br /> {subscribe,true},<br /> {access_model,open},<br /> {roster_groups_allowed,[]},<br /> {publish_model,publishers},<br /> {notification_type,headline},<br /> {max_payload_size,60000},<br /> {send_last_published_item,on_sub_and_presence},<br /> {deliver_notifications,true},<br /> {presence_based_delivery,false}] <p>=INFO REPORT==== 2011-06-15 09:56:18 ===<br />D(&lt;0.357.0&gt;:mod_sequence:67) : mod_sequence: Node created at &lt;&lt;&quot;localhost&quot;&gt;&gt;, &lt;&lt;&quot;pubsub.localhost&quot;&gt;&gt; is &lt;&lt;&quot;test1&quot;&gt;&gt; with<br />[{deliver_payloads,true},<br /> {notify_config,false},<br /> {notify_delete,false},<br /> {notify_retract,true},<br /> {notify_sub,false},<br /> {purge_offline,false},<br /> {persist_items,true},<br /> {max_items,10},<br /> {subscribe,true},<br /> {access_model,open},<br /> {roster_groups_allowed,[]},<br /> {publish_model,publishers},<br /> {notification_type,headline},<br /> {max_payload_size,60000},<br /> {send_last_published_item,on_sub_and_presence},<br /> {deliver_notifications,true},<br /> {presence_based_delivery,false}]</p></code></div> <p>Is this expected behaviour?</p> <p>I finally figured out how to dump stacktrace and here are the results. It is being called twice, but I am still not sure why. Here is what I see in the log file:</p> <div class="codeblock"><code>=INFO REPORT==== 2011-06-18 20:23:32 ===<br />D(&lt;0.357.0&gt;:mod_sequence:73) : mod_sequence: stack trace <br />[{mod_sequence,create_node,4},<br /> {ejabberd_hooks,run1,3},<br /> {ejabberd_hooks,run,3},<br /> {mod_pubsub,create_node,7},<br /> {mod_pubsub,do_route,7},<br /> {mod_pubsub,handle_info,2},<br /> {gen_server,handle_msg,5},<br /> {proc_lib,init_p_do_apply,3}] <p>=INFO REPORT==== 2011-06-18 20:23:32 ===<br />D(&lt;0.357.0&gt;:mod_sequence:75) : mod_sequence: Node created at &lt;&lt;&quot;localhost&quot;&gt;&gt;, &lt;&lt;&quot;pubsub.localhost&quot;&gt;&gt; is &lt;&lt;&quot;test1&quot;&gt;&gt; with <br />[{deliver_payloads,true},<br /> {notify_config,false},<br /> {notify_delete,false},<br /> {notify_retract,true},<br /> {notify_sub,false},<br /> {purge_offline,false},<br /> {persist_items,true},<br /> {max_items,10},<br /> {subscribe,true},<br /> {access_model,open},<br /> {roster_groups_allowed,[]},<br /> {publish_model,publishers},<br /> {notification_type,headline},<br /> {max_payload_size,60000},<br /> {send_last_published_item,on_sub_and_presence},<br /> {deliver_notifications,true},<br /> {presence_based_delivery,false}]</p> <p>=INFO REPORT==== 2011-06-18 20:23:32 ===<br />D(&lt;0.357.0&gt;:mod_sequence:73) : mod_sequence: stack trace <br />[{mod_sequence,create_node,4},<br /> {ejabberd_hooks,run1,3},<br /> {mod_pubsub,create_node,7},<br /> {mod_pubsub,do_route,7},<br /> {mod_pubsub,handle_info,2},<br /> {gen_server,handle_msg,5},<br /> {proc_lib,init_p_do_apply,3}]</p> <p>=INFO REPORT==== 2011-06-18 20:23:32 ===<br />D(&lt;0.357.0&gt;:mod_sequence:75) : mod_sequence: Node created at &lt;&lt;&quot;localhost&quot;&gt;&gt;, &lt;&lt;&quot;pubsub.localhost&quot;&gt;&gt; is &lt;&lt;&quot;test1&quot;&gt;&gt; with <br />[{deliver_payloads,true},<br /> {notify_config,false},<br /> {notify_delete,false},<br /> {notify_retract,true},<br /> {notify_sub,false},<br /> {purge_offline,false},<br /> {persist_items,true},<br /> {max_items,10},<br /> {subscribe,true},<br /> {access_model,open},<br /> {roster_groups_allowed,[]},<br /> {publish_model,publishers},<br /> {notification_type,headline},<br /> {max_payload_size,60000},<br /> {send_last_published_item,on_sub_and_presence},<br /> {deliver_notifications,true},<br /> {presence_based_delivery,false}]</p></code></div> Sun, 19 Jun 2011 03:28:02 +0000 kailesmith comment 57506 at https://www.ejabberd.im Great. Glad to see that you https://www.ejabberd.im/node/4772#comment-57504 <p>Great. Glad to see that you agree. I will make the changes, test them and submit them via bug tracker.</p> Wed, 15 Jun 2011 15:02:14 +0000 kailesmith comment 57504 at https://www.ejabberd.im Right, the best way would be https://www.ejabberd.im/node/4772#comment-57501 <p>Right, the best way would be to run two new hooks in mod_pubsub.</p> <p>The improvement looks useful. Once you have a patch that you like, you can create a ticket in the bug tracker describing the problem and attaching your patch as a proposed solution.</p> <p>Here's a preliminary implementation. I didn't test it.</p> <pre> --- mod_pubsub/mod_pubsub.erl +++ mod_pubsub/mod_pubsub.erl @@ -1783,13 +1783,16 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -&gt; case transaction(CreateNode, transaction) of {result, {NodeId, SubsByDepth, {Result, broadcast}}} -&gt; broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth), + ejabberd_hooks:run(pubsub_create_node, ServerHost, [ServerHost, Host, NodeId, NodeOptions, SubsByDepth]), case Result of default -&gt; {result, Reply}; _ -&gt; {result, Result} end; - {result, {_NodeId, _SubsByDepth, default}} -&gt; + {result, {NodeId, SubsByDepth, default}} -&gt; + ejabberd_hooks:run(pubsub_create_node, ServerHost, [ServerHost, Host, NodeId, NodeOptions, SubsByDepth]), {result, Reply}; - {result, {_NodeId, _SubsByDepth, Result}} -&gt; + {result, {NodeId, SubsByDepth, Result}} -&gt; + ejabberd_hooks:run(pubsub_create_node, ServerHost, [ServerHost, Host, NodeId, NodeOptions, SubsByDepth]), {result, Result}; Error -&gt; %% in case we change transaction to sync_dirty... @@ -1834,6 +1837,7 @@ delete_node(Host, Node, Owner) -&gt; end end, Reply = [], + ServerHost = dumb_get_serverhost(Host), case transaction(Host, Node, Action, transaction) of {result, {_, {SubsByDepth, {Result, broadcast, Removed}}}} -&gt; lists:foreach(fun({RNode, _RSubscriptions}) -&gt; @@ -1843,23 +1847,31 @@ delete_node(Host, Node, Owner) -&gt; Options = RNode#pubsub_node.options, broadcast_removed_node(RH, RN, NodeId, Type, Options, SubsByDepth) end, Removed), + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]), case Result of default -&gt; {result, Reply}; _ -&gt; {result, Result} end; {result, {_, {_, {Result, _Removed}}}} -&gt; + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]), case Result of default -&gt; {result, Reply}; _ -&gt; {result, Result} end; {result, {_, {_, default}}} -&gt; + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]), {result, Reply}; {result, {_, {_, Result}}} -&gt; + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]), {result, Result}; Error -&gt; Error end. +%% "pubsub.localhost.pubsub.example.org" --&gt; "localhost.pubsub.example.org" +dumb_get_serverhost(Host) -&gt; + string:join(string:substr(string:tokens(Host, "."), 2), "."). + %% @spec (Host, Node, From, JID, Configuration) -&gt; %% {error, Reason::stanzaError()} | %% {result, []} </pre> Wed, 15 Jun 2011 10:55:27 +0000 mfoss comment 57501 at https://www.ejabberd.im