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