utils_admin.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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>Parameters</title>
  69. <section id="utils.p.http_query_timeout">
  70. <title><varname>http_query_timeout</varname> (int)</title>
  71. <para>
  72. Defines in seconds how long &kamailio; waits for response
  73. from HTTP server.
  74. </para>
  75. <para>
  76. <emphasis>
  77. Default value is zero, i.e.,
  78. that the http_query_timeout 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 id="utils.p.forward_active">
  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> - disabled.
  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 id="utils.p.pres_db_url">
  110. <title><varname>pres_db_url</varname> (string)</title>
  111. <para>
  112. Defines presence server database URL. If not
  113. given, the 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 id="utils.p.xcap_table">
  130. <title><varname>xcap_table</varname> (string)</title>
  131. <para>
  132. Defines the name of the xcap table in the presence server database.
  133. See the xcap_server module documentation for more information.
  134. </para>
  135. <para>
  136. <emphasis>
  137. Default value is <quote>xcap</quote>.
  138. </emphasis>
  139. </para>
  140. <example>
  141. <title>Set <varname>xcap_table</varname> parameter</title>
  142. <programlisting format="linespecific">
  143. ...
  144. modparam("utils", "xcap_table", "pres_xcap")
  145. ...
  146. </programlisting>
  147. </example>
  148. </section>
  149. </section>
  150. <section>
  151. <title>Functions</title>
  152. <section id="utils.f.http_query">
  153. <title>
  154. <function moreinfo="none">http_query(url, [post-data], result)</function>
  155. </title>
  156. <para>
  157. Sends HTTP GET or POST request according to URL given in
  158. <quote>url</quote> parameter, which is a string that may
  159. contain pseudo variables.
  160. </para>
  161. <para>
  162. If you want to make a POST-Request, you have to define
  163. the <quote>post</quote>-data, that should be submitted
  164. in that request as the second parameter.
  165. </para>
  166. <para>
  167. If HTTP server returns a class 2xx, 3xx or 4xx reply,
  168. the first line of the reply's body (if any) is
  169. stored in <quote>result</quote> parameter,
  170. which must be a writable pseudo variable.
  171. </para>
  172. <para>
  173. Function returns reply code of HTTP reply or -1
  174. if something went wrong.
  175. </para>
  176. <para>
  177. This function can be used from REQUEST_ROUTE,
  178. ONREPLY_ROUTE, FAILURE_ROUTE, and BRANCH_ROUTE.
  179. </para>
  180. <example>
  181. <title><function>http_query()</function> usage</title>
  182. <programlisting format="linespecific">
  183. ...
  184. # GET-Request
  185. http_query("http://tutpro.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
  186. "$var(result)")
  187. switch ($retcode) {
  188. ...
  189. }
  190. ...
  191. </programlisting>
  192. <programlisting format="linespecific">
  193. ...
  194. # POST-Request
  195. http_query("http://tutpro.com/index.php", "r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
  196. "$var(result)")
  197. switch ($retcode) {
  198. ...
  199. }
  200. ...
  201. </programlisting>
  202. </example>
  203. </section>
  204. <section id="utils.f.xcap_auth_status">
  205. <title>
  206. <function moreinfo="none">xcap_auth_status(watcher_uri, presentity_uri)</function>
  207. </title>
  208. <para>
  209. Function checks in the presence server database if
  210. a watcher is authorized to subscribe to event
  211. <quote>presence</quote> of presentity. Sphere
  212. checking is not included.
  213. </para>
  214. <para>
  215. Both watcher_uri and presentity_uri are
  216. pseudo variables. The function returns
  217. ACTIVE_STATUS, if a subscription is
  218. allowed and PENDING_STATUS, TERMINATED_STATUS,
  219. or WAITING_STATUS otherwise. See
  220. presence/subscribe.h for the corresponding integer
  221. codes. In case of error, function returns -1.
  222. </para>
  223. <para>
  224. Function can be used from REQUEST_ROUTE.
  225. </para>
  226. <example>
  227. <title><function>xcap_auth_status()</function> usage</title>
  228. <programlisting format="linespecific">
  229. ...
  230. if (method=="MESSAGE") {
  231. xcap_auth_status("$fu", $ru");
  232. if ($retcode == 1) {
  233. t_relay();
  234. } else {
  235. send_reply("403", "Forbidden");
  236. }
  237. }
  238. ...
  239. </programlisting>
  240. </example>
  241. </section>
  242. </section>
  243. <section>
  244. <title><acronym>MI</acronym> Commands</title>
  245. <section id="utils.m.forward_list">
  246. <title><function moreinfo="none">forward_list</function></title>
  247. <para>
  248. List active forward rules.
  249. </para>
  250. <para>
  251. No parameters.
  252. </para>
  253. <example>
  254. <title><function>forward_list</function> usage</title>
  255. <programlisting format="linespecific">
  256. ...
  257. &ctltool; fifo forward_list
  258. id switch filter proxy
  259. 0 off REGISTER:INVITE:SUBSCRIBE host-a.domain-a:5060
  260. ...
  261. </programlisting>
  262. </example>
  263. </section>
  264. <section id="utils.m.forward_switch">
  265. <title><function moreinfo="none">forward_switch</function></title>
  266. <para>
  267. This command can be used to activate or deactivate forwarding rules.
  268. The syntax of this configuration string is described in 1.6. (switch_setting_list).
  269. </para>
  270. <example>
  271. <title><function>forward_switch</function> usage</title>
  272. <programlisting format="linespecific">
  273. ...
  274. &ctltool; fifo forward_switch 0=on
  275. ...
  276. </programlisting>
  277. </example>
  278. </section>
  279. <section id="utils.m.forward_filter">
  280. <title><function moreinfo="none">forward_filter</function></title>
  281. <para>
  282. Can be used to specify the filter for a certain id. Messages will only be
  283. forwarded if one of the filters matches the message.
  284. </para>
  285. <para>
  286. There are special filters and regular filters.
  287. Special filters are:
  288. <itemizedlist>
  289. <listitem>REQUEST (matches on every request)</listitem>
  290. <listitem>REPLY (matches on every reply)</listitem>
  291. </itemizedlist>
  292. </para>
  293. <para>
  294. Regular filters are arbitrary strings not containing the
  295. delimiter ':'. They are matched against the request method
  296. names of the sip messages. The syntax of this configuration
  297. string is described in 1.6. (filter_setting_list).
  298. </para>
  299. <example>
  300. <title><function>forward_filter</function> usage</title>
  301. <programlisting format="linespecific">
  302. ...
  303. &ctltool; fifo forward_filter 0=REGISTER:INVITE
  304. ...
  305. </programlisting>
  306. </example>
  307. </section>
  308. <section id="utils.m.forward_proxy">
  309. <title><function moreinfo="none">forward_proxy</function></title>
  310. <para>
  311. This command can be used to configure forwarding rules. Specifies
  312. the destination for a certain id. Messages will be forwarded to
  313. this destination if the preconditions hold (matching id, filter, and
  314. switch). The syntax of this configuration string is described in 1.6.
  315. (proxy_setting_list).
  316. </para>
  317. <example>
  318. <title><function>forward_proxy</function> usage</title>
  319. <programlisting format="linespecific">
  320. ...
  321. &ctltool; fifo forward_proxy 0=host-c.domain-c:5060
  322. ...
  323. </programlisting>
  324. </example>
  325. </section>
  326. </section>
  327. <section>
  328. <title>Configuration syntax</title>
  329. <para>This grammar specify the usable configuration syntax</para>
  330. <itemizedlist>
  331. <listitem>switch_setting_list ::= switch_setting { "," switch_setting }</listitem>
  332. <listitem>filter_setting_list ::= switch_setting { "," switch_setting }</listitem>
  333. <listitem>proxy_setting_list ::= proxy_setting { "," proxy_setting }</listitem>
  334. <listitem>switch_setting ::= id "=" switch</listitem>
  335. <listitem>filter_setting ::= id "=" filter_list</listitem>
  336. <listitem>proxy_setting ::= id "=" proxy</listitem>
  337. <listitem>switch ::= ( "off" | "on" )</listitem>
  338. <listitem>filter_list ::= filter { ":" filter }</listitem>
  339. <listitem>proxy ::= host ":" port</listitem>
  340. <listitem>filter ::= ( special_filter | regular_filter )</listitem>
  341. <listitem>special_filter ::= ( "REQUEST" | "REPLY" )</listitem>
  342. <listitem>regular_filter ::= ? [^:]* ?</listitem>
  343. <listitem>host ::= char { char }</listitem>
  344. <listitem>char ::= ? A-Za-z0-9.-_ ?</listitem>
  345. <listitem>id ::= number</listitem>
  346. <listitem>port ::= number</listitem>
  347. <listitem>number ::= digit {digit}</listitem>
  348. <listitem>digit ::= ? 0-9 ?</listitem>
  349. </itemizedlist>
  350. </section>
  351. </chapter>