Debian Codegraph @

src/modules/avp/README

raw
1 The AVP module
2
3 Jiri Kuthan
4
5 FhG Fokus
6 <[email protected]>
7
8 Michal Matyska
9
10 iptel
11 <[email protected]>
12
13 Copyright © 2004, 2005, 2006 FhG FOKUS, iptelorg GmbH
14 __________________________________________________________________
15
16 Table of Contents
17
18 1. Admin Guide
19
20 1. Overview
21 2. Functions
22
23 2.1. set_iattr(attribute, value)
24 2.2. flags2attr("$avp")
25 2.3. set_sattr(attribute, value)
26 2.4. print_attr($attribute)
27 2.5. attr2uri($attribute[, uri-part])
28 2.6. attr_exists(attribute)
29 2.7. attr_equals(attribute, value)
30 2.8. attr_equals_xl(attribute, xl_format)
31 2.9. dump_attrs()
32 2.10. xlset_attr($attribute, xl_format)
33 2.11. xlfix_attr($attribute)
34 2.12. insert_attr_hf(name)
35 2.13. insert_attr_hf(header_name, $avp_name)
36 2.14. append_attr_hf(name)
37 2.15. append_attr_hf(header_name, $avp_name)
38 2.16. replace_attr_hf(name)
39 2.17. replace_attr_hf(header_name, $avp_name)
40 2.18. attr_to_reply(name)
41 2.19. attr_to_reply(header_name, $avp_name)
42 2.20. attr_destination($avp_name)
43 2.21. xlset_destination(xl_format)
44 2.22. subst_attr($avp_name, subst_re)
45 2.23. del_attr($avp_name)
46 2.24. hdr_body2attrs(headername, prefix)
47 2.25. hdr_body2attrs2(headername, prefix)
48
49 3. Parameters
50
51 3.1. xlbuf_size (integer)
52
53 List of Examples
54
55 1.1. set_iattr usage
56 1.2. flags2attr usage
57 1.3. set_sattr usage
58 1.4. attr_exists usage
59 1.5. attr_equals_xl usage
60 1.6. insert_attr_hf usage
61 1.7. attr_to_reply usage
62 1.8. attr_destination usage
63 1.9. xlset_destination usage
64 1.10. subst_attr usage
65 1.11. del_attr usage
66 1.12. hdr_body2attrs and hdr_body2attrs2 usage
67 1.13. Set xlbuf_size parameter
68
69 Chapter 1. Admin Guide
70
71 Table of Contents
72
73 1. Overview
74 2. Functions
75
76 2.1. set_iattr(attribute, value)
77 2.2. flags2attr("$avp")
78 2.3. set_sattr(attribute, value)
79 2.4. print_attr($attribute)
80 2.5. attr2uri($attribute[, uri-part])
81 2.6. attr_exists(attribute)
82 2.7. attr_equals(attribute, value)
83 2.8. attr_equals_xl(attribute, xl_format)
84 2.9. dump_attrs()
85 2.10. xlset_attr($attribute, xl_format)
86 2.11. xlfix_attr($attribute)
87 2.12. insert_attr_hf(name)
88 2.13. insert_attr_hf(header_name, $avp_name)
89 2.14. append_attr_hf(name)
90 2.15. append_attr_hf(header_name, $avp_name)
91 2.16. replace_attr_hf(name)
92 2.17. replace_attr_hf(header_name, $avp_name)
93 2.18. attr_to_reply(name)
94 2.19. attr_to_reply(header_name, $avp_name)
95 2.20. attr_destination($avp_name)
96 2.21. xlset_destination(xl_format)
97 2.22. subst_attr($avp_name, subst_re)
98 2.23. del_attr($avp_name)
99 2.24. hdr_body2attrs(headername, prefix)
100 2.25. hdr_body2attrs2(headername, prefix)
101
102 3. Parameters
103
104 3.1. xlbuf_size (integer)
105
106 1. Overview
107
108 This module contains several functions that can be used to manipulate
109 the contents of AVPs (Attribute-Value pairs). The AVPs are variables
110 attached to the SIP message being processed. Each variable has its name
111 and value. AVPs can be used to store arbitrary data or as a means of
112 inter-module communication.
113
114 You may also want to check the avpops module which is more flexible and
115 contains more functions. In future Kamailio releases the avp module
116 will be probably deprecated in favor of avpops module.
117
118 2. Functions
119
120 2.1. set_iattr(attribute, value)
121 2.2. flags2attr("$avp")
122 2.3. set_sattr(attribute, value)
123 2.4. print_attr($attribute)
124 2.5. attr2uri($attribute[, uri-part])
125 2.6. attr_exists(attribute)
126 2.7. attr_equals(attribute, value)
127 2.8. attr_equals_xl(attribute, xl_format)
128 2.9. dump_attrs()
129 2.10. xlset_attr($attribute, xl_format)
130 2.11. xlfix_attr($attribute)
131 2.12. insert_attr_hf(name)
132 2.13. insert_attr_hf(header_name, $avp_name)
133 2.14. append_attr_hf(name)
134 2.15. append_attr_hf(header_name, $avp_name)
135 2.16. replace_attr_hf(name)
136 2.17. replace_attr_hf(header_name, $avp_name)
137 2.18. attr_to_reply(name)
138 2.19. attr_to_reply(header_name, $avp_name)
139 2.20. attr_destination($avp_name)
140 2.21. xlset_destination(xl_format)
141 2.22. subst_attr($avp_name, subst_re)
142 2.23. del_attr($avp_name)
143 2.24. hdr_body2attrs(headername, prefix)
144 2.25. hdr_body2attrs2(headername, prefix)
145
146 2.1. set_iattr(attribute, value)
147
148 Create an AVP of type integer.
149
150 Meaning of the parameter is as follows:
151 * attribute - The name of the AVP to be created.
152 * value - Integer value of the AVP.
153
154 Example 1.1. set_iattr usage
155 ...
156 set_iattr("fr_inv_timer", "60")
157 ...
158
159 2.2. flags2attr("$avp")
160
161 Store the current state of Kamailio flags into the specified AVP.
162
163 Example 1.2. flags2attr usage
164 ...
165 flags2attr("$msg_flags")
166 ...
167
168 2.3. set_sattr(attribute, value)
169
170 Create an AVP of type string.
171
172 Meaning of the parameter is as follows:
173 * attribute - The name of the AVP to be created.
174 * value - String value of the AVP.
175
176 Example 1.3. set_sattr usage
177 ...
178 set_sattr("called_number", "1234")
179 ...
180
181 2.4. print_attr($attribute)
182
183 Print the value of an AVP to syslog.
184
185 Meaning of the parameter is as follows:
186 * attribute - The name of the AVP.
187
188 2.5. attr2uri($attribute[, uri-part])
189
190 Rewrite the whole Request-URI of the message being processed with the
191 value of an AVP, or if an uri-part is specified, rewrite only that
192 specific part.
193
194 Meaning of the parameter is as follows:
195 * $attribute - The name of the AVP.
196 * uri-part - The name of the part of the uri that will be rewritten.
197 The supported values are: "prefix", "uri", "username", "user",
198 "usernamepassword", "userpass", "domain", "host", "domainport",
199 "hostport", "port", "strip", "strip_tail". "prefix" will add the
200 AVP as a prefix to the username (equivalent to prefix("string")),
201 "strip" and "strip_tail" expect a number in the AVP and they will
202 remove the specified number of characters from the beginning,
203 respective the end of the username part of the uri. The rest of the
204 uri-part values names are self-explaining.
205
206 2.6. attr_exists(attribute)
207
208 Test for the existence of AVP with given name. The function returns 1
209 if given AVP exists and -1 if not.
210
211 Meaning of the parameter is as follows:
212 * attribute - The name of the AVP.
213
214 Example 1.4. attr_exists usage
215 ...
216 if (attr_exists("saved_ruri")) {
217 attr2uri("saved_uri");
218 } else {
219 rewriteuri("sip:[email protected]");
220 };
221 ...
222
223 2.7. attr_equals(attribute, value)
224
225 Test whether an AVP with given name and value exists. The function
226 returns 1 if the AVP with given name and value exists and -1 if not.
227 The value of the AVP is compared string-wise. The comparison is case
228 sensitive.
229
230 Meaning of the parameter is as follows:
231 * attribute - The name of the AVP.
232 * value - The AVP value to look for.
233
234 2.8. attr_equals_xl(attribute, xl_format)
235
236 Test whether an AVP with given name and value exists. The function
237 returns 1 if the AVP with given name and value exists and -1 if not.
238 The value of the AVP is compared string-wise to the result of xprint
239 formatting call. The comparison is case sensitive.
240
241 Meaning of the parameter is as follows:
242 * attribute - The name of the AVP.
243 * xl_format - The xprint formatting string, result of which is looked
244 for in AVP.
245
246 Note: You must ensure, that the xprint module is loaded to be able to
247 use this function.
248
249 Example 1.5. attr_equals_xl usage
250 ...
251 if (attr_equals_xl("my_avp", "%ct")) {
252 # my_avp has value equal to current Contact header field
253 } else {
254 # my_avp was different
255 }
256 ...
257
258 2.9. dump_attrs()
259
260 Dumps all AVPs in user lists to the debug output (with level INFO).
261
262 The function does not require any parameters.
263
264 2.10. xlset_attr($attribute, xl_format)
265
266 Creates new AVP identified by attribute and assigns the result string
267 of xprint formatting rules as its value.
268
269 Meaning of the parameter is as follows:
270 * $attribute - The name of the AVP.
271 * xl_format - String used for xprint formatting. For detailed info
272 see documentation of xprint module.
273
274 Note: You must ensure, that the xprint module is loaded to be able to
275 use this function.
276
277 2.11. xlfix_attr($attribute)
278
279 Fixes an xl formatted attribute value to pure string.
280
281 Meaning of the parameter is as follows:
282 * $attribute - The name of the AVP.
283
284 2.12. insert_attr_hf(name)
285
286 Inserts new header into the request, which is being forwarded. The AVP
287 name is the name of the header field. If you need to insert header with
288 name which differs from the AVP name use insert_attr_hf(header_name,
289 $avp_name) instead.
290
291 Inserting means putting the header to the beginning of the request,
292 before any others.
293
294 Meaning of the parameter is as follows:
295 * name - The name of the header field which is inserted into
296 forwarded request as well as name of AVP which's value is put as
297 the header field value.
298
299 2.13. insert_attr_hf(header_name, $avp_name)
300
301 Inserts new header into the request, which is being forwarded.
302
303 Inserting means putting the header to the beginning of the request,
304 before any others.
305
306 Meaning of the parameter is as follows:
307 * header_name - The name of the header field which is inserted into
308 forwarded request.
309 * $avp_name - The name of AVP which's value is put as the header
310 field value.
311
312 Example 1.6. insert_attr_hf usage
313 ...
314 set_sattr("my_route","<sip:user@host:port;lr>");
315 insert_attr_hf("Route", "$my_route");
316 ...
317
318 2.14. append_attr_hf(name)
319
320 Appends new header into the request, which is being forwarded. The AVP
321 name is the name of the header field. If you need to append header with
322 name which differs from the AVP name use append_attr_hf(header_name,
323 $avp_name) instead.
324
325 Appending means putting the header to the end of the request, after any
326 others.
327
328 Meaning of the parameter is as follows:
329 * name - The name of the header field which is appended into
330 forwarded request as well as name of AVP which's value is put as
331 the header field value.
332
333 2.15. append_attr_hf(header_name, $avp_name)
334
335 Appends new header into the request, which is being forwarded.
336
337 Appending means putting the header to the end of the request, after any
338 others.
339
340 Meaning of the parameter is as follows:
341 * header_name - The name of the header field which is appended into
342 forwarded request.
343 * $avp_name - The name of AVP which's value is put as the header
344 field value.
345
346 2.16. replace_attr_hf(name)
347
348 Replaces header in the request, which is being forwarded. The AVP name
349 is the same as the name of the header field. If you need to replace
350 header with name which differs from the AVP name use
351 replace_attr_hf(header_name, $avp_name) instead.
352
353 Replacing means removing all the headers with specified name and
354 appending new one at the end, with the value from AVP.
355
356 Meaning of the parameter is as follows:
357 * name - The name of the header field which is replaced in forwarded
358 request as well as name of AVP which's value is put as the header
359 field value.
360
361 2.17. replace_attr_hf(header_name, $avp_name)
362
363 Replaces header in the request, which is being forwarded.
364
365 Replacing means removing all the headers with specified name and
366 appending new one at the end, with the value from AVP.
367
368 Meaning of the parameter is as follows:
369 * header_name - The name of the header field which is replaced in
370 forwarded request.
371 * $avp_name - The name of AVP which's value is put as the header
372 field value.
373
374 2.18. attr_to_reply(name)
375
376 Appends new header into the reply at the request time processing. The
377 AVP name is the name of the header field. If you need to append header
378 with name which differs from the AVP name use
379 attr_to_reply(header_name, $avp_name) instead.
380
381 If you need to append headers during reply processing you can use
382 insert_attr_hf and append_attr_hf. This function stores data and waits
383 for the reply being created.
384
385 Meaning of the parameter is as follows:
386 * name - The name of the header field which is appended into reply as
387 well as name of AVP which's value is put as the header field value.
388
389 2.19. attr_to_reply(header_name, $avp_name)
390
391 Appends new header into the reply at the request time processing.
392
393 Meaning of the parameter is as follows:
394 * header_name - The name of the header field which is appended into
395 reply.
396 * $avp_name - The name of AVP which's value is put as the header
397 field value.
398
399 Example 1.7. attr_to_reply usage
400 ...
401 xlset_attr("$my_route","<sip:%Hf:5080;lr>";
402 attr_to_reply("P-Hint-Route", "my_route");
403 ...
404
405 2.20. attr_destination($avp_name)
406
407 Sets the destination of the forwarded request to the value of AVP,
408 which must be either a SIP URI or a string in nameaddr format (e.g.
409 "Foo Bar" <sip:uri>).
410
411 Meaning of the parameter is as follows:
412 * $avp_name - The name of AVP which's value is used for further
413 request forwarding.
414
415 Example 1.8. attr_destination usage
416 ...
417 xlset_attr("$my_route","<sip:%<next_host>:%<next_port>;myparam=a123;lr>");
418 insert_attr_hf("Route", "$my_route");
419 attr_destination("$my_route");
420 t_relay();
421 ...
422
423 2.21. xlset_destination(xl_format)
424
425 Sets the destination of the forwarded request to the value of result of
426 xprint formatted string. Either SIP URI or nameaddr format is allowed.
427
428 Meaning of the parameter is as follows:
429 * xl_format - xprint module formatting string, the result is used for
430 request forwarding.
431
432 Note: You must ensure, that the xprint module is loaded to be able to
433 use this function.
434
435 Example 1.9. xlset_destination usage
436 ...
437 xlset_destination("%<next_host>:%<next_port>");
438 t_relay();
439 ...
440
441 2.22. subst_attr($avp_name, subst_re)
442
443 The value of the AVP identified by $avp_name name is matched and
444 substitued according to the subst_re sed like expression. Result of the
445 substitution is then stored in the original AVP.
446
447 Meaning of the parameter is as follows:
448 * $avp_name - Name of the AVP which will be used for the
449 substitution.
450 * subst_re - SED like match&replace regullar expression.
451
452 Example 1.10. subst_attr usage
453 ...
454 subst_attr("$uri","/tel:[0-9]*/sip:\[email protected];user=phone/");
455 ...
456
457 2.23. del_attr($avp_name)
458
459 The AVP identified by $avp_name name is deleted.
460
461 Meaning of the parameter is as follows:
462 * $avp_name - Name of the AVP which will be deleted.
463
464 Example 1.11. del_attr usage
465 ...
466 failure_route[1] {
467 if (status=~4[0-9][0-9]) {
468 if (attr_exists("backup_gw") {
469 append_branch;
470 attr_destination("backup_gw");
471 del_attr("backup_gw");
472 t_relay();
473 }
474 }
475 ...
476
477 2.24. hdr_body2attrs(headername, prefix)
478
479 Function parses a header body content scans for fld1=val1,fld2=val2,...
480 and creates bunch of avps prefixfld1:= val1, prefixfld2:= val2, .... If
481 possible stores values as integers.
482
483 Meaning of the parameter is as follows:
484 * headername - The header name, which will be scanned for the
485 name=value pairs.
486 If you want to create only AVPs with integer value use "/i" postfix
487 to the header name.
488 If you want to create only AVPs with string value use "/s" postfix
489 to the header name.
490 * prefix - The prefix, which is added before the name parsed from the
491 header body.
492
493 2.25. hdr_body2attrs2(headername, prefix)
494
495 Function parses a header body content scans for
496 fld1=val1,val2;fld2=val3,... and creates bunch of avps prefixfld1#1:=
497 val1, prefixfld1#2:= val2, prefixfld2:=val3 .... If possible stores
498 values as integers.
499
500 Meaning of the parameter is as follows:
501 * headername - The header name, which will be scanned for the
502 name=value pairs.
503 If you want to create only AVPs with integer value use "/i" postfix
504 to the header name.
505 If you want to create only AVPs with string value use "/s" postfix
506 to the header name.
507 * prefix - The prefix, which is added before the name parsed from the
508 header body.
509
510 Example 1.12. hdr_body2attrs and hdr_body2attrs2 usage
511 if (method=="BYE") {
512 # QoS reporting
513 if (search("^User-Agent: AVM FRITZ!Box Fon*")) {
514 hdr_body2attrs2("X-RTP-Stat/i", "QoS_");
515 xplog("L_INFO", "QoS: %Ts, %fu, %tu, %ci, %{User-Agent}, %{X-RTP
516 -Stat}\n");
517 } else if (search("^User-Agent: Sipura/*")) {
518 hdr_body2attrs("P-RTP-Stat/i", "QoS_");
519 xplog("L_INFO", "QoS: %Ts, %fu, %tu, %ci, %{User-Agent}, %{P-RTP
520 -Stat}\n");
521 }
522 }
523 # AVP QoS_xx now contain the values from appropriate header
524 # e.g. QoS_JI is jitter
525
526 3. Parameters
527
528 3.1. xlbuf_size (integer)
529
530 3.1. xlbuf_size (integer)
531
532 Defines size of internal buffer for all xprint formatting calls. If you
533 don't use xprint formatting calls, you can set it to 0 to preserve some
534 memory, if you get errors while formatting due to buffer size, you can
535 enlarge it.
536
537 Default value is 256.
538
539 Example 1.13. Set xlbuf_size parameter
540 ...
541 modparam("avp", "xlbuf_size", 1024)
542 ...