[erlang-questions] Hook user_send_packet is crashing when client tries to connect
Stefan Strigler
stefan.strigler@REDACTED
Wed Apr 5 18:11:29 CEST 2017
Hi,
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.
On Wed, Apr 5, 2017 at 3:08 PM Abhishek Ranjan <abhishek@REDACTED>
wrote:
> *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->*
>
> -module(newCust).
> -behaviour(gen_mod).
>
> -export([]).
>
> -export([start/2,stop/1,depends/2,mod_opt_type/1,myMessage/4]).
> -include("logger.hrl").
> -include("xmpp.hrl").
> -include("ejabberd.hrl").
>
> start(_Host, _Opts) ->
>
> ?INFO_MSG("Inside customMod start function ",[]),
> ejabberd_hooks:add(user_send_packet, _Host, ?MODULE,
> myMessage, 105),
> ok.
> stop(_Host) ->
> ejabberd_hooks:delete(user_send_packet, _Host, ?MODULE, myMessage,105).
>
> depends(_Host, _Opts)->[{?MODULE,soft}].
>
> mod_opt_type(_Option)->
> ok.
>
> myMessage(#xmlel{name = <<"message">>} = Pkt, _C2SState, _From, _To)->
>
> ?INFO_MSG("hello buddy ",[]),
> Pkt.
>
>
> *The log values are :*
>
> 2017-04-05 17:43:02.498 [info] <0.7.0> Application lager started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.502 [info] <0.7.0> Application crypto started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.511 [info] <0.7.0> Application sasl started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.521 [info] <0.7.0> Application asn1 started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.521 [info] <0.7.0> Application public_key started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.529 [info] <0.7.0> Application ssl started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.543 [info] <0.7.0> Application fast_yaml started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.559 [info] <0.7.0> Application fast_tls started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.575 [info] <0.7.0> Application fast_xml started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.579 [info] <0.7.0> Application p1_utils started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.581 [info] <0.7.0> Application stringprep started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.582 [info] <0.7.0> Application xmpp started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.595 [info] <0.7.0> Application cache_tab started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:02.618 [info] <0.7.0> Application elixir started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:02.786 [info] <0.7.0> Application mnesia started on node
> ejabberd@REDACTED
> 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
> 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
> 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
> 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
> 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
> 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
> 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
> 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:
> []
> 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
> 2017-04-05 17:43:04.176 [info] <0.7.0> Application p1_mysql started on
> node ejabberd@REDACTED
> 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
> 2017-04-05 17:43:04.309 [warning] <0.277.0>@gen_mod:sort_modules:157
> cyclic dependency detected between modules: [newCust,newCust]
> 2017-04-05 17:43:04.314 [info] <0.277.0>@newCust:start:17 Inside customMod
> start function
> 2017-04-05 17:43:04.443 [info] <0.7.0> Application inets started on node
> ejabberd@REDACTED
> 2017-04-05 17:43:04.458 [info] <0.325.0>@ejabberd_listener:init_tcp:149
> Start accepting TCP connections at 0.0.0.0:5222 for ejabberd_c2s
> 2017-04-05 17:43:04.458 [info] <0.326.0>@ejabberd_listener:init_tcp:149
> Start accepting TCP connections at 0.0.0.0:5269 for ejabberd_s2s_in
> 2017-04-05 17:43:04.458 [info] <0.37.0>@ejabberd_app:start:59 ejabberd
> 17.03 is started in the node ejabberd@REDACTED in 2.22s
> 2017-04-05 17:43:04.458 [info] <0.327.0>@ejabberd_listener:init_tcp:149
> Start accepting TCP connections at 0.0.0.0:5280 for ejabberd_http
> 2017-04-05 17:43:04.458 [info] <0.7.0> Application ejabberd started on
> node ejabberd@REDACTED
> 2017-04-05 17:43:09.676 [info] <0.325.0>@ejabberd_listener:accept:311
> (<0.491.0>) Accepted connection 127.0.0.1:63321 -> 127.0.0.1:5222
> 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 admin2@REDACTED by sql backend from 127.0.0.1
> 2017-04-05 17:43:09.981 [info] <0.492.0>@ejabberd_c2s:bind:410
> (tls|<0.491.0>) *Opened c2s session for admin2@REDACTED/-
> <http://admin2@casino.com/->*
> 2017-04-05 17:43:09.991 [error] <0.492.0>@*ejabberd_hooks:safe_apply:383
> Hook user_send_packet crashed when running newCust:myMessage/1:*
> ** *Reason* =
> {error,undef,[{newCust,myMessage,[],[{{iq,<<"purple701889db">>,set,<<"en">>,{jid,<<"admin2">>,<<"
> casino.com">>,<<"-">>,<<"admin2">>,<<"casino.com
> ">>,<<"-">>},{jid,<<"admin2">>,<<"casino.com">>,<<>>,<<"admin2">>,<<"
> casino.com">>,<<>>},[{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 => <<"casino.com">>,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">>,<<"
> casino.com">>,<<>>},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 => <<"casino.com">>,zlib
> => false,lang => <<"en">>,ip => {{127,0,0,1},63321},mgmt_max_queue =>
> 1000,stream_version => {1,0},resource => <<"-">>,jid =>
> {jid,<<"admin2">>,<<"casino.com">>,<<"-">>,<<"admin2">>,<<"casino.com">>,<<"-">>},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">>,<<"casino.com">>,<<>>},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,...},...]}
>
>
>
> ** *Arguments* =
> [{{iq,<<"purple701889db">>,set,<<"en">>,{jid,<<"admin2">>,<<"casino.com
> ">>,<<"-">>,<<"admin2">>,<<"casino.com">>,<<"-">>},{jid,<<"admin2">>,<<"
> casino.com">>,<<>>,<<"admin2">>,<<"casino.com">>,<<>>},[{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 => <<"casino.com">>,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">>,<<"
> casino.com">>,<<>>},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 => <<"casino.com">>,zlib
> => false,lang => <<"en">>,ip => {{127,0,0,1},63321},mgmt_max_queue =>
> 1000,stream_version => {1,0},resource => <<"-">>,jid =>
> {jid,<<"admin2">>,<<"casino.com">>,<<"-">>,<<"admin2">>,<<"casino.com">>,<<"-">>},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">>,<<"casino.com">>,<<>>},nil,nil}},owner =>
> <0.492.0>,stream_header_sent => true,pres_a => {0,nil},stream_authenticated
> => true,conn => c2s_tls}}]
>
>
> *And the same error and reason is getting printed again and again after
> some time as the client tries to connect with the server.*
>
> Can anyone help please?
>
> Also i am new to erlang and ejabberd so can anyone tell me how to create
> custom hooks in ejabberd?
>
> Thank you in advance
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170405/ccdd7399/attachment.htm>
More information about the erlang-questions
mailing list