lost: added civic address parsing via xpath
[kamailio] / src / modules / lost / doc / lost_admin.xml
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
5 <!-- Include general documentation entities -->
6 <!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
7 %docentities;
8
9 ]>
10 <!-- Module User's Guide -->
11
12 <chapter>
13         <title>&adminguide;</title>
14         <section>
15         <title>Overview</title>
16         <para>
17         SIP requests may be forwarded based on a location provided with the
18         request or retrieved from a specific location server using an identity
19         (HELD). This module implements the basic functionality to get or parse
20         location information (civic and geodetic) and to query a mapping service
21         (LOST) in order to get next hop based on location and service urn either
22         specified or provided with the request. 
23         </para>
24         <para>
25         This module implements protocol functions that use the http_client api
26         to fetch data from external LOST and HELD servers. The module is using
27         the http_client concept of "connections" to define properties of HTTP
28         sessions. A connection has one or multiple servers and a set of settings
29         that apply to the specific connection.
30         </para>
31         <para>
32         The function lost_held_query allows &kamailio; to assemble a HELD
33         locationRequest as defined in RFC6155
34         (<ulink url="https://tools.ietf.org/html/rfc6155"/>) to query location
35         information represented as PIDF-LO for a given identity (in most cases
36         a SIP URI). The identity may be a specific parameter or taken from the
37         P-Asserted-Identity or From header. The locationRequest response is
38         parsed and represented as PIDF-LO and location URI to dereference
39         location via HTTP(S).
40         </para>
41         <para>
42         The function lost_query allows &kamailio; to assemble a LOST
43         findService request  as defined in RFC5222
44         (<ulink url="https://tools.ietf.org/html/rfc5255"/>) to query 
45         routing information for a given (geodetic or civic) location and a service
46         URN. Both, PIDF-LO and service URN may be provided as function parameter,
47         or are taken from the request message if applicable. The findServiceResponse
48         is parsed and represented asdisplay name and SIP URI typically used as next
49         hop in a Route header.
50         </para>
51         <para>
52         The http_client module use the CURL library setting up connections.
53         The CURL library by default use the system configured DNS resolvers,
54         not the Kamailio resolver.
55         </para>
56         <para>
57         The module is limited to using HTTP and HTTPS protocols.
58         </para>
59         </section>
60         <section>
61             <title>Dependencies</title>
62             <section>
63                     <title>&kamailio; Modules</title>
64                     <para>
65                         The following modules must be loaded before this module:
66                 <itemizedlist>
67                 <listitem><para>
68                 HTTP_CLIENT - the http_client module should be
69                 loaded first in order to initialize connections properly.
70                 </para></listitem>
71                 <listitem><para>
72                 TLS - if you use TLS connections (https) the tls module should be
73                 loaded first in order to initialize &openssl; properly.
74                 </para></listitem>
75                             </itemizedlist>
76             </para>
77         </section>
78         <section>
79             <title>External Libraries or Applications</title>
80             <para>
81             The following libraries or applications must be
82             installed before running &kamailio; with this module loaded:
83                 <itemizedlist>
84                 <listitem>
85                 <para>
86                     <emphasis>&libcurl;</emphasis>
87                 </para>
88                 </listitem>
89                 <listitem>
90                 <para>
91                     <emphasis>libxml2</emphasis>
92                 </para>
93                 </listitem>
94                 </itemizedlist>
95             </para>
96         </section>
97         </section>
98         <section id="lost.p.general">
99                 <title>Parameters</title>
100         <para>
101         This module has no specific paramater but uses <emphasis>http_client</emphasis> therfore according
102         parameters may apply.
103         </para>
104         </section>
105         <section>
106             <title>Functions</title>
107                 <section id="lost.f.lost_held_query">
108                         <title>
109                                 <function moreinfo="none">lost_held_query(con, [id,] pidf-lo, url, error)</function>
110                         </title>
111                         <para>
112                         Sends a HELD locationRequest to a given connection. The device identity is either specified,
113             or the P-A-I header value, or the From header value.
114                 </para>
115                             <itemizedlist>
116                                     <listitem><para>
117                                                 <emphasis>con</emphasis> - the name of an existing
118                                                 HTTP connection, definied by a httpcon modparam
119                                     </para></listitem>
120                     <listitem><para>
121                                                 <emphasis>id</emphasis> - the device id used in the HELD
122                         locationRequest
123                     </para></listitem>
124                     <listitem><para>
125                                                 <emphasis>pidf-lo</emphasis> - the PIDF-LO returned in the
126                         HELD locationRequest response
127                     </para></listitem>
128                     <listitem><para>
129                                                 <emphasis>url</emphasis> - the location reference returned
130                         in the HELD locationRequest response - this reference may be
131                         added as Geolocation header value and forwarded downstream
132                     </para></listitem>
133                     <listitem><para>
134                                                 <emphasis>error</emphasis> - any error code returned in the
135                         HELD locationRequest response
136                     </para></listitem>
137                             </itemizedlist>
138                         <para>
139                         The return value is 200 on success, 400 if an internal error occured, or 500 if an
140             error code is returned in the HELD locationRequest response.
141                 </para>
142                         <para>
143                         This function can be used from REQUEST_ROUTE,
144                         ONREPLY_ROUTE, FAILURE_ROUTE, and BRANCH_ROUTE.
145                         </para>
146                         <example>
147                                 <title><function>lost_held_query()</function> usage</title>
148                                 <programlisting format="linespecific">
149 ...
150 modparam("http_client", "httpcon", "heldsrv=>http://service.org/api/held");
151 ...
152 # HELD location request
153 $var(id) = "sip:alice@atlanta";
154 $var(res) = lost_held_query("heldsrv", "$var(id)" , "$var(pidf)", "$var(url)", "$var(err)");
155 xlog("L_INFO", "HELD locationRequest: Result code $var(res)\nUrl: $var(url)\n$var(pidf)");
156 ...
157 $var(res) = lost_held_query("heldsrv", "$var(pidf)", "$var(url)"", "$var(err)");
158 xlog("L_INFO", "HELD locationRequest: Result code $var(res)\nUrl: $var(url)\n$var(pidf)\n");
159 ...
160                                 </programlisting>
161                         </example>
162                 </section>
163                 <section id="lost.f.lost_query">
164                         <title>
165                                 <function moreinfo="none">lost_query(con, [pidf-lo, urn,] uri, name, error)</function>
166                         </title>
167                         <para>
168                         Sends a LOST findService request to a given connection. PIDF-LO and URN are either specified,
169             or, if omitted, parsed from the message body (PIDF-LO) and request line (URN). Either "pidf-lo"
170             or "urn" can be set to an empty string in order to be ignored. 
171                 </para>
172                         <itemizedlist>
173                 <listitem><para>
174                     <emphasis>con</emphasis> - the name of an existing
175                     HTTP connection definied by a httpcon modparam
176                 </para></listitem>
177                 <listitem><para>
178                     <emphasis>pidf-lo</emphasis> - the PIDF-LO used to create the
179                     LOST findService request
180                 </para></listitem>
181                 <listitem><para>
182                     <emphasis>urn</emphasis> - the URN used to create the
183                     LOST findService request
184                 </para></listitem>
185                 <listitem><para>
186                     <emphasis>uri</emphasis> - the SIP uri returned in the
187                     LOST findServiceResponse
188                 </para></listitem>
189                 <listitem><para>
190                     <emphasis>name</emphasis> - the display name returned in the
191                     LOST findServiceResponse
192                 </para></listitem>
193                 <listitem><para>
194                     <emphasis>error</emphasis> - any error code returned in the
195                     LOST findServiceResponse
196                 </para></listitem>
197                         </itemizedlist>
198                         <para>
199                         The return value is 200 on success, 400 if an internal error occured, or 500 if an
200             error code is returned in the LOST findServiceResponse.
201                 </para>
202                         <para>
203                         This function can be used from REQUEST_ROUTE,
204                         ONREPLY_ROUTE, FAILURE_ROUTE, and BRANCH_ROUTE.
205                         </para>
206                         <example>
207                                 <title><function>lost()</function> usage</title>
208                                 <programlisting format="linespecific">
209 ...
210 modparam("http_client", "httpcon", "heldsrv=>http://service.org/api/held");
211 modparam("http_client", "httpcon", "lostsrv=>http://service.org/api/lost");
212 ...
213 # HELD location request
214 $var(id) = "sip:alice@atlanta";
215 $var(res) = lost_held_query("heldsrv", "$var(id)" , "$var(pidf)", "$var(url)", "$var(err)");
216 ...
217 # LOST findService request - pidf-lo and urn as parameter
218 $var(id) = "urn:service:sos";
219 $var(res) = lost_query("lostsrv", "$var(pidf)", "$var(urn)", "$var(uri)", "$var(name)", "$var(err)");
220 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $var(name)\n");
221 ...
222 # LOST findService request - pidf-lo as parameter, urn taken from request line
223 $var(res) = lost_query("lostsrv", "$var(pidf)", "", "$var(uri)", "$var(name)", "$var(err)");
224 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $var(name)\n");
225 ...
226 # LOST findService request - urn as parameter, pidf-lo taken from message body
227 $var(res) = lost_query("lostsrv", "", "$var(urn)", "$var(uri)", "$var(name)", "$var(err)");
228 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $var(name\n");
229 ...
230 # LOST findService request - pidf-lo and urn taken from message
231 $var(res) = lost_query("lostsrv", "$var(uri)", "$var(name)", "$var(err)");
232 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $var(name)\n");
233 ...
234                                 </programlisting>
235                         </example>
236                 </section>
237
238     </section>
239     <section id="lost.s.counters">
240             <title>Counters</title>
241         <para>
242             This module has no specific counters but uses http_client therefore
243             according counters may apply.
244         </para>
245         </section>
246
247     <section id="lost.s.remarks">
248         <title>Remarks</title>
249         <para>
250             Note: libcurl leak in CentOS 6 - this module uses libcurl library
251             (via http_client) and in case if you are using CentOS 6, be aware that
252             standard libcurl-7.19.7-52 has a memory leak. To fix this memory, install
253             libcurl from city-fan repository. More details at:
254             <ulink url="https://www.digitalocean.com/community/questions/how-to-upgrade-curl-in-centos6">
255             https://www.digitalocean.com/community/questions/how-to-upgrade-curl-in-centos6</ulink>
256         </para>
257         <para>
258             Note: http_client_query exported by the http_client API returns by default the first line of
259             the HTTP response (query_params.oneline = 1), but the lost module requires the complete
260             response message, which requires query_params.oneline set to 0. In the case lost_query
261             is used with the default http_client API, dereferencing location via HTTP provided with
262                         the Geolocation header causes an error. Therefore, to work properly, it requires to set
263                         <ulink url="https://www.kamailio.org/docs/modules/devel/modules/http_client.html#http_client.p.query_result">
264                         http_client module parameter query_result to 0</ulink>.
265         </para>
266     </section>
267 </chapter>