[ejabberd] Make an IQ inside auth module

Anton Belyaev anton.belyaev at gmail.com
Tue Sep 28 17:04:51 MSD 2010

>> 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) ->
>                feature_response(
>                  IQReply, Host, From, Caps, SubNodes)
>        end,
>    ejabberd_local:route_iq(
>      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
> course.

Thanks Badlop, Magnus!

Finally I did the trick. Code snippet and comments are here:

More information about the ejabberd mailing list