[ejabberd] Can someone tell me what am I doing wrong?

Santiago Ignacio Poli santiago at etermax.com
Thu Apr 30 16:09:27 MSK 2015


Recently I've been trying to implement my own IQ Handlers in ejabberd. I've
been using the hook mechanism for some time now but I think IQ Handlers are
more suitable for the features I need to implement.

I've made a simple IQ handler to learn how to do this and encountered a
problem: Every time I send my custom IQ from my client, ejabberd throws
this exception (and don't return anything to the client):

09:59:28.135 [error] gen_fsm <0.574.0> in state session_established
terminated with reason: bad argument in call to
xml:element_to_binary({xmlel,<<"iq">>,[{<<"from">>,<<"localhost">>},{<<"to">>,<<"1 at localhost/11909950391430398765210138">>},...],...})
in ejabberd_c2s:send_element/2 line 1908
09:59:28.136 [error] CRASH REPORT Process <0.574.0> with 0 neighbours
exited with reason: bad argument in call to
xml:element_to_binary({xmlel,<<"iq">>,[{<<"from">>,<<"localhost">>},{<<"to">>,<<"1 at localhost/11909950391430398765210138">>},...],...})
in ejabberd_c2s:send_element/2 line 1908
09:59:28.136 [error] Supervisor ejabberd_c2s_sup had child undefined
started with {ejabberd_c2s,start_link,undefined} at <0.574.0> exit with
reason bad argument in call to
xml:element_to_binary({xmlel,<<"iq">>,[{<<"from">>,<<"localhost">>},{<<"to">>,<<"1 at localhost/11909950391430398765210138">>},...],...})
in ejabberd_c2s:send_element/2 line 1908 in context child_terminated

The code inside the handler is called correctly (I echoed things to test
that) but the problem is when the function tries to return the response.

Here's my code:

-module(mod_iq_test).

-author("poli").

-behaviour(gen_mod).

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

-include("jlib.hrl").
-define(IQ_CUSTOM, <<"test:iq:custom">>).

start(Host, _) ->
  error_logger:error_msg("Started mod_block"),
  gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?IQ_CUSTOM,
?MODULE, process_local_iq, one_queue),
  ok.

stop(Host) ->
  gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?IQ_CUSTOM),
  ok.

process_local_iq(From,_ ,IQ) ->
  User = From#jid.luser,
  error_logger:error_msg("User: ~s", [User]),
  IQ#iq{type = result,
    sub_el =
    [#xmlel{
      name = <<"query">>,
      attrs = [{<<"xmlns">>, ?IQ_CUSTOM}, {<<"test">>,1}],
      children = []
    }]
  }.

The problem occurs when I send stanzas like this:
*<iq id="test1" to="localhost" type="get"><query
xmlns="test:iq:custom"/></iq>*

Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20150430/0b1f36cb/attachment.html>


More information about the ejabberd mailing list