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

<chapter>
	
	<title>&adminguide;</title>
	
	<section id="overview" xreflabel="Overview">
	<title>Overview</title>
	<para>
	This module allows to use the unixodbc package with &osips;. It have been 
	tested with mysql and the odbc connector, but it should work also with 
	other database. The auth_db module works.
	</para>
	<para>
	For more information, see the <ulink url="http://www.unixodbc.org/">
	http://www.unixodbc.org/</ulink> project web page.
	</para>
	<para>
	To see what DB engines can be used via unixodbc, look at 
	<ulink url="http://www.unixodbc.org/drivers.html">
	http://www.unixodbc.org/drivers.html</ulink>.
	</para>
	</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>No dependencies on other &osips; modules</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>None</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>

	<section id="exported_parameters" xreflabel="Exported Parameters">
	<title>Exported Parameters</title>
	<section id="param_auto_reconnect" xreflabel="auto_reconnect">
		<title><varname>auto_reconnect</varname> (int)</title>
		<para>
		Turns on or off the auto_reconnect mode.
		</para>
		<para>
		<emphasis>
			Default value is <quote>1</quote>, this means it is enabled.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>auto_reconnect</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("db_unixodbc", "auto_reconnect", 0)
...
</programlisting>
		</example>
	</section>

	<section id="param_use_escape_common" xreflabel="use_escape_common">
		<title><varname>use_escape_common</varname> (int)</title>
		<para>
		Escape values in query using internal escape_common() function.
		It escapes single quote ''', double quote '"', backslash '\',
		and NULL characters.
		</para>
		<para>
		You should enable this parameter if you know that the ODBC driver
		considers the above characters as special (for marking begin and end
		of a value, escape other characters ...). It prevents against SQL
		injection.
		</para>
		<para>
		<emphasis>
			Default value is <quote>0</quote> (0 = disabled; 1 = enabled).
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>use_escape_common</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("db_unixodbc", "use_escape_common", 1)
...
</programlisting>
		</example>
	</section>
    </section>

	<section id="exported_functions" xreflabel="exported_functions">
	<title>Exported Functions</title>
		<para>
		NONE
		</para>
	</section>

	<section>
	<title>Installation and Running</title>

	<section>
	<title>Installing</title>
	<para>
	Prerequirement: you should first install unixodbc (or another program that 
	implements the odbc standard, such iodbc), your database, and the right 
	connector. Set the DSN in the odbc.ini file and the connector drivers in 
	the odbcinst.ini file.
	</para>
	</section>

	<section>
	<title>Configuring and Running</title>
	<para>
	In the opensips.conf file, add the line:
	</para>
	<programlisting format="linespecific">
....
loadmodule "/usr/local/lib/opensips/modules/db_unixodbc.so"
....
</programlisting>
	<para>
	You should also uncomment this:
	</para>
	<programlisting format="linespecific">
....
loadmodule "/usr/local/lib/opensips/modules/auth.so"
loadmodule "/usr/local/lib/opensips/modules/auth_db.so"
modparam("usrloc", "db_mode", 2)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
....
</programlisting>
	<para>
	and setting the DSN specified in the odbc.ini, inserting this with the 
	url adding this line:
	</para>
	<programlisting format="linespecific">
....
modparam("usrloc|auth_db", "db_url", 
    "unixodbc://opensips:opensipsrw@localhost/my_dsn")
....
</programlisting>
	<para>
	replacing my_dsn with the correct value.
	</para>
	<para>
	HINT: if unixodbc don't want to connect to mysql server, try restarting 
	mysql server with:
	</para>
	<programlisting format="linespecific">
shell>safe_mysqld --user=mysql --socket=/var/lib/mysql/mysql.sock
</programlisting>
	<para>
	The connector search the socket in /var/lib/mysql/mysql.sock and not 
	in /tmp/mysql.sock
	</para>
	</section>

	</section>
</chapter>

