<!-- Module User's Guide -->

<chapter>
	
	<title>&adminguide;</title>
	
	<section id="overview" xreflabel="Overview">
	<title>Overview</title>
	<para>	This modules is a gateway between OpenSIPS and a jabber server. It enables the exchange of instant messages between
		SIP clients and XMPP(jabber) clients. </para>
	<para>	The gateway has two modes to run:</para>

	<itemizedlist>
		<listitem>
			<para>	<emphasis role='bold'>the component-mode</emphasis> - the gateway requires a standalone XMPP server amd the 'xmpp' module acts as
			a XMPP component </para>
		</listitem>
		<listitem>
			<para>	<emphasis role='bold'>the server-mode</emphasis> - the module acts itself as a XMPP server, no requirement for another XMPP server in the system. NOTE: this is limited implementation of a XMPP server, it does not support SRV or TLS so far. This mode is in beta stage for the moment.</para>
		</listitem>
	</itemizedlist>
	<para>	In the component mode, you need a local XMPP server (recommended jabberd2 or ejabberd); the xmpp module will relay all your connections to a tcp connection to the local jabber server.</para>
	<para> After you have a running XMPP server, what you need to do is set the following parameters in the OpenSIPS configuration file:</para>
	<itemizedlist>
		<listitem>
			<para>xmpp_domain and xmpp_host, which are explained in the
				<xref linkend="exported_parameters"/> section;
			</para>
		</listitem>
		<listitem>
			<para>socket= your ip;</para>
		</listitem> 
		<listitem>
			<para>alias=opensips domain and 
	alias=gateway domain;</para>
		</listitem>
		<listitem>
			<para>you can also change the jabber server password, which must be the same as the xmpp_password parameter.</para>
		</listitem>
	</itemizedlist>
	<para>	A use case, for the component-mode, would look like this:</para>
	<itemizedlist>
		<listitem>
			<para>OpenSIPS is running on sip-server.opensips.org;</para>
		</listitem>
		<listitem>
			<para>the jabber server is running on xmpp.opensips.org;</para>
		</listitem>	
		<listitem>
			<para>the component is running on xmpp-sip.opensips.org.</para>
		</listitem>	
	</itemizedlist>
	<para>
		In the server mode, the xmpp module is a minimal jabber server, thus you do not need to install another jabber server, the gateway will connect to the jabber servers, where the users you want to chat with have an account. </para>
	<para>
	If you want to change to server-mode, you have to change the
	"backend" parameter, as shown in the
	<xref linkend="exported_parameters"/> section, from component to server.</para>
	<para>	A use case, for the server-mode, would look like this: </para>
	<itemizedlist>
		<listitem>
			<para>OpenSIPS is running on sip-server.opensips.org; </para>
		</listitem>
		<listitem>
			<para>the "XMPP server" is running on xmpp-sip.opensips.org.</para>
		</listitem>
	</itemizedlist>	
	</section>
	<section id="dependencies" xreflabel="Dependencies">
	<title>Dependencies</title>
	<section>
		<title>&osips; Modules</title>
		<para>
		The following modules must be loaded before this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>requires 'tm' module</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	<section>
		<title>External Libraries or Applications</title>
		<para>
		The following libraries or applications must be installed before running
		&osips; with this module loaded:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>libexpat1-devel</emphasis> - used for parsing/building XML.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>

	<section id="exported_parameters" xreflabel="Exported Parameters">
	<title>Exported Parameters</title>
	<section id="param_backend" xreflabel="backend">
		<title><varname>backend</varname> (string)</title>
		<para>
		The mode you are using the module; it can be either component or server.
		</para>
		<para>
		<emphasis>
			Default value is "component".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>backend</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "backend", "server")
...
</programlisting>
		</example>
	</section>
	<section id="param_xmpp_domain" xreflabel="xmpp_domain">
		<title><varname>xmpp_domain</varname> (string)</title>
		<para>
			The xmpp domain of the component or the server, depending on the mode we are in.
		</para>
		<para>
		<emphasis>
			Default value is "127.0.0.1".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>xmpp_domain</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "xmpp_domain", "xmpp.opensips.org")
...
</programlisting>
		</example>
	</section>
	<section id="param_xmpp_host" xreflabel="xmpp_host">
		<title><varname>xmpp_host</varname> (string)</title>
		<para>
			 The ip address or the name of the local jabber server, if the backend is set to "component"; or the address to bind to in the server mode.
		</para>
		<para>
		<emphasis>
			Default value is "127.0.0.1".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>xmpp_host</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "xmpp_host", "xmpp.opensips.org")
...
</programlisting>
		</example>
	</section>

	<section id="param_sip_domain" xreflabel="sip_domain">
		<title><varname>sip_domain</varname> (string)</title>
		<para>
		This parameter must be set only if the xmpp module is used in component mode and the domain
		that is the host for the jabber server is the same as the domain of the sip server(when using
		the same domain name for the SIP service and for the XMPP service). In this case,
		if we were to add buddies in xmpp accounts with that domain, then all the messages that will
		reach the jabber server will be considered to be for local xmpp users. It is necessary therefore
		to make a translate the sip domain name into another domain when sending messages in xmpp.
		This parameter is exactly the name that should be used as the SIP domain name in XMPP.
		Usage example: If the sip and xmpp domain is opensips.org and this parameter is set to sip.opensips.org,
		than in all the requests sent in xmpp the sip users will have the domain translated to sip.opensips.org.
		Also, in XMPP account the SIP buddies must have this domain: sip.opensips.org, and it will be
		translated to the real one opensips.org when traversing the gateway.
		</para>
		<para>
		<emphasis>
			Default value is NULL.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>xmpp_host</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "sip_domain", "sip.opensips.org")
...
</programlisting>
		</example>
	</section>

	<section id="param_xmpp_port" xreflabel="xmpp_port">
		<title><varname>xmpp_port</varname> (integer)</title>
		<para>
			In the component mode, this is the port of the jabber router we connect to. In the server mode, it is the transport address to bind to.	 
		</para>
		<para>
		<emphasis>
			Default value is "5347", if backend is set to "component" and "5269", if backend is set to "server".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>xmpp_port</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "xmpp_port", 5269)
...
</programlisting>
		</example>
	</section>

<section id="param_xmpp_password" xreflabel="xmpp_password">
		<title><varname>xmpp_password</varname> (string)</title>
		<para>	The password of the local jabber server. 	</para>
		<para>
			<emphasis>
				Default value is "secret"; if changed here, it must also be changed in the c2s.xml, added by the jabber server. This is how the default configuration for the jabberd2 looks like:
			</emphasis>
			<programlisting format="linespecific">
		<![CDATA[	<router>
	............... 
	<!-- Username/password to authenticate as --&gt;
    <user>jabberd</user>;          <!-- default: jabberd -->;
    <pass>secret</pass>;           <!-- default: secret -->;	]]>
			</programlisting>
		</para>
		<example>
		<title>Set <varname>xmpp_password</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "xmpp_password", "secret")
...
</programlisting>
		</example>
	</section>
	<section id="param_outbound_proxy" xreflabel="outbound_proxy">
		<title><varname>outbound_proxy</varname> (string)</title>
		<para>
		The SIP address used as next hop when sending the message. Very
		useful when using OpenSIPS with a domain name not in DNS, or
		when using a separate OpenSIPS instance for xmpp processing. If
		not set, the message will be sent to the address in destination
		URI.
		</para>
		<para>
		<emphasis>
		Default value is NULL.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>outbound_proxy</varname> parameter</title>
		<programlisting format="linespecific">
...
 modparam("xmpp", "outbound_proxy", "sip:opensips.org;transport=tcp")
...
</programlisting>
		</example>
	</section>
	</section>

	<section id="exported_functions" xreflabel="exported_functions">
	<title>Exported Functions</title>
	<section id="func_xmpp_send_message" xreflabel="xmpp_send_message()">
		<title>
		<function moreinfo="none">xmpp_send_message()</function>
		</title>
		<para>
		Converts SIP messages to XMPP(jabber) messages, in order to be relayed to a XMPP(jabber) client.
		</para>
		
		<example>
		<title><function>xmpp_send_message()</function> usage</title>
		<programlisting format="linespecific">
...
xmpp_send_message();
...
</programlisting>
		</example>
	</section>
	</section>
	<section>
	<title>Configuration</title>
		<para>
		Next is presented a sample configuration file one can use to implement a
		standalone SIP-to-XMPP gateway. You can run an instance of OpenSIPS on a
		separate machine or on different port with the following config, and have
		the main SIP server configured to forward all SIP requests for XMPP world
		to it.
		</para>
		<programlisting format="linespecific">
....
&cfg;
....
</programlisting>

	</section>
</chapter>

