<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<section id="options.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
    <sectioninfo>
	<revhistory>
	    <revision>
		<revnumber>$Revision: 1.3.2.1 $</revnumber>
		<date>$Date: 2008/06/11 11:56:00 $</date>
	    </revision>
	</revhistory>
    </sectioninfo>

    <title>Functions</title>

    <section id="sanity_check">
	    <title>
		<function>sanity_check()</function>
	    </title>
	<para>
		This function makes a row of sanity checks on the given request.
		The function returns true if one of the checks failed. If one
		of the checks fails the module sends a precise error reply via 
		sl_send_reply. Thus their is no need to reply with a generic 
		error message.
	</para>
	<example>
	    <title><function>sanity_check</function> usage</title>
	    <programlisting>
<![CDATA[
...
if (sanity_check()) {
	break;
}
...
]]>
	    </programlisting>
	</example>
	<para>
		Optionally the function takes an integer argument which overwrites
		the global module parameter default_checks. This allows to make
		certain test from script regions. The integer value is again the sum
		of the checks (like for the module parameter) which should be executed
		at this function call.
	</para>
	<example>
	    <title><function>sanity_check</function> usage with parameter</title>
	    <programlisting>
<![CDATA[
...
if (method=="REGISTER" && sanity_check("256")) {
	/* the register contains an invalid expires value and is replied with a 400 */
	break;
}
...
]]>
	    </programlisting>
	</example>
	<para>
		Optionally the function takes a second integer argument which
		overwrites the global module parameter uri_checks and thus determines
		which URIs will be checked if the parse uri test will be executed.
	</para>
	<example>
		<title><function>sanity_check</function> usage with two parameters</title>
		<programlisting>
<![CDATA[
...
if (method=="INVITE" && sanity_check("1024", "6")) {
	/* the INVITE contains an invalid From or To header and is replied with a 400 */
	break;
}
...
]]>
		</programlisting>
	</example>
    </section>
</section>
