<!DOCTYPE html>
<html><head>
    <meta charset="UTF-8">
</head><body><p>I have developed an application in erlang and have place it inside the ebin folder of ejabberd. I had to decide a server to be able to host the game hence I chose ejabberd for it.I am using Pidgin as a client side messaging server.My strategy was to detect the message stanza sent by the client and extract the actual message from its body tag and use it as a function call to run my application.</p><p>I have created a custom module as</p><p><br></p><p>-module(customMod).<br>-behaviour(gen_mod).</p><p><br>-export([start/2,stop/1,depends/2,mod_opt_type/1,extractMessage/1]).<br>-include("logger.hrl").<br>-include("xmpp.hrl").<br>-include("ejabberd.hrl").</p><p>start(_Host, _Opts) -> <br> ejabberd_hooks:add(user_send_packet, _Host, ?MODULE,<br> extractMessage, 95).<br><br></p><p>stop(_Host) -> <br> ejabberd_hooks:delete(user_send_packet, _Host, ?MODULE, extractMessage,95).</p><p>depends(_Host, _Opts)->[{?MODULE,soft}].</p><p>mod_opt_type(_Option)-><br> ok.<br><br></p><p>extractMessage(Args)-><br>A=10,<br> ?INFO_MSG("hello buddy ~p",[A]),<br>Args.<br><br></p><p>Now to call this module I have written the following code snippet in ejabberd_router inside do_route:</p><p>do_route(OrigPacket) -><br> ?DEBUG("route:~n~s", [xmpp:pp(OrigPacket)]),<br>  </p><p>A=1,<br> To1 = xmpp:get_to(OrigPacket),<br> LDstDomain = To1#jid.lserver,<br> case xmpp:get_type(OrigPacket) of<br> get-><br> get;<br> result-><br> result;<br> error-><br> error;<br> probe-><br> probe;<br> available-><br> available;<br> set-><br> set;<br> chat-><br> ?INFO_MSG("Inside ejabberd router value of PacketType is ~p",[A]),<br> ejabberd_hooks:run_fold(user_receive_packet, LDstDomain, OrigPacket, ["dharun"])<br> end,</p><p> case ejabberd_hooks:run_fold(filter_packet, OrigPacket, []) of<br> drop -><br> ok;<br> Packet -><br> To = xmpp:get_to(Packet),<br> LDstDomain = To#jid.lserver,<br> Mod = get_backend(),<br> case Mod:find_routes(LDstDomain) of<br> [] -><br> ejabberd_s2s:route(Packet);<br> [Route] -><br> do_route(Packet, Route);<br> Routes -><br> From = xmpp:get_from(Packet),<br> balancing_route(From, To, Packet, Routes)<br> end,<br> ok<br> end.</p><p><br></p><p>So according to me my custom module should be called fro ejabberd_router but it is being called as I start my ejabberd and that to it is being called multiple times</p><p>ejabberd_log is:</p><p>(ejabberd@localhost)1> 18:44:06.134 [info] Application lager started on node ejabberd@localhost<br>18:44:06.137 [info] Application crypto started on node ejabberd@localhost<br>18:44:06.146 [info] Application sasl started on node ejabberd@localhost<br>18:44:06.156 [info] Application asn1 started on node ejabberd@localhost<br>18:44:06.156 [info] Application public_key started on node ejabberd@localhost<br>18:44:06.164 [info] Application ssl started on node ejabberd@localhost<br>18:44:06.176 [info] Application fast_yaml started on node ejabberd@localhost<br>18:44:06.191 [info] Application fast_tls started on node ejabberd@localhost<br>18:44:06.207 [info] Application fast_xml started on node ejabberd@localhost<br>18:44:06.212 [info] Application p1_utils started on node ejabberd@localhost<br>18:44:06.215 [info] Application stringprep started on node ejabberd@localhost<br>18:44:06.217 [info] Application xmpp started on node ejabberd@localhost<br>18:44:06.229 [info] Application cache_tab started on node ejabberd@localhost<br>18:44:06.252 [info] Application elixir started on node ejabberd@localhost<br>18:44:06.419 [info] Application mnesia started on node ejabberd@localhost<br>18:44:06.542 [warning] Module mod_last_odbc is deprecated, use mod_last with 'db_type: sql' instead<br>18:44:06.554 [warning] Module mod_offline_odbc is deprecated, use mod_offline with 'db_type: sql' instead<br>18:44:06.561 [warning] Module mod_privacy_odbc is deprecated, use mod_privacy with 'db_type: sql' instead<br>18:44:06.566 [warning] Module mod_private_odbc is deprecated, use mod_private with 'db_type: sql' instead<br>18:44:06.570 [warning] Module mod_pubsub_odbc is deprecated, use mod_pubsub with 'db_type: sql' instead<br>18:44:06.575 [warning] Module mod_roster_odbc is deprecated, use mod_roster with 'db_type: sql' instead<br>18:44:06.591 [warning] Module mod_vcard_odbc is deprecated, use mod_vcard with 'db_type: sql' instead<br>18:44:07.355 [info] Adding machine's DNS IPs to Erlang system:<br>[]<br>18:44:07.367 [info] FQDN used to check DIGEST-MD5 SASL authentication: DESKTOP-RI8MDR6<br>18:44:07.905 [info] Application p1_mysql started on node ejabberd@localhost<br>18:44:08.088 [warning] cyclic dependency detected between modules: [customMod,customMod]<br>18:44:08.088 [warning] module 'mod_mam' is recommended for module 'mod_muc' but is not found in the config<br>slot has started <br>18:44:08.100 [info] Inside customMod start function {ok,<0.444.0>}<br>18:44:08.187 [info] Application inets started on node ejabberd@localhost<br>18:44:08.202 [info] Start accepting TCP connections at 0.0.0.0:5222 for ejabberd_c2s<br>18:44:08.202 [info] ejabberd 17.03 is started in the node ejabberd@localhost in 2.38s<br>18:44:08.202 [info] Start accepting TCP connections at 0.0.0.0:5269 for ejabberd_s2s_in<br>18:44:08.202 [info] Application ejabberd started on node ejabberd@localhost<br>18:44:08.202 [info] Start accepting TCP connections at 0.0.0.0:5280 for ejabberd_http<br>18:44:15.864 [info] (<0.498.0>) Accepted connection 127.0.0.1:63043 -> 127.0.0.1:5222<br>18:44:16.046 [info] (tls|<0.498.0>) Accepted c2s PLAIN authentication for admin1@casino.com by sql backend from 127.0.0.1<br>18:44:16.085 [info] (<0.500.0>) Accepted connection 127.0.0.1:63044 -> 127.0.0.1:5222<br>18:44:16.179 [info] (tls|<0.500.0>) Accepted c2s PLAIN authentication for admin2@casino.com by sql backend from 127.0.0.1<br>18:44:16.204 [info] (tls|<0.498.0>) Opened c2s session for admin1@casino.com/-<br>18:44:16.266 [info] hello buddy 10<br>18:44:16.266 [info] hello buddy 10<br>18:44:16.374 [info] (tls|<0.500.0>) Opened c2s session for admin2@casino.com/-<br>18:44:16.436 [info] hello buddy 10<br>18:44:16.436 [info] hello buddy 10<br>18:44:16.468 [info] Outbound s2s connection started: casino.com -> proxy.eu.jabber.org<br>18:44:16.469 [info] hello buddy 10<br>18:44:16.469 [info] hello buddy 10<br>18:44:16.469 [info] hello buddy 10<br>18:44:16.469 [info] hello buddy 10<br>18:44:16.503 [info] hello buddy 10<br>18:44:16.503 [info] hello buddy 10<br>18:44:16.508 [info] Failed to establish outbound s2s connection casino.com -> proxy.eu.jabber.org: DNS lookup failed: non-existing domain; bouncing for 129 seconds<br>18:44:16.508 [info] hello buddy 10<br>18:44:16.639 [info] hello buddy 10<br>18:44:16.639 [info] hello buddy 10<br>18:44:16.640 [info] hello buddy 10<br>18:44:16.640 [info] hello buddy 10<br>18:44:16.641 [info] hello buddy 10<br>18:44:16.641 [info] hello buddy 10<br>18:44:16.642 [info] hello buddy 10<br>18:44:17.214 [info] hello buddy 10<br>18:44:17.309 [info] The value of mod inside sm is ejabberd_sm_mnesia<br>18:44:17.309 [info] hello buddy 10<br>18:44:17.379 [info] hello buddy 10<br>18:44:17.449 [info] The value of mod inside sm is ejabberd_sm_mnesia<br>18:44:17.449 [info] hello buddy 10<br>18:44:47.007 [info] hello buddy 10<br>18:44:47.007 [info] hello buddy 10<br>18:45:47.000 [info] hello buddy 10<br>18:45:47.000 [info] hello buddy 10<br>18:46:47.001 [info] hello buddy 10<br>18:46:47.002 [info] hello buddy 10<br>18:47:47.001 [info] hello buddy 10<br>18:47:47.001 [info] hello buddy 10<br>18:48:47.001 [info] hello buddy 10<br>18:48:47.001 [info] hello buddy 10<br>18:49:47.001 [info] hello buddy 10<br>18:49:47.002 [info] hello buddy 10<br>18:50:47.001 [info] hello buddy 10<br>18:50:47.002 [info] hello buddy 10<br>18:51:47.002 [info] hello buddy 10<br>18:51:47.004 [info] hello buddy 10<br>18:52:47.001 [info] hello buddy 10<br>18:52:47.002 [info] hello buddy 10<br>18:53:47.002 [info] hello buddy 10<br>18:53:47.003 [info] hello buddy 10</p><p>18:54:47.001 [info] hello buddy 10<br>18:54:47.002 [info] hello buddy 10<br>18:55:47.000 [info] hello buddy 10<br>18:55:47.001 [info] hello buddy 10<br>18:56:47.002 [info] hello buddy 10<br>18:56:47.002 [info] hello buddy 10<br>18:57:47.000 [info] hello buddy 10<br>18:57:47.001 [info] hello buddy 10<br>18:58:47.001 [info] hello buddy 10<br>18:58:47.001 [info] hello buddy 10<br>18:59:47.003 [info] hello buddy 10<br>18:59:47.004 [info] hello buddy 10<br>19:00:47.002 [info] hello buddy 10<br>19:00:47.004 [info] hello buddy 10<br>19:01:47.001 [info] hello buddy 10<br>19:01:47.001 [info] hello buddy 10<br>19:02:47.001 [info] hello buddy 10<br>19:02:47.001 [info] hello buddy 10<br>19:03:47.001 [info] hello buddy 10<br>19:03:47.002 [info] hello buddy 10<br>19:04:47.002 [info] hello buddy 10<br>19:04:47.003 [info] hello buddy 10<br>19:05:47.001 [info] hello buddy 10<br>19:05:47.002 [info] hello buddy 10<br>19:06:47.001 [info] hello buddy 10<br>19:06:47.002 [info] hello buddy 10<br>19:07:47.002 [info] hello buddy 10<br>19:07:47.003 [info] hello buddy 10<br>19:08:47.001 [info] hello buddy 10<br>19:08:47.002 [info] hello buddy 10<br>19:09:47.001 [info] hello buddy 10<br>19:09:47.001 [info] hello buddy 10<br>19:10:47.001 [info] hello buddy 10<br>19:10:47.001 [info] hello buddy 10<br>19:11:47.000 [info] hello buddy 10<br>19:11:47.001 [info] hello buddy 10<br>19:12:47.000 [info] hello buddy 10<br>19:12:47.000 [info] hello buddy 10<br>19:13:47.000 [info] hello buddy 10<br>19:13:47.000 [info] hello buddy 10<br>19:14:47.001 [info] hello buddy 10<br>19:14:47.001 [info] hello buddy 10<br>19:15:47.001 [info] hello buddy 10<br>19:15:47.001 [info] hello buddy 10<br></p><p><br></p><p>can anyone help?</p></body></html>