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

<chapter>

	<title>&adminguide;</title>

	<section id="overview" xreflabel="Overview">
	<title>Overview</title>
	<para>
		This is a module which provides a FIFO transport layer
		implementation for Management Interface. It receives the
		command over a FIFO file and returns the output through the
		reply_fifo specified.
	</para>
	<para>
		The module checks every 30 seconds if the FIFO file exists,
		and if it was deleted, it recreates it. If one wants to force
		the fifo file recreation, it should send a SIGHUP signal to
		the MI process PID.
	</para>
	</section>

	<section>
	<title>FIFO command syntax</title>
	<para>
		The external commands issued via FIFO interface must follow the
		following syntax:
		<para><emphasis>request = ':'(reply_fifo)?':'jsonrpc_command</emphasis></para>
	</para>
	<para>
		If the <emphasis>reply_fifo</emphasis> is missing, the MI FIFO
		module will not send any reply back. A similar behavior happens
		when the <emphasis>jsonrpc_command</emphasis> does not contain
		the <emphasis>id</emphasis> element, and the command is considered
		a JSON-RPC notification.
	</para>
	</section>

	<section>
	<title>Values Returned</title>
	<para>
		In case of success, a valid
		<ulink url="http://www.jsonrpc.org/specification">JSON-RPC</ulink>
		response is replied back on the fifo file, containing a successful
		JSON-RPC response.
	</para>
	<para>
		In case of failure of the MI command, a JSON-RPC reply error is
		sent back over the reply fifo file.
	</para>
	<para>
		If case of an error generated by the MI engine, mostly internal
		errors, an error cause is sent back over the reply FIFO in
		plain text.
	</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_fifo_name" xreflabel="fifo_name">
		<title><varname>fifo_name</varname> (string)</title>
		<para>
		The name of the FIFO file to be created for listening and
		reading external commands.
		</para>
		<para>
			<emphasis>NOTE:</emphasis>Starting with Linux kernel 4.19,
			processes can no longer read from FIFO files that are saved
			in directories with sticky bits (such as <emphasis>/tmp</emphasis>)
			and are not owned by the same user the process runs with. This
			prevents external tools (such as <emphasis>opensips-cli</emphasis>)
			from running MI commands using a different user (a
			<emphasis>Permissions denied</emphasis> error is triggered). If
			you are getting this error while trying to use
			<emphasis>opensips-cli</emphasis>, you can fix it by either store
			the fifo file in a non-sticky bit directory (such as
			<emphasis>/run/opensips</emphasis>), or disable the fifo
			protection using <emphasis>sysctl fs.protected_fifos = 0</emphasis>
			(NOT RECOMMENDED).
		</para>
		<para>
		<emphasis>
			Default value is "/tmp/opensips_fifo".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>fifo_name</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("mi_fifo", "fifo_name", "/tmp/opensips_b2b_fifo")
...
</programlisting>
		</example>
	</section>

	<section id="param_fifo_mode" xreflabel="fifo_mode">
		<title><varname>fifo_mode</varname> (integer)</title>
		<para>
		Permission to be used for creating the listening FIFO file. It
		follows the UNIX conventions.
		</para>
		<para>
		<emphasis>
			Default value is 0660 (rw-rw----).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>fifo_mode</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("mi_fifo", "fifo_mode", 0600)
...
</programlisting>
		</example>
	</section>

	<section id="param_fifo_group" xreflabel="fifo_group">
		<title><varname>fifo_group</varname> (integer)
		<varname>fifo_group</varname> (string)</title>
		<para>
		Group to be used for creating the listening FIFO file.
		</para>
		<para>
		<emphasis>
			Default value is the inherited one.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>fifo_group</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("mi_fifo", "fifo_group", 0)
modparam("mi_fifo", "fifo_group", "root")
...
</programlisting>
		</example>
	</section>

	<section id="param_fifo_user" xreflabel="fifo_user">
		<title><varname>fifo_user</varname> (integer)
		<varname>fifo_group</varname> (string)</title>
		<para>
		User to be used for creating the listening FIFO file.
		</para>
		<para>
		<emphasis>
			Default value is the inherited one.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>fifo_user</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("mi_fifo", "fifo_user", 0)
modparam("mi_fifo", "fifo_user", "root")
...
</programlisting>
		</example>
	</section>

	<section id="param_reply_dir" xreflabel="reply_dir">
		<title><varname>reply_dir</varname> (string)</title>
		<para>
		Directory to be used for creating the reply FIFO files.
		</para>
		<para>
		<emphasis>
			Default value is <quote>/tmp/</quote>
		</emphasis>
		</para>
		<example>
		<title>Set <varname>reply_dir</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("mi_fifo", "reply_dir", "/home/opensips/tmp/")
...
</programlisting>
		</example>
	</section>

	<section id="param_pretty_printing" xreflabel="pretty_printing">
		<title><varname>pretty_printing</varname> (int)</title>
		<para>
		Indicates whether the JSONRPC responses sent through MI should
		be pretty-printed or not.
		</para>
		<para>
		<emphasis>
			Default value is <quote>0 - no pretty-printing</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>pretty_printing</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("mi_fifo", "pretty_printing", 1)
...
</programlisting>
		</example>
	</section>

	<section id="param_trace_destination" xreflabel="trace_destination">
		<title><varname>trace_destination</varname> (string)</title>
		<para>
			Trace destination as defined in the tracing module. Currently
		the only tracing module is <emphasis role="bold">proto_hep</emphasis>.
		This is where traced mi messages will go.
		</para>
		<para>
			<emphasis role="bold">WARNING: </emphasis>A tracing module must be
			loaded in order for this parameter to work. (for example
			<emphasis role="bold">proto_hep</emphasis>).
		</para>
		<para>
		<emphasis>
			Default value is none(not defined).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_destination</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "trace_destination", "[hep_dest]10.0.0.2;transport=tcp;version=3")

modparam("mi_fifo", "trace_destination", "hep_dest")
...
</programlisting>
		</example>
	</section>

	<section id="param_trace_bwlist" xreflabel="trace_bwlist">
		<title><varname>trace_bwlist</varname> (string)</title>
		<para>
			Filter traced mi commands based on a blacklist or a whitelist.
		<emphasis role="bold">trace_destination</emphasis> must be defined for
		this parameter to have any purpose. Whitelists can be defined using
		'w' or 'W', blacklists using 'b' or 'B'. The type is separate by the
		actual blacklist by ':'. The mi commands in the list must be separated
		by ','.
		</para>
		<para>
			Defining a blacklists means all the commands that are not blacklisted
			will be traced. Defining a whitelist means all the commands that are
			not whitelisted will not be traced.
			<emphasis role="bold">WARNING: </emphasis> One can't define both
			a whitelist and a blacklist. Only one of them is allowed. Defining
			the parameter a second time will just overwrite the first one.
		</para>
		<para>
			<emphasis role="bold">WARNING: </emphasis>A tracing module must be
			loaded in order for this parameter to work. (for example
			<emphasis role="bold">proto_hep)</emphasis>.
		</para>
		<para>
		<emphasis>
			Default value is none(not defined).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_destination</varname> parameter</title>
		<programlisting format="linespecific">
...
## blacklist ps and which mi commands
## all the other commands shall be traced
modparam("mi_fifo", "trace_bwlist", "b: ps, which")
...
## allow only sip_trace mi command
## all the other commands will not be traced
modparam("mi_fifo", "trace_bwlist", "w: sip_trace")
...
</programlisting>
		</example>
	</section>

	</section>

	<section id="exported_functions" xreflabel="exported_functions">

	<title>Exported Functions</title>
		<para>
		No function exported to be used from configuration file.
		</para>
	</section>

	<section>
	<title>Example</title>
		<para>
		This is an example showing the FIFO format for the
		<quote>get_statistics dialog: tm:</quote> MI commad:
		response.
		</para>
		<example>
		<title>FIFO request</title>
		<programlisting format="linespecific">

:reply_fifo:{"jsonrpc":"2.0","method":"get_statistics","id":"5672","params":[["dialog:","tm:"]]}

</programlisting>
		</example>

	</section>


</chapter>

