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