From e569931dcd96087729eec1772a318e78ed505d14 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 17 May 2023 16:37:13 +0200 Subject: [PATCH] siputils: clang-format for coherent indentation and coding style --- src/modules/siputils/chargingvector.c | 356 +++++++++++------------- src/modules/siputils/checks.c | 381 +++++++++++++------------- src/modules/siputils/checks.h | 51 ++-- src/modules/siputils/config.c | 21 +- src/modules/siputils/config.h | 13 +- src/modules/siputils/contact_ops.c | 190 +++++++------ src/modules/siputils/options.c | 45 ++- src/modules/siputils/options.h | 4 +- src/modules/siputils/rpid.c | 78 +++--- src/modules/siputils/rpid.h | 8 +- src/modules/siputils/sipops.c | 101 ++++--- src/modules/siputils/siputils.c | 365 ++++++++++++------------ src/modules/siputils/siputils.h | 19 +- src/modules/siputils/utils.c | 47 ++-- src/modules/siputils/utils.h | 8 +- 15 files changed, 817 insertions(+), 870 deletions(-) diff --git a/src/modules/siputils/chargingvector.c b/src/modules/siputils/chargingvector.c index e99a5fa751e..bc6adc364d2 100644 --- a/src/modules/siputils/chargingvector.c +++ b/src/modules/siputils/chargingvector.c @@ -35,15 +35,16 @@ #define PCV_BUF_SIZE 256 static char pcv_buf[PCV_BUF_SIZE]; -static str pcv = { pcv_buf, 0 }; -static str pcv_id = { NULL, 0 }; -static str pcv_host = { NULL, 0 }; -static str pcv_orig = { NULL, 0 }; -static str pcv_term = { NULL, 0 }; +static str pcv = {pcv_buf, 0}; +static str pcv_id = {NULL, 0}; +static str pcv_host = {NULL, 0}; +static str pcv_orig = {NULL, 0}; +static str pcv_term = {NULL, 0}; static uint64_t counter = 0; -enum PCV_Status { +enum PCV_Status +{ PCV_NONE = 0, PCV_PARSED = 1, PCV_GENERATED = 2 @@ -52,80 +53,65 @@ enum PCV_Status { static enum PCV_Status pcv_status = PCV_NONE; static unsigned int current_msg_id = (unsigned int)-1; -static void sip_generate_charging_vector(char * pcv) +static void sip_generate_charging_vector(char *pcv) { - char s[PATH_MAX] = {0}; - struct hostent* host = NULL; - int cdx = 0; - int tdx = 0; - int idx = 0; - int ipx = 0; + char s[PATH_MAX] = {0}; + struct hostent *host = NULL; + int cdx = 0; + int tdx = 0; + int idx = 0; + int ipx = 0; int pid; - uint64_t ct = 0; - struct in_addr* in = NULL; - static struct in_addr ip = {0}; - unsigned char newConferenceIdentifier[SIZE_CONF_ID]={0}; + uint64_t ct = 0; + struct in_addr *in = NULL; + static struct in_addr ip = {0}; + unsigned char newConferenceIdentifier[SIZE_CONF_ID] = {0}; - memset(pcv,0,SIZE_CONF_ID); + memset(pcv, 0, SIZE_CONF_ID); pid = getpid(); - if ( ip.s_addr == 0 ) - { - if (!gethostname(s, PATH_MAX)) - { - if ((host = gethostbyname(s)) != NULL) - { - int idx = 0 ; - for (idx = 0 ; host->h_addr_list[idx]!=NULL ; idx++) - { - in = (struct in_addr*)host->h_addr_list[idx]; - if (in->s_addr == LOOPBACK_IP ) - { - if ( ip.s_addr == 0 ) - { - ip=*in; + if(ip.s_addr == 0) { + if(!gethostname(s, PATH_MAX)) { + if((host = gethostbyname(s)) != NULL) { + int idx = 0; + for(idx = 0; host->h_addr_list[idx] != NULL; idx++) { + in = (struct in_addr *)host->h_addr_list[idx]; + if(in->s_addr == LOOPBACK_IP) { + if(ip.s_addr == 0) { + ip = *in; } - } - else - { - ip=*in; + } else { + ip = *in; } } } } } - ct=counter++; - if ( counter > 0xFFFFFFFF ) counter=0; - - memset(newConferenceIdentifier,0,SIZE_CONF_ID); - newConferenceIdentifier[0]='I'; - newConferenceIdentifier[1]='V'; - newConferenceIdentifier[2]='S'; - idx=3; - while ( idx < SIZE_CONF_ID ) - { - if ( idx < 7 ) - { + ct = counter++; + if(counter > 0xFFFFFFFF) + counter = 0; + + memset(newConferenceIdentifier, 0, SIZE_CONF_ID); + newConferenceIdentifier[0] = 'I'; + newConferenceIdentifier[1] = 'V'; + newConferenceIdentifier[2] = 'S'; + idx = 3; + while(idx < SIZE_CONF_ID) { + if(idx < 7) { // 3-6 =IP - newConferenceIdentifier[idx]=((ip.s_addr>>(ipx*8))&0xff); + newConferenceIdentifier[idx] = ((ip.s_addr >> (ipx * 8)) & 0xff); ipx++; - } - else if (idx < 11 ) - { + } else if(idx < 11) { // 7-11 = PID - newConferenceIdentifier[idx]=((pid>>(cdx*8))&0xff); + newConferenceIdentifier[idx] = ((pid >> (cdx * 8)) & 0xff); cdx++; - } - else if (idx == 11 ) - { + } else if(idx == 11) { time_t ts = time(NULL); - newConferenceIdentifier[idx]=(ts&0xff); - } - else - { + newConferenceIdentifier[idx] = (ts & 0xff); + } else { // 12-16 = COUNTER - newConferenceIdentifier[idx]=((ct>>(tdx*8))&0xff); + newConferenceIdentifier[idx] = ((ct >> (tdx * 8)) & 0xff); tdx++; } idx++; @@ -133,31 +119,28 @@ static void sip_generate_charging_vector(char * pcv) LM_DBG("PCV generate\n"); int i = 0; pcv[0] = '\0'; - for ( i = 0 ; i < SIZE_CONF_ID ; i ++ ) - { + for(i = 0; i < SIZE_CONF_ID; i++) { char hex[4] = {0}; - snprintf(hex,4,"%02X",newConferenceIdentifier[i]); - strcat(pcv,hex); + snprintf(hex, 4, "%02X", newConferenceIdentifier[i]); + strcat(pcv, hex); } } -static unsigned int sip_param_end(const char * s, unsigned int len) +static unsigned int sip_param_end(const char *s, unsigned int len) { unsigned int i; - for (i=0; i 0) - { + if(pcv_host.s == NULL && pcv_id.s != NULL && len > 0) { LM_WARN("icid-generated-at is missing %.*s\n", len, pcv_value); } return (pcv_id.s != NULL); } -static int sip_get_charging_vector(struct sip_msg *msg, struct hdr_field ** hf_pcv ) +static int sip_get_charging_vector( + struct sip_msg *msg, struct hdr_field **hf_pcv) { struct hdr_field *hf; - char * hdrname_cstr = P_CHARGING_VECTOR; - str hdrname = { hdrname_cstr , strlen( hdrname_cstr) }; + char *hdrname_cstr = P_CHARGING_VECTOR; + str hdrname = {hdrname_cstr, strlen(hdrname_cstr)}; /* we need to be sure we have parsed all headers */ - if (parse_headers(msg, HDR_EOH_F, 0)<0) - { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("error parsing headers\n"); return -1; } - for (hf=msg->headers; hf; hf=hf->next) - { - if ( hf->name.s[0] != 'P' ) - { + for(hf = msg->headers; hf; hf = hf->next) { + if(hf->name.s[0] != 'P') { continue; } - if ( cmp_hdrname_str(&hf->name, &hdrname) == 0) - { + if(cmp_hdrname_str(&hf->name, &hdrname) == 0) { /* * append p charging vector values after the header name "P-Charging-Vector" and * the ": " (+2) */ - char * pcv_body = pcv_buf + strlen(P_CHARGING_VECTOR) + 2; + char *pcv_body = pcv_buf + strlen(P_CHARGING_VECTOR) + 2; - if (hf->body.len > 0) - { - memcpy( pcv_body, hf->body.s, hf->body.len ); + if(hf->body.len > 0) { + memcpy(pcv_body, hf->body.s, hf->body.len); pcv.len = hf->body.len + strlen(P_CHARGING_VECTOR) + 2; - pcv_body[hf->body.len]= '\0'; - if ( sip_parse_charging_vector( pcv_body, hf->body.len ) == 0) - { - LM_ERR("P-Charging-Vector header found but failed to parse value [%s].\n", pcv_body); + pcv_body[hf->body.len] = '\0'; + if(sip_parse_charging_vector(pcv_body, hf->body.len) == 0) { + LM_ERR("P-Charging-Vector header found but failed to parse " + "value [%s].\n", + pcv_body); pcv_status = PCV_NONE; pcv.s = NULL; pcv.len = 0; - } - else - { + } else { pcv_status = PCV_PARSED; pcv.s = hf->body.s; pcv.len = hf->body.len; } return 2; - } - else - { + } else { pcv_id.s = 0; pcv_id.len = 0; pcv_host.s = 0; @@ -295,47 +258,41 @@ static int sip_get_charging_vector(struct sip_msg *msg, struct hdr_field ** hf_p } // Remove PCV if it is in the inbound request (if it was found by sip_get_charging_vector) -static int sip_remove_charging_vector(struct sip_msg *msg, struct hdr_field *hf) +static int sip_remove_charging_vector(struct sip_msg *msg, struct hdr_field *hf) { - struct lump* l; + struct lump *l; - if ( hf != NULL ) - { - l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0); - if (l==0) - { + if(hf != NULL) { + l = del_lump(msg, hf->name.s - msg->buf, hf->len, 0); + if(l == 0) { LM_ERR("no memory\n"); return -1; } return 2; - } - else - { + } else { return 1; } } static int sip_add_charging_vector(struct sip_msg *msg) { - struct lump* anchor; - char * s; + struct lump *anchor; + char *s; anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0); - if(anchor == 0) - { + if(anchor == 0) { LM_ERR("can't get anchor\n"); return -1; } - s = (char*)pkg_malloc(pcv.len); - if (!s) { + s = (char *)pkg_malloc(pcv.len); + if(!s) { PKG_MEM_ERROR; return -1; } - memcpy(s, pcv.s, pcv.len ); + memcpy(s, pcv.s, pcv.len); - if (insert_new_lump_before(anchor, s, pcv.len, 0) == 0) - { + if(insert_new_lump_before(anchor, s, pcv.len, 0) == 0) { LM_ERR("can't insert lump\n"); pkg_free(s); return -1; @@ -350,21 +307,19 @@ int sip_handle_pcv(struct sip_msg *msg, char *flags, char *str2) int replace_pcv = 0; int i; str flag_str; - struct hdr_field * hf_pcv = NULL; + struct hdr_field *hf_pcv = NULL; pcv.len = 0; pcv_status = PCV_NONE; - if(fixup_get_svalue(msg, (gparam_p)flags, &flag_str)<0) { + if(fixup_get_svalue(msg, (gparam_p)flags, &flag_str) < 0) { LM_ERR("failed to retrieve parameter value\n"); return -1; } // Process command flags - for (i = 0; i < flag_str.len; i++) - { - switch (flag_str.s[i]) - { + for(i = 0; i < flag_str.len; i++) { + switch(flag_str.s[i]) { case 'r': case 'R': remove_pcv = 1; @@ -392,49 +347,51 @@ int sip_handle_pcv(struct sip_msg *msg, char *flags, char *str2) * We need to remove the original PCV if it was present and either * we were asked to remove it or we were asked to replace it */ - if ( pcv_status == PCV_PARSED && (replace_pcv || remove_pcv) ) - { + if(pcv_status == PCV_PARSED && (replace_pcv || remove_pcv)) { i = sip_remove_charging_vector(msg, hf_pcv); - if (i <= 0) return (i==0)?-1:i; + if(i <= 0) + return (i == 0) ? -1 : i; } /* Generate PCV if * - we were asked to generate it and it could not be obtained from the inbound packet * - or if we were asked to replace it alltogether regardless its former value */ - if ( replace_pcv || (generate_pcv && pcv_status != PCV_GENERATED && pcv_status != PCV_PARSED ) ) - { + if(replace_pcv + || (generate_pcv && pcv_status != PCV_GENERATED + && pcv_status != PCV_PARSED)) { strcpy(pcv_buf, P_CHARGING_VECTOR); strcat(pcv_buf, ": "); - char * pcv_body = pcv_buf + 19; + char *pcv_body = pcv_buf + 19; char pcv_value[40]; /* We use the IP address of the interface that received the message as generated-at */ - if(msg->rcv.bind_address==NULL || msg->rcv.bind_address->address_str.s==NULL) - { - LM_ERR("No IP address for message. Failed to generate charging vector.\n"); + if(msg->rcv.bind_address == NULL + || msg->rcv.bind_address->address_str.s == NULL) { + LM_ERR("No IP address for message. Failed to generate charging " + "vector.\n"); return -2; } sip_generate_charging_vector(pcv_value); - pcv.len = snprintf( pcv_body, PCV_BUF_SIZE - 19, "icid-value=%.*s; icid-generated-at=%.*s\r\n", 32, pcv_value, + pcv.len = snprintf(pcv_body, PCV_BUF_SIZE - 19, + "icid-value=%.*s; icid-generated-at=%.*s\r\n", 32, pcv_value, msg->rcv.bind_address->address_str.len, - msg->rcv.bind_address->address_str.s ); + msg->rcv.bind_address->address_str.s); pcv.len += 19; pcv_status = PCV_GENERATED; /* if generated, reparse it */ - sip_parse_charging_vector( pcv_body, pcv.len-19 ); + sip_parse_charging_vector(pcv_body, pcv.len - 19); /* if it was generated, we need to send it out as a header */ - LM_INFO("Generated PCV header %.*s\n", pcv.len-2, pcv_buf ); + LM_INFO("Generated PCV header %.*s\n", pcv.len - 2, pcv_buf); i = sip_add_charging_vector(msg); - if (i <= 0) - { + if(i <= 0) { LM_ERR("Failed to add P-Charging-Vector header\n"); - return (i==0)?-1:i; + return (i == 0) ? -1 : i; } } @@ -443,32 +400,27 @@ int sip_handle_pcv(struct sip_msg *msg, char *flags, char *str2) } -int pv_get_charging_vector(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) +int pv_get_charging_vector( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str pcv_pv; - if ( current_msg_id != msg->id || pcv_status == PCV_NONE ) - { - struct hdr_field * hf_pcv = NULL; - if ( sip_get_charging_vector(msg, &hf_pcv) > 0 ) - { + if(current_msg_id != msg->id || pcv_status == PCV_NONE) { + struct hdr_field *hf_pcv = NULL; + if(sip_get_charging_vector(msg, &hf_pcv) > 0) { current_msg_id = msg->id; } LM_DBG("Parsed charging vector for pseudo-var\n"); - } - else - { + } else { LM_DBG("Charging vector is in state %d for pseudo-var\n", pcv_status); } - switch(pcv_status) - { + switch(pcv_status) { case PCV_GENERATED: LM_DBG("pcv_status==PCV_GENERATED\n"); case PCV_PARSED: LM_DBG("pcv_status==PCV_PARSED\n"); - switch( param->pvn.u.isname.name.n ) - { + switch(param->pvn.u.isname.name.n) { case 5: pcv_pv = pcv_term; break; @@ -489,10 +441,11 @@ int pv_get_charging_vector(struct sip_msg *msg, pv_param_t *param, pv_value_t *r break; } - if ( pcv_pv.len > 0 ) - return pv_get_strval(msg, param, res, &pcv_pv ); + if(pcv_pv.len > 0) + return pv_get_strval(msg, param, res, &pcv_pv); else - LM_WARN("No value for pseudo-var $pcv but status was %d.\n", pcv_status); + LM_WARN("No value for pseudo-var $pcv but status was %d.\n", + pcv_status); break; @@ -506,33 +459,36 @@ int pv_get_charging_vector(struct sip_msg *msg, pv_param_t *param, pv_value_t *r int pv_parse_charging_vector_name(pv_spec_p sp, str *in) { - if(sp==NULL || in==NULL || in->len<=0) + if(sp == NULL || in == NULL || in->len <= 0) return -1; - switch(in->len) - { + switch(in->len) { case 3: - if(strncmp(in->s, "all", 3)==0) + if(strncmp(in->s, "all", 3) == 0) sp->pvp.pvn.u.isname.name.n = 1; - else goto error; - break; + else + goto error; + break; case 4: - if(strncmp(in->s, "orig", 4)==0) + if(strncmp(in->s, "orig", 4) == 0) sp->pvp.pvn.u.isname.name.n = 4; - else if(strncmp(in->s, "term", 4)==0) + else if(strncmp(in->s, "term", 4) == 0) sp->pvp.pvn.u.isname.name.n = 5; - else goto error; - break; + else + goto error; + break; case 5: - if(strncmp(in->s, "value", 5)==0) + if(strncmp(in->s, "value", 5) == 0) sp->pvp.pvn.u.isname.name.n = 3; - else goto error; - break; + else + goto error; + break; case 7: - if(strncmp(in->s, "genaddr", 7)==0) + if(strncmp(in->s, "genaddr", 7) == 0) sp->pvp.pvn.u.isname.name.n = 2; - else goto error; - break; + else + goto error; + break; default: goto error; } diff --git a/src/modules/siputils/checks.c b/src/modules/siputils/checks.c index 758bdacc44a..e3b4c97ff9d 100644 --- a/src/modules/siputils/checks.c +++ b/src/modules/siputils/checks.c @@ -33,14 +33,14 @@ #include #include "../../core/str.h" -#include "../../core/dprint.h" /* Debugging */ +#include "../../core/dprint.h" /* Debugging */ #include "../../core/mem/mem.h" #include "../../core/parser/digest/digest.h" /* get_authorized_cred */ #include "../../core/parser/parse_from.h" #include "../../core/parser/parse_uri.h" #include "../../core/parser/parse_param.h" -#include "../../core/ut.h" /* Handy utilities */ -#include "../../lib/srdb1/db.h" /* Database API */ +#include "../../core/ut.h" /* Handy utilities */ +#include "../../lib/srdb1/db.h" /* Database API */ #include "../../core/dset.h" #include "../../core/pvar.h" #include "../../core/lvalue.h" @@ -53,9 +53,9 @@ extern int e164_max_len; /** * return 1 (true) if the SIP message type is request */ -int w_is_request(struct sip_msg* msg, char *foo, char *bar) +int w_is_request(struct sip_msg *msg, char *foo, char *bar) { - if(msg==NULL) + if(msg == NULL) return -1; if(msg->first_line.type == SIP_REQUEST) @@ -64,9 +64,9 @@ int w_is_request(struct sip_msg* msg, char *foo, char *bar) return -1; } -int is_request(struct sip_msg* msg) +int is_request(struct sip_msg *msg) { - if(msg==NULL) + if(msg == NULL) return -1; if(msg->first_line.type == SIP_REQUEST) @@ -78,9 +78,9 @@ int is_request(struct sip_msg* msg) /** * return 1 (true) if the SIP message type is reply */ -int w_is_reply(struct sip_msg* msg, char *foo, char *bar) +int w_is_reply(struct sip_msg *msg, char *foo, char *bar) { - if(msg==NULL) + if(msg == NULL) return -1; if(msg->first_line.type == SIP_REPLY) @@ -89,9 +89,9 @@ int w_is_reply(struct sip_msg* msg, char *foo, char *bar) return -1; } -int is_reply(struct sip_msg* msg) +int is_reply(struct sip_msg *msg) { - if(msg==NULL) + if(msg == NULL) return -1; if(msg->first_line.type == SIP_REPLY) @@ -105,20 +105,20 @@ int is_reply(struct sip_msg* msg) * Checks if From includes a To-tag -- good to identify * if a request creates a new dialog */ -int has_totag(struct sip_msg* _m) +int has_totag(struct sip_msg *_m) { str tag; - if (!_m->to && parse_headers(_m, HDR_TO_F,0)==-1) { + if(!_m->to && parse_headers(_m, HDR_TO_F, 0) == -1) { LM_ERR("To parsing failed\n"); return -1; } - if (!_m->to) { + if(!_m->to) { LM_ERR("no To\n"); return -1; } - tag=get_to(_m)->tag_value; - if (tag.s==0 || tag.len==0) { + tag = get_to(_m)->tag_value; + if(tag.s == 0 || tag.len == 0) { LM_DBG("no totag\n"); return -1; } @@ -126,7 +126,7 @@ int has_totag(struct sip_msg* _m) return 1; } -int w_has_totag(struct sip_msg* _m, char* _foo, char* _bar) +int w_has_totag(struct sip_msg *_m, char *_foo, char *_bar) { return has_totag(_m); } @@ -134,16 +134,16 @@ int w_has_totag(struct sip_msg* _m, char* _foo, char* _bar) /* * Check if pseudo variable contains a valid uri */ -int is_uri(struct sip_msg* _m, char* _sp, char* _s2) +int is_uri(struct sip_msg *_m, char *_sp, char *_s2) { sip_uri_t turi; str uval; - if(fixup_get_svalue(_m, (gparam_t*)_sp, &uval)!=0) { + if(fixup_get_svalue(_m, (gparam_t *)_sp, &uval) != 0) { LM_ERR("cannot get parameter value\n"); return -1; } - if(parse_uri(uval.s, uval.len, &turi)!=0) { + if(parse_uri(uval.s, uval.len, &turi) != 0) { return -1; } return 1; @@ -154,32 +154,33 @@ int is_uri(struct sip_msg* _m, char* _sp, char* _s2) */ int ki_is_user(sip_msg_t *_m, str *suser) { - struct hdr_field* h; - auth_body_t* c; + struct hdr_field *h; + auth_body_t *c; get_authorized_cred(_m->authorization, &h); - if (!h) { + if(!h) { get_authorized_cred(_m->proxy_auth, &h); - if (!h) { + if(!h) { LM_ERR("no authorized credentials found (error in scripts)\n"); - LM_ERR("Call {www,proxy}_authorize before calling is_user function !\n"); + LM_ERR("Call {www,proxy}_authorize before calling is_user function " + "!\n"); return -1; } } - c = (auth_body_t*)(h->parsed); + c = (auth_body_t *)(h->parsed); - if (!c->digest.username.user.len) { + if(!c->digest.username.user.len) { LM_DBG("username not found in credentials\n"); return -1; } - if (suser->len != c->digest.username.user.len) { + if(suser->len != c->digest.username.user.len) { LM_DBG("username length does not match\n"); return -1; } - if (!memcmp(suser->s, c->digest.username.user.s, suser->len)) { + if(!memcmp(suser->s, c->digest.username.user.s, suser->len)) { LM_DBG("username matches\n"); return 1; } else { @@ -188,11 +189,11 @@ int ki_is_user(sip_msg_t *_m, str *suser) } } -int is_user(struct sip_msg* _m, char* _user, char* _str2) +int is_user(struct sip_msg *_m, char *_user, char *_str2) { str suser; - if(fixup_get_svalue(_m, (gparam_t*)_user, &suser)<0) { + if(fixup_get_svalue(_m, (gparam_t *)_user, &suser) < 0) { LM_ERR("failed to get user param\n"); return -1; } @@ -203,10 +204,10 @@ int is_user(struct sip_msg* _m, char* _user, char* _str2) /* * Find if Request URI has a given parameter with no value */ -int uri_param_1(struct sip_msg* _msg, char* _param, char* _str2) +int uri_param_1(struct sip_msg *_msg, char *_param, char *_str2) { str sparam; - if(fixup_get_svalue(_msg, (gparam_t*)_param, &sparam)<0) { + if(fixup_get_svalue(_msg, (gparam_t *)_param, &sparam) < 0) { LM_ERR("failed to get parameter\n"); return -1; } @@ -216,15 +217,15 @@ int uri_param_1(struct sip_msg* _msg, char* _param, char* _str2) /* * Find if Request URI has a given parameter with matching value */ -int uri_param_2(struct sip_msg* _msg, char* _param, char* _value) +int uri_param_2(struct sip_msg *_msg, char *_param, char *_value) { str sparam; str svalue; - if(fixup_get_svalue(_msg, (gparam_t*)_param, &sparam)<0) { + if(fixup_get_svalue(_msg, (gparam_t *)_param, &sparam) < 0) { LM_ERR("failed to get parameter\n"); return -1; } - if(fixup_get_svalue(_msg, (gparam_t*)_value, &svalue)<0) { + if(fixup_get_svalue(_msg, (gparam_t *)_value, &svalue) < 0) { LM_ERR("failed to get value\n"); return -1; } @@ -239,32 +240,32 @@ int ki_uri_param_value(sip_msg_t *_msg, str *sparam, str *svalue) str t; param_hooks_t hooks; - param_t* params, *pit; + param_t *params, *pit; - if (parse_sip_msg_uri(_msg) < 0) { + if(parse_sip_msg_uri(_msg) < 0) { LM_ERR("ruri parsing failed\n"); return -1; } t = _msg->parsed_uri.params; - if (parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { + if(parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { LM_ERR("ruri parameter parsing failed\n"); return -1; } - for (pit = params; pit; pit = pit->next) { - if ((pit->name.len == sparam->len) && - (strncmp(pit->name.s, sparam->s, sparam->len) == 0)) { - if (svalue) { - if ((svalue->len == pit->body.len) && - strncmp(svalue->s, pit->body.s, svalue->len) == 0) { + for(pit = params; pit; pit = pit->next) { + if((pit->name.len == sparam->len) + && (strncmp(pit->name.s, sparam->s, sparam->len) == 0)) { + if(svalue) { + if((svalue->len == pit->body.len) + && strncmp(svalue->s, pit->body.s, svalue->len) == 0) { goto ok; } else { goto nok; } } else { - if (pit->body.len > 0) { + if(pit->body.len > 0) { goto nok; } else { goto ok; @@ -300,7 +301,7 @@ int ki_uri_param_any(sip_msg_t *msg, str *sparam) str ouri; sip_uri_t puri; param_hooks_t hooks; - param_t* params, *pit; + param_t *params, *pit; if((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) { ouri = msg->first_line.u.request.uri; @@ -312,31 +313,31 @@ int ki_uri_param_any(sip_msg_t *msg, str *sparam) ouri = msg->new_uri; } - if (parse_uri(ouri.s, ouri.len, &puri) < 0) { + if(parse_uri(ouri.s, ouri.len, &puri) < 0) { LM_ERR("failed to parse r-uri [%.*s]\n", ouri.len, ouri.s); return -1; } - if(puri.sip_params.len>0) { + if(puri.sip_params.len > 0) { t = puri.sip_params; - } else if(puri.params.len>0) { + } else if(puri.params.len > 0) { t = puri.params; } else { LM_DBG("no uri params [%.*s]\n", ouri.len, ouri.s); return -1; } - if (parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { + if(parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { LM_ERR("ruri parameter parsing failed\n"); return -1; } - for (pit = params; pit; pit = pit->next) { - if ((pit->name.len == sparam->len) + for(pit = params; pit; pit = pit->next) { + if((pit->name.len == sparam->len) && (strncasecmp(pit->name.s, sparam->s, sparam->len) == 0)) { break; } } - if(pit==NULL) { + if(pit == NULL) { free_params(params); return -1; } @@ -348,10 +349,10 @@ int ki_uri_param_any(sip_msg_t *msg, str *sparam) /* * Find if Request URI has a given parameter with or without value */ -int w_uri_param_any(struct sip_msg* _msg, char* _param, char* _str2) +int w_uri_param_any(struct sip_msg *_msg, char *_param, char *_str2) { str sparam; - if(fixup_get_svalue(_msg, (gparam_t*)_param, &sparam)<0) { + if(fixup_get_svalue(_msg, (gparam_t *)_param, &sparam) < 0) { LM_ERR("failed to get parameter\n"); return -1; } @@ -361,17 +362,17 @@ int w_uri_param_any(struct sip_msg* _msg, char* _param, char* _str2) /* * Adds a new parameter to Request URI - kemi export */ -int ki_add_uri_param(struct sip_msg* _msg, str* param) +int ki_add_uri_param(struct sip_msg *_msg, str *param) { str *cur_uri, new_uri; struct sip_uri *parsed_uri; char *at; - if (param==NULL || param->len == 0) { + if(param == NULL || param->len == 0) { return 1; } - if (parse_sip_msg_uri(_msg) < 0) { + if(parse_sip_msg_uri(_msg) < 0) { LM_ERR("ruri parsing failed\n"); return -1; } @@ -379,22 +380,22 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param) parsed_uri = &(_msg->parsed_uri); /* if current ruri has no headers, pad param at the end */ - if (parsed_uri->headers.len == 0) { - cur_uri = GET_RURI(_msg); + if(parsed_uri->headers.len == 0) { + cur_uri = GET_RURI(_msg); new_uri.len = cur_uri->len + param->len + 1; - if (new_uri.len > MAX_URI_SIZE) { + if(new_uri.len > MAX_URI_SIZE) { LM_ERR("new ruri too long\n"); return -1; } new_uri.s = pkg_malloc(new_uri.len); - if (new_uri.s == 0) { + if(new_uri.s == 0) { PKG_MEM_ERROR; return -1; } memcpy(new_uri.s, cur_uri->s, cur_uri->len); *(new_uri.s + cur_uri->len) = ';'; memcpy(new_uri.s + cur_uri->len + 1, param->s, param->len); - if (rewrite_uri(_msg, &new_uri ) == 1) { + if(rewrite_uri(_msg, &new_uri) == 1) { goto ok; } else { goto nok; @@ -402,20 +403,19 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param) } /* otherwise take the long path */ - new_uri.len = 4 + - (parsed_uri->user.len ? parsed_uri->user.len + 1 : 0) + - (parsed_uri->passwd.len ? parsed_uri->passwd.len + 1 : 0) + - parsed_uri->host.len + - (parsed_uri->port.len ? parsed_uri->port.len + 1 : 0) + - parsed_uri->params.len + param->len + 1 + - parsed_uri->headers.len + 1; - if (new_uri.len > MAX_URI_SIZE) { + new_uri.len = 4 + (parsed_uri->user.len ? parsed_uri->user.len + 1 : 0) + + (parsed_uri->passwd.len ? parsed_uri->passwd.len + 1 : 0) + + parsed_uri->host.len + + (parsed_uri->port.len ? parsed_uri->port.len + 1 : 0) + + parsed_uri->params.len + param->len + 1 + + parsed_uri->headers.len + 1; + if(new_uri.len > MAX_URI_SIZE) { LM_ERR("new ruri too long\n"); return -1; } new_uri.s = pkg_malloc(new_uri.len); - if (new_uri.s == 0) { + if(new_uri.s == 0) { PKG_MEM_ERROR; return -1; } @@ -423,9 +423,9 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param) at = new_uri.s; memcpy(at, "sip:", 4); at = at + 4; - if (parsed_uri->user.len) { + if(parsed_uri->user.len) { memcpy(at, parsed_uri->user.s, parsed_uri->user.len); - if (parsed_uri->passwd.len) { + if(parsed_uri->passwd.len) { *at = ':'; at = at + 1; memcpy(at, parsed_uri->passwd.s, parsed_uri->passwd.len); @@ -436,7 +436,7 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param) } memcpy(at, parsed_uri->host.s, parsed_uri->host.len); at = at + parsed_uri->host.len; - if (parsed_uri->port.len) { + if(parsed_uri->port.len) { *at = ':'; at = at + 1; memcpy(at, parsed_uri->port.s, parsed_uri->port.len); @@ -452,7 +452,7 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param) at = at + 1; memcpy(at, parsed_uri->headers.s, parsed_uri->headers.len); - if (rewrite_uri(_msg, &new_uri) == 1) { + if(rewrite_uri(_msg, &new_uri) == 1) { goto ok; } @@ -468,9 +468,9 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param) /* * Adds a new parameter to Request URI - cfg export */ -int add_uri_param(struct sip_msg* _msg, char* _param, char* _s2) +int add_uri_param(struct sip_msg *_msg, char *_param, char *_s2) { - return ki_add_uri_param(_msg, (str*)_param); + return ki_add_uri_param(_msg, (str *)_param); } /* @@ -484,7 +484,7 @@ int ki_uri_param_rm(sip_msg_t *msg, str *sparam) str nuri; sip_uri_t puri; param_hooks_t hooks; - param_t* params, *pit; + param_t *params, *pit; if((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) { ouri = msg->first_line.u.request.uri; @@ -495,36 +495,36 @@ int ki_uri_param_rm(sip_msg_t *msg, str *sparam) } else { ouri = msg->new_uri; } - if(ouri.len>=MAX_URI_SIZE) { + if(ouri.len >= MAX_URI_SIZE) { LM_ERR("r-uri is too long (%d)\n", ouri.len); return -1; } - if (parse_uri(ouri.s, ouri.len, &puri) < 0) { + if(parse_uri(ouri.s, ouri.len, &puri) < 0) { LM_ERR("failed to parse r-uri [%.*s]\n", ouri.len, ouri.s); return -1; } - if(puri.sip_params.len>0) { + if(puri.sip_params.len > 0) { t = puri.sip_params; - } else if(puri.params.len>0) { + } else if(puri.params.len > 0) { t = puri.params; } else { LM_DBG("no uri params [%.*s]\n", ouri.len, ouri.s); return 1; } - if (parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { + if(parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { LM_ERR("ruri parameter parsing failed\n"); return -1; } - for (pit = params; pit; pit = pit->next) { - if ((pit->name.len == sparam->len) && - (strncasecmp(pit->name.s, sparam->s, sparam->len) == 0)) { + for(pit = params; pit; pit = pit->next) { + if((pit->name.len == sparam->len) + && (strncasecmp(pit->name.s, sparam->s, sparam->len) == 0)) { break; } } - if(pit==NULL) { + if(pit == NULL) { free_params(params); return 1; } @@ -536,7 +536,7 @@ int ki_uri_param_rm(sip_msg_t *msg, str *sparam) memcpy(buri, ouri.s, nuri.s - ouri.s); nuri.len = nuri.s - ouri.s; nuri.s = buri; - if(pit->body.len>0) { + if(pit->body.len > 0) { if(pit->body.s + pit->body.len < ouri.s + ouri.len) { memcpy(nuri.s + nuri.len, pit->body.s + pit->body.len, ouri.s + ouri.len - pit->body.s - pit->body.len); @@ -555,16 +555,15 @@ int ki_uri_param_rm(sip_msg_t *msg, str *sparam) return -1; } return 1; - } /* * Remove param from Request URI */ -int w_uri_param_rm(struct sip_msg* _msg, char* _param, char* _str2) +int w_uri_param_rm(struct sip_msg *_msg, char *_param, char *_str2) { str sparam; - if(fixup_get_svalue(_msg, (gparam_t*)_param, &sparam)<0) { + if(fixup_get_svalue(_msg, (gparam_t *)_param, &sparam) < 0) { LM_ERR("failed to get parameter\n"); return -1; } @@ -577,7 +576,7 @@ int w_uri_param_rm(struct sip_msg* _msg, char* _param, char* _str2) * tel URI. Returns -1, if conversion failed. Takes SIP URI hostpart from * second parameter and (if needed) writes the result to third parameter. */ -int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res) +int tel2sip(struct sip_msg *_msg, char *_uri, char *_hostpart, char *_res) { str uri, hostpart, tel_uri, sip_uri; char *at; @@ -586,37 +585,39 @@ int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res) pv_value_t res_val; /* get parameters */ - if (get_str_fparam(&uri, _msg, (fparam_t*)_uri) < 0) { + if(get_str_fparam(&uri, _msg, (fparam_t *)_uri) < 0) { LM_ERR("failed to get uri value\n"); return -1; } - if (get_str_fparam(&hostpart, _msg, (fparam_t*)_hostpart) < 0) { + if(get_str_fparam(&hostpart, _msg, (fparam_t *)_hostpart) < 0) { LM_ERR("failed to get hostpart value\n"); return -1; } res = (pv_spec_t *)_res; /* check if anything needs to be done */ - if (uri.len < 4) return 2; - if (strncasecmp(uri.s, "tel:", 4) != 0) return 2; + if(uri.len < 4) + return 2; + if(strncasecmp(uri.s, "tel:", 4) != 0) + return 2; /* reserve memory for clean tel uri */ - tel_uri.s = pkg_malloc(uri.len+1); - if (tel_uri.s == 0) { + tel_uri.s = pkg_malloc(uri.len + 1); + if(tel_uri.s == 0) { PKG_MEM_ERROR; return -1; } /* Remove visual separators before converting to SIP URI. Don't remove * visual separators in TEL URI parameters (after the first ";") */ - for (i=0, j=0; i < uri.len; i++) { - if (in_tel_parameters == 0) { - if (uri.s[i] == ';') + for(i = 0, j = 0; i < uri.len; i++) { + if(in_tel_parameters == 0) { + if(uri.s[i] == ';') in_tel_parameters = 1; } - if (in_tel_parameters == 0) { - if ((uri.s[i] != '-') && (uri.s[i] != '.') && - (uri.s[i] != '(') && (uri.s[i] != ')')) + if(in_tel_parameters == 0) { + if((uri.s[i] != '-') && (uri.s[i] != '.') && (uri.s[i] != '(') + && (uri.s[i] != ')')) tel_uri.s[j++] = tolower(uri.s[i]); } else { tel_uri.s[j++] = tolower(uri.s[i]); @@ -627,8 +628,8 @@ int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res) /* reserve memory for resulting sip uri */ sip_uri.len = 4 + tel_uri.len - 4 + 1 + hostpart.len + 1 + 10; - sip_uri.s = pkg_malloc(sip_uri.len+1); - if (sip_uri.s == 0) { + sip_uri.s = pkg_malloc(sip_uri.len + 1); + if(sip_uri.s == 0) { PKG_MEM_ERROR; pkg_free(tel_uri.s); return -1; @@ -649,7 +650,7 @@ int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res) /* set result pv value and write sip uri to result pv */ res_val.rs = sip_uri; res_val.flags = PV_VAL_STR; - if (res->setf(_msg, &res->pvp, (int)EQ_T, &res_val) != 0) { + if(res->setf(_msg, &res->pvp, (int)EQ_T, &res_val) != 0) { LM_ERR("failed to set result pvar\n"); pkg_free(sip_uri.s); return -1; @@ -664,15 +665,17 @@ int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res) /* * Check if parameter is an e164 number. */ -int siputils_e164_check(str* _user) +int siputils_e164_check(str *_user) { int i; char c; - if ((_user->len > 2) && (_user->len <= e164_max_len) && ((_user->s)[0] == '+')) { - for (i = 1; i < _user->len; i++) { + if((_user->len > 2) && (_user->len <= e164_max_len) + && ((_user->s)[0] == '+')) { + for(i = 1; i < _user->len; i++) { c = (_user->s)[i]; - if (c < '0' || c > '9') return -1; + if(c < '0' || c > '9') + return -1; } return 1; } @@ -683,16 +686,16 @@ int siputils_e164_check(str* _user) /* * Check if user part of URI in pseudo variable is an e164 number */ -int w_is_e164(struct sip_msg* _m, char* _sp, char* _s2) +int w_is_e164(struct sip_msg *_m, char *_sp, char *_s2) { pv_spec_t *sp; pv_value_t pv_val; sp = (pv_spec_t *)_sp; - if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { - if (pv_val.flags & PV_VAL_STR) { - if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) { + if(sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { + if(pv_val.flags & PV_VAL_STR) { + if(pv_val.rs.len == 0 || pv_val.rs.s == NULL) { LM_DBG("missing argument\n"); return -1; } @@ -711,16 +714,16 @@ int w_is_e164(struct sip_msg* _m, char* _sp, char* _s2) /* * Check if user part of URI in pseudo variable is an e164 number */ -int w_is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2) +int w_is_uri_user_e164(struct sip_msg *_m, char *_sp, char *_s2) { pv_spec_t *sp; pv_value_t pv_val; sp = (pv_spec_t *)_sp; - if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { - if (pv_val.flags & PV_VAL_STR) { - if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) { + if(sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { + if(pv_val.flags & PV_VAL_STR) { + if(pv_val.rs.len == 0 || pv_val.rs.s == NULL) { LM_DBG("missing uri\n"); return -1; } @@ -742,13 +745,14 @@ int is_uri_user_e164(str *uri) str user; chr = memchr(uri->s, ':', uri->len); - if (chr == NULL) { + if(chr == NULL) { LM_ERR("parsing URI failed\n"); return -1; }; user.s = chr + 1; chr = memchr(user.s, '@', uri->len - (user.s - uri->s)); - if (chr == NULL) return -1; + if(chr == NULL) + return -1; user.len = chr - user.s; return siputils_e164_check(&user); @@ -757,7 +761,7 @@ int is_uri_user_e164(str *uri) /* * Set userpart of URI */ -int set_uri_user(struct sip_msg* _m, char* _uri, char* _value) +int set_uri_user(struct sip_msg *_m, char *_uri, char *_value) { pv_spec_t *uri_pv, *value_pv; pv_value_t uri_val, value_val, res_val; @@ -766,9 +770,9 @@ int set_uri_user(struct sip_msg* _m, char* _uri, char* _value) char new_uri[MAX_URI_SIZE + 1]; uri_pv = (pv_spec_t *)_uri; - if (uri_pv && (pv_get_spec_value(_m, uri_pv, &uri_val) == 0)) { - if (uri_val.flags & PV_VAL_STR) { - if (uri_val.rs.len == 0 || uri_val.rs.s == NULL) { + if(uri_pv && (pv_get_spec_value(_m, uri_pv, &uri_val) == 0)) { + if(uri_val.flags & PV_VAL_STR) { + if(uri_val.rs.len == 0 || uri_val.rs.s == NULL) { LM_ERR("missing uri value\n"); return -1; } @@ -783,9 +787,9 @@ int set_uri_user(struct sip_msg* _m, char* _uri, char* _value) uri = uri_val.rs; value_pv = (pv_spec_t *)_value; - if (value_pv && (pv_get_spec_value(_m, value_pv, &value_val) == 0)) { - if (value_val.flags & PV_VAL_STR) { - if (value_val.rs.s == NULL) { + if(value_pv && (pv_get_spec_value(_m, value_pv, &value_val) == 0)) { + if(value_val.flags & PV_VAL_STR) { + if(value_val.rs.s == NULL) { LM_ERR("missing uriuser value\n"); return -1; } @@ -800,15 +804,16 @@ int set_uri_user(struct sip_msg* _m, char* _uri, char* _value) value = value_val.rs; colon = strchr(uri.s, ':'); - if (colon == NULL) { + if(colon == NULL) { LM_ERR("uri does not contain ':' character\n"); return -1; } at = strchr(uri.s, '@'); c = &(new_uri[0]); - if (at == NULL) { - if (value.len == 0) return 1; - if (uri.len + value.len > MAX_URI_SIZE) { + if(at == NULL) { + if(value.len == 0) + return 1; + if(uri.len + value.len > MAX_URI_SIZE) { LM_ERR("resulting uri would be too large\n"); return -1; } @@ -818,12 +823,12 @@ int set_uri_user(struct sip_msg* _m, char* _uri, char* _value) append_str(c, colon + 1, uri.len - (colon - uri.s + 1)); res_val.rs.len = uri.len + value.len + 1; } else { - if (value.len == 0) { + if(value.len == 0) { append_str(c, uri.s, colon - uri.s + 1); append_str(c, at + 1, uri.len - (at - uri.s + 1)); res_val.rs.len = uri.len - (at - colon); } else { - if (uri.len + value.len - (at - colon - 1) > MAX_URI_SIZE) { + if(uri.len + value.len - (at - colon - 1) > MAX_URI_SIZE) { LM_ERR("resulting uri would be too large\n"); return -1; } @@ -845,7 +850,7 @@ int set_uri_user(struct sip_msg* _m, char* _uri, char* _value) /* * Set hostpart of URI */ -int set_uri_host(struct sip_msg* _m, char* _uri, char* _value) +int set_uri_host(struct sip_msg *_m, char *_uri, char *_value) { pv_spec_t *uri_pv, *value_pv; pv_value_t uri_val, value_val, res_val; @@ -855,9 +860,9 @@ int set_uri_host(struct sip_msg* _m, char* _uri, char* _value) char new_uri[MAX_URI_SIZE + 1]; uri_pv = (pv_spec_t *)_uri; - if (uri_pv && (pv_get_spec_value(_m, uri_pv, &uri_val) == 0)) { - if (uri_val.flags & PV_VAL_STR) { - if (uri_val.rs.len == 0 || uri_val.rs.s == NULL) { + if(uri_pv && (pv_get_spec_value(_m, uri_pv, &uri_val) == 0)) { + if(uri_val.flags & PV_VAL_STR) { + if(uri_val.rs.len == 0 || uri_val.rs.s == NULL) { LM_ERR("missing uri value\n"); return -1; } @@ -872,9 +877,9 @@ int set_uri_host(struct sip_msg* _m, char* _uri, char* _value) uri = uri_val.rs; value_pv = (pv_spec_t *)_value; - if (value_pv && (pv_get_spec_value(_m, value_pv, &value_val) == 0)) { - if (value_val.flags & PV_VAL_STR) { - if (value_val.rs.s == NULL) { + if(value_pv && (pv_get_spec_value(_m, value_pv, &value_val) == 0)) { + if(value_val.flags & PV_VAL_STR) { + if(value_val.rs.s == NULL) { LM_ERR("missing uri value\n"); return -1; } @@ -888,23 +893,23 @@ int set_uri_host(struct sip_msg* _m, char* _uri, char* _value) } value = value_val.rs; - if (value.len == 0) { + if(value.len == 0) { LM_ERR("hostpart of uri cannot be empty\n"); return -1; } - if (uri.len + value.len > MAX_URI_SIZE) { + if(uri.len + value.len > MAX_URI_SIZE) { LM_ERR("resulting uri would be too large\n"); return -1; } colon = strchr(uri.s, ':'); - if (colon == NULL) { + if(colon == NULL) { LM_ERR("uri does not contain ':' character\n"); return -1; } c = &(new_uri[0]); at = strchr(colon + 1, '@'); - if (at == NULL) { + if(at == NULL) { next = colon + 1; } else { next = at + 1; @@ -926,32 +931,32 @@ int set_uri_host(struct sip_msg* _m, char* _uri, char* _value) /** * Find if Request URI has a given parameter and returns the value. */ -int get_uri_param(struct sip_msg* _msg, char* _param, char* _value) +int get_uri_param(struct sip_msg *_msg, char *_param, char *_value) { str *param, t; - pv_spec_t* dst; + pv_spec_t *dst; pv_value_t val; param_hooks_t hooks; - param_t* params; + param_t *params; - param = (str*)_param; - dst = (pv_spec_t *) _value; + param = (str *)_param; + dst = (pv_spec_t *)_value; - if (parse_sip_msg_uri(_msg) < 0) { + if(parse_sip_msg_uri(_msg) < 0) { LM_ERR("ruri parsing failed\n"); return -1; } t = _msg->parsed_uri.params; - if (parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { + if(parse_params(&t, CLASS_ANY, &hooks, ¶ms) < 0) { LM_ERR("ruri parameter parsing failed\n"); return -1; } - while (params) { - if ((params->name.len == param->len) + while(params) { + if((params->name.len == param->len) && (strncmp(params->name.s, param->s, param->len) == 0)) { memset(&val, 0, sizeof(pv_value_t)); val.rs.s = params->body.s; @@ -981,20 +986,20 @@ int ki_is_tel_number(sip_msg_t *msg, str *tval) { int i; - if(tval==NULL || tval->len<1) + if(tval == NULL || tval->len < 1) return -2; i = 0; - if(tval->s[0]=='+') { - if(tval->len<2) + if(tval->s[0] == '+') { + if(tval->len < 2) return -2; - if(tval->s[1]<'1' || tval->s[1]>'9') + if(tval->s[1] < '1' || tval->s[1] > '9') return -2; i = 2; } - for(; ilen; i++) { - if(tval->s[i]<'0' || tval->s[i]>'9') + for(; i < tval->len; i++) { + if(tval->s[i] < '0' || tval->s[i] > '9') return -2; } @@ -1006,11 +1011,11 @@ int ki_is_tel_number(sip_msg_t *msg, str *tval) * Check if the parameter is a valid telephone number * - optional leading + followed by digits only */ -int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2) +int is_tel_number(sip_msg_t *msg, char *_sp, char *_s2) { str tval = {0, 0}; - if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)_sp, &tval) != 0) { LM_ERR("cannot get parameter value\n"); return -1; } @@ -1026,12 +1031,12 @@ int ki_is_numeric(sip_msg_t *msg, str *tval) { int i; - if(tval==NULL || tval->len<=0) + if(tval == NULL || tval->len <= 0) return -2; i = 0; - for(; ilen; i++) { - if(tval->s[i]<'0' || tval->s[i]>'9') + for(; i < tval->len; i++) { + if(tval->s[i] < '0' || tval->s[i] > '9') return -2; } @@ -1042,11 +1047,11 @@ int ki_is_numeric(sip_msg_t *msg, str *tval) /* * Check if the parameter contains decimal digits only */ -int is_numeric(sip_msg_t *msg, char *_sp, char* _s2) +int is_numeric(sip_msg_t *msg, char *_sp, char *_s2) { str tval = {0, 0}; - if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)_sp, &tval) != 0) { LM_ERR("cannot get parameter value\n"); return -1; } @@ -1062,14 +1067,14 @@ int ki_is_alphanum(sip_msg_t *msg, str *tval) { int i; - if(tval==NULL || tval->len<=0) + if(tval == NULL || tval->len <= 0) return -2; i = 0; - for(; ilen; i++) { - if( !((tval->s[i]>='0' && tval->s[i]<='9') - || (tval->s[i]>='A' && tval->s[i]<='Z') - || (tval->s[i]>='a' && tval->s[i]<='z')) ) + for(; i < tval->len; i++) { + if(!((tval->s[i] >= '0' && tval->s[i] <= '9') + || (tval->s[i] >= 'A' && tval->s[i] <= 'Z') + || (tval->s[i] >= 'a' && tval->s[i] <= 'z'))) return -3; } @@ -1079,11 +1084,11 @@ int ki_is_alphanum(sip_msg_t *msg, str *tval) /* * Check if the parameter contains alphanumeric characters */ -int ksr_is_alphanum(sip_msg_t *msg, char *_sp, char* _s2) +int ksr_is_alphanum(sip_msg_t *msg, char *_sp, char *_s2) { str tval = {0, 0}; - if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)_sp, &tval) != 0) { LM_ERR("cannot get parameter value\n"); return -1; } @@ -1101,25 +1106,25 @@ int ki_is_alphanumex(sip_msg_t *msg, str *tval, str *eset) int j; int found; - if(tval==NULL || tval->len<=0) + if(tval == NULL || tval->len <= 0) return -2; i = 0; - for(; ilen; i++) { - if( !((tval->s[i]>='0' && tval->s[i]<='9') - || (tval->s[i]>='A' && tval->s[i]<='Z') - || (tval->s[i]>='a' && tval->s[i]<='z')) ) { - if(eset==NULL || eset->len<=0) { + for(; i < tval->len; i++) { + if(!((tval->s[i] >= '0' && tval->s[i] <= '9') + || (tval->s[i] >= 'A' && tval->s[i] <= 'Z') + || (tval->s[i] >= 'a' && tval->s[i] <= 'z'))) { + if(eset == NULL || eset->len <= 0) { return -3; } found = 0; - for(j=0; jlen; j++) { - if(tval->s[i]==eset->s[j]) { + for(j = 0; j < eset->len; j++) { + if(tval->s[i] == eset->s[j]) { found = 1; break; } } - if(found==0) { + if(found == 0) { return -3; } } @@ -1132,16 +1137,16 @@ int ki_is_alphanumex(sip_msg_t *msg, str *tval, str *eset) * Check if the parameter contains alphanumeric characters or are part of * the second parameter */ -int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char* _se) +int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char *_se) { str tval = {0, 0}; str eset = {0, 0}; - if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)_sp, &tval) != 0) { LM_ERR("cannot get tval parameter value\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)_se, &eset)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)_se, &eset) != 0) { LM_ERR("cannot get eset parameter value\n"); return -1; } diff --git a/src/modules/siputils/checks.h b/src/modules/siputils/checks.h index e55739e66ad..a5a36f43d5c 100644 --- a/src/modules/siputils/checks.h +++ b/src/modules/siputils/checks.h @@ -29,7 +29,6 @@ */ - #ifndef CHECKS_H #define CHECKS_H @@ -39,33 +38,33 @@ /* * Check if given username matches those in digest credentials */ -int is_user(struct sip_msg* _msg, char* _user, char* _str2); +int is_user(struct sip_msg *_msg, char *_user, char *_str2); /* * Check if message includes a to-tag */ -int has_totag(struct sip_msg* _m); -int w_has_totag(struct sip_msg* _m, char* _foo, char* _bar); +int has_totag(struct sip_msg *_m); +int w_has_totag(struct sip_msg *_m, char *_foo, char *_bar); /* * Find if Request URI has a given parameter with no value */ -int uri_param_1(struct sip_msg* _msg, char* _param, char* _str2); +int uri_param_1(struct sip_msg *_msg, char *_param, char *_str2); /* * Find if Request URI has a given parameter with matching value */ -int uri_param_2(struct sip_msg* _msg, char* _param, char* _value); +int uri_param_2(struct sip_msg *_msg, char *_param, char *_value); /* * Adds a new parameter to Request URI */ -int add_uri_param(struct sip_msg* _msg, char* _param, char* _s2); -int ki_add_uri_param(struct sip_msg* _msg, str* param); +int add_uri_param(struct sip_msg *_msg, char *_param, char *_s2); +int ki_add_uri_param(struct sip_msg *_msg, str *param); /* * Converts URI, if it is tel URI, to SIP URI. Returns 1, if @@ -73,73 +72,73 @@ int ki_add_uri_param(struct sip_msg* _msg, str* param); * tel URI. Returns -1, if conversion failed. Takes SIP URI hostpart from * second parameter and (if needed) writes the result to third parameter. */ -int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res); +int tel2sip(struct sip_msg *_msg, char *_uri, char *_hostpart, char *_res); /* * Check if pseudo variable contains a valid uri */ -int is_uri(struct sip_msg* _m, char* _sp, char* _s2); +int is_uri(struct sip_msg *_m, char *_sp, char *_s2); /* * Check if user part of URI in pseudo variable is an e164 number */ -int w_is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2); +int w_is_uri_user_e164(struct sip_msg *_m, char *_sp, char *_s2); int is_uri_user_e164(str *uri); /* * Check if pseudo variable argument value is an e164 number */ -int w_is_e164(struct sip_msg* _m, char* _sp, char* _s2); +int w_is_e164(struct sip_msg *_m, char *_sp, char *_s2); -int siputils_e164_check(str* _user); +int siputils_e164_check(str *_user); /* * Set userpart of URI */ -int set_uri_user(struct sip_msg* _m, char* _uri, char* _value); +int set_uri_user(struct sip_msg *_m, char *_uri, char *_value); /* * Set hostpart of URI */ -int set_uri_host(struct sip_msg* _m, char* _uri, char* _value); +int set_uri_host(struct sip_msg *_m, char *_uri, char *_value); /* * Return true (1) if SIP message is request, otherwise false (-1) */ -int w_is_request(struct sip_msg* msg, char *foo, char *bar); -int is_request(struct sip_msg* msg); +int w_is_request(struct sip_msg *msg, char *foo, char *bar); +int is_request(struct sip_msg *msg); /* * Return true (1) if SIP message is reply, otherwise false (-1) */ -int w_is_reply(struct sip_msg* msg, char *foo, char *bar); -int is_reply(struct sip_msg* msg); +int w_is_reply(struct sip_msg *msg, char *foo, char *bar); +int is_reply(struct sip_msg *msg); /* * Find if Request URI has a given parameter with matching value */ -int get_uri_param(struct sip_msg* _msg, char* _param, char* _value); +int get_uri_param(struct sip_msg *_msg, char *_param, char *_value); /* * Check if parameter value has a telephone number format */ -int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2); +int is_tel_number(sip_msg_t *msg, char *_sp, char *_s2); /* * Check if parameter value consists solely of decimal digits */ -int is_numeric(sip_msg_t *msg, char *_sp, char* _s2); +int is_numeric(sip_msg_t *msg, char *_sp, char *_s2); /* * Check if the parameter contains alphanumeric characters */ -int ksr_is_alphanum(sip_msg_t *msg, char *_sp, char* _s2); +int ksr_is_alphanum(sip_msg_t *msg, char *_sp, char *_s2); /* * Check if the parameter contains alphanumeric characters or are part of * the second parameter */ -int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char* _se); +int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char *_se); int ki_is_user(sip_msg_t *_m, str *suser); @@ -157,10 +156,10 @@ int ki_is_alphanumex(sip_msg_t *msg, str *tval, str *eset); int ki_uri_param_rm(sip_msg_t *msg, str *sparam); -int w_uri_param_rm(struct sip_msg* _msg, char* _param, char* _str2); +int w_uri_param_rm(struct sip_msg *_msg, char *_param, char *_str2); int ki_uri_param_any(sip_msg_t *msg, str *sparam); -int w_uri_param_any(struct sip_msg* _msg, char* _param, char* _str2); +int w_uri_param_any(struct sip_msg *_msg, char *_param, char *_str2); #endif /* CHECKS_H */ diff --git a/src/modules/siputils/config.c b/src/modules/siputils/config.c index 3a63c40d243..d154141b7c9 100644 --- a/src/modules/siputils/config.c +++ b/src/modules/siputils/config.c @@ -29,19 +29,18 @@ #include "config.h" -struct cfg_group_siputils default_siputils_cfg = { - 0 - }; +struct cfg_group_siputils default_siputils_cfg = {0}; -void *siputils_cfg = &default_siputils_cfg; +void *siputils_cfg = &default_siputils_cfg; -cfg_def_t siputils_cfg_def[] = { - {"ring_timeout", CFG_VAR_INT | CFG_ATOMIC, 0, 0, ring_timeout_fixup, 0, - "define how long the Call-id is kept in the internal list" }, - {0, 0, 0, 0, 0, 0} -}; +cfg_def_t siputils_cfg_def[] = { + {"ring_timeout", CFG_VAR_INT | CFG_ATOMIC, 0, 0, ring_timeout_fixup, 0, + "define how long the Call-id is kept in the internal list"}, + {0, 0, 0, 0, 0, 0}}; -int ring_timeout_fixup(void *handle, str* gname, str* name, void **val){ - if((int)(long)*val > 0) return 0; +int ring_timeout_fixup(void *handle, str *gname, str *name, void **val) +{ + if((int)(long)*val > 0) + return 0; return -1; } diff --git a/src/modules/siputils/config.h b/src/modules/siputils/config.h index 7fe1e83b33a..a029e30ea00 100644 --- a/src/modules/siputils/config.h +++ b/src/modules/siputils/config.h @@ -30,14 +30,15 @@ #include "../../core/cfg/cfg.h" #include "../../core/str.h" -struct cfg_group_siputils { - unsigned int ring_timeout; +struct cfg_group_siputils +{ + unsigned int ring_timeout; }; -extern struct cfg_group_siputils default_siputils_cfg; -extern void *siputils_cfg; -extern cfg_def_t siputils_cfg_def[]; +extern struct cfg_group_siputils default_siputils_cfg; +extern void *siputils_cfg; +extern cfg_def_t siputils_cfg_def[]; -int ring_timeout_fixup(void*, str*, str*, void**); +int ring_timeout_fixup(void *, str *, str *, void **); #endif diff --git a/src/modules/siputils/contact_ops.c b/src/modules/siputils/contact_ops.c index 8f59cdca5b8..59fed951e19 100644 --- a/src/modules/siputils/contact_ops.c +++ b/src/modules/siputils/contact_ops.c @@ -160,8 +160,8 @@ int ki_decode_contact(sip_msg_t *msg) LM_DBG("newuri.s=[%.*s]\n", newUri.len, newUri.s); if(res != 0) { - LM_ERR("failed decoding contact [%.*s] - return code %d\n", - uri.len, uri.s, res); + LM_ERR("failed decoding contact [%.*s] - return code %d\n", uri.len, + uri.s, res); return res; } else { /* we do not modify the original first line */ @@ -171,7 +171,7 @@ int ki_decode_contact(sip_msg_t *msg) pkg_free(msg->new_uri.s); msg->new_uri = newUri; } - msg->parsed_uri_ok=0; + msg->parsed_uri_ok = 0; ruri_mark_new(); } return 1; @@ -226,8 +226,8 @@ int ki_decode_contact_header(sip_msg_t *msg) res = decode_uri(uri, separator, &newUri); if(res != 0) { - LM_ERR("failed decoding contact [%.*s] - return code %d\n", - uri.len, uri.s, res); + LM_ERR("failed decoding contact [%.*s] - return code %d\n", uri.len, + uri.s, res); return res; } LM_DBG("newuri.s=[%.*s]\n", newUri.len, newUri.s); @@ -308,8 +308,8 @@ int encode2format(str uri, struct uri_format *format) * parse_uri,myfunction works good */ foo = parse_uri(start, end - start, &sipUri); if(foo != 0) { - LM_ERR("parse_uri failed on [%.*s] - return code %d \n", - uri.len, uri.s, foo); + LM_ERR("parse_uri failed on [%.*s] - return code %d \n", uri.len, uri.s, + foo); return foo - 10; } @@ -660,40 +660,41 @@ int ki_contact_param_encode(sip_msg_t *msg, str *nparam, str *saddr) c = cb->contacts; /* we visit each contact */ while(c != NULL) { - if(c->uri.len>4) { - pval.len = base64url_enc(c->uri.s, c->uri.len, bval, MAX_URI_SIZE-1); - if (pval.len < 0) { - LM_ERR("failed to encode contact uri [%.*s]\n", - c->uri.len, c->uri.s); + if(c->uri.len > 4) { + pval.len = + base64url_enc(c->uri.s, c->uri.len, bval, MAX_URI_SIZE - 1); + if(pval.len < 0) { + LM_ERR("failed to encode contact uri [%.*s]\n", c->uri.len, + c->uri.s); return -1; } - if (pval.len>1 && bval[pval.len-1] == '=') { + if(pval.len > 1 && bval[pval.len - 1] == '=') { pval.len--; - if (pval.len>1 && bval[pval.len-1] == '=') { + if(pval.len > 1 && bval[pval.len - 1] == '=') { pval.len--; } } bval[pval.len] = '\0'; pval.s = bval; - nuri.s = (char*)pkg_malloc(MAX_URI_SIZE * sizeof(char)); - if(nuri.s==NULL) { + nuri.s = (char *)pkg_malloc(MAX_URI_SIZE * sizeof(char)); + if(nuri.s == NULL) { PKG_MEM_ERROR; return -1; } q = 1; - for(p = c->uri.s-1; p > msg->buf; p++) { + for(p = c->uri.s - 1; p > msg->buf; p++) { if(*p == '<') { q = 0; break; } - if(*p != ' ' && *p != '\t' && *p != '\n' && *p != '\n') { + if(*p != ' ' && *p != '\t' && *p != '\n' && *p != '\n') { break; } } - nuri.len = snprintf(nuri.s, MAX_URI_SIZE-1, "%s%.*s;%.*s=%.*s%s", - (q)?"<":"", saddr->len, saddr->s, nparam->len, nparam->s, - pval.len, pval.s, (q)?">":""); - if(nuri.len<=0 || nuri.len>=MAX_URI_SIZE) { + nuri.len = snprintf(nuri.s, MAX_URI_SIZE - 1, "%s%.*s;%.*s=%.*s%s", + (q) ? "<" : "", saddr->len, saddr->s, nparam->len, + nparam->s, pval.len, pval.s, (q) ? ">" : ""); + if(nuri.len <= 0 || nuri.len >= MAX_URI_SIZE) { LM_ERR("failed to build the new contact for [%.*s] uri (%d)\n", c->uri.len, c->uri.s, nuri.len); pkg_free(nuri.s); @@ -701,8 +702,8 @@ int ki_contact_param_encode(sip_msg_t *msg, str *nparam, str *saddr) } LM_DBG("encoded uri [%.*s] (%d)\n", nuri.len, nuri.s, nuri.len); if(patch(msg, c->uri.s, c->uri.len, nuri.s, nuri.len) < 0) { - LM_ERR("failed to update contact uri [%.*s]\n", - c->uri.len, c->uri.s); + LM_ERR("failed to update contact uri [%.*s]\n", c->uri.len, + c->uri.s); pkg_free(nuri.s); return -3; } @@ -719,9 +720,9 @@ int ki_contact_param_decode(sip_msg_t *msg, str *nparam) contact_t *c; sip_uri_t puri; str sparams; - param_t* params = NULL; + param_t *params = NULL; param_hooks_t phooks; - param_t* pit; + param_t *pit; hdr_field_t *hf = NULL; char boval[MAX_URI_SIZE]; char bnval[MAX_URI_SIZE]; @@ -729,7 +730,7 @@ int ki_contact_param_decode(sip_msg_t *msg, str *nparam) str nval; int i; - if(parse_contact_headers(msg)<0 || msg->contact==NULL + if(parse_contact_headers(msg) < 0 || msg->contact == NULL || msg->contact->parsed == NULL) { LM_DBG("no Contact header present\n"); return 1; @@ -743,35 +744,38 @@ int ki_contact_param_decode(sip_msg_t *msg, str *nparam) } cb = (contact_body_t *)hf->parsed; for(c = cb->contacts; c != NULL; c = c->next) { - if(c->uri.len<4) { + if(c->uri.len < 4) { continue; } - if (parse_uri(c->uri.s, c->uri.len, &puri) < 0) { - LM_ERR("failed to parse contact uri [%.*s]\n", c->uri.len, c->uri.s); + if(parse_uri(c->uri.s, c->uri.len, &puri) < 0) { + LM_ERR("failed to parse contact uri [%.*s]\n", c->uri.len, + c->uri.s); return -1; } - if(puri.sip_params.len>0) { + if(puri.sip_params.len > 0) { sparams = puri.sip_params; - } else if(puri.params.len>0) { + } else if(puri.params.len > 0) { sparams = puri.params; } else { continue; } - if (parse_params2(&sparams, CLASS_ANY, &phooks, ¶ms, ';')<0) { - LM_ERR("failed to parse uri params [%.*s]\n", c->uri.len, c->uri.s); + if(parse_params2(&sparams, CLASS_ANY, &phooks, ¶ms, ';') < 0) { + LM_ERR("failed to parse uri params [%.*s]\n", c->uri.len, + c->uri.s); continue; } pit = params; - while(pit!=NULL) { - if(pit->name.len==nparam->len - && strncasecmp(pit->name.s, nparam->s, nparam->len)==0) { + while(pit != NULL) { + if(pit->name.len == nparam->len + && strncasecmp(pit->name.s, nparam->s, nparam->len) + == 0) { break; } - pit=pit->next; + pit = pit->next; } - if(pit==NULL || pit->body.len<=0) { + if(pit == NULL || pit->body.len <= 0) { free_params(params); params = NULL; continue; @@ -779,29 +783,29 @@ int ki_contact_param_decode(sip_msg_t *msg, str *nparam) oval = pit->body; if(oval.len % 4) { - if(oval.len + 4 >= MAX_URI_SIZE-1) { + if(oval.len + 4 >= MAX_URI_SIZE - 1) { LM_ERR("not enough space to insert padding [%.*s]\n", c->uri.len, c->uri.s); free_params(params); return -1; } memcpy(boval, oval.s, oval.len); - for(i=0; i < (4 - (oval.len % 4)); i++) { + for(i = 0; i < (4 - (oval.len % 4)); i++) { boval[oval.len + i] = '='; } oval.s = boval; oval.len += (4 - (oval.len % 4)); /* move to next buffer */ } - nval.len = base64url_dec(oval.s, oval.len, bnval, MAX_URI_SIZE-1); - if (nval.len <= 0) { + nval.len = base64url_dec(oval.s, oval.len, bnval, MAX_URI_SIZE - 1); + if(nval.len <= 0) { free_params(params); - LM_ERR("failed to decode contact uri [%.*s]\n", - c->uri.len, c->uri.s); + LM_ERR("failed to decode contact uri [%.*s]\n", c->uri.len, + c->uri.s); return -1; } - nval.s = (char*)pkg_malloc((nval.len+1)*sizeof(char)); - if(nval.s==NULL) { + nval.s = (char *)pkg_malloc((nval.len + 1) * sizeof(char)); + if(nval.s == NULL) { free_params(params); PKG_MEM_ERROR; return -1; @@ -811,8 +815,8 @@ int ki_contact_param_decode(sip_msg_t *msg, str *nparam) LM_DBG("decoded new uri [%.*s] (%d)\n", nval.len, nval.s, nval.len); if(patch(msg, c->uri.s, c->uri.len, nval.s, nval.len) < 0) { - LM_ERR("failed to update contact uri [%.*s]\n", - c->uri.len, c->uri.s); + LM_ERR("failed to update contact uri [%.*s]\n", c->uri.len, + c->uri.s); free_params(params); pkg_free(nval.s); return -2; @@ -834,9 +838,9 @@ int ki_contact_param_decode_ruri(sip_msg_t *msg, str *nparam) str uri; sip_uri_t puri; str sparams; - param_t* params = NULL; + param_t *params = NULL; param_hooks_t phooks; - param_t *pit=NULL; + param_t *pit = NULL; char boval[MAX_URI_SIZE]; char bnval[MAX_URI_SIZE]; str oval; @@ -853,33 +857,33 @@ int ki_contact_param_decode_ruri(sip_msg_t *msg, str *nparam) uri = msg->new_uri; } - if (parse_uri (uri.s, uri.len, &puri) < 0) { + if(parse_uri(uri.s, uri.len, &puri) < 0) { LM_ERR("failed to parse r-uri [%.*s]\n", uri.len, uri.s); return -1; } - if(puri.sip_params.len>0) { + if(puri.sip_params.len > 0) { sparams = puri.sip_params; - } else if(puri.params.len>0) { + } else if(puri.params.len > 0) { sparams = puri.params; } else { LM_DBG("no uri params [%.*s]\n", uri.len, uri.s); return 1; } - if (parse_params2(&sparams, CLASS_ANY, &phooks, ¶ms, ';')<0) { + if(parse_params2(&sparams, CLASS_ANY, &phooks, ¶ms, ';') < 0) { LM_ERR("failed to parse uri params [%.*s]\n", uri.len, uri.s); return -1; } pit = params; - while(pit!=NULL) { - if(pit->name.len==nparam->len - && strncasecmp(pit->name.s, nparam->s, nparam->len)==0) { + while(pit != NULL) { + if(pit->name.len == nparam->len + && strncasecmp(pit->name.s, nparam->s, nparam->len) == 0) { break; } - pit=pit->next; + pit = pit->next; } - if(pit==NULL || pit->body.len<=0) { + if(pit == NULL || pit->body.len <= 0) { free_params(params); LM_DBG("no uri param value [%.*s]\n", uri.len, uri.s); return 1; @@ -887,22 +891,22 @@ int ki_contact_param_decode_ruri(sip_msg_t *msg, str *nparam) oval = pit->body; if(oval.len % 4) { - if(oval.len + 4 >= MAX_URI_SIZE-1) { - LM_ERR("not enough space to insert padding [%.*s]\n", - uri.len, uri.s); + if(oval.len + 4 >= MAX_URI_SIZE - 1) { + LM_ERR("not enough space to insert padding [%.*s]\n", uri.len, + uri.s); free_params(params); return -1; } memcpy(boval, oval.s, oval.len); - for(i=0; i < (4 - (oval.len % 4)); i++) { + for(i = 0; i < (4 - (oval.len % 4)); i++) { boval[oval.len + i] = '='; } oval.s = boval; oval.len += (4 - (oval.len % 4)); /* move to next buffer */ } - nval.len = base64url_dec(oval.s, oval.len, bnval, MAX_URI_SIZE-1); - if (nval.len <= 0) { + nval.len = base64url_dec(oval.s, oval.len, bnval, MAX_URI_SIZE - 1); + if(nval.len <= 0) { free_params(params); LM_ERR("failed to decode uri [%.*s]\n", uri.len, uri.s); return -1; @@ -929,12 +933,12 @@ int ki_contact_param_rm(sip_msg_t *msg, str *nparam) str sparams; str rms; hdr_field_t *hf = NULL; - param_t* params = NULL; + param_t *params = NULL; param_hooks_t phooks; - param_t* pit; + param_t *pit; int offset; - if(parse_contact_headers(msg)<0 || msg->contact==NULL + if(parse_contact_headers(msg) < 0 || msg->contact == NULL || msg->contact->parsed == NULL) { LM_DBG("no Contact header present\n"); return 1; @@ -948,63 +952,69 @@ int ki_contact_param_rm(sip_msg_t *msg, str *nparam) } cb = (contact_body_t *)hf->parsed; for(c = cb->contacts; c != NULL; c = c->next) { - if(c->uri.len<4) { + if(c->uri.len < 4) { continue; } - if (parse_uri(c->uri.s, c->uri.len, &puri) < 0) { - LM_ERR("failed to parse contact uri [%.*s]\n", c->uri.len, c->uri.s); + if(parse_uri(c->uri.s, c->uri.len, &puri) < 0) { + LM_ERR("failed to parse contact uri [%.*s]\n", c->uri.len, + c->uri.s); return -1; } - if(puri.sip_params.len>0) { + if(puri.sip_params.len > 0) { sparams = puri.sip_params; - } else if(puri.params.len>0) { + } else if(puri.params.len > 0) { sparams = puri.params; } else { continue; } - if (parse_params2(&sparams, CLASS_ANY, &phooks, ¶ms, ';')<0) { - LM_ERR("failed to parse uri params [%.*s]\n", c->uri.len, c->uri.s); + if(parse_params2(&sparams, CLASS_ANY, &phooks, ¶ms, ';') < 0) { + LM_ERR("failed to parse uri params [%.*s]\n", c->uri.len, + c->uri.s); continue; } pit = params; - while(pit!=NULL) { - if(pit->name.len==nparam->len - && strncasecmp(pit->name.s, nparam->s, nparam->len)==0) { + while(pit != NULL) { + if(pit->name.len == nparam->len + && strncasecmp(pit->name.s, nparam->s, nparam->len) + == 0) { break; } - pit=pit->next; + pit = pit->next; } - if(pit==NULL) { + if(pit == NULL) { free_params(params); params = NULL; continue; } rms.s = pit->name.s; - while(rms.s>c->uri.s && *rms.s!=';') { + while(rms.s > c->uri.s && *rms.s != ';') { rms.s--; } - if(*rms.s!=';') { - LM_ERR("failed to find start of the parameter delimiter [%.*s]\n", + if(*rms.s != ';') { + LM_ERR("failed to find start of the parameter delimiter " + "[%.*s]\n", c->uri.len, c->uri.s); free_params(params); params = NULL; continue; } - if(pit->body.len>0) { + if(pit->body.len > 0) { rms.len = (int)(pit->body.s + pit->body.len - rms.s); } else { rms.len = (int)(pit->name.s + pit->name.len - rms.s); } offset = rms.s - msg->buf; - if (offset < 0) { - LM_ERR("negative offset - contact uri [%.*s]\n", c->uri.len, c->uri.s); + if(offset < 0) { + LM_ERR("negative offset - contact uri [%.*s]\n", c->uri.len, + c->uri.s); free_params(params); continue; } - if (del_lump (msg, offset, rms.len, 0) == 0) { - LM_ERR("failed to remove param from message - contact uri [%.*s]\n", + if(del_lump(msg, offset, rms.len, 0) == 0) { + LM_ERR("failed to remove param from message - contact uri " + "[%.*s]\n", c->uri.len, c->uri.s); free_params(params); continue; @@ -1012,7 +1022,7 @@ int ki_contact_param_rm(sip_msg_t *msg, str *nparam) free_params(params); params = NULL; } - hf= hf->next; + hf = hf->next; } return 1; diff --git a/src/modules/siputils/options.c b/src/modules/siputils/options.c index 58140214c9a..9a500601cd2 100644 --- a/src/modules/siputils/options.c +++ b/src/modules/siputils/options.c @@ -29,7 +29,7 @@ */ #ifdef EXTRA_DEBUG -#include /* required by abort() */ +#include /* required by abort() */ #endif #include "options.h" #include "../../core/ut.h" @@ -41,33 +41,33 @@ static str opt_200_rpl = str_init("OK"); static str opt_500_rpl = str_init("Server internal error"); -int ki_opt_reply(struct sip_msg* _msg) { +int ki_opt_reply(struct sip_msg *_msg) +{ str rpl_hf; int offset = 0; /* check if it is called for an OPTIONS request */ - if (_msg->REQ_METHOD!=METHOD_OPTIONS) { - LM_ERR("called for non-OPTIONS request (%d!=%d)\n", - _msg->REQ_METHOD, METHOD_OPTIONS); + if(_msg->REQ_METHOD != METHOD_OPTIONS) { + LM_ERR("called for non-OPTIONS request (%d!=%d)\n", _msg->REQ_METHOD, + METHOD_OPTIONS); return -1; } - if(_msg->parsed_uri_ok==0 && parse_sip_msg_uri(_msg)<0) - { + if(_msg->parsed_uri_ok == 0 && parse_sip_msg_uri(_msg) < 0) { LM_ERR("ERROR while parsing the R-URI\n"); return -1; } /* FIXME: should we additionally check if ruri == server addresses ?! */ - if (_msg->parsed_uri.user.len != 0) { + if(_msg->parsed_uri.user.len != 0) { LM_ERR("ruri contains username\n"); return -1; } /* calculate the length and allocated the mem */ - rpl_hf.len = ACPT_STR_LEN + ACPT_ENC_STR_LEN + ACPT_LAN_STR_LEN + - SUPT_STR_LEN + 4*HF_SEP_STR_LEN + opt_accept.len + opt_accept_enc.len - + opt_accept_lang.len + opt_supported.len; - rpl_hf.s = (char*)pkg_malloc(rpl_hf.len); - if (!rpl_hf.s) { + rpl_hf.len = ACPT_STR_LEN + ACPT_ENC_STR_LEN + ACPT_LAN_STR_LEN + + SUPT_STR_LEN + 4 * HF_SEP_STR_LEN + opt_accept.len + + opt_accept_enc.len + opt_accept_lang.len + opt_supported.len; + rpl_hf.s = (char *)pkg_malloc(rpl_hf.len); + if(!rpl_hf.s) { PKG_MEM_CRITICAL; goto error; } @@ -99,20 +99,19 @@ int ki_opt_reply(struct sip_msg* _msg) { #ifdef EXTRA_DEBUG offset += HF_SEP_STR_LEN; - if (offset != rpl_hf.len) { + if(offset != rpl_hf.len) { LM_CRIT("headerlength (%i) != offset (%i)\n", rpl_hf.len, offset); abort(); } #endif - if (add_lump_rpl( _msg, rpl_hf.s, rpl_hf.len, - LUMP_RPL_HDR|LUMP_RPL_NODUP)!=0) { - if (opt_slb.freply(_msg, 200, &opt_200_rpl) == -1) { + if(add_lump_rpl(_msg, rpl_hf.s, rpl_hf.len, LUMP_RPL_HDR | LUMP_RPL_NODUP) + != 0) { + if(opt_slb.freply(_msg, 200, &opt_200_rpl) == -1) { LM_ERR("failed to send 200 via send_reply\n"); return -1; - } - else + } else return 1; } else { pkg_free(rpl_hf.s); @@ -120,14 +119,14 @@ int ki_opt_reply(struct sip_msg* _msg) { } error: - if (opt_slb.freply(_msg, 500, &opt_500_rpl) == -1) { + if(opt_slb.freply(_msg, 500, &opt_500_rpl) == -1) { LM_ERR("failed to send 500 via send_reply\n"); return -1; - } - else + } else return 1; } -int opt_reply(struct sip_msg* _msg, char* _foo, char* _bar) { +int opt_reply(struct sip_msg *_msg, char *_foo, char *_bar) +{ return ki_opt_reply(_msg); } diff --git a/src/modules/siputils/options.h b/src/modules/siputils/options.h index a045754bf8c..217f687e00c 100644 --- a/src/modules/siputils/options.h +++ b/src/modules/siputils/options.h @@ -63,7 +63,7 @@ extern str opt_accept_enc; extern str opt_accept_lang; extern str opt_supported; -int ki_opt_reply(struct sip_msg* _msg); -int opt_reply(struct sip_msg* _msg, char* _foo, char* _bar); +int ki_opt_reply(struct sip_msg *_msg); +int opt_reply(struct sip_msg *_msg, char *_foo, char *_bar); #endif diff --git a/src/modules/siputils/rpid.c b/src/modules/siputils/rpid.c index 78de689bd1b..42ef275bb2f 100644 --- a/src/modules/siputils/rpid.c +++ b/src/modules/siputils/rpid.c @@ -44,8 +44,8 @@ #define RPID_HF_NAME "Remote-Party-ID: " #define RPID_HF_NAME_LEN (sizeof(RPID_HF_NAME) - 1) -extern str rpid_prefix; /*!< Remote-Party-ID prefix */ -extern str rpid_suffix; /*!< Remote-Party-ID suffix */ +extern str rpid_prefix; /*!< Remote-Party-ID prefix */ +extern str rpid_suffix; /*!< Remote-Party-ID suffix */ /* rpid AVP specs */ static unsigned short rpid_avp_type; @@ -61,17 +61,16 @@ int init_rpid_avp(char *rpid_avp_param) { pv_spec_t avp_spec; str stmp; - if (rpid_avp_param && *rpid_avp_param) { - stmp.s = rpid_avp_param; stmp.len = strlen(stmp.s); - if (pv_parse_spec(&stmp, &avp_spec)==0 - || avp_spec.type!=PVT_AVP) { + if(rpid_avp_param && *rpid_avp_param) { + stmp.s = rpid_avp_param; + stmp.len = strlen(stmp.s); + if(pv_parse_spec(&stmp, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", rpid_avp_param); return -1; } - if(pv_get_avp_name(0, &(avp_spec.pvp), &rpid_avp_name, - &rpid_avp_type)!=0) - { + if(pv_get_avp_name(0, &(avp_spec.pvp), &rpid_avp_name, &rpid_avp_type) + != 0) { LM_ERR("[%s]- invalid AVP definition\n", rpid_avp_param); return -1; } @@ -89,7 +88,7 @@ int init_rpid_avp(char *rpid_avp_param) * \param rpid_avp_p AVP name * \param rpid_avp_type_p AVP type */ -void get_rpid_avp( int_str *rpid_avp_p, int *rpid_avp_type_p ) +void get_rpid_avp(int_str *rpid_avp_p, int *rpid_avp_type_p) { *rpid_avp_p = rpid_avp_name; *rpid_avp_type_p = rpid_avp_type; @@ -103,22 +102,22 @@ void get_rpid_avp( int_str *rpid_avp_p, int *rpid_avp_type_p ) * \note Copy of append_hf_helper from textops * \return 0 on success, negative on failure */ -static inline int append_rpid_helper(struct sip_msg* _m, str *_s) +static inline int append_rpid_helper(struct sip_msg *_m, str *_s) { - struct lump* anchor; + struct lump *anchor; - if (parse_headers(_m, HDR_EOH_F, 0) == -1) { + if(parse_headers(_m, HDR_EOH_F, 0) == -1) { LM_ERR("failed to parse message\n"); return -1; } anchor = anchor_lump(_m, _m->unparsed - _m->buf, 0, 0); - if (!anchor) { + if(!anchor) { LM_ERR("can't get anchor\n"); return -2; } - if (!insert_new_lump_before(anchor, _s->s, _s->len, 0)) { + if(!insert_new_lump_before(anchor, _s->s, _s->len, 0)) { LM_ERR("can't insert lump\n"); return -3; } @@ -134,24 +133,24 @@ static inline int append_rpid_helper(struct sip_msg* _m, str *_s) * \param _s2 unused * \return 1 on success, -1 on failure */ -int append_rpid_hf(struct sip_msg* _m, char* _s1, char* _s2) +int append_rpid_hf(struct sip_msg *_m, char *_s1, char *_s2) { struct usr_avp *avp; str rpid_hf, rpid; char *at; int_str val; - if (rpid_avp_name.n==0) { + if(rpid_avp_name.n == 0) { LM_ERR("rpid avp not defined\n"); return -1; } - if ( (avp=search_first_avp( rpid_avp_type , rpid_avp_name, &val, 0))==0 ) { + if((avp = search_first_avp(rpid_avp_type, rpid_avp_name, &val, 0)) == 0) { LM_DBG("no rpid AVP\n"); return -1; } - if ( !(avp->flags&AVP_VAL_STR) || !val.s.s || !val.s.len) { + if(!(avp->flags & AVP_VAL_STR) || !val.s.s || !val.s.len) { LM_DBG("empty or non-string rpid, nothing to append\n"); return -1; } @@ -159,9 +158,9 @@ int append_rpid_hf(struct sip_msg* _m, char* _s1, char* _s2) rpid = val.s; rpid_hf.len = RPID_HF_NAME_LEN + rpid_prefix.len + rpid.len - + rpid_suffix.len + CRLF_LEN; + + rpid_suffix.len + CRLF_LEN; rpid_hf.s = pkg_malloc(rpid_hf.len); - if (!rpid_hf.s) { + if(!rpid_hf.s) { PKG_MEM_ERROR; return -1; } @@ -181,7 +180,7 @@ int append_rpid_hf(struct sip_msg* _m, char* _s1, char* _s2) memcpy(at, CRLF, CRLF_LEN); - if (append_rpid_helper(_m, &rpid_hf) < 0) { + if(append_rpid_helper(_m, &rpid_hf) < 0) { pkg_free(rpid_hf.s); return -1; } @@ -197,37 +196,37 @@ int append_rpid_hf(struct sip_msg* _m, char* _s1, char* _s2) * \param _suffix suffix * \return 1 on success, -1 on failure */ -int append_rpid_hf_p(struct sip_msg* _m, char* _prefix, char* _suffix) +int append_rpid_hf_p(struct sip_msg *_m, char *_prefix, char *_suffix) { struct usr_avp *avp; str rpid_hf, rpid; - char* at; - str* p, *s; + char *at; + str *p, *s; int_str val; - if (rpid_avp_name.n==0) { + if(rpid_avp_name.n == 0) { LM_ERR("rpid avp not defined\n"); return -1; } - if ( (avp=search_first_avp( rpid_avp_type , rpid_avp_name, &val, 0))==0 ) { + if((avp = search_first_avp(rpid_avp_type, rpid_avp_name, &val, 0)) == 0) { LM_DBG("no rpid AVP\n"); return -1; } - if ( !(avp->flags&AVP_VAL_STR) || !val.s.s || !val.s.len) { + if(!(avp->flags & AVP_VAL_STR) || !val.s.s || !val.s.len) { LM_DBG("empty or non-string rpid, nothing to append\n"); return -1; } rpid = val.s; - p = (str*)_prefix; - s = (str*)_suffix; + p = (str *)_prefix; + s = (str *)_suffix; rpid_hf.len = RPID_HF_NAME_LEN + p->len + rpid.len + s->len + CRLF_LEN; rpid_hf.s = pkg_malloc(rpid_hf.len); - if (!rpid_hf.s) { + if(!rpid_hf.s) { PKG_MEM_ERROR; return -1; } @@ -247,7 +246,7 @@ int append_rpid_hf_p(struct sip_msg* _m, char* _prefix, char* _suffix) memcpy(at, CRLF, CRLF_LEN); - if (append_rpid_helper(_m, &rpid_hf) < 0) { + if(append_rpid_helper(_m, &rpid_hf) < 0) { pkg_free(rpid_hf.s); return -1; } @@ -263,7 +262,7 @@ int append_rpid_hf_p(struct sip_msg* _m, char* _prefix, char* _suffix) * \param _s2 unused * \return 1 if the URI contains an E164 user part, -1 if not */ -int is_rpid_user_e164(struct sip_msg* _m, char* _s1, char* _s2) +int is_rpid_user_e164(struct sip_msg *_m, char *_s1, char *_s2) { struct usr_avp *avp; name_addr_t parsed; @@ -271,25 +270,25 @@ int is_rpid_user_e164(struct sip_msg* _m, char* _s1, char* _s2) struct sip_uri uri; int_str val; - if (rpid_avp_name.n==0) { + if(rpid_avp_name.n == 0) { LM_ERR("rpid avp not defined\n"); return -1; } - if ( (avp=search_first_avp( rpid_avp_type , rpid_avp_name, &val, 0))==0 ) { + if((avp = search_first_avp(rpid_avp_type, rpid_avp_name, &val, 0)) == 0) { LM_DBG("no rpid AVP\n"); goto err; } - if ( !(avp->flags&AVP_VAL_STR) || !val.s.s || !val.s.len) { + if(!(avp->flags & AVP_VAL_STR) || !val.s.s || !val.s.len) { LM_DBG("empty or non-string rpid, nothing to append\n"); return -1; } rpid = val.s; - if (find_not_quoted(&rpid, '<')) { - if (parse_nameaddr(&rpid, &parsed) < 0) { + if(find_not_quoted(&rpid, '<')) { + if(parse_nameaddr(&rpid, &parsed) < 0) { LM_ERR("failed to parse RPID\n"); goto err; } @@ -298,7 +297,7 @@ int is_rpid_user_e164(struct sip_msg* _m, char* _s1, char* _s2) tmp = rpid; } - if (parse_uri(tmp.s, tmp.len, &uri) < 0) { + if(parse_uri(tmp.s, tmp.len, &uri) < 0) { LM_ERR("failed to parse RPID URI\n"); goto err; } @@ -308,4 +307,3 @@ int is_rpid_user_e164(struct sip_msg* _m, char* _s1, char* _s2) err: return -1; } - diff --git a/src/modules/siputils/rpid.h b/src/modules/siputils/rpid.h index 0c9ad53c481..70c83b7ad36 100644 --- a/src/modules/siputils/rpid.h +++ b/src/modules/siputils/rpid.h @@ -47,7 +47,7 @@ int init_rpid_avp(char *rpid_avp_param); * \param rpid_avp_p AVP name * \param rpid_avp_type_p AVP type */ -void get_rpid_avp( int_str *rpid_avp_p, int *rpid_avp_type_p ); +void get_rpid_avp(int_str *rpid_avp_p, int *rpid_avp_type_p); /*! @@ -57,7 +57,7 @@ void get_rpid_avp( int_str *rpid_avp_p, int *rpid_avp_type_p ); * \param _s2 unused * \return 1 on success, -1 on failure */ -int append_rpid_hf(struct sip_msg* _m, char* _s1, char* _s2); +int append_rpid_hf(struct sip_msg *_m, char *_s1, char *_s2); /*! @@ -67,7 +67,7 @@ int append_rpid_hf(struct sip_msg* _m, char* _s1, char* _s2); * \param _suffix suffix * \return 1 on success, -1 on failure */ -int append_rpid_hf_p(struct sip_msg* _m, char* _prefix, char* _suffix); +int append_rpid_hf_p(struct sip_msg *_m, char *_prefix, char *_suffix); /*! @@ -77,7 +77,7 @@ int append_rpid_hf_p(struct sip_msg* _m, char* _prefix, char* _suffix); * \param _s2 unused * \return 1 if the URI contains an E164 user part, -1 if not */ -int is_rpid_user_e164(struct sip_msg* _m, char* _s1, char* _s2); +int is_rpid_user_e164(struct sip_msg *_m, char *_s1, char *_s2); #endif diff --git a/src/modules/siputils/sipops.c b/src/modules/siputils/sipops.c index 5aba445b022..cf879948af3 100644 --- a/src/modules/siputils/sipops.c +++ b/src/modules/siputils/sipops.c @@ -45,9 +45,9 @@ int ki_cmp_uri(sip_msg_t *msg, str *uri1, str *uri2) int ret; ret = cmp_uri_str(uri1, uri2); - if(ret==0) + if(ret == 0) return 1; - if(ret>0) + if(ret > 0) return -1; return -2; } @@ -58,20 +58,18 @@ int w_cmp_uri(struct sip_msg *msg, char *uri1, char *uri2) str s2; int ret; - if(fixup_get_svalue(msg, (gparam_p)uri1, &s1)!=0) - { + if(fixup_get_svalue(msg, (gparam_p)uri1, &s1) != 0) { LM_ERR("cannot get first parameter\n"); return -8; } - if(fixup_get_svalue(msg, (gparam_p)uri2, &s2)!=0) - { + if(fixup_get_svalue(msg, (gparam_p)uri2, &s2) != 0) { LM_ERR("cannot get second parameter\n"); return -8; } ret = cmp_uri_str(&s1, &s2); - if(ret==0) + if(ret == 0) return 1; - if(ret>0) + if(ret > 0) return -1; return -2; } @@ -81,9 +79,9 @@ int ki_cmp_aor(sip_msg_t *msg, str *uri1, str *uri2) int ret; ret = cmp_aor_str(uri1, uri2); - if(ret==0) + if(ret == 0) return 1; - if(ret>0) + if(ret > 0) return -1; return -2; } @@ -94,20 +92,18 @@ int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2) str s2; int ret; - if(fixup_get_svalue(msg, (gparam_p)uri1, &s1)!=0) - { + if(fixup_get_svalue(msg, (gparam_p)uri1, &s1) != 0) { LM_ERR("cannot get first parameter\n"); return -8; } - if(fixup_get_svalue(msg, (gparam_p)uri2, &s2)!=0) - { + if(fixup_get_svalue(msg, (gparam_p)uri2, &s2) != 0) { LM_ERR("cannot get second parameter\n"); return -8; } ret = cmp_aor_str(&s1, &s2); - if(ret==0) + if(ret == 0) return 1; - if(ret>0) + if(ret > 0) return -1; return -2; } @@ -117,9 +113,9 @@ int ki_cmp_hdr_name(sip_msg_t *msg, str *shname1, str *shname2) int ret; ret = cmp_hdrname_str(shname1, shname2); - if(ret==0) + if(ret == 0) return 1; - if(ret>0) + if(ret > 0) return -1; return -2; } @@ -129,11 +125,11 @@ int w_cmp_hdr_name(sip_msg_t *msg, char *hname1, char *hname2) str shname1; str shname2; - if(fixup_get_svalue(msg, (gparam_p)hname1, &shname1)!=0) { + if(fixup_get_svalue(msg, (gparam_p)hname1, &shname1) != 0) { LM_ERR("cannot get first parameter\n"); return -8; } - if(fixup_get_svalue(msg, (gparam_p)hname2, &shname2)!=0) { + if(fixup_get_svalue(msg, (gparam_p)hname2, &shname2) != 0) { LM_ERR("cannot get second parameter\n"); return -8; } @@ -146,29 +142,26 @@ int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2) sip_uri_t turi; sip_uri_t *puri; - if(uri1!=NULL) - { - if(fixup_get_svalue(msg, (gparam_p)uri1, &s1)!=0) - { + if(uri1 != NULL) { + if(fixup_get_svalue(msg, (gparam_p)uri1, &s1) != 0) { LM_ERR("cannot get first parameter\n"); return -8; } - if(parse_uri(s1.s, s1.len, &turi)!=0) { + if(parse_uri(s1.s, s1.len, &turi) != 0) { LM_ERR("parsing of uri '%.*s' failed\n", s1.len, s1.s); return -1; } puri = &turi; } else { - if(parse_sip_msg_uri(msg)<0) { + if(parse_sip_msg_uri(msg) < 0) { s2 = GET_RURI(msg); LM_ERR("parsing of uri '%.*s' failed\n", s2->len, s2->s); return -1; } puri = &msg->parsed_uri; } - if(puri->gr.s!=NULL) - { - if(puri->gr_val.len>0) + if(puri->gr.s != NULL) { + if(puri->gr_val.len > 0) return 1; return 2; } @@ -181,11 +174,12 @@ int w_is_supported(sip_msg_t *msg, char *_option, char *p2) option = (unsigned long)_option; - if (parse_supported(msg) < 0) + if(parse_supported(msg) < 0) return -1; - if ((((struct option_tag_body*)msg->supported->parsed)->option_tags_all & - option) == 0) + if((((struct option_tag_body *)msg->supported->parsed)->option_tags_all + & option) + == 0) return -1; else return 1; @@ -195,17 +189,16 @@ int w_is_supported(sip_msg_t *msg, char *_option, char *p2) int is_first_hop_mode(sip_msg_t *msg, int mode) { int ret; - rr_t* r = NULL; + rr_t *r = NULL; sip_uri_t puri; struct ip_addr *ip = NULL; - if(msg==NULL) + if(msg == NULL) return -1; if(msg->first_line.type == SIP_REQUEST) { - if (parse_headers( msg, HDR_VIA2_F, 0 )<0 - || (msg->via2==0) || (msg->via2->error!=PARSE_OK)) - { + if(parse_headers(msg, HDR_VIA2_F, 0) < 0 || (msg->via2 == 0) + || (msg->via2->error != PARSE_OK)) { /* sip request: if more than one via, then not first hop */ /* no second via or error */ LM_DBG("no 2nd via found - first hop\n"); @@ -215,42 +208,44 @@ int is_first_hop_mode(sip_msg_t *msg, int mode) } else if(msg->first_line.type == SIP_REPLY) { /* sip reply: if top record-route is myself * and not received from myself (loop), then is first hop */ - if (parse_headers( msg, HDR_EOH_F, 0 )<0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_DBG("error parsing headers\n"); return -1; } - if(msg->record_route==NULL) { + if(msg->record_route == NULL) { LM_DBG("no record-route header - first hop\n"); return 1; } - if(parse_rr(msg->record_route)<0) { + if(parse_rr(msg->record_route) < 0) { LM_DBG("failed to parse first record-route header\n"); return -1; } - r = (rr_t*)msg->record_route->parsed; - if(parse_uri(r->nameaddr.uri.s, r->nameaddr.uri.len, &puri)<0) { + r = (rr_t *)msg->record_route->parsed; + if(parse_uri(r->nameaddr.uri.s, r->nameaddr.uri.len, &puri) < 0) { LM_DBG("failed to parse uri in first record-route header\n"); return -1; } - if(mode==0) { - if (((ip = str2ip(&(puri.host))) == NULL) + if(mode == 0) { + if(((ip = str2ip(&(puri.host))) == NULL) && ((ip = str2ip6(&(puri.host))) == NULL)) { LM_DBG("uri host is not an ip address\n"); return -1; } } - ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0, - (puri.transport_val.s)?puri.proto:0); - if(ret!=1) { + ret = check_self(&puri.host, (puri.port.s) ? puri.port_no : 0, + (puri.transport_val.s) ? puri.proto : 0); + if(ret != 1) { LM_DBG("top record route uri is not myself\n"); return -1; } - if(mode==0) { - if (ip_addr_cmp(ip, &(msg->rcv.src_ip)) + if(mode == 0) { + if(ip_addr_cmp(ip, &(msg->rcv.src_ip)) && ((msg->rcv.src_port == puri.port_no) - || ((puri.port.len == 0) && (msg->rcv.src_port == 5060))) - && (puri.proto==msg->rcv.proto - || (puri.proto==0 && msg->rcv.proto==PROTO_UDP)) ) { + || ((puri.port.len == 0) + && (msg->rcv.src_port == 5060))) + && (puri.proto == msg->rcv.proto + || (puri.proto == 0 + && msg->rcv.proto == PROTO_UDP))) { LM_DBG("source address matches top record route uri - loop\n"); return -1; } @@ -266,7 +261,7 @@ int w_is_first_hop_mode(sip_msg_t *msg, char *p1mode, char *p2) { int mode = 0; - if(fixup_get_ivalue(msg, (gparam_t*)p1mode, &mode)<0) { + if(fixup_get_ivalue(msg, (gparam_t *)p1mode, &mode) < 0) { LM_ERR("failed to get mode parameter\n"); return -1; } diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c index 099248555ec..56232e0d837 100644 --- a/src/modules/siputils/siputils.c +++ b/src/modules/siputils/siputils.c @@ -87,7 +87,7 @@ str rpid_prefix = {DEF_RPID_PREFIX, sizeof(DEF_RPID_PREFIX) - 1}; /*! Default Remote-Party-IDD suffix */ str rpid_suffix = {DEF_RPID_SUFFIX, sizeof(DEF_RPID_SUFFIX) - 1}; /*! Definition of AVP containing rpid value */ -char* rpid_avp_param = DEF_RPID_AVP; +char *rpid_avp_param = DEF_RPID_AVP; /* max length for e164 number including the leading '+' */ int e164_max_len = 16; @@ -111,156 +111,146 @@ static int w_contact_param_rm(sip_msg_t *msg, char *pnparam, char *p2); static int w_hdr_date_check(sip_msg_t *msg, char *ptdiff, char *p2); /* Fixup functions to be defined later */ -static int fixup_set_uri(void** param, int param_no); -static int fixup_free_set_uri(void** param, int param_no); -static int fixup_tel2sip(void** param, int param_no); -static int fixup_get_uri_param(void** param, int param_no); -static int free_fixup_get_uri_param(void** param, int param_no); -static int fixup_option(void** param, int param_no); +static int fixup_set_uri(void **param, int param_no); +static int fixup_free_set_uri(void **param, int param_no); +static int fixup_tel2sip(void **param, int param_no); +static int fixup_get_uri_param(void **param, int param_no); +static int free_fixup_get_uri_param(void **param, int param_no); +static int fixup_option(void **param, int param_no); static int ki_is_gruu(sip_msg_t *msg); char *contact_flds_separator = DEFAULT_SEPARATOR; -static cmd_export_t cmds[]={ - {"options_reply", (cmd_function)opt_reply, 0, 0, - 0, REQUEST_ROUTE}, - {"is_user", (cmd_function)is_user, 1, fixup_spve_null, - 0, REQUEST_ROUTE|LOCAL_ROUTE}, - {"has_totag", (cmd_function)w_has_totag, 0, 0, - 0, ANY_ROUTE}, - {"uri_param", (cmd_function)uri_param_1, 1, fixup_spve_null, - 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, - {"uri_param", (cmd_function)uri_param_2, 2, fixup_spve_spve, - 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, - {"uri_param_any", (cmd_function)w_uri_param_any, 1, fixup_spve_null, - 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, - {"add_uri_param", (cmd_function)add_uri_param, 1, fixup_str_null, - 0, REQUEST_ROUTE}, - {"get_uri_param", (cmd_function)get_uri_param, 2, fixup_get_uri_param, - free_fixup_get_uri_param, REQUEST_ROUTE|LOCAL_ROUTE}, - {"uri_param_rm", (cmd_function)w_uri_param_rm, 1, fixup_spve_null, - 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, - {"tel2sip", (cmd_function)tel2sip, 3, fixup_tel2sip, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE}, - {"is_uri", (cmd_function)is_uri, 1, fixup_spve_null, - fixup_free_spve_null, ANY_ROUTE}, - {"is_e164", (cmd_function)w_is_e164, 1, fixup_pvar_null, - fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE}, - {"is_uri_user_e164", (cmd_function)w_is_uri_user_e164, 1, fixup_pvar_null, - fixup_free_pvar_null, ANY_ROUTE}, - {"encode_contact", (cmd_function)encode_contact, 2, 0, - 0, REQUEST_ROUTE|ONREPLY_ROUTE}, - {"decode_contact", (cmd_function)decode_contact, 0, 0, - 0, REQUEST_ROUTE}, - {"decode_contact_header", (cmd_function)decode_contact_header, 0, 0, - 0,REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE}, - {"cmp_uri", (cmd_function)w_cmp_uri, 2, fixup_spve_spve, - 0, ANY_ROUTE}, - {"cmp_aor", (cmd_function)w_cmp_aor, 2, fixup_spve_spve, - 0, ANY_ROUTE}, - {"cmp_hdr_name", (cmd_function)w_cmp_hdr_name, 2, fixup_spve_spve, - 0, ANY_ROUTE}, - {"is_rpid_user_e164", (cmd_function)is_rpid_user_e164, 0, 0, - 0, REQUEST_ROUTE}, - {"append_rpid_hf", (cmd_function)append_rpid_hf, 0, 0, - 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, - {"append_rpid_hf", (cmd_function)append_rpid_hf_p, 2, fixup_str_str, - 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, - {"set_uri_user", (cmd_function)set_uri_user, 2, fixup_set_uri, - fixup_free_set_uri, ANY_ROUTE}, - {"set_uri_host", (cmd_function)set_uri_host, 2, fixup_set_uri, - fixup_free_set_uri, ANY_ROUTE}, - {"is_request", (cmd_function)w_is_request, 0, 0, - 0, ANY_ROUTE}, - {"is_reply", (cmd_function)w_is_reply, 0, 0, - 0, ANY_ROUTE}, - {"is_gruu", (cmd_function)w_is_gruu, 0, 0, - 0, ANY_ROUTE}, - {"is_gruu", (cmd_function)w_is_gruu, 1, fixup_spve_null, - 0, ANY_ROUTE}, - {"is_supported", (cmd_function)w_is_supported, 1, fixup_option, - 0, ANY_ROUTE}, - {"is_first_hop", (cmd_function)w_is_first_hop, 0, 0, - 0, ANY_ROUTE}, - {"is_first_hop", (cmd_function)w_is_first_hop, 1, fixup_igp_null, - fixup_free_igp_null, ANY_ROUTE}, - {"is_tel_number", (cmd_function)is_tel_number, 1, fixup_spve_null, - 0, ANY_ROUTE}, - {"is_numeric", (cmd_function)is_numeric, 1, fixup_spve_null, - 0, ANY_ROUTE}, - {"is_alphanum", (cmd_function)ksr_is_alphanum, 1, fixup_spve_null, - 0, ANY_ROUTE}, - {"is_alphanumex", (cmd_function)ksr_is_alphanumex, 2, fixup_spve_spve, - 0, ANY_ROUTE}, - {"sip_p_charging_vector", (cmd_function)sip_handle_pcv, 1, fixup_spve_null, - fixup_free_spve_null, ANY_ROUTE}, - {"contact_param_encode", (cmd_function)w_contact_param_encode, 2, - fixup_spve_spve, fixup_free_spve_spve, REQUEST_ROUTE|ONREPLY_ROUTE}, - {"contact_param_decode", (cmd_function)w_contact_param_decode, 1, - fixup_spve_null, fixup_free_spve_null, REQUEST_ROUTE|ONREPLY_ROUTE}, - {"contact_param_decode_ruri", (cmd_function)w_contact_param_decode_ruri, 1, - fixup_spve_null, fixup_free_spve_null, REQUEST_ROUTE}, - {"contact_param_rm", (cmd_function)w_contact_param_rm, 1, - fixup_spve_null, fixup_free_spve_null, REQUEST_ROUTE|ONREPLY_ROUTE}, - {"hdr_date_check", (cmd_function)w_hdr_date_check, 1, fixup_igp_null, - fixup_free_igp_null, ANY_ROUTE}, - - {"bind_siputils", (cmd_function)bind_siputils, 1, 0, - 0, 0}, - - {0,0,0,0,0,0} -}; - -static param_export_t params[] = { - {"options_accept", PARAM_STR, &opt_accept}, - {"options_accept_encoding", PARAM_STR, &opt_accept_enc}, - {"options_accept_language", PARAM_STR, &opt_accept_lang}, - {"options_support", PARAM_STR, &opt_supported}, - {"contact_flds_separator", PARAM_STRING, &contact_flds_separator}, - {"rpid_prefix", PARAM_STR, &rpid_prefix }, - {"rpid_suffix", PARAM_STR, &rpid_suffix }, - {"rpid_avp", PARAM_STRING, &rpid_avp_param }, - {"e164_max_len", PARAM_INT, &e164_max_len }, - {0, 0, 0} -}; - - -static pv_export_t mod_pvs[] = { - { {"pcv", (sizeof("pcv")-1)}, PVT_OTHER, pv_get_charging_vector, - 0, pv_parse_charging_vector_name, 0, 0, 0}, - - { {0, 0}, 0, 0, 0, 0, 0, 0, 0 } -}; - -struct module_exports exports= { - "siputils", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* exported functions */ - params, /* param exports */ - 0, /* exported RPC functions */ - mod_pvs, /* exported pseudo-variables */ - 0, /* response function */ - mod_init, /* initialization function */ - 0, /* child init function */ - mod_destroy /* destroy function */ +static cmd_export_t cmds[] = { + {"options_reply", (cmd_function)opt_reply, 0, 0, 0, REQUEST_ROUTE}, + {"is_user", (cmd_function)is_user, 1, fixup_spve_null, 0, + REQUEST_ROUTE | LOCAL_ROUTE}, + {"has_totag", (cmd_function)w_has_totag, 0, 0, 0, ANY_ROUTE}, + {"uri_param", (cmd_function)uri_param_1, 1, fixup_spve_null, 0, + REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE}, + {"uri_param", (cmd_function)uri_param_2, 2, fixup_spve_spve, 0, + REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE}, + {"uri_param_any", (cmd_function)w_uri_param_any, 1, fixup_spve_null, 0, + REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE}, + {"add_uri_param", (cmd_function)add_uri_param, 1, fixup_str_null, 0, + REQUEST_ROUTE}, + {"get_uri_param", (cmd_function)get_uri_param, 2, fixup_get_uri_param, + free_fixup_get_uri_param, REQUEST_ROUTE | LOCAL_ROUTE}, + {"uri_param_rm", (cmd_function)w_uri_param_rm, 1, fixup_spve_null, 0, + REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE}, + {"tel2sip", (cmd_function)tel2sip, 3, fixup_tel2sip, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE}, + {"is_uri", (cmd_function)is_uri, 1, fixup_spve_null, + fixup_free_spve_null, ANY_ROUTE}, + {"is_e164", (cmd_function)w_is_e164, 1, fixup_pvar_null, + fixup_free_pvar_null, + REQUEST_ROUTE | FAILURE_ROUTE | LOCAL_ROUTE}, + {"is_uri_user_e164", (cmd_function)w_is_uri_user_e164, 1, + fixup_pvar_null, fixup_free_pvar_null, ANY_ROUTE}, + {"encode_contact", (cmd_function)encode_contact, 2, 0, 0, + REQUEST_ROUTE | ONREPLY_ROUTE}, + {"decode_contact", (cmd_function)decode_contact, 0, 0, 0, + REQUEST_ROUTE}, + {"decode_contact_header", (cmd_function)decode_contact_header, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, + {"cmp_uri", (cmd_function)w_cmp_uri, 2, fixup_spve_spve, 0, ANY_ROUTE}, + {"cmp_aor", (cmd_function)w_cmp_aor, 2, fixup_spve_spve, 0, ANY_ROUTE}, + {"cmp_hdr_name", (cmd_function)w_cmp_hdr_name, 2, fixup_spve_spve, 0, + ANY_ROUTE}, + {"is_rpid_user_e164", (cmd_function)is_rpid_user_e164, 0, 0, 0, + REQUEST_ROUTE}, + {"append_rpid_hf", (cmd_function)append_rpid_hf, 0, 0, 0, + REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE}, + {"append_rpid_hf", (cmd_function)append_rpid_hf_p, 2, fixup_str_str, 0, + REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE}, + {"set_uri_user", (cmd_function)set_uri_user, 2, fixup_set_uri, + fixup_free_set_uri, ANY_ROUTE}, + {"set_uri_host", (cmd_function)set_uri_host, 2, fixup_set_uri, + fixup_free_set_uri, ANY_ROUTE}, + {"is_request", (cmd_function)w_is_request, 0, 0, 0, ANY_ROUTE}, + {"is_reply", (cmd_function)w_is_reply, 0, 0, 0, ANY_ROUTE}, + {"is_gruu", (cmd_function)w_is_gruu, 0, 0, 0, ANY_ROUTE}, + {"is_gruu", (cmd_function)w_is_gruu, 1, fixup_spve_null, 0, ANY_ROUTE}, + {"is_supported", (cmd_function)w_is_supported, 1, fixup_option, 0, + ANY_ROUTE}, + {"is_first_hop", (cmd_function)w_is_first_hop, 0, 0, 0, ANY_ROUTE}, + {"is_first_hop", (cmd_function)w_is_first_hop, 1, fixup_igp_null, + fixup_free_igp_null, ANY_ROUTE}, + {"is_tel_number", (cmd_function)is_tel_number, 1, fixup_spve_null, 0, + ANY_ROUTE}, + {"is_numeric", (cmd_function)is_numeric, 1, fixup_spve_null, 0, + ANY_ROUTE}, + {"is_alphanum", (cmd_function)ksr_is_alphanum, 1, fixup_spve_null, 0, + ANY_ROUTE}, + {"is_alphanumex", (cmd_function)ksr_is_alphanumex, 2, fixup_spve_spve, + 0, ANY_ROUTE}, + {"sip_p_charging_vector", (cmd_function)sip_handle_pcv, 1, + fixup_spve_null, fixup_free_spve_null, ANY_ROUTE}, + {"contact_param_encode", (cmd_function)w_contact_param_encode, 2, + fixup_spve_spve, fixup_free_spve_spve, + REQUEST_ROUTE | ONREPLY_ROUTE}, + {"contact_param_decode", (cmd_function)w_contact_param_decode, 1, + fixup_spve_null, fixup_free_spve_null, + REQUEST_ROUTE | ONREPLY_ROUTE}, + {"contact_param_decode_ruri", (cmd_function)w_contact_param_decode_ruri, + 1, fixup_spve_null, fixup_free_spve_null, REQUEST_ROUTE}, + {"contact_param_rm", (cmd_function)w_contact_param_rm, 1, + fixup_spve_null, fixup_free_spve_null, + REQUEST_ROUTE | ONREPLY_ROUTE}, + {"hdr_date_check", (cmd_function)w_hdr_date_check, 1, fixup_igp_null, + fixup_free_igp_null, ANY_ROUTE}, + + {"bind_siputils", (cmd_function)bind_siputils, 1, 0, 0, 0}, + + {0, 0, 0, 0, 0, 0}}; + +static param_export_t params[] = {{"options_accept", PARAM_STR, &opt_accept}, + {"options_accept_encoding", PARAM_STR, &opt_accept_enc}, + {"options_accept_language", PARAM_STR, &opt_accept_lang}, + {"options_support", PARAM_STR, &opt_supported}, + {"contact_flds_separator", PARAM_STRING, &contact_flds_separator}, + {"rpid_prefix", PARAM_STR, &rpid_prefix}, + {"rpid_suffix", PARAM_STR, &rpid_suffix}, + {"rpid_avp", PARAM_STRING, &rpid_avp_param}, + {"e164_max_len", PARAM_INT, &e164_max_len}, {0, 0, 0}}; + + +static pv_export_t mod_pvs[] = { + {{"pcv", (sizeof("pcv") - 1)}, PVT_OTHER, pv_get_charging_vector, 0, + pv_parse_charging_vector_name, 0, 0, 0}, + + {{0, 0}, 0, 0, 0, 0, 0, 0, 0}}; + +struct module_exports exports = { + "siputils", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* exported functions */ + params, /* param exports */ + 0, /* exported RPC functions */ + mod_pvs, /* exported pseudo-variables */ + 0, /* response function */ + mod_init, /* initialization function */ + 0, /* child init function */ + mod_destroy /* destroy function */ }; static int mod_init(void) { /* bind the SL API */ - if (sl_load_api(&opt_slb)!=0) { + if(sl_load_api(&opt_slb) != 0) { LM_ERR("cannot bind to SL API\n"); return -1; } - if ( init_rpid_avp(rpid_avp_param)<0 ) { + if(init_rpid_avp(rpid_avp_param) < 0) { LM_ERR("failed to init rpid AVP name\n"); return -1; } - if(cfg_declare("siputils", siputils_cfg_def, &default_siputils_cfg, cfg_sizeof(siputils), &siputils_cfg)){ + if(cfg_declare("siputils", siputils_cfg_def, &default_siputils_cfg, + cfg_sizeof(siputils), &siputils_cfg)) { LM_ERR("Fail to declare the configuration\n"); return -1; } @@ -271,7 +261,6 @@ static int mod_init(void) static void mod_destroy(void) { - } @@ -280,14 +269,14 @@ static void mod_destroy(void) * \param api binded API * \return 0 on success, -1 on failure */ -int bind_siputils(siputils_api_t* api) +int bind_siputils(siputils_api_t *api) { - if (!api) { + if(!api) { LM_ERR("invalid parameter value\n"); return -1; } - get_rpid_avp( &api->rpid_avp, &api->rpid_avp_type ); + get_rpid_avp(&api->rpid_avp, &api->rpid_avp_type); api->has_totag = w_has_totag; api->is_uri_user_e164 = is_uri_user_e164; @@ -297,21 +286,21 @@ int bind_siputils(siputils_api_t* api) /* * Fix set_uri_* function params: uri (writable pvar) and value (pvar) */ -static int fixup_set_uri(void** param, int param_no) +static int fixup_set_uri(void **param, int param_no) { - if (param_no == 1) { - if (fixup_pvar_null(param, 1) != 0) { + if(param_no == 1) { + if(fixup_pvar_null(param, 1) != 0) { LM_ERR("failed to fixup uri pvar\n"); return -1; } - if (((pv_spec_t *)(*param))->setf == NULL) { + if(((pv_spec_t *)(*param))->setf == NULL) { LM_ERR("uri pvar is not writeble\n"); return -1; } return 0; } - if (param_no == 2) { + if(param_no == 2) { return fixup_pvar_null(param, 1); } @@ -322,7 +311,7 @@ static int fixup_set_uri(void** param, int param_no) /* * Free set_uri_* params. */ -static int fixup_free_set_uri(void** param, int param_no) +static int fixup_free_set_uri(void **param, int param_no) { return fixup_free_pvar_null(param, 1); } @@ -332,22 +321,22 @@ static int fixup_free_set_uri(void** param, int param_no) * Fix tel2sip function params: uri and hostpart pvars and * result writable pvar. */ -static int fixup_tel2sip(void** param, int param_no) +static int fixup_tel2sip(void **param, int param_no) { - if ((param_no == 1) || (param_no == 2)) { - if (fixup_var_str_12(param, 1) < 0) { + if((param_no == 1) || (param_no == 2)) { + if(fixup_var_str_12(param, 1) < 0) { LM_ERR("failed to fixup uri or hostpart pvar\n"); return -1; } return 0; } - if (param_no == 3) { - if (fixup_pvar_null(param, 1) != 0) { + if(param_no == 3) { + if(fixup_pvar_null(param, 1) != 0) { LM_ERR("failed to fixup result pvar\n"); return -1; } - if (((pv_spec_t *)(*param))->setf == NULL) { + if(((pv_spec_t *)(*param))->setf == NULL) { LM_ERR("result pvar is not writeble\n"); return -1; } @@ -359,16 +348,17 @@ static int fixup_tel2sip(void** param, int param_no) } /* */ -static int fixup_get_uri_param(void** param, int param_no) { - if (param_no == 1) { +static int fixup_get_uri_param(void **param, int param_no) +{ + if(param_no == 1) { return fixup_str_null(param, 1); } - if (param_no == 2) { - if (fixup_pvar_null(param, 1) != 0) { + if(param_no == 2) { + if(fixup_pvar_null(param, 1) != 0) { LM_ERR("failed to fixup result pvar\n"); return -1; } - if (((pv_spec_t *)(*param))->setf == NULL) { + if(((pv_spec_t *)(*param))->setf == NULL) { LM_ERR("result pvar is not writeble\n"); return -1; } @@ -380,12 +370,13 @@ static int fixup_get_uri_param(void** param, int param_no) { } /* */ -static int free_fixup_get_uri_param(void** param, int param_no) { - if (param_no == 1) { +static int free_fixup_get_uri_param(void **param, int param_no) +{ + if(param_no == 1) { LM_WARN("free function has not been defined for spve\n"); return 0; } - if (param_no == 2) { + if(param_no == 2) { return fixup_free_pvar_null(param, 1); } LM_ERR("invalid parameter number <%d>\n", param_no); @@ -393,7 +384,8 @@ static int free_fixup_get_uri_param(void** param, int param_no) { } /* */ -static int fixup_option(void** param, int param_no) { +static int fixup_option(void **param, int param_no) +{ char *option; unsigned int option_len, res; @@ -401,16 +393,16 @@ static int fixup_option(void** param, int param_no) { option = (char *)*param; option_len = strlen(option); - if (param_no != 1) { + if(param_no != 1) { LM_ERR("invalid parameter number <%d>\n", param_no); return -1; } - switch (option_len) { + switch(option_len) { case 4: - if (strncasecmp(option, "path", 4) == 0) + if(strncasecmp(option, "path", 4) == 0) res = F_OPTION_TAG_PATH; - else if (strncasecmp(option, "gruu", 4) == 0) + else if(strncasecmp(option, "gruu", 4) == 0) res = F_OPTION_TAG_GRUU; else { LM_ERR("unknown option <%s>\n", option); @@ -418,7 +410,7 @@ static int fixup_option(void** param, int param_no) { } break; case 5: - if (strncasecmp(option, "timer", 5) == 0) + if(strncasecmp(option, "timer", 5) == 0) res = F_OPTION_TAG_TIMER; else { LM_ERR("unknown option <%s>\n", option); @@ -426,7 +418,7 @@ static int fixup_option(void** param, int param_no) { } break; case 6: - if (strncasecmp(option, "100rel", 6) == 0) + if(strncasecmp(option, "100rel", 6) == 0) res = F_OPTION_TAG_100REL; else { LM_ERR("unknown option <%s>\n", option); @@ -434,7 +426,7 @@ static int fixup_option(void** param, int param_no) { } break; case 8: - if (strncasecmp(option, "outbound", 8) == 0) + if(strncasecmp(option, "outbound", 8) == 0) res = F_OPTION_TAG_OUTBOUND; else { LM_ERR("unknown option <%s>\n", option); @@ -442,7 +434,7 @@ static int fixup_option(void** param, int param_no) { } break; case 9: - if (strncasecmp(option, "eventlist", 9) == 0) + if(strncasecmp(option, "eventlist", 9) == 0) res = F_OPTION_TAG_EVENTLIST; else { LM_ERR("unknown option <%s>\n", option); @@ -463,12 +455,12 @@ static int w_contact_param_encode(sip_msg_t *msg, char *pnparam, char *psaddr) str nparam = STR_NULL; str saddr = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pnparam, &nparam)<0) { + if(fixup_get_svalue(msg, (gparam_t *)pnparam, &nparam) < 0) { LM_ERR("failed to get p1\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)psaddr, &saddr)<0) { + if(fixup_get_svalue(msg, (gparam_t *)psaddr, &saddr) < 0) { LM_ERR("failed to get p1\n"); return -1; } @@ -479,7 +471,7 @@ static int w_contact_param_decode(sip_msg_t *msg, char *pnparam, char *p2) { str nparam = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pnparam, &nparam)<0) { + if(fixup_get_svalue(msg, (gparam_t *)pnparam, &nparam) < 0) { LM_ERR("failed to get p1\n"); return -1; } @@ -491,7 +483,7 @@ static int w_contact_param_decode_ruri(sip_msg_t *msg, char *pnparam, char *p3) { str nparam = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pnparam, &nparam)<0) { + if(fixup_get_svalue(msg, (gparam_t *)pnparam, &nparam) < 0) { LM_ERR("failed to get p1\n"); return -1; } @@ -503,7 +495,7 @@ static int w_contact_param_rm(sip_msg_t *msg, char *pnparam, char *p2) { str nparam = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pnparam, &nparam)<0) { + if(fixup_get_svalue(msg, (gparam_t *)pnparam, &nparam) < 0) { LM_ERR("failed to get p1\n"); return -1; } @@ -514,14 +506,14 @@ static int w_contact_param_rm(sip_msg_t *msg, char *pnparam, char *p2) /* * Check if pseudo variable contains a valid uri */ -static int ki_is_uri(sip_msg_t* msg, str* suri) +static int ki_is_uri(sip_msg_t *msg, str *suri) { sip_uri_t turi; - if(suri==NULL || suri->s==NULL || suri->len<=0) { + if(suri == NULL || suri->s == NULL || suri->len <= 0) { return -1; } - if(parse_uri(suri->s, suri->len, &turi)!=0) { + if(parse_uri(suri->s, suri->len, &turi) != 0) { return -1; } return 1; @@ -530,47 +522,47 @@ static int ki_is_uri(sip_msg_t* msg, str* suri) /* * Check date header value with time difference */ -static int ki_hdr_date_check(sip_msg_t* msg, int tdiff) +static int ki_hdr_date_check(sip_msg_t *msg, int tdiff) { time_t tnow, tmsg; - if ((!msg->date) && (parse_headers(msg, HDR_DATE_F, 0) == -1)) { + if((!msg->date) && (parse_headers(msg, HDR_DATE_F, 0) == -1)) { LM_ERR("failed parsing Date header\n"); return -1; } - if (!msg->date) { + if(!msg->date) { LM_ERR("Date header field is not found\n"); return -1; } - if ((!(msg->date)->parsed) && (parse_date_header(msg) < 0)) { + if((!(msg->date)->parsed) && (parse_date_header(msg) < 0)) { LM_ERR("failed parsing DATE body\n"); return -1; } #ifdef HAVE_TIMEGM - tmsg=timegm(&get_date(msg)->date); + tmsg = timegm(&get_date(msg)->date); #else - tmsg=_timegm(&get_date(msg)->date); + tmsg = _timegm(&get_date(msg)->date); #endif - if (tmsg < 0) { + if(tmsg < 0) { LM_ERR("timegm error\n"); return -2; } - if ((tnow=time(0)) < 0) { + if((tnow = time(0)) < 0) { LM_ERR("time error %s\n", strerror(errno)); return -3; } - if (tnow > tmsg + tdiff) { - LM_ERR("outdated date header value (%" TIME_T_FMT " sec)\n", TIME_T_CAST(tnow - tmsg + tdiff)); + if(tnow > tmsg + tdiff) { + LM_ERR("outdated date header value (%" TIME_T_FMT " sec)\n", + TIME_T_CAST(tnow - tmsg + tdiff)); return -4; } else { LM_ERR("Date header value OK\n"); } return 1; - } /** @@ -580,7 +572,7 @@ static int w_hdr_date_check(sip_msg_t *msg, char *ptdiff, char *p2) { int tdiff = 0; - if(fixup_get_ivalue(msg, (gparam_t*)ptdiff, &tdiff)<0) { + if(fixup_get_ivalue(msg, (gparam_t *)ptdiff, &tdiff) < 0) { LM_ERR("failed to get time diff parameter\n"); return -1; } @@ -742,7 +734,8 @@ static sr_kemi_t sr_kemi_siputils_exports[] = { }; /* clang-format on */ -static int ki_is_gruu(sip_msg_t *msg) { +static int ki_is_gruu(sip_msg_t *msg) +{ return w_is_gruu(msg, NULL, NULL); } diff --git a/src/modules/siputils/siputils.h b/src/modules/siputils/siputils.h index e3af5cf8e3b..ad9957b30b8 100644 --- a/src/modules/siputils/siputils.h +++ b/src/modules/siputils/siputils.h @@ -23,31 +23,32 @@ #ifndef _SIPUTILS_H_ #define _SIPUTILS_H_ -typedef int (*siputils_has_totag_t)(struct sip_msg*, char*, char*); -typedef int (*siputils_is_uri_user_e164_t)(str*); +typedef int (*siputils_has_totag_t)(struct sip_msg *, char *, char *); +typedef int (*siputils_is_uri_user_e164_t)(str *); /*! Siputils module API */ -typedef struct siputils_api { - int_str rpid_avp; /*!< Name of AVP containing Remote-Party-ID */ - int rpid_avp_type; /*!< type of the RPID AVP */ +typedef struct siputils_api +{ + int_str rpid_avp; /*!< Name of AVP containing Remote-Party-ID */ + int rpid_avp_type; /*!< type of the RPID AVP */ siputils_has_totag_t has_totag; siputils_is_uri_user_e164_t is_uri_user_e164; } siputils_api_t; -typedef int (*bind_siputils_t)(siputils_api_t* api); +typedef int (*bind_siputils_t)(siputils_api_t *api); /*! * \brief Bind function for the SIPUtils API * \param api binded API * \return 0 on success, -1 on failure */ -int bind_siputils(siputils_api_t* api); +int bind_siputils(siputils_api_t *api); inline static int siputils_load_api(siputils_api_t *pxb) { bind_siputils_t bind_siputils_exports; - if (!(bind_siputils_exports = (bind_siputils_t)find_export("bind_siputils", 1, 0))) - { + if(!(bind_siputils_exports = + (bind_siputils_t)find_export("bind_siputils", 1, 0))) { LM_ERR("Failed to import bind_siputils\n"); return -1; } diff --git a/src/modules/siputils/utils.c b/src/modules/siputils/utils.c index e118203b8a1..3fad311b08b 100644 --- a/src/modules/siputils/utils.c +++ b/src/modules/siputils/utils.c @@ -32,35 +32,32 @@ #include "utils.h" -#include "../../core/parser/msg_parser.h" /* struct sip_msg */ +#include "../../core/parser/msg_parser.h" /* struct sip_msg */ #include "../../core/mem/mem.h" #include "../../core/data_lump.h" #include -int -patch (struct sip_msg *msg, char *oldstr, unsigned int oldlen, char *newstr, +int patch(struct sip_msg *msg, char *oldstr, unsigned int oldlen, char *newstr, unsigned int newlen) { int off; struct lump *anchor; - if (oldstr == NULL) + if(oldstr == NULL) return -1; - if (newstr == NULL) + if(newstr == NULL) return -2; off = oldstr - msg->buf; - if (off < 0) + if(off < 0) return -3; - if ((anchor = del_lump (msg, off, oldlen, 0)) == 0) - { + if((anchor = del_lump(msg, off, oldlen, 0)) == 0) { LM_ERR("lumping with del_lump\n"); return -4; } - if ((insert_new_lump_after (anchor, newstr, newlen, 0)) == 0) - { + if((insert_new_lump_after(anchor, newstr, newlen, 0)) == 0) { LM_ERR("lumping with insert_new_lump_after\n"); return -5; } @@ -70,8 +67,7 @@ patch (struct sip_msg *msg, char *oldstr, unsigned int oldlen, char *newstr, /* TESTED */ -int -patch_content_length (struct sip_msg *msg, unsigned int newValue) +int patch_content_length(struct sip_msg *msg, unsigned int newValue) { struct hdr_field *contentLength; @@ -79,41 +75,36 @@ patch_content_length (struct sip_msg *msg, unsigned int newValue) int len; contentLength = msg->content_length; - if (contentLength == NULL) /* maybe not yet parsed */ + if(contentLength == NULL) /* maybe not yet parsed */ { - if (parse_headers (msg, HDR_CONTENTLENGTH_F, 0) == -1) - { + if(parse_headers(msg, HDR_CONTENTLENGTH_F, 0) == -1) { LM_ERR("parse headers on Content-Length failed\n"); return -1; } contentLength = msg->content_length; - if (contentLength == NULL) - { + if(contentLength == NULL) { LM_ERR("failed to parse headers on Content-Length " - "succeeded but msg->content_length is still NULL\n"); + "succeeded but msg->content_length is still NULL\n"); return -2; } } /* perhaps dangerous because buffer is static ? */ //pos = int2str(newValue,&len); - len = snprintf ((char *) pos, 10, "%u", newValue); - s = pkg_malloc (len); - if (s == NULL) - { + len = snprintf((char *)pos, 10, "%u", newValue); + s = pkg_malloc(len); + if(s == NULL) { PKG_MEM_ERROR_FMT("missing %d bytes\n", len); return -3; } - memcpy (s, pos, len); + memcpy(s, pos, len); /* perhaps we made it and no one called int2str,might use sprintf */ - if (patch(msg, contentLength->body.s, contentLength->body.len, s, len)<0) - { - pkg_free (s); + if(patch(msg, contentLength->body.s, contentLength->body.len, s, len) < 0) { + pkg_free(s); LM_ERR("lumping failed\n"); return -4; } - LM_DBG ("succeeded in altering Content-Length to new value %u\n",newValue); + LM_DBG("succeeded in altering Content-Length to new value %u\n", newValue); return 0; - } diff --git a/src/modules/siputils/utils.h b/src/modules/siputils/utils.h index 4b991d2af8e..7f960ec1cf6 100644 --- a/src/modules/siputils/utils.h +++ b/src/modules/siputils/utils.h @@ -32,7 +32,7 @@ #ifndef UTILS_H #define UTILS_H -#include "../../core/parser/msg_parser.h" /* struct sip_msg */ +#include "../../core/parser/msg_parser.h" /* struct sip_msg */ /* replace a part of a sip message identified by (start address,length) with a new part @param msg a pointer to a sip message @@ -43,14 +43,14 @@ @return 0 in case of success, negative on error */ -int patch (struct sip_msg *msg, char *oldstr, unsigned int oldlen, - char *newstr, unsigned int newlen); +int patch(struct sip_msg *msg, char *oldstr, unsigned int oldlen, char *newstr, + unsigned int newlen); /* modify the Content-Length header of a sip message @param msg a pointer to a sip message @param newValue the new value of Content-Length @return 0 in case of success, negative on error */ -int patch_content_length (struct sip_msg *msg, unsigned int newValue); +int patch_content_length(struct sip_msg *msg, unsigned int newValue); #endif