Skip to content

Commit

Permalink
Merge pull request #442 from rgagnon24/redirect_fix
Browse files Browse the repository at this point in the history
Fix get_redirects(max, reason)
(cherry picked from commit ead1033)
  • Loading branch information
bogdan-iancu committed Apr 20, 2015
1 parent 89eb9fd commit b800d74
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 47 deletions.
23 changes: 20 additions & 3 deletions modules/uac_redirect/README
Expand Up @@ -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$ $Date$
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -338,6 +355,6 @@ failure_route[1] {
}

failure_route[2] {
get_redirects("6:2","redirect");
get_redirects("6:2", "300 redirect");
t_relay();
}
13 changes: 7 additions & 6 deletions modules/uac_redirect/doc/uac_redirect.xml
Expand Up @@ -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>
Expand Down
10 changes: 7 additions & 3 deletions modules/uac_redirect/doc/uac_redirect_admin.xml
Expand Up @@ -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
Expand All @@ -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>
Expand Down Expand Up @@ -503,7 +507,7 @@ failure_route[1] {
}

failure_route[2] {
get_redirects("6:2","redirect");
get_redirects("6:2", "300 redirect");
t_relay();
}
</programlisting>
Expand Down
6 changes: 3 additions & 3 deletions modules/uac_redirect/rd_funcs.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion modules/uac_redirect/rd_funcs.h
Expand Up @@ -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

59 changes: 28 additions & 31 deletions modules/uac_redirect/redirect.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -336,15 +333,15 @@ 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;

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);
Expand All @@ -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);
}
Expand Down

0 comments on commit b800d74

Please sign in to comment.