Produits Support Open Source Company
 
 
 
Home > Wiki > ejabberd events and hooks

Article - Talk ejabberd events and hooks

Return to ejabberd module development

Introduction

ejabberd provides an event mechanism. Each module can subscribe to events and a hook in the module code is called when the event occurs.

Example

The module mod_offline.erl is an example of how the events/hooks mechanism can be used.

API

ejabberd_hooks:add(HookHostModule, Function, Priority)
ejabberd_hooks:remove(HookHostModule, Function, Priority)
Hook atom()
Host string()
Module atom()
* Function = 
atom()
Priority integer() 

The Hook parameter is the name of the event (see below). Host is the name of the virtual host related to the event. Module and Function describe the hook to be called when the event occurs. Priority is the hook rank, to determine in which order the hooks are run (when several hooks are defined for the same event), use it if you have dependencies between hooks.

List of events

The list of available events, and the type of corresponding hooks, is described below.

Events

adhoc_local_items(AccFromToLang) -> Adhoc
adhoc_sm_items
(AccFromToLang) -> Adhoc
c2s_stream_features
(Acc)
c2s_unauthenticated_iq(AccServerIQ) -> Adhoc
disco_local_features
(AccFromToNodeLang) -> Adhoc
disco_local_identity
(AccFromToNodeLang) -> Adhoc
disco_local_items
(AccFromToNodeLang) -> Adhoc
disco_sm_features
(AccFromToNodeLang) -> Adhoc
disco_sm_identity
(AccFromToNodeLang) -> Adhoc
disco_sm_items
(AccFromToNodeLang) -> Adhoc
ejabberd_ctl_process
(Args) -> CtlStatus
filter_packet
({FromToPacket}) -> {FromToPacket}
local_send_to_resource_hook
(FromToPacket) -> ok
offline_message_hook
(FromToPacket) -> ok
privacy_check_packet
(AccUserServerPrivacyList{FromToPacket}Dir) -> Auth
privacy_get_user_list
(AccUserServer) -> PrivacyList
privacy_iq_get
(AccFromToIQ) -> {resultPacket} {errorError}
privacy_iq_set
(AccFromToIQ) -> {resultPacket} {errorError}
privacy_updated_list
(AccOldPrivacyListNewPrivacyList) -> PrivacyList
pubsub_publish_item
(FromToNodeItemIDPayload) -> ok
remove_user
(UserServer) -> ok
resend_offline_messages_hook
(AccUserServer) -> [Route]
resend_subscription_requests_hook
(AccUserServer) -> [Packet]
roster_get
(Acc{UserServer}) -> [RosterItem]
roster_get_jid_info
(AccUserServerJID) -> {SubscriptionGroups}
roster_get_subscription_lists
(AccUserServer) -> {[FromSubscription][ToSubscription]}
roster_in_subscription
(AccUserServerJIDSubscriptionTypeReason) -> bool()
roster_out_subscription(AccUserServerJIDSubscriptionTypeReason) -> bool()
roster_process_item(RosterItemServer) -> RosterItem
set_presence_hook
(UserServerResourcePriority) -> none
sm_register_connection_hook
(SIDJID) -> ok
sm_remove_connection_hook
(SIDJID) -> ok
unset_presence_hook
(UserServerResourceStatus) -> void()
user_available_hook(JID) -> ok
user_receive_packet
(JIDFromToPacket) -> ok
user_send_packet
(FromToPacket) -> ok 

Types

To = From = JID = ServerJID = #jid (see jlib)
Packet = Payload = {xmlelement, Name, Attrs, SubEl}
IQ = #iq (see jlib)
Error = ?STANZA_ERROR/3 (see jlib.h)
Lang = string()
Dir = in | out
Auth = allow | deny
PrivacyList = OldPrivacyList = NewPrivacyList = none | #userlist
CtlStatus = false | ?STATUS_SUCCESS | ?STATUS_ERROR | ?STATUS_USAGE | ?STATUS_BADRPC (see ejabberd_ctl.hrl”)
Adhoc = {result, I} | {error, Error} | empty
Arg = [string()]
Node = [string()]
ItemID = string()
Route = {route, From, To, Packet
RosterItem = #roster (see mod_roster.hrl)
Subscription = none | from | to | both | remove
SubscriptionType = subscribe | unsubscribe
Reason = string()
Groups = [string()]
SimpleJID = FromSubscription = ToSubscription = {User, Server, Resource}
User = string()
Server = string()
Resource = string()
Status = string()
SID = {Time, pid()}
Time = {MegaSecs, Secs, MicroSecs} (see erlang:now/0)
MegaSecs = Secs = MicroSecs = int()
Acc = same type as the return type of the function
 
 
 
Valid HTML 4.01!   Valid CSS!