<div dir="ltr">Hi, <div><br></div><div>this is because you only have one clause, the one for packets of type "message" but none for all the others. Check the example I've sent to you, it had a second clause that acts as a catch all.</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 5, 2017 at 3:08 PM Abhishek Ranjan <<a href="mailto:abhishek@blacklightsw.com">abhishek@blacklightsw.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u class="gmail_msg"></u>
<div class="gmail_msg"><p class="gmail_msg"><strong class="gmail_msg">I have created a custom module in ejabberd that should print hello buddy in logs only when there is a exchange of message stanzas between the client and server: Here is the code-></strong></p><p class="gmail_msg">-module(newCust).<br class="gmail_msg">-behaviour(gen_mod).</p><p class="gmail_msg">-export([]).</p><p class="gmail_msg">-export([start/2,stop/1,depends/2,mod_opt_type/1,myMessage/4]).<br class="gmail_msg">-include("logger.hrl").<br class="gmail_msg">-include("xmpp.hrl").<br class="gmail_msg">-include("ejabberd.hrl").</p><p class="gmail_msg">start(_Host, _Opts) -></p><p class="gmail_msg">?INFO_MSG("Inside customMod start function ",[]),<br class="gmail_msg"> ejabberd_hooks:add(user_send_packet, _Host, ?MODULE,<br class="gmail_msg"> myMessage, 105),<br class="gmail_msg"> ok.<br class="gmail_msg">stop(_Host) -> <br class="gmail_msg"> ejabberd_hooks:delete(user_send_packet, _Host, ?MODULE, myMessage,105).</p><p class="gmail_msg">depends(_Host, _Opts)->[{?MODULE,soft}].</p><p class="gmail_msg">mod_opt_type(_Option)-><br class="gmail_msg"> ok.</p><p class="gmail_msg">myMessage(#xmlel{name = <<"message">>} = Pkt, _C2SState, _From, _To)-></p><p class="gmail_msg">?INFO_MSG("hello buddy ",[]),<br class="gmail_msg">Pkt.<br class="gmail_msg"></p><p class="gmail_msg"><br class="gmail_msg"></p><p class="gmail_msg"><strong class="gmail_msg">The log values are :</strong></p><p class="gmail_msg">2017-04-05 17:43:02.498 [info] <0.7.0> Application lager started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.502 [info] <0.7.0> Application crypto started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.511 [info] <0.7.0> Application sasl started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.521 [info] <0.7.0> Application asn1 started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.521 [info] <0.7.0> Application public_key started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.529 [info] <0.7.0> Application ssl started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.543 [info] <0.7.0> Application fast_yaml started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.559 [info] <0.7.0> Application fast_tls started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.575 [info] <0.7.0> Application fast_xml started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.579 [info] <0.7.0> Application p1_utils started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.581 [info] <0.7.0> Application stringprep started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.582 [info] <0.7.0> Application xmpp started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.595 [info] <0.7.0> Application cache_tab started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.618 [info] <0.7.0> Application elixir started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.786 [info] <0.7.0> Application mnesia started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:02.900 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_last_odbc is deprecated, use mod_last with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:02.911 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_offline_odbc is deprecated, use mod_offline with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:02.918 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_privacy_odbc is deprecated, use mod_privacy with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:02.922 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_private_odbc is deprecated, use mod_private with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:02.926 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_pubsub_odbc is deprecated, use mod_pubsub with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:02.930 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_roster_odbc is deprecated, use mod_roster with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:02.944 [warning] <0.37.0>@ejabberd_config:emit_deprecation_warning:1427 Module mod_vcard_odbc is deprecated, use mod_vcard with 'db_type: sql' instead<br class="gmail_msg">2017-04-05 17:43:03.643 [info] <0.37.0>@ejabberd_app:add_windows_nameservers:132 Adding machine's DNS IPs to Erlang system:<br class="gmail_msg">[]<br class="gmail_msg">2017-04-05 17:43:03.654 [info] <0.279.0>@cyrsasl_digest:start:62 FQDN used to check DIGEST-MD5 SASL authentication: DESKTOP-RI8MDR6<br class="gmail_msg">2017-04-05 17:43:04.176 [info] <0.7.0> Application p1_mysql started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:04.308 [warning] <0.277.0>@gen_mod:sort_modules:149 module 'mod_mam' is recommended for module 'mod_muc' but is not found in the config<br class="gmail_msg">2017-04-05 17:43:04.309 [warning] <0.277.0>@gen_mod:sort_modules:157 cyclic dependency detected between modules: [newCust,newCust]<br class="gmail_msg">2017-04-05 17:43:04.314 [info] <0.277.0>@newCust:start:17 Inside customMod start function <br class="gmail_msg">2017-04-05 17:43:04.443 [info] <0.7.0> Application inets started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:04.458 [info] <0.325.0>@ejabberd_listener:init_tcp:149 Start accepting TCP connections at <a href="http://0.0.0.0:5222" class="gmail_msg" target="_blank">0.0.0.0:5222</a> for ejabberd_c2s<br class="gmail_msg">2017-04-05 17:43:04.458 [info] <0.326.0>@ejabberd_listener:init_tcp:149 Start accepting TCP connections at <a href="http://0.0.0.0:5269" class="gmail_msg" target="_blank">0.0.0.0:5269</a> for ejabberd_s2s_in<br class="gmail_msg">2017-04-05 17:43:04.458 [info] <0.37.0>@ejabberd_app:start:59 ejabberd 17.03 is started in the node ejabberd@localhost in 2.22s<br class="gmail_msg">2017-04-05 17:43:04.458 [info] <0.327.0>@ejabberd_listener:init_tcp:149 Start accepting TCP connections at <a href="http://0.0.0.0:5280" class="gmail_msg" target="_blank">0.0.0.0:5280</a> for ejabberd_http<br class="gmail_msg">2017-04-05 17:43:04.458 [info] <0.7.0> Application ejabberd started on node ejabberd@localhost<br class="gmail_msg">2017-04-05 17:43:09.676 [info] <0.325.0>@ejabberd_listener:accept:311 (<0.491.0>) Accepted connection <a href="http://127.0.0.1:63321" class="gmail_msg" target="_blank">127.0.0.1:63321</a> -> <a href="http://127.0.0.1:5222" class="gmail_msg" target="_blank">127.0.0.1:5222</a><br class="gmail_msg">2017-04-05 17:43:09.807 [info] <0.492.0>@ejabberd_c2s:handle_auth_success:439 (tls|<0.491.0>) Accepted c2s PLAIN authentication for <a href="mailto:admin2@casino.com" class="gmail_msg" target="_blank">admin2@casino.com</a> by sql backend from 127.0.0.1<br class="gmail_msg">2017-04-05 17:43:09.981 [info] <0.492.0>@ejabberd_c2s:bind:410 (tls|<0.491.0>) <strong class="gmail_msg">Opened c2s session for <a href="http://admin2@casino.com/-" class="gmail_msg" target="_blank">admin2@casino.com/-</a></strong><br class="gmail_msg">2017-04-05 17:43:09.991 [error] <0.492.0>@<strong class="gmail_msg">ejabberd_hooks:safe_apply:383 Hook user_send_packet crashed when running newCust:myMessage/1:</strong><br class="gmail_msg">** <strong class="gmail_msg">Reason</strong> = {error,undef,[{newCust,myMessage,[],[{{iq,<<"purple701889db">>,set,<<"en">>,{jid,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>},{jid,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>},[{xmlel,<<"session">>,[{<<"xmlns">>,<<"urn:ietf:params:xml:ns:xmpp-session">>}],[]}],#{ip => {127,0,0,1}}},#{mgmt_stanzas_in => 0,xmlns => <<"jabber:client">>,stream_encrypted => true,tls_enabled => true,socket => {socket_state,fast_tls,{tlssock,#Port<0.23143>,#Port<0.23190>},<0.491.0>},mod => ejabberd_c2s,server => <<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,mgmt_state => inactive,mgmt_max_timeout => 300,stream_restarted => true,auth_module => ejabberd_auth_sql,stream_id => <<"15132958958157338735">>,mgmt_ack_timeout => 60000,privacy_list => {userlist,none,[],false},stream_timeout => infinity,sid => {{1491,394389,1},<0.492.0>},pres_f => {1,{{<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>},nil,nil}},tls_options => [compression_none,{protocol_options,<<"no_sslv3">>},{certfile,<<"C:\\ProgramData\\ejabberd\\conf\\server.pem">>}],tls_required => false,mgmt_timeout => 300,socket_monitor => #Ref<0.0.2.141>,stream_compressed => false,mgmt_resend => false,mgmt_stanzas_out => 0,csi_state => active,lserver => <<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,zlib => false,lang => <<"en">>,ip => {{127,0,0,1},63321},mgmt_max_queue => 1000,stream_version => {1,0},resource => <<"-">>,jid => {jid,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>},csi_queue => {0,0,#{}},shaper => c2s_shaper,user => <<"admin2">>,access => c2s,stream_state => established,tls_verify => false,sockmod => ejabberd_socket,stream_direction => in,mgmt_stanzas_req => 0,pres_t => {1,{{<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>},nil,nil}},owner => <0.492.0>,stream_header_sent => true,pres_a => {0,nil},stream_authenticated => true,conn => c2s_tls}}]},{ejabberd_hooks,safe_apply,[{file,"src/ejabberd_hooks.erl"},{line,380}],4},{ejabberd_hooks,run_fold1,[{file,"src/ejabberd_hooks.erl"},{line,364}],4},{ejabberd_c2s,...},...]}</p><p class="gmail_msg"><br class="gmail_msg"></p><p class="gmail_msg"><br class="gmail_msg">** <strong class="gmail_msg">Arguments</strong> = [{{iq,<<"purple701889db">>,set,<<"en">>,{jid,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>},{jid,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>},[{xmlel,<<"session">>,[{<<"xmlns">>,<<"urn:ietf:params:xml:ns:xmpp-session">>}],[]}],#{ip => {127,0,0,1}}},#{mgmt_stanzas_in => 0,xmlns => <<"jabber:client">>,stream_encrypted => true,tls_enabled => true,socket => {socket_state,fast_tls,{tlssock,#Port<0.23143>,#Port<0.23190>},<0.491.0>},mod => ejabberd_c2s,server => <<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,mgmt_state => inactive,mgmt_max_timeout => 300,stream_restarted => true,auth_module => ejabberd_auth_sql,stream_id => <<"15132958958157338735">>,mgmt_ack_timeout => 60000,privacy_list => {userlist,none,[],false},stream_timeout => infinity,sid => {{1491,394389,1},<0.492.0>},pres_f => {1,{{<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>},nil,nil}},tls_options => [compression_none,{protocol_options,<<"no_sslv3">>},{certfile,<<"C:\\ProgramData\\ejabberd\\conf\\server.pem">>}],tls_required => false,mgmt_timeout => 300,socket_monitor => #Ref<0.0.2.141>,stream_compressed => false,mgmt_resend => false,mgmt_stanzas_out => 0,csi_state => active,lserver => <<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,zlib => false,lang => <<"en">>,ip => {{127,0,0,1},63321},mgmt_max_queue => 1000,stream_version => {1,0},resource => <<"-">>,jid => {jid,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>,<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<"-">>},csi_queue => {0,0,#{}},shaper => c2s_shaper,user => <<"admin2">>,access => c2s,stream_state => established,tls_verify => false,sockmod => ejabberd_socket,stream_direction => in,mgmt_stanzas_req => 0,pres_t => {1,{{<<"admin2">>,<<"<a href="http://casino.com" class="gmail_msg" target="_blank">casino.com</a>">>,<<>>},nil,nil}},owner => <0.492.0>,stream_header_sent => true,pres_a => {0,nil},stream_authenticated => true,conn => c2s_tls}}]</p><p class="gmail_msg"><br class="gmail_msg"></p><p class="gmail_msg"><strong class="gmail_msg">And the same error and reason is getting printed again and again after some time as the client tries to connect with the server.</strong></p><p class="gmail_msg">Can anyone help please?</p><p class="gmail_msg">Also i am new to erlang and ejabberd so can anyone tell me how to create custom hooks in ejabberd?</p><p class="gmail_msg">Thank you in advance</p></div>
_______________________________________________<br class="gmail_msg">
erlang-questions mailing list<br class="gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg">
</blockquote></div>