0

I am willing to develop a custom module by using a hook "user_send_packet"

For now I have deleted custom work from the function and compiled the code. But when I use this module... Server is crashing and restarting continuously. I am not getting whats going wrong ... simplified code is as below :

-module(mod_gpcustom).

-behaviour(gen_mod).

%% API
-export([start/2, stop/1]).

-export([user_send_packet/4,
     mod_opt_type/1]).

-include_lib("stdlib/include/ms_transform.hrl").
-include("jlib.hrl").

%%%===================================================================
%%% API
%%%===================================================================
start(Host, _Opts) ->

    ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
                       user_send_packet, 600),
    ok.

stop(Host) ->
    ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
              user_send_packet, 600),
    ok.


user_send_packet(Pkt, C2SState, JID, Peer) ->
    LUser = JID#jid.luser,
    LServer = JID#jid.lserver,
    ok.



mod_opt_type(cache_life_time) ->
    fun (I) when is_integer(I), I > 0 -> I end;
mod_opt_type(cache_size) ->
    fun (I) when is_integer(I), I > 0 -> I end;
mod_opt_type(db_type) -> fun gen_mod:v_db/1;
mod_opt_type(default) ->
    fun (always) -> always;
    (never) -> never;
    (roster) -> roster
    end;
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(store_body_only) ->
    fun (B) when is_boolean(B) -> B end;
mod_opt_type(_) ->
    [cache_life_time, cache_size, db_type, default, iqdisc,
     store_body_only].
Gopal S Rathore
  • 9,885
  • 3
  • 30
  • 38
  • 1
    What about providing more information, like for example what are the error in the log file for example ? That would be helpful to get an idea of what the issue could be. – Mickaël Rémond Dec 08 '15 at 14:10
  • when I see the log, error-log and crash log... I dont see any error related to this module specifically... but there are some errors... I can show that.... – Gopal S Rathore Dec 08 '15 at 14:17

1 Answers1

2

As described in documentation, the hook you use expect that your function will return an XMPP packet structure:

user_send_packet(Packet, C2SState, From, To) -> Packet

You can see that in the doc: http://docs.ejabberd.im/developer/hooks/

So your function should not return ok but a packet:

user_send_packet(Pkt, _C2SState, _JID, _Peer) ->
    Pkt.

It should be obvious to catch by reading the badmatch error in your ejabberd log file, but unfortunately, you did not post them.

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44