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

<chapter>

	<title>&adminguide;</title>

	<section id="overview" xreflabel="Overview">
	<title>Overview</title>
	<section id="sec-call-routing">
		<title>Call Routing</title>
		<para>
		The module can be used to determine if a call has appropriate
		permission to be established.
		Permission rules are stored in plaintext configuration files similar to
		<filename moreinfo="none">hosts.allow</filename> and <filename
		moreinfo="none">hosts.deny</filename> files used by tcpd.
		</para>
		<para>
		When <function moreinfo="none">allow_routing</function> function is
		called it tries to find a rule that matches selected fields of the
		message.
		</para>
		<para>
		&osips; is a forking proxy and therefore a single message can be sent
		to different destinations simultaneously. When checking permissions
		all the destinations must be checked and if one of them fails, the
		forwarding will fail.
		</para>
		<para>
		The matching algorithm is as follows, first match wins:
		</para>
		<itemizedlist>
		<listitem>
			<para>
			Create a set of pairs of form (From, R-URI of branch 1),
			(From, R-URI of branch 2), etc.
			</para>
		</listitem>
		<listitem>
			<para>
			Routing will be allowed when all pairs match an entry in the
			allow file.
			</para>
		</listitem>
		<listitem>
			<para>
			Otherwise routing will be denied when one of pairs matches an
			entry in the deny file.
			</para>
		</listitem>
		<listitem>
			<para>
			Otherwise, routing will be allowed.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		A non-existing permission control file is treated as if it were an
		empty file. Thus, permission control can be turned off by providing
		no permission control files.
		</para>
		<para>
		From header field and Request-URIs are always compared with regular
		expressions! For the syntax see the sample file:
		<filename moreinfo="none">config/permissions.allow</filename>.
		</para>
	</section>
	<section id="sec-registration-permissions">
		<title>Registration Permissions</title>
		<para>
		In addition to call routing it is also possible to check REGISTER
		messages and decide--based on the configuration files--whether the
		message should be allowed and the registration accepted or not.
		</para>
		<para>
		Main purpose of the function is to prevent registration of "prohibited"
		IP addresses. One example, when a malicious user registers a contact
		containing IP address of a PSTN gateway, he might be able to bypass
		authorization checks performed by the SIP proxy. That is undesirable
		and therefore attempts to register IP address of a PSTN gateway should
		be rejected. Files <filename
		moreinfo="none">config/register.allow</filename> and <filename
		moreinfo="none">config/register.deny</filename> contain an example
		configuration.
		</para>
		<para>
		Function for registration checking is called <function
		moreinfo="none">allow_register</function> and the algorithm is very
		similar to the algorithm described in
		<xref linkend="sec-call-routing"/>. The only difference is in the way
		how pairs are created.
		</para>
		<para>
		Instead of From header field the function uses To header field because
		To header field in REGISTER messages contains the URI of the person
		being registered. Instead of the Request-URI of branches the function
		uses Contact header field.
		</para>
		<para>
		Thus, pairs used in matching will look like this: (To, Contact 1),
		(To, Contact 2), (To, Contact 3), and so on..
		</para>
		<para>
		The algorithm of matching is same as described in
		<xref linkend="sec-call-routing"/>.
		</para>
	</section>
	<section id="sec-uri-permissions">
		<title>URI Permissions</title>
		<para>
		The module can be used to determine if request is
		allowed to the destination specified by an URI stored in
		a pvar.  Permission rules are stored in
		plaintext configuration files similar to
		<filename moreinfo="none">hosts.allow</filename> and
		<filename moreinfo="none">hosts.deny</filename> used by tcpd.
		</para>
		<para>
		When <function moreinfo="none">allow_uri</function>
		function is called, it tries to find a rule that matches
		selected fields of the message.
		The matching algorithm is as follows, first match wins:
		</para>
		<itemizedlist>
		<listitem>
			<para>
			Create a pair &lt;From URI, URI stored in pvar&gt;.
			</para>
		</listitem>
		<listitem>
			<para>
			Request will be allowed when the pair matches
			an entry in the allow file.
			</para>
		</listitem>
		<listitem>
			<para>
			Otherwise request will be denied when the pair
			matches an entry in the	deny file.
			</para>
		</listitem>
		<listitem>
			<para>
			Otherwise, request will be allowed.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		A non-existing permission control file is treated as if it were an
		empty file. Thus, permission control can be turned off by providing
		no permission control files.
		</para>
		<para>
		From URI and URI stored in pvar are always compared with regular
		expressions! For the syntax see the sample file:
		<filename moreinfo="none">config/permissions.allow</filename>.
		</para>
	</section>
	<section id="sec-address-permissions">
		<title>Address Permissions</title>
		<para>
		The module can be used to determine if an address (IP
		address and port) matches any of the IP subnets
		stored in cached &osips; database table.
		Port 0 in cached database table matches any port.  Group ID, IP
		address, port and transport protocol values to be matched can be either taken from
		the request (<function moreinfo="none">check_source_address</function>) or given as pvar
		arguments or directly as strings(<function moreinfo="none">check_address</function>).
		</para>
		<para>
		Addresses stored in cached database table can be grouped
		together into one or more groups specified by a group
		identifier (unsigned integer). Group identifier is given as
		argument to <function moreinfo="none">check_address</function> and
		<function moreinfo="none">check_source_address</function>.
		</para>
		<para>
		Otherwise the request is rejected.
		</para>
		<para>
		The address database table is specified by module parameters.
		</para>
	</section>
	</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_default_allow_file" xreflabel="default_allow_file">
		<title><varname>default_allow_file</varname> (string)</title>
		<para>
		Default allow file used by functions without parameters. If you
		don't specify full pathname then the directory in which is the main
		config file is located will be used.
		</para>
		<para>
		<emphasis>
			Default value is <quote>permissions.allow</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>default_allow_file</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "default_allow_file", "/etc/permissions.allow")
...
</programlisting>
		</example>
	</section>
	<section id="param_default_deny_file" xreflabel="default_deny_file">
		<title><varname>default_deny_file</varname> (string)</title>
		<para>
		Default file containing deny rules. The file is used by functions
		without parameters. If you don't specify full pathname then the
		directory in which the main config file is located will be used.
		</para>
		<para>
		<emphasis>
			Default value is <quote>permissions.deny</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>default_deny_file</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "default_deny_file", "/etc/permissions.deny")
...
</programlisting>
		</example>
	</section>
	<section id="param_check_all_branches" xreflabel="check_all_branches">
		<title><varname>check_all_branches</varname> (integer)</title>
		<para>
		If set then allow_routing functions will check Request-URI of all
		branches (default). If disabled then only Request-URI of the first
		branch will be checked.
		</para>
		<warning>
		<para>
		Do not disable this parameter unless you really know what you
		are doing.
		</para>
		</warning>
		<para>
		<emphasis>
			Default value is 1.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>check_all_branches</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "check_all_branches", 0)
...
</programlisting>
		</example>
	</section>
	<section id="param_allow_suffix" xreflabel="allow_suffix">
		<title><varname>allow_suffix</varname> (string)</title>
		<para>
		Suffix to be appended to basename to create filename of the allow
		file when version with one parameter of either
		<function moreinfo="none">allow_routing</function> or
		<function moreinfo="none">allow_register</function> is used.
		</para>
		<note>
		<para>
			Including leading dot.
		</para>
		</note>
		<para>
		<emphasis>
			Default value is <quote>.allow</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>allow_suffix</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "allow_suffix", ".allow")
...
</programlisting>
		</example>
	</section>
	<section id="param_deny_suffix" xreflabel="deny_suffix">
		<title><varname>deny_suffix</varname> (string)</title>
		<para>
		Suffix to be appended to basename to create filename of the deny file
		when version with one parameter of either
		<function moreinfo="none">allow_routing</function> or
		<function moreinfo="none">allow_register</function> is used.
		</para>
		<note>
		<para>
			Including leading dot.
		</para>
		</note>
		<para>
		<emphasis>
			Default value is <quote>.deny</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>deny_suffix</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "deny_suffix", ".deny")
...
</programlisting>
		</example>
	</section>
	<section id="param_db_url" xreflabel="db_url">
		<title><varname>db_url</varname> (string)</title>
		<para>
		The URL of the database to be used for loading the data related to
		IP-based checking (<quote>address</quote> table).
		</para>
		<para>
		This parameter is optional and it is needed only if you use
		functions related to IP-based checking. If you do so, you need to
		explicitly set this parameter (it will not inherit from 
		<quote>db_default_url</quote>)
		</para>
		<para>
		Since version 2.2, this URL represents the db_url for the 
		<quote>default</quote> partition.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>db_url</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "db_url", "&exampledb;")
...
</programlisting>
		</example>
	</section>
	<section id="param_address_table" xreflabel="address_table">
		<title><varname>address_table</varname> (string)</title>
		<para>
		Name of database table containing matching rules used by
		<function moreinfo="none">allow_register</function> function.
		Since version 2.2, this table name also represents the default table
		name for partitions without a 'table_name' setting.
		</para>
		<para>
		<emphasis>
		Default value is <quote>address</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>address_table</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "address_table", "pbx")
...
</programlisting>
		</example>
	</section>
	<section id="param_partition" xreflabel="partition">
		<title><varname>partition</varname> (string)</title>
		<para>
		Specify a new IP-based checking partition (data source).  This
		parameter may be set multiple times.  Each partition may have a
		specific "db_url" and "table_name".  If not specified, these values
		will be inherited from <xref linkend="param_db_url"/>, db_default_url
		or <xref linkend="param_address_table"/>, respectively.  The name of
		the default partition is 'default'.
		</para>
		<para>
		</para>
		<example>
		<title>Set <varname>partition</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "partition", "
	inbound:
		db_url = postgres://opensips:opensipsrw@127.0.0.1/opensips;
		table_name = address")
...

</programlisting>
		</example>
	</section>
	<section id="param_grp_col" xreflabel="grp_col">
		<title><varname>grp_col</varname> (string)</title>
		<para>
		Name of address table column containing group
		identifier of the address.
		</para>
		<para>
		<emphasis>
		Default value is <quote>grp</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>grp_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "grp_col", "group_id")
...
</programlisting>
		</example>
	</section>
	<section id="param_ip_col" xreflabel="ip_col">
		<title><varname>ip_col</varname> (string)</title>
		<para>
		Name of address table column containing IP address
		part of the address.
		</para>
		<para>
		<emphasis>
		Default value is <quote>ip</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>ip_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "ip_col", "ipess")
...
</programlisting>
		</example>
	</section>
	<section id="param_mask_col" xreflabel="mask_col">
		<title><varname>mask_col</varname> (string)</title>
		<para>
		Name of address table column containing network mask of
		the address.  Possible values are 0-128. It should be up to 32 if 
		the IP is v4 and up to 128 if the IP is v6.
		</para>
		<para>
		<emphasis>
		Default value is <quote>mask</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>mask_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "mask_col", "subnet_length")
...
</programlisting>
		</example>
	</section>
	<section id="param_port_col" xreflabel="port_col">
		<title><varname>port_col</varname> (string)</title>
		<para>
		Name of address table column containing port
		part of the address.
		</para>
		<para>
		<emphasis>
		Default value is <quote>port</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>port_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "port_col", "prt")
...
</programlisting>
		</example>
	</section>


	<section id="param_proto_col" xreflabel="proto_col">
		<title><varname>proto_col</varname> (string)</title>
		<para>
		Name of address table column containing transport
		protocol that is matched against transport protocol of
		received request.  Possible values that can be stored in
		proto_col are <quote>any</quote>, <quote>udp</quote>,
		<quote>tcp</quote>, <quote>tls</quote>,
		<quote>sctp</quote>, and <quote>none</quote>.  Value
		<quote>any</quote> matches always and value
		<quote>none</quote> never.
		</para>
		<para>
		<emphasis>
			Default value is <quote>proto</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>proto_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "proto_col", "transport")
...
</programlisting>
		</example>
	</section>
	<section id="param_pattern_col" xreflabel="pattern_col">
		<title><varname>pattern_col</varname> (string)</title>
		<para>
		Name of address table column containinga a pattern (a shell wildcard
		pattern, like the ones used for file name matching) that is matched 
		against the arguments received by
		<function moreinfo="none">check_address</function>
		or <function moreinfo="none">check_source_address</function>.
		</para>
		<para>
		<emphasis>
		Default value is <quote>pattern</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>pattern_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "pattern_col", "wildcard_col")
...
</programlisting>
		</example>
	</section>
	<section id="param_info_col" xreflabel="info_col">
		<title><varname>info_col</varname> (string)</title>
		<para>
		Name of address table column containing a string
		that is added as value to a pvar given as argument
		to <function moreinfo="none">check_address</function>
		or <function moreinfo="none">check_source_address</function> in
		case the function succedes.
		</para>
		<para>
		<emphasis>
		Default value is <quote>context_info</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>info_col</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("permissions", "info_col", "info_col")
...
</programlisting>
		</example>
	</section>
	</section>

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

	<section id="func_check_address" xreflabel="check_address()">
		<title>
		<function moreinfo="none">check_address(group_id, ip,
		port, proto [, context_info], [pattern], [partition])</function>
		</title>
		<para>
		Returns 1 if group id, IP address, port and protocol given as
		arguments match an IP subnet found in cached address table,
		as described in <xref linkend="sec-address-permissions"/> .
		The function takes 4 mandatory arguments and 3 optional ones.
		</para>
		<para>
		This function can be useful to check if a request can be allowed
		without authentication.
		</para>

		<para>Meaning of the parameter is as follows:</para>

		<itemizedlist>
		<listitem>
			group_id (int)
		<para>
			This argument represents the group id to be matched.
			If the group_id argument is "0", the query can match any group
			in the cached address table.
		</para>
		</listitem>
		<listitem>
			ip (string)
		<para>
			This argument represents the ip address to be matched.
			This argument cannot be null/empty.
		</para>
		</listitem>
		<listitem>
			port (int)
		<para>
			This argument represents the port to be matched.
			Cached address table entry containing port value 0
			matches any port.
			Also, a <emphasis>0</emphasis> value for the argument will match any port in the
			address table.
			</para>
		</listitem>
		<listitem>
			proto (string)
		<para>
			This argument represents the protocol used for transport;
			Transport protocol is either "ANY" or any
			valid transport protocol value: "UDP, "TCP", "TLS", and "SCTP".
		</para>
		</listitem>
		<listitem>
			context_info (var, optional)
		<para>
			This argument represents the variable in wich the context_info field
			from the cached address table will be stored in case of match.
		</para>
		</listitem>
		<listitem>
			pattern (string, optional)
		<para>
			This argument is a string to be matched against the wildcard
			pattern field from the address table.
		</para>
		</listitem>
		<listitem>
			partition (string, optional)
		<para>
			An optional parition name for the group id. If no partition
			specified, the <quote>default</quote> one will be used.
		</para>
		</listitem>

		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
		LOCAL_ROUTE, BRANCH_ROUTE, STARTUP_ROUTE, TIMER_ROUTE, EVENT_ROUTE.
		</para>
		<example>
		<title><function>check_address()
		</function> usage</title>
		<programlisting format="linespecific">
...

// Checks if the tuple IP address/port (given as strings) and source protocol
// (given as pvar), belongs to group 4, verifies if the string "texttest"
// matches the wildcard pattern field in the database table and stores the
// context information in $avp(ctx)
if (check_address( 4, "192.168.2.135", 5700, "$socket_in(proto)", $avp(ctx), "texttest")) {
	t_relay();
	xlog("$avp(ctx)\n");
}

if (check_address( 4, "192.168.2.135", 5700, "$socket_in(proto)", , , "my_part")) {
	t_relay();
	xlog("$avp(ctx)\n");
}
...

// Checks if the tuple IP address/port/protocol of the source message is in group 4
if (check_address( 4, "$si", "$sp", "$socket_in(proto)")) {
	t_relay();
}

...

// Checks if the tuple IP address/port/protocol stored in AVPs s:ip/s:port/s:proto
// is in group 4 and stores context information in $avp(ctx)
$avp(ip) = "192.168.2.135";
$avp(port) = 5061;
$avp(proto) = "any";
$avp(partition)="my_part";
if (check_address( 4, $avp(ip), $avp(port), $avp(proto), $avp(ctx), , $avp(partition))) {
	t_relay();
	xlog("$avp(ctx)\n");
}

...

// Checks if the tuple IP address/port (given as strings) and source protocol
// (given as pvar) is in group 4, verifies if string the "texttest" matches
// the wildcard pattern field in the database table, without storing any
// context information
if (check_address( 4,$si, 5700, $socket_in(proto), ,"texttest")) {
	t_relay();
}

...

</programlisting>
		</example>
	</section>

	<section id="func_check_source_address" xreflabel="check_source_address()">
		<title>
		<function moreinfo="none">check_source_address(group_id , [context_info], [pattern], [partition])</function>
		</title>
		<para>
		Equivalent to check_address(group_id, "$si", "$sp", "$socket_in(proto)", context_info, pattern, partition).
		</para>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
		LOCAL_ROUTE, BRANCH_ROUTE, STARTUP_ROUTE, TIMER_ROUTE, EVENT_ROUTE.
		</para>
		<example>
		<title><function>check_source_address()</function> usage</title>
		<programlisting format="linespecific">
...
// Check if source address/port/proto is in group 4 and stores
// context information in $avp(ctx)
if (check_source_address( 4,$avp(ctx), , , $avp(my_partition))) {
	xlog("$avp(ctx)\n");
}else {
	sl_send_reply(403, "Forbidden");
}
...
</programlisting>
		</example>
	</section>

	<section id="func_get_source_group" xreflabel="get_source_group()">
		<title>
		<function moreinfo="none">get_source_group(var,[partition])</function>
		</title>
		<para>
		Checks if an entry with the source ip/port/protocol is
		found in cached address or subnet table in any group.
		If yes, returns that group in the variable parameter.
		If not returns -1.  Port value 0 in cached address and
		subnet table matches any port. Optionally, you can also
		specify the partition. If no partition
		specified, the <quote>default</quote> one will be used.
		</para>
		<para>Parameters:</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>var</emphasis> (var)
			</para></listitem>
			<listitem><para>
				<emphasis>partition</emphasis> (string, optional)
			</para></listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
		LOCAL_ROUTE, BRANCH_ROUTE.
		</para>
		<example>
		<title><function>get_source_group()</function> usage</title>
		<programlisting format="linespecific">

...

if ( get_source_group( $var(group)) ) {
   # do something with $var(group)
   xlog("group is $var(group)\n");
};
...

</programlisting>
		</example>
	</section>

	<section id="func_allow_routing" xreflabel="allow_routing()">
		<title>
		<function moreinfo="none">allow_routing()</function>
		</title>
		<para>
		Returns true if all pairs constructed as described in <xref
			linkend="sec-call-routing"/> have appropriate permissions according to
		the configuration files. This function uses default configuration
		files specified in <varname>default_allow_file</varname> and
		<varname>default_deny_file</varname>.
		</para>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
		</para>
		<example>
		<title><function>allow_routing</function> usage</title>
		<programlisting format="linespecific">
...
if (allow_routing()) {
	t_relay();
};
...
</programlisting>
		</example>
	</section>
	<section id="func_allow_routing_1" xreflabel="allow_routing()">
		<title>
		<function moreinfo="none">allow_routing(basename)</function>
		</title>
		<para>
		Returns true if all pairs constructed as described in <xref
			linkend="sec-call-routing"/> have appropriate permissions according
		to the configuration files given as parameters.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>basename</emphasis> (string) - Basename from which allow
			and deny filenames will be created by appending contents of
			<varname>allow_suffix</varname> and <varname>deny_suffix</varname>
			parameters.
			</para>
			<para>
			If the parameter doesn't contain full pathname then the function
			expects the file to be located in the same directory as the main
			configuration file of the server.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
		</para>
		<example>
		<title><function>allow_routing(basename)</function> usage</title>
		<programlisting format="linespecific">
...
if (allow_routing("basename")) {
	t_relay();
};
...
</programlisting>
		</example>
	</section>
	<section id="func_allow_register" xreflabel="allow_register()">
		<title>
		<function moreinfo="none">allow_register(basename)</function>
		</title>
		<para>
		The function returns true if all pairs constructed as described in <xref
			linkend="sec-registration-permissions"/> have appropriate permissions
		according to the configuration files given as parameters.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>basename</emphasis> (string) - Basename from which allow
			and deny filenames will be created by appending contents of
			<varname>allow_suffix</varname> and <varname>deny_suffix</varname>
			parameters.
			</para>
			<para>
			If the parameter doesn't contain full pathname then the function
			expects the file to be located in the same directory as the main
			configuration file of the server.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
		</para>
		<example>
		<title><function>allow_register(basename)</function> usage</title>
		<programlisting format="linespecific">
...
if ($rm=="REGISTER") {
	if (allow_register("register")) {
		save("location");
		exit;
	} else {
		sl_send_reply(403, "Forbidden");
	};
};
...
</programlisting>
		</example>
	</section>
	<section id="func_allow_uri" xreflabel="allow_uri()">
		<title>
		<function moreinfo="none">allow_uri(basename, uri)</function>
		</title>
		<para>
		Returns true if the pair constructed as described in <xref
			linkend="sec-uri-permissions"/> have appropriate permissions
		according to the configuration files specified by the parameter.
		</para>
		<para>Meaning of the parameter is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>basename</emphasis> (string) - Basename from which allow
			and deny filenames will be created by appending contents of
			<varname>allow_suffix</varname> and <varname>deny_suffix</varname>
			parameters.
			</para>
			<para>
			If the parameter doesn't contain full pathname then the function
			expects the file to be located in the same directory as the main
			configuration file of the server.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>uri</emphasis> (string) - SIP URI to be checked.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
		</para>
		<example>
		<title><function>allow_uri(basename, uri)</function> usage</title>
		<programlisting format="linespecific">
...
if (allow_uri("basename", $rt)) {  // Check Refer-To URI
	t_relay();
};
if (allow_uri("basename", $avp(uri)) {  // Check URI stored in $avp(uri)
	t_relay();
};
...
</programlisting>
		</example>
	</section>

	</section>

	<section id="exported_mi_functions" xreflabel="Exported MI Functions">
	<title>Exported MI Functions</title>

	<section id="mi_address_reload" xreflabel="address_reload">
		<title>
		<function moreinfo="none">address_reload</function>
		</title>
		<para>
				Causes permissions module to re-read the contents of
				the address database table into cache
				memory.  In cache memory the entries are
				for performance reasons stored in two
                                different tables:  address table and
				subnet table depending on the value of
				the mask field (32 or smaller).
				</para>
		<para>Parameters:
			<itemizedlist>
				<listitem><para>
					<emphasis>partition</emphasis> -
					the name of the partition to be reloaded. If none
					specified all the partitions shall be reloaded.
				</para></listitem>
			</itemizedlist>
		</para>

	</section>

	<section id="mi_address_dump" xreflabel="address_dump">
		<title>
		<function moreinfo="none">address_dump</function>
		</title>
		<para>
				Causes permissions module to dump contents of
				the address table from cache memory.
				</para>
		<para>Parameters:
			<itemizedlist>
				<listitem><para>
					<emphasis>partition</emphasis> -
					the name of the partition to be dumped. If none
					specified all the partitions shall be dumped.
				</para></listitem>
			</itemizedlist>
		</para>


	</section>

	<section id="mi_subnet_dump" xreflabel="subnet_dump">
		<title>
		<function moreinfo="none">subnet_dump</function>
		</title>
		<para>
				Causes permissions module to dump
				contents of cache memory subnet table.
				</para>
		<para>Parameters:
			<itemizedlist>
				<listitem><para>
					<emphasis>partition</emphasis> -
					the name of the partition to be dumped. If none
					specified all the partitions shall be dumped.
				</para></listitem>
			</itemizedlist>
		</para>


	</section>

	<section id="mi_allow_uri" xreflabel="allow_uri">
		<title>
		<function moreinfo="none">allow_uri</function>
		</title>
		<para>
		Tests if (URI, Contact) pair is allowed according to
		allow/deny files.  The files must already have been
		 loaded by OpenSIPS.
		</para>
		<para>Parameters: </para>
		<itemizedlist>
			<listitem><para>
				<emphasis>basename</emphasis> -
						Basename from
		which allow and deny filenames will be created by
		appending contents of allow_suffix and deny_suffix
		parameters.
			</para></listitem>
			<listitem><para>
				<emphasis>URI</emphasis> - URI to be tested
			</para></listitem>
			<listitem><para>
				<emphasis>Contact</emphasis> - Contact
						to be tested
			</para></listitem>
		</itemizedlist>

	</section>
	</section>

</chapter>

