diff --git a/src/modules/uac_redirect/rd_filter.c b/src/modules/uac_redirect/rd_filter.c index 2764d40ef58..b245847ddfb 100644 --- a/src/modules/uac_redirect/rd_filter.c +++ b/src/modules/uac_redirect/rd_filter.c @@ -39,12 +39,12 @@ static int start_filters[NR_FILTER_TYPES]; void init_filters(void) { - memset( rd_filters , 0, NR_FILTER_TYPES*MAX_FILTERS*sizeof(regex_t*)); + memset(rd_filters, 0, NR_FILTER_TYPES * MAX_FILTERS * sizeof(regex_t *)); reset_filters(); } -void set_default_rule( int type ) +void set_default_rule(int type) { default_rule = type; } @@ -53,33 +53,33 @@ void set_default_rule( int type ) void reset_filters(void) { nr_filters[ACCEPT_FILTER] = 1; - nr_filters[DENY_FILTER] = 1; + nr_filters[DENY_FILTER] = 1; start_filters[ACCEPT_FILTER] = 0; - start_filters[DENY_FILTER] = 0; + start_filters[DENY_FILTER] = 0; } -void add_default_filter( int type, regex_t *filter) +void add_default_filter(int type, regex_t *filter) { rd_filters[type][0] = filter; } -int add_filter( int type, regex_t *filter, int flags) +int add_filter(int type, regex_t *filter, int flags) { - if ( nr_filters[type]==MAX_FILTERS ) { + if(nr_filters[type] == MAX_FILTERS) { LM_ERR("too many filters type %d\n", type); return -1; } /* flags? */ - if (flags&RESET_ADDED) + if(flags & RESET_ADDED) nr_filters[type] = 1; - if (flags&RESET_DEFAULT) + if(flags & RESET_DEFAULT) start_filters[type] = 1; /* set filter */ - rd_filters[type][ nr_filters[type]++ ] = filter; + rd_filters[type][nr_filters[type]++] = filter; return 0; } @@ -90,25 +90,24 @@ int run_filters(char *s) int i; /* check for accept filters */ - for( i=start_filters[ACCEPT_FILTER] ; i /* for regex */ #include -#define ACCEPT_FILTER 0 -#define DENY_FILTER 1 +#define ACCEPT_FILTER 0 +#define DENY_FILTER 1 #define NR_FILTER_TYPES 2 -#define ACCEPT_RULE 11 -#define DENY_RULE 12 +#define ACCEPT_RULE 11 +#define DENY_RULE 12 -#define RESET_ADDED (1<<0) -#define RESET_DEFAULT (1<<1) +#define RESET_ADDED (1 << 0) +#define RESET_DEFAULT (1 << 1) void init_filters(void); -void set_default_rule( int type ); +void set_default_rule(int type); void reset_filters(void); -void add_default_filter( int type, regex_t *filter); -int add_filter( int type, regex_t *filter, int flags); +void add_default_filter(int type, regex_t *filter); +int add_filter(int type, regex_t *filter, int flags); int run_filters(char *s); #endif diff --git a/src/modules/uac_redirect/rd_funcs.c b/src/modules/uac_redirect/rd_funcs.c index b5cfbee8a0f..e11b4cb8e14 100644 --- a/src/modules/uac_redirect/rd_funcs.c +++ b/src/modules/uac_redirect/rd_funcs.c @@ -34,14 +34,14 @@ extern sruid_t _redirect_sruid; extern int _redirect_q_value; -#define MAX_CONTACTS_PER_REPLY 16 +#define MAX_CONTACTS_PER_REPLY 16 -static int shmcontact2dset(struct sip_msg *req, struct sip_msg *shrpl, - long max, str *reason, unsigned int bflags); +static int shmcontact2dset(struct sip_msg *req, struct sip_msg *shrpl, long max, + str *reason, unsigned int bflags); -int get_redirect( struct sip_msg *msg , int maxt, int maxb, - str *reason, unsigned int bflags) +int get_redirect(struct sip_msg *msg, int maxt, int maxb, str *reason, + unsigned int bflags) { struct cell *t; str backup_uri; @@ -53,45 +53,46 @@ int get_redirect( struct sip_msg *msg , int maxt, int maxb, /* get transaction */ t = rd_tmb.t_gett(); - if (t==T_UNDEFINED || t==T_NULL_CELL) - { + if(t == T_UNDEFINED || t == T_NULL_CELL) { LM_CRIT("no current transaction found\n"); goto error; } - for(first_branch=t->nr_of_outgoings-1; first_branch>=0; first_branch--) - if(t->uac[first_branch].flags&TM_UAC_FLAG_FB) + for(first_branch = t->nr_of_outgoings - 1; first_branch >= 0; + first_branch--) + if(t->uac[first_branch].flags & TM_UAC_FLAG_FB) break; - if(first_branch<0) - { + if(first_branch < 0) { LM_CRIT("no current first branch found\n"); goto error; } LM_DBG("resume branch=%d\n", first_branch); - cts_added = 0; /* no contact added */ + cts_added = 0; /* no contact added */ backup_uri = msg->new_uri; /* shmcontact2dset will ater this value */ /* look if there are any 3xx branches starting from resume_branch */ - for( i=first_branch ; inr_of_outgoings ; i++) { + for(i = first_branch; i < t->nr_of_outgoings; i++) { LM_DBG("checking branch=%d (added=%d)\n", i, cts_added); /* is a redirected branch? */ - if (t->uac[i].last_received<300 || t->uac[i].last_received>399) + if(t->uac[i].last_received < 300 || t->uac[i].last_received > 399) continue; LM_DBG("branch=%d is a redirect (added=%d)\n", i, cts_added); /* ok - we have a new redirected branch -> how many contacts can * we get from it*/ - if (maxb==0) { - max = maxt?(maxt-cts_added):(-1); + if(maxb == 0) { + max = maxt ? (maxt - cts_added) : (-1); } else { - max = maxt?((maxt-cts_added>=maxb)?maxb:(maxt-cts_added)):maxb; + max = maxt ? ((maxt - cts_added >= maxb) ? maxb + : (maxt - cts_added)) + : maxb; } - if (max==0) + if(max == 0) continue; /* get the contact from it */ - n = shmcontact2dset( msg, t->uac[i].reply, max, reason, bflags); - if ( n<0 ) { - LM_ERR("get contact from shm_reply branch %d failed\n",i); + n = shmcontact2dset(msg, t->uac[i].reply, max, reason, bflags); + if(n < 0) { + LM_ERR("get contact from shm_reply branch %d failed\n", i); /* do not go to error, try next branches */ } else { /* count the added contacts */ @@ -103,68 +104,69 @@ int get_redirect( struct sip_msg *msg , int maxt, int maxb, msg->new_uri = backup_uri; /* return false if no contact was appended */ - return (cts_added>0)?1:-1; + return (cts_added > 0) ? 1 : -1; error: return -1; } - /* returns the number of contacts put in the sorted array */ -static int sort_contacts(hdr_field_t *chdr, contact_t **ct_array, - qvalue_t *q_array) +static int sort_contacts( + hdr_field_t *chdr, contact_t **ct_array, qvalue_t *q_array) { param_t *q_para; qvalue_t q; int n; - int i,j; + int i, j; char backup; contact_t *ct_list; hdr_field_t *hdr; n = 0; /* number of sorted contacts */ - for(hdr=chdr; hdr; hdr=hdr->next) { - if(hdr->type != HDR_CONTACT_T) continue; - ct_list = ((contact_body_t*)hdr->parsed)->contacts; - for( ; ct_list ; ct_list = ct_list->next ) { + for(hdr = chdr; hdr; hdr = hdr->next) { + if(hdr->type != HDR_CONTACT_T) + continue; + ct_list = ((contact_body_t *)hdr->parsed)->contacts; + for(; ct_list; ct_list = ct_list->next) { /* check the filters first */ backup = ct_list->uri.s[ct_list->uri.len]; ct_list->uri.s[ct_list->uri.len] = 0; - if ( run_filters( ct_list->uri.s )==-1 ){ + if(run_filters(ct_list->uri.s) == -1) { ct_list->uri.s[ct_list->uri.len] = backup; continue; } ct_list->uri.s[ct_list->uri.len] = backup; /* does the contact has a q val? */ q_para = ct_list->q; - if (q_para==0 || q_para->body.len==0) { + if(q_para == 0 || q_para->body.len == 0) { q = _redirect_q_value; } else { - if (str2q( &q, q_para->body.s, q_para->body.len)!=0) { + if(str2q(&q, q_para->body.s, q_para->body.len) != 0) { LM_ERR("invalid q param\n"); /* skip this contact */ continue; } } - LM_DBG("sort_contacts: <%.*s> q=%d\n", - ct_list->uri.len,ct_list->uri.s,q); + LM_DBG("sort_contacts: <%.*s> q=%d\n", ct_list->uri.len, + ct_list->uri.s, q); /*insert the contact into the sorted array */ - for(i=0;i=i ; j-- ) { - ct_array[j+1] = ct_array[j]; - q_array[j+1] = q_array[j]; + for(j = n - 1 - 1 * (n == MAX_CONTACTS_PER_REPLY); j >= i; + j--) { + ct_array[j + 1] = ct_array[j]; + q_array[j + 1] = q_array[j]; } - ct_array[j+1] = ct_list; - q_array[j+1] = q; - if (n!=MAX_CONTACTS_PER_REPLY) + ct_array[j + 1] = ct_list; + q_array[j + 1] = q; + if(n != MAX_CONTACTS_PER_REPLY) n++; } } @@ -173,21 +175,20 @@ static int sort_contacts(hdr_field_t *chdr, contact_t **ct_array, } - /* returns : -1 - error * 0 - ok, but no contact added * n - ok and n contacts added */ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl, - long max, str *reason, unsigned int bflags) + long max, str *reason, unsigned int bflags) { - static struct sip_msg dup_rpl; + static struct sip_msg dup_rpl; static contact_t *scontacts[MAX_CONTACTS_PER_REPLY]; - static qvalue_t sqvalues[MAX_CONTACTS_PER_REPLY]; + static qvalue_t sqvalues[MAX_CONTACTS_PER_REPLY]; struct hdr_field *hdr; struct hdr_field *contact_hdr; - contact_t *contacts; - int n,i; + contact_t *contacts; + int n, i; int added; int dup; int ret; @@ -203,23 +204,23 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl, ret = 0; /* success and no contact added */ contact_hdr = 0; - if (sh_rpl==0 || sh_rpl==FAKED_REPLY) + if(sh_rpl == 0 || sh_rpl == FAKED_REPLY) return 0; - if (sh_rpl->contact==0) { + if(sh_rpl->contact == 0) { /* contact header is not parsed */ - if ( sh_rpl->msg_flags&FL_SHM_CLONE ) { + if(sh_rpl->msg_flags & FL_SHM_CLONE) { /* duplicate the reply into private memory to be able * to parse it and afterwards to free the parsed mems */ - memcpy( &dup_rpl, sh_rpl, sizeof(struct sip_msg) ); + memcpy(&dup_rpl, sh_rpl, sizeof(struct sip_msg)); dup = 2; /* ok -> force the parsing of contact header */ - if ( parse_headers( &dup_rpl, HDR_EOH_F, 0)<0 ) { + if(parse_headers(&dup_rpl, HDR_EOH_F, 0) < 0) { LM_ERR("dup_rpl parse failed\n"); ret = -1; goto restore; } - if (dup_rpl.contact==0) { + if(dup_rpl.contact == 0) { LM_DBG("contact hdr not found in dup_rpl\n"); goto restore; } @@ -227,12 +228,12 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl, } else { dup = 3; /* force the parsing of contact header */ - if ( parse_headers( sh_rpl, HDR_EOH_F, 0)<0 ) { + if(parse_headers(sh_rpl, HDR_EOH_F, 0) < 0) { LM_ERR("sh_rpl parse failed\n"); ret = -1; goto restore; } - if (sh_rpl->contact==0) { + if(sh_rpl->contact == 0) { LM_DBG("contact hdr not found in sh_rpl\n"); goto restore; } @@ -245,76 +246,82 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl, /* parse the body of contact headers */ hdr = contact_hdr; while(hdr) { - if (hdr->type == HDR_CONTACT_T) { - if (hdr->parsed==0) { + if(hdr->type == HDR_CONTACT_T) { + if(hdr->parsed == 0) { if(parse_contact(hdr) < 0) { LM_ERR("failed to parse Contact body\n"); ret = -1; goto restore; } - if (dup==0) + if(dup == 0) dup = 1; - } + } } hdr = hdr->next; } /* we have the contact header and its body parsed -> sort the contacts * based on the q value */ - contacts = ((contact_body_t*)contact_hdr->parsed)->contacts; - if (contacts==0) { + contacts = ((contact_body_t *)contact_hdr->parsed)->contacts; + if(contacts == 0) { LM_DBG("contact hdr has no contacts\n"); goto restore; } n = sort_contacts(contact_hdr, scontacts, sqvalues); - if (n==0) { + if(n == 0) { LM_DBG("no contacts left after filtering\n"); goto restore; } - i=0; + i = 0; /* more branches than requested in the parameter * - add only the last ones from sorted array, * because the order is by increasing q */ - if (max!=-1 && n>max) + if(max != -1 && n > max) i = n - max; added = 0; /* add the sortet contacts as branches in dset and log this! */ - for ( ; i\n", scontacts[i]->uri.len, scontacts[i]->uri.s); - if(sruid_next(&_redirect_sruid)==0) { - if (flags_hdr_mode && scontacts[i]->flags && str2int(&(scontacts[i]->flags->body), &flags) == 0) { - if (flags_hdr_mode == 2) + if(sruid_next(&_redirect_sruid) == 0) { + if(flags_hdr_mode && scontacts[i]->flags + && str2int(&(scontacts[i]->flags->body), &flags) == 0) { + if(flags_hdr_mode == 2) flags |= bflags; } else { flags = bflags; } - if(append_branch( 0, &scontacts[i]->uri, 0, 0, sqvalues[i], - flags, 0, &_redirect_sruid.uid, 0, - &_redirect_sruid.uid, &_redirect_sruid.uid)<0) { + if(append_branch(0, &scontacts[i]->uri, 0, 0, sqvalues[i], flags, 0, + &_redirect_sruid.uid, 0, &_redirect_sruid.uid, + &_redirect_sruid.uid) + < 0) { LM_ERR("failed to add contact to dset\n"); } else { added++; - if (_uacred_accb.acc_request!=NULL && reason) { + if(_uacred_accb.acc_request != NULL && reason) { /* log the redirect */ - req->new_uri = scontacts[i]->uri; + req->new_uri = scontacts[i]->uri; //FIXME - if(uacred_acc_fct_s.len==11 - && strncmp(uacred_acc_fct_s.s, - "acc_request", 11)==0) { - _uacred_accb.acc_request(req, reason, &uacred_acc_db_table); - } else if(uacred_acc_fct_s.len==15 - && strncmp(uacred_acc_fct_s.s, - "acc_log_request", 15)==0) { + if(uacred_acc_fct_s.len == 11 + && strncmp(uacred_acc_fct_s.s, "acc_request", 11) + == 0) { + _uacred_accb.acc_request( + req, reason, &uacred_acc_db_table); + } else if(uacred_acc_fct_s.len == 15 + && strncmp(uacred_acc_fct_s.s, "acc_log_request", + 15) + == 0) { _uacred_accb.acc_log_request(req, reason); - } else if(uacred_acc_fct_s.len==14 - && strncmp(uacred_acc_fct_s.s, - "acc_db_request", 14)==0) { - _uacred_accb.acc_db_request(req, reason, &uacred_acc_db_table); + } else if(uacred_acc_fct_s.len == 14 + && strncmp(uacred_acc_fct_s.s, "acc_db_request", + 14) + == 0) { + _uacred_accb.acc_db_request( + req, reason, &uacred_acc_db_table); } } } @@ -323,21 +330,19 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl, } } - ret = (added==0)?-1:added; + ret = (added == 0) ? -1 : added; restore: - if (dup==1) { - free_contact( (contact_body_t**)(void*)(&contact_hdr->parsed) ); - } else if (dup==2) { + if(dup == 1) { + free_contact((contact_body_t **)(void *)(&contact_hdr->parsed)); + } else if(dup == 2) { /* are any new headers found? */ - if (dup_rpl.last_header!=sh_rpl->last_header) { + if(dup_rpl.last_header != sh_rpl->last_header) { /* identify in the new headere list (from dup_rpl) * the sh_rpl->last_header and start remove everything after */ hdr = sh_rpl->last_header; free_hdr_field_lst(hdr->next); - hdr->next=0; + hdr->next = 0; } } return ret; - } - diff --git a/src/modules/uac_redirect/rd_funcs.h b/src/modules/uac_redirect/rd_funcs.h index b80fe054201..3c22ae97b4a 100644 --- a/src/modules/uac_redirect/rd_funcs.h +++ b/src/modules/uac_redirect/rd_funcs.h @@ -29,7 +29,7 @@ #include "../../modules/tm/tm_load.h" #include "../acc/acc_logic.h" -typedef int (*tm_get_trans_f)( struct sip_msg*, struct cell**); +typedef int (*tm_get_trans_f)(struct sip_msg *, struct cell **); extern struct tm_binds rd_tmb; @@ -40,8 +40,7 @@ extern acc_api_t _uacred_accb; extern int flags_hdr_mode; -int get_redirect( struct sip_msg *msg , int maxt, int maxb, - str *reason, unsigned int bflags); +int get_redirect(struct sip_msg *msg, int maxt, int maxb, str *reason, + unsigned int bflags); #endif - diff --git a/src/modules/uac_redirect/uac_redirect.c b/src/modules/uac_redirect/uac_redirect.c index 9925621d0e0..141437a7e0e 100644 --- a/src/modules/uac_redirect/uac_redirect.c +++ b/src/modules/uac_redirect/uac_redirect.c @@ -37,11 +37,11 @@ MODULE_VERSION /* internal global variables */ -struct tm_binds rd_tmb; /*imported functions from tm */ +struct tm_binds rd_tmb; /*imported functions from tm */ /* global parameter variables */ str uacred_acc_db_table = str_init("acc"); -str uacred_acc_fct_s = str_init("acc_log_request"); +str uacred_acc_fct_s = str_init("acc_log_request"); /* private parameter variables */ char *deny_filter_s = 0; @@ -52,7 +52,7 @@ unsigned int bflags = 0; int flags_hdr_mode = 0; #define ACCEPT_RULE_STR "accept" -#define DENY_RULE_STR "deny" +#define DENY_RULE_STR "deny" #define DEFAULT_Q_VALUE 10 int _redirect_q_value = DEFAULT_Q_VALUE; @@ -65,112 +65,106 @@ acc_api_t _uacred_accb = {0}; static int redirect_init(void); static int child_init(int rank); -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_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 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); - - -static cmd_export_t cmds[] = { - {"set_deny_filter", (cmd_function)w_set_deny, 2, setf_fixup, 0, - FAILURE_ROUTE }, - {"set_accept_filter", (cmd_function)w_set_accept, 2, setf_fixup, 0, - FAILURE_ROUTE }, - {"get_redirects", (cmd_function)w_get_redirect2, 2, get_redirect_fixup, 0, - FAILURE_ROUTE }, - {"get_redirects", (cmd_function)w_get_redirect1, 1, get_redirect_fixup, 0, - FAILURE_ROUTE }, - {0, 0, 0, 0, 0, 0} -}; - -static param_export_t params[] = { - {"deny_filter", PARAM_STRING, &deny_filter_s }, - {"accept_filter", PARAM_STRING, &accept_filter_s }, - {"default_filter", PARAM_STRING, &def_filter_s }, - {"acc_function", PARAM_STR, &uacred_acc_fct_s }, - {"acc_db_table", PARAM_STR, &uacred_acc_db_table }, - {"bflags", INT_PARAM, &bflags }, - {"flags_hdr_mode", INT_PARAM, &flags_hdr_mode }, - {"q_value", INT_PARAM, &_redirect_q_value }, - {0, 0, 0} -}; +static int get_redirect_fixup(void **param, int param_no); +static int setf_fixup(void **param, int param_no); + + +static cmd_export_t cmds[] = {{"set_deny_filter", (cmd_function)w_set_deny, 2, + setf_fixup, 0, FAILURE_ROUTE}, + {"set_accept_filter", (cmd_function)w_set_accept, 2, setf_fixup, 0, + FAILURE_ROUTE}, + {"get_redirects", (cmd_function)w_get_redirect2, 2, get_redirect_fixup, + 0, FAILURE_ROUTE}, + {"get_redirects", (cmd_function)w_get_redirect1, 1, get_redirect_fixup, + 0, FAILURE_ROUTE}, + {0, 0, 0, 0, 0, 0}}; + +static param_export_t params[] = {{"deny_filter", PARAM_STRING, &deny_filter_s}, + {"accept_filter", PARAM_STRING, &accept_filter_s}, + {"default_filter", PARAM_STRING, &def_filter_s}, + {"acc_function", PARAM_STR, &uacred_acc_fct_s}, + {"acc_db_table", PARAM_STR, &uacred_acc_db_table}, + {"bflags", INT_PARAM, &bflags}, + {"flags_hdr_mode", INT_PARAM, &flags_hdr_mode}, + {"q_value", INT_PARAM, &_redirect_q_value}, {0, 0, 0}}; struct module_exports exports = { - "uac_redirect", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* exported functions */ - params, /* exported parameters */ - 0, /* exported RPC functions */ - 0, /* exported pseudo-variables */ - 0, /* response handling function */ - redirect_init, /* module initialization function */ - child_init, /* per-child init function */ - 0 /* module destroy function */ + "uac_redirect", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* exported functions */ + params, /* exported parameters */ + 0, /* exported RPC functions */ + 0, /* exported pseudo-variables */ + 0, /* response handling function */ + redirect_init, /* module initialization function */ + child_init, /* per-child init function */ + 0 /* module destroy function */ }; - int get_nr_max(char *s, unsigned char *max) { unsigned short nr; int err; - if ( s[0]=='*' && s[1]==0 ) { + if(s[0] == '*' && s[1] == 0) { /* is '*' -> infinit ;-) */ *max = 0; return 0; } else { /* must be a positive number less than 255 */ nr = str2s(s, strlen(s), &err); - if (err==0){ - if (nr>255){ - LM_ERR("number too big <%d> (max=255)\n",nr); + if(err == 0) { + if(nr > 255) { + LM_ERR("number too big <%d> (max=255)\n", nr); return -1; } *max = (unsigned char)nr; return 0; - }else{ - LM_ERR("bad number <%s>\n",s); + } else { + LM_ERR("bad number <%s>\n", s); return -1; } } } -static int get_redirect_fixup(void** param, int param_no) +static int get_redirect_fixup(void **param, int param_no) { - unsigned char maxb,maxt; + unsigned char maxb, maxt; char *p; char *s; - s = (char*)*param; - if (param_no==1) { - if ( (p=strchr(s,':'))!=0 ) { + s = (char *)*param; + if(param_no == 1) { + if((p = strchr(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, &maxt) != 0) return E_UNSPEC; pkg_free(*param); - *param=(void*)(long)( (((unsigned short)maxt)<<8) | maxb); - } else if (param_no==2) { + *param = (void *)(long)((((unsigned short)maxt) << 8) | maxb); + } else if(param_no == 2) { /* acc function loaded? */ - if (uacred_acc_fct_s.s==0 || uacred_acc_fct_s.s[0]=='\0') { + if(uacred_acc_fct_s.s == 0 || uacred_acc_fct_s.s[0] == '\0') { LM_ERR("acc support enabled, but no acc function defined\n"); return E_UNSPEC; } - if (_uacred_accb.acc_request==NULL) { + if(_uacred_accb.acc_request == NULL) { /* bind the ACC API */ if(acc_load_api(&_uacred_accb) < 0) { LM_ERR("cannot bind to ACC API\n"); @@ -184,54 +178,53 @@ static int get_redirect_fixup(void** param, int param_no) } -static int setf_fixup(void** param, int param_no) +static int setf_fixup(void **param, int param_no) { unsigned short nr; regex_t *filter; char *s; - s = (char*)*param; - if (param_no==1) { + s = (char *)*param; + if(param_no == 1) { /* compile the filter */ - if (regexp_compile( s, &filter)<0) { + if(regexp_compile(s, &filter) < 0) { LM_ERR("cannot init filter <%s>\n", s); return E_BAD_RE; } pkg_free(*param); - *param = (void*)filter; - } else if (param_no==2) { - if (s==0 || s[0]==0) { + *param = (void *)filter; + } else if(param_no == 2) { + if(s == 0 || s[0] == 0) { nr = 0; - } else if (strcasecmp(s,"reset_all")==0) { - nr = RESET_ADDED|RESET_DEFAULT; - } else if (strcasecmp(s,"reset_default")==0) { + } else if(strcasecmp(s, "reset_all") == 0) { + nr = RESET_ADDED | RESET_DEFAULT; + } else if(strcasecmp(s, "reset_default") == 0) { nr = RESET_DEFAULT; - } else if (strcasecmp(s,"reset_added")==0) { + } else if(strcasecmp(s, "reset_added") == 0) { nr = RESET_ADDED; } else { - LM_ERR("unknown reset type <%s>\n",s); + LM_ERR("unknown reset type <%s>\n", s); return E_UNSPEC; } pkg_free(*param); - *param = (void*)(long)nr; + *param = (void *)(long)nr; } return 0; } - static int regexp_compile(char *re_s, regex_t **re) { *re = 0; - if (re_s==0 || strlen(re_s)==0 ) { + if(re_s == 0 || strlen(re_s) == 0) { return 0; } else { - if ((*re=pkg_malloc(sizeof(regex_t)))==0) { + if((*re = pkg_malloc(sizeof(regex_t))) == 0) { PKG_MEM_ERROR; return E_OUT_OF_MEM; } - if (regcomp(*re, re_s, REG_EXTENDED|REG_ICASE|REG_NEWLINE) ){ + if(regcomp(*re, re_s, REG_EXTENDED | REG_ICASE | REG_NEWLINE)) { pkg_free(*re); *re = 0; LM_ERR("regexp_compile:bad regexp <%s>\n", re_s); @@ -242,13 +235,12 @@ static int regexp_compile(char *re_s, regex_t **re) } - static int redirect_init(void) { regex_t *filter; /* load the TM API */ - if (load_tm_api(&rd_tmb)!=0) { + if(load_tm_api(&rd_tmb) != 0) { LM_ERR("failed to load TM API\n"); goto error; } @@ -265,31 +257,31 @@ static int redirect_init(void) init_filters(); /* what's the default rule? */ - if (def_filter_s) { - if ( !strcasecmp(def_filter_s,ACCEPT_RULE_STR) ) { - set_default_rule( ACCEPT_RULE ); - } else if ( !strcasecmp(def_filter_s,DENY_RULE_STR) ) { - set_default_rule( DENY_RULE ); + if(def_filter_s) { + if(!strcasecmp(def_filter_s, ACCEPT_RULE_STR)) { + set_default_rule(ACCEPT_RULE); + } else if(!strcasecmp(def_filter_s, DENY_RULE_STR)) { + set_default_rule(DENY_RULE); } else { - LM_ERR("unknown default filter <%s>\n",def_filter_s); + LM_ERR("unknown default filter <%s>\n", def_filter_s); } } /* if accept filter specify, compile it */ - if (regexp_compile(accept_filter_s, &filter)<0) { + if(regexp_compile(accept_filter_s, &filter) < 0) { LM_ERR("failed to init accept filter\n"); goto error; } - add_default_filter( ACCEPT_FILTER, filter); + add_default_filter(ACCEPT_FILTER, filter); /* if deny filter specify, compile it */ - if (regexp_compile(deny_filter_s, &filter)<0) { + if(regexp_compile(deny_filter_s, &filter) < 0) { LM_ERR("failed to init deny filter\n"); goto error; } - add_default_filter( DENY_FILTER, filter); + add_default_filter(DENY_FILTER, filter); - if(sruid_init(&_redirect_sruid, '-', "rdir", SRUID_INC)<0) + if(sruid_init(&_redirect_sruid, '-', "rdir", SRUID_INC) < 0) return -1; return 0; @@ -299,21 +291,21 @@ static int redirect_init(void) static int child_init(int rank) { - if(sruid_init(&_redirect_sruid, '-', "rdir", SRUID_INC)<0) + if(sruid_init(&_redirect_sruid, '-', "rdir", SRUID_INC) < 0) return -1; return 0; } -static inline void msg_tracer(struct sip_msg* msg, int reset) +static inline void msg_tracer(struct sip_msg *msg, int reset) { - static unsigned int id = 0; + static unsigned int id = 0; static unsigned int set = 0; - if (reset) { + if(reset) { set = 0; } else { - if (set) { - if (id!=msg->id) { + if(set) { + if(id != msg->id) { LM_WARN("filters set but not used -> resetting to default\n"); reset_filters(); id = msg->id; @@ -326,59 +318,63 @@ static inline void msg_tracer(struct sip_msg* msg, int reset) } -static int w_set_deny(struct sip_msg* msg, char *re, char *flags) +static int w_set_deny(struct sip_msg *msg, char *re, char *flags) { - msg_tracer( msg, 0); - return (add_filter( DENY_FILTER, (regex_t*)re, (int)(long)flags)==0)?1:-1; + msg_tracer(msg, 0); + return (add_filter(DENY_FILTER, (regex_t *)re, (int)(long)flags) == 0) ? 1 + : -1; } -static int w_set_accept(struct sip_msg* msg, char *re, char *flags) +static int w_set_accept(struct sip_msg *msg, char *re, char *flags) { - msg_tracer( msg, 0); - return (add_filter( ACCEPT_FILTER, (regex_t*)re, (int)(long)flags)==0)?1:-1; + msg_tracer(msg, 0); + return (add_filter(ACCEPT_FILTER, (regex_t *)re, (int)(long)flags) == 0) + ? 1 + : -1; } -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, char *reason) { int n; unsigned short max; str sreason = {0}; - if(reason!=NULL) { - if(fixup_get_svalue(msg, (gparam_t*)reason, &sreason)<0) { + if(reason != NULL) { + if(fixup_get_svalue(msg, (gparam_t *)reason, &sreason) < 0) { LM_ERR("failed to get reason parameter\n"); return -1; } } - msg_tracer( msg, 0); + msg_tracer(msg, 0); /* get the contacts */ max = (unsigned short)(long)max_c; - n = get_redirect(msg , (max>>8)&0xff, max&0xff, (reason)?&sreason:NULL, bflags); + n = get_redirect(msg, (max >> 8) & 0xff, max & 0xff, + (reason) ? &sreason : NULL, bflags); reset_filters(); /* reset the tracer */ - msg_tracer( msg, 1); + msg_tracer(msg, 1); return n; } -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, char *foo) { return w_get_redirect2(msg, max_c, 0); } -static int ki_get_redirects_acc(sip_msg_t* msg, int max_c, int max_b, - str *reason) +static int ki_get_redirects_acc( + sip_msg_t *msg, int max_c, int max_b, str *reason) { int n; msg_tracer(msg, 0); /* get the contacts */ - n = get_redirect(msg, max_c, max_b, (reason && reason->len>0)?reason:NULL, - bflags); + n = get_redirect(msg, max_c, max_b, + (reason && reason->len > 0) ? reason : NULL, bflags); reset_filters(); /* reset the tracer */ msg_tracer(msg, 1); @@ -386,7 +382,7 @@ static int ki_get_redirects_acc(sip_msg_t* msg, int max_c, int max_b, return n; } -static int ki_get_redirects(sip_msg_t* msg, int max_c, int max_b) +static int ki_get_redirects(sip_msg_t *msg, int max_c, int max_b) { int n; @@ -400,7 +396,7 @@ static int ki_get_redirects(sip_msg_t* msg, int max_c, int max_b) return n; } -static int ki_get_redirects_all(sip_msg_t* msg) +static int ki_get_redirects_all(sip_msg_t *msg) { int n;