README 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. utils
  2. Juha Heinanen
  3. TutPro Inc.
  4. Copyright © 2008 Juha Heinanen
  5. __________________________________________________________________
  6. Table of Contents
  7. 1. Admin Guide
  8. 1. Overview
  9. 2. Dependencies
  10. 2.1. Kamailio Modules
  11. 2.2. External Libraries or Applications
  12. 3. Exported Parameters
  13. 3.1. http_query_timeout (int)
  14. 3.2. forward_active (int)
  15. 3.3. pres_db_url (string)
  16. 3.4. xcap_table (string)
  17. 4. Exported Functions
  18. 4.1. http_query(url, result)
  19. 4.2. xcap_auth_status(watcher_uri, presentity_uri)
  20. 5. MI Commands
  21. 5.1. forward_list
  22. 5.2. forward_switch
  23. 5.3. forward_filter
  24. 5.4. forward_proxy
  25. 6. Configuration syntax
  26. List of Examples
  27. 1.1. Set http_query_timeout parameter
  28. 1.2. Set forward_active parameter
  29. 1.3. Set pres_db_url parameter
  30. 1.4. Set xcap_table parameter
  31. 1.5. http_query() usage
  32. 1.6. xcap_auth_status() usage
  33. 1.7. forward_list usage
  34. 1.8. forward_switch usage
  35. 1.9. forward_filter usage
  36. 1.10. forward_proxy usage
  37. Chapter 1. Admin Guide
  38. Table of Contents
  39. 1. Overview
  40. 2. Dependencies
  41. 2.1. Kamailio Modules
  42. 2.2. External Libraries or Applications
  43. 3. Exported Parameters
  44. 3.1. http_query_timeout (int)
  45. 3.2. forward_active (int)
  46. 3.3. pres_db_url (string)
  47. 3.4. xcap_table (string)
  48. 4. Exported Functions
  49. 4.1. http_query(url, result)
  50. 4.2. xcap_auth_status(watcher_uri, presentity_uri)
  51. 5. MI Commands
  52. 5.1. forward_list
  53. 5.2. forward_switch
  54. 5.3. forward_filter
  55. 5.4. forward_proxy
  56. 6. Configuration syntax
  57. 1. Overview
  58. This module implements various utility functions that are not SIP
  59. related.
  60. Function http_query allows Kamailio to issue an HTTP GET request and
  61. get access to parts of the reply.
  62. The forward functionality allows Kamailio to configure forwarding at
  63. runtime with FIFO commands. The forwarding is executed in the pre
  64. script call back and therefore handled before the routing script is
  65. executed on the current message. The callback is not installed on
  66. default, thus this functionality has no runtime overhead when its
  67. deactivated.
  68. Function xcap_auth_status can be used to check from presence server
  69. database, if watcher is authorized to subscribe event "presence" of
  70. presentity.
  71. 2. Dependencies
  72. 2.1. Kamailio Modules
  73. 2.2. External Libraries or Applications
  74. 2.1. Kamailio Modules
  75. The following modules must be loaded before this module:
  76. * None.
  77. 2.2. External Libraries or Applications
  78. The following libraries or applications must be installed before
  79. running Kamailio with this module loaded:
  80. * libcurl.
  81. 3. Exported Parameters
  82. 3.1. http_query_timeout (int)
  83. 3.2. forward_active (int)
  84. 3.3. pres_db_url (string)
  85. 3.4. xcap_table (string)
  86. 3.1. http_query_timeout (int)
  87. Defines in seconds how long Kamailio waits response from HTTP server.
  88. Default value is "4".
  89. Example 1.1. Set http_query_timeout parameter
  90. ...
  91. modparam("utils", "http_query_timeout", 2)
  92. ...
  93. 3.2. forward_active (int)
  94. Defines if the forwarding callback should be installed.
  95. Default value is "0".
  96. Example 1.2. Set forward_active parameter
  97. ...
  98. modparam("utils", "forward_active", 1)
  99. ...
  100. 3.3. pres_db_url (string)
  101. Defines presence server database URL. If not given, xcap_auth_status
  102. function is disabled.
  103. There is no default value.
  104. Example 1.3. Set pres_db_url parameter
  105. ...
  106. modparam("utils", "pres_db_url", "mysql://foo:secret@localhost/pres")
  107. ...
  108. 3.4. xcap_table (string)
  109. Defines name of xcap table in presence server database.
  110. Default value is "xcap".
  111. Example 1.4. Set xcap_table parameter
  112. ...
  113. modparam("utils", "xcap_table", "pres_xcap")
  114. ...
  115. 4. Exported Functions
  116. 4.1. http_query(url, result)
  117. 4.2. xcap_auth_status(watcher_uri, presentity_uri)
  118. 4.1. http_query(url, result)
  119. Sends HTTP GET request according to URL given in "url" parameter, which
  120. is a string that may contain pseudo variables.
  121. If HTTP server returns a class 2xx or 3xx reply, first line of reply's
  122. body (if any) is stored in "result" parameter, which must be a writable
  123. pseudo variable.
  124. Function returns reply code of HTTP reply or -1 if something went
  125. wrong.
  126. This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
  127. FAILURE_ROUTE, and BRANCH_ROUTE.
  128. Example 1.5. http_query() usage
  129. ...
  130. http_query("http://tutpro.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{s
  131. .escape.param})",
  132. "$var(result)")
  133. switch ($retcode) {
  134. ...
  135. }
  136. ...
  137. 4.2. xcap_auth_status(watcher_uri, presentity_uri)
  138. Function checks from presence server database if watcher is authorized
  139. to subscribe event "presence" of presentity. Sphere checking is not
  140. included.
  141. Both watcher_uri and presentity_uri are pseudo variables. Function
  142. returns ACTIVE_STATUS, if subscription is allowed and PENDING_STATUS,
  143. TERMINATED_STATUS, or WAITING_STATUS otherwise. See
  144. presence/subscribe.h for the corresponding integer codes. In case of
  145. error, function returns -1.
  146. Function can be used from REQUEST_ROUTE.
  147. Example 1.6. xcap_auth_status() usage
  148. ...
  149. if (method=="MESSAGE") {
  150. xcap_auth_status("$fu", $ru");
  151. if ($retcode == 1) {
  152. t_relay();
  153. } else {
  154. send_reply("403", "Forbidden");
  155. }
  156. }
  157. ...
  158. 5. MI Commands
  159. 5.1. forward_list
  160. 5.2. forward_switch
  161. 5.3. forward_filter
  162. 5.4. forward_proxy
  163. 5.1. forward_list
  164. List active forward rules.
  165. No parameters.
  166. Example 1.7. forward_list usage
  167. ...
  168. kamctl fifo forward_list
  169. id switch filter proxy
  170. 0 off REGISTER:INVITE:SUBSCRIBE host-a.domain-a:5060
  171. ...
  172. 5.2. forward_switch
  173. This command can be used to activate or deactivate forwarding rules.
  174. The syntax of this configuration string is described in 1.6.
  175. (switch_setting_list).
  176. Example 1.8. forward_switch usage
  177. ...
  178. kamctl fifo sp_forward_switch 0=on
  179. ...
  180. 5.3. forward_filter
  181. Can be used to specify the filter for a certain id. Messages will only
  182. be forwarded if one of the filters matches the message.
  183. There are special filters and regular filters. Special filters are:
  184. * REQUEST (matches on every request)
  185. * REPLY (matches on every reply)
  186. Regular filters are arbitrary strings not containing the delimiter ':'.
  187. They are matched against the request method names of the sip messages.
  188. The syntax of this configuration string is described in 1.6.
  189. (filter_setting_list).
  190. Example 1.9. forward_filter usage
  191. ...
  192. kamctl fifo sp_forward_filter 0=REGISTER:INVITE
  193. ...
  194. 5.4. forward_proxy
  195. This command can be used to configure forwarding rules. Specifies the
  196. destination for a certain id. Messages will be forwarded to this
  197. destination if the preconditions hold (matching id, filter, and
  198. switch). The syntax of this configuration string is described in 1.6.
  199. (proxy_setting_list).
  200. Example 1.10. forward_proxy usage
  201. ...
  202. kamctl fifo sp_forward_proxy 0=host-c.domain-c:5060
  203. ...
  204. 6. Configuration syntax
  205. This grammar specify the usable configuration syntax
  206. * switch_setting_list ::= switch_setting { "," switch_setting }
  207. * filter_setting_list ::= switch_setting { "," switch_setting }
  208. * proxy_setting_list ::= proxy_setting { "," proxy_setting }
  209. * switch_setting ::= id "=" switch
  210. * filter_setting ::= id "=" filter_list
  211. * proxy_setting ::= id "=" proxy
  212. * switch ::= ( "off" | "on" )
  213. * filter_list ::= filter { ":" filter }
  214. * proxy ::= host ":" port
  215. * filter ::= ( special_filter | regular_filter )
  216. * special_filter ::= ( "REQUEST" | "REPLY" )
  217. * regular_filter ::= ? [^:]* ?
  218. * host ::= char { char }
  219. * char ::= ? A-Za-z0-9.-_ ?
  220. * id ::= number
  221. * port ::= number
  222. * number ::= digit {digit}
  223. * digit ::= ? 0-9 ?