utils_admin.xml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. This module implements various utility functions that are not SIP
  15. related.
  16. </para>
  17. <para>
  18. Function http_query allows &kamailio; to issue an HTTP GET
  19. request and get access to parts of the reply.
  20. </para>
  21. <para>
  22. The forward functionality allows &kamailio; to configure forwarding
  23. at runtime with FIFO commands. The forwarding is executed in the pre
  24. script call back and therefore handled before the routing script is
  25. executed on the current message. The callback is not installed on
  26. default, thus this functionality has no runtime overhead when its
  27. deactivated.
  28. </para>
  29. <para>
  30. Function xcap_auth_status can be used to check from presence
  31. server database, if watcher is authorized to subscribe event
  32. <quote>presence</quote> of presentity.
  33. </para>
  34. </section>
  35. <section>
  36. <title>Dependencies</title>
  37. <section>
  38. <title>&kamailio; Modules</title>
  39. <para>
  40. The following modules must be loaded before this module:
  41. <itemizedlist>
  42. <listitem>
  43. <para>
  44. <emphasis>a database module if
  45. xcap_auth_status function is enabled</emphasis>.
  46. </para>
  47. </listitem>
  48. </itemizedlist>
  49. </para>
  50. </section>
  51. <section>
  52. <title>External Libraries or Applications</title>
  53. <para>
  54. The following libraries or applications must be
  55. installed before
  56. running &kamailio; with this module loaded:
  57. <itemizedlist>
  58. <listitem>
  59. <para>
  60. <emphasis>libcurl</emphasis>.
  61. </para>
  62. </listitem>
  63. </itemizedlist>
  64. </para>
  65. </section>
  66. </section>
  67. <section>
  68. <title>Exported Parameters</title>
  69. <section>
  70. <title><varname>http_query_timeout</varname> (int)</title>
  71. <para>
  72. Defines in seconds how long &kamailio; waits response
  73. from HTTP server.
  74. </para>
  75. <para>
  76. <emphasis>
  77. Default value is null, i.e.,
  78. xcap_auth_status function is disabled.
  79. </emphasis>
  80. </para>
  81. <example>
  82. <title>Set <varname>http_query_timeout</varname> parameter</title>
  83. <programlisting format="linespecific">
  84. ...
  85. modparam("utils", "http_query_timeout", 2)
  86. ...
  87. </programlisting>
  88. </example>
  89. </section>
  90. <section>
  91. <title><varname>forward_active</varname> (int)</title>
  92. <para>
  93. Defines if the forwarding callback should be installed.
  94. </para>
  95. <para>
  96. <emphasis>
  97. Default value is <quote>0</quote>.
  98. </emphasis>
  99. </para>
  100. <example>
  101. <title>Set <varname>forward_active</varname> parameter</title>
  102. <programlisting format="linespecific">
  103. ...
  104. modparam("utils", "forward_active", 1)
  105. ...
  106. </programlisting>
  107. </example>
  108. </section>
  109. <section>
  110. <title><varname>pres_db_url</varname> (string)</title>
  111. <para>
  112. Defines presence server database URL. If not
  113. given, xcap_auth_status function is disabled.
  114. </para>
  115. <para>
  116. <emphasis>
  117. There is no default value.
  118. </emphasis>
  119. </para>
  120. <example>
  121. <title>Set <varname>pres_db_url</varname> parameter</title>
  122. <programlisting format="linespecific">
  123. ...
  124. modparam("utils", "pres_db_url", "mysql://foo:secret@localhost/pres")
  125. ...
  126. </programlisting>
  127. </example>
  128. </section>
  129. <section>
  130. <title><varname>xcap_table</varname> (string)</title>
  131. <para>
  132. Defines name of xcap table in presence server database.
  133. </para>
  134. <para>
  135. <emphasis>
  136. Default value is <quote>xcap</quote>.
  137. </emphasis>
  138. </para>
  139. <example>
  140. <title>Set <varname>xcap_table</varname> parameter</title>
  141. <programlisting format="linespecific">
  142. ...
  143. modparam("utils", "xcap_table", "pres_xcap")
  144. ...
  145. </programlisting>
  146. </example>
  147. </section>
  148. </section>
  149. <section>
  150. <title>Exported Functions</title>
  151. <section>
  152. <title>
  153. <function moreinfo="none">http_query(url, result)</function>
  154. </title>
  155. <para>
  156. Sends HTTP GET request according to URL given in
  157. <quote>url</quote> parameter, which is a string that may
  158. contain pseudo variables.
  159. </para>
  160. <para>
  161. If HTTP server returns a class 2xx or 3xx reply,
  162. first line of reply's body (if any) is
  163. stored in <quote>result</quote> parameter,
  164. which must be a writable pseudo variable.
  165. </para>
  166. <para>
  167. Function returns reply code of HTTP reply or -1
  168. if something went wrong.
  169. </para>
  170. <para>
  171. This function can be used from REQUEST_ROUTE,
  172. ONREPLY_ROUTE, FAILURE_ROUTE, and BRANCH_ROUTE.
  173. </para>
  174. <example>
  175. <title><function>http_query()</function> usage</title>
  176. <programlisting format="linespecific">
  177. ...
  178. http_query("http://tutpro.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
  179. "$var(result)")
  180. switch ($retcode) {
  181. ...
  182. }
  183. ...
  184. </programlisting>
  185. </example>
  186. </section>
  187. <section>
  188. <title>
  189. <function moreinfo="none">xcap_auth_status(watcher_uri, presentity_uri)</function>
  190. </title>
  191. <para>
  192. Function checks from presence server database if
  193. watcher is authorized to subscribe event
  194. <quote>presence</quote> of presentity. Sphere
  195. checking is not included.
  196. </para>
  197. <para>
  198. Both watcher_uri and presentity_uri are
  199. pseudo variables. Function returns
  200. ACTIVE_STATUS, if subscription is
  201. allowed and PENDING_STATUS, TERMINATED_STATUS,
  202. or WAITING_STATUS otherwise. See
  203. presence/subscribe.h for the corresponding integer
  204. codes. In case of error, function returns -1.
  205. </para>
  206. <para>
  207. Function can be used from REQUEST_ROUTE.
  208. </para>
  209. <example>
  210. <title><function>xcap_auth_status()</function> usage</title>
  211. <programlisting format="linespecific">
  212. ...
  213. if (method=="MESSAGE") {
  214. xcap_auth_status("$fu", $ru");
  215. if ($retcode == 1) {
  216. t_relay();
  217. } else {
  218. send_reply("403", "Forbidden");
  219. }
  220. }
  221. ...
  222. </programlisting>
  223. </example>
  224. </section>
  225. </section>
  226. <section>
  227. <title><acronym>MI</acronym> Commands</title>
  228. <section>
  229. <title><function moreinfo="none">forward_list</function></title>
  230. <para>
  231. List active forward rules.
  232. </para>
  233. <para>
  234. No parameters.
  235. </para>
  236. <example>
  237. <title><function>forward_list</function> usage</title>
  238. <programlisting format="linespecific">
  239. ...
  240. kamctl fifo forward_list
  241. id switch filter proxy
  242. 0 off REGISTER:INVITE:SUBSCRIBE host-a.domain-a:5060
  243. ...
  244. </programlisting>
  245. </example>
  246. </section>
  247. <section>
  248. <title><function moreinfo="none">forward_switch</function></title>
  249. <para>
  250. This command can be used to activate or deactivate forwarding rules.
  251. The syntax of this configuration string is described in 1.6. (switch_setting_list).
  252. </para>
  253. <example>
  254. <title><function>forward_switch</function> usage</title>
  255. <programlisting format="linespecific">
  256. ...
  257. kamctl fifo sp_forward_switch 0=on
  258. ...
  259. </programlisting>
  260. </example>
  261. </section>
  262. <section>
  263. <title><function moreinfo="none">forward_filter</function></title>
  264. <para>
  265. Can be used to specify the filter for a certain id. Messages will only be
  266. forwarded if one of the filters matches the message.
  267. </para>
  268. <para>
  269. There are special filters and regular filters.
  270. Special filters are:
  271. <itemizedlist>
  272. <listitem>REQUEST (matches on every request)</listitem>
  273. <listitem>REPLY (matches on every reply)</listitem>
  274. </itemizedlist>
  275. </para>
  276. <para>
  277. Regular filters are arbitrary strings not containing the
  278. delimiter ':'. They are matched against the request method
  279. names of the sip messages. The syntax of this configuration
  280. string is described in 1.6. (filter_setting_list).
  281. </para>
  282. <example>
  283. <title><function>forward_filter</function> usage</title>
  284. <programlisting format="linespecific">
  285. ...
  286. kamctl fifo sp_forward_filter 0=REGISTER:INVITE
  287. ...
  288. </programlisting>
  289. </example>
  290. </section>
  291. <section>
  292. <title><function moreinfo="none">forward_proxy</function></title>
  293. <para>
  294. This command can be used to configure forwarding rules. Specifies
  295. the destination for a certain id. Messages will be forwarded to
  296. this destination if the preconditions hold (matching id, filter, and
  297. switch). The syntax of this configuration string is described in 1.6.
  298. (proxy_setting_list).
  299. </para>
  300. <example>
  301. <title><function>forward_proxy</function> usage</title>
  302. <programlisting format="linespecific">
  303. ...
  304. kamctl fifo sp_forward_proxy 0=host-c.domain-c:5060
  305. ...
  306. </programlisting>
  307. </example>
  308. </section>
  309. </section>
  310. <section>
  311. <title>Configuration syntax</title>
  312. <para>This grammar specify the usable configuration syntax</para>
  313. <itemizedlist>
  314. <listitem>switch_setting_list ::= switch_setting { "," switch_setting }</listitem>
  315. <listitem>filter_setting_list ::= switch_setting { "," switch_setting }</listitem>
  316. <listitem>proxy_setting_list ::= proxy_setting { "," proxy_setting }</listitem>
  317. <listitem>switch_setting ::= id "=" switch</listitem>
  318. <listitem>filter_setting ::= id "=" filter_list</listitem>
  319. <listitem>proxy_setting ::= id "=" proxy</listitem>
  320. <listitem>switch ::= ( "off" | "on" )</listitem>
  321. <listitem>filter_list ::= filter { ":" filter }</listitem>
  322. <listitem>proxy ::= host ":" port</listitem>
  323. <listitem>filter ::= ( special_filter | regular_filter )</listitem>
  324. <listitem>special_filter ::= ( "REQUEST" | "REPLY" )</listitem>
  325. <listitem>regular_filter ::= ? [^:]* ?</listitem>
  326. <listitem>host ::= char { char }</listitem>
  327. <listitem>char ::= ? A-Za-z0-9.-_ ?</listitem>
  328. <listitem>id ::= number</listitem>
  329. <listitem>port ::= number</listitem>
  330. <listitem>number ::= digit {digit}</listitem>
  331. <listitem>digit ::= ? 0-9 ?</listitem>
  332. </itemizedlist>
  333. </section>
  334. </chapter>