|
|
ad1a97e |
From: Bogdan Andrei IANCU <bogdan@opensips.org>
|
|
|
ad1a97e |
Date: Mon, 20 Apr 2015 11:06:35 +0300
|
|
|
ad1a97e |
Subject: [PATCH] Merge pull request #442 from rgagnon24/redirect_fix
|
|
|
ad1a97e |
|
|
|
ad1a97e |
Fix get_redirects(max, reason)
|
|
|
ad1a97e |
(cherry picked from commit ead10331a2f5b024f885f1f69e160c78c9d8eb7b)
|
|
|
ad1a97e |
|
|
|
ad1a97e |
diff --git a/modules/uac_redirect/README b/modules/uac_redirect/README
|
|
|
ad1a97e |
index fc155b9..f0ae6f5 100644
|
|
|
ad1a97e |
--- a/modules/uac_redirect/README
|
|
|
ad1a97e |
+++ b/modules/uac_redirect/README
|
|
|
ad1a97e |
@@ -2,10 +2,20 @@ UAC_REDIRECT Module
|
|
|
ad1a97e |
|
|
|
ad1a97e |
Bogdan-Andrei Iancu
|
|
|
ad1a97e |
|
|
|
ad1a97e |
+ <bogdan@opensips.org>
|
|
|
ad1a97e |
+
|
|
|
ad1a97e |
Edited by
|
|
|
ad1a97e |
|
|
|
ad1a97e |
Bogdan-Andrei Iancu
|
|
|
ad1a97e |
|
|
|
ad1a97e |
+ <bogdan@opensips.org>
|
|
|
ad1a97e |
+
|
|
|
ad1a97e |
+Edited by
|
|
|
ad1a97e |
+
|
|
|
ad1a97e |
+Robert Gagnon
|
|
|
ad1a97e |
+
|
|
|
ad1a97e |
+ Telepoint Global Hosting Services, LLC
|
|
|
ad1a97e |
+
|
|
|
ad1a97e |
Copyright © 2005 Voice Sistem
|
|
|
ad1a97e |
Revision History
|
|
|
ad1a97e |
Revision $Revision: 8740 $ $Date$
|
|
|
ad1a97e |
@@ -284,7 +294,11 @@ get_redirects("*");
|
|
|
ad1a97e |
The function has same functionality as get_redirects(max)
|
|
|
ad1a97e |
function, but it will produce accounting records.
|
|
|
ad1a97e |
|
|
|
ad1a97e |
- The accounting records will be mark by the reason phrase.
|
|
|
ad1a97e |
+ The accounting records will be mark by the reason phrase. This
|
|
|
ad1a97e |
+ phrase shall be in the same format as the reason parameter that
|
|
|
ad1a97e |
+ would be passed to the accounting function set by the
|
|
|
ad1a97e |
+ acc_function module parameter. See the ACC module documentation
|
|
|
ad1a97e |
+ for more information.
|
|
|
ad1a97e |
|
|
|
ad1a97e |
If this function appears in the script, at startup, the module
|
|
|
ad1a97e |
will import the accounting function. Otherwise not.
|
|
|
ad1a97e |
@@ -293,7 +307,10 @@ get_redirects("*");
|
|
|
ad1a97e |
|
|
|
ad1a97e |
Example 1.9. get_redirects usage
|
|
|
ad1a97e |
...
|
|
|
ad1a97e |
-get_redirects("4:1","Redirected");
|
|
|
ad1a97e |
+get_redirects("4:1","300"); # Record 300, using the default reason stri
|
|
|
ad1a97e |
+ng for a 300
|
|
|
ad1a97e |
+get_redirects("4:1","302 Redirected"); # Record as 302, with custom "Re
|
|
|
ad1a97e |
+directed" reason string
|
|
|
ad1a97e |
...
|
|
|
ad1a97e |
|
|
|
ad1a97e |
1.6. Script Example
|
|
|
ad1a97e |
@@ -338,6 +355,6 @@ failure_route[1] {
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
|
|
|
ad1a97e |
failure_route[2] {
|
|
|
ad1a97e |
- get_redirects("6:2","redirect");
|
|
|
ad1a97e |
+ get_redirects("6:2", "300 redirect");
|
|
|
ad1a97e |
t_relay();
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
diff --git a/modules/uac_redirect/doc/uac_redirect.xml b/modules/uac_redirect/doc/uac_redirect.xml
|
|
|
ad1a97e |
index 8213fd0..7d7c553 100644
|
|
|
ad1a97e |
--- a/modules/uac_redirect/doc/uac_redirect.xml
|
|
|
ad1a97e |
+++ b/modules/uac_redirect/doc/uac_redirect.xml
|
|
|
ad1a97e |
@@ -20,16 +20,17 @@
|
|
|
ad1a97e |
<author>
|
|
|
ad1a97e |
<firstname>Bogdan-Andrei</firstname>
|
|
|
ad1a97e |
<surname>Iancu</surname>
|
|
|
ad1a97e |
- <address>
|
|
|
ad1a97e |
- <email>bogdan@opensips.org</email>
|
|
|
ad1a97e |
- </address>
|
|
|
ad1a97e |
+ <email>bogdan@opensips.org</email>
|
|
|
ad1a97e |
</author>
|
|
|
ad1a97e |
<editor>
|
|
|
ad1a97e |
<firstname>Bogdan-Andrei</firstname>
|
|
|
ad1a97e |
<surname>Iancu</surname>
|
|
|
ad1a97e |
- <address>
|
|
|
ad1a97e |
- <email>bogdan@opensips.org</email>
|
|
|
ad1a97e |
- </address>
|
|
|
ad1a97e |
+ <email>bogdan@opensips.org</email>
|
|
|
ad1a97e |
+ </editor>
|
|
|
ad1a97e |
+ <editor>
|
|
|
ad1a97e |
+ <firstname>Robert</firstname>
|
|
|
ad1a97e |
+ <surname>Gagnon</surname>
|
|
|
ad1a97e |
+ <affiliation><orgname>Telepoint Global Hosting Services, LLC</orgname></affiliation>
|
|
|
ad1a97e |
</editor>
|
|
|
ad1a97e |
</authorgroup>
|
|
|
ad1a97e |
<copyright>
|
|
|
ad1a97e |
diff --git a/modules/uac_redirect/doc/uac_redirect_admin.xml b/modules/uac_redirect/doc/uac_redirect_admin.xml
|
|
|
ad1a97e |
index 111ba6d..d3591a0 100644
|
|
|
ad1a97e |
--- a/modules/uac_redirect/doc/uac_redirect_admin.xml
|
|
|
ad1a97e |
+++ b/modules/uac_redirect/doc/uac_redirect_admin.xml
|
|
|
ad1a97e |
@@ -439,7 +439,10 @@ get_redirects("*");
|
|
|
ad1a97e |
</para>
|
|
|
ad1a97e |
<para>
|
|
|
ad1a97e |
The accounting records will be mark by the
|
|
|
ad1a97e |
- <emphasis>reason</emphasis> phrase.
|
|
|
ad1a97e |
+ <emphasis>reason</emphasis> phrase. This phrase shall be in the same format
|
|
|
ad1a97e |
+ as the <varname>reason</varname> parameter that would be passed to the
|
|
|
ad1a97e |
+ accounting function set by the <varname>acc_function</varname> module parameter.
|
|
|
ad1a97e |
+ See the ACC module documentation for more information.
|
|
|
ad1a97e |
</para>
|
|
|
ad1a97e |
<para>
|
|
|
ad1a97e |
If this function appears in the script, at startup, the module
|
|
|
ad1a97e |
@@ -452,7 +455,8 @@ get_redirects("*");
|
|
|
ad1a97e |
<title><function>get_redirects</function> usage</title>
|
|
|
ad1a97e |
<programlisting format="linespecific">
|
|
|
ad1a97e |
...
|
|
|
ad1a97e |
-get_redirects("4:1","Redirected");
|
|
|
ad1a97e |
+get_redirects("4:1","300"); # Record 300, using the default reason string for a 300
|
|
|
ad1a97e |
+get_redirects("4:1","302 Redirected"); # Record as 302, with custom "Redirected" reason string
|
|
|
ad1a97e |
...
|
|
|
ad1a97e |
</programlisting>
|
|
|
ad1a97e |
</example>
|
|
|
ad1a97e |
@@ -503,7 +507,7 @@ failure_route[1] {
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
|
|
|
ad1a97e |
failure_route[2] {
|
|
|
ad1a97e |
- get_redirects("6:2","redirect");
|
|
|
ad1a97e |
+ get_redirects("6:2", "300 redirect");
|
|
|
ad1a97e |
t_relay();
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
</programlisting>
|
|
|
ad1a97e |
diff --git a/modules/uac_redirect/rd_funcs.c b/modules/uac_redirect/rd_funcs.c
|
|
|
ad1a97e |
index 850a4be..32f1d5f 100644
|
|
|
ad1a97e |
--- a/modules/uac_redirect/rd_funcs.c
|
|
|
ad1a97e |
+++ b/modules/uac_redirect/rd_funcs.c
|
|
|
ad1a97e |
@@ -41,11 +41,11 @@
|
|
|
ad1a97e |
#define DEFAULT_Q_VALUE 10
|
|
|
ad1a97e |
|
|
|
ad1a97e |
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *shrpl,
|
|
|
ad1a97e |
- long max, struct acc_param *reason);
|
|
|
ad1a97e |
+ long max, pv_elem_t *reason);
|
|
|
ad1a97e |
|
|
|
ad1a97e |
|
|
|
ad1a97e |
int get_redirect( struct sip_msg *msg , int maxt, int maxb,
|
|
|
ad1a97e |
- struct acc_param *reason)
|
|
|
ad1a97e |
+ pv_elem_t *reason)
|
|
|
ad1a97e |
{
|
|
|
ad1a97e |
struct cell *t;
|
|
|
ad1a97e |
int max;
|
|
|
ad1a97e |
@@ -159,7 +159,7 @@ static void sort_contacts(contact_t *ct_list, str *ct_array,
|
|
|
ad1a97e |
* n - ok and n contacts added
|
|
|
ad1a97e |
*/
|
|
|
ad1a97e |
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
|
|
|
ad1a97e |
- long max, struct acc_param *reason)
|
|
|
ad1a97e |
+ long max, pv_elem_t *reason)
|
|
|
ad1a97e |
{
|
|
|
ad1a97e |
static struct sip_msg dup_rpl;
|
|
|
ad1a97e |
static str scontacts[MAX_CONTACTS_PER_REPLY];
|
|
|
ad1a97e |
diff --git a/modules/uac_redirect/rd_funcs.h b/modules/uac_redirect/rd_funcs.h
|
|
|
ad1a97e |
index b87b7d5..79c27f7 100644
|
|
|
ad1a97e |
--- a/modules/uac_redirect/rd_funcs.h
|
|
|
ad1a97e |
+++ b/modules/uac_redirect/rd_funcs.h
|
|
|
ad1a97e |
@@ -43,7 +43,7 @@ extern cmd_function rd_acc_fct;
|
|
|
ad1a97e |
extern char *acc_db_table;
|
|
|
ad1a97e |
|
|
|
ad1a97e |
int get_redirect( struct sip_msg *msg , int maxt, int maxb,
|
|
|
ad1a97e |
- struct acc_param *reason);
|
|
|
ad1a97e |
+ pv_elem_t *reason);
|
|
|
ad1a97e |
|
|
|
ad1a97e |
#endif
|
|
|
ad1a97e |
|
|
|
ad1a97e |
diff --git a/modules/uac_redirect/redirect.c b/modules/uac_redirect/redirect.c
|
|
|
ad1a97e |
index a235c2b..560786a 100644
|
|
|
ad1a97e |
--- a/modules/uac_redirect/redirect.c
|
|
|
ad1a97e |
+++ b/modules/uac_redirect/redirect.c
|
|
|
ad1a97e |
@@ -60,8 +60,8 @@ char *def_filter_s = 0;
|
|
|
ad1a97e |
static int redirect_init(void);
|
|
|
ad1a97e |
static int w_set_deny(struct sip_msg* msg, char *dir, char *foo);
|
|
|
ad1a97e |
static int w_set_accept(struct sip_msg* msg, char *dir, char *foo);
|
|
|
ad1a97e |
-static int w_get_redirect1(struct sip_msg* msg, char *dir, char *foo);
|
|
|
ad1a97e |
-static int w_get_redirect2(struct sip_msg* msg, char *dir, char *foo);
|
|
|
ad1a97e |
+static int w_get_redirect1(struct sip_msg* msg, char *max_c);
|
|
|
ad1a97e |
+static int w_get_redirect2(struct sip_msg* msg, char *max_c, pv_elem_t *reason);
|
|
|
ad1a97e |
static int regexp_compile(char *re_s, regex_t **re);
|
|
|
ad1a97e |
static int get_redirect_fixup(void** param, int param_no);
|
|
|
ad1a97e |
static int setf_fixup(void** param, int param_no);
|
|
|
ad1a97e |
@@ -137,62 +137,59 @@ int get_nr_max(char *s, unsigned char *max)
|
|
|
ad1a97e |
static int get_redirect_fixup(void** param, int param_no)
|
|
|
ad1a97e |
{
|
|
|
ad1a97e |
unsigned char maxb,maxt;
|
|
|
ad1a97e |
- struct acc_param *accp;
|
|
|
ad1a97e |
+ pv_elem_t *reason;
|
|
|
ad1a97e |
cmd_function fct;
|
|
|
ad1a97e |
char *p;
|
|
|
ad1a97e |
- char *s;
|
|
|
ad1a97e |
+ str s;
|
|
|
ad1a97e |
|
|
|
ad1a97e |
- s = (char*)*param;
|
|
|
ad1a97e |
- if (param_no==1) {
|
|
|
ad1a97e |
- if ( (p=strchr(s,':'))!=0 ) {
|
|
|
ad1a97e |
+ s.s = (char*)*param;
|
|
|
ad1a97e |
+ if (param_no == 1) {
|
|
|
ad1a97e |
+ if ( (p = strchr(s.s, ':')) != 0 ) {
|
|
|
ad1a97e |
/* have max branch also */
|
|
|
ad1a97e |
*p = 0;
|
|
|
ad1a97e |
- if (get_nr_max(p+1, &maxb)!=0)
|
|
|
ad1a97e |
+ if (get_nr_max(p + 1, &maxb) != 0)
|
|
|
ad1a97e |
return E_UNSPEC;
|
|
|
ad1a97e |
} else {
|
|
|
ad1a97e |
maxb = 0; /* infinit */
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
|
|
|
ad1a97e |
/* get max total */
|
|
|
ad1a97e |
- if (get_nr_max(s, &maxt)!=0)
|
|
|
ad1a97e |
+ if (get_nr_max(s.s, &maxt) != 0)
|
|
|
ad1a97e |
return E_UNSPEC;
|
|
|
ad1a97e |
|
|
|
ad1a97e |
pkg_free(*param);
|
|
|
ad1a97e |
- *param=(void*)(long)( (((unsigned short)maxt)<<8) | maxb);
|
|
|
ad1a97e |
+ *param = (void*)(long)( (((unsigned short)maxt) << 8) | maxb);
|
|
|
ad1a97e |
|
|
|
ad1a97e |
- } else if (param_no==2) {
|
|
|
ad1a97e |
+ } else if (param_no == 2) {
|
|
|
ad1a97e |
/* acc function loaded? */
|
|
|
ad1a97e |
- if (rd_acc_fct!=0)
|
|
|
ad1a97e |
+ if (rd_acc_fct != 0)
|
|
|
ad1a97e |
return 0;
|
|
|
ad1a97e |
/* must import the acc stuff */
|
|
|
ad1a97e |
- if (acc_fct_s==0 || acc_fct_s[0]==0) {
|
|
|
ad1a97e |
+ if (acc_fct_s == 0 || acc_fct_s[0] == 0) {
|
|
|
ad1a97e |
LM_ERR("acc support enabled, but no acc function defined\n");
|
|
|
ad1a97e |
return E_UNSPEC;
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
fct = find_export(acc_fct_s, 2, REQUEST_ROUTE);
|
|
|
ad1a97e |
- if ( fct==0 )
|
|
|
ad1a97e |
+ if (fct == 0)
|
|
|
ad1a97e |
fct = find_export(acc_fct_s, 1, REQUEST_ROUTE);
|
|
|
ad1a97e |
- if ( fct==0 ) {
|
|
|
ad1a97e |
+ if (fct == 0) {
|
|
|
ad1a97e |
LM_ERR("cannot import %s function; is acc loaded and proper "
|
|
|
ad1a97e |
"compiled?\n", acc_fct_s);
|
|
|
ad1a97e |
return E_UNSPEC;
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
rd_acc_fct = fct;
|
|
|
ad1a97e |
- /* set the reason str */
|
|
|
ad1a97e |
- accp = (struct acc_param*)pkg_malloc(sizeof(struct acc_param));
|
|
|
ad1a97e |
- if (accp==0) {
|
|
|
ad1a97e |
- LM_ERR("no more pkg mem\n");
|
|
|
ad1a97e |
- return E_UNSPEC;
|
|
|
ad1a97e |
- }
|
|
|
ad1a97e |
- memset( accp, 0, sizeof(struct acc_param));
|
|
|
ad1a97e |
- if (s!=0 && *s!=0) {
|
|
|
ad1a97e |
- accp->reason.s = s;
|
|
|
ad1a97e |
- accp->reason.len = strlen(s);
|
|
|
ad1a97e |
+ /* Convert reason into pv_elem_t */
|
|
|
ad1a97e |
+ if (s.s == 0 || s.s[0] == 0) {
|
|
|
ad1a97e |
+ s.s = "n/a";
|
|
|
ad1a97e |
+ s.len = 3;
|
|
|
ad1a97e |
} else {
|
|
|
ad1a97e |
- accp->reason.s = "n/a";
|
|
|
ad1a97e |
- accp->reason.len = 3;
|
|
|
ad1a97e |
+ s.len = strlen(s.s);
|
|
|
ad1a97e |
+ }
|
|
|
ad1a97e |
+ if (pv_parse_format(&s, &reason) < 0) {
|
|
|
ad1a97e |
+ LM_ERR("pv_parse_format failed\n");
|
|
|
ad1a97e |
+ return E_OUT_OF_MEM;
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
- *param=(void*)accp;
|
|
|
ad1a97e |
+ *param = (void*)reason;
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
|
|
|
ad1a97e |
return 0;
|
|
|
ad1a97e |
@@ -336,7 +333,7 @@ static int w_set_accept(struct sip_msg* msg, char *re, char *flags)
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
|
|
|
ad1a97e |
|
|
|
ad1a97e |
-static int w_get_redirect2(struct sip_msg* msg, char *max_c, char *reason)
|
|
|
ad1a97e |
+static int w_get_redirect2(struct sip_msg* msg, char *max_c, pv_elem_t *reason)
|
|
|
ad1a97e |
{
|
|
|
ad1a97e |
int n;
|
|
|
ad1a97e |
unsigned short max;
|
|
|
ad1a97e |
@@ -344,7 +341,7 @@ static int w_get_redirect2(struct sip_msg* msg, char *max_c, char *reason)
|
|
|
ad1a97e |
msg_tracer( msg, 0);
|
|
|
ad1a97e |
/* get the contacts */
|
|
|
ad1a97e |
max = (unsigned short)(long)max_c;
|
|
|
ad1a97e |
- n = get_redirect(msg , (max>>8)&0xff, max&0xff, (struct acc_param*)reason);
|
|
|
ad1a97e |
+ n = get_redirect(msg , (max>>8)&0xff, max&0xff, reason);
|
|
|
ad1a97e |
reset_filters();
|
|
|
ad1a97e |
/* reset the tracer */
|
|
|
ad1a97e |
msg_tracer( msg, 1);
|
|
|
ad1a97e |
@@ -353,7 +350,7 @@ static int w_get_redirect2(struct sip_msg* msg, char *max_c, char *reason)
|
|
|
ad1a97e |
}
|
|
|
ad1a97e |
|
|
|
ad1a97e |
|
|
|
ad1a97e |
-static int w_get_redirect1(struct sip_msg* msg, char *max_c, char *foo)
|
|
|
ad1a97e |
+static int w_get_redirect1(struct sip_msg* msg, char *max_c)
|
|
|
ad1a97e |
{
|
|
|
ad1a97e |
return w_get_redirect2(msg, max_c, 0);
|
|
|
ad1a97e |
}
|