Debian Codegraph @

src/modules/lost/README

raw
1 LOST Module
2
3 Wolfgang Kampichler
4
5 Frequentis AG
6 DEC112 (funded by netidee)
7
8 Edited by
9
10 Wolfgang Kampichler
11
12 Copyright © 2018-2021 Wolfgang Kampichler
13 __________________________________________________________________
14
15 Table of Contents
16
17 1. Admin Guide
18
19 1. Overview
20 2. Dependencies
21
22 2.1. Kamailio Modules
23 2.2. External Libraries or Applications
24
25 3. Parameters
26
27 3.1. exact_type (int)
28 3.2. response_time (int)
29 3.3. location_type (string)
30 3.4. post_request (int)
31 3.5. location_profile (int)
32 3.6. location_3d (int)
33 3.7. geoheader_type (int)
34 3.8. geoheader_order (int)
35 3.9. recursion (int)
36 3.10. verbose (int)
37
38 4. Functions
39
40 4.1. lost_held_query(con, [id,] pidf-lo, url, error)
41 4.2. lost_held_dereference(url, rtime, rtype, pidf-lo,
42 error)
43
44 4.3. lost_query(con, [pidf-lo, urn,] uri, name, error)
45
46 5. Counters
47 6. Remarks
48
49 List of Examples
50
51 1.1. Set exact_type parameter
52 1.2. Set response_time parameter
53 1.3. Set location_type parameter
54 1.4. Set post_request parameter
55 1.5. Set location_profile parameter
56 1.6. Set location_3d parameter
57 1.7. Set geoheader_type parameter
58 1.8. Set geoheader_order parameter
59 1.9. Set recursion parameter
60 1.10. Set verbose parameter
61 1.11. lost_held_query() usage
62 1.12. lost_held_dereference() usage
63 1.13. lost() usage
64
65 Chapter 1. Admin Guide
66
67 Table of Contents
68
69 1. Overview
70 2. Dependencies
71
72 2.1. Kamailio Modules
73 2.2. External Libraries or Applications
74
75 3. Parameters
76
77 3.1. exact_type (int)
78 3.2. response_time (int)
79 3.3. location_type (string)
80 3.4. post_request (int)
81 3.5. location_profile (int)
82 3.6. location_3d (int)
83 3.7. geoheader_type (int)
84 3.8. geoheader_order (int)
85 3.9. recursion (int)
86 3.10. verbose (int)
87
88 4. Functions
89
90 4.1. lost_held_query(con, [id,] pidf-lo, url, error)
91 4.2. lost_held_dereference(url, rtime, rtype, pidf-lo, error)
92 4.3. lost_query(con, [pidf-lo, urn,] uri, name, error)
93
94 5. Counters
95 6. Remarks
96
97 1. Overview
98
99 SIP requests may be forwarded based on a location provided by the
100 request or retrieved from a specific location server using an identity
101 (HELD). This module implements the basic functionality to get or parse
102 location information (civic and geodetic) and to query a mapping
103 service (LOST) to get the next hop based on location and service urn
104 either specified or provided with the request.
105
106 This module implements protocol functions that use the http_client API
107 to fetch data from external LOST and HELD servers. The module is using
108 the http_client concept of "connections" to define properties of HTTP
109 sessions. A connection has one or multiple servers and a set of
110 settings that apply to the specific connection.
111
112 The function lost_held_query allows Kamailio to assemble a HELD
113 locationRequest as defined in RFC6155
114 (https://tools.ietf.org/html/rfc6155) to query location information
115 represented as PIDF-LO for a given identity (in most cases a SIP URI).
116 The identity may be a specific parameter or taken from the
117 P-Asserted-Identity or From header. The locationRequest response is
118 parsed and represented as PIDF-LO and location URI to dereference
119 location via HTTP(S).
120
121 The function lost_held_dereference allows Kamailio to assemble a HELD
122 dereference request as defined in RFC6155
123 (https://tools.ietf.org/html/rfc6753) to dereference location
124 information represented as PIDF-LO for a given URL. Required parameters
125 are an URL, responseTime, and responseType. The response is represented
126 as PIDF-LO.
127
128 The function lost_query allows Kamailio to assemble a LOST findService
129 request as defined in RFC5222 (https://tools.ietf.org/html/rfc5255) to
130 query routing information for a given (geodetic or civic) location and
131 a service URN. Both, PIDF-LO and service URN may be provided as
132 function parameters, or are taken from the request message if
133 applicable. The findServiceResponse is parsed and represented as
134 display name and SIP URI typically used as the next hop in a Route
135 header.
136
137 The http_client module uses the CURL library to set up connections. The
138 CURL library by default uses the system-configured DNS resolver, not
139 the Kamailio resolver.
140
141 The module is limited to using HTTP and HTTPS protocols.
142
143 2. Dependencies
144
145 2.1. Kamailio Modules
146 2.2. External Libraries or Applications
147
148 2.1. Kamailio Modules
149
150 The following modules must be loaded before this module:
151 * HTTP_CLIENT - the http_client module should be loaded first to
152 initialize connections properly.
153 * TLS - if you use TLS connections (https) the TLS module should be
154 loaded first in order to initialize OpenSSL properly.
155
156 2.2. External Libraries or Applications
157
158 The following libraries or applications must be installed before
159 running Kamailio with this module loaded:
160 * libcurl
161 * libxml2
162
163 3. Parameters
164
165 3.1. exact_type (int)
166 3.2. response_time (int)
167 3.3. location_type (string)
168 3.4. post_request (int)
169 3.5. location_profile (int)
170 3.6. location_3d (int)
171 3.7. geoheader_type (int)
172 3.8. geoheader_order (int)
173 3.9. recursion (int)
174 3.10. verbose (int)
175
176 Besides parameters listed, this module uses http_client therefore
177 appropriate module parameters may apply.
178
179 3.1. exact_type (int)
180
181 Indicates to the location server that the contents of the
182 "location_type" parameter must be strictly followed. Values are 0
183 (false) or 1 (true).
184
185 Default: 0 (false)
186
187 Example 1.1. Set exact_type parameter
188 ...
189 modparam("lost", "exact_type", 1)
190 ...
191
192 3.2. response_time (int)
193
194 A time value informs the location server how long the client is
195 prepared to wait for a response.
196
197 The value is expressed as an integer, either -1 'emergencyDispatch', 0
198 'emergencyRouting', a non-negative integer (>0) in units of
199 milliseconds. Note: The time value is indicative only.
200
201 Default: 0 ('emergencyRouting')
202
203 Example 1.2. Set response_time parameter
204 ...
205 modparam("lost", "response_time", 0)
206 ...
207
208 3.3. location_type (string)
209
210 The "locationType" element contains a list of types that are requested.
211 Values are "any", "geodetic", "civic" or "locationURI" and
212 combinations.
213 * any - returns location information in all forms available
214 * geodetic - returns a location by value in the form of a geodetic
215 location
216 * civic - returns a location by value in the form of a civic address
217 * locationURI - returns a set of location URIs (location by
218 reference)
219
220 Default: "geodetic locationURI".
221
222 Example 1.3. Set location_type parameter
223 ...
224 modparam("lost", "location_type", "civic geodetic locationURI")
225 ...
226
227 3.4. post_request (int)
228
229 Dereferencing the location can be done using either the HTTP GET or
230 POST method. This parameter globally defines whether only HTTP POST
231 method should be used. Values are 0 (GET) or 1 (POST).
232
233 Default: 0 (GET)
234
235 Example 1.4. Set post_request parameter
236 ...
237 modparam("lost", "post_request", 1)
238 ...
239
240 3.5. location_profile (int)
241
242 A Presence Information Data Format Location Object (PIDF-LO) may
243 contain geodetic or civic location profile or combinations. A LoST
244 findService contains only one location, which is selected via this
245 parameter as follows:
246 * 0 - takes the first location of any type
247 * 1 - takes the last location of any type
248 * 2 - takes the first geodetic location
249 * 3 - takes the first civic location
250
251 Default: 0 (first).
252
253 Example 1.5. Set location_profile parameter
254 ...
255 modparam("lost", "location_profile, 2)
256 ...
257
258 3.6. location_3d (int)
259
260 A Presence Information Data Format Location Object (PIDF-LO) may
261 contain one of the shape types as listed in RFC5491
262 (https://tools.ietf.org/html/rfc5491). A LoST findService request
263 currently contains only a profile for two-dimensional geodetic location
264 information, which is the default setting for this parameter. The
265 parameter can be set to 1 if a LoST server supports 3d, otherwise a 3d
266 location is reduced to 2d by the module.
267 * 0 - two-dimensional (2d) shape representations only
268 * 1 - three-dimensional (3d) volume representations allowed
269
270 Default: 0 (2d representations).
271
272 Example 1.6. Set location_3d parameter
273 ...
274 modparam("lost", "location_3d, 1)
275 ...
276
277 3.7. geoheader_type (int)
278
279 A Geolocation header may include a list of locationValues pointing to
280 either a Presence Information Data Format Location Object (PIDF-LO) in
281 the SIP body using a content-indirection (cid:) URI per RFC4483
282 (https://tools.ietf.org/html/rfc4483), or an http(s) URI pointing to an
283 external source. This parameter supports filtering of the following
284 types:
285 * 0 (any) - any URI (first or last)
286 * 1 (cid) - cid URI (aka Location-by-Value)
287 * 2 (http) - http URI (aka Location-by-Reference)
288 * 3 (https) - https URI (aka Location-by-Reference)
289
290 Default: 0 (any)
291
292 Example 1.7. Set geoheader_type parameter
293 ...
294 modparam("lost", "geoheader_type", 1)
295 ...
296
297 3.8. geoheader_order (int)
298
299 A Geolocation header may include a list of locationValues. This
300 parameter sets the order of the URI used to retrieve the location
301 information, either the first element of a certain type or the last.
302 Values are 0 (first) or 1 (last).
303
304 Default: 0 (first)
305
306 Example 1.8. Set geoheader_order parameter
307 ...
308 modparam("lost", "geoheader_order", 0)
309 ...
310
311 3.9. recursion (int)
312
313 A Geolocation header may include a list of locationValues. This
314 parameter sets the order of the URI used to retrieve the location
315 information, either the first element of a certain type or the last.
316 Values are 0 (first) or 1 (last).
317
318 Default: 1 (allowed)
319
320 Example 1.9. Set recursion parameter
321 ...
322 modparam("lost", "recursion", 0)
323 ...
324
325 3.10. verbose (int)
326
327 Detailed output of LoST findService, redirect or error response as
328 shown below. Values are 0 (disabled) or 1 (enabled).
329 ### LOST expires: [2031-01-27T14:54:21+00:00]
330 ### LOST lastUpdated: [2021-01-29T14:54:21+00:00]
331 ### LOST source: [ecrf.demo.gridgears.xx]
332 ### LOST sourceId: [06ac5b1c-d6c8-42bd-a667-5d1b90bb3d95]
333 ### LOST displayName: [Polizeinotruf (de)]
334 ### LOST serviceNumber: [112]
335 ### LOST service: [urn:service:sos]
336 ### LOST uri: [sip:[email protected]]
337 ### LOST via: [ecrf.demo.gridgears.xx]
338
339 Default: 0
340
341 Example 1.10. Set verbose parameter
342 ...
343 modparam("lost", "verbose", 1)
344 ...
345
346 4. Functions
347
348 4.1. lost_held_query(con, [id,] pidf-lo, url, error)
349 4.2. lost_held_dereference(url, rtime, rtype, pidf-lo, error)
350 4.3. lost_query(con, [pidf-lo, urn,] uri, name, error)
351
352 4.1. lost_held_query(con, [id,] pidf-lo, url, error)
353
354 Sends a HELD locationRequest to a given connection. The device identity
355 is either specified, or the P-A-I header value, or the From header
356 value.
357 * con - the name of an existing HTTP connection, defined by a httpcon
358 modparam
359 * id - the device id used in the HELD locationRequest
360 * pidf-lo - the PIDF-LO returned in the HELD locationRequest response
361 * url - the location reference returned in the HELD locationRequest
362 response - this reference may be added as Geolocation header value
363 and forwarded downstream. Note: to work properly, it is required to
364 include "locationURI" in the location_type parameter.
365 * error - any error code returned in the HELD response
366
367 The return value is 200 on success, 400 if an internal error occurred,
368 or 500 if an error code is returned in the HELD locationRequest
369 response.
370
371 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
372 FAILURE_ROUTE, and BRANCH_ROUTE.
373
374 Example 1.11. lost_held_query() usage
375 ...
376 modparam("http_client", "httpcon", "heldsrv=>http://service.org/api/held");
377 ...
378 # HELD location request
379 $var(id) = "sip:alice@atlanta";
380 $var(res) = lost_held_query("heldsrv", "$var(id)" , "$var(pidf)", "$var(url)", "
381 $var(err)");
382 xlog("L_INFO", "HELD locationRequest: Result code $var(res)\nUrl: $var(url)\n$va
383 r(pidf)");
384 ...
385 $var(res) = lost_held_query("heldsrv", "$var(pidf)", "$var(url)", "$var(err)");
386 xlog("L_INFO", "HELD locationRequest: Result code $var(res)\nUrl: $var(url)\n$va
387 r(pidf)\n");
388 ...
389
390 4.2. lost_held_dereference(url, rtime, rtype, pidf-lo, error)
391
392 Sends a HELD POST locationRequest to a given URL. Attributes are
393 responseTime and responseType. The locationType property "exact" is set
394 to "false".
395 * url - a URL received via Geolocation header to dereference location
396 * rtime - the response time as defined in Section 3.2, “response_time
397 (int)”
398 * rtype - the response type (location) as defined in Section 3.3,
399 “location_type (string)”
400 * pidf-lo - the PIDF-LO returned in the HELD locationRequest response
401 * error - any error code returned in the HELD response
402
403 The return value is 200..203 on success, 400 if an internal error
404 occurred, or 500 if an error code is returned in the HELD response.
405 Success codes in detail are as follows:
406 * 200 - received 200 OK, but neither location-info nor locationURI
407 element found
408 * 201 - received 200 OK with locationURI (aka Location-by-Reference)
409 * 202 - received 200 OK with location-info element (aka
410 Location-by-Value)
411 * 203 - received 200 OK with location-info and locationURI element
412
413 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
414 FAILURE_ROUTE, and BRANCH_ROUTE.
415
416 Example 1.12. lost_held_dereference() usage
417 ...
418 # HELD location dereference
419 if ($hdr(Geolocation)=~"^<http.*$") {
420 $var(url) = $(hdr(Geolocation){s.select,0,;});
421 $var(res) = lost_held_dereference("$(var(url){s.unbracket})", "emergencyDisp
422 atch", "civic geodetic", "$var(pidf)", "$var(err)");
423 xlog("L_INFO", "HELD location dereference: Result code $var(res)\n$var(pidf)
424 ");
425 ...
426 }
427
428 4.3. lost_query(con, [pidf-lo, urn,] uri, name, error)
429
430 Sends a LOST findService request to a given connection. PIDF-LO and URN
431 are either specified, or, if omitted, parsed from the message body
432 (PIDF-LO) and request line (URN). Either "pidf-lo" or "urn" can be set
433 to an empty string to be ignored.
434 * con - the name of an existing HTTP connection defined by a httpcon
435 modparam
436 * pidf-lo - the PIDF-LO used to create the LOST findService request
437 * urn - the URN used to create the LOST findService request
438 * uri - the SIP uri returned in the LOST findServiceResponse
439 * name - the display name returned in the LOST findServiceResponse
440 * error - any error code returned in the LOST findServiceResponse
441
442 The return value is 200 on success, 400 if an internal error occurred,
443 or 500 if an error code is returned in the LOST findServiceResponse.
444
445 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
446 FAILURE_ROUTE, and BRANCH_ROUTE.
447
448 Example 1.13. lost() usage
449 ...
450 modparam("http_client", "httpcon", "heldsrv=>http://service.org/api/held");
451 modparam("http_client", "httpcon", "lostsrv=>http://service.org/api/lost");
452 ...
453 # HELD location request
454 $var(id) = "sip:alice@atlanta";
455 $var(res) = lost_held_query("heldsrv", "$var(id)" , "$var(pidf)", "$var(url)", "
456 $var(err)");
457 ...
458 # LOST findService request - pidf-lo and urn as parameter
459 $var(id) = "urn:service:sos";
460 $var(res) = lost_query("lostsrv", "$var(pidf)", "$var(urn)", "$var(uri)", "$var(
461 name)", "$var(err)");
462 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $
463 var(name)\n");
464 ...
465 # LOST findService request - pidf-lo as parameter, urn taken from request line
466 $var(res) = lost_query("lostsrv", "$var(pidf)", "", "$var(uri)", "$var(name)", "
467 $var(err)");
468 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $
469 var(name)\n");
470 ...
471 # LOST findService request - urn as parameter, pidf-lo taken from message body
472 $var(res) = lost_query("lostsrv", "", "$var(urn)", "$var(uri)", "$var(name)", "$
473 var(err)");
474 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $
475 var(name\n");
476 ...
477 # LOST findService request - pidf-lo and urn taken from message
478 $var(res) = lost_query("lostsrv", "$var(uri)", "$var(name)", "$var(err)");
479 xlog("L_INFO", "LOST findService: Result code $var(res)\nUri: $var(uri)\nName: $
480 var(name)\n");
481 ...
482
483 5. Counters
484
485 This module has no specific counters but uses http_client therefore
486 according counters may apply.
487
488 6. Remarks
489
490 Note: libcurl leak in CentOS 6 - this module uses libcurl library (via
491 http_client) and in case you are using CentOS 6, be aware that standard
492 libcurl-7.19.7-52 has a memory leak. To fix this memory, install
493 libcurl from city-fan repository. More details at:
494 https://www.digitalocean.com/community/questions/how-to-upgrade-curl-in
495 -centos6.
496
497 Note: http_client_query exported by the http_client API returns by
498 default the first line of the HTTP response, but the lost module
499 requires the complete response message, otherwise dereferencing
500 location via the HTTP URL provided with the Geolocation header causes
501 an error. Therefore, to work properly, it is required to set the
502 http_client module parameter query_result to 0. More details at:
503 https://www.kamailio.org/docs/modules/devel/modules/http_client.html#ht
504 tp_client.p.query_result.
505
506 Note: to test the module with a mapping service (LOST), an API key may
507 be requested under the following link (search for "GET ACCESS"):
508 https://gridgears.at/.
509
510 Note: in case modparam "geoheader_type" is set to 2 (http), the module
511 may use 3 (https) as a fallback and vice versa.