1
votes

The problem I have is that the hook I defined is not being called on the event "user_send_packet". I did assume that any stanza (including messages) that is being sent would trigger this event.

I have taken into account the priority of how the hook is being called by setting it to '0'. In the log I have verified that the module is started ("mod_stanza_ack starting"). The erl file did compile, it only got the warning "gen_mod" is undefined, but I have read on a ejabberd mailing list that this is harmless and also that the variable "Host" is unused in line 12. Maybe this has something to do with it, but I cannot find out if this is the case.

-module(mod_stanza_ack).
-behaviour(gen_mod).

-include("ejabberd.hrl").

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

-export([on_user_send_packet/3]).


start(Host, _Opts) ->
    ?INFO_MSG("mod_stanza_ack starting", []),
    ejabberd_hooks:add(user_send_packet, global, ?MODULE, on_user_send_packet, 0),
    ok.

stop(Host) ->
    ?INFO_MSG("mod_stanza_ack stopping", []),
    ejabberd_hooks:delete(user_send_packet, global, ?MODULE, on_user_send_packet, 0),
    ok.

on_user_send_packet(From, To, Packet) ->
    ?INFO_MSG("mod_stanza_ack a package has been sent coming from: ~p", [From]),
    ?INFO_MSG("mod_stanza_ack a package has been sent to: ~p", [To]),
    ?INFO_MSG("mod_stanza_ack a package has been sent with the following packet: ~p",     [Packet]),
    Packet.
1

1 Answers

0
votes

The syntax looks OK and you have correct assumptions regarding the hook and compilation warnings. Which version of ejabberd do you use?

It seems there is bug/confusion in 'global' handling.

ejabberd_c2s which runs user_send_packet, runs it with Host as a scope. The implementation of scopes is pretty naive and 'global' callback is not hooked up under Host hook.

In my 2.1.6 there is still the 'buggy' behaviour and I could reproduce your case. To fix it add hook with Host, not 'global' keyword.