<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">

    <title type="text">Process&#45;one</title>
    <subtitle type="text">Process&#45;one</subtitle>
    <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/" />
    <link rel="self" type="application/atom+xml" href="http://www.process-one.net/en/wiki/Special:Recentchanges_Atom" />
    <updated>2010-02-10T14:22:22Z</updated>
    <rights>Copyright (c) 2006, contact@process-one.net</rights>
    <generator uri="http://www.pmachine.com/" version="1.6.8">ExpressionEngine</generator>
    <id>tag:process-one.net,2010:02:10:wiki</id>


    <entry>
      <title>ejabberd events and hooks</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/ejabberd_events_and_hooks/" />
      <id>tag:process-one.net,2010:wiki:ejabberd events and hooks/6.147</id>
      <published>2010-02-10T14:22:22Z</published>
      <updated>2010-02-10T14:22:22Z</updated>
      <author>
            <name>Badlop</name>
            <email>badlop@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<p><em>Return to <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_module_development%2F" title="ejabberd_module_development">ejabberd module development</a></em></p>

	<h2>Introduction</h2>

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

	<h2>Example</h2>

	<p>The module <a href="https://forge.process-one.net/browse/ejabberd/trunk/src/mod_offline.erl?r=trunk">mod_offline.erl</a> is an example of how the events/hooks mechanism can be used.</p>

	<h2><span class="caps">API</span></h2>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">ejabberd_hooks</span><span style="color: #007700">:</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">Hook</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Module</span><span style="color: #007700">,&nbsp;Function,&nbsp;</span><span style="color: #0000BB">Priority</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">ejabberd_hooks</span><span style="color: #007700">:</span><span style="color: #0000BB">remove</span><span style="color: #007700">(</span><span style="color: #0000BB">Hook</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Module</span><span style="color: #007700">,&nbsp;Function,&nbsp;</span><span style="color: #0000BB">Priority</span><span style="color: #007700">)<br />*&nbsp;</span><span style="color: #0000BB">Hook&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">atom</span><span style="color: #007700">()<br />*&nbsp;</span><span style="color: #0000BB">Host&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()<br />*&nbsp;</span><span style="color: #0000BB">Module&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">atom</span><span style="color: #007700">()<br />*&nbsp;Function&nbsp;=&nbsp;</span><span style="color: #0000BB">atom</span><span style="color: #007700">()<br />*&nbsp;</span><span style="color: #0000BB">Priority&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">integer</span><span style="color: #007700">()&nbsp;</span>
</span>
</code></div>

	<ul>
		<li>The <em>Hook</em> parameter is the name of the event (see below).</li>
		<li>The <em>Host</em> parameter is the name of the virtual host related to the event.</li>
		<li>The <em>Module</em> and <em>Function</em> parameters describe the hook to be called when the event occurs.</li>
		<li>The <em>Priority</em> parameter 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.</li>
	</ul>

	<p>To stop ejabberd from calling other functions in that hook, your function must return the atom() <em>stop</em>. An another way to stop the call chain is to return tuple &#123;stop, Val&#125; to override the return value.</p>

	<h2>List of events</h2>

	<p>The list of available events, and the type of corresponding hooks, is described below.</p>

	<h3>Events</h3>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">adhoc_local_items</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />adhoc_sm_items</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />c2s_stream_features</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">c2s_unauthenticated_iq</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IQ</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />disco_local_features</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />disco_local_identity</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />disco_local_items</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />disco_sm_features</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />disco_sm_identity</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />disco_sm_items</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Lang</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Adhoc<br />ejabberd_ctl_process</span><span style="color: #007700">(</span><span style="color: #0000BB">Args</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">CtlStatus<br />filter_packet</span><span style="color: #007700">(</span><span style="color: #0000BB">&#123;From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet&#125;</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#123;From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet&#125;<br />local_send_to_resource_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />offline_message_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />privacy_check_packet</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PrivacyList</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#123;From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet&#125;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Dir</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">Auth<br />privacy_get_user_list</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">PrivacyList<br />privacy_iq_get</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IQ</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#123;result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet&#125;&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">&#123;error</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Error&#125;<br />privacy_iq_set</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IQ</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#123;result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet&#125;&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">&#123;error</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Error&#125;<br />privacy_updated_list</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">OldPrivacyList</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NewPrivacyList</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">PrivacyList<br />pubsub_publish_item</span><span style="color: #007700">(</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Node</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ItemID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Payload</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />remove_user</span><span style="color: #007700">(</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />resend_offline_messages_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#91;Route&#93;<br />resend_subscription_requests_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#91;Packet&#93;<br />roster_get</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#123;User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server&#125;</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#91;RosterItem&#93;<br />roster_get_jid_info</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">JID</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#123;Subscription</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Groups&#125;<br />roster_get_subscription_lists</span><span style="color: #007700">(</span><span style="color: #0000BB">Acc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#123;&#91;FromSubscription&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;ToSubscription&#93;&#125;<br />roster_in_subscription</span><span style="color: #007700">(</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">JID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SubscriptionType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Reason</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">bool</span><span style="color: #007700">()<br /></span><span style="color: #0000BB">roster_out_subscription</span><span style="color: #007700">(</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">JID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SubscriptionType</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">bool</span><span style="color: #007700">()<br /></span><span style="color: #0000BB">roster_process_item</span><span style="color: #007700">(</span><span style="color: #0000BB">RosterItem</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">RosterItem<br />set_presence_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Resource</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">none<br />sm_register_connection_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">SID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">JID</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />sm_remove_connection_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">SID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">JID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SessionInfo</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />unset_presence_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">User</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Server</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Resource</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Status</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">void</span><span style="color: #007700">()<br /></span><span style="color: #0000BB">user_available_hook</span><span style="color: #007700">(</span><span style="color: #0000BB">JID</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />user_receive_packet</span><span style="color: #007700">(</span><span style="color: #0000BB">JID</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />user_send_packet</span><span style="color: #007700">(</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok&nbsp;</span>
</span>
</code></div>

	<h3>Types</h3>

	<p><code>To = From = JID = ServerJID = #jid</code> (see <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fjlib%2F" title="jlib">jlib</a>)<br />
<code>Packet = Payload = &#123;xmlelement, Name, Attrs, SubEl&#125;</code><br />
<code>IQ = #iq</code> (see <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fjlib%2F" title="jlib">jlib</a>)<br />
<code>Error = ?STANZA_ERROR/3</code> (see <a href="https://forge.process-one.net/browse/ejabberd/trunk/src/jlib.hrl?r=trunk">jlib.h</a>)<br />
<code>Lang = string()</code><br />
<code>Dir = in | out</code><br />
<code>Auth = allow | deny</code><br />
<code>PrivacyList = OldPrivacyList = NewPrivacyList = none | #userlist</code><br />
<code>CtlStatus = false | ?STATUS_SUCCESS | ?STATUS_ERROR | ?STATUS_USAGE | ?STATUS_BADRPC</code> (see <a href="https://forge.process-one.net/browse/ejabberd/trunk/src/ejabberd_ctl.hrl?r=trunk">ejabberd_ctl.hrl</a>")<br />
<code>Adhoc = &#123;result, I&#125; | &#123;error, Error&#125; | empty</code><br />
<code>Arg = [string()]</code><br />
<code>Node = [string()]</code><br />
<code>ItemID = string()</code><br />
<code>Route = &#123;route, From, To, Packet</code><br />
<code>RosterItem = #roster</code> (see <a href="https://forge.process-one.net/browse/ejabberd/trunk/src/mod_roster.hrl?r=trunk">mod_roster.hrl</a>)<br />
<code>Subscription = none | from | to | both | remove</code><br />
<code>SubscriptionType = subscribe | subscribed | unsubscribe | unsubscribed</code><br />
<code>Reason = string()</code><br />
<code>Groups = [string()]</code><br />
<code>SimpleJID = FromSubscription = ToSubscription = &#123;User, Server, Resource&#125;</code><br />
<code>User = string()</code><br />
<code>Server = string()</code><br />
<code>Resource = string()</code><br />
<code>Status = string()</code><br />
<code>SID = &#123;Time, pid()&#125;</code><br />
<code>Time = &#123;MegaSecs, Secs, MicroSecs&#125;</code> (see <a href="http://www.erlang.org/doc/doc-5.5.3/lib/kernel-2.11.3/doc/html/erlang.html#now/0">erlang:now/0</a>)<br />
<code>MegaSecs = Secs = MicroSecs = int()</code><br />
<code>Acc = same type as the return type of the function. Each module adds to the accumulator Acc their contribution</code></p>

	<h2>Event Details</h2>

	<h3>adhoc_local_items(Acc, From, To, Lang) -&gt; Adhoc</h3>

	<h3>adhoc_sm_items(Acc, From, To, Lang) -&gt; Adhoc</h3>

	<h3>c2s_stream_features(Acc)</h3>

	<h3>c2s_unauthenticated_iq(Acc, Server, IQ) -&gt; Adhoc</h3>

	<h3>disco_local_features(Acc, From, To, Node, Lang) -&gt; Adhoc</h3>

	<h3>disco_local_identity(Acc, From, To, Node, Lang) -&gt; Adhoc</h3>

	<p>This hook is related to <a href="http://xmpp.org/extensions/xep-0030.html"><span class="caps">XEP</span>-0030</a> </p>

	<h3>disco_local_items(Acc, From, To, Node, Lang)</h3>

	<p>This hook is related to <a href="http://xmpp.org/extensions/xep-0030.html"><span class="caps">XEP</span>-0030</a> </p>

	<h3>disco_sm_features(Acc, From, To, Node, Lang) -&gt; Adhoc</h3>

	<h3>disco_sm_identity(Acc, From, To, Node, Lang) -&gt; Adhoc</h3>

	<h3>disco_sm_items(Acc, From, To, Node, Lang) -&gt; Adhoc</h3>

	<h3>ejabberd_ctl_process(Args) -&gt; CtlStatus</h3>

	<h3>filter_packet(&#123;From, To, Packet&#125;) -&gt; &#123;From, To, Packet&#125;</h3>

	<h3>local_send_to_resource_hook(From, To, Packet)</h3>

	<h3>offline_message_hook(From, To, Packet)</h3>

	<p>Triggered when a message is sent to an offline user. The ejabberd session manager adds a default function to the offline_message_hook chain that bounces the incoming message with a service unavailable error. This hook is added at the lowest priority so that it executes after anything else in the chain.</p>

	<h3>privacy_check_packet(Acc, User, Server, PrivacyList, &#123;From, To, Packet&#125;, Dir) -&gt; Auth</h3>

	<h3>privacy_get_user_list(Acc, User, Server) -&gt; PrivacyList</h3>

	<h3>privacy_iq_get(Acc, From, To, IQ) -&gt; &#123;result, Packet&#125; | &#123;error, Error&#125;</h3>

	<h3>privacy_iq_set(Acc, From, To, IQ) -&gt; &#123;result, Packet&#125; | &#123;error, Error&#125;</h3>

	<h3>privacy_updated_list(Acc, OldPrivacyList, NewPrivacyList) -&gt; PrivacyList</h3>

	<h3>pubsub_publish_item(From, To, Node, ItemID, Payload) -&gt; ok</h3>

	<h3>remove_user(User, Server) -&gt; ok</h3>

	<h3>resend_offline_messages_hook(Acc, User, Server) -&gt; [Route]</h3>

	<h3>resend_subscription_requests_hook(Acc, User, Server) -&gt; [Packet]</h3>

	<h3>roster_get(Acc, &#123;User, Server&#125;) -&gt; [RosterItem]</h3>

	<h3>roster_get_jid_info(Acc, User, Server, <span class="caps">JID</span>) -&gt; &#123;Subscription, Groups&#125;</h3>

	<h3>roster_get_subscription_lists(Acc, User, Server) -&gt; &#123;[FromSubscription], [ToSubscription]&#125;</h3>

	<h3>roster_in_subscription(User, Server, <span class="caps">JID</span>, SubscriptionType, Reason) -&gt; bool()</h3>

	<h3>roster_out_subscription(User, Server, <span class="caps">JID</span>, SubscriptionType) -&gt; bool()</h3>

	<h3>roster_process_item(RosterItem, Server) -&gt; RosterItem</h3>

	<h3>set_presence_hook(User, Server, Resource, Priority)</h3>

	<p>This hook is processed whenever a connected user sends a presence stanza to the server.</p>

	<h3>sm_register_connection_hook(<span class="caps">SID</span>, <span class="caps">JID</span>) -&gt; ok</h3>

	<h3>sm_remove_connection_hook(<span class="caps">SID</span>, <span class="caps">JID</span>, SessionInfo) -&gt; ok</h3>

	<h3>unset_presence_hook(User, Server, Resource, Status) -&gt; void()</h3>

	<h3>user_available_hook(<span class="caps">JID</span>) -&gt; ok</h3>

	<h3>user_receive_packet(<span class="caps">JID</span>, From, To, Packet) -&gt; ok</h3>

	<h3>user_send_packet(From, To, Packet) -&gt; ok</h3>

	<h3>offline_message_hook</h3>

	<h3>resend_offline_messages_hook</h3>
      ]]></content>
    </entry>

    <entry>
      <title>ejabberd module development</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/ejabberd_module_development/" />
      <id>tag:process-one.net,2009:wiki:ejabberd module development/5.144</id>
      <published>2009-10-20T20:31:00Z</published>
      <updated>2009-10-20T20:31:00Z</updated>
      <author>
            <name>dS_Jeffrey</name>
            <email>jeffrey@digsby.com</email>
      </author>
      <content type="html"><![CDATA[
        	<h2>Introduction</h2>

	<p>ejabberd internal modules works as plugins. Each module is an <a href="http://erlang.org/">erlang</a> module with a name beginning with &#8220;mod_&#8221;. If you don&#8217;t already know Erlang, you should also take a look at this <a href="http://erlang.org/doc/getting_started/part_frame.html">doc</a>.</p>

	<h2><span class="caps">API</span> of the module</h2>

	<p>All the internal modules must use the &#8220;gen_mod&#8221; behavior.</p>

	<p>It must provide the following <span class="caps">API</span>:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">start</span><span style="color: #007700">(</span><span style="color: #0000BB">Host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Opts</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br />stop</span><span style="color: #007700">(</span><span style="color: #0000BB">Host</span><span style="color: #007700">)&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">ok<br /></span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">Host&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()<br />*&nbsp;</span><span style="color: #0000BB">Opts&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">&#91;&#123;Name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Value&#125;&#93;<br /></span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">Name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()&nbsp;</span>
</span>
</code></div>

	<p>Host is the name of the virtual host running the module. The start/2 and stop/1 functions are called for each virtual host at start and stop time of the server.<br />
Opts is a lists of options set in the configuration file for the module. They can be retrieved with the <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fgen_mod%2F" title="gen_mod">gen mod:get opt/3</a> function.</p>

	<h2>ejabberd <span class="caps">API</span></h2>

	<p>The modules interact with ejabberd using one or several of the following mechanisms:
	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_core_modules%2F" title="ejabberd_core_modules">ejabberd core modules</a></li>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_events_and_hooks%2F" title="ejabberd_events_and_hooks">ejabberd events and hooks</a></li>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_IQ_handlers%2F" title="ejabberd_IQ_handlers">ejabberd IQ handlers</a></li>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_route_table%2F" title="ejabberd_route_table">ejabberd route table</a></li>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_HTTP_request_handlers%2F" title="ejabberd_HTTP_request_handlers">ejabberd <span class="caps">HTTP</span> request handlers</a></li>
	</ul></p>

	<h2>Running an internal module as an external module</h2>

	<p>ejabberd internal modules using only the route table can also be used as external modules conform to <a href="http://www.xmpp.org/extensions/xep-0114.html" title="Jabber Component Protocol"><span class="caps">XEP</span>-0114</a> with <a href="http://www.process-one.net/en/blogs/article/epeios_write_a_module_for_an_xmpp_server_once_run_it_everywhere/">epeios</a>, and thus, they can be used with any other <span class="caps">XEP</span>-0114 compliant <span class="caps">XMPP</span> servers.</p>
      ]]></content>
    </entry>

    <entry>
      <title>ejabberd HTTP request handlers</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/ejabberd_HTTP_request_handlers/" />
      <id>tag:process-one.net,2008:wiki:ejabberd HTTP request handlers/17.132</id>
      <published>2008-05-31T20:42:38Z</published>
      <updated>2008-05-31T20:42:38Z</updated>
      <author>
            <name>gam3</name>
            <email>gam3-ejabberd@gam3.net</email>
      </author>
      <content type="html"><![CDATA[
        	<p>The web server embedded in ejabberd can be extended by writing your own<br />
modules.</p>

	<h2>Tutorial</h2>

	<p>Assume that you want to write a simple &#8220;mod_http_hello&#8221; module to handle<br />
all requests whose <span class="caps">URL</span> path begins with &#8220;/hello&#8221;, such as:</p>

	<ul>
		<li>http://localhost:5280/hello/world</li>
		<li>http://localhost:5280/hello/hedgehog</li>
	</ul>

	<p>Start by writing a &#8220;mod_http_hello.erl&#8221; file that contains request<br />
handlers, which are clauses of the process/2 function.  For<br />
example, to handle a request with the &#8220;/hello/world&#8221; path:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">_LocalPath&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">&#91;</span><span style="color: #DD0000">"world"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_Request</span><span style="color: #007700">)&nbsp;-&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"html"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;</span><span style="color: #DD0000">"xmlns"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"http://www.w3.org/1999/xhtml"</span><span style="color: #0000BB">&#125;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"head"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"title"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;&#125;&#93;&#125;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"body"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"p"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlcdata</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello,&nbsp;world!"</span><span style="color: #0000BB">&#125;&#93;&#125;&#93;&#125;&#93;&#125;</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div>

 (Note that the &#8220;hello&#8221; part is not taken care of here, since it&#8217;s common to all handlers.)

	<p>The entire mod_http_hello.erl file would look like:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">%%%----------------------------------------------------------------------<br />%%%&nbsp;</span><span style="color: #0000BB">File&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">mod_http_hello</span><span style="color: #007700">.</span><span style="color: #0000BB">erl<br /></span><span style="color: #007700">%%%&nbsp;</span><span style="color: #0000BB">Author&nbsp;&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Your&nbsp;Name&nbsp;</span><span style="color: #007700">&lt;</span><span style="color: #0000BB">your&nbsp;&#91;at&#93;&nbsp;email&nbsp;&#91;dot&#93;&nbsp;org</span><span style="color: #007700">&gt;<br />%%%&nbsp;</span><span style="color: #0000BB">Purpose&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Sample&nbsp;module&nbsp;that&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">embedded&nbsp;ejabberd&nbsp;HTTP&nbsp;server<br /></span><span style="color: #007700">%%%&nbsp;</span><span style="color: #0000BB">Created&nbsp;</span><span style="color: #007700">:<br />%%%&nbsp;</span><span style="color: #0000BB">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">:<br />%%%----------------------------------------------------------------------<br /><br />-</span><span style="color: #0000BB">module</span><span style="color: #007700">(</span><span style="color: #0000BB">mod_http_hello</span><span style="color: #007700">).<br />-</span><span style="color: #0000BB">author</span><span style="color: #007700">(</span><span style="color: #DD0000">'your@email.org'</span><span style="color: #007700">).<br />-</span><span style="color: #0000BB">vsn</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">).<br />-</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #0000BB">ejabberd_debug</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">).<br /><br />-</span><span style="color: #0000BB">behaviour</span><span style="color: #007700">(</span><span style="color: #0000BB">gen_mod</span><span style="color: #007700">).<br /><br />-</span><span style="color: #0000BB">export</span><span style="color: #007700">(</span><span style="color: #0000BB">&#91;<br />&nbsp;&nbsp;&nbsp;&nbsp;start</span><span style="color: #007700">/</span><span style="color: #0000BB">2</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">stop</span><span style="color: #007700">/</span><span style="color: #0000BB">1</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">process</span><span style="color: #007700">/</span><span style="color: #0000BB">2<br />&nbsp;&nbsp;&nbsp;&nbsp;&#93;</span><span style="color: #007700">).<br /><br />-include(</span><span style="color: #DD0000">"ejabberd.hrl"</span><span style="color: #007700">).<br />-include(</span><span style="color: #DD0000">"jlib.hrl"</span><span style="color: #007700">).<br />-include(</span><span style="color: #DD0000">"ejabberd_http.hrl"</span><span style="color: #007700">).<br /><br />%%%----------------------------------------------------------------------<br />%%%&nbsp;</span><span style="color: #0000BB">REQUEST&nbsp;HANDLERS<br /></span><span style="color: #007700">%%%----------------------------------------------------------------------<br /><br /></span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">&#91;</span><span style="color: #DD0000">"world"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_Request</span><span style="color: #007700">)&nbsp;-&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"html"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;</span><span style="color: #DD0000">"xmlns"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"http://www.w3.org/1999/xhtml"</span><span style="color: #0000BB">&#125;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"head"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"title"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;&#125;&#93;&#125;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"body"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"p"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlcdata</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello,&nbsp;world!"</span><span style="color: #0000BB">&#125;&#93;&#125;&#93;&#125;&#93;&#125;</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">&#91;</span><span style="color: #DD0000">"produce_error"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_Request</span><span style="color: #007700">)&nbsp;-&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;400</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"h1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlcdata</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"400&nbsp;Bad&nbsp;Request"</span><span style="color: #0000BB">&#125;&#93;&#125;&#125;</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">LocalPath</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_Request</span><span style="color: #007700">)&nbsp;-&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"html"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;</span><span style="color: #DD0000">"xmlns"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"http://www.w3.org/1999/xhtml"</span><span style="color: #0000BB">&#125;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"head"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"title"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;&#125;&#93;&#125;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"body"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"p"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;xmlcdata</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">io_lib</span><span style="color: #007700">:</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"Called&nbsp;with&nbsp;path:&nbsp;~p"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;LocalPath&#93;</span><span style="color: #007700">)</span><span style="color: #0000BB">&#125;&#93;&#125;&#93;&#125;&#93;&#125;</span><span style="color: #007700">.<br /><br />%%%----------------------------------------------------------------------<br />%%%&nbsp;</span><span style="color: #0000BB">BEHAVIOUR&nbsp;CALLBACKS<br /></span><span style="color: #007700">%%%----------------------------------------------------------------------<br /><br /></span><span style="color: #0000BB">start</span><span style="color: #007700">(</span><span style="color: #0000BB">_Host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_Opts</span><span style="color: #007700">)&nbsp;-&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ok</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB">stop</span><span style="color: #007700">(</span><span style="color: #0000BB">_Host</span><span style="color: #007700">)&nbsp;-&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ok</span><span style="color: #007700">.&nbsp;</span>
</span>
</code></div>

	<p>Modify ejabberd.cfg so that mod_http_hello is loaded when ejabberd starts:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#123;modules</span><span style="color: #007700">,<br />&nbsp;</span><span style="color: #0000BB">&#91;<br />&nbsp;&nbsp;</span><span style="color: #007700">%%&nbsp;...<br />&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;mod_http_hello</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#93;&#125;</span><span style="color: #007700">,<br />&nbsp;&nbsp;%%&nbsp;...<br />&nbsp;</span><span style="color: #0000BB">&#93;&#125;</span><span style="color: #007700">.&nbsp;</span>
</span>
</code></div>

	<p>Also in ejabberd.cfg, configure ejabberd_http so that it dispatches requests beginning with &#8220;/hello/&#8221; to mod_http_hello:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#123;5280</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ejabberd_http</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;http_poll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">web_admin</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;request_handlers</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;&#91;</span><span style="color: #DD0000">"hello"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mod_http_hello&#125;&#93;&#125;&#93;&#125;&nbsp;</span>
</span>
</code></div>

	<h2><span class="caps">API</span></h2>

	<p>Apart from callbacks required by gen_mod, your module only has to implement (one or more clauses of) process/2:</p>

	<ul>
		<li>your_http_module:process(LocalPath, Request)</li>
	</ul>

	<p>The process/2 function handles an <span class="caps">HTTP</span> request.  It returns the data to be sent back to the client, optionally with a status code and additional headers.</p>

	<p>process/2 will be called with two arguments: LocalPath and Request.</p>

	<p>The <strong>LocalPath</strong> argument is a list containing the part of the requested <span class="caps">URL</span> path that is &#8220;local to the module&#8221;.</p>

	<p>Example: mod_foo was configured in ejabberd.cfg to handle requests whose path begins with &#8220;/a/b&#8221;:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#123;5280</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ejabberd_http</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;http_poll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">web_admin</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;request_handlers</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;&#91;</span><span style="color: #DD0000">"a"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mod_foo&#125;&#93;&#125;&#93;&#125;&nbsp;</span>
</span>
</code></div>

	<p>User requests the <span class="caps">URL</span>:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">http</span><span style="color: #007700">:</span><span style="color: #FF8000">//server:5280/a/b/c/d&nbsp;</span>
</span>
</code></div>

	<p>Path &#8220;local to the module&#8221; will be:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#91;</span><span style="color: #DD0000">"c"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"d"</span><span style="color: #0000BB">&#93;&nbsp;</span>
</span>
</code></div>

	<p>Usually you will want to select a handler based on the local path instead of the full path (Request#request.path), so that server administrators can make the module available under the path prefix of their choice.</p>

	<p>The <strong>Request</strong> argument is a record containing information about the <span class="caps">HTTP</span> request as defined in ejabberd_http.hrl.  It consists of the following fields:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"request"</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #0000BB">method</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">HTTP&nbsp;method&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">"GET"&nbsp;</span><span style="color: #007700">or&nbsp;</span><span style="color: #DD0000">"POST"</span><span style="color: #007700">)<br />&nbsp;&nbsp;</span><span style="color: #0000BB">path</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">Full&nbsp;path&nbsp;to&nbsp;requested&nbsp;resource<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">%%&nbsp;</span><span style="color: #0000BB">e</span><span style="color: #007700">.</span><span style="color: #0000BB">g</span><span style="color: #007700">.&nbsp;for&nbsp;</span><span style="color: #DD0000">"http://server:5280/a/b/c/d"</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">&#91;</span><span style="color: #DD0000">"a"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"c"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"d"</span><span style="color: #0000BB">&#93;<br />&nbsp;&nbsp;q</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">Query&nbsp;part&nbsp;of&nbsp;the&nbsp;URL<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">%%&nbsp;</span><span style="color: #0000BB">e</span><span style="color: #007700">.</span><span style="color: #0000BB">g</span><span style="color: #007700">.&nbsp;for&nbsp;</span><span style="color: #DD0000">"http://server:5280/a/b/c/d?foo=bar"</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">&#91;&#123;</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"bar"</span><span style="color: #0000BB">&#125;&#93;<br />&nbsp;&nbsp;us</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">Authenticated&nbsp;user&nbsp;</span><span style="color: #007700">and&nbsp;</span><span style="color: #0000BB">server</span><span style="color: #007700">.&nbsp;&nbsp;</span><span style="color: #0000BB">Used&nbsp;in&nbsp;ejabberd_web_admin&nbsp;</span><span style="color: #007700">for&nbsp;</span><span style="color: #0000BB">now</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">e</span><span style="color: #007700">.</span><span style="color: #0000BB">g</span><span style="color: #007700">.&nbsp;for&nbsp;</span><span style="color: #DD0000">"foo@jabber.server.org"</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">&#123;</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"jabber.server.org"</span><span style="color: #0000BB">&#125;<br />&nbsp;&nbsp;auth</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">Information&nbsp;provided&nbsp;</span><span style="color: #007700">for&nbsp;</span><span style="color: #0000BB">HTTP</span><span style="color: #007700">-</span><span style="color: #0000BB">auth&nbsp;</span><span style="color: #007700">(if&nbsp;</span><span style="color: #0000BB">any</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%%&nbsp;</span><span style="color: #0000BB">e</span><span style="color: #007700">.</span><span style="color: #0000BB">g</span><span style="color: #007700">.&nbsp;for&nbsp;</span><span style="color: #0000BB">a&nbsp;user&nbsp;</span><span style="color: #DD0000">"john"&nbsp;</span><span style="color: #0000BB">who&nbsp;entered&nbsp;the&nbsp;password&nbsp;</span><span style="color: #DD0000">"secret"</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">&#123;</span><span style="color: #DD0000">"john"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"secret"</span><span style="color: #0000BB">&#125;<br />&nbsp;&nbsp;lang&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;%%&nbsp;</span><span style="color: #0000BB">Language&nbsp;code<br />&nbsp;&nbsp;data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;%%&nbsp;</span><span style="color: #0000BB">POST&nbsp;data<br />&#125;&nbsp;</span>
</span>
</code></div>
      ]]></content>
    </entry>

    <entry>
      <title>Talk:ejabberd HTTP request handlers</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/Talk:ejabberd_HTTP_request_handlers/" />
      <id>tag:process-one.net,2007:wiki:Talk:ejabberd HTTP request handlers/20.131</id>
      <published>2007-05-26T09:34:13Z</published>
      <updated>2007-05-26T09:34:13Z</updated>
      <author>
            <name>Victor Y. Sklyar</name>
            <email>vinnitu@gmail.com</email>
      </author>
      <content type="html"><![CDATA[
        <div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#123;5280</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ejabberd_http</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;http_poll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">web_admin</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;request_handlers</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;&#91;</span><span style="color: #DD0000">"hello"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mod_http_hello&#125;&#93;&#125;&#93;&#125;&nbsp;</span>
</span>
</code></div>

	<p>this if one http handler, but if two?</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&#123;5280</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ejabberd_http</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#91;http_poll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">web_admin</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;request_handlers</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;&#91;</span><span style="color: #DD0000">"hello"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mod_http_hello&#125;</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&#123;request_handlers</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">&#91;&#123;&#91;</span><span style="color: #DD0000">"http-bind"</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mod_http_bind&#125;&#93;&#125;&nbsp;</span>
</span>
</code></div>

	<p>am I right?</p>
      ]]></content>
    </entry>

    <entry>
      <title>Writing a Tsung plugin</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/Writing_a_Tsung_plugin/" />
      <id>tag:process-one.net,2007:wiki:Writing a Tsung plugin/19.129</id>
      <published>2007-03-25T17:41:27Z</published>
      <updated>2007-03-25T17:41:27Z</updated>
      <author>
            <name>Mickaël Rémond</name>
            <email>mickael.remond@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<p>This is a simple tutorial on writing a tsung plugin.</p>

	<p>Since tsung is used to test servers lets define a simple server for testing. <em>myserver.erl</em> provides 3 operations: echo, add and subtract.</p>

	<p><em>myserver.erl</em> assumes the first byte to be a control instruction followed by 2 or more byte data. The echo operation merely returns the byte data while add and subtract performs these operations on the 2 byte data before returning the results. See the code of <em>myserver.erl</em> for details.</p>

	<p>We assume the source files for tsung-1.2.1 are available. This example was compiled using Erlang <span class="caps">OTP</span> R11B-3.</p>

	<h2>Step 0. Download the source code for this tutorial</h2>

	<p>The source code for this tutorial is available: <a href="http://www.process-one.net/downloads/tutorials/tutorial_tsung_1.tgz">tutorial_tsung_1.tgz</a></p>

	<h2>Step 1. Create tsung configuration file</h2>

	<p>Based on the 3 operations we want to test we define the <em>myclient.xml</em> which <br />
will take place of <em>tsung.xml</em>. You will notice <em>myclient.xml</em> looks very much <br />
like any normal tsung configuration file. The main difference is in the <br />
session definition. Here we use the <em>ts_myclient</em> type.</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">session&nbsp;probability</span><span style="color: #007700">=</span><span style="color: #DD0000">"100"&nbsp;</span><span style="color: #0000BB">name</span><span style="color: #007700">=</span><span style="color: #DD0000">"myclient-example"&nbsp;</span><span style="color: #0000BB">type</span><span style="color: #007700">=</span><span style="color: #DD0000">"ts_myclient"</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div>

	<p>This indicates which plugin tsung should call when creating a server request.<br />
We choose to name this plugin <em>ts_myclient</em>.</p>

	<p>The next difference is within the request element. Here we define a &#8216;myclient&#8217;<br />
element indicates the operations to test followed by the relevant data.</p>

	<p>Notice that <em>myclient</em> has 2 attributes: <em>type</em> and <em>arith</em> (optional). </p>

	<h2>Step 2. Update <span class="caps">DTD</span></h2>

	<p>We now need to modify the <em>tsung-1.0.dtd</em> or validation would fail.</p>

	<p>In the request element we add the <em>myclient</em> tag. </p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;!</span><span style="color: #0000BB">ELEMENT&nbsp;request&nbsp;</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">match</span><span style="color: #007700">*,&nbsp;</span><span style="color: #0000BB">dyn_variable</span><span style="color: #007700">*,&nbsp;(&nbsp;</span><span style="color: #0000BB">http&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">jabber&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">raw&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">pgsql&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">myclient&nbsp;</span><span style="color: #007700">)&nbsp;)&gt;&nbsp;</span>
</span>
</code></div>

	<p>Next we create the <em>myclient</em> element. </p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;!</span><span style="color: #0000BB">ELEMENT&nbsp;myclient&nbsp;</span><span style="color: #007700">(</span><span style="color: #FF8000">#PCDATA)&nbsp;&gt;&nbsp;</span>
</span>
</code></div>

	<p>Followed by defining the attributes list for <em>myclient</em>.</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;!</span><span style="color: #0000BB">ATTLIST&nbsp;myclient<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arith&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">add&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">sub</span><span style="color: #007700">)&nbsp;</span><span style="color: #FF8000">#IMPLIED<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">(echo&nbsp;|&nbsp;</span><span style="color: #0000BB">compute</span><span style="color: #007700">)&nbsp;</span><span style="color: #FF8000">#REQUIRED&nbsp;&gt;&nbsp;</span>
</span>
</code></div>

	<p>Next, we add the <em>ts_myclient</em> option into the element&#8217;s <em>type</em> attribute list.</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">ts_http&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_jabber&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_pgsql&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_myclient&nbsp;</span><span style="color: #007700">)&nbsp;</span><span style="color: #FF8000">#IMPLIED&nbsp;</span>
</span>
</code></div>

	<p>We do the same to the session&#8217;s <em>type</em> attribute list.</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">ts_jabber&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_http&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_raw&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_pgsql&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ts_myclient&nbsp;</span><span style="color: #007700">)&nbsp;</span><span style="color: #FF8000">#REQUIRED&gt;&nbsp;</span>
</span>
</code></div>

	<h2>Step 3. Create include file</h2>

	<p>In <em><span class="caps">PATH</span>/include</em> create the include file <em>ts_myclient.hrl</em>. <br />
This include file should have a minimum of two records:
	<ol>
		<li><em>myclient_request</em>: for storing request information parsed from tsung configuration. Will be use to generate server requests.</li>
		<li><em>myclient_dyndata</em>: for storing dynamic information. Not used in this case.</li>
	</ol></p>

	<h2>Step 4. Config reader</h2>

	<p>Create the <em>ts_config_myclient.erl</em> in <em><span class="caps">PATH</span>/src/tsung_controller</em> to parse the <span class="caps">XML</span> file. This file must export <em>parse_config/2</em>.<br />
<em>ts_config_myclient:parse_config/2</em> is called from <em>ts_config:parse/1</em>.</p>

	<p>However trying to run <em>ts_config:parse/1</em> seperately seem to throw an undefined case error. </p>

	<p>The important function definition is:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">parse_config</span><span style="color: #007700">(</span><span style="color: #0000BB">Element&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #FF8000">#xmlElement&#123;name=myclient&#125;,&nbsp;...)&nbsp;</span>
</span>
</code></div>

	<p>Within this pattern we gather the various attributes, echo, compute, add, sub,<br />
and data creating a <em>myclient_request</em> record as needed. Notice for the case<br />
of type <em>compute</em> we parse the data into a list of 2 integers. Ensure you keep<br />
any data manipulation here consistant with calls in <em>ts_myclient:get_message/1</em>.</p>

	<p>If your configuration file support several element types then you will need a <em>parse_config</em> function for each.</p>

	<h2>Step 5. ts_myclient</h2>

	<p>The final file to create is <em>ts_myclient.erl</em> in <em><span class="caps">PATH</span>/src/tsung</em>. </p>

	<p>The <em>get_message/1</em> function builds the actual data to be transmitted to the server. The function returns a binary even if your protocol uses strings.</p>

	<p>In <em>ts_myclient:get_message/1</em>, you can see how we create the message from the <em>myclient_request</em> record. Compare this with <em>myserver:test/3</em> and <em>myserver:test/1</em>.</p>

	<p><em>parse/2</em> deals with server responses. It is possible to parse the return data and update monitoring parameters. In the <em>ts_myclient:parse/1</em> we count the number of single and multi bytes returned from the server. Obviously these must match <em>echo</em> and <em>add / _sub</em> calls.</p>

	<p>The <em>ts_mon:add/1</em> parameters are restricted to:
	<ol>
		<li>&#123;count, Type&#125;  &#8211; increments a running counter</li>
		<li>&#123;sum, Type, Val&#125; &#8211; adds <em>Val</em> to running counter</li>
		<li>&#123;sample_counter, Type, Value&#125; &#8211; updates <em>sample_counter</em></li>
		<li>&#123;sample, Type, Value&#125; &#8211; updates <em>counter</em></li>
	</ol></p>

	<h2>Step 6. Build and install</h2>

	<p>Return to <span class="caps">PATH</span> and type <em>make</em> followed by <em>make install</em>. </p>

	<p>There is no need to update any make files.</p>

	<h2>Step 7. Running</h2>

	<p>Start myserver then call <em>myserver:server()</em> in the erlang shell to start listening to the socket.</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">sh</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">erl&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">s&nbsp;myserver&nbsp;start_link<br />1</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">myserver</span><span style="color: #007700">:</span><span style="color: #0000BB">server</span><span style="color: #007700">().&nbsp;</span>
</span>
</code></div>

	<p>Run tsung, passing it <em>myclient.xml</em>:</p>

<div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">sh</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">tsung&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">f&nbsp;myclient</span><span style="color: #007700">.</span><span style="color: #0000BB">xml&nbsp;</span>
</span>
</code></div>

	<h2>Authors</h2>

	<p>The first version of this tutorial has been written by tty.</p>

	<p><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2FCategory%3Atutorials%2F" title="Category:tutorials">Category:tutorials</a></p>
      ]]></content>
    </entry>

    <entry>
      <title>Tsung</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/Tsung/" />
      <id>tag:process-one.net,2007:wiki:Tsung/18.106</id>
      <published>2007-03-25T15:38:20Z</published>
      <updated>2007-03-25T15:38:20Z</updated>
      <author>
            <name>Mickaël Rémond</name>
            <email>mickael.remond@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<p>Tsung is a high-performance, high-load benchmark platform.</p>

	<p>Here is some documentation, mainly targetting developers of contributed modules:</p>

	<p>- tutorial: <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2FWriting_a_Tsung_plugin%2F" title="Writing_a_Tsung_plugin">Writing a Tsung plugin</a></p>
      ]]></content>
    </entry>

    <entry>
      <title>index</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/index/" />
      <id>tag:process-one.net,2007:wiki:index/2.103</id>
      <published>2007-03-25T13:15:05Z</published>
      <updated>2007-03-25T13:15:05Z</updated>
      <author>
            <name>Mickaël Rémond</name>
            <email>mickael.remond@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<h1>Documentation</h1>

	<h2>ejabberd</h2>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd%2F" title="ejabberd">ejabberd documentation</a></li>
	</ul>

	<h2>Tsung</h2>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2FTsung%2F" title="Tsung">tsung documentation</a></li>
	</ul>
      ]]></content>
    </entry>

    <entry>
      <title>ejabberd core modules</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/ejabberd_core_modules/" />
      <id>tag:process-one.net,2007:wiki:ejabberd core modules/7.95</id>
      <published>2007-02-26T13:27:12Z</published>
      <updated>2007-02-26T13:27:12Z</updated>
      <author>
            <name>Massimiliano Mirra</name>
            <email>mmirra@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<p><em>Return to <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_module_development%2F" title="ejabberd_module_development">ejabberd module development</a></em></p>

	<h2>Router (ejabberd_router)</h2>

	<p>This module is the main router for <span class="caps">XMPP</span> packets on each node. It routes packets based on their destination domains. It has two tables: local and global routes. First, the destination domain of each packet is searched in local table. If found, the packet is routed to the appropriate process. Else, it searches in global table, and routes to the appropriate ejabberd node or process. If it does not exists in either tables, then the packet is sends to the S2S manager.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_router%2F" title="ejabberd_router">Router <span class="caps">API</span></a></li>
	</ul>

	<h2>Local router (ejabberd_local)</h2>

	<p>This module routes packets which have a destination domain equal to one of the virtual host name of the server. If destination <span class="caps">JID</span> has a non-empty user part, then it routes packets to the session manager, else it is processed depending on it&#8217;s content.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_local%2F" title="ejabberd_local" class="noArticle">Local router <span class="caps">API</span></a></li>
	</ul>

	<h2>Session manager (ejabberd_sm)</h2>

	<p>Handle the currently opened sessions.</p>

	<p>This module routes packets to local users. It determines which user resource the packet must be sent via the presence table. If this resource is connected to this node, it is routed to the C2S manager. If it&#8217;s connected via another node, then the packet is sent to the session manager on that node.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_sm%2F" title="ejabberd_sm">Session manager <span class="caps">API</span></a></li>
	</ul>

	<h2>Utilities (jlib)</h2>

	<p>Various helper functions. Modules should include the <a href="https://forge.process-one.net/browse/ejabberd/trunk/src/jlib.hrl?r=trunk">jlib.hrl</a> file in order to use the records defined by this module.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fjlib%2F" title="jlib">jlib <span class="caps">API</span></a></li>
	</ul>

	<h2>Modules utilities (gen_mod)</h2>

	<p>Utility functions useful in a module. This module also define the &#8220;gen_mod&#8221; behavior.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fgen_mod%2F" title="gen_mod">gen mod <span class="caps">API</span></a></li>
	</ul>

	<h2><span class="caps">XML</span> utilities (xml)</h2>

	<p>Various utilities to manipulate <span class="caps">XML</span> packets.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fxml%2F" title="xml"><span class="caps">XML</span> <span class="caps">API</span></a></li>
	</ul>

	<h2>Relational database (ejabberd_odbc)</h2>

	<p>Used to run <span class="caps">SQL</span> queries.</p>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_odbc%2F" title="ejabberd_odbc">Relational database <span class="caps">API</span></a></li>
	</ul>
      ]]></content>
    </entry>

    <entry>
      <title>ejabberd router</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/ejabberd_router/" />
      <id>tag:process-one.net,2007:wiki:ejabberd router/8.88</id>
      <published>2007-02-21T16:32:53Z</published>
      <updated>2007-02-21T16:32:53Z</updated>
      <author>
            <name>Jérôme Sautret</name>
            <email>jerome.sautret@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<p><em>Return the list of <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_core_modules%2F" title="ejabberd_core_modules">ejabberd core modules</a></em></p>

	<h2>Router (ejabberd_router)</h2>

	<p>This module is the main router for <span class="caps">XMPP</span> packets on each node. It routes packets based on their destination domains. It has two tables: local and global routes. First, the destination domain of each packet is searched in local table. If found, the packet is routed to the appropriate process. Else, it searches in global table, and routes to the appropriate ejabberd node or process. If it does not exists in either tables, then the packet is sends to the S2S manager.</p>

	<h3><span class="caps">API</span></h3>

	<h4>route/3</h4>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">route</span><span style="color: #007700">(</span><span style="color: #0000BB">From</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">To</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Packet</span><span style="color: #007700">)<br />*&nbsp;</span><span style="color: #0000BB">Packet&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">&#123;xmlelement</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Attrs</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SubEl&#125;<br /></span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">Attrs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">&#91;&#123;Name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Value&#125;&#93;<br /></span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">Name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()<br />*&nbsp;</span><span style="color: #0000BB">SubEl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">&#91;Packet&#93;&nbsp;</span>
</span>
</code></div><br />
Route an <span class="caps">XML</span> packet.</p>

	<h4>register_route/1 and unregister_route/1</h4>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">register_route</span><span style="color: #007700">(</span><span style="color: #0000BB">Host</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">unregister_route</span><span style="color: #007700">(</span><span style="color: #0000BB">Host</span><span style="color: #007700">),<br />*&nbsp;</span><span style="color: #0000BB">Host&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()&nbsp;</span>
</span>
</code></div><br />
Host is the <span class="caps">XMPP</span> name of the route name. See the <a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_route_table%2F" title="ejabberd_route_table">routage mechanism of services</a> for more details.</p>

	<h4>dirty_get_all_routes/0</h4>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">dirty_get_all_routes</span><span style="color: #007700">()&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#91;RouteName&#93;<br /></span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">RouteName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()&nbsp;</span>
</span>
</code></div><br />
Return a list of all registered route names.</p>

	<h4>dirty_get_all_domains/0</h4>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">dirty_get_all_domains</span><span style="color: #007700">()&nbsp;-&gt;&nbsp;</span><span style="color: #0000BB">&#91;Domains&#93;<br /></span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">Domains&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">string</span><span style="color: #007700">()&nbsp;</span>
</span>
</code></div><br />
Return a list of all known domains.</p>
      ]]></content>
    </entry>

    <entry>
      <title>ejabberd</title>
      <link rel="alternate" type="text/html" href="http://www.process-one.net/en/wiki/ejabberd/" />
      <id>tag:process-one.net,2007:wiki:ejabberd/16.84</id>
      <published>2007-02-21T16:22:26Z</published>
      <updated>2007-02-21T16:22:26Z</updated>
      <author>
            <name>Jérôme Sautret</name>
            <email>jerome.sautret@process-one.net</email>
      </author>
      <content type="html"><![CDATA[
        	<h2>ejabberd documentation</h2>

	<ul>
		<li><a href="http://www.process-one.net/en?URL=http%3A%2F%2Fwww.process-one.net%2Fen%2Fwiki%2Fejabberd_module_development%2F" title="ejabberd_module_development">ejabberd module development</a></li>
	</ul>
      ]]></content>
    </entry>


</feed>