• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..15-Apr-2021-

doc/H15-Apr-2021-647611

MakefileH A D15-Apr-2021210 125

READMEH A D15-Apr-202112.3 KiB430319

rd_filter.cH A D15-Apr-20212.6 KiB11563

rd_filter.hH A D15-Apr-20211.3 KiB4718

rd_funcs.cH A D15-Apr-20219 KiB340239

rd_funcs.hH A D15-Apr-20211.3 KiB4615

uac_redirect.cH A D15-Apr-202111.1 KiB476353

README

1UAC_REDIRECT Module
2
3Bogdan-Andrei Iancu
4
5   Voice System
6
7Edited by
8
9Bogdan-Andrei Iancu
10
11   Copyright © 2005 Voice Sistem
12     __________________________________________________________________
13
14   Table of Contents
15
16   1. Admin Guide
17
18        1. Overview
19        2. Accounting
20        3. Dependencies
21
22              3.1. Kamailio Modules
23              3.2. External Libraries or Applications
24
25        4. Parameters
26
27              4.1. default_filter (string)
28              4.2. deny_filter (string)
29              4.3. accept_filter (string)
30              4.4. acc_function (string)
31              4.5. acc_db_table (string)
32              4.6. bflags (int)
33              4.7. flags_hdr_mode (int)
34
35        5. Functions
36
37              5.1. set_deny_filter(filter,flags)
38              5.2. set_accept_filter(filter,flags)
39              5.3. get_redirects(max)
40              5.4. get_redirects(max,reason)
41
42        6. Script Example
43
44   List of Examples
45
46   1.1. Set default_filter module parameter
47   1.2. Set deny_filter module parameter
48   1.3. Set accept_filter module parameter
49   1.4. Set acc_function parameter
50   1.5. Set acc_db_table parameter
51   1.6. Set bflags module parameter
52   1.7. Set flags_hdr_mode parameter
53   1.8. set_deny_filter usage
54   1.9. set_accept_filter usage
55   1.10. get_redirects usage
56   1.11. get_redirects usage
57   1.12. Redirection script example
58
59Chapter 1. Admin Guide
60
61   Table of Contents
62
63   1. Overview
64   2. Accounting
65   3. Dependencies
66
67        3.1. Kamailio Modules
68        3.2. External Libraries or Applications
69
70   4. Parameters
71
72        4.1. default_filter (string)
73        4.2. deny_filter (string)
74        4.3. accept_filter (string)
75        4.4. acc_function (string)
76        4.5. acc_db_table (string)
77        4.6. bflags (int)
78        4.7. flags_hdr_mode (int)
79
80   5. Functions
81
82        5.1. set_deny_filter(filter,flags)
83        5.2. set_accept_filter(filter,flags)
84        5.3. get_redirects(max)
85        5.4. get_redirects(max,reason)
86
87   6. Script Example
88
891. Overview
90
91   UAC REDIRECT - User Agent Client redirection - module enhance Kamailio
92   with the functionality of being able to handle (interpret, filter, log
93   and follow) redirect responses ( 3xx replies class).
94
95   UAC REDIRECT module offer stateful processing, gathering the contacts
96   from all 3xx branches of a call.
97
98   The module provide a powerful mechanism for selecting and filtering the
99   contacts to be used for the new redirect:
100     * number based - limits like the number of total contacts to be used
101       or the maximum number of contacts per branch to be selected.
102     * Regular Expression based - combinations of deny and accept filters
103       allow a strict control of the contacts to be used for redirection.
104
105   When selecting from a 3xx branch the contacts to be used, the contacts
106   will be ordered and prioritized based on the “q” value.
107
1082. Accounting
109
110   UAC REDIRECT module allows to log all the redirection (to be later used
111   for CDR aggregation). This functionality may be dynamically enabled for
112   each redirection situation.
113
114   The logging will be done via the accounting module functions (all are
115   supported). The information to be logged will be the same as the normal
116   logged information directly via ACC module, but with following
117   differences:
118     * reason phrase - which will be dynamically set by the redirection
119       function;
120     * outgoing URI - which will be the redirect URI.
121
122   For each redirect contact, a separate record will be logged. For
123   example, if a call is redirected to three new contacts, the module will
124   log three additional records corresponding to each redirect URI.
125
1263. Dependencies
127
128   3.1. Kamailio Modules
129   3.2. External Libraries or Applications
130
1313.1. Kamailio Modules
132
133   The following modules must be loaded before this module:
134     * TM - Transaction Module, for accessing replies.
135     * ACC - Accounting Module, but only if the logging feature is used.
136
1373.2. External Libraries or Applications
138
139   The following libraries or applications must be installed before
140   running Kamailio with this module loaded:
141     * None
142
1434. Parameters
144
145   4.1. default_filter (string)
146   4.2. deny_filter (string)
147   4.3. accept_filter (string)
148   4.4. acc_function (string)
149   4.5. acc_db_table (string)
150   4.6. bflags (int)
151   4.7. flags_hdr_mode (int)
152
1534.1. default_filter (string)
154
155   The default behavior in filtering contacts. It may be “accept” or
156   “deny”.
157
158   The default value is “accept”.
159
160   Example 1.1. Set default_filter module parameter
161...
162modparam("uac_redirect","default_filter","deny")
163...
164
1654.2. deny_filter (string)
166
167   The regular expression for default deny filtering. It makes sense to be
168   defined only if the default_filter parameter is set to “accept”. All
169   contacts matching the deny_filter will be rejected; the rest of them
170   will be accepted for redirection.
171
172   The parameter may be defined only one - multiple definition will
173   overwrite the previous definitions. If more regular expression need to
174   be defined, use the set_deny_filter() scripting function.
175
176   This parameter is optional, it's default value being NULL.
177
178   Example 1.2. Set deny_filter module parameter
179...
180modparam("uac_redirect","deny_filter",".*@siphub\.net")
181...
182
1834.3. accept_filter (string)
184
185   The regular expression for default accept filtering. It makes sense to
186   be defined only if the default_filter parameter is set to “deny”. All
187   contacts matching the accept_filter will be accepted; the rest of them
188   will be rejected for redirection.
189
190   The parameter may be defined only one - multiple definition will
191   overwrite the previous definitions. If more regular expression need to
192   be defined, use the set_accept_filter() scripting function.
193
194   This parameter is optional, it's default value being NULL.
195
196   Example 1.3. Set accept_filter module parameter
197...
198modparam("uac_redirect","accept_filter",".*@siphub\.net")
199...
200
2014.4. acc_function (string)
202
203   Specifies the accounting function to be used. Just by defining this
204   parameter, the accounting support will not be enabled. Accounting may
205   only be enabled via two parameters set_accept_filter() scripting
206   function.
207
208   Its values may be:
209     * acc_log_request
210     * acc_db_request
211     * acc_rad_request
212     * acc_diam_request
213
214   The default value is “acc_log_request”.
215
216   Example 1.4. Set acc_function parameter
217...
218modparam("uac_redirect","acc_function","acc_db_request")
219...
220
2214.5. acc_db_table (string)
222
223   Specifies the accounting table to be used if DB accounting was chosen
224   (acc_function was set to “acc_db_request”). Just by defining this
225   parameter, the accounting support will not be enabled. Accounting may
226   only be enabled via two parameters set_accept_filter() scripting
227   function.
228
229   The default value is “acc”.
230
231   Example 1.5. Set acc_db_table parameter
232...
233modparam("uac_redirect","acc_db_table","acc_redirect")
234...
235
2364.6. bflags (int)
237
238   This parameter defines the branch-flags to be set for new, added
239   branch.
240
241   This parameter is optional, it's default value being 0.
242
243   Example 1.6. Set bflags module parameter
244...
245modparam("uac_redirect","bflags", 1)
246...
247
248branch_route[1] {
249        if (isbflagset(1)) {
250                log(1, "This branch comes from a 302 Forward Request.\n");
251        } else {
252                log(1, "This is a regular branch.\n");
253        }
254}
255
2564.7. flags_hdr_mode (int)
257
258   Specifies if and how a Contact's flags header parameter must be used.
259   If set, and a flags header parameter is set, its value will be set as
260   branch flags for that contact.
261
262   Its values may be:
263     * 0 - ignore flags header parameter, just use bflags module parameter
264     * 1 - use flags header parameter if present, ignore bflags module
265       parameter
266     * 2 - use flags header parameter if present and merge (binary or) it
267       with the bflags module parameter
268
269   The default value is “0”.
270
271   Example 1.7. Set flags_hdr_mode parameter
272...
273modparam("uac_redirect","flags_hdr_mode",2)
274...
275
2765. Functions
277
278   5.1. set_deny_filter(filter,flags)
279   5.2. set_accept_filter(filter,flags)
280   5.3. get_redirects(max)
281   5.4. get_redirects(max,reason)
282
2835.1.  set_deny_filter(filter,flags)
284
285   Sets additional deny filters. Maximum 6 may be combined. This
286   additional filter will apply only to the current message - it will not
287   have a global effect.
288
289   Default or previous added deny filter may be reset depending of the
290   flag parameter value:
291     * reset_all - reset both default and previous added deny filters;
292     * reset_default - reset only the default deny filter;
293     * reset_added - reset only the previous added deny filters;
294     * empty - no reset, just add the filter.
295
296   This function can be used from FAILURE_ROUTE.
297
298   Example 1.8. set_deny_filter usage
299...
300set_deny_filter(".*@domain2.net","reset_all");
301set_deny_filter(".*@domain1.net","");
302...
303
3045.2.  set_accept_filter(filter,flags)
305
306   Sets additional accept filters. Maximum 6 may be combined. This
307   additional filter will apply only to the current message - it will not
308   have a global effect.
309
310   Default or previous added deny filter may be reset depending of the
311   flag parameter value:
312     * reset_all - reset both default and previous added accept filters;
313     * reset_default - reset only the default accept filter;
314     * reset_added - reset only the previous added accept filters;
315     * empty - no reset, just add the filter.
316
317   This function can be used from FAILURE_ROUTE.
318
319   Example 1.9. set_accept_filter usage
320...
321set_accept_filter(".*@domain2.net","reset_added");
322set_accept_filter(".*@domain1.net","");
323...
324
3255.3.  get_redirects(max)
326
327   The function may be called only from failure routes. It will extract
328   the contacts from all 3xx branches and append them as new branches.
329   Note that the function will not forward the new branches, this must be
330   done explicitly from script.
331
332   How many contacts (in total and per branch) are selected depends of the
333   max parameter values. Its syntax is:
334     * max = max_total [":" max_branch]
335     * max_total = number of total contacts to be selected
336     * max_branch = number of contacts per branch to be selected
337
338   Both “max_total” and “max_branch” are positive integer. To specify
339   unlimited values, use 0 value or "*" character.
340
341   NOTE that during the selection process, each set of contacts from a
342   specific branch are ordered based on “q” value.
343
344   This function will produce no accounting records.
345
346   This function can be used from FAILURE_ROUTE.
347
348   Example 1.10. get_redirects usage
349...
350# max 2 contacts per branch, but no overall limit
351get_redirects("*:2");
352...
353# no limits per branch, but not more than 6 overall contacts
354get_redirects("6:*");
355...
356# no restrictions
357get_redirects("*");
358...
359
3605.4.  get_redirects(max,reason)
361
362   The function has same functionality as get_redirects(max) function, but
363   it will produce accounting records.
364
365   The accounting records will be mark by the reason phrase.
366
367   If this function appears in the script, at startup, the module will
368   import the accounting function. Otherwise not.
369
370   This function can be used from FAILURE_ROUTE.
371
372   Example 1.11. get_redirects usage
373...
374get_redirects("4:1","Redirected");
375...
376
3776. Script Example
378
379   Example 1.12. Redirection script example
380loadmodule "modules/sl/sl.so"
381loadmodule "modules/usrloc/usrloc.so"
382loadmodule "modules/registrar/registrar.so"
383loadmodule "modules/tm/tm.so"
384loadmodule "modules/acc/acc.so"
385loadmodule "modules/uac_redirect/uac_redirect.so"
386
387modparam("usrloc", "db_mode",   0)
388
389request_route{
390        if (uri==myself) {
391
392                if (method=="REGISTER") {
393                        save("location");
394                        exit;
395                }
396
397                if (!lookup("location")) {
398                        sl_send_reply("404", "Not Found");
399                        exit;
400                }
401                # do redirect with accounting
402                t_on_failure("REDIRECT_ACC");
403        } else {
404                # just do redirect
405                t_on_failure("REDIRECT_NOACC");
406        }
407
408        if (!t_relay()) {
409                sl_reply_error();
410        }
411}
412
413# redirect without storing acc record
414failure_route[REDIRECT_NOACC] {
415        if(!t_check_status("3[0-9][0-9]")) {
416                exit;
417        }
418        get_redirects("3:1");
419        t_relay();
420}
421
422# redirect with storing acc record
423failure_route[REDIRECT_ACC] {
424        if(!t_check_status("3[0-9][0-9]")) {
425                exit;
426        }
427        get_redirects("6:2", "redirect");
428        t_relay();
429}
430