diff --git a/src/modules/avpops/avpops.c b/src/modules/avpops/avpops.c index 1cd4c104eba..577a7d7fabe 100644 --- a/src/modules/avpops/avpops.c +++ b/src/modules/avpops/avpops.c @@ -43,132 +43,144 @@ MODULE_VERSION /* modules param variables */ -static str db_url = {NULL, 0}; /* database url */ -static str db_table = {NULL, 0}; /* table */ -static int use_domain = 0; /* if domain should be use for avp matching */ -static str uuid_col = str_init("uuid"); -static str attribute_col = str_init("attribute"); -static str value_col = str_init("value"); -static str type_col = str_init("type"); -static str username_col = str_init("username"); -static str domain_col = str_init("domain"); -static str* db_columns[6] = {&uuid_col, &attribute_col, &value_col, &type_col, &username_col, &domain_col}; +static str db_url = {NULL, 0}; /* database url */ +static str db_table = {NULL, 0}; /* table */ +static int use_domain = 0; /* if domain should be use for avp matching */ +static str uuid_col = str_init("uuid"); +static str attribute_col = str_init("attribute"); +static str value_col = str_init("value"); +static str type_col = str_init("type"); +static str username_col = str_init("username"); +static str domain_col = str_init("domain"); +static str *db_columns[6] = {&uuid_col, &attribute_col, &value_col, &type_col, + &username_col, &domain_col}; static int avpops_init(void); static int avpops_child_init(int rank); -static int fixup_db_load_avp(void** param, int param_no); -static int fixup_db_delete_avp(void** param, int param_no); -static int fixup_db_store_avp(void** param, int param_no); -static int fixup_db_query_avp(void** param, int param_no); -static int fixup_delete_avp(void** param, int param_no); -static int fixup_copy_avp(void** param, int param_no); -static int fixup_pushto_avp(void** param, int param_no); -static int fixup_check_avp(void** param, int param_no); -static int fixup_op_avp(void** param, int param_no); -static int fixup_subst(void** param, int param_no); -static int fixup_subst_pv(void** param, int param_no); -static int fixup_free_subst_pv(void** param, int param_no); -static int fixup_is_avp_set(void** param, int param_no); - -static int w_print_avps(struct sip_msg* msg, char* foo, char *bar); -static int w_dbload_avps(struct sip_msg* msg, char* source, char* param); -static int w_dbdelete_avps(struct sip_msg* msg, char* source, char* param); -static int w_dbstore_avps(struct sip_msg* msg, char* source, char* param); -static int w_dbquery1_avps(struct sip_msg* msg, char* query, char* param); -static int w_dbquery2_avps(struct sip_msg* msg, char* query, char* dest); -static int w_delete_avps(struct sip_msg* msg, char* param, char *foo); -static int w_copy_avps(struct sip_msg* msg, char* param, char *check); -static int w_pushto_avps(struct sip_msg* msg, char* destination, char *param); -static int w_check_avps(struct sip_msg* msg, char* param, char *check); -static int w_op_avps(struct sip_msg* msg, char* param, char *op); -static int w_subst(struct sip_msg* msg, char* src, char *subst); -static int w_subst_pv(struct sip_msg* msg, char* src, char *param); -static int w_is_avp_set(struct sip_msg* msg, char* param, char *foo); +static int fixup_db_load_avp(void **param, int param_no); +static int fixup_db_delete_avp(void **param, int param_no); +static int fixup_db_store_avp(void **param, int param_no); +static int fixup_db_query_avp(void **param, int param_no); +static int fixup_delete_avp(void **param, int param_no); +static int fixup_copy_avp(void **param, int param_no); +static int fixup_pushto_avp(void **param, int param_no); +static int fixup_check_avp(void **param, int param_no); +static int fixup_op_avp(void **param, int param_no); +static int fixup_subst(void **param, int param_no); +static int fixup_subst_pv(void **param, int param_no); +static int fixup_free_subst_pv(void **param, int param_no); +static int fixup_is_avp_set(void **param, int param_no); + +static int w_print_avps(struct sip_msg *msg, char *foo, char *bar); +static int w_dbload_avps(struct sip_msg *msg, char *source, char *param); +static int w_dbdelete_avps(struct sip_msg *msg, char *source, char *param); +static int w_dbstore_avps(struct sip_msg *msg, char *source, char *param); +static int w_dbquery1_avps(struct sip_msg *msg, char *query, char *param); +static int w_dbquery2_avps(struct sip_msg *msg, char *query, char *dest); +static int w_delete_avps(struct sip_msg *msg, char *param, char *foo); +static int w_copy_avps(struct sip_msg *msg, char *param, char *check); +static int w_pushto_avps(struct sip_msg *msg, char *destination, char *param); +static int w_check_avps(struct sip_msg *msg, char *param, char *check); +static int w_op_avps(struct sip_msg *msg, char *param, char *op); +static int w_subst(struct sip_msg *msg, char *src, char *subst); +static int w_subst_pv(struct sip_msg *msg, char *src, char *param); +static int w_is_avp_set(struct sip_msg *msg, char *param, char *foo); /*! \brief * Exported functions */ static cmd_export_t cmds[] = { - {"avp_print", (cmd_function)w_print_avps, 0, 0, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_db_load", (cmd_function)w_dbload_avps, 2, fixup_db_load_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_db_delete", (cmd_function)w_dbdelete_avps, 2, fixup_db_delete_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_db_store", (cmd_function)w_dbstore_avps, 2, fixup_db_store_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_db_query", (cmd_function)w_dbquery1_avps, 1, fixup_db_query_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_db_query", (cmd_function)w_dbquery2_avps, 2, fixup_db_query_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_delete", (cmd_function)w_delete_avps, 1, fixup_delete_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_copy", (cmd_function)w_copy_avps, 2, fixup_copy_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_pushto", (cmd_function)w_pushto_avps, 2, fixup_pushto_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_check", (cmd_function)w_check_avps, 2, fixup_check_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_op", (cmd_function)w_op_avps, 2, fixup_op_avp, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_subst", (cmd_function)w_subst, 2, fixup_subst, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"avp_subst_pv", (cmd_function)w_subst_pv, 2, fixup_subst_pv, - fixup_free_subst_pv, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {"is_avp_set", (cmd_function)w_is_avp_set, 1, fixup_is_avp_set, 0, - REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE}, - {0, 0, 0, 0, 0, 0} -}; + {"avp_print", (cmd_function)w_print_avps, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_db_load", (cmd_function)w_dbload_avps, 2, fixup_db_load_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_db_delete", (cmd_function)w_dbdelete_avps, 2, fixup_db_delete_avp, + 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_db_store", (cmd_function)w_dbstore_avps, 2, fixup_db_store_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_db_query", (cmd_function)w_dbquery1_avps, 1, fixup_db_query_avp, + 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_db_query", (cmd_function)w_dbquery2_avps, 2, fixup_db_query_avp, + 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_delete", (cmd_function)w_delete_avps, 1, fixup_delete_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_copy", (cmd_function)w_copy_avps, 2, fixup_copy_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_pushto", (cmd_function)w_pushto_avps, 2, fixup_pushto_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_check", (cmd_function)w_check_avps, 2, fixup_check_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_op", (cmd_function)w_op_avps, 2, fixup_op_avp, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_subst", (cmd_function)w_subst, 2, fixup_subst, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"avp_subst_pv", (cmd_function)w_subst_pv, 2, fixup_subst_pv, + fixup_free_subst_pv, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {"is_avp_set", (cmd_function)w_is_avp_set, 1, fixup_is_avp_set, 0, + REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE | ONREPLY_ROUTE + | LOCAL_ROUTE}, + {0, 0, 0, 0, 0, 0}}; /*! \brief * Exported parameters */ -static param_export_t params[] = { - {"db_url", PARAM_STR, &db_url }, - {"avp_table", PARAM_STR, &db_table }, - {"use_domain", INT_PARAM, &use_domain }, - {"uuid_column", PARAM_STR, &uuid_col }, - {"attribute_column", PARAM_STR, &attribute_col }, - {"value_column", PARAM_STR, &value_col }, - {"type_column", PARAM_STR, &type_col }, - {"username_column", PARAM_STR, &username_col }, - {"domain_column", PARAM_STR, &domain_col }, - {"db_scheme", PARAM_STRING|USE_FUNC_PARAM, (void*)avp_add_db_scheme }, - {0, 0, 0} -}; +static param_export_t params[] = {{"db_url", PARAM_STR, &db_url}, + {"avp_table", PARAM_STR, &db_table}, + {"use_domain", INT_PARAM, &use_domain}, + {"uuid_column", PARAM_STR, &uuid_col}, + {"attribute_column", PARAM_STR, &attribute_col}, + {"value_column", PARAM_STR, &value_col}, + {"type_column", PARAM_STR, &type_col}, + {"username_column", PARAM_STR, &username_col}, + {"domain_column", PARAM_STR, &domain_col}, + {"db_scheme", PARAM_STRING | USE_FUNC_PARAM, (void *)avp_add_db_scheme}, + {0, 0, 0}}; struct module_exports exports = { - "avpops", - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* Exported functions */ - params, /* Exported parameters */ - 0, /* exported RPC methods */ - 0, /* exported pseudo-variables */ - 0, /* response handling function */ - avpops_init, /* Module initialization function */ - avpops_child_init, /* per-child init function */ - 0 /* module destroy function */ + "avpops", DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* Exported functions */ + params, /* Exported parameters */ + 0, /* exported RPC methods */ + 0, /* exported pseudo-variables */ + 0, /* response handling function */ + avpops_init, /* Module initialization function */ + avpops_child_init, /* per-child init function */ + 0 /* module destroy function */ }; static int avpops_init(void) { /* if DB_URL defined -> bind to a DB module */ - if (db_url.s && db_url.len>0) - { + if(db_url.s && db_url.len > 0) { /* check AVP_TABLE param */ - if (!db_table.s || db_table.len<=0) - { + if(!db_table.s || db_table.len <= 0) { LM_CRIT("\"AVP_DB\" present but \"AVP_TABLE\" found empty\n"); goto error; } /* bind to the DB module */ - if (avpops_db_bind(&db_url)<0) + if(avpops_db_bind(&db_url) < 0) goto error; } @@ -183,66 +195,64 @@ static int avpops_init(void) static int avpops_child_init(int rank) { /* init DB only if enabled */ - if (db_url.s==0) + if(db_url.s == 0) return 0; /* skip main process and TCP manager process */ - if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) + if(rank == PROC_INIT || rank == PROC_MAIN || rank == PROC_TCP_MAIN) return 0; /* init DB connection */ return avpops_db_init(&db_url, &db_table, db_columns); } -static int fixup_db_avp(void** param, int param_no, int allow_scheme) +static int fixup_db_avp(void **param, int param_no, int allow_scheme) { struct fis_param *sp; - struct db_param *dbp; + struct db_param *dbp; int flags; str s; char *p; - flags=0; - if (db_url.s==0) - { - LM_ERR("you have to configure a db_url for using avp_db_xxx functions\n"); + flags = 0; + if(db_url.s == 0) { + LM_ERR("you have to configure a db_url for using avp_db_xxx " + "functions\n"); return E_UNSPEC; } - s.s = (char*)*param; - if (param_no==1) - { + s.s = (char *)*param; + if(param_no == 1) { /* prepare the fis_param structure */ - sp = (struct fis_param*)pkg_malloc(sizeof(struct fis_param)); - if (sp==0) { + sp = (struct fis_param *)pkg_malloc(sizeof(struct fis_param)); + if(sp == 0) { PKG_MEM_ERROR; return E_OUT_OF_MEM; } memset(sp, 0, sizeof(struct fis_param)); - if ( (p=strchr(s.s,'/'))!=0) - { + if((p = strchr(s.s, '/')) != 0) { *(p++) = 0; /* check for extra flags/params */ - if (!strcasecmp("domain",p)) { - flags|=AVPOPS_FLAG_DOMAIN0; - } else if (!strcasecmp("username",p)) { - flags|=AVPOPS_FLAG_USER0; - } else if (!strcasecmp("uri",p)) { - flags|=AVPOPS_FLAG_URI0; - } else if (!strcasecmp("uuid",p)) { - flags|=AVPOPS_FLAG_UUID0; + if(!strcasecmp("domain", p)) { + flags |= AVPOPS_FLAG_DOMAIN0; + } else if(!strcasecmp("username", p)) { + flags |= AVPOPS_FLAG_USER0; + } else if(!strcasecmp("uri", p)) { + flags |= AVPOPS_FLAG_URI0; + } else if(!strcasecmp("uuid", p)) { + flags |= AVPOPS_FLAG_UUID0; } else { - LM_ERR("unknown flag <%s>\n",p); + LM_ERR("unknown flag <%s>\n", p); pkg_free(sp); return E_UNSPEC; } } - if (*s.s!='$') - { + if(*s.s != '$') { /* is a constant string -> use it as uuid*/ - sp->opd = ((flags==0)?AVPOPS_FLAG_UUID0:flags)|AVPOPS_VAL_STR; - sp->u.s.s = (char*)pkg_malloc(strlen(s.s)+1); - if (sp->u.s.s==0) { + sp->opd = + ((flags == 0) ? AVPOPS_FLAG_UUID0 : flags) | AVPOPS_VAL_STR; + sp->u.s.s = (char *)pkg_malloc(strlen(s.s) + 1); + if(sp->u.s.s == 0) { PKG_MEM_ERROR; pkg_free(sp); return E_OUT_OF_MEM; @@ -253,106 +263,100 @@ static int fixup_db_avp(void** param, int param_no, int allow_scheme) /* is a variable $xxxxx */ s.len = strlen(s.s); sp->u.sval = pv_cache_get(&s); - if (sp->u.sval==0 || sp->u.sval->type==PVT_NULL || sp->u.sval->type==PVT_EMPTY) - { + if(sp->u.sval == 0 || sp->u.sval->type == PVT_NULL + || sp->u.sval->type == PVT_EMPTY) { LM_ERR("bad param 1; " - "expected : $pseudo-variable or int/str value\n"); + "expected : $pseudo-variable or int/str value\n"); pkg_free(sp); return E_UNSPEC; } - - if(sp->u.sval->type==PVT_RURI || sp->u.sval->type==PVT_FROM - || sp->u.sval->type==PVT_TO || sp->u.sval->type==PVT_OURI) - { - sp->opd = ((flags==0)?AVPOPS_FLAG_URI0:flags)|AVPOPS_VAL_PVAR; + + if(sp->u.sval->type == PVT_RURI || sp->u.sval->type == PVT_FROM + || sp->u.sval->type == PVT_TO + || sp->u.sval->type == PVT_OURI) { + sp->opd = ((flags == 0) ? AVPOPS_FLAG_URI0 : flags) + | AVPOPS_VAL_PVAR; } else { - sp->opd = ((flags==0)?AVPOPS_FLAG_UUID0:flags)|AVPOPS_VAL_PVAR; + sp->opd = ((flags == 0) ? AVPOPS_FLAG_UUID0 : flags) + | AVPOPS_VAL_PVAR; } } - *param=(void*)sp; - } else if (param_no==2) { + *param = (void *)sp; + } else if(param_no == 2) { /* compose the db_param structure */ - dbp = (struct db_param*)pkg_malloc(sizeof(struct db_param)); - if (dbp==0) - { + dbp = (struct db_param *)pkg_malloc(sizeof(struct db_param)); + if(dbp == 0) { PKG_MEM_ERROR; return E_OUT_OF_MEM; } - memset( dbp, 0, sizeof(struct db_param)); - if ( parse_avp_db( s.s, dbp, allow_scheme)!=0 ) - { + memset(dbp, 0, sizeof(struct db_param)); + if(parse_avp_db(s.s, dbp, allow_scheme) != 0) { LM_ERR("parse failed\n"); pkg_free(dbp); return E_UNSPEC; } - *param=(void*)dbp; + *param = (void *)dbp; } return 0; } -static int fixup_db_load_avp(void** param, int param_no) +static int fixup_db_load_avp(void **param, int param_no) { - return fixup_db_avp( param, param_no, 1/*allow scheme*/); + return fixup_db_avp(param, param_no, 1 /*allow scheme*/); } -static int fixup_db_delete_avp(void** param, int param_no) +static int fixup_db_delete_avp(void **param, int param_no) { - return fixup_db_avp( param, param_no, 0/*no scheme*/); + return fixup_db_avp(param, param_no, 0 /*no scheme*/); } -static int fixup_db_store_avp(void** param, int param_no) +static int fixup_db_store_avp(void **param, int param_no) { - return fixup_db_avp( param, param_no, 0/*no scheme*/); + return fixup_db_avp(param, param_no, 0 /*no scheme*/); } -static int fixup_db_query_avp(void** param, int param_no) +static int fixup_db_query_avp(void **param, int param_no) { pv_elem_t *model = NULL; pvname_list_t *anlist = NULL; str s; - if (db_url.s==0) - { - LM_ERR("you have to configure db_url for using avp_db_query function\n"); + if(db_url.s == 0) { + LM_ERR("you have to configure db_url for using avp_db_query " + "function\n"); return E_UNSPEC; } - s.s = (char*)(*param); - if (param_no==1) - { - if(s.s==NULL) - { - LM_ERR("null format in P%d\n", - param_no); + s.s = (char *)(*param); + if(param_no == 1) { + if(s.s == NULL) { + LM_ERR("null format in P%d\n", param_no); return E_UNSPEC; } s.len = strlen(s.s); - if(pv_parse_format(&s, &model)<0) - { + if(pv_parse_format(&s, &model) < 0) { LM_ERR("wrong format[%s]\n", s.s); return E_UNSPEC; } - - *param = (void*)model; + + *param = (void *)model; return 0; - } else if(param_no==2) { - if(s.s==NULL) - { + } else if(param_no == 2) { + if(s.s == NULL) { LM_ERR("null format in P%d\n", param_no); return E_UNSPEC; } - s.len = strlen(s.s); + s.len = strlen(s.s); anlist = parse_pvname_list(&s, PVT_AVP); - if(anlist==NULL) - { + if(anlist == NULL) { LM_ERR("bad format in P%d [%s]\n", param_no, s.s); return E_UNSPEC; } - *param = (void*)anlist; + *param = (void *)anlist; return 0; } @@ -360,62 +364,61 @@ static int fixup_db_query_avp(void** param, int param_no) } -static int fixup_delete_avp(void** param, int param_no) +static int fixup_delete_avp(void **param, int param_no) { - struct fis_param *ap=NULL; + struct fis_param *ap = NULL; char *p; char *s; unsigned int flags; str s0; - s = (char*)(*param); - if (param_no==1) { + s = (char *)(*param); + if(param_no == 1) { /* attribute name / alias */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; - - if(*s=='$') - { + if((p = strchr(s, '/')) != 0) + *(p++) = 0; + + if(*s == '$') { /* is variable */ ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get" - " pseudo-variable in param \n"); + " pseudo-variable in param \n"); return E_UNSPEC; } - if (ap->u.sval->type!=PVT_AVP) - { + if(ap->u.sval->type != PVT_AVP) { LM_ERR("bad param; expected : $avp(name)\n"); pkg_free(ap); return E_UNSPEC; } - ap->opd|=AVPOPS_VAL_PVAR; + ap->opd |= AVPOPS_VAL_PVAR; ap->type = AVPOPS_VAL_PVAR; } else { - if(strlen(s)<1) - { + if(strlen(s) < 1) { LM_ERR("bad param - expected : $avp(name), *, s or i value\n"); return E_UNSPEC; } - ap = (struct fis_param*)pkg_malloc(sizeof(struct fis_param)); - if (ap==0) - { + ap = (struct fis_param *)pkg_malloc(sizeof(struct fis_param)); + if(ap == 0) { PKG_MEM_ERROR; return E_OUT_OF_MEM; } memset(ap, 0, sizeof(struct fis_param)); - ap->opd|=AVPOPS_VAL_NONE; + ap->opd |= AVPOPS_VAL_NONE; switch(*s) { - case 's': case 'S': - ap->opd = AVPOPS_VAL_NONE|AVPOPS_VAL_STR; - break; - case 'i': case 'I': - ap->opd = AVPOPS_VAL_NONE|AVPOPS_VAL_INT; - break; - case '*': case 'a': case 'A': + case 's': + case 'S': + ap->opd = AVPOPS_VAL_NONE | AVPOPS_VAL_STR; + break; + case 'i': + case 'I': + ap->opd = AVPOPS_VAL_NONE | AVPOPS_VAL_INT; + break; + case '*': + case 'a': + case 'A': ap->opd = AVPOPS_VAL_NONE; - break; + break; default: LM_ERR(" bad param - expected : *, s or i AVP flag\n"); pkg_free(ap); @@ -423,204 +426,187 @@ static int fixup_delete_avp(void** param, int param_no) } /* flags */ flags = 0; - if(*(s+1)!='\0') - { - s0.s = s+1; + if(*(s + 1) != '\0') { + s0.s = s + 1; s0.len = strlen(s0.s); - if(str2int(&s0, &flags)!=0) - { + if(str2int(&s0, &flags) != 0) { LM_ERR("bad avp flags\n"); pkg_free(ap); return E_UNSPEC; } } ap->type = AVPOPS_VAL_INT; - ap->u.n = flags<<8; + ap->u.n = flags << 8; } /* flags */ - for( ; p&&*p ; p++ ) - { - switch (*p) - { + for(; p && *p; p++) { + switch(*p) { case 'g': case 'G': - ap->ops|=AVPOPS_FLAG_ALL; + ap->ops |= AVPOPS_FLAG_ALL; break; default: - LM_ERR(" bad flag <%c>\n",*p); - if(ap!=NULL) + LM_ERR(" bad flag <%c>\n", *p); + if(ap != NULL) pkg_free(ap); return E_UNSPEC; } } /* force some flags: if no avp name is given, force "all" flag */ - if (ap->opd&AVPOPS_VAL_NONE) + if(ap->opd & AVPOPS_VAL_NONE) ap->ops |= AVPOPS_FLAG_ALL; - *param=(void*)ap; + *param = (void *)ap; } return 0; } -static int fixup_copy_avp(void** param, int param_no) +static int fixup_copy_avp(void **param, int param_no) { struct fis_param *ap; char *s; char *p; - s = (char*)*param; + s = (char *)*param; ap = 0; p = 0; - if (param_no==2) - { + if(param_no == 2) { /* avp / flags */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; + if((p = strchr(s, '/')) != 0) + *(p++) = 0; } ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in P%d\n", param_no); return E_OUT_OF_MEM; } /* attr name is mandatory */ - if (ap->u.sval->type!=PVT_AVP) - { + if(ap->u.sval->type != PVT_AVP) { LM_ERR("you must specify only AVP as parameter\n"); pkg_free(ap); return E_UNSPEC; } - if (param_no==2) - { + if(param_no == 2) { /* flags */ - for( ; p&&*p ; p++ ) - { - switch (*p) { + for(; p && *p; p++) { + switch(*p) { case 'g': case 'G': - ap->ops|=AVPOPS_FLAG_ALL; + ap->ops |= AVPOPS_FLAG_ALL; break; case 'd': case 'D': - ap->ops|=AVPOPS_FLAG_DELETE; + ap->ops |= AVPOPS_FLAG_DELETE; break; case 'n': case 'N': - ap->ops|=AVPOPS_FLAG_CASTN; + ap->ops |= AVPOPS_FLAG_CASTN; break; case 's': case 'S': - ap->ops|=AVPOPS_FLAG_CASTS; + ap->ops |= AVPOPS_FLAG_CASTS; break; default: - LM_ERR("bad flag <%c>\n",*p); + LM_ERR("bad flag <%c>\n", *p); pkg_free(ap); return E_UNSPEC; } } } - *param=(void*)ap; + *param = (void *)ap; return 0; } -static int fixup_pushto_avp(void** param, int param_no) +static int fixup_pushto_avp(void **param, int param_no) { struct fis_param *ap; char *s; char *p; - s = (char*)*param; + s = (char *)*param; ap = 0; - if (param_no==1) - { - if ( *s!='$') - { + if(param_no == 1) { + if(*s != '$') { LM_ERR("bad param 1; expected : $ru $du ...\n"); return E_UNSPEC; } /* compose the param structure */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; + if((p = strchr(s, '/')) != 0) + *(p++) = 0; ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in param 1\n"); return E_OUT_OF_MEM; } switch(ap->u.sval->type) { case PVT_RURI: - ap->opd = AVPOPS_VAL_NONE|AVPOPS_USE_RURI; - if ( p && !( - (!strcasecmp("username",p) - && (ap->opd|=AVPOPS_FLAG_USER0)) || - (!strcasecmp("domain",p) - && (ap->opd|=AVPOPS_FLAG_DOMAIN0)) )) - { - LM_ERR("unknown ruri flag \"%s\"!\n",p); + ap->opd = AVPOPS_VAL_NONE | AVPOPS_USE_RURI; + if(p + && !((!strcasecmp("username", p) + && (ap->opd |= AVPOPS_FLAG_USER0)) + || (!strcasecmp("domain", p) + && (ap->opd |= AVPOPS_FLAG_DOMAIN0)))) { + LM_ERR("unknown ruri flag \"%s\"!\n", p); pkg_free(ap); return E_UNSPEC; } - break; + break; case PVT_DSTURI: - if ( p!=0 ) - { - LM_ERR("unknown duri flag \"%s\"!\n",p); + if(p != 0) { + LM_ERR("unknown duri flag \"%s\"!\n", p); pkg_free(ap); return E_UNSPEC; } - ap->opd = AVPOPS_VAL_NONE|AVPOPS_USE_DURI; - break; + ap->opd = AVPOPS_VAL_NONE | AVPOPS_USE_DURI; + break; case PVT_HDR: /* what's the hdr destination ? request or reply? */ LM_ERR("push to header is obsoleted - use append_hf() " - "or append_to_reply() from textops module!\n"); + "or append_to_reply() from textops module!\n"); pkg_free(ap); return E_UNSPEC; - break; + break; case PVT_BRANCH: - if ( p!=0 ) - { - LM_ERR("unknown branch flag \"%s\"!\n",p); + if(p != 0) { + LM_ERR("unknown branch flag \"%s\"!\n", p); pkg_free(ap); return E_UNSPEC; } - ap->opd = AVPOPS_VAL_NONE|AVPOPS_USE_BRANCH; - break; + ap->opd = AVPOPS_VAL_NONE | AVPOPS_USE_BRANCH; + break; default: LM_ERR("unsupported destination \"%s\"; " - "expected $ru,$du,$br\n",s); + "expected $ru,$du,$br\n", + s); pkg_free(ap); return E_UNSPEC; } - } else if (param_no==2) { + } else if(param_no == 2) { /* attribute name*/ - if ( *s!='$') - { + if(*s != '$') { LM_ERR("bad param 2; expected: $pseudo-variable ...\n"); return E_UNSPEC; } /* compose the param structure */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; + if((p = strchr(s, '/')) != 0) + *(p++) = 0; ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in param 2\n"); return E_OUT_OF_MEM; } - if (ap->u.sval->type==PVT_NULL) - { + if(ap->u.sval->type == PVT_NULL) { LM_ERR("bad param 2; expected : $pseudo-variable ...\n"); pkg_free(ap); return E_UNSPEC; @@ -628,183 +614,167 @@ static int fixup_pushto_avp(void** param, int param_no) ap->opd |= AVPOPS_VAL_PVAR; /* flags */ - for( ; p&&*p ; p++ ) - { - switch (*p) { + for(; p && *p; p++) { + switch(*p) { case 'g': case 'G': - ap->ops|=AVPOPS_FLAG_ALL; + ap->ops |= AVPOPS_FLAG_ALL; break; default: - LM_ERR("bad flag <%c>\n",*p); + LM_ERR("bad flag <%c>\n", *p); pkg_free(ap); return E_UNSPEC; } } } - *param=(void*)ap; + *param = (void *)ap; return 0; } -static int fixup_check_avp(void** param, int param_no) +static int fixup_check_avp(void **param, int param_no) { struct fis_param *ap; - regex_t* re; + regex_t *re; char *s; - s = (char*)*param; + s = (char *)*param; ap = 0; - if (param_no==1) - { + if(param_no == 1) { ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in param 1\n"); return E_OUT_OF_MEM; } /* attr name is mandatory */ - if (ap->u.sval->type==PVT_NULL) - { + if(ap->u.sval->type == PVT_NULL) { LM_ERR("null pseudo-variable in param 1\n"); pkg_free(ap); return E_UNSPEC; } - } else if (param_no==2) { - if ( (ap=parse_check_value(s))==0 ) - { + } else if(param_no == 2) { + if((ap = parse_check_value(s)) == 0) { LM_ERR("failed to parse checked value \n"); return E_UNSPEC; } /* if REGEXP op -> compile the expression */ - if (ap->ops&AVPOPS_OP_RE) - { - if ( (ap->opd&AVPOPS_VAL_STR)!=0 ) - { - re = (regex_t*) pkg_malloc(sizeof(regex_t)); - if (re==0) - { + if(ap->ops & AVPOPS_OP_RE) { + if((ap->opd & AVPOPS_VAL_STR) != 0) { + re = (regex_t *)pkg_malloc(sizeof(regex_t)); + if(re == 0) { PKG_MEM_ERROR; pkg_free(ap); return E_OUT_OF_MEM; } LM_DBG("compiling regexp <%.*s>\n", ap->u.s.len, ap->u.s.s); - if (regcomp(re, ap->u.s.s,REG_EXTENDED|REG_ICASE|REG_NEWLINE)) - { + if(regcomp(re, ap->u.s.s, + REG_EXTENDED | REG_ICASE | REG_NEWLINE)) { LM_ERR("bad re <%.*s>\n", ap->u.s.len, ap->u.s.s); pkg_free(re); pkg_free(ap); return E_BAD_RE; } - ap->u.s.s = (char*)re; + ap->u.s.s = (char *)re; } - } else if (ap->ops&AVPOPS_OP_FM) { - if ( !( ap->opd&AVPOPS_VAL_PVAR || - (!(ap->opd&AVPOPS_VAL_PVAR) && ap->opd&AVPOPS_VAL_STR) ) ) - { + } else if(ap->ops & AVPOPS_OP_FM) { + if(!(ap->opd & AVPOPS_VAL_PVAR + || (!(ap->opd & AVPOPS_VAL_PVAR) + && ap->opd & AVPOPS_VAL_STR))) { LM_ERR("fast_match operation requires string value or " - "avp name/alias (%d/%d)\n", ap->opd, ap->ops); + "avp name/alias (%d/%d)\n", + ap->opd, ap->ops); pkg_free(ap); return E_UNSPEC; } } } - *param=(void*)ap; + *param = (void *)ap; return 0; } -static int fixup_subst_pv(void** param, int param_no) +static int fixup_subst_pv(void **param, int param_no) { - if(param_no==1) { + if(param_no == 1) { return fixup_subst(param, param_no); - } else if (param_no==2) { + } else if(param_no == 2) { return fixup_var_str_2(param, param_no); } return 0; } -static int fixup_subst(void** param, int param_no) +static int fixup_subst(void **param, int param_no) { - struct subst_expr* se; + struct subst_expr *se; str subst; struct fis_param *ap; struct fis_param **av; char *s; char *p; - - if (param_no==1) { - s = (char*)*param; + + if(param_no == 1) { + s = (char *)*param; ap = 0; p = 0; - av = (struct fis_param**)pkg_malloc(2*sizeof(struct fis_param*)); - if(av==NULL) - { + av = (struct fis_param **)pkg_malloc(2 * sizeof(struct fis_param *)); + if(av == NULL) { PKG_MEM_ERROR; - return E_UNSPEC; + return E_UNSPEC; } - memset(av, 0, 2*sizeof(struct fis_param*)); + memset(av, 0, 2 * sizeof(struct fis_param *)); /* avp src / avp dst /flags */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; + if((p = strchr(s, '/')) != 0) + *(p++) = 0; ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in param 2 [%s]\n", s); pkg_free(av); return E_OUT_OF_MEM; } - if (ap->u.sval->type!=PVT_AVP) - { - LM_ERR("bad attribute name <%s>\n", (char*)*param); + if(ap->u.sval->type != PVT_AVP) { + LM_ERR("bad attribute name <%s>\n", (char *)*param); pkg_free(av); pkg_free(ap); return E_UNSPEC; } /* attr name is mandatory */ - if (ap->opd&AVPOPS_VAL_NONE) - { + if(ap->opd & AVPOPS_VAL_NONE) { LM_ERR("you must specify a name for the AVP\n"); pkg_free(av); pkg_free(ap); return E_UNSPEC; } av[0] = ap; - if(p==0 || *p=='\0') - { - *param=(void*)av; + if(p == 0 || *p == '\0') { + *param = (void *)av; return 0; } ap = 0; - + /* dst || flags */ s = p; - if(*s==PV_MARKER) - { - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; - if(p==0 || (p!=0 && p-s>1)) - { + if(*s == PV_MARKER) { + if((p = strchr(s, '/')) != 0) + *(p++) = 0; + if(p == 0 || (p != 0 && p - s > 1)) { ap = avpops_parse_pvar(s); - if (ap==0) - { - LM_ERR("unable to get pseudo-variable in param 2 [%s]\n",s); + if(ap == 0) { + LM_ERR("unable to get pseudo-variable in param 2 [%s]\n", + s); pkg_free(av); return E_OUT_OF_MEM; } - - if (ap->u.sval->type!=PVT_AVP) - { + + if(ap->u.sval->type != PVT_AVP) { LM_ERR("bad attribute name <%s>!\n", s); pkg_free(av); pkg_free(ap); return E_UNSPEC; } /* attr name is mandatory */ - if (ap->opd&AVPOPS_VAL_NONE) - { + if(ap->opd & AVPOPS_VAL_NONE) { LM_ERR("you must specify a name for the AVP!\n"); pkg_free(av); pkg_free(ap); @@ -812,114 +782,106 @@ static int fixup_subst(void** param, int param_no) } av[1] = ap; } - if(p==0 || *p=='\0') - { - *param=(void*)av; + if(p == 0 || *p == '\0') { + *param = (void *)av; return 0; } } - + /* flags */ - for( ; p&&*p ; p++ ) - { - switch (*p) { + for(; p && *p; p++) { + switch(*p) { case 'g': case 'G': - av[0]->ops|=AVPOPS_FLAG_ALL; + av[0]->ops |= AVPOPS_FLAG_ALL; break; case 'd': case 'D': - av[0]->ops|=AVPOPS_FLAG_DELETE; + av[0]->ops |= AVPOPS_FLAG_DELETE; break; default: - LM_ERR("bad flag <%c>\n",*p); + LM_ERR("bad flag <%c>\n", *p); pkg_free(av[0]); - if(av[1]) pkg_free(av[1]); + if(av[1]) + pkg_free(av[1]); pkg_free(av); return E_UNSPEC; } } - *param=(void*)av; - } else if (param_no==2) { - LM_DBG("%s fixing %s\n", exports.name, (char*)(*param)); - subst.s=*param; - subst.len=strlen(*param); - se=subst_parser(&subst); - if (se==0){ - LM_ERR("%s: bad subst re %s\n",exports.name, (char*)*param); + *param = (void *)av; + } else if(param_no == 2) { + LM_DBG("%s fixing %s\n", exports.name, (char *)(*param)); + subst.s = *param; + subst.len = strlen(*param); + se = subst_parser(&subst); + if(se == 0) { + LM_ERR("%s: bad subst re %s\n", exports.name, (char *)*param); return E_BAD_RE; } /* don't free string -- needed for specifiers */ /* pkg_free(*param); */ /* replace it with the compiled subst. re */ - *param=se; + *param = se; } return 0; } -static int fixup_free_subst_pv(void** param, int param_no) +static int fixup_free_subst_pv(void **param, int param_no) { - if (param_no==2) + if(param_no == 2) fparam_free_restore(param); return 0; } -static int fixup_op_avp(void** param, int param_no) +static int fixup_op_avp(void **param, int param_no) { struct fis_param *ap; struct fis_param **av; char *s; char *p; - s = (char*)*param; + s = (char *)*param; ap = 0; - if (param_no==1) - { - av = (struct fis_param**)pkg_malloc(2*sizeof(struct fis_param*)); - if(av==NULL) - { + if(param_no == 1) { + av = (struct fis_param **)pkg_malloc(2 * sizeof(struct fis_param *)); + if(av == NULL) { PKG_MEM_ERROR; - return E_UNSPEC; + return E_UNSPEC; } - memset(av, 0, 2*sizeof(struct fis_param*)); + memset(av, 0, 2 * sizeof(struct fis_param *)); /* avp src / avp dst */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; + if((p = strchr(s, '/')) != 0) + *(p++) = 0; av[0] = avpops_parse_pvar(s); - if (av[0]==0) - { + if(av[0] == 0) { LM_ERR("unable to get pseudo-variable in param 1\n"); pkg_free(av); return E_OUT_OF_MEM; } - if (av[0]->u.sval->type!=PVT_AVP) - { - LM_ERR("bad attribute name <%s>\n", (char*)*param); + if(av[0]->u.sval->type != PVT_AVP) { + LM_ERR("bad attribute name <%s>\n", (char *)*param); pkg_free(av[0]); pkg_free(av); return E_UNSPEC; } - if(p==0 || *p=='\0') - { - *param=(void*)av; + if(p == 0 || *p == '\0') { + *param = (void *)av; return 0; } - + s = p; ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in param 1 (2)\n"); pkg_free(av[0]); pkg_free(av); return E_OUT_OF_MEM; } - if (ap->u.sval->type!=PVT_AVP) - { + if(ap->u.sval->type != PVT_AVP) { LM_ERR("bad attribute name/alias <%s>!\n", s); pkg_free(ap); pkg_free(av[0]); @@ -927,256 +889,242 @@ static int fixup_op_avp(void** param, int param_no) return E_UNSPEC; } av[1] = ap; - *param=(void*)av; + *param = (void *)av; return 0; - } else if (param_no==2) { - if ( (ap=parse_op_value(s))==0 ) - { + } else if(param_no == 2) { + if((ap = parse_op_value(s)) == 0) { LM_ERR("failed to parse the value \n"); return E_UNSPEC; } /* only integer values or avps */ - if ( (ap->opd&AVPOPS_VAL_STR)!=0 && (ap->opd&AVPOPS_VAL_PVAR)==0) - { + if((ap->opd & AVPOPS_VAL_STR) != 0 + && (ap->opd & AVPOPS_VAL_PVAR) == 0) { LM_ERR("operations requires integer values\n"); pkg_free(ap); return E_UNSPEC; } - *param=(void*)ap; + *param = (void *)ap; return 0; } return -1; } -static int fixup_is_avp_set(void** param, int param_no) +static int fixup_is_avp_set(void **param, int param_no) { struct fis_param *ap; char *p; char *s; - - s = (char*)(*param); - if (param_no==1) { + + s = (char *)(*param); + if(param_no == 1) { /* attribute name | alias / flags */ - if ( (p=strchr(s,'/'))!=0 ) - *(p++)=0; - + if((p = strchr(s, '/')) != 0) + *(p++) = 0; + ap = avpops_parse_pvar(s); - if (ap==0) - { + if(ap == 0) { LM_ERR("unable to get pseudo-variable in param\n"); return E_OUT_OF_MEM; } - - if (ap->u.sval->type!=PVT_AVP) - { - LM_ERR("bad attribute name <%s>\n", (char*)*param); + + if(ap->u.sval->type != PVT_AVP) { + LM_ERR("bad attribute name <%s>\n", (char *)*param); pkg_free(ap); return E_UNSPEC; } - if(p==0 || *p=='\0') - ap->ops|=AVPOPS_FLAG_ALL; + if(p == 0 || *p == '\0') + ap->ops |= AVPOPS_FLAG_ALL; /* flags */ - for( ; p&&*p ; p++ ) - { - switch (*p) { + for(; p && *p; p++) { + switch(*p) { case 'e': case 'E': - ap->ops|=AVPOPS_FLAG_EMPTY; + ap->ops |= AVPOPS_FLAG_EMPTY; break; case 'n': case 'N': - if(ap->ops&AVPOPS_FLAG_CASTS) - { - LM_ERR("invalid flag combination <%c> and 's|S'\n",*p); + if(ap->ops & AVPOPS_FLAG_CASTS) { + LM_ERR("invalid flag combination <%c> and 's|S'\n", *p); pkg_free(ap); return E_UNSPEC; } - ap->ops|=AVPOPS_FLAG_CASTN; + ap->ops |= AVPOPS_FLAG_CASTN; break; case 's': case 'S': - if(ap->ops&AVPOPS_FLAG_CASTN) - { - LM_ERR("invalid flag combination <%c> and 'n|N'\n",*p); + if(ap->ops & AVPOPS_FLAG_CASTN) { + LM_ERR("invalid flag combination <%c> and 'n|N'\n", *p); pkg_free(ap); return E_UNSPEC; } - ap->ops|=AVPOPS_FLAG_CASTS; + ap->ops |= AVPOPS_FLAG_CASTS; break; default: - LM_ERR("bad flag <%c>\n",*p); + LM_ERR("bad flag <%c>\n", *p); pkg_free(ap); return E_UNSPEC; } } - - *param=(void*)ap; + + *param = (void *)ap; } return 0; } -static int w_dbload_avps(struct sip_msg* msg, char* source, char* param) +static int w_dbload_avps(struct sip_msg *msg, char *source, char *param) { - return ops_dbload_avps ( msg, (struct fis_param*)source, - (struct db_param*)param, use_domain); + return ops_dbload_avps(msg, (struct fis_param *)source, + (struct db_param *)param, use_domain); } -static int w_dbdelete_avps(struct sip_msg* msg, char* source, char* param) +static int w_dbdelete_avps(struct sip_msg *msg, char *source, char *param) { - return ops_dbdelete_avps ( msg, (struct fis_param*)source, - (struct db_param*)param, use_domain); + return ops_dbdelete_avps(msg, (struct fis_param *)source, + (struct db_param *)param, use_domain); } -static int w_dbstore_avps(struct sip_msg* msg, char* source, char* param) +static int w_dbstore_avps(struct sip_msg *msg, char *source, char *param) { - return ops_dbstore_avps ( msg, (struct fis_param*)source, - (struct db_param*)param, use_domain); + return ops_dbstore_avps(msg, (struct fis_param *)source, + (struct db_param *)param, use_domain); } -static int w_dbquery1_avps(struct sip_msg* msg, char* query, char* param) +static int w_dbquery1_avps(struct sip_msg *msg, char *query, char *param) { - return ops_dbquery_avps ( msg, (pv_elem_t*)query, 0); + return ops_dbquery_avps(msg, (pv_elem_t *)query, 0); } -static int w_dbquery2_avps(struct sip_msg* msg, char* query, char* dest) +static int w_dbquery2_avps(struct sip_msg *msg, char *query, char *dest) { - return ops_dbquery_avps ( msg, (pv_elem_t*)query, (pvname_list_t*)dest); + return ops_dbquery_avps(msg, (pv_elem_t *)query, (pvname_list_t *)dest); } -static int w_delete_avps(struct sip_msg* msg, char* param, char* foo) +static int w_delete_avps(struct sip_msg *msg, char *param, char *foo) { - return ops_delete_avp ( msg, (struct fis_param*)param); + return ops_delete_avp(msg, (struct fis_param *)param); } -static int w_copy_avps(struct sip_msg* msg, char* name1, char *name2) +static int w_copy_avps(struct sip_msg *msg, char *name1, char *name2) { - return ops_copy_avp ( msg, (struct fis_param*)name1, - (struct fis_param*)name2); + return ops_copy_avp( + msg, (struct fis_param *)name1, (struct fis_param *)name2); } -static int w_pushto_avps(struct sip_msg* msg, char* destination, char *param) +static int w_pushto_avps(struct sip_msg *msg, char *destination, char *param) { - return ops_pushto_avp ( msg, (struct fis_param*)destination, - (struct fis_param*)param); + return ops_pushto_avp( + msg, (struct fis_param *)destination, (struct fis_param *)param); } -static int w_check_avps(struct sip_msg* msg, char* param, char *check) +static int w_check_avps(struct sip_msg *msg, char *param, char *check) { - return ops_check_avp ( msg, (struct fis_param*)param, - (struct fis_param*)check); + return ops_check_avp( + msg, (struct fis_param *)param, (struct fis_param *)check); } -static int w_op_avps(struct sip_msg* msg, char* param, char *op) +static int w_op_avps(struct sip_msg *msg, char *param, char *op) { - return ops_op_avp ( msg, (struct fis_param**)param, - (struct fis_param*)op); + return ops_op_avp(msg, (struct fis_param **)param, (struct fis_param *)op); } -static int w_subst(struct sip_msg* msg, char* src, char *subst) +static int w_subst(struct sip_msg *msg, char *src, char *subst) { - return ops_subst(msg, (struct fis_param**)src, (struct subst_expr*)subst); + return ops_subst(msg, (struct fis_param **)src, (struct subst_expr *)subst); } -static int w_subst_pv(struct sip_msg* msg, char* src, char *param) +static int w_subst_pv(struct sip_msg *msg, char *src, char *param) { str tstr = STR_NULL; str subst = STR_NULL; - struct subst_expr* se; + struct subst_expr *se; fparam_t *fp; int res; - fp = (fparam_t*)param; - if(get_str_fparam(&tstr, msg, fp) != 0) - { + fp = (fparam_t *)param; + if(get_str_fparam(&tstr, msg, fp) != 0) { LM_ERR("error fetching subst re\n"); return -1; } LM_DBG("preparing to evaluate: [%.*s]\n", tstr.len, tstr.s); - if(pv_eval_str(msg, &subst, &tstr)<0){ + if(pv_eval_str(msg, &subst, &tstr) < 0) { subst.s = tstr.s; subst.len = tstr.len; } LM_DBG("preparing %s\n", subst.s); se = subst_parser(&subst); - if(se==0) - { + if(se == 0) { LM_ERR("bad subst re %s\n", subst.s); return E_BAD_RE; } - res = ops_subst(msg, (struct fis_param**)src, se); + res = ops_subst(msg, (struct fis_param **)src, se); subst_expr_free(se); return res; } -static int w_is_avp_set(struct sip_msg* msg, char* param, char *op) +static int w_is_avp_set(struct sip_msg *msg, char *param, char *op) { - return ops_is_avp_set(msg, (struct fis_param*)param); + return ops_is_avp_set(msg, (struct fis_param *)param); } -static int w_print_avps(struct sip_msg* msg, char* foo, char *bar) +static int w_print_avps(struct sip_msg *msg, char *foo, char *bar) { return ops_print_avp(); } -static int ki_check_avps(struct sip_msg* msg, str* param, str *check) +static int ki_check_avps(struct sip_msg *msg, str *param, str *check) { struct fis_param *fparam, *fcheck; - regex_t* re = NULL; + regex_t *re = NULL; int res; - if((fparam = avpops_parse_pvar(param->s)) == NULL) - { + if((fparam = avpops_parse_pvar(param->s)) == NULL) { LM_ERR("unable to get pseudo-variable in param 1\n"); return E_OUT_OF_MEM; } /* attr name is mandatory */ - if (fparam->u.sval->type==PVT_NULL) - { + if(fparam->u.sval->type == PVT_NULL) { LM_ERR("null pseudo-variable in param 1\n"); pkg_free(fparam); return E_UNSPEC; } - if((fcheck = avpops_parse_pvar(check->s)) == NULL) - { + if((fcheck = avpops_parse_pvar(check->s)) == NULL) { LM_ERR("failed to parse checked value \n"); pkg_free(fparam); return E_UNSPEC; } /* if REGEXP op -> compile the expression */ - if(fcheck->ops&AVPOPS_OP_RE) - { - if( (fcheck->opd&AVPOPS_VAL_STR) != 0 ) - { - if((re = (regex_t*) pkg_malloc(sizeof(regex_t))) == NULL) - { + if(fcheck->ops & AVPOPS_OP_RE) { + if((fcheck->opd & AVPOPS_VAL_STR) != 0) { + if((re = (regex_t *)pkg_malloc(sizeof(regex_t))) == NULL) { PKG_MEM_ERROR; pkg_free(fparam); pkg_free(fcheck); return E_OUT_OF_MEM; } LM_DBG("compiling regexp <%.*s>\n", fcheck->u.s.len, fcheck->u.s.s); - if (regcomp(re, fcheck->u.s.s,REG_EXTENDED|REG_ICASE|REG_NEWLINE)) - { + if(regcomp(re, fcheck->u.s.s, + REG_EXTENDED | REG_ICASE | REG_NEWLINE)) { LM_ERR("bad re <%.*s>\n", fcheck->u.s.len, fcheck->u.s.s); pkg_free(fparam); pkg_free(re); pkg_free(fcheck); return E_BAD_RE; } - fcheck->u.s.s = (char*)re; + fcheck->u.s.s = (char *)re; } - } else if (fcheck->ops&AVPOPS_OP_FM) { - if (!( fcheck->opd&AVPOPS_VAL_PVAR || - (!(fcheck->opd&AVPOPS_VAL_PVAR) && fcheck->opd&AVPOPS_VAL_STR) ) ) - { + } else if(fcheck->ops & AVPOPS_OP_FM) { + if(!(fcheck->opd & AVPOPS_VAL_PVAR + || (!(fcheck->opd & AVPOPS_VAL_PVAR) + && fcheck->opd & AVPOPS_VAL_STR))) { LM_ERR("fast_match operation requires string value or " - "avp name/alias (%d/%d)\n", fcheck->opd, fcheck->ops); + "avp name/alias (%d/%d)\n", + fcheck->opd, fcheck->ops); pkg_free(fparam); pkg_free(fcheck); return E_UNSPEC; @@ -1186,42 +1134,39 @@ static int ki_check_avps(struct sip_msg* msg, str* param, str *check) res = ops_check_avp(msg, fparam, fcheck); pkg_free(fparam); pkg_free(fcheck); - if(re) pkg_free(re); + if(re) + pkg_free(re); return res; } -static int ki_copy_avps(struct sip_msg* msg, str *name1, str *name2) +static int ki_copy_avps(struct sip_msg *msg, str *name1, str *name2) { struct fis_param *fname1, *fname2; char *p = NULL; int res; - if((fname1 = avpops_parse_pvar(name1->s)) == NULL) - { + if((fname1 = avpops_parse_pvar(name1->s)) == NULL) { LM_ERR("unable to get pseudo-variable in param 1\n"); return E_OUT_OF_MEM; } /* attr name is mandatory */ - if (fname1->u.sval->type != PVT_AVP) - { + if(fname1->u.sval->type != PVT_AVP) { LM_ERR("you must specify only AVP as parameter\n"); pkg_free(fname1); return E_UNSPEC; } /* avp / flags */ - if ( (p=strchr(name2->s,'/')) != 0 ) + if((p = strchr(name2->s, '/')) != 0) *(p++) = 0; - if((fname2 = avpops_parse_pvar(name2->s)) == NULL) - { + if((fname2 = avpops_parse_pvar(name2->s)) == NULL) { LM_ERR("unable to get pseudo-variable in param 2\n"); pkg_free(fname1); return E_OUT_OF_MEM; } /* attr name is mandatory */ - if (fname2->u.sval->type != PVT_AVP) - { + if(fname2->u.sval->type != PVT_AVP) { LM_ERR("you must specify only AVP as parameter\n"); pkg_free(fname1); pkg_free(fname2); @@ -1229,34 +1174,33 @@ static int ki_copy_avps(struct sip_msg* msg, str *name1, str *name2) } /* flags */ - for( ; p&&*p ; p++ ) - { - switch (*p) { + for(; p && *p; p++) { + switch(*p) { case 'g': case 'G': - fname2->ops|=AVPOPS_FLAG_ALL; + fname2->ops |= AVPOPS_FLAG_ALL; break; case 'd': case 'D': - fname2->ops|=AVPOPS_FLAG_DELETE; + fname2->ops |= AVPOPS_FLAG_DELETE; break; case 'n': case 'N': - fname2->ops|=AVPOPS_FLAG_CASTN; + fname2->ops |= AVPOPS_FLAG_CASTN; break; case 's': case 'S': - fname2->ops|=AVPOPS_FLAG_CASTS; + fname2->ops |= AVPOPS_FLAG_CASTS; break; default: - LM_ERR("bad flag <%c>\n",*p); + LM_ERR("bad flag <%c>\n", *p); pkg_free(fname1); pkg_free(fname2); return E_UNSPEC; } } - res = ops_copy_avp( msg, fname1, fname2); + res = ops_copy_avp(msg, fname1, fname2); pkg_free(fname1); pkg_free(fname2); return res; @@ -1281,7 +1225,8 @@ static sr_kemi_t sr_kemi_rtpengine_exports[] = { }; /* clang-format on */ -int mod_register(char *path, int *dlflags, void *p1, void *p2) { - sr_kemi_modules_add(sr_kemi_rtpengine_exports); - return 0; +int mod_register(char *path, int *dlflags, void *p1, void *p2) +{ + sr_kemi_modules_add(sr_kemi_rtpengine_exports); + return 0; } diff --git a/src/modules/avpops/avpops_db.c b/src/modules/avpops/avpops_db.c index 6d353f79ac9..6449171a6aa 100644 --- a/src/modules/avpops/avpops_db.c +++ b/src/modules/avpops/avpops_db.c @@ -32,50 +32,45 @@ #include "avpops_db.h" -static db1_con_t *db_hdl=0; /* DB handler */ -static db_func_t avpops_dbf; /* DB functions */ -static str def_table; /* default DB table */ -static str **db_columns; /* array with names of DB columns */ +static db1_con_t *db_hdl = 0; /* DB handler */ +static db_func_t avpops_dbf; /* DB functions */ +static str def_table; /* default DB table */ +static str **db_columns; /* array with names of DB columns */ -static db_key_t keys_cmp[3]; /* array of keys and values used in selection */ -static db_val_t vals_cmp[3]; /* statement as in "select" and "delete" */ +static db_key_t keys_cmp[3]; /* array of keys and values used in selection */ +static db_val_t vals_cmp[3]; /* statement as in "select" and "delete" */ /* linked list with all defined DB schemes */ -static struct db_scheme *db_scheme_list=0; +static struct db_scheme *db_scheme_list = 0; -int avpops_db_bind(const str* db_url) +int avpops_db_bind(const str *db_url) { - if (db_bind_mod(db_url, &avpops_dbf )) - { + if(db_bind_mod(db_url, &avpops_dbf)) { LM_CRIT("cannot bind to database module! " - "Did you load a database module ?\n"); + "Did you load a database module ?\n"); return -1; } - if (!DB_CAPABILITY(avpops_dbf, DB_CAP_ALL)) - { + if(!DB_CAPABILITY(avpops_dbf, DB_CAP_ALL)) { LM_CRIT("database modules does not " - "provide all functions needed by avpops module\n"); + "provide all functions needed by avpops module\n"); return -1; } return 0; - } -int avpops_db_init(const str* db_url, const str* db_table, str** db_cols) +int avpops_db_init(const str *db_url, const str *db_table, str **db_cols) { db_hdl = avpops_dbf.init(db_url); - if (db_hdl==0) - { + if(db_hdl == 0) { LM_ERR("cannot initialize database connection\n"); goto error; } - if (avpops_dbf.use_table(db_hdl, db_table)<0) - { + if(avpops_dbf.use_table(db_hdl, db_table) < 0) { LM_ERR("cannot select table \"%.*s\"\n", db_table->len, db_table->s); goto error; } @@ -85,88 +80,84 @@ int avpops_db_init(const str* db_url, const str* db_table, str** db_cols) return 0; error: - if (db_hdl) - { + if(db_hdl) { avpops_dbf.close(db_hdl); - db_hdl=0; + db_hdl = 0; } return -1; } -int avp_add_db_scheme( modparam_t type, void* val) +int avp_add_db_scheme(modparam_t type, void *val) { struct db_scheme *scheme; - scheme = (struct db_scheme*)pkg_malloc( sizeof(struct db_scheme) ); - if (scheme==0) - { + scheme = (struct db_scheme *)pkg_malloc(sizeof(struct db_scheme)); + if(scheme == 0) { PKG_MEM_ERROR; goto error; } - memset( scheme, 0, sizeof(struct db_scheme)); + memset(scheme, 0, sizeof(struct db_scheme)); /* parse the scheme */ - if ( parse_avp_db_scheme( (char*)val, scheme)!=0 ) - { + if(parse_avp_db_scheme((char *)val, scheme) != 0) { LM_ERR("failed to parse scheme\n"); goto error; } /* check for duplicates */ - if ( avp_get_db_scheme(&scheme->name)!=0 ) - { - LM_ERR("duplicated scheme name <%.*s>\n", - scheme->name.len,scheme->name.s); + if(avp_get_db_scheme(&scheme->name) != 0) { + LM_ERR("duplicated scheme name <%.*s>\n", scheme->name.len, + scheme->name.s); goto error; } /* print scheme */ LM_DBG("new scheme <%.*s> added\n" - "\t\tuuid_col=<%.*s>\n\t\tusername_col=<%.*s>\n" - "\t\tdomain_col=<%.*s>\n\t\tvalue_col=<%.*s>\n" - "\t\tdb_flags=%d\n\t\ttable=<%.*s>\n", - scheme->name.len,scheme->name.s, - scheme->uuid_col.len, scheme->uuid_col.s, scheme->username_col.len, - scheme->username_col.s, scheme->domain_col.len, scheme->domain_col.s, - scheme->value_col.len, scheme->value_col.s, scheme->db_flags, - scheme->table.len, scheme->table.s); + "\t\tuuid_col=<%.*s>\n\t\tusername_col=<%.*s>\n" + "\t\tdomain_col=<%.*s>\n\t\tvalue_col=<%.*s>\n" + "\t\tdb_flags=%d\n\t\ttable=<%.*s>\n", + scheme->name.len, scheme->name.s, scheme->uuid_col.len, + scheme->uuid_col.s, scheme->username_col.len, + scheme->username_col.s, scheme->domain_col.len, + scheme->domain_col.s, scheme->value_col.len, scheme->value_col.s, + scheme->db_flags, scheme->table.len, scheme->table.s); scheme->next = db_scheme_list; db_scheme_list = scheme; return 0; error: - if(scheme) pkg_free(scheme); + if(scheme) + pkg_free(scheme); return -1; } -struct db_scheme *avp_get_db_scheme (str *name) +struct db_scheme *avp_get_db_scheme(str *name) { struct db_scheme *scheme; - for( scheme=db_scheme_list ; scheme ; scheme=scheme->next ) - if ( name->len==scheme->name.len && - !strcasecmp( name->s, scheme->name.s) ) + for(scheme = db_scheme_list; scheme; scheme = scheme->next) + if(name->len == scheme->name.len + && !strcasecmp(name->s, scheme->name.s)) return scheme; return 0; } -static inline int set_table( const str *table, char *func) +static inline int set_table(const str *table, char *func) { - if (table && table->s) - { - if ( avpops_dbf.use_table( db_hdl, table)<0 ) - { - LM_ERR("db-%s: cannot set table \"%.*s\"\n", func, table->len, table->s); + if(table && table->s) { + if(avpops_dbf.use_table(db_hdl, table) < 0) { + LM_ERR("db-%s: cannot set table \"%.*s\"\n", func, table->len, + table->s); return -1; } } else { - if ( avpops_dbf.use_table( db_hdl, &def_table)<0 ) - { - LM_ERR("db-%s: cannot set table \"%.*s\"\n", func, def_table.len, def_table.s); + if(avpops_dbf.use_table(db_hdl, &def_table) < 0) { + LM_ERR("db-%s: cannot set table \"%.*s\"\n", func, def_table.len, + def_table.s); return -1; } } @@ -174,110 +165,107 @@ static inline int set_table( const str *table, char *func) } - -static inline int prepare_selection( str *uuid, str *username, str *domain, - char *attr, struct db_scheme *scheme) +static inline int prepare_selection(str *uuid, str *username, str *domain, + char *attr, struct db_scheme *scheme) { unsigned int nr_keys_cmp; nr_keys_cmp = 0; - if (uuid) - { + if(uuid) { /* uuid column */ - keys_cmp[ nr_keys_cmp ] = - (scheme&&scheme->uuid_col.s)?&scheme->uuid_col:db_columns[0]; - vals_cmp[ nr_keys_cmp ].type = DB1_STR; - vals_cmp[ nr_keys_cmp ].nul = 0; - vals_cmp[ nr_keys_cmp ].val.str_val = *uuid; + keys_cmp[nr_keys_cmp] = (scheme && scheme->uuid_col.s) + ? &scheme->uuid_col + : db_columns[0]; + vals_cmp[nr_keys_cmp].type = DB1_STR; + vals_cmp[nr_keys_cmp].nul = 0; + vals_cmp[nr_keys_cmp].val.str_val = *uuid; nr_keys_cmp++; } else { - if (username) - { + if(username) { /* username column */ - keys_cmp[ nr_keys_cmp ] = - (scheme&&scheme->username_col.s)?&scheme->username_col:db_columns[4]; - vals_cmp[ nr_keys_cmp ].type = DB1_STR; - vals_cmp[ nr_keys_cmp ].nul = 0; - vals_cmp[ nr_keys_cmp ].val.str_val = *username; + keys_cmp[nr_keys_cmp] = (scheme && scheme->username_col.s) + ? &scheme->username_col + : db_columns[4]; + vals_cmp[nr_keys_cmp].type = DB1_STR; + vals_cmp[nr_keys_cmp].nul = 0; + vals_cmp[nr_keys_cmp].val.str_val = *username; nr_keys_cmp++; } - if (domain) - { + if(domain) { /* domain column */ - keys_cmp[ nr_keys_cmp ] = - (scheme&&scheme->domain_col.s)?&scheme->domain_col:db_columns[5]; - vals_cmp[ nr_keys_cmp ].type = DB1_STR; - vals_cmp[ nr_keys_cmp ].nul = 0; - vals_cmp[ nr_keys_cmp ].val.str_val = *domain; + keys_cmp[nr_keys_cmp] = (scheme && scheme->domain_col.s) + ? &scheme->domain_col + : db_columns[5]; + vals_cmp[nr_keys_cmp].type = DB1_STR; + vals_cmp[nr_keys_cmp].nul = 0; + vals_cmp[nr_keys_cmp].val.str_val = *domain; nr_keys_cmp++; } } - if (attr && scheme==0) - { + if(attr && scheme == 0) { /* attribute name column */ - keys_cmp[ nr_keys_cmp ] = db_columns[1]; - vals_cmp[ nr_keys_cmp ].type = DB1_STRING; - vals_cmp[ nr_keys_cmp ].nul = 0; - vals_cmp[ nr_keys_cmp ].val.string_val = attr; + keys_cmp[nr_keys_cmp] = db_columns[1]; + vals_cmp[nr_keys_cmp].type = DB1_STRING; + vals_cmp[nr_keys_cmp].nul = 0; + vals_cmp[nr_keys_cmp].val.string_val = attr; nr_keys_cmp++; } return nr_keys_cmp; } -db1_res_t *db_load_avp( str *uuid, str *username, str *domain, - char *attr, const str *table, struct db_scheme *scheme) +db1_res_t *db_load_avp(str *uuid, str *username, str *domain, char *attr, + const str *table, struct db_scheme *scheme) { - static db_key_t keys_ret[3]; - unsigned int nr_keys_cmp; - unsigned int nr_keys_ret; - db1_res_t *res = NULL; + static db_key_t keys_ret[3]; + unsigned int nr_keys_cmp; + unsigned int nr_keys_ret; + db1_res_t *res = NULL; /* prepare DB query */ - nr_keys_cmp = prepare_selection( uuid, username, domain, attr, scheme); + nr_keys_cmp = prepare_selection(uuid, username, domain, attr, scheme); /* set table */ - if (set_table( scheme?&scheme->table:table ,"load")!=0) + if(set_table(scheme ? &scheme->table : table, "load") != 0) return 0; /* return keys */ - if (scheme==0) - { + if(scheme == 0) { keys_ret[0] = db_columns[2]; /*value*/ keys_ret[1] = db_columns[1]; /*attribute*/ keys_ret[2] = db_columns[3]; /*type*/ nr_keys_ret = 3; } else { /* value */ - keys_ret[0] = scheme->value_col.s?&scheme->value_col:db_columns[2]; + keys_ret[0] = scheme->value_col.s ? &scheme->value_col : db_columns[2]; nr_keys_ret = 1; } /* do the DB query */ - if ( avpops_dbf.query( db_hdl, keys_cmp, 0/*op*/, vals_cmp, keys_ret, - nr_keys_cmp, nr_keys_ret, 0/*order*/, &res) < 0) + if(avpops_dbf.query(db_hdl, keys_cmp, 0 /*op*/, vals_cmp, keys_ret, + nr_keys_cmp, nr_keys_ret, 0 /*order*/, &res) + < 0) return 0; return res; } -void db_close_query( db1_res_t *res ) +void db_close_query(db1_res_t *res) { LM_DBG("close avp query\n"); - avpops_dbf.free_result( db_hdl, res); + avpops_dbf.free_result(db_hdl, res); } -int db_store_avp( db_key_t *keys, db_val_t *vals, int n, const str *table) +int db_store_avp(db_key_t *keys, db_val_t *vals, int n, const str *table) { int r; - if (set_table( table ,"store")!=0) + if(set_table(table, "store") != 0) return -1; - r = avpops_dbf.insert( db_hdl, keys, vals, n); - if (r<0) - { + r = avpops_dbf.insert(db_hdl, keys, vals, n); + if(r < 0) { LM_ERR("insert failed\n"); return -1; } @@ -285,38 +273,36 @@ int db_store_avp( db_key_t *keys, db_val_t *vals, int n, const str *table) } - -int db_delete_avp( str *uuid, str *username, str *domain, char *attr, - const str *table) +int db_delete_avp( + str *uuid, str *username, str *domain, char *attr, const str *table) { - unsigned int nr_keys_cmp; + unsigned int nr_keys_cmp; /* prepare DB query */ - nr_keys_cmp = prepare_selection( uuid, username, domain, attr, 0); + nr_keys_cmp = prepare_selection(uuid, username, domain, attr, 0); /* set table */ - if (set_table( table ,"delete")!=0) + if(set_table(table, "delete") != 0) return -1; /* do the DB query */ - if ( avpops_dbf.delete( db_hdl, keys_cmp, 0, vals_cmp, nr_keys_cmp) < 0) + if(avpops_dbf.delete(db_hdl, keys_cmp, 0, vals_cmp, nr_keys_cmp) < 0) return 0; return 0; } -int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t* dest) +int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t *dest) { int_str avp_val; int_str avp_name; unsigned short avp_type; - db1_res_t* db_res = NULL; + db1_res_t *db_res = NULL; int i, j; - pvname_list_t* crt; + pvname_list_t *crt; static str query_str; - if(query==NULL) - { + if(query == NULL) { LM_ERR("bad parameter\n"); return -1; } @@ -324,104 +310,96 @@ int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t* dest) query_str.s = query; query_str.len = strlen(query); - if(avpops_dbf.raw_query(db_hdl, &query_str, &db_res)!=0) - { + if(avpops_dbf.raw_query(db_hdl, &query_str, &db_res) != 0) { LM_ERR("cannot do the query\n"); return -1; } - if(db_res==NULL || RES_ROW_N(db_res)<=0 || RES_COL_N(db_res)<=0) - { + if(db_res == NULL || RES_ROW_N(db_res) <= 0 || RES_COL_N(db_res) <= 0) { LM_DBG("no result after query\n"); - db_close_query( db_res ); + db_close_query(db_res); return -2; } LM_DBG("rows [%d]\n", RES_ROW_N(db_res)); /* reverse order of rows so that first row get's in front of avp list */ - for(i = RES_ROW_N(db_res)-1; i >= 0; i--) - { + for(i = RES_ROW_N(db_res) - 1; i >= 0; i--) { LM_DBG("row [%d]\n", i); crt = dest; - for(j = 0; j < RES_COL_N(db_res); j++) - { + for(j = 0; j < RES_COL_N(db_res); j++) { if(RES_ROWS(db_res)[i].values[j].nul) goto next_avp; avp_type = 0; - if(crt==NULL) - { - avp_name.n = j+1; + if(crt == NULL) { + avp_name.n = j + 1; } else { - if(pv_get_avp_name(msg, &crt->sname.pvp, &avp_name, - &avp_type)!=0) - { + if(pv_get_avp_name(msg, &crt->sname.pvp, &avp_name, &avp_type) + != 0) { LM_ERR("cant get avp name [%d/%d]\n", i, j); goto next_avp; } } - switch(RES_ROWS(db_res)[i].values[j].type) - { + switch(RES_ROWS(db_res)[i].values[j].type) { case DB1_STRING: avp_type |= AVP_VAL_STR; - avp_val.s.s= - (char*)RES_ROWS(db_res)[i].values[j].val.string_val; - avp_val.s.len=strlen(avp_val.s.s); - if(avp_val.s.len<=0) + avp_val.s.s = (char *)RES_ROWS(db_res)[i] + .values[j] + .val.string_val; + avp_val.s.len = strlen(avp_val.s.s); + if(avp_val.s.len <= 0) goto next_avp; - break; + break; case DB1_STR: avp_type |= AVP_VAL_STR; - avp_val.s.len= - RES_ROWS(db_res)[i].values[j].val.str_val.len; - avp_val.s.s= - (char*)RES_ROWS(db_res)[i].values[j].val.str_val.s; - if(avp_val.s.len<=0) + avp_val.s.len = + RES_ROWS(db_res)[i].values[j].val.str_val.len; + avp_val.s.s = + (char *)RES_ROWS(db_res)[i].values[j].val.str_val.s; + if(avp_val.s.len <= 0) goto next_avp; - break; + break; case DB1_BLOB: avp_type |= AVP_VAL_STR; - avp_val.s.len= - RES_ROWS(db_res)[i].values[j].val.blob_val.len; - avp_val.s.s= - (char*)RES_ROWS(db_res)[i].values[j].val.blob_val.s; - if(avp_val.s.len<=0) + avp_val.s.len = + RES_ROWS(db_res)[i].values[j].val.blob_val.len; + avp_val.s.s = (char *)RES_ROWS(db_res)[i] + .values[j] + .val.blob_val.s; + if(avp_val.s.len <= 0) goto next_avp; - break; + break; case DB1_INT: - avp_val.n - = (long)RES_ROWS(db_res)[i].values[j].val.int_val; - break; + avp_val.n = (long)RES_ROWS(db_res)[i].values[j].val.int_val; + break; case DB1_BIGINT: - avp_val.n - = (long)RES_ROWS(db_res)[i].values[j].val.ll_val; - break; + avp_val.n = (long)RES_ROWS(db_res)[i].values[j].val.ll_val; + break; case DB1_DATETIME: - avp_val.n - = (long)(uint64_t)RES_ROWS(db_res)[i].values[j].val.time_val; - break; + avp_val.n = (long)(uint64_t)RES_ROWS(db_res)[i] + .values[j] + .val.time_val; + break; case DB1_BITMAP: - avp_val.n - = (long)RES_ROWS(db_res)[i].values[j].val.bitmap_val; - break; + avp_val.n = + (long)RES_ROWS(db_res)[i].values[j].val.bitmap_val; + break; default: goto next_avp; } - if(add_avp(avp_type, avp_name, avp_val)!=0) - { + if(add_avp(avp_type, avp_name, avp_val) != 0) { LM_ERR("unable to add avp\n"); - db_close_query( db_res ); + db_close_query(db_res); return -1; } -next_avp: - if(crt) - { + next_avp: + if(crt) { crt = crt->next; - if(crt==NULL) + if(crt == NULL) break; } } } - db_close_query( db_res ); + db_close_query(db_res); return 0; } diff --git a/src/modules/avpops/avpops_db.h b/src/modules/avpops/avpops_db.h index 57031b865ca..aaa829a02b6 100644 --- a/src/modules/avpops/avpops_db.h +++ b/src/modules/avpops/avpops_db.h @@ -20,7 +20,6 @@ */ - #ifndef _AVP_OPS_DB_H_ #define _AVP_OPS_DB_H_ @@ -45,24 +44,24 @@ struct db_scheme }; -int avpops_db_bind(const str* db_url); +int avpops_db_bind(const str *db_url); -int avpops_db_init(const str* db_url, const str* db_table, str **db_columns); +int avpops_db_init(const str *db_url, const str *db_table, str **db_columns); -db1_res_t *db_load_avp( str *uuid, str *username, str *domain, - char *attr, const str *table, struct db_scheme *scheme); +db1_res_t *db_load_avp(str *uuid, str *username, str *domain, char *attr, + const str *table, struct db_scheme *scheme); -void db_close_query( db1_res_t *res ); +void db_close_query(db1_res_t *res); -int db_store_avp( db_key_t *keys, db_val_t *vals, int n, const str *table); +int db_store_avp(db_key_t *keys, db_val_t *vals, int n, const str *table); -int db_delete_avp( str *uuid, str *username, str *domain, - char *attr, const str *table); +int db_delete_avp( + str *uuid, str *username, str *domain, char *attr, const str *table); -int db_query_avp(struct sip_msg* msg, char *query, pvname_list_t* dest); +int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t *dest); -int avp_add_db_scheme( modparam_t type, void* val); +int avp_add_db_scheme(modparam_t type, void *val); -struct db_scheme *avp_get_db_scheme( str *name ); +struct db_scheme *avp_get_db_scheme(str *name); #endif diff --git a/src/modules/avpops/avpops_impl.c b/src/modules/avpops/avpops_impl.c index ff067aa79e0..99f2b3d31de 100644 --- a/src/modules/avpops/avpops_impl.c +++ b/src/modules/avpops/avpops_impl.c @@ -44,17 +44,17 @@ #define avpops_str2int_str(a, b) \ - do { \ - if(a.s==0) \ - b.n = a.len; \ - else \ - b.s = a; \ + do { \ + if(a.s == 0) \ + b.n = a.len; \ + else \ + b.s = a; \ } while(0) -static db_key_t store_keys[6]; -static db_val_t store_vals[6]; -static str empty={"",0}; +static db_key_t store_keys[6]; +static db_val_t store_vals[6]; +static str empty = {"", 0}; #define AVP_PRINTBUF_SIZE 1024 @@ -65,27 +65,27 @@ void init_store_avps(str **db_columns) /* unique user id */ store_keys[0] = db_columns[0]; /*uuid*/ store_vals[0].type = DB1_STR; - store_vals[0].nul = 0; + store_vals[0].nul = 0; /* attribute */ store_keys[1] = db_columns[1]; /*attribute*/ store_vals[1].type = DB1_STR; - store_vals[1].nul = 0; + store_vals[1].nul = 0; /* value */ store_keys[2] = db_columns[2]; /*value*/ store_vals[2].type = DB1_STR; - store_vals[2].nul = 0; + store_vals[2].nul = 0; /* type */ store_keys[3] = db_columns[3]; /*type*/ store_vals[3].type = DB1_INT; - store_vals[3].nul = 0; + store_vals[3].nul = 0; /* user name */ store_keys[4] = db_columns[4]; /*username*/ store_vals[4].type = DB1_STR; - store_vals[4].nul = 0; + store_vals[4].nul = 0; /* domain */ store_keys[5] = db_columns[5]; /*domain*/ store_vals[5].type = DB1_STR; - store_vals[5].nul = 0; + store_vals[5].nul = 0; } @@ -94,52 +94,52 @@ void init_store_avps(str **db_columns) * value 2 - attr type */ static int dbrow2avp(struct db_row *row, struct db_param *dbp, int_str attr, - int attr_type, int just_val_flags) + int attr_type, int just_val_flags) { unsigned int uint; - int db_flags; - str atmp; - str vtmp; + int db_flags; + str atmp; + str vtmp; int_str avp_attr; int_str avp_val; int flags; flags = dbp->a.opd; - if (just_val_flags==-1) - { + if(just_val_flags == -1) { /* check for null fields into the row */ - if (row->values[0].nul || row->values[1].nul || row->values[2].nul ) - { + if(row->values[0].nul || row->values[1].nul || row->values[2].nul) { LM_ERR("dbrow contains NULL fields\n"); return -1; } /* check the value types */ - if ( (row->values[0].type!=DB1_STRING && row->values[0].type!=DB1_STR) - || (row->values[1].type!=DB1_STRING && row->values[1].type!=DB1_STR) - || row->values[2].type!=DB1_INT ) - { + if((row->values[0].type != DB1_STRING && row->values[0].type != DB1_STR) + || (row->values[1].type != DB1_STRING + && row->values[1].type != DB1_STR) + || row->values[2].type != DB1_INT) { LM_ERR("wrong field types in dbrow\n"); return -1; } /* check the content of flag field */ uint = (unsigned int)row->values[2].val.int_val; - db_flags = ((uint&AVPOPS_DB_NAME_INT)?0:AVP_NAME_STR) | - ((uint&AVPOPS_DB_VAL_INT)?0:AVP_VAL_STR); - - LM_DBG("db_flags=%d, flags=%d\n",db_flags,flags); + db_flags = ((uint & AVPOPS_DB_NAME_INT) ? 0 : AVP_NAME_STR) + | ((uint & AVPOPS_DB_VAL_INT) ? 0 : AVP_VAL_STR); + + LM_DBG("db_flags=%d, flags=%d\n", db_flags, flags); /* does the avp type match ? */ - if(!((flags&(AVPOPS_VAL_INT|AVPOPS_VAL_STR))==0 || - ((flags&AVPOPS_VAL_INT)&&((db_flags&AVP_NAME_STR)==0)) || - ((flags&AVPOPS_VAL_STR)&&(db_flags&AVP_NAME_STR)))) + if(!((flags & (AVPOPS_VAL_INT | AVPOPS_VAL_STR)) == 0 + || ((flags & AVPOPS_VAL_INT) + && ((db_flags & AVP_NAME_STR) == 0)) + || ((flags & AVPOPS_VAL_STR) && (db_flags & AVP_NAME_STR)))) return -2; } else { /* check the validity of value column */ - if (row->values[0].nul || (row->values[0].type!=DB1_STRING && - row->values[0].type!=DB1_STR && row->values[0].type!=DB1_INT) ) - { + if(row->values[0].nul + || (row->values[0].type != DB1_STRING + && row->values[0].type != DB1_STR + && row->values[0].type != DB1_INT)) { LM_ERR("empty or wrong type for 'value' using scheme\n"); return -1; } @@ -147,28 +147,24 @@ static int dbrow2avp(struct db_row *row, struct db_param *dbp, int_str attr, } /* is the avp name already known? */ - if ( (flags&AVPOPS_VAL_NONE)==0 ) - { + if((flags & AVPOPS_VAL_NONE) == 0) { /* use the name */ avp_attr = attr; db_flags |= attr_type; } else { /* take the name from db response */ - if (row->values[1].type==DB1_STRING) - { - atmp.s = (char*)row->values[1].val.string_val; + if(row->values[1].type == DB1_STRING) { + atmp.s = (char *)row->values[1].val.string_val; atmp.len = strlen(atmp.s); } else { atmp = row->values[1].val.str_val; } - if (db_flags&AVP_NAME_STR) - { + if(db_flags & AVP_NAME_STR) { /* name is string */ avp_attr.s = atmp; } else { /* name is ID */ - if (str2int( &atmp, &uint)==-1) - { + if(str2int(&atmp, &uint) == -1) { LM_ERR("name is not ID as flags say <%s>\n", atmp.s); return -1; } @@ -177,27 +173,26 @@ static int dbrow2avp(struct db_row *row, struct db_param *dbp, int_str attr, } /* now get the value as correct type */ - if (row->values[0].type==DB1_STRING) - { - vtmp.s = (char*)row->values[0].val.string_val; + if(row->values[0].type == DB1_STRING) { + vtmp.s = (char *)row->values[0].val.string_val; vtmp.len = strlen(vtmp.s); - } else if (row->values[0].type==DB1_STR){ + } else if(row->values[0].type == DB1_STR) { vtmp = row->values[0].val.str_val; } else { vtmp.s = 0; vtmp.len = 0; } - if (db_flags&AVP_VAL_STR) { + if(db_flags & AVP_VAL_STR) { /* value must be saved as string */ - if (row->values[0].type==DB1_INT) { - vtmp.s = int2str( (unsigned long)row->values[0].val.int_val, - &vtmp.len); + if(row->values[0].type == DB1_INT) { + vtmp.s = int2str( + (unsigned long)row->values[0].val.int_val, &vtmp.len); } avp_val.s = vtmp; } else { /* value must be saved as integer */ - if (row->values[0].type!=DB1_INT) { - if (vtmp.len==0 || vtmp.s==0 || str2int(&vtmp, &uint)==-1) { + if(row->values[0].type != DB1_INT) { + if(vtmp.len == 0 || vtmp.s == 0 || str2int(&vtmp, &uint) == -1) { LM_ERR("value is not int as flags say <%s>\n", vtmp.s); return -1; } @@ -210,28 +205,25 @@ static int dbrow2avp(struct db_row *row, struct db_param *dbp, int_str attr, /* added the avp */ db_flags |= AVP_IS_IN_DB; /* set script flags */ - db_flags |= dbp->a.u.sval->pvp.pvn.u.isname.type&0xff00; - return add_avp( (unsigned short)db_flags, avp_attr, avp_val); + db_flags |= dbp->a.u.sval->pvp.pvn.u.isname.type & 0xff00; + return add_avp((unsigned short)db_flags, avp_attr, avp_val); } -static inline void int_str2db_val( int_str is_val, str *val, int is_s) +static inline void int_str2db_val(int_str is_val, str *val, int is_s) { - if (is_s) - { + if(is_s) { /* val is string */ *val = is_val.s; } else { /* val is integer */ - val->s = - int2str((unsigned long)is_val.n, &val->len); + val->s = int2str((unsigned long)is_val.n, &val->len); } } -static int avpops_get_aname(struct sip_msg* msg, struct fis_param *ap, +static int avpops_get_aname(struct sip_msg *msg, struct fis_param *ap, int_str *avp_name, unsigned short *name_type) { - if(ap==NULL || avp_name==NULL || name_type==NULL) - { + if(ap == NULL || avp_name == NULL || name_type == NULL) { LM_ERR("bad parameters\n"); return -1; } @@ -239,23 +231,23 @@ static int avpops_get_aname(struct sip_msg* msg, struct fis_param *ap, return pv_get_avp_name(msg, &ap->u.sval->pvp, avp_name, name_type); } -#define AVPOPS_ATTR_LEN 64 +#define AVPOPS_ATTR_LEN 64 static char avpops_attr_buf[AVPOPS_ATTR_LEN]; -int ops_dbload_avps (struct sip_msg* msg, struct fis_param *sp, - struct db_param *dbp, int use_domain) +int ops_dbload_avps(struct sip_msg *msg, struct fis_param *sp, + struct db_param *dbp, int use_domain) { - struct sip_uri uri; - db1_res_t *res = NULL; - str uuid; - int i, n, sh_flg; + struct sip_uri uri; + db1_res_t *res = NULL; + str uuid; + int i, n, sh_flg; str *s0, *s1, *s2; int_str avp_name; int avp_type = 0; pv_value_t xvalue; s0 = s1 = s2 = NULL; - if (!((sp->opd&AVPOPS_VAL_PVAR)||(sp->opd&AVPOPS_VAL_STR))) { + if(!((sp->opd & AVPOPS_VAL_PVAR) || (sp->opd & AVPOPS_VAL_STR))) { LM_CRIT("invalid flag combination (%d/%d)\n", sp->opd, sp->ops); goto error; } @@ -263,68 +255,56 @@ int ops_dbload_avps (struct sip_msg* msg, struct fis_param *sp, memset(&xvalue, 0, sizeof(pv_value_t)); /* get uuid from avp */ - if (sp->opd&AVPOPS_VAL_PVAR) - { - if(pv_get_spec_value(msg, sp->u.sval, &xvalue)!=0) - { + if(sp->opd & AVPOPS_VAL_PVAR) { + if(pv_get_spec_value(msg, sp->u.sval, &xvalue) != 0) { LM_CRIT("failed to get PVAR value (%d/%d)\n", sp->opd, sp->ops); goto error; } - if(xvalue.flags&(PV_VAL_NULL|PV_VAL_EMPTY)) - { + if(xvalue.flags & (PV_VAL_NULL | PV_VAL_EMPTY)) { LM_ERR("no value for first param\n"); goto error; } uuid = xvalue.rs; } else { - uuid.s = sp->u.s.s; + uuid.s = sp->u.s.s; uuid.len = sp->u.s.len; } - - if(sp->opd&AVPOPS_FLAG_UUID0) - { + + if(sp->opd & AVPOPS_FLAG_UUID0) { s0 = &uuid; } else { /* parse uri */ - if (parse_uri(uuid.s, uuid.len, &uri)<0) - { + if(parse_uri(uuid.s, uuid.len, &uri) < 0) { LM_ERR("failed to parse uri\n"); goto error; } /* check uri */ - if(!uri.user.s|| !uri.user.len|| !uri.host.len|| !uri.host.s) - { + if(!uri.user.s || !uri.user.len || !uri.host.len || !uri.host.s) { LM_ERR("incomplete uri <%.*s>\n", uuid.len, uuid.s); goto error; } - if((sp->opd&AVPOPS_FLAG_URI0)||(sp->opd&AVPOPS_FLAG_USER0)) + if((sp->opd & AVPOPS_FLAG_URI0) || (sp->opd & AVPOPS_FLAG_USER0)) s1 = &uri.user; - if((sp->opd&AVPOPS_FLAG_URI0)||(sp->opd&AVPOPS_FLAG_DOMAIN0)) + if((sp->opd & AVPOPS_FLAG_URI0) || (sp->opd & AVPOPS_FLAG_DOMAIN0)) s2 = &uri.host; } /* is dynamic avp name ? */ - if(dbp->a.type==AVPOPS_VAL_PVAR) - { - if(pv_has_dname(dbp->a.u.sval)) - { - if(pv_get_spec_name(msg, &(dbp->a.u.sval->pvp), &xvalue)!=0) - { + if(dbp->a.type == AVPOPS_VAL_PVAR) { + if(pv_has_dname(dbp->a.u.sval)) { + if(pv_get_spec_name(msg, &(dbp->a.u.sval->pvp), &xvalue) != 0) { LM_CRIT("failed to get value for P2\n"); goto error; } - if(xvalue.flags&(PV_VAL_NULL|PV_VAL_EMPTY)) - { + if(xvalue.flags & (PV_VAL_NULL | PV_VAL_EMPTY)) { LM_ERR("no value for p2\n"); goto error; } - if(xvalue.flags&PV_VAL_STR) - { - if(xvalue.rs.len>=AVPOPS_ATTR_LEN) - { - LM_ERR("name too long [%d/%.*s...]\n", - xvalue.rs.len, 16, xvalue.rs.s); + if(xvalue.flags & PV_VAL_STR) { + if(xvalue.rs.len >= AVPOPS_ATTR_LEN) { + LM_ERR("name too long [%d/%.*s...]\n", xvalue.rs.len, 16, + xvalue.rs.s); goto error; } dbp->sa.s = avpops_attr_buf; @@ -339,29 +319,24 @@ int ops_dbload_avps (struct sip_msg* msg, struct fis_param *sp, } /* do DB query */ - res = db_load_avp( s0, s1, - ((use_domain)||(sp->opd&AVPOPS_FLAG_DOMAIN0))?s2:0, + res = db_load_avp(s0, s1, + ((use_domain) || (sp->opd & AVPOPS_FLAG_DOMAIN0)) ? s2 : 0, dbp->sa.s, &dbp->table, dbp->scheme); /* res query ? */ - if (res==0) - { + if(res == 0) { LM_ERR("db_load failed\n"); goto error; } - sh_flg = (dbp->scheme)?dbp->scheme->db_flags:-1; + sh_flg = (dbp->scheme) ? dbp->scheme->db_flags : -1; /* process the results */ - for( n=0,i=0 ; in ; i++) - { + for(n = 0, i = 0; i < res->n; i++) { /* validate row */ memset(&avp_name, 0, sizeof(int_str)); - if(dbp->a.type==AVPOPS_VAL_PVAR) - { - if(pv_has_dname(dbp->a.u.sval)) - { - if(xvalue.flags&PV_TYPE_INT) - { + if(dbp->a.type == AVPOPS_VAL_PVAR) { + if(pv_has_dname(dbp->a.u.sval)) { + if(xvalue.flags & PV_TYPE_INT) { avp_name.n = xvalue.ri; } else { avpops_str2int_str(xvalue.rs, avp_name); @@ -373,99 +348,87 @@ int ops_dbload_avps (struct sip_msg* msg, struct fis_param *sp, } } //if ( dbrow2avp( &res->rows[i], dbp->a.opd, avp_name, sh_flg) < 0 ) - if ( dbrow2avp( &res->rows[i], dbp, avp_name, avp_type, sh_flg) < 0 ) + if(dbrow2avp(&res->rows[i], dbp, avp_name, avp_type, sh_flg) < 0) continue; n++; } - db_close_query( res ); + db_close_query(res); - LM_DBG("loaded avps = %d\n",n); + LM_DBG("loaded avps = %d\n", n); - return n?1:-1; + return n ? 1 : -1; error: return -1; } -int ops_dbdelete_avps (struct sip_msg* msg, struct fis_param *sp, - struct db_param *dbp, int use_domain) +int ops_dbdelete_avps(struct sip_msg *msg, struct fis_param *sp, + struct db_param *dbp, int use_domain) { - struct sip_uri uri; - int res; - str uuid; + struct sip_uri uri; + int res; + str uuid; pv_value_t xvalue; str *s0, *s1, *s2; s0 = s1 = s2 = NULL; - if (!((sp->opd&AVPOPS_VAL_PVAR)||(sp->opd&AVPOPS_VAL_STR))) { + if(!((sp->opd & AVPOPS_VAL_PVAR) || (sp->opd & AVPOPS_VAL_STR))) { LM_CRIT("invalid flag combination (%d/%d)\n", sp->opd, sp->ops); goto error; } /* get uuid from avp */ - if (sp->opd&AVPOPS_VAL_PVAR) - { - if(pv_get_spec_value(msg, sp->u.sval, &xvalue)!=0) - { + if(sp->opd & AVPOPS_VAL_PVAR) { + if(pv_get_spec_value(msg, sp->u.sval, &xvalue) != 0) { LM_CRIT("failed to get PVAR value (%d/%d)\n", sp->opd, sp->ops); goto error; } - if(xvalue.flags&(PV_VAL_NULL|PV_VAL_EMPTY)) - { + if(xvalue.flags & (PV_VAL_NULL | PV_VAL_EMPTY)) { LM_ERR("no value for first param\n"); goto error; } uuid = xvalue.rs; } else { - uuid.s = sp->u.s.s; + uuid.s = sp->u.s.s; uuid.len = sp->u.s.len; } - - if(sp->opd&AVPOPS_FLAG_UUID0) - { + + if(sp->opd & AVPOPS_FLAG_UUID0) { s0 = &uuid; } else { /* parse uri */ - if (parse_uri(uuid.s, uuid.len, &uri)<0) - { + if(parse_uri(uuid.s, uuid.len, &uri) < 0) { LM_ERR("failed to parse uri\n"); goto error; } /* check uri */ - if(!uri.user.s|| !uri.user.len|| !uri.host.len|| !uri.host.s) - { + if(!uri.user.s || !uri.user.len || !uri.host.len || !uri.host.s) { LM_ERR("incomplete uri <%.*s>\n", uuid.len, uuid.s); goto error; } - if((sp->opd&AVPOPS_FLAG_URI0)||(sp->opd&AVPOPS_FLAG_USER0)) + if((sp->opd & AVPOPS_FLAG_URI0) || (sp->opd & AVPOPS_FLAG_USER0)) s1 = &uri.user; - if((sp->opd&AVPOPS_FLAG_URI0)||(sp->opd&AVPOPS_FLAG_DOMAIN0)) + if((sp->opd & AVPOPS_FLAG_URI0) || (sp->opd & AVPOPS_FLAG_DOMAIN0)) s2 = &uri.host; } /* is dynamic avp name ? */ - if(dbp->a.type==AVPOPS_VAL_PVAR) - { - if(pv_has_dname(dbp->a.u.sval)) - { - if(pv_get_spec_name(msg, &(dbp->a.u.sval->pvp), &xvalue)!=0) - { + if(dbp->a.type == AVPOPS_VAL_PVAR) { + if(pv_has_dname(dbp->a.u.sval)) { + if(pv_get_spec_name(msg, &(dbp->a.u.sval->pvp), &xvalue) != 0) { LM_CRIT("failed to get value for P2\n"); goto error; } - if(xvalue.flags&(PV_VAL_NULL|PV_VAL_EMPTY)) - { + if(xvalue.flags & (PV_VAL_NULL | PV_VAL_EMPTY)) { LM_INFO("no value for p2\n"); goto error; } - if(xvalue.flags&PV_VAL_STR) - { - if(xvalue.rs.len>=AVPOPS_ATTR_LEN) - { - LM_ERR("name too long [%d/%.*s...]\n", - xvalue.rs.len, 16, xvalue.rs.s); + if(xvalue.flags & PV_VAL_STR) { + if(xvalue.rs.len >= AVPOPS_ATTR_LEN) { + LM_ERR("name too long [%d/%.*s...]\n", xvalue.rs.len, 16, + xvalue.rs.s); goto error; } dbp->sa.s = avpops_attr_buf; @@ -481,12 +444,11 @@ int ops_dbdelete_avps (struct sip_msg* msg, struct fis_param *sp, /* do DB delete */ res = db_delete_avp(s0, s1, - (use_domain||(sp->opd&AVPOPS_FLAG_DOMAIN0))?s2:0, - dbp->sa.s, &dbp->table); + (use_domain || (sp->opd & AVPOPS_FLAG_DOMAIN0)) ? s2 : 0, dbp->sa.s, + &dbp->table); /* res ? */ - if (res<0) - { + if(res < 0) { LM_ERR("db_delete failed\n"); goto error; } @@ -497,115 +459,102 @@ int ops_dbdelete_avps (struct sip_msg* msg, struct fis_param *sp, } -int ops_dbstore_avps (struct sip_msg* msg, struct fis_param *sp, - struct db_param *dbp, int use_domain) +int ops_dbstore_avps(struct sip_msg *msg, struct fis_param *sp, + struct db_param *dbp, int use_domain) { struct search_state st; - struct sip_uri uri; + struct sip_uri uri; avp_list_t avp_list; - struct usr_avp *avp; - unsigned short name_type; - int_str avp_name = {0}; - int_str i_s; - str uuid; - int keys_nr; - int n; + struct usr_avp *avp; + unsigned short name_type; + int_str avp_name = {0}; + int_str i_s; + str uuid; + int keys_nr; + int n; pv_value_t xvalue; str *s0, *s1, *s2; str *sn; s0 = s1 = s2 = NULL; name_type = 0; - if (!((sp->opd&AVPOPS_VAL_PVAR)||(sp->opd&AVPOPS_VAL_STR))) { + if(!((sp->opd & AVPOPS_VAL_PVAR) || (sp->opd & AVPOPS_VAL_STR))) { LM_CRIT("invalid flag combination (%d/%d)\n", sp->opd, sp->ops); goto error; } keys_nr = 6; /* uuid, avp name, avp val, avp type, user, domain */ - + /* get uuid from avp */ - if (sp->opd&AVPOPS_VAL_PVAR) - { - if(pv_get_spec_value(msg, sp->u.sval, &xvalue)!=0) - { + if(sp->opd & AVPOPS_VAL_PVAR) { + if(pv_get_spec_value(msg, sp->u.sval, &xvalue) != 0) { LM_CRIT("failed to get PVAR value (%d/%d)\n", sp->opd, sp->ops); goto error; } - if(xvalue.flags&(PV_VAL_NULL|PV_VAL_EMPTY)) - { + if(xvalue.flags & (PV_VAL_NULL | PV_VAL_EMPTY)) { LM_ERR("no value for first param\n"); goto error; } uuid = xvalue.rs; } else { - uuid.s = sp->u.s.s; + uuid.s = sp->u.s.s; uuid.len = sp->u.s.len; } - - if(sp->opd&AVPOPS_FLAG_UUID0) - { + + if(sp->opd & AVPOPS_FLAG_UUID0) { s0 = &uuid; } else { /* parse uri */ - if (parse_uri(uuid.s, uuid.len, &uri)<0) - { + if(parse_uri(uuid.s, uuid.len, &uri) < 0) { LM_ERR("failed to parse uri\n"); goto error; } /* check uri */ - if(!uri.user.s|| !uri.user.len|| !uri.host.len|| !uri.host.s) - { + if(!uri.user.s || !uri.user.len || !uri.host.len || !uri.host.s) { LM_ERR("incomplete uri <%.*s>\n", uuid.len, uuid.s); goto error; } - if((sp->opd&AVPOPS_FLAG_URI0)||(sp->opd&AVPOPS_FLAG_USER0)) + if((sp->opd & AVPOPS_FLAG_URI0) || (sp->opd & AVPOPS_FLAG_USER0)) s1 = &uri.user; - if((sp->opd&AVPOPS_FLAG_URI0)||(sp->opd&AVPOPS_FLAG_DOMAIN0)) + if((sp->opd & AVPOPS_FLAG_URI0) || (sp->opd & AVPOPS_FLAG_DOMAIN0)) s2 = &uri.host; } /* set values for keys */ - store_vals[0].val.str_val = (s0)?*s0:empty; - store_vals[4].val.str_val = (s1)?*s1:empty; - if (use_domain || sp->opd&AVPOPS_FLAG_DOMAIN0) - store_vals[5].val.str_val = (s2)?*s2:empty; + store_vals[0].val.str_val = (s0) ? *s0 : empty; + store_vals[4].val.str_val = (s1) ? *s1 : empty; + if(use_domain || sp->opd & AVPOPS_FLAG_DOMAIN0) + store_vals[5].val.str_val = (s2) ? *s2 : empty; /* is dynamic avp name ? */ - if(dbp->a.type==AVPOPS_VAL_PVAR) - { - if(pv_has_dname(dbp->a.u.sval)) - { - if(pv_get_spec_name(msg, &(dbp->a.u.sval->pvp), &xvalue)!=0) - { + if(dbp->a.type == AVPOPS_VAL_PVAR) { + if(pv_has_dname(dbp->a.u.sval)) { + if(pv_get_spec_name(msg, &(dbp->a.u.sval->pvp), &xvalue) != 0) { LM_CRIT("failed to get value for P2\n"); goto error; } - if(xvalue.flags&(PV_VAL_NULL|PV_VAL_EMPTY)) - { + if(xvalue.flags & (PV_VAL_NULL | PV_VAL_EMPTY)) { LM_INFO("no value for P2\n"); goto error; } - if(xvalue.flags&PV_TYPE_INT) - { + if(xvalue.flags & PV_TYPE_INT) { name_type = 0; avp_name.n = xvalue.ri; } else { name_type = AVP_NAME_STR; } - if(xvalue.flags&PV_VAL_STR) - { - if(xvalue.rs.len>=AVPOPS_ATTR_LEN) - { - LM_ERR("name too long [%d/%.*s...]\n", - xvalue.rs.len, 16, xvalue.rs.s); - goto error; - } - dbp->sa.s = avpops_attr_buf; - memcpy(dbp->sa.s, xvalue.rs.s, xvalue.rs.len); - dbp->sa.len = xvalue.rs.len; - dbp->sa.s[dbp->sa.len] = '\0'; - avp_name.s = dbp->sa; + if(xvalue.flags & PV_VAL_STR) { + if(xvalue.rs.len >= AVPOPS_ATTR_LEN) { + LM_ERR("name too long [%d/%.*s...]\n", xvalue.rs.len, 16, + xvalue.rs.s); + goto error; + } + dbp->sa.s = avpops_attr_buf; + memcpy(dbp->sa.s, xvalue.rs.s, xvalue.rs.len); + dbp->sa.len = xvalue.rs.len; + dbp->sa.s[dbp->sa.len] = '\0'; + avp_name.s = dbp->sa; } else { LM_INFO("no string value for p2\n"); goto error; @@ -617,34 +566,31 @@ int ops_dbstore_avps (struct sip_msg* msg, struct fis_param *sp, } /* set the script flags */ - if(dbp->a.type==AVPOPS_VAL_PVAR) - name_type |= dbp->a.u.sval->pvp.pvn.u.isname.type&0xff00; - + if(dbp->a.type == AVPOPS_VAL_PVAR) + name_type |= dbp->a.u.sval->pvp.pvn.u.isname.type & 0xff00; + /* set uuid/(username and domain) fields */ - n =0 ; + n = 0; memset(&st, 0, sizeof(struct search_state)); - if ((dbp->a.opd&AVPOPS_VAL_NONE)==0) - { + if((dbp->a.opd & AVPOPS_VAL_NONE) == 0) { /* avp name is known ->set it and its type */ store_vals[1].val.str_val = dbp->sa; /*attr name*/ - avp = search_first_avp( name_type, avp_name, &i_s, &st); - for( ; avp; avp=search_next_avp( &st, &i_s)) - { + avp = search_first_avp(name_type, avp_name, &i_s, &st); + for(; avp; avp = search_next_avp(&st, &i_s)) { /* don't insert avps which were loaded */ - if (avp->flags&AVP_IS_IN_DB) + if(avp->flags & AVP_IS_IN_DB) continue; /* set type */ store_vals[3].val.int_val = - (avp->flags&AVP_NAME_STR?0:AVPOPS_DB_NAME_INT)| - (avp->flags&AVP_VAL_STR?0:AVPOPS_DB_VAL_INT); + (avp->flags & AVP_NAME_STR ? 0 : AVPOPS_DB_NAME_INT) + | (avp->flags & AVP_VAL_STR ? 0 : AVPOPS_DB_VAL_INT); /* set value */ - int_str2db_val( i_s, &store_vals[2].val.str_val, - avp->flags&AVP_VAL_STR); + int_str2db_val( + i_s, &store_vals[2].val.str_val, avp->flags & AVP_VAL_STR); /* save avp */ - if (db_store_avp( store_keys, store_vals, - keys_nr, &dbp->table)==0 ) - { + if(db_store_avp(store_keys, store_vals, keys_nr, &dbp->table) + == 0) { avp->flags |= AVP_IS_IN_DB; n++; } @@ -654,77 +600,75 @@ int ops_dbstore_avps (struct sip_msg* msg, struct fis_param *sp, avp_list = get_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI); avp = avp_list; - for ( ; avp ; avp=avp->next ) - { + for(; avp; avp = avp->next) { /* don't insert avps which were loaded */ - if (avp->flags&AVP_IS_IN_DB) + if(avp->flags & AVP_IS_IN_DB) continue; /* check if type match */ - if ( !( (dbp->a.opd&(AVPOPS_VAL_INT|AVPOPS_VAL_STR))==0 || - ((dbp->a.opd&AVPOPS_VAL_INT)&&((avp->flags&AVP_NAME_STR))==0) - ||((dbp->a.opd&AVPOPS_VAL_STR)&&(avp->flags&AVP_NAME_STR)))) + if(!((dbp->a.opd & (AVPOPS_VAL_INT | AVPOPS_VAL_STR)) == 0 + || ((dbp->a.opd & AVPOPS_VAL_INT) + && ((avp->flags & AVP_NAME_STR)) == 0) + || ((dbp->a.opd & AVPOPS_VAL_STR) + && (avp->flags & AVP_NAME_STR)))) continue; /* set attribute name and type */ - if ( (sn=get_avp_name(avp))==0 ) + if((sn = get_avp_name(avp)) == 0) i_s.n = avp->id; else i_s.s = *sn; - int_str2db_val( i_s, &store_vals[1].val.str_val, - avp->flags&AVP_NAME_STR); + int_str2db_val( + i_s, &store_vals[1].val.str_val, avp->flags & AVP_NAME_STR); store_vals[3].val.int_val = - (avp->flags&AVP_NAME_STR?0:AVPOPS_DB_NAME_INT)| - (avp->flags&AVP_VAL_STR?0:AVPOPS_DB_VAL_INT); + (avp->flags & AVP_NAME_STR ? 0 : AVPOPS_DB_NAME_INT) + | (avp->flags & AVP_VAL_STR ? 0 : AVPOPS_DB_VAL_INT); /* set avp value */ - get_avp_val( avp, &i_s); - int_str2db_val( i_s, &store_vals[2].val.str_val, - avp->flags&AVP_VAL_STR); + get_avp_val(avp, &i_s); + int_str2db_val( + i_s, &store_vals[2].val.str_val, avp->flags & AVP_VAL_STR); /* save avp */ - if (db_store_avp( store_keys, store_vals, - keys_nr, &dbp->table)==0) - { + if(db_store_avp(store_keys, store_vals, keys_nr, &dbp->table) + == 0) { avp->flags |= AVP_IS_IN_DB; n++; } } } - LM_DBG(" %d avps were stored\n",n); + LM_DBG(" %d avps were stored\n", n); - return n==0?-1:1; + return n == 0 ? -1 : 1; error: return -1; } -int ops_dbquery_avps(struct sip_msg* msg, pv_elem_t* query, - pvname_list_t* dest) +int ops_dbquery_avps(struct sip_msg *msg, pv_elem_t *query, pvname_list_t *dest) { int printbuf_len; int r; - if(msg==NULL || query==NULL) - { + if(msg == NULL || query == NULL) { LM_ERR("bad parameters\n"); return -1; } - - printbuf_len = AVP_PRINTBUF_SIZE-1; - if(pv_printf(msg, query, printbuf, &printbuf_len)<0 || printbuf_len<=0) - { + + printbuf_len = AVP_PRINTBUF_SIZE - 1; + if(pv_printf(msg, query, printbuf, &printbuf_len) < 0 + || printbuf_len <= 0) { LM_ERR("cannot print the query\n"); return -1; } LM_DBG("query [%s]\n", printbuf); - + r = db_query_avp(msg, printbuf, dest); - if(r>=0) + if(r >= 0) return 1; return r; } -int ops_delete_avp(struct sip_msg* msg, struct fis_param *ap) +int ops_delete_avp(struct sip_msg *msg, struct fis_param *ap) { avp_list_t avp_list; avp_t *avp; @@ -735,51 +679,50 @@ int ops_delete_avp(struct sip_msg* msg, struct fis_param *ap) n = 0; - if ((ap->opd&AVPOPS_VAL_NONE)==0) - { + if((ap->opd & AVPOPS_VAL_NONE) == 0) { /* avp name is known ->search by name */ /* get avp name */ - if(avpops_get_aname(msg, ap, &avp_name, &name_type)!=0) - { + if(avpops_get_aname(msg, ap, &avp_name, &name_type) != 0) { LM_ERR("failed to get dst AVP name\n"); return -1; } - n = destroy_avps( name_type, avp_name, ap->ops&AVPOPS_FLAG_ALL ); + n = destroy_avps(name_type, avp_name, ap->ops & AVPOPS_FLAG_ALL); } else { /* avp name is not given - we have just flags */ /* -> go through all list */ avp_list = get_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI); avp = avp_list; - for ( ; avp ; avp=avp_next ) - { + for(; avp; avp = avp_next) { avp_next = avp->next; /* check if type match */ - if ( !( (ap->opd&(AVPOPS_VAL_INT|AVPOPS_VAL_STR))==0 || - ((ap->opd&AVPOPS_VAL_INT)&&((avp->flags&AVP_NAME_STR))==0) || - ((ap->opd&AVPOPS_VAL_STR)&&(avp->flags&AVP_NAME_STR)) ) ) + if(!((ap->opd & (AVPOPS_VAL_INT | AVPOPS_VAL_STR)) == 0 + || ((ap->opd & AVPOPS_VAL_INT) + && ((avp->flags & AVP_NAME_STR)) == 0) + || ((ap->opd & AVPOPS_VAL_STR) + && (avp->flags & AVP_NAME_STR)))) continue; /* remove avp */ - destroy_avp( avp ); + destroy_avp(avp); n++; - if ( !(ap->ops&AVPOPS_FLAG_ALL) ) + if(!(ap->ops & AVPOPS_FLAG_ALL)) break; } } - LM_DBG("%d avps were removed\n",n); + LM_DBG("%d avps were removed\n", n); - return n?1:-1; + return n ? 1 : -1; } -int ops_copy_avp( struct sip_msg* msg, struct fis_param* src, - struct fis_param* dst) +int ops_copy_avp( + struct sip_msg *msg, struct fis_param *src, struct fis_param *dst) { struct search_state st; struct usr_avp *avp; struct usr_avp *prev_avp; - int_str avp_val; - int_str avp_val2; + int_str avp_val; + int_str avp_val2; unsigned short name_type1; unsigned short name_type2; int_str avp_name1; @@ -790,76 +733,74 @@ int ops_copy_avp( struct sip_msg* msg, struct fis_param* src, prev_avp = 0; /* get avp src name */ - if(avpops_get_aname(msg, src, &avp_name1, &name_type1)!=0) - { + if(avpops_get_aname(msg, src, &avp_name1, &name_type1) != 0) { LM_ERR("failed to get src AVP name\n"); goto error; } /* get avp dst name */ - if(avpops_get_aname(msg, dst, &avp_name2, &name_type2)!=0) - { + if(avpops_get_aname(msg, dst, &avp_name2, &name_type2) != 0) { LM_ERR("failed to get dst AVP name\n"); goto error; } - avp = search_first_avp( name_type1, avp_name1, &avp_val, &st); - while ( avp ) - { + avp = search_first_avp(name_type1, avp_name1, &avp_val, &st); + while(avp) { /* build a new avp with new name, but old value */ /* do we need cast conversion ?!?! */ - if((avp->flags&AVP_VAL_STR) && (dst->ops&AVPOPS_FLAG_CASTN)) { - if(str2int(&avp_val.s, (unsigned int*)&avp_val2.n)!=0) - { + if((avp->flags & AVP_VAL_STR) && (dst->ops & AVPOPS_FLAG_CASTN)) { + if(str2int(&avp_val.s, (unsigned int *)&avp_val2.n) != 0) { LM_ERR("cannot convert str to int\n"); goto error; } - if ( add_avp( name_type2, avp_name2, avp_val2)==-1 ) { + if(add_avp(name_type2, avp_name2, avp_val2) == -1) { LM_ERR("failed to create new avp!\n"); goto error; } - } else if(!(avp->flags&AVP_VAL_STR)&&(dst->ops&AVPOPS_FLAG_CASTS)) { + } else if(!(avp->flags & AVP_VAL_STR) + && (dst->ops & AVPOPS_FLAG_CASTS)) { avp_val2.s.s = int2str(avp_val.n, &avp_val2.s.len); - if ( add_avp( name_type2|AVP_VAL_STR, avp_name2, avp_val2)==-1 ) { + if(add_avp(name_type2 | AVP_VAL_STR, avp_name2, avp_val2) == -1) { LM_ERR("failed to create new avp.\n"); goto error; } } else { - if ( add_avp( name_type2|(avp->flags&AVP_VAL_STR), avp_name2, - avp_val)==-1 ) { + if(add_avp(name_type2 | (avp->flags & AVP_VAL_STR), avp_name2, + avp_val) + == -1) { LM_ERR("failed to create new avp\n"); goto error; } } n++; /* copy all avps? */ - if ( !(dst->ops&AVPOPS_FLAG_ALL) ) { + if(!(dst->ops & AVPOPS_FLAG_ALL)) { /* delete the old one? */ - if (dst->ops&AVPOPS_FLAG_DELETE) - destroy_avp( avp ); + if(dst->ops & AVPOPS_FLAG_DELETE) + destroy_avp(avp); break; } else { prev_avp = avp; avp = search_next_avp(&st, &avp_val); /* delete the old one? */ - if (dst->ops&AVPOPS_FLAG_DELETE) - destroy_avp( prev_avp ); + if(dst->ops & AVPOPS_FLAG_DELETE) + destroy_avp(prev_avp); } } - return n?1:-1; + return n ? 1 : -1; error: return -1; } -#define STR_BUF_SIZE 1024 +#define STR_BUF_SIZE 1024 static char str_buf[STR_BUF_SIZE]; inline static int append_0(str *in, str *out) { - if (in->len+1>STR_BUF_SIZE) + if(in->len + 1 > STR_BUF_SIZE) return -1; - memcpy( str_buf, in->s, in->len); + memcpy(str_buf, in->s, in->len); str_buf[in->len] = 0; out->len = in->len; out->s = str_buf; @@ -867,47 +808,42 @@ inline static int append_0(str *in, str *out) } -int ops_pushto_avp (struct sip_msg* msg, struct fis_param* dst, - struct fis_param* src) +int ops_pushto_avp( + struct sip_msg *msg, struct fis_param *dst, struct fis_param *src) { struct search_state st; - struct action act; + struct action act; struct usr_avp *avp; unsigned short name_type; - int_str avp_val; - int_str avp_name; - str val; - int act_type; - int n; - int flags; - pv_value_t xvalue; + int_str avp_val; + int_str avp_name; + str val; + int act_type; + int n; + int flags; + pv_value_t xvalue; struct run_act_ctx ra_ctx; avp = NULL; flags = 0; - if(src->u.sval->type==PVT_AVP) - { + if(src->u.sval->type == PVT_AVP) { /* search for the avp */ - if(avpops_get_aname(msg, src, &avp_name, &name_type)!=0) - { + if(avpops_get_aname(msg, src, &avp_name, &name_type) != 0) { LM_ERR("failed to get src AVP name\n"); goto error; } - avp = search_first_avp( name_type, avp_name, &avp_val, &st); - if (avp==0) - { + avp = search_first_avp(name_type, avp_name, &avp_val, &st); + if(avp == 0) { LM_DBG(" no src avp found\n"); goto error; } flags = avp->flags; } else { - if(pv_get_spec_value(msg, src->u.sval, &xvalue)!=0) - { + if(pv_get_spec_value(msg, src->u.sval, &xvalue) != 0) { LM_ERR("cannot get src value\n"); goto error; } - if(xvalue.flags&PV_TYPE_INT) - { + if(xvalue.flags & PV_TYPE_INT) { avp_val.n = xvalue.ri; } else { flags = AVP_VAL_STR; @@ -918,7 +854,7 @@ int ops_pushto_avp (struct sip_msg* msg, struct fis_param* dst, n = 0; do { /* the avp val will be used all the time as str */ - if (flags&AVP_VAL_STR) { + if(flags & AVP_VAL_STR) { val = avp_val.s; } else { val.s = int2str((unsigned long)avp_val.n, &val.len); @@ -926,41 +862,37 @@ int ops_pushto_avp (struct sip_msg* msg, struct fis_param* dst, act_type = 0; /* push the value into right position */ - if (dst->opd&AVPOPS_USE_RURI) - { - if (dst->opd&AVPOPS_FLAG_USER0) + if(dst->opd & AVPOPS_USE_RURI) { + if(dst->opd & AVPOPS_FLAG_USER0) act_type = SET_USER_T; - else if (dst->opd&AVPOPS_FLAG_DOMAIN0) + else if(dst->opd & AVPOPS_FLAG_DOMAIN0) act_type = SET_HOST_T; else act_type = SET_URI_T; - if ( flags&AVP_VAL_STR && append_0( &val, &val)!=0 ) { + if(flags & AVP_VAL_STR && append_0(&val, &val) != 0) { LM_ERR("failed to make 0 term.\n"); goto error; } - } else if (dst->opd&AVPOPS_USE_DURI) { - if (!(flags&AVP_VAL_STR)) { + } else if(dst->opd & AVPOPS_USE_DURI) { + if(!(flags & AVP_VAL_STR)) { goto error; } - } else if (dst->opd&AVPOPS_USE_BRANCH) { - if (!(flags&AVP_VAL_STR)) { + } else if(dst->opd & AVPOPS_USE_BRANCH) { + if(!(flags & AVP_VAL_STR)) { goto error; } } else { LM_CRIT("destination unknown (%d/%d)\n", dst->opd, dst->ops); goto error; } - - if ( act_type ) - { + + if(act_type) { /* rewrite part of ruri */ - if (n) - { + if(n) { /* if is not the first modification, push the current uri as * branch */ - if (append_branch( msg, 0, 0, 0, Q_UNSPECIFIED, - 0, 0, 0, 0, 0, 0) != 1) - { + if(append_branch(msg, 0, 0, 0, Q_UNSPECIFIED, 0, 0, 0, 0, 0, 0) + != 1) { LM_ERR("append_branch action failed\n"); goto error; } @@ -970,24 +902,22 @@ int ops_pushto_avp (struct sip_msg* msg, struct fis_param* dst, act.val[0].u.string = val.s; act.type = act_type; init_run_actions_ctx(&ra_ctx); - if (do_action(&ra_ctx, &act, msg)<0) - { + if(do_action(&ra_ctx, &act, msg) < 0) { LM_ERR("SET_XXXX_T action failed\n"); goto error; } - } else if (dst->opd&AVPOPS_USE_DURI) { - if(set_dst_uri(msg, &val)!=0) - { + } else if(dst->opd & AVPOPS_USE_DURI) { + if(set_dst_uri(msg, &val) != 0) { LM_ERR("changing dst uri failed\n"); goto error; } /* dst_uri changes, so it makes sense to re-use the current uri for forking */ ruri_mark_new(); /* re-use uri for serial forking */ - } else if (dst->opd&AVPOPS_USE_BRANCH) { - if (append_branch( msg, &val, 0, 0, Q_UNSPECIFIED, 0, - msg->force_send_socket, 0, 0, 0, 0) != 1) - { + } else if(dst->opd & AVPOPS_USE_BRANCH) { + if(append_branch(msg, &val, 0, 0, Q_UNSPECIFIED, 0, + msg->force_send_socket, 0, 0, 0, 0) + != 1) { LM_ERR("append_branch action failed\n"); goto error; } @@ -997,91 +927,83 @@ int ops_pushto_avp (struct sip_msg* msg, struct fis_param* dst, } n++; - if ( !(src->ops&AVPOPS_FLAG_ALL) ) + if(!(src->ops & AVPOPS_FLAG_ALL)) break; - if(avp==NULL) + if(avp == NULL) break; - if((avp = search_next_avp(&st, &avp_val))!=NULL) + if((avp = search_next_avp(&st, &avp_val)) != NULL) flags = avp->flags; - } while (avp);/* end while */ + } while(avp); /* end while */ - LM_DBG("%d avps were processed\n",n); + LM_DBG("%d avps were processed\n", n); return 1; error: return -1; } -int get_xavp(struct sip_msg *msg, pv_xavp_name_t *xname, - sr_xavp_t **avp, int *flag) +int get_xavp( + struct sip_msg *msg, pv_xavp_name_t *xname, sr_xavp_t **avp, int *flag) { int idxf = 0; int idx = 0; int count; - if(xname==NULL) - { + if(xname == NULL) { LM_ERR("bad parameters\n"); return -1; } - if(xname->index.type==PVT_EXTRA) - { + if(xname->index.type == PVT_EXTRA) { /* get the index */ - if(pv_get_spec_index(msg, &xname->index.pvp, &idx, &idxf)!=0) - { + if(pv_get_spec_index(msg, &xname->index.pvp, &idx, &idxf) != 0) { LM_ERR("invalid index\n"); return -1; } LM_DBG("key1 idx:%d idxf:%d\n", idx, idxf); - if(idxf==PV_IDX_ALL) + if(idxf == PV_IDX_ALL) LM_ERR("idx:* at first key not implemented. Using idx:0\n"); } /* fix the index */ - if(idx<0) - { + if(idx < 0) { count = xavp_count(&xname->name, NULL); idx = count + idx; } *avp = xavp_get_by_index(&xname->name, idx, NULL); - if(*avp==NULL) + if(*avp == NULL) return -1; - if(xname->next==NULL) + if(xname->next == NULL) return 0; idx = 0; idxf = 0; - if(xname->next->index.type==PVT_EXTRA) - { + if(xname->next->index.type == PVT_EXTRA) { /* get the index */ - if(pv_get_spec_index(msg, &xname->next->index.pvp, &idx, &idxf)!=0) - { + if(pv_get_spec_index(msg, &xname->next->index.pvp, &idx, &idxf) != 0) { LM_ERR("invalid index\n"); return -1; } LM_DBG("key2 idx:%d idxf:%d\n", idx, idxf); - *flag=idxf; + *flag = idxf; } /* fix the index */ - if(idx<0) - { + if(idx < 0) { count = xavp_count(&xname->next->name, &(*avp)->val.v.xavp); idx = count + idx; } *avp = xavp_get_by_index(&xname->next->name, idx, &(*avp)->val.v.xavp); - if(*avp==NULL) + if(*avp == NULL) return -1; return 1; } -int get_xavp_param(struct sip_msg* msg, pv_spec_p spec, sr_xavp_t **xavp, - int *flag) +int get_xavp_param( + struct sip_msg *msg, pv_spec_p spec, sr_xavp_t **xavp, int *flag) { int res; - pv_xavp_name_t *xname = (pv_xavp_name_t*)spec->pvp.pvn.u.dname; + pv_xavp_name_t *xname = (pv_xavp_name_t *)spec->pvp.pvn.u.dname; res = get_xavp(msg, xname, xavp, flag); - if(res<=0) - { - if(res==0) + if(res <= 0) { + if(res == 0) LM_ERR("xavp has to have key2\n"); LM_DBG("no dst xavp found\n"); goto error; @@ -1093,10 +1015,9 @@ int get_xavp_param(struct sip_msg* msg, pv_spec_p spec, sr_xavp_t **xavp, int set_val_xavp(sr_xavp_t *xavp, int_str *avp_val, int *flag) { - if(xavp->val.type!=SR_XTYPE_LONG && xavp->val.type!=SR_XTYPE_STR) + if(xavp->val.type != SR_XTYPE_LONG && xavp->val.type != SR_XTYPE_STR) return -1; - if(xavp->val.type==SR_XTYPE_LONG) - { + if(xavp->val.type == SR_XTYPE_LONG) { avp_val->n = xavp->val.v.l; } else { *flag = AVP_VAL_STR; @@ -1105,70 +1026,63 @@ int set_val_xavp(sr_xavp_t *xavp, int_str *avp_val, int *flag) return 1; } -int ops_check_avp( struct sip_msg* msg, struct fis_param* src, - struct fis_param* val) +int ops_check_avp( + struct sip_msg *msg, struct fis_param *src, struct fis_param *val) { struct search_state st1, st2; - unsigned short name_type1; - unsigned short name_type2; - struct usr_avp *avp1 = NULL; - struct usr_avp *avp2 = NULL; - regmatch_t pmatch; - int_str avp_name1; - int_str avp_name2; - int_str avp_val; - int_str check_val; - int check_flags; - int n, rt; - int flags; - pv_value_t xvalue; - char backup; - regex_t re_temp; - regex_t *re; - sr_xavp_t *xavp1 = NULL; // first parameter - sr_xavp_t *xavp2 = NULL; // second parameter - int xavp1_flags=0; - int xavp2_flags=0; + unsigned short name_type1; + unsigned short name_type2; + struct usr_avp *avp1 = NULL; + struct usr_avp *avp2 = NULL; + regmatch_t pmatch; + int_str avp_name1; + int_str avp_name2; + int_str avp_val; + int_str check_val; + int check_flags; + int n, rt; + int flags; + pv_value_t xvalue; + char backup; + regex_t re_temp; + regex_t *re; + sr_xavp_t *xavp1 = NULL; // first parameter + sr_xavp_t *xavp2 = NULL; // second parameter + int xavp1_flags = 0; + int xavp2_flags = 0; /* look if the required avp(s) is/are present */ - if(src->u.sval->type==PVT_AVP) - { + if(src->u.sval->type == PVT_AVP) { /* search for the avp */ - if(avpops_get_aname(msg, src, &avp_name1, &name_type1)!=0) - { + if(avpops_get_aname(msg, src, &avp_name1, &name_type1) != 0) { LM_ERR("failed to get src AVP name\n"); goto error; } - avp1 = search_first_avp( name_type1, avp_name1, &avp_val, &st1); - if (avp1==0) - { + avp1 = search_first_avp(name_type1, avp_name1, &avp_val, &st1); + if(avp1 == 0) { LM_DBG("no src avp found\n"); goto error; } flags = avp1->flags; - } else if(src->u.sval->type==PVT_XAVP) - { + } else if(src->u.sval->type == PVT_XAVP) { avp1 = 0; flags = 0; LM_DBG("xavp1 found!"); /* search for the xavp */ - if(get_xavp_param(msg, src->u.sval, &xavp1, &xavp1_flags)<0) + if(get_xavp_param(msg, src->u.sval, &xavp1, &xavp1_flags) < 0) goto error; - if(set_val_xavp(xavp1, &avp_val, &flags)<0) - { + if(set_val_xavp(xavp1, &avp_val, &flags) < 0) { LM_ERR("src value is not INT or STR\n"); goto next; } } else { avp1 = 0; flags = 0; - if(pv_get_spec_value(msg, src->u.sval, &xvalue)!=0) - { + if(pv_get_spec_value(msg, src->u.sval, &xvalue) != 0) { LM_ERR("cannot get src value\n"); goto error; } - if(xvalue.flags&PV_TYPE_INT) - { + if(xvalue.flags & PV_TYPE_INT) { avp_val.n = xvalue.ri; } else { flags = AVP_VAL_STR; @@ -1178,10 +1092,8 @@ int ops_check_avp( struct sip_msg* msg, struct fis_param* src, cycle1: /* copy string since pseudo-variables uses static buffer */ - if(flags&AVP_VAL_STR) - { - if(avp_val.s.len>=STR_BUF_SIZE) - { + if(flags & AVP_VAL_STR) { + if(avp_val.s.len >= STR_BUF_SIZE) { LM_ERR("src value too long\n"); goto error; } @@ -1190,44 +1102,35 @@ int ops_check_avp( struct sip_msg* msg, struct fis_param* src, avp_val.s.s = str_buf; } - if (val->opd&AVPOPS_VAL_PVAR) - { + if(val->opd & AVPOPS_VAL_PVAR) { /* the 2nd operator is variable -> get avp value */ check_flags = 0; - if(val->u.sval->type==PVT_AVP) - { + if(val->u.sval->type == PVT_AVP) { /* search for the avp */ - if(avpops_get_aname(msg, val, &avp_name2, &name_type2)!=0) - { + if(avpops_get_aname(msg, val, &avp_name2, &name_type2) != 0) { LM_ERR("failed to get dst AVP name\n"); goto error; } - avp2 = search_first_avp( name_type2, avp_name2, &check_val, &st2); - if (avp2==0) - { + avp2 = search_first_avp(name_type2, avp_name2, &check_val, &st2); + if(avp2 == 0) { LM_DBG("no dst avp found\n"); goto error; } check_flags = avp2->flags; - } - else if(val->u.sval->type==PVT_XAVP) - { - if(xavp2==NULL) - if(get_xavp_param(msg, val->u.sval, &xavp2, &xavp2_flags)<0) + } else if(val->u.sval->type == PVT_XAVP) { + if(xavp2 == NULL) + if(get_xavp_param(msg, val->u.sval, &xavp2, &xavp2_flags) < 0) goto error; - if(set_val_xavp(xavp2, &check_val, &check_flags)<0) - { + if(set_val_xavp(xavp2, &check_val, &check_flags) < 0) { LM_ERR("dst value is not INT or STR\n"); goto next; } } else { - if(pv_get_spec_value(msg, val->u.sval, &xvalue)!=0) - { + if(pv_get_spec_value(msg, val->u.sval, &xvalue) != 0) { LM_ERR("cannot get dst value\n"); goto error; } - if(xvalue.flags&PV_TYPE_INT) - { + if(xvalue.flags & PV_TYPE_INT) { check_val.n = xvalue.ri; } else { check_flags = AVP_VAL_STR; @@ -1236,8 +1139,7 @@ int ops_check_avp( struct sip_msg* msg, struct fis_param* src, } } else { check_flags = 0; - if(val->type == AVPOPS_VAL_INT) - { + if(val->type == AVPOPS_VAL_INT) { check_val.n = val->u.n; } else { check_val.s = val->u.s; @@ -1247,169 +1149,160 @@ int ops_check_avp( struct sip_msg* msg, struct fis_param* src, cycle2: /* are both values of the same type? */ - if ((flags&AVP_VAL_STR)^(check_flags&AVP_VAL_STR)) - { + if((flags & AVP_VAL_STR) ^ (check_flags & AVP_VAL_STR)) { LM_ERR("value types don't match\n"); goto next; } - if (flags&AVP_VAL_STR) - { + if(flags & AVP_VAL_STR) { /* string values to check */ - LM_DBG("check <%.*s> against <%.*s> as str /%d\n", - avp_val.s.len,avp_val.s.s, - (val->ops&AVPOPS_OP_RE)?6:check_val.s.len, - (val->ops&AVPOPS_OP_RE)?"REGEXP":check_val.s.s, - val->ops); + LM_DBG("check <%.*s> against <%.*s> as str /%d\n", avp_val.s.len, + avp_val.s.s, (val->ops & AVPOPS_OP_RE) ? 6 : check_val.s.len, + (val->ops & AVPOPS_OP_RE) ? "REGEXP" : check_val.s.s, val->ops); /* do check */ - if (val->ops&AVPOPS_OP_EQ) - { - if (avp_val.s.len==check_val.s.len) - { - if (val->ops&AVPOPS_FLAG_CI) - { - if (strncasecmp(avp_val.s.s,check_val.s.s, - check_val.s.len)==0) + if(val->ops & AVPOPS_OP_EQ) { + if(avp_val.s.len == check_val.s.len) { + if(val->ops & AVPOPS_FLAG_CI) { + if(strncasecmp(avp_val.s.s, check_val.s.s, check_val.s.len) + == 0) return 1; } else { - if (strncmp(avp_val.s.s,check_val.s.s,check_val.s.len)==0 ) + if(strncmp(avp_val.s.s, check_val.s.s, check_val.s.len) + == 0) return 1; } } - } else if (val->ops&AVPOPS_OP_NE) { - if (avp_val.s.len!=check_val.s.len) + } else if(val->ops & AVPOPS_OP_NE) { + if(avp_val.s.len != check_val.s.len) return 1; - if (val->ops&AVPOPS_FLAG_CI) - { - if (strncasecmp(avp_val.s.s,check_val.s.s,check_val.s.len)!=0) + if(val->ops & AVPOPS_FLAG_CI) { + if(strncasecmp(avp_val.s.s, check_val.s.s, check_val.s.len) + != 0) return 1; } else { - if (strncmp(avp_val.s.s,check_val.s.s,check_val.s.len)!=0 ) + if(strncmp(avp_val.s.s, check_val.s.s, check_val.s.len) != 0) return 1; } - } else if (val->ops&AVPOPS_OP_LT) { - n = (avp_val.s.len>=check_val.s.len)?avp_val.s.len:check_val.s.len; - rt = strncasecmp(avp_val.s.s,check_val.s.s,n); - if (rt<0) + } else if(val->ops & AVPOPS_OP_LT) { + n = (avp_val.s.len >= check_val.s.len) ? avp_val.s.len + : check_val.s.len; + rt = strncasecmp(avp_val.s.s, check_val.s.s, n); + if(rt < 0) return 1; - if(rt==0 && avp_val.s.lenops&AVPOPS_OP_LE) { - n = (avp_val.s.len>=check_val.s.len)?avp_val.s.len:check_val.s.len; - if (strncasecmp(avp_val.s.s,check_val.s.s,n)<=0) + } else if(val->ops & AVPOPS_OP_LE) { + n = (avp_val.s.len >= check_val.s.len) ? avp_val.s.len + : check_val.s.len; + if(strncasecmp(avp_val.s.s, check_val.s.s, n) <= 0) return 1; - } else if (val->ops&AVPOPS_OP_GT) { - n = (avp_val.s.len>=check_val.s.len)?avp_val.s.len:check_val.s.len; - rt = strncasecmp(avp_val.s.s,check_val.s.s,n); - if (rt>0) + } else if(val->ops & AVPOPS_OP_GT) { + n = (avp_val.s.len >= check_val.s.len) ? avp_val.s.len + : check_val.s.len; + rt = strncasecmp(avp_val.s.s, check_val.s.s, n); + if(rt > 0) return 1; - if(rt==0 && avp_val.s.len>check_val.s.len) + if(rt == 0 && avp_val.s.len > check_val.s.len) return 1; - } else if (val->ops&AVPOPS_OP_GE) { - n = (avp_val.s.len>=check_val.s.len)?avp_val.s.len:check_val.s.len; - if (strncasecmp(avp_val.s.s,check_val.s.s,n)>=0) + } else if(val->ops & AVPOPS_OP_GE) { + n = (avp_val.s.len >= check_val.s.len) ? avp_val.s.len + : check_val.s.len; + if(strncasecmp(avp_val.s.s, check_val.s.s, n) >= 0) return 1; - } else if (val->ops&AVPOPS_OP_RE) { - if (val->opd&AVPOPS_VAL_PVAR) { - LM_DBG("compiling regexp <%.*s>\n", check_val.s.len, check_val.s.s); - if (regcomp(&re_temp, check_val.s.s,REG_EXTENDED|REG_ICASE|REG_NEWLINE)) - { + } else if(val->ops & AVPOPS_OP_RE) { + if(val->opd & AVPOPS_VAL_PVAR) { + LM_DBG("compiling regexp <%.*s>\n", check_val.s.len, + check_val.s.s); + if(regcomp(&re_temp, check_val.s.s, + REG_EXTENDED | REG_ICASE | REG_NEWLINE)) { LM_ERR("bad re <%.*s>\n", check_val.s.len, check_val.s.s); goto next; } re = &re_temp; - } - else re = (regex_t*)check_val.s.s; - backup = avp_val.s.s[avp_val.s.len]; + } else + re = (regex_t *)check_val.s.s; + backup = avp_val.s.s[avp_val.s.len]; avp_val.s.s[avp_val.s.len] = '\0'; - rt=regexec(re, avp_val.s.s, 1, &pmatch,0); - if (val->opd&AVPOPS_VAL_PVAR) { + rt = regexec(re, avp_val.s.s, 1, &pmatch, 0); + if(val->opd & AVPOPS_VAL_PVAR) { regfree(re); } avp_val.s.s[avp_val.s.len] = backup; - if (rt==0) return 1; - } else if (val->ops&AVPOPS_OP_FM){ - backup = avp_val.s.s[avp_val.s.len]; + if(rt == 0) + return 1; + } else if(val->ops & AVPOPS_OP_FM) { + backup = avp_val.s.s[avp_val.s.len]; avp_val.s.s[avp_val.s.len] = '\0'; - if (fnmatch( check_val.s.s, avp_val.s.s, - #ifdef FNM_CASEFOLD - (val->ops&AVPOPS_FLAG_CI)?FNM_CASEFOLD: - #endif - 0 )==0) - { + if(fnmatch(check_val.s.s, avp_val.s.s, +#ifdef FNM_CASEFOLD + (val->ops & AVPOPS_FLAG_CI) ? FNM_CASEFOLD : +#endif + 0) + == 0) { avp_val.s.s[avp_val.s.len] = backup; return 1; } avp_val.s.s[avp_val.s.len] = backup; } else { - LM_CRIT("unknown operation (flg=%d/%d)\n",val->opd, val->ops); + LM_CRIT("unknown operation (flg=%d/%d)\n", val->opd, val->ops); } } else { /* int values to check -> do check */ - LM_DBG("check <%ld> against <%ld> as int /%d\n", - avp_val.n, check_val.n, val->ops); - if (val->ops&AVPOPS_OP_EQ) - { - if ( avp_val.n==check_val.n) + LM_DBG("check <%ld> against <%ld> as int /%d\n", avp_val.n, check_val.n, + val->ops); + if(val->ops & AVPOPS_OP_EQ) { + if(avp_val.n == check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_NE) { - if ( avp_val.n!=check_val.n) + } else if(val->ops & AVPOPS_OP_NE) { + if(avp_val.n != check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_LT) { - if ( avp_val.nops & AVPOPS_OP_LT) { + if(avp_val.n < check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_LE) { - if ( avp_val.n<=check_val.n) + } else if(val->ops & AVPOPS_OP_LE) { + if(avp_val.n <= check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_GT) { - if ( avp_val.n>check_val.n) + } else if(val->ops & AVPOPS_OP_GT) { + if(avp_val.n > check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_GE) { - if ( avp_val.n>=check_val.n) + } else if(val->ops & AVPOPS_OP_GE) { + if(avp_val.n >= check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_BAND) { - if ( avp_val.n&check_val.n) + } else if(val->ops & AVPOPS_OP_BAND) { + if(avp_val.n & check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_BOR) { - if ( avp_val.n|check_val.n) + } else if(val->ops & AVPOPS_OP_BOR) { + if(avp_val.n | check_val.n) return 1; - } else if (val->ops&AVPOPS_OP_BXOR) { - if ( avp_val.n^check_val.n) + } else if(val->ops & AVPOPS_OP_BXOR) { + if(avp_val.n ^ check_val.n) return 1; } else { - LM_CRIT("unknown operation (flg=%d)\n",val->ops); + LM_CRIT("unknown operation (flg=%d)\n", val->ops); } } next: /* cycle for the second value (only if avp can have multiple vals) */ - if ((avp2!=NULL) - && (avp2=search_next_avp(&st2, &check_val))!=NULL) - { + if((avp2 != NULL) && (avp2 = search_next_avp(&st2, &check_val)) != NULL) { check_flags = avp2->flags; goto cycle2; - } else if ((xavp2!=NULL) && (xavp2_flags&PV_IDX_ALL) - && (xavp2=xavp_get_next(xavp2))!=NULL) - { + } else if((xavp2 != NULL) && (xavp2_flags & PV_IDX_ALL) + && (xavp2 = xavp_get_next(xavp2)) != NULL) { LM_DBG("xavp2->next\n"); goto cycle1; - /* cycle for the first value -> next avp */ + /* cycle for the first value -> next avp */ } else { - if(avp1 && val->ops&AVPOPS_FLAG_ALL) - { - avp1=search_next_avp(&st1, &avp_val); - if (avp1) + if(avp1 && val->ops & AVPOPS_FLAG_ALL) { + avp1 = search_next_avp(&st1, &avp_val); + if(avp1) goto cycle1; - } - else if((xavp1!=NULL) && (xavp1_flags&PV_IDX_ALL)) - { - xavp1=xavp_get_next(xavp1); - if (xavp1!=NULL) - { + } else if((xavp1 != NULL) && (xavp1_flags & PV_IDX_ALL)) { + xavp1 = xavp_get_next(xavp1); + if(xavp1 != NULL) { LM_DBG("xavp1->next\n"); xavp2 = NULL; - if(set_val_xavp(xavp1, &avp_val, &flags)<0) - { + if(set_val_xavp(xavp1, &avp_val, &flags) < 0) { LM_ERR("src value is not INT or STR\n"); goto next; } @@ -1429,73 +1322,67 @@ int ops_print_avp(void) { avp_list_t avp_list; avp_t *avp; - int_str val; - str *name; + int_str val; + str *name; /* go through all list */ avp_list = get_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI); avp = avp_list; - for ( ; avp ; avp=avp->next) - { - LM_INFO("p=%p, flags=0x%04X\n",avp, avp->flags); - if (avp->flags&AVP_NAME_STR) - { + for(; avp; avp = avp->next) { + LM_INFO("p=%p, flags=0x%04X\n", avp, avp->flags); + if(avp->flags & AVP_NAME_STR) { name = get_avp_name(avp); - LM_INFO("\t\t\tname=<%.*s>\n",name->len,name->s); + LM_INFO("\t\t\tname=<%.*s>\n", name->len, name->s); } else { - LM_INFO("\t\t\tid=<%d>\n",avp->id); + LM_INFO("\t\t\tid=<%d>\n", avp->id); } - get_avp_val( avp, &val); - if (avp->flags&AVP_VAL_STR) - { - LM_INFO("\t\t\tval_str=<%.*s / %d>\n",val.s.len,val.s.s, + get_avp_val(avp, &val); + if(avp->flags & AVP_VAL_STR) { + LM_INFO("\t\t\tval_str=<%.*s / %d>\n", val.s.len, val.s.s, val.s.len); } else { - LM_INFO("\t\t\tval_int=<%ld>\n",val.n); + LM_INFO("\t\t\tval_int=<%ld>\n", val.n); } } - + return 1; } -int ops_subst(struct sip_msg* msg, struct fis_param** src, - struct subst_expr* se) +int ops_subst( + struct sip_msg *msg, struct fis_param **src, struct subst_expr *se) { struct search_state st; struct usr_avp *avp; struct usr_avp *prev_avp; - int_str avp_val; + int_str avp_val; unsigned short name_type1; unsigned short name_type2; - int_str avp_name1; - int_str avp_name2; + int_str avp_name1; + int_str avp_name2; int n; int nmatches; - str* result; + str *result; n = 0; prev_avp = 0; /* avp name is known ->search by name */ /* get src avp name */ - if(avpops_get_aname(msg, src[0], &avp_name1, &name_type1)!=0) - { + if(avpops_get_aname(msg, src[0], &avp_name1, &name_type1) != 0) { LM_ERR("failed to get src AVP name\n"); return -1; } avp = search_first_avp(name_type1, avp_name1, &avp_val, &st); - if(avp==NULL) + if(avp == NULL) return -1; - - if(src[1]!=0) - { + + if(src[1] != 0) { /* get dst avp name */ - if(avpops_get_aname(msg, src[1], &avp_name2, &name_type2)!=0) - { + if(avpops_get_aname(msg, src[1], &avp_name2, &name_type2) != 0) { LM_ERR("failed to get dst AVP name\n"); return -1; } @@ -1503,11 +1390,9 @@ int ops_subst(struct sip_msg* msg, struct fis_param** src, name_type2 = name_type1; avp_name2 = avp_name1; } - - if(name_type2&AVP_NAME_STR) - { - if(avp_name2.s.len>=STR_BUF_SIZE) - { + + if(name_type2 & AVP_NAME_STR) { + if(avp_name2.s.len >= STR_BUF_SIZE) { LM_ERR("dst name too long\n"); goto error; } @@ -1516,114 +1401,103 @@ int ops_subst(struct sip_msg* msg, struct fis_param** src, avp_name2.s.s = str_buf; } - while(avp) - { - if(!is_avp_str_val(avp)) - { + while(avp) { + if(!is_avp_str_val(avp)) { prev_avp = avp; avp = search_next_avp(&st, &avp_val); continue; } - - result=subst_str(avp_val.s.s, msg, se, &nmatches); - if(result!=NULL) - { + + result = subst_str(avp_val.s.s, msg, se, &nmatches); + if(result != NULL) { /* build a new avp with new name */ avp_val.s = *result; - if(add_avp(name_type2|AVP_VAL_STR, avp_name2, avp_val)==-1 ) { + if(add_avp(name_type2 | AVP_VAL_STR, avp_name2, avp_val) == -1) { LM_ERR("failed to create new avp\n"); - if(result->s!=0) + if(result->s != 0) pkg_free(result->s); pkg_free(result); goto error; } - if(result->s!=0) + if(result->s != 0) pkg_free(result->s); pkg_free(result); n++; /* copy all avps? */ - if (!(src[0]->ops&AVPOPS_FLAG_ALL) ) { + if(!(src[0]->ops & AVPOPS_FLAG_ALL)) { /* delete the old one? */ - if (src[0]->ops&AVPOPS_FLAG_DELETE || src[1]==0) + if(src[0]->ops & AVPOPS_FLAG_DELETE || src[1] == 0) destroy_avp(avp); break; } else { prev_avp = avp; avp = search_next_avp(&st, &avp_val); /* delete the old one? */ - if (src[0]->ops&AVPOPS_FLAG_DELETE || src[1]==0) - destroy_avp( prev_avp ); + if(src[0]->ops & AVPOPS_FLAG_DELETE || src[1] == 0) + destroy_avp(prev_avp); } } else { prev_avp = avp; avp = search_next_avp(&st, &avp_val); } - } LM_DBG("subst to %d avps\n", n); - return n?1:-1; + return n ? 1 : -1; error: return -1; } -int ops_op_avp( struct sip_msg* msg, struct fis_param** av, - struct fis_param* val) +int ops_op_avp( + struct sip_msg *msg, struct fis_param **av, struct fis_param *val) { struct search_state st1, st2; - unsigned short name_type1; - unsigned short name_type2; - unsigned short name_type3; - struct fis_param* src; - struct usr_avp *avp1; - struct usr_avp *avp2; - struct usr_avp *prev_avp; - int_str avp_name1; - int_str avp_name2; - int_str avp_name3; - int_str avp_val; - int_str op_val; - int result; - pv_value_t xvalue; + unsigned short name_type1; + unsigned short name_type2; + unsigned short name_type3; + struct fis_param *src; + struct usr_avp *avp1; + struct usr_avp *avp2; + struct usr_avp *prev_avp; + int_str avp_name1; + int_str avp_name2; + int_str avp_name3; + int_str avp_val; + int_str op_val; + int result; + pv_value_t xvalue; src = av[0]; /* look if the required avp(s) is/are present */ - /* search for the avp */ - if(avpops_get_aname(msg, src, &avp_name1, &name_type1)!=0) - { + /* search for the avp */ + if(avpops_get_aname(msg, src, &avp_name1, &name_type1) != 0) { LM_ERR("failed to get src AVP name\n"); goto error; } avp1 = search_first_avp(name_type1, avp_name1, &avp_val, &st1); - if (avp1==0) - { + if(avp1 == 0) { LM_DBG(" no src avp found\n"); goto error; } - while(avp1!=0) - { - if(!(avp1->flags&AVP_VAL_STR)) + while(avp1 != 0) { + if(!(avp1->flags & AVP_VAL_STR)) break; avp1 = search_next_avp(&st1, &avp_val); } - if (avp1==0 && !(val->ops&AVPOPS_OP_BNOT)) { + if(avp1 == 0 && !(val->ops & AVPOPS_OP_BNOT)) { LM_DBG("no proper avp found\n"); goto error; } name_type3 = name_type1; avp_name3 = avp_name1; - if(av[1]!=0) - { - if(avpops_get_aname(msg, av[1], &avp_name3, &name_type3)!=0) - { + if(av[1] != 0) { + if(avpops_get_aname(msg, av[1], &avp_name3, &name_type3) != 0) { LM_ERR("failed to get dst AVP name\n"); goto error; } } - if(name_type3&AVP_NAME_STR) - { - if(avp_name3.s.len>=STR_BUF_SIZE) - { + if(name_type3 & AVP_NAME_STR) { + if(avp_name3.s.len >= STR_BUF_SIZE) { LM_ERR("failed to get dst name too long\n"); goto error; } @@ -1635,38 +1509,31 @@ int ops_op_avp( struct sip_msg* msg, struct fis_param** av, result = 0; cycle1: - if (val->opd&AVPOPS_VAL_PVAR) - { + if(val->opd & AVPOPS_VAL_PVAR) { /* the 2nd operator is variable -> get value */ - if(val->u.sval->type==PVT_AVP) - { + if(val->u.sval->type == PVT_AVP) { /* search for the avp */ - if(avpops_get_aname(msg, val, &avp_name2, &name_type2)!=0) - { + if(avpops_get_aname(msg, val, &avp_name2, &name_type2) != 0) { LM_ERR("failed to get dst AVP name\n"); goto error; } - avp2 = search_first_avp( name_type2, avp_name2, &op_val, &st2); - while(avp2!=0) - { - if(!(avp2->flags&AVP_VAL_STR)) + avp2 = search_first_avp(name_type2, avp_name2, &op_val, &st2); + while(avp2 != 0) { + if(!(avp2->flags & AVP_VAL_STR)) break; - avp2 = search_next_avp( &st2, &op_val); + avp2 = search_next_avp(&st2, &op_val); } - if (avp2==0) - { + if(avp2 == 0) { LM_DBG("no dst avp found\n"); goto error; } } else { avp2 = 0; - if(pv_get_spec_value(msg, val->u.sval, &xvalue)!=0) - { + if(pv_get_spec_value(msg, val->u.sval, &xvalue) != 0) { LM_ERR("cannot get dst value\n"); goto error; } - if(xvalue.flags&PV_TYPE_INT) - { + if(xvalue.flags & PV_TYPE_INT) { op_val.n = xvalue.ri; } else { LM_ERR("dst value is str\n"); @@ -1683,67 +1550,57 @@ int ops_op_avp( struct sip_msg* msg, struct fis_param** av, cycle2: /* do operation */ - LM_DBG(" use <%ld> and <%ld>\n", - avp_val.n, op_val.n); - if (val->ops&AVPOPS_OP_ADD) - { - result = avp_val.n+op_val.n; - } else if (val->ops&AVPOPS_OP_SUB) { - result = avp_val.n-op_val.n; - } else if (val->ops&AVPOPS_OP_MUL) { - result = avp_val.n*op_val.n; - } else if (val->ops&AVPOPS_OP_DIV) { - if(op_val.n!=0) - result = (int)(avp_val.n/op_val.n); - else - { + LM_DBG(" use <%ld> and <%ld>\n", avp_val.n, op_val.n); + if(val->ops & AVPOPS_OP_ADD) { + result = avp_val.n + op_val.n; + } else if(val->ops & AVPOPS_OP_SUB) { + result = avp_val.n - op_val.n; + } else if(val->ops & AVPOPS_OP_MUL) { + result = avp_val.n * op_val.n; + } else if(val->ops & AVPOPS_OP_DIV) { + if(op_val.n != 0) + result = (int)(avp_val.n / op_val.n); + else { LM_ERR("division by 0\n"); result = 0; } - } else if (val->ops&AVPOPS_OP_MOD) { - if(op_val.n!=0) - result = avp_val.n%op_val.n; - else - { + } else if(val->ops & AVPOPS_OP_MOD) { + if(op_val.n != 0) + result = avp_val.n % op_val.n; + else { LM_ERR("modulo by 0\n"); result = 0; } - } else if (val->ops&AVPOPS_OP_BAND) { - result = avp_val.n&op_val.n; - } else if (val->ops&AVPOPS_OP_BOR) { - result = avp_val.n|op_val.n; - } else if (val->ops&AVPOPS_OP_BXOR) { - result = avp_val.n^op_val.n; - } else if (val->ops&AVPOPS_OP_BNOT) { + } else if(val->ops & AVPOPS_OP_BAND) { + result = avp_val.n & op_val.n; + } else if(val->ops & AVPOPS_OP_BOR) { + result = avp_val.n | op_val.n; + } else if(val->ops & AVPOPS_OP_BXOR) { + result = avp_val.n ^ op_val.n; + } else if(val->ops & AVPOPS_OP_BNOT) { result = ~op_val.n; } else { - LM_CRIT("unknown operation (flg=%d)\n",val->ops); + LM_CRIT("unknown operation (flg=%d)\n", val->ops); goto error; } /* add the new avp */ avp_val.n = result; - if(add_avp(name_type3, avp_name3, avp_val)==-1 ) { + if(add_avp(name_type3, avp_name3, avp_val) == -1) { LM_ERR("failed to create new avp\n"); goto error; } /* cycle for the second value (only if avp can have multiple vals) */ - while((avp2!=NULL) - &&(avp2=search_next_avp( &st2, &op_val))!=0) - { - if(!(avp2->flags&AVP_VAL_STR)) + while((avp2 != NULL) && (avp2 = search_next_avp(&st2, &op_val)) != 0) { + if(!(avp2->flags & AVP_VAL_STR)) goto cycle2; } prev_avp = avp1; /* cycle for the first value -> next avp */ - while((avp1!=NULL) - &&(avp1=search_next_avp(&st1, &avp_val))!=0) - { - if (!(avp1->flags&AVP_VAL_STR)) - { - if(val->ops&AVPOPS_FLAG_DELETE && prev_avp!=0) - { + while((avp1 != NULL) && (avp1 = search_next_avp(&st1, &avp_val)) != 0) { + if(!(avp1->flags & AVP_VAL_STR)) { + if(val->ops & AVPOPS_FLAG_DELETE && prev_avp != 0) { destroy_avp(prev_avp); prev_avp = 0; } @@ -1751,8 +1608,7 @@ int ops_op_avp( struct sip_msg* msg, struct fis_param** av, } } LM_DBG("done\n"); - if(val->ops&AVPOPS_FLAG_DELETE && prev_avp!=0) - { + if(val->ops & AVPOPS_FLAG_DELETE && prev_avp != 0) { destroy_avp(prev_avp); prev_avp = 0; } @@ -1762,53 +1618,49 @@ int ops_op_avp( struct sip_msg* msg, struct fis_param** av, return -1; } -int ops_is_avp_set(struct sip_msg* msg, struct fis_param *ap) +int ops_is_avp_set(struct sip_msg *msg, struct fis_param *ap) { struct search_state st; struct usr_avp *avp; - unsigned short name_type; + unsigned short name_type; int_str avp_name; int_str avp_value; int index; int findex; - + /* get avp name */ - if(avpops_get_aname(msg, ap, &avp_name, &name_type)!=0) - { + if(avpops_get_aname(msg, ap, &avp_name, &name_type) != 0) { LM_ERR("failed to get AVP name\n"); return -1; } /* get avp index */ - if(pv_get_spec_index(msg, &ap->u.sval->pvp, &index, &findex)!=0) - { + if(pv_get_spec_index(msg, &ap->u.sval->pvp, &index, &findex) != 0) { LM_ERR("failed to get AVP index\n"); return -1; } - - avp=search_first_avp(name_type, avp_name, &avp_value, &st); - if(avp==0) + + avp = search_first_avp(name_type, avp_name, &avp_value, &st); + if(avp == 0) return -1; - + do { /* last index [-1] or all [*] go here as well */ - if(index<=0) - { - if(ap->ops&AVPOPS_FLAG_ALL) + if(index <= 0) { + if(ap->ops & AVPOPS_FLAG_ALL) return 1; - if((ap->ops&AVPOPS_FLAG_CASTS && !(avp->flags&AVP_VAL_STR)) - ||(ap->ops&AVPOPS_FLAG_CASTN && avp->flags&AVP_VAL_STR)) + if((ap->ops & AVPOPS_FLAG_CASTS && !(avp->flags & AVP_VAL_STR)) + || (ap->ops & AVPOPS_FLAG_CASTN + && avp->flags & AVP_VAL_STR)) return -1; - if(ap->ops&AVPOPS_FLAG_EMPTY) - { - if(avp->flags&AVP_VAL_STR) - { - if(avp_value.s.s==0 || avp_value.s.len==0) + if(ap->ops & AVPOPS_FLAG_EMPTY) { + if(avp->flags & AVP_VAL_STR) { + if(avp_value.s.s == 0 || avp_value.s.len == 0) return 1; else return -1; } else { - if(avp_value.n==0) + if(avp_value.n == 0) return 1; else return -1; @@ -1817,8 +1669,7 @@ int ops_is_avp_set(struct sip_msg* msg, struct fis_param *ap) return 1; } index--; - } while ((avp=search_next_avp(&st, &avp_value))!=0); - + } while((avp = search_next_avp(&st, &avp_value)) != 0); + return -1; } - diff --git a/src/modules/avpops/avpops_impl.h b/src/modules/avpops/avpops_impl.h index c71d6503116..c12758baeaa 100644 --- a/src/modules/avpops/avpops_impl.h +++ b/src/modules/avpops/avpops_impl.h @@ -20,7 +20,6 @@ */ - #ifndef _AVP_OPS_IMPL_H_ #define _AVP_OPS_IMPL_H_ @@ -33,73 +32,73 @@ #include "avpops_db.h" - /* flags used inside avps */ /* IMPORTANT: flagss 0-4 are reserved by core; 8-15 by script */ -#define AVP_IS_IN_DB (1<<12) +#define AVP_IS_IN_DB (1 << 12) /* DB flags */ -#define AVPOPS_DB_NAME_INT (1<<1) -#define AVPOPS_DB_VAL_INT (1<<0) +#define AVPOPS_DB_NAME_INT (1 << 1) +#define AVPOPS_DB_VAL_INT (1 << 0) /* operand flags */ -#define AVPOPS_VAL_NONE (1<<0) -#define AVPOPS_VAL_INT (1<<1) -#define AVPOPS_VAL_STR (1<<2) -#define AVPOPS_VAL_PVAR (1<<3) - -#define AVPOPS_USE_FROM (1<<5) -#define AVPOPS_USE_TO (1<<6) -#define AVPOPS_USE_RURI (1<<7) -#define AVPOPS_USE_USERNAME (1<<8) -#define AVPOPS_USE_DOMAIN (1<<9) - -#define AVPOPS_USE_SRC_IP (1<<12) -#define AVPOPS_USE_DST_IP (1<<13) -#define AVPOPS_USE_DURI (1<<14) -#define AVPOPS_USE_BRANCH (1<<15) +#define AVPOPS_VAL_NONE (1 << 0) +#define AVPOPS_VAL_INT (1 << 1) +#define AVPOPS_VAL_STR (1 << 2) +#define AVPOPS_VAL_PVAR (1 << 3) + +#define AVPOPS_USE_FROM (1 << 5) +#define AVPOPS_USE_TO (1 << 6) +#define AVPOPS_USE_RURI (1 << 7) +#define AVPOPS_USE_USERNAME (1 << 8) +#define AVPOPS_USE_DOMAIN (1 << 9) + +#define AVPOPS_USE_SRC_IP (1 << 12) +#define AVPOPS_USE_DST_IP (1 << 13) +#define AVPOPS_USE_DURI (1 << 14) +#define AVPOPS_USE_BRANCH (1 << 15) /* flags for operation flags 24..31 */ -#define AVPOPS_FLAG_USER0 (1<<24) -#define AVPOPS_FLAG_DOMAIN0 (1<<25) -#define AVPOPS_FLAG_URI0 (1<<26) -#define AVPOPS_FLAG_UUID0 (1<<27) +#define AVPOPS_FLAG_USER0 (1 << 24) +#define AVPOPS_FLAG_DOMAIN0 (1 << 25) +#define AVPOPS_FLAG_URI0 (1 << 26) +#define AVPOPS_FLAG_UUID0 (1 << 27) /* operation flags */ -#define AVPOPS_OP_EQ (1<<0) -#define AVPOPS_OP_NE (1<<1) -#define AVPOPS_OP_LT (1<<2) -#define AVPOPS_OP_LE (1<<3) -#define AVPOPS_OP_GT (1<<4) -#define AVPOPS_OP_GE (1<<5) -#define AVPOPS_OP_RE (1<<6) -#define AVPOPS_OP_FM (1<<7) -#define AVPOPS_OP_BAND (1<<8) -#define AVPOPS_OP_BOR (1<<9) -#define AVPOPS_OP_BXOR (1<<10) -#define AVPOPS_OP_BNOT (1<<11) -#define AVPOPS_OP_ADD (1<<12) -#define AVPOPS_OP_SUB (1<<13) -#define AVPOPS_OP_MUL (1<<14) -#define AVPOPS_OP_DIV (1<<15) -#define AVPOPS_OP_MOD (1<<16) +#define AVPOPS_OP_EQ (1 << 0) +#define AVPOPS_OP_NE (1 << 1) +#define AVPOPS_OP_LT (1 << 2) +#define AVPOPS_OP_LE (1 << 3) +#define AVPOPS_OP_GT (1 << 4) +#define AVPOPS_OP_GE (1 << 5) +#define AVPOPS_OP_RE (1 << 6) +#define AVPOPS_OP_FM (1 << 7) +#define AVPOPS_OP_BAND (1 << 8) +#define AVPOPS_OP_BOR (1 << 9) +#define AVPOPS_OP_BXOR (1 << 10) +#define AVPOPS_OP_BNOT (1 << 11) +#define AVPOPS_OP_ADD (1 << 12) +#define AVPOPS_OP_SUB (1 << 13) +#define AVPOPS_OP_MUL (1 << 14) +#define AVPOPS_OP_DIV (1 << 15) +#define AVPOPS_OP_MOD (1 << 16) /* flags for operation flags 24..31 */ -#define AVPOPS_FLAG_ALL (1<<24) -#define AVPOPS_FLAG_CI (1<<25) -#define AVPOPS_FLAG_DELETE (1<<26) -#define AVPOPS_FLAG_CASTN (1<<27) -#define AVPOPS_FLAG_CASTS (1<<28) -#define AVPOPS_FLAG_EMPTY (1<<29) +#define AVPOPS_FLAG_ALL (1 << 24) +#define AVPOPS_FLAG_CI (1 << 25) +#define AVPOPS_FLAG_DELETE (1 << 26) +#define AVPOPS_FLAG_CASTN (1 << 27) +#define AVPOPS_FLAG_CASTS (1 << 28) +#define AVPOPS_FLAG_EMPTY (1 << 29) /* container structer for Flag+Int_Spec_value parameter */ struct fis_param { - int ops; /* operation flags */ - int opd; /* operand flags */ - int type; - union { - pv_spec_t *sval; /* values int or str */ + int ops; /* operation flags */ + int opd; /* operand flags */ + int type; + union + { + pv_spec_t *sval; /* values int or str */ int n; str s; } u; @@ -107,47 +106,45 @@ struct fis_param struct db_param { - struct fis_param a; /* attribute */ - str sa; /* attribute as str (for db queries) */ - str table; /* DB table/scheme name */ - struct db_scheme *scheme; /* DB scheme */ + struct fis_param a; /* attribute */ + str sa; /* attribute as str (for db queries) */ + str table; /* DB table/scheme name */ + struct db_scheme *scheme; /* DB scheme */ }; void init_store_avps(str **db_columns); -int ops_dbload_avps (struct sip_msg* msg, struct fis_param *sp, - struct db_param *dbp, int use_domain); +int ops_dbload_avps(struct sip_msg *msg, struct fis_param *sp, + struct db_param *dbp, int use_domain); -int ops_dbdelete_avps(struct sip_msg* msg, struct fis_param *sp, - struct db_param *dbp, int use_domain); +int ops_dbdelete_avps(struct sip_msg *msg, struct fis_param *sp, + struct db_param *dbp, int use_domain); -int ops_dbstore_avps(struct sip_msg* msg, struct fis_param *sp, - struct db_param *dbp, int use_domain); +int ops_dbstore_avps(struct sip_msg *msg, struct fis_param *sp, + struct db_param *dbp, int use_domain); -int ops_dbquery_avps(struct sip_msg* msg, pv_elem_t* query, - pvname_list_t* dest); +int ops_dbquery_avps( + struct sip_msg *msg, pv_elem_t *query, pvname_list_t *dest); -int ops_delete_avp(struct sip_msg* msg, - struct fis_param *ap); +int ops_delete_avp(struct sip_msg *msg, struct fis_param *ap); -int ops_copy_avp(struct sip_msg* msg, struct fis_param* name1, - struct fis_param* name2); +int ops_copy_avp( + struct sip_msg *msg, struct fis_param *name1, struct fis_param *name2); -int ops_pushto_avp(struct sip_msg* msg, struct fis_param* dst, - struct fis_param* ap); +int ops_pushto_avp( + struct sip_msg *msg, struct fis_param *dst, struct fis_param *ap); -int ops_check_avp(struct sip_msg* msg, struct fis_param* param, - struct fis_param* check); +int ops_check_avp( + struct sip_msg *msg, struct fis_param *param, struct fis_param *check); -int ops_op_avp(struct sip_msg* msg, struct fis_param** param, - struct fis_param* op); +int ops_op_avp( + struct sip_msg *msg, struct fis_param **param, struct fis_param *op); -int ops_subst(struct sip_msg* msg, struct fis_param** src, - struct subst_expr* subst); +int ops_subst( + struct sip_msg *msg, struct fis_param **src, struct subst_expr *subst); -int ops_is_avp_set(struct sip_msg* msg, struct fis_param *ap); +int ops_is_avp_set(struct sip_msg *msg, struct fis_param *ap); int ops_print_avp(void); #endif - diff --git a/src/modules/avpops/avpops_parse.c b/src/modules/avpops/avpops_parse.c index 675de6f9004..d2e3f7d9fe0 100644 --- a/src/modules/avpops/avpops_parse.c +++ b/src/modules/avpops/avpops_parse.c @@ -20,7 +20,6 @@ */ - #include #include @@ -31,22 +30,22 @@ #include "avpops_parse.h" -#define SCHEME_UUID_COL "uuid_col" -#define SCHEME_UUID_COL_LEN (sizeof(SCHEME_UUID_COL)-1) -#define SCHEME_USERNAME_COL "username_col" -#define SCHEME_USERNAME_COL_LEN (sizeof(SCHEME_USERNAME_COL)-1) -#define SCHEME_DOMAIN_COL "domain_col" -#define SCHEME_DOMAIN_COL_LEN (sizeof(SCHEME_DOMAIN_COL)-1) -#define SCHEME_VALUE_COL "value_col" -#define SCHEME_VALUE_COL_LEN (sizeof(SCHEME_VALUE_COL)-1) -#define SCHEME_TABLE "table" -#define SCHEME_TABLE_LEN (sizeof(SCHEME_TABLE)-1) -#define SCHEME_VAL_TYPE "value_type" -#define SCHEME_VAL_TYPE_LEN (sizeof(SCHEME_VAL_TYPE)-1) -#define SCHEME_INT_TYPE "integer" -#define SCHEME_INT_TYPE_LEN (sizeof(SCHEME_INT_TYPE)-1) -#define SCHEME_STR_TYPE "string" -#define SCHEME_STR_TYPE_LEN (sizeof(SCHEME_STR_TYPE)-1) +#define SCHEME_UUID_COL "uuid_col" +#define SCHEME_UUID_COL_LEN (sizeof(SCHEME_UUID_COL) - 1) +#define SCHEME_USERNAME_COL "username_col" +#define SCHEME_USERNAME_COL_LEN (sizeof(SCHEME_USERNAME_COL) - 1) +#define SCHEME_DOMAIN_COL "domain_col" +#define SCHEME_DOMAIN_COL_LEN (sizeof(SCHEME_DOMAIN_COL) - 1) +#define SCHEME_VALUE_COL "value_col" +#define SCHEME_VALUE_COL_LEN (sizeof(SCHEME_VALUE_COL) - 1) +#define SCHEME_TABLE "table" +#define SCHEME_TABLE_LEN (sizeof(SCHEME_TABLE) - 1) +#define SCHEME_VAL_TYPE "value_type" +#define SCHEME_VAL_TYPE_LEN (sizeof(SCHEME_VAL_TYPE) - 1) +#define SCHEME_INT_TYPE "integer" +#define SCHEME_INT_TYPE_LEN (sizeof(SCHEME_INT_TYPE) - 1) +#define SCHEME_STR_TYPE "string" +#define SCHEME_STR_TYPE_LEN (sizeof(SCHEME_STR_TYPE) - 1) struct fis_param *avpops_parse_pvar(char *in) { @@ -54,17 +53,16 @@ struct fis_param *avpops_parse_pvar(char *in) str s; /* compose the param structure */ - ap = (struct fis_param*)pkg_malloc(sizeof(struct fis_param)); - if (ap==0) - { + ap = (struct fis_param *)pkg_malloc(sizeof(struct fis_param)); + if(ap == 0) { PKG_MEM_ERROR; return NULL; } - memset( ap, 0, sizeof(struct fis_param)); - s.s = in; s.len = strlen(s.s); + memset(ap, 0, sizeof(struct fis_param)); + s.s = in; + s.len = strlen(s.s); ap->u.sval = pv_cache_get(&s); - if(ap->u.sval==NULL) - { + if(ap->u.sval == NULL) { pkg_free(ap); return NULL; } @@ -78,65 +76,64 @@ struct fis_param *avpops_parse_pvar(char *in) int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) { unsigned long ul; - str tmp; - str s0; - char have_scheme; + str tmp; + str s0; + char have_scheme; char *p0; unsigned int flags; tmp.s = s; /* parse the attribute name - check first if it's not an alias */ - p0=strchr(tmp.s, '/'); - if(p0!=NULL) - *p0=0; - if ( *s!='$') - { - if(strlen(s)<1) - { + p0 = strchr(tmp.s, '/'); + if(p0 != NULL) + *p0 = 0; + if(*s != '$') { + if(strlen(s) < 1) { LM_ERR("bad param - expected : $avp(name), *, s or i value\n"); return E_UNSPEC; } switch(*s) { - case 's': case 'S': - dbp->a.opd = AVPOPS_VAL_NONE|AVPOPS_VAL_STR; - break; - case 'i': case 'I': - dbp->a.opd = AVPOPS_VAL_NONE|AVPOPS_VAL_INT; - break; - case '*': case 'a': case 'A': + case 's': + case 'S': + dbp->a.opd = AVPOPS_VAL_NONE | AVPOPS_VAL_STR; + break; + case 'i': + case 'I': + dbp->a.opd = AVPOPS_VAL_NONE | AVPOPS_VAL_INT; + break; + case '*': + case 'a': + case 'A': dbp->a.opd = AVPOPS_VAL_NONE; - break; + break; default: LM_ERR("bad param - expected : *, s or i AVP flag\n"); - return E_UNSPEC; + return E_UNSPEC; } /* flags */ flags = 0; - if(*(s+1)!='\0') - { - s0.s = s+1; + if(*(s + 1) != '\0') { + s0.s = s + 1; s0.len = strlen(s0.s); - if(str2int(&s0, &flags)!=0) - { + if(str2int(&s0, &flags) != 0) { LM_ERR("error - bad avp flags\n"); goto error; } } /* no pv to lookup, create one to store flags details */ - dbp->a.u.sval = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t)); - if(dbp->a.u.sval==NULL) - { + dbp->a.u.sval = (pv_spec_t *)pkg_malloc(sizeof(pv_spec_t)); + if(dbp->a.u.sval == NULL) { PKG_MEM_ERROR; goto error; } memset(dbp->a.u.sval, 0, sizeof(pv_spec_t)); - dbp->a.u.sval->pvp.pvn.u.isname.type |= (flags<<8)&0xff00; + dbp->a.u.sval->pvp.pvn.u.isname.type |= (flags << 8) & 0xff00; dbp->a.type = AVPOPS_VAL_NONE; } else { - s0.s = s; s0.len = strlen(s0.s); + s0.s = s; + s0.len = strlen(s0.s); dbp->a.u.sval = pv_cache_get(&s0); - if (dbp->a.u.sval==0 || dbp->a.u.sval->type!=PVT_AVP) - { + if(dbp->a.u.sval == 0 || dbp->a.u.sval->type != PVT_AVP) { LM_ERR("bad param - expected : $avp(name) or int/str value\n"); return E_UNSPEC; } @@ -145,15 +142,12 @@ int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) /* optimize and keep the attribute name as str also to * speed up db querie builds */ - if (dbp->a.type == AVPOPS_VAL_PVAR) - { + if(dbp->a.type == AVPOPS_VAL_PVAR) { dbp->a.opd = AVPOPS_VAL_PVAR; - if(pv_has_sname(dbp->a.u.sval)) - { - dbp->sa.s=(char*)pkg_malloc( - dbp->a.u.sval->pvp.pvn.u.isname.name.s.len+1); - if (dbp->sa.s==0) - { + if(pv_has_sname(dbp->a.u.sval)) { + dbp->sa.s = (char *)pkg_malloc( + dbp->a.u.sval->pvp.pvn.u.isname.name.s.len + 1); + if(dbp->sa.s == 0) { PKG_MEM_ERROR; goto error; } @@ -161,20 +155,19 @@ int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) dbp->a.u.sval->pvp.pvn.u.isname.name.s.len); dbp->sa.len = dbp->a.u.sval->pvp.pvn.u.isname.name.s.len; dbp->sa.s[dbp->sa.len] = 0; - dbp->a.opd = AVPOPS_VAL_PVAR|AVPOPS_VAL_STR; + dbp->a.opd = AVPOPS_VAL_PVAR | AVPOPS_VAL_STR; } else if(pv_has_iname(dbp->a.u.sval)) { ul = (unsigned long)dbp->a.u.sval->pvp.pvn.u.isname.name.n; - tmp.s = int2str( ul, &(tmp.len) ); - dbp->sa.s = (char*)pkg_malloc( tmp.len + 1 ); - if (dbp->sa.s==0) - { + tmp.s = int2str(ul, &(tmp.len)); + dbp->sa.s = (char *)pkg_malloc(tmp.len + 1); + if(dbp->sa.s == 0) { PKG_MEM_ERROR; goto error; } - memcpy( dbp->sa.s, tmp.s, tmp.len); + memcpy(dbp->sa.s, tmp.s, tmp.len); dbp->sa.len = tmp.len; dbp->sa.s[dbp->sa.len] = 0; - dbp->a.opd = AVPOPS_VAL_PVAR|AVPOPS_VAL_INT; + dbp->a.opd = AVPOPS_VAL_PVAR | AVPOPS_VAL_INT; } } @@ -183,20 +176,17 @@ int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) *p0 = '/'; /* is there a table name ? */ s = p0; - if (s && *s) - { + if(s && *s) { s++; - if (*s=='$') - { - if (allow_scheme==0) - { + if(*s == '$') { + if(allow_scheme == 0) { LM_ERR("function doesn't support DB schemes\n"); goto error; } - if (dbp->a.opd&AVPOPS_VAL_NONE) - { + if(dbp->a.opd & AVPOPS_VAL_NONE) { LM_ERR("inconsistent usage of " - "DB scheme without complete specification of AVP name\n"); + "DB scheme without complete specification of AVP " + "name\n"); goto error; } have_scheme = 1; @@ -206,23 +196,22 @@ int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) } tmp.s = s; tmp.len = 0; - while ( *s ) s++; + while(*s) + s++; tmp.len = s - tmp.s; - if (tmp.len==0) - { + if(tmp.len == 0) { LM_ERR("empty scheme/table name\n"); goto error; } - if (have_scheme) - { - dbp->scheme = avp_get_db_scheme( &tmp ); - if (dbp->scheme==0) - { + if(have_scheme) { + dbp->scheme = avp_get_db_scheme(&tmp); + if(dbp->scheme == 0) { LM_ERR("scheme <%s> not found\n", tmp.s); goto error; } /* update scheme flags with AVP name type*/ - dbp->scheme->db_flags|=dbp->a.opd&AVPOPS_VAL_STR?AVP_NAME_STR:0; + dbp->scheme->db_flags |= + dbp->a.opd & AVPOPS_VAL_STR ? AVP_NAME_STR : 0; } else { /* duplicate table as str */ pkg_str_dup(&dbp->table, &tmp); @@ -235,63 +224,57 @@ int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) } -struct fis_param* parse_intstr_value(char *p, int len) +struct fis_param *parse_intstr_value(char *p, int len) { struct fis_param *vp = 0; unsigned int uint; str val_str; int flags; - if (p==0 || len==0) - goto error; + if(p == 0 || len == 0) + goto error; - if (len>1 && *(p+1)==':') - { - if (*p=='i' || *p=='I') + if(len > 1 && *(p + 1) == ':') { + if(*p == 'i' || *p == 'I') flags = AVPOPS_VAL_INT; - else if (*p=='s' || *p=='S') + else if(*p == 's' || *p == 'S') flags = AVPOPS_VAL_STR; - else - { - LM_ERR("unknown value type <%c>\n",*p); + else { + LM_ERR("unknown value type <%c>\n", *p); goto error; } p += 2; len -= 2; - if (*p==0 || len<=0 ) - { - LM_ERR("parse error around <%.*s>\n",len,p); - goto error; + if(*p == 0 || len <= 0) { + LM_ERR("parse error around <%.*s>\n", len, p); + goto error; } } else { flags = AVPOPS_VAL_STR; } /* get the value */ - vp = (struct fis_param*)pkg_malloc(sizeof(struct fis_param)); - if (vp==0) - { + vp = (struct fis_param *)pkg_malloc(sizeof(struct fis_param)); + if(vp == 0) { PKG_MEM_ERROR; goto error; } - memset( vp, 0, sizeof(struct fis_param)); + memset(vp, 0, sizeof(struct fis_param)); vp->opd = flags; val_str.s = p; val_str.len = len; - if (flags&AVPOPS_VAL_INT) { + if(flags & AVPOPS_VAL_INT) { /* convert the value to integer */ - if(val_str.len>2 && p[0]=='0' && (p[1]=='x' || p[1]=='X')) - { - if(hexstr2int(val_str.s+2, val_str.len-2, &uint)) - { - LM_ERR("value is not hex int as type says <%.*s>\n", + if(val_str.len > 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + if(hexstr2int(val_str.s + 2, val_str.len - 2, &uint)) { + LM_ERR("value is not hex int as type says <%.*s>\n", val_str.len, val_str.s); goto error; } } else { - if(str2sint( &val_str, (int*)&uint)==-1) - { + if(str2sint(&val_str, (int *)&uint) == -1) { LM_ERR("value is not int" - " as type says <%.*s>\n", val_str.len, val_str.s); + " as type says <%.*s>\n", + val_str.len, val_str.s); goto error; } } @@ -299,9 +282,8 @@ struct fis_param* parse_intstr_value(char *p, int len) vp->type = AVPOPS_VAL_INT; } else { /* duplicate the value as string */ - vp->u.s.s = (char*)pkg_malloc((val_str.len+1)*sizeof(char)); - if (vp->u.s.s==0) - { + vp->u.s.s = (char *)pkg_malloc((val_str.len + 1) * sizeof(char)); + if(vp->u.s.s == 0) { PKG_MEM_ERROR; goto error; } @@ -313,155 +295,158 @@ struct fis_param* parse_intstr_value(char *p, int len) return vp; error: - if(vp) pkg_free(vp); + if(vp) + pkg_free(vp); return 0; } -#define duplicate_str(_p, _str, _error) \ - do { \ - _p.s = (char*)pkg_malloc(_str.len+1); \ - if (_p.s==0) \ - { \ - PKG_MEM_ERROR;\ - goto _error; \ - } \ - _p.len = _str.len; \ - memcpy( _p.s, _str.s, _str.len); \ - _p.s[_str.len] = 0; \ - }while(0) - -int parse_avp_db_scheme( char *s, struct db_scheme *scheme) +#define duplicate_str(_p, _str, _error) \ + do { \ + _p.s = (char *)pkg_malloc(_str.len + 1); \ + if(_p.s == 0) { \ + PKG_MEM_ERROR; \ + goto _error; \ + } \ + _p.len = _str.len; \ + memcpy(_p.s, _str.s, _str.len); \ + _p.s[_str.len] = 0; \ + } while(0) + +int parse_avp_db_scheme(char *s, struct db_scheme *scheme) { str foo; str bar; char *p; - if (s==0 || *s==0) + if(s == 0 || *s == 0) goto error; p = s; /*parse the name */ - while (*p && isspace((int)*p)) p++; + while(*p && isspace((int)*p)) + p++; foo.s = p; - while (*p && *p!=':' && !isspace((int)*p)) p++; - if (foo.s==p || *p==0) + while(*p && *p != ':' && !isspace((int)*p)) + p++; + if(foo.s == p || *p == 0) /* missing name or empty scheme */ goto parse_error; foo.len = p - foo.s; /* dulicate it */ - duplicate_str( scheme->name, foo, error); + duplicate_str(scheme->name, foo, error); /* parse the ':' separator */ - while (*p && isspace((int)*p)) p++; - if (*p!=':') + while(*p && isspace((int)*p)) + p++; + if(*p != ':') goto parse_error; p++; - while (*p && isspace((int)*p)) p++; - if (*p==0) + while(*p && isspace((int)*p)) + p++; + if(*p == 0) goto parse_error; /* set as default value type string */ scheme->db_flags = AVP_VAL_STR; /* parse the attributes */ - while (*p) - { + while(*p) { /* get the attribute name */ foo.s = p; - while (*p && *p!='=' && !isspace((int)*p)) p++; - if (p==foo.s || *p==0) + while(*p && *p != '=' && !isspace((int)*p)) + p++; + if(p == foo.s || *p == 0) /* missing attribute name */ goto parse_error; foo.len = p - foo.s; /* parse the '=' separator */ - while (*p && isspace((int)*p)) p++; - if (*p!='=') + while(*p && isspace((int)*p)) + p++; + if(*p != '=') goto parse_error; p++; - while (*p && isspace((int)*p)) p++; - if (*p==0) + while(*p && isspace((int)*p)) + p++; + if(*p == 0) goto parse_error; /* parse the attribute value */ bar.s = p; - while (*p && *p!=';' && !isspace((int)*p)) p++; - if (p==bar.s) + while(*p && *p != ';' && !isspace((int)*p)) + p++; + if(p == bar.s) /* missing attribute value */ goto parse_error; bar.len = p - bar.s; /* parse the ';' separator, if any */ - while (*p && isspace((int)*p)) p++; - if (*p!=0 && *p!=';') + while(*p && isspace((int)*p)) + p++; + if(*p != 0 && *p != ';') goto parse_error; - if (*p==';') p++; - while (*p && isspace((int)*p)) p++; + if(*p == ';') + p++; + while(*p && isspace((int)*p)) + p++; /* identify the attribute */ - if ( foo.len==SCHEME_UUID_COL_LEN && - !strncasecmp( foo.s, SCHEME_UUID_COL, foo.len) ) - { - if (scheme->uuid_col.s) goto parse_error; - duplicate_str( scheme->uuid_col, bar, error); - } else - if ( foo.len==SCHEME_USERNAME_COL_LEN && - !strncasecmp( foo.s, SCHEME_USERNAME_COL, foo.len) ) - { - if (scheme->username_col.s) goto parse_error; - duplicate_str( scheme->username_col, bar, error); - } else - if ( foo.len==SCHEME_DOMAIN_COL_LEN && - !strncasecmp( foo.s, SCHEME_DOMAIN_COL, foo.len) ) - { - if (scheme->domain_col.s) goto parse_error; - duplicate_str( scheme->domain_col, bar, error); - } else - if ( foo.len==SCHEME_VALUE_COL_LEN && - !strncasecmp( foo.s, SCHEME_VALUE_COL, foo.len) ) - { - if (scheme->value_col.s) goto parse_error; - duplicate_str( scheme->value_col, bar, error); - } else - if ( foo.len==SCHEME_TABLE_LEN && - !strncasecmp( foo.s, SCHEME_TABLE, foo.len) ) - { - if (scheme->table.s) goto parse_error; - duplicate_str( scheme->table, bar, error); - } else - if ( foo.len==SCHEME_VAL_TYPE_LEN && - !strncasecmp( foo.s, SCHEME_VAL_TYPE, foo.len) ) - { - if ( bar.len==SCHEME_INT_TYPE_LEN && - !strncasecmp( bar.s, SCHEME_INT_TYPE, bar.len) ) + if(foo.len == SCHEME_UUID_COL_LEN + && !strncasecmp(foo.s, SCHEME_UUID_COL, foo.len)) { + if(scheme->uuid_col.s) + goto parse_error; + duplicate_str(scheme->uuid_col, bar, error); + } else if(foo.len == SCHEME_USERNAME_COL_LEN + && !strncasecmp(foo.s, SCHEME_USERNAME_COL, foo.len)) { + if(scheme->username_col.s) + goto parse_error; + duplicate_str(scheme->username_col, bar, error); + } else if(foo.len == SCHEME_DOMAIN_COL_LEN + && !strncasecmp(foo.s, SCHEME_DOMAIN_COL, foo.len)) { + if(scheme->domain_col.s) + goto parse_error; + duplicate_str(scheme->domain_col, bar, error); + } else if(foo.len == SCHEME_VALUE_COL_LEN + && !strncasecmp(foo.s, SCHEME_VALUE_COL, foo.len)) { + if(scheme->value_col.s) + goto parse_error; + duplicate_str(scheme->value_col, bar, error); + } else if(foo.len == SCHEME_TABLE_LEN + && !strncasecmp(foo.s, SCHEME_TABLE, foo.len)) { + if(scheme->table.s) + goto parse_error; + duplicate_str(scheme->table, bar, error); + } else if(foo.len == SCHEME_VAL_TYPE_LEN + && !strncasecmp(foo.s, SCHEME_VAL_TYPE, foo.len)) { + if(bar.len == SCHEME_INT_TYPE_LEN + && !strncasecmp(bar.s, SCHEME_INT_TYPE, bar.len)) scheme->db_flags &= (~AVP_VAL_STR); - else if ( bar.len==SCHEME_STR_TYPE_LEN && - !strncasecmp( bar.s, SCHEME_STR_TYPE, bar.len) ) + else if(bar.len == SCHEME_STR_TYPE_LEN + && !strncasecmp(bar.s, SCHEME_STR_TYPE, bar.len)) scheme->db_flags = AVP_VAL_STR; - else - { - LM_ERR("unknown value type <%.*s>\n",bar.len,bar.s); + else { + LM_ERR("unknown value type <%.*s>\n", bar.len, bar.s); goto error; } } else { - LM_ERR("unknown attribute <%.*s>\n",foo.len,foo.s); + LM_ERR("unknown attribute <%.*s>\n", foo.len, foo.s); goto error; } } /* end while */ return 0; parse_error: - LM_ERR("parse error in <%s> around %ld\n", s, (long)(p-s)); + LM_ERR("parse error in <%s> around %ld\n", s, (long)(p - s)); error: return -1; } -struct fis_param* parse_check_value(char *s) +struct fis_param *parse_check_value(char *s) { struct fis_param *vp; - int ops; - int opd; + int ops; + int opd; char *p; char *t; int len; @@ -470,54 +455,51 @@ struct fis_param* parse_check_value(char *s) opd = 0; vp = 0; - if ( (p=strchr(s,'/'))==0 || (p-s!=2&&p-s!=3) ) + if((p = strchr(s, '/')) == 0 || (p - s != 2 && p - s != 3)) goto parse_error; /* get the operation */ - if (strncasecmp(s,"eq",2)==0) { + if(strncasecmp(s, "eq", 2) == 0) { ops |= AVPOPS_OP_EQ; - } else if (strncasecmp(s,"ne",2)==0) { + } else if(strncasecmp(s, "ne", 2) == 0) { ops |= AVPOPS_OP_NE; - } else if (strncasecmp(s,"lt",2)==0) { + } else if(strncasecmp(s, "lt", 2) == 0) { ops |= AVPOPS_OP_LT; - } else if (strncasecmp(s,"le",2)==0) { + } else if(strncasecmp(s, "le", 2) == 0) { ops |= AVPOPS_OP_LE; - } else if (strncasecmp(s,"gt",2)==0) { + } else if(strncasecmp(s, "gt", 2) == 0) { ops |= AVPOPS_OP_GT; - } else if (strncasecmp(s,"ge",2)==0) { + } else if(strncasecmp(s, "ge", 2) == 0) { ops |= AVPOPS_OP_GE; - } else if (strncasecmp(s,"re",2)==0) { + } else if(strncasecmp(s, "re", 2) == 0) { ops |= AVPOPS_OP_RE; - } else if (strncasecmp(s,"fm",2)==0) { + } else if(strncasecmp(s, "fm", 2) == 0) { ops |= AVPOPS_OP_FM; - } else if (strncasecmp(s,"and",3)==0) { + } else if(strncasecmp(s, "and", 3) == 0) { ops |= AVPOPS_OP_BAND; - } else if (strncasecmp(s,"or",2)==0) { + } else if(strncasecmp(s, "or", 2) == 0) { ops |= AVPOPS_OP_BOR; - } else if (strncasecmp(s,"xor",3)==0) { + } else if(strncasecmp(s, "xor", 3) == 0) { ops |= AVPOPS_OP_BXOR; } else { - LM_ERR("unknown operation <%.*s>\n",2,s); + LM_ERR("unknown operation <%.*s>\n", 2, s); goto error; } /* get the value */ - if (*(++p)==0) + if(*(++p) == 0) goto parse_error; - if ( (t=strchr(p,'/'))==0) + if((t = strchr(p, '/')) == 0) len = strlen(p); else - len = t-p; + len = t - p; - if (*p=='$') - { + if(*p == '$') { /* is variable */ vp = avpops_parse_pvar(p); - if (vp==0) - { + if(vp == 0) { LM_ERR("unable to get pseudo-variable\n"); goto error; } - if (vp->u.sval->type==PVT_NULL) - { + if(vp->u.sval->type == PVT_NULL) { LM_ERR("bad param; expected : $pseudo-variable or int/str value\n"); goto error; } @@ -525,7 +507,7 @@ struct fis_param* parse_check_value(char *s) LM_DBG("flag==%d/%d\n", opd, ops); } else { /* value is explicitly given */ - if ( (vp=parse_intstr_value(p,len))==0) { + if((vp = parse_intstr_value(p, len)) == 0) { LM_ERR("unable to parse value\n"); goto error; } @@ -533,24 +515,21 @@ struct fis_param* parse_check_value(char *s) p = t; /* any flags */ - if (p!=NULL && *p!=0) - { - if (*p!='/' || *(++p)==0) + if(p != NULL && *p != 0) { + if(*p != '/' || *(++p) == 0) goto parse_error; - while (*p) - { - switch (*p) - { + while(*p) { + switch(*p) { case 'g': case 'G': - ops|=AVPOPS_FLAG_ALL; + ops |= AVPOPS_FLAG_ALL; break; case 'i': case 'I': - ops|=AVPOPS_FLAG_CI; + ops |= AVPOPS_FLAG_CI; break; default: - LM_ERR("unknown flag <%c>\n",*p); + LM_ERR("unknown flag <%c>\n", *p); goto error; } p++; @@ -561,17 +540,18 @@ struct fis_param* parse_check_value(char *s) vp->opd |= opd; return vp; parse_error: - LM_ERR("parse error in <%s> pos %ld\n", s,(long)(p-s)); + LM_ERR("parse error in <%s> pos %ld\n", s, (long)(p - s)); error: - if (vp) pkg_free(vp); + if(vp) + pkg_free(vp); return 0; } -struct fis_param* parse_op_value(char *s) +struct fis_param *parse_op_value(char *s) { struct fis_param *vp; - int ops; - int opd; + int ops; + int opd; char *p; char *t; int len; @@ -580,50 +560,47 @@ struct fis_param* parse_op_value(char *s) opd = 0; vp = 0; - if ( (p=strchr(s,'/'))==0 || (p-s!=2&&p-s!=3) ) + if((p = strchr(s, '/')) == 0 || (p - s != 2 && p - s != 3)) goto parse_error; /* get the operation */ - if (strncasecmp(s,"add",3)==0) { + if(strncasecmp(s, "add", 3) == 0) { ops |= AVPOPS_OP_ADD; - } else if (strncasecmp(s,"sub",3)==0) { + } else if(strncasecmp(s, "sub", 3) == 0) { ops |= AVPOPS_OP_SUB; - } else if (strncasecmp(s,"mul",3)==0) { + } else if(strncasecmp(s, "mul", 3) == 0) { ops |= AVPOPS_OP_MUL; - } else if (strncasecmp(s,"div",3)==0) { + } else if(strncasecmp(s, "div", 3) == 0) { ops |= AVPOPS_OP_DIV; - } else if (strncasecmp(s,"mod",3)==0) { + } else if(strncasecmp(s, "mod", 3) == 0) { ops |= AVPOPS_OP_MOD; - } else if (strncasecmp(s,"and",3)==0) { + } else if(strncasecmp(s, "and", 3) == 0) { ops |= AVPOPS_OP_BAND; - } else if (strncasecmp(s,"or",2)==0) { + } else if(strncasecmp(s, "or", 2) == 0) { ops |= AVPOPS_OP_BOR; - } else if (strncasecmp(s,"xor",3)==0) { + } else if(strncasecmp(s, "xor", 3) == 0) { ops |= AVPOPS_OP_BXOR; - } else if (strncasecmp(s,"not",3)==0) { + } else if(strncasecmp(s, "not", 3) == 0) { ops |= AVPOPS_OP_BNOT; } else { - LM_ERR("unknown operation <%.*s>\n",2,s); + LM_ERR("unknown operation <%.*s>\n", 2, s); goto error; } /* get the value */ - if (*(++p)==0) + if(*(++p) == 0) goto parse_error; - if ( (t=strchr(p,'/'))==0) + if((t = strchr(p, '/')) == 0) len = strlen(p); else - len = t-p; + len = t - p; - if (*p=='$') - { + if(*p == '$') { /* is variable */ vp = avpops_parse_pvar(p); - if (vp==0) - { + if(vp == 0) { LM_ERR("unable to get pseudo-variable\n"); goto error; } - if (vp->u.sval->type==PVT_NULL) - { + if(vp->u.sval->type == PVT_NULL) { LM_ERR("bad param; expected : $pseudo-variable or int/str value\n"); goto error; } @@ -631,11 +608,11 @@ struct fis_param* parse_op_value(char *s) LM_DBG("flag==%d/%d\n", opd, ops); } else { /* value is explicitly given */ - if ( (vp=parse_intstr_value(p,len))==0) { + if((vp = parse_intstr_value(p, len)) == 0) { LM_ERR("unable to parse value\n"); goto error; } - if((vp->opd&AVPOPS_VAL_INT)==0) { + if((vp->opd & AVPOPS_VAL_INT) == 0) { LM_ERR("value must be int\n"); goto error; } @@ -643,24 +620,21 @@ struct fis_param* parse_op_value(char *s) /* any flags */ p = t; - if (p!=0 && *p!=0 ) - { - if (*p!='/' || *(++p)==0) + if(p != 0 && *p != 0) { + if(*p != '/' || *(++p) == 0) goto parse_error; - while (*p) - { - switch (*p) - { + while(*p) { + switch(*p) { case 'g': case 'G': - ops|=AVPOPS_FLAG_ALL; + ops |= AVPOPS_FLAG_ALL; break; case 'd': case 'D': - ops|=AVPOPS_FLAG_DELETE; + ops |= AVPOPS_FLAG_DELETE; break; default: - LM_ERR("unknown flag <%c>\n",*p); + LM_ERR("unknown flag <%c>\n", *p); goto error; } p++; @@ -671,9 +645,9 @@ struct fis_param* parse_op_value(char *s) vp->opd |= opd; return vp; parse_error: - LM_ERR("parse error in <%s> pos %ld\n", s,(long)(p-s)); + LM_ERR("parse error in <%s> pos %ld\n", s, (long)(p - s)); error: - if (vp) pkg_free(vp); + if(vp) + pkg_free(vp); return 0; } - diff --git a/src/modules/avpops/avpops_parse.h b/src/modules/avpops/avpops_parse.h index 6cecd9a7ea4..389fbc8a210 100644 --- a/src/modules/avpops/avpops_parse.h +++ b/src/modules/avpops/avpops_parse.h @@ -31,17 +31,16 @@ struct fis_param *avpops_parse_pvar(char *s); -int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme); +int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme); -int parse_avp_aliases(char *s, char c1, char c2); +int parse_avp_aliases(char *s, char c1, char c2); -struct fis_param* parse_intstr_value(char *p, int len); +struct fis_param *parse_intstr_value(char *p, int len); int parse_avp_db_scheme(char *s, struct db_scheme *scheme); -struct fis_param* parse_check_value(char *s); +struct fis_param *parse_check_value(char *s); -struct fis_param* parse_op_value(char *s); +struct fis_param *parse_op_value(char *s); #endif -