[ejabberd] Make an IQ inside auth module

Magnus Henoch mange at freemail.hu
Thu Sep 23 22:55:12 MSD 2010

Anton Belyaev <anton.belyaev at gmail.com> writes:

> I am writing a custom auth module. The module is going to send an IQ
> to a component to check if user password is valid.
> So, I want do send an IQ from check_password(User, _Server, Password)
> function in my auth module.
> How do I send an IQ and receive its response right inside the function?
> Is there a blocking (synchronous) function in ejabberd to make IQ requests?

Have a look at mod_caps:feature_request/4:

    IQ = #iq{type = get,
             xmlns = ?NS_DISCO_INFO,
             sub_el = [{xmlelement, "query",
                        [{"xmlns", ?NS_DISCO_INFO},
                         {"node", Node ++ "#" ++ SubNode}],
    F = fun(IQReply) ->
                  IQReply, Host, From, Caps, SubNodes)
      jlib:make_jid("", Host, ""), From, IQ, F);

Here, F is a function that gets called once you get an IQ response.  As
you'll see from the surrounding code, the feature_response function
comes right after this piece of code, so it's almost as if it were in
the same function :)  Though strictly speaking it's not blocking, of

Magnus Henoch

More information about the ejabberd mailing list