Produits Support Open Source Company
 
 
 
Home > Wiki > ejabberd IQ handlers

Article - Talk ejabberd IQ handlers

Return to ejabberd module development

Introduction

ejabberd internal modules can register themselves to handle IQ using a specific namespace, in a way similar to the events and hooks mechanism.

Example

The module mod_last.erl is using the IQ handling mechanism. It also uses the events and hooks mechanism.

API

gen_iq_handler:add_iq_handler(ScopeHostNamespaceModule, Function, IQDisc)
gen_iq_handler:remove_iq_handler(ScopeHostNamespaceModule, 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 {queuesN} parallel
integer() 

ejabberd_local Scope registers IQ that are addressed to the server itself. ejabberd_sm Scope registers IQ addressed to a bare JID of an account, where the serverpart is the server.
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(FromToIQ) -> 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

 
 
 
Valid HTML 4.01!   Valid CSS!