Introduction
ejabberd internal modules can register themselves to handle IQ using a specific namespace, in a way similar to the hooks mechanism.
Example
The module mod_last.erl is using the IQ handling mechanism. It also uses the events/hooks mechanism.
API
gen_iq_handler:add_iq_handler(Scope, Host, Namespace, Module, Function, IQDisc) gen_iq_handler:remove_iq_handler(Scope, Host, Namespace, Module, Function, IQDisc) * Scope = ejabberd_local | ejabberd_sm * Namespace = string() (some namespaces macros are defined in jlib.hrl) * Host = string() * Module = atom() * Fonction = atom() * IQDisc = no_queue | one_queue | {queues, N} | parallel * N = integer()
ejabberd_local Scope registers IQ that are addressed to the server itself. ejabberd_sm Scope registers all other IQ.
Host is the name of the virtual host related to the IQ.
Module and Function describe the handler function to be called when the IQ with Namespace is received. Handler function must have the following type:
Module:Function(From, To, IQ) -> IQ * From = To = #jid * IQ = #iq
The handler function returns the result IQ.
IQDisc describes how concurrent IQ are handled:
- no_queue: no thread is created to run the handler
- one_queue: one thread is dedicated to run the handler
- {queues, N}: N threads are created to run the handler
- parallel: one thread is created for each IQ received