diff --git a/modules/dialog/dialog.c b/modules/dialog/dialog.c index e29dba9d233..f46ab726d86 100644 --- a/modules/dialog/dialog.c +++ b/modules/dialog/dialog.c @@ -48,7 +48,6 @@ #include "../../ut.h" #include "../../pt.h" #include "../../pvar.h" -#include "../../mod_fix.h" #include "../../context.h" #include "../../script_cb.h" #include "../../script_var.h" @@ -130,39 +129,36 @@ static int pv_get_dlg_count( struct sip_msg *msg, pv_param_t *param, pv_value_t *res); /* commands wrappers and fixups */ -static int fixup_profile(void** param, int param_no); -static int fixup_get_profile2(void** param, int param_no); -static int fixup_get_profile3(void** param, int param_no); -static int w_create_dialog(struct sip_msg*); -static int w_create_dialog2(struct sip_msg*,char *); -static int w_match_dialog(struct sip_msg*, char *seq_match_mode_gp); +static int w_create_dialog(struct sip_msg*, str *flags_str); +static int w_match_dialog(struct sip_msg *msg, void *seq_match_mode_val); static int api_match_dialog(struct sip_msg *msg, int _seq_match_mode); -static int fixup_create_dlg2(void **param,int param_no); static int w_validate_dialog(struct sip_msg*); static int w_fix_route_dialog(struct sip_msg*); -static int w_set_dlg_profile(struct sip_msg*, char*, char*); -static int w_unset_dlg_profile(struct sip_msg*, char*, char*); -static int w_is_in_profile(struct sip_msg*, char*, char*); -static int w_get_profile_size(struct sip_msg*, char*, char*, char*); -static int fixup_mmode(void **param, int param_no); -static int fixup_dlg_flag(void** param, int param_no); -static int w_set_dlg_flag(struct sip_msg*, char*); -static int w_reset_dlg_flag(struct sip_msg*, char*); -static int w_is_dlg_flag_set(struct sip_msg*, char*); -static int fixup_dlg_sval(void** param, int param_no); -static int fixup_dlg_fval(void** param, int param_no); -static int w_store_dlg_value(struct sip_msg*, char*, char*); -static int w_fetch_dlg_value(struct sip_msg*, char*, char*); -static int fixup_get_info(void** param, int param_no); -static int fixup_get_jsons(void** param, int param_no); -static int fixup_get_vals(void** param, int param_no); -static int w_get_dlg_info(struct sip_msg*, char*, char*, char*, char*,char *); -static int w_get_dlg_jsons_by_val(struct sip_msg*, char*, char*, char*, char*); -static int w_get_dlg_jsons_by_profile(struct sip_msg*, char*, char*, char*, char*); -static int w_get_dlg_vals(struct sip_msg*, char*, char*, char*); -static int w_tsl_dlg_flag(struct sip_msg *msg, char *_idx, char *_val); -static int w_set_dlg_shtag(struct sip_msg *msg, char *shtag); -static int load_dlg_ctx(struct sip_msg *msg, char *callid); +static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value); +static int w_unset_dlg_profile(struct sip_msg *msg, str *prof_name, str *value); +static int w_is_in_profile(struct sip_msg *msg, str *prof_name, str *value); +static int w_get_profile_size(struct sip_msg *msg, str *prof_name, + str *value, pv_spec_t *result); +static int fixup_mmode(void **param); +static int fixup_dlg_flag(void** param); +static int fixup_check_avp(void** param); +static int fixup_check_var(void** param); +static int w_set_dlg_flag(struct sip_msg *msg, void *mask); +static int w_reset_dlg_flag(struct sip_msg *msg, void *mask); +static int w_is_dlg_flag_set(struct sip_msg *msg, void *mask); +static int w_store_dlg_value(struct sip_msg *msg, str *name, str *val); +int w_fetch_dlg_value(struct sip_msg *msg, str *name, pv_spec_t *result); +static int w_get_dlg_info(struct sip_msg *msg, str *attr, pv_spec_t *attr_val, + str *key, str *key_val, pv_spec_t *number_val); +static int w_get_dlg_jsons_by_val(struct sip_msg *msg, str *attr, str *attr_val, + pv_spec_t *out, pv_spec_t *number_val); +static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, str *attr, str *attr_val, + pv_spec_t *out, pv_spec_t *number_val); +static int w_get_dlg_vals(struct sip_msg *msg, pv_spec_t *v_name, + pv_spec_t *v_val, str *callid); +static int w_tsl_dlg_flag(struct sip_msg *msg, int *_idx, int *_val); +static int w_set_dlg_shtag(struct sip_msg *msg, str *shtag); +static int load_dlg_ctx(struct sip_msg *msg, str *callid); static int unload_dlg_ctx(struct sip_msg *msg); /* item/pseudo-variables functions */ @@ -182,74 +178,88 @@ int pv_get_dlg_json(struct sip_msg *msg, pv_param_t *param, int pv_get_dlg_ctx_json(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); - static cmd_export_t cmds[]={ - {"create_dialog", (cmd_function)w_create_dialog, 0,NULL, - 0, REQUEST_ROUTE}, - {"create_dialog", (cmd_function)w_create_dialog2, 1,fixup_create_dlg2, - 0, REQUEST_ROUTE}, - {"set_dlg_profile", (cmd_function)w_set_dlg_profile, 1,fixup_profile, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE }, - {"set_dlg_profile", (cmd_function)w_set_dlg_profile, 2,fixup_profile, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE }, - {"unset_dlg_profile", (cmd_function)w_unset_dlg_profile,1,fixup_profile, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE }, - {"unset_dlg_profile", (cmd_function)w_unset_dlg_profile,2,fixup_profile, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE }, - {"is_in_profile", (cmd_function)w_is_in_profile, 1,fixup_profile, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"is_in_profile", (cmd_function)w_is_in_profile, 2,fixup_profile, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"get_profile_size",(cmd_function)w_get_profile_size, 2,fixup_get_profile2, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"get_profile_size",(cmd_function)w_get_profile_size, 3,fixup_get_profile3, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE}, - {"set_dlg_flag",(cmd_function)w_set_dlg_flag, 1,fixup_dlg_flag, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE}, - {"test_and_set_dlg_flag",(cmd_function)w_tsl_dlg_flag,2,fixup_uint_uint, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"reset_dlg_flag",(cmd_function)w_reset_dlg_flag, 1,fixup_dlg_flag, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"is_dlg_flag_set",(cmd_function)w_is_dlg_flag_set, 1,fixup_dlg_flag, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"store_dlg_value",(cmd_function)w_store_dlg_value, 2,fixup_dlg_sval, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"fetch_dlg_value",(cmd_function)w_fetch_dlg_value, 2,fixup_dlg_fval, - 0, REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | - BRANCH_ROUTE | LOCAL_ROUTE }, - {"validate_dialog",(cmd_function)w_validate_dialog, 0, NULL, - 0, REQUEST_ROUTE}, - {"fix_route_dialog",(cmd_function)w_fix_route_dialog,0,NULL, - 0, REQUEST_ROUTE}, - {"get_dialog_info",(cmd_function)w_get_dlg_info, 5,fixup_get_info, - 0, ALL_ROUTES }, - {"get_dialog_vals",(cmd_function)w_get_dlg_vals, 3,fixup_get_vals, - 0, ALL_ROUTES }, - {"get_dialogs_by_val",(cmd_function)w_get_dlg_jsons_by_val, 4,fixup_get_jsons, - 0, ALL_ROUTES }, - {"get_dialogs_by_profile",(cmd_function)w_get_dlg_jsons_by_profile, 4,fixup_get_jsons, - 0, ALL_ROUTES }, - {"match_dialog", (cmd_function)w_match_dialog, 0,NULL, - 0, REQUEST_ROUTE}, - {"match_dialog", (cmd_function)w_match_dialog, 1,fixup_mmode, - 0, REQUEST_ROUTE}, - {"set_dlg_sharing_tag", (cmd_function)w_set_dlg_shtag, 1, - fixup_spve_null, 0, REQUEST_ROUTE}, - {"load_dialog_ctx",(cmd_function)load_dlg_ctx, 1, fixup_sgp_null, - 0, ALL_ROUTES }, - {"unload_dialog_ctx",(cmd_function)unload_dlg_ctx, 0, NULL, - 0, ALL_ROUTES }, - {"load_dlg", (cmd_function)load_dlg, 0, 0, 0, 0}, - {0,0,0,0,0,0} + {"create_dialog", (cmd_function)w_create_dialog, { + {CMD_PARAM_STR,0,0}, {0,0,0}}, + REQUEST_ROUTE}, + {"set_dlg_profile", (cmd_function)w_set_dlg_profile, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}}, + REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE}, + {"unset_dlg_profile", (cmd_function)w_unset_dlg_profile, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}}, + REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE}, + {"is_in_profile", (cmd_function)w_is_in_profile, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}}, + REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE}, + {"get_profile_size", (cmd_function)w_get_profile_size, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, + {CMD_PARAM_VAR,fixup_check_var,0}, {0,0,0}}, + REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE}, + {"set_dlg_flag", (cmd_function)w_set_dlg_flag, { + {CMD_PARAM_INT,fixup_dlg_flag,0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE}, + {"test_and_set_dlg_flag",(cmd_function)w_tsl_dlg_flag, { + {CMD_PARAM_INT,0,0}, + {CMD_PARAM_INT,0,0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE}, + {"reset_dlg_flag", (cmd_function)w_reset_dlg_flag, { + {CMD_PARAM_INT,fixup_dlg_flag,0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE}, + {"is_dlg_flag_set",(cmd_function)w_is_dlg_flag_set, { + {CMD_PARAM_INT,fixup_dlg_flag,0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE}, + {"store_dlg_value",(cmd_function)w_store_dlg_value, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR,0,0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE}, + {"fetch_dlg_value",(cmd_function)w_fetch_dlg_value, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_VAR,fixup_check_var,0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE}, + {"validate_dialog",(cmd_function)w_validate_dialog, {{0,0,0}}, + REQUEST_ROUTE}, + {"fix_route_dialog",(cmd_function)w_fix_route_dialog, {{0,0,0}}, + REQUEST_ROUTE}, + {"get_dialog_info",(cmd_function)w_get_dlg_info, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_VAR,fixup_check_avp,0}, + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_VAR,fixup_check_var,0}, {0,0,0}}, + ALL_ROUTES}, + {"get_dialog_vals",(cmd_function)w_get_dlg_vals, { + {CMD_PARAM_VAR,fixup_check_avp,0}, + {CMD_PARAM_VAR,fixup_check_avp,0}, + {CMD_PARAM_STR,0,0}, {0,0,0}}, + ALL_ROUTES}, + {"get_dialogs_by_val",(cmd_function)w_get_dlg_jsons_by_val, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_VAR,fixup_check_avp,0}, + {CMD_PARAM_VAR,fixup_check_var,0}, {0,0,0}}, + ALL_ROUTES}, + {"get_dialogs_by_profile",(cmd_function)w_get_dlg_jsons_by_profile, { + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_STR,0,0}, + {CMD_PARAM_VAR,fixup_check_avp,0}, + {CMD_PARAM_VAR,fixup_check_var,0}, {0,0,0}}, + ALL_ROUTES}, + {"match_dialog", (cmd_function)w_match_dialog, { + {CMD_PARAM_STR|CMD_PARAM_OPT,fixup_mmode,0}, {0,0,0}}, + REQUEST_ROUTE}, + {"set_dlg_sharing_tag", (cmd_function)w_set_dlg_shtag, { + {CMD_PARAM_STR,0,0}, {0,0,0}}, + REQUEST_ROUTE}, + {"load_dialog_ctx",(cmd_function)load_dlg_ctx, { + {CMD_PARAM_STR,0,0}, {0,0,0}}, + ALL_ROUTES}, + {"unload_dialog_ctx",(cmd_function)unload_dlg_ctx, + {{0,0,0}}, ALL_ROUTES}, + {0,0,{{0,0,0}},0} }; static param_export_t mod_params[]={ @@ -462,282 +472,48 @@ struct module_exports exports= { }; -static int fixup_profile(void** param, int param_no) -{ - pv_elem_t *model=NULL; - str s; - - s.s = (char*)(*param); - s.len = strlen(s.s); - if(s.len==0) { - LM_ERR("param %d is empty string!\n", param_no); - return E_CFG; - } - - if (param_no == 1) - return fixup_sgp(param); - else if (param_no==2) { - if(pv_parse_format(&s ,&model) || model==NULL) { - LM_ERR("wrong format [%s] for value param!\n", s.s); - return E_CFG; - } - *param = (void*)model; - } - return 0; -} - - - -static int fixup_get_profile2(void** param, int param_no) +static int fixup_check_var(void** param) { - pv_spec_t *sp; - int ret; - action_elem_t * p; - - if (param_no==1) { - return fixup_profile(param, 1); - } else if (param_no==2) { - ret = fixup_pvar(param); - if (ret<0) return ret; - sp = (pv_spec_t*)(*param); - if (sp->type!=PVT_AVP && sp->type!=PVT_SCRIPTVAR) { - LM_ERR("return must be an AVP or SCRIPT VAR!\n"); - return E_SCRIPT; - } - - p = container_of(param, action_elem_t, u.data); - p++; - p->u.data = *param; - - *param = NULL; + if (((pv_spec_t *)*param)->type!=PVT_AVP && + ((pv_spec_t *)*param)->type!=PVT_SCRIPTVAR) { + LM_ERR("return parameter must be an AVP or SCRIPT VAR!\n"); + return E_SCRIPT; } return 0; } - -static int fixup_get_profile3(void** param, int param_no) +static int fixup_check_avp(void** param) { - int ret; - pv_spec_t *sp; - - if (param_no==1) { - return fixup_profile(param, 1); - } else if (param_no==2) { - return fixup_profile(param, 2); - } else if (param_no==3) { - ret = fixup_pvar(param); - if (ret<0) return ret; - sp = (pv_spec_t*)(*param); - if (!pv_is_w(sp)) { - LM_ERR("'size' must be a writable pvar! (given: %d)\n", - pv_type(sp->type)); - return E_SCRIPT; - } + if (((pv_spec_t *)*param)->type!=PVT_AVP) { + LM_ERR("return parameter must be an AVP\n"); + return E_SCRIPT; } return 0; } - -static int fixup_dlg_flag(void** param, int param_no) +static int fixup_dlg_flag(void** param) { - unsigned int ui; - str s; + int val = *(int*)*param; - s.s = (char*)*param; - s.len = strlen(s.s); - if (str2int(&s, &ui)!=0) { - LM_ERR("flag index must be a number <%s>\n", (char *)(*param)); + if (val<0) { + LM_ERR("Negative index\n"); return E_CFG; } - if ( ui>=8*sizeof(unsigned int) ) { + if (val>=8*sizeof(unsigned int) ) { LM_ERR("flag index too high <%u> (max=%u)\n", - ui, (unsigned int)(8*sizeof(unsigned int)-1) ); + val, (unsigned int)(8*sizeof(unsigned int)-1) ); return E_CFG; } - pkg_free(*param); - *param=(void *)(unsigned long)(1<type != GPARAM_TYPE_STR) - return 0; - - gp->v.sval.len = dlg_match_mode_str_to_int(&gp->v.sval); - - return 0; -} - -static int fixup_create_dlg2(void **param, int param_no) -{ - return fixup_sgp(param); -} - -static int fixup_dlg_sval(void** param, int param_no) -{ - pv_elem_t *model=NULL; - str s; - - s.s = (char*)*param; - s.len = strlen(s.s); - if (param_no==1) { - /* name of the value */ - return fixup_str(param); - } else if (param_no==2) { - /* value */ - if(pv_parse_format(&s ,&model) || model==NULL) { - LM_ERR("wrong format [%s] for value param!\n", s.s); - return E_CFG; - } - *param = (void*)model; - } - - return 0; -} - - -static int fixup_dlg_fval(void** param, int param_no) -{ - pv_spec_t *sp; - int ret; - - if (param_no==1) { - /* name of the value */ - return fixup_str(param); - } else if (param_no==2) { - /* var to store the value */ - ret = fixup_pvar(param); - if (ret<0) return ret; - sp = (pv_spec_t*)(*param); - if (!pv_is_w(sp)) { - LM_ERR("output pvar must be writable! (given: %d)\n", - pv_type(sp->type)); - return E_SCRIPT; - } - } - - return 0; -} - - -static int fixup_get_info(void** param, int param_no) -{ - pv_elem_t *model=NULL; - pv_spec_t *sp,*sp2; - str s; - int ret; - - if (param_no==1) { - /* name of the dlg val to be returned */ - return fixup_str(param); - } else if (param_no==2) { - /* var to store the dlg_val value */ - ret = fixup_pvar(param); - if (ret<0) return ret; - sp = (pv_spec_t*)(*param); - if (sp->type!=PVT_AVP) { - LM_ERR("return must be an AVP!\n"); - return E_SCRIPT; - } - } else if (param_no==3) { - /* name of the dlg val to identify the dialog */ - return fixup_str(param); - } else if (param_no==4) { - /* var to hold the value of the indeification dlg val */ - s.s = (char*)*param; - s.len = strlen(s.s); - if(pv_parse_format(&s ,&model) || model==NULL) { - LM_ERR("wrong format [%s] for value param!\n", s.s); - return E_CFG; - } - *param = (void*)model; - } else if (param_no==5) { - /* output variable with number of matched dialogs */ - ret = fixup_pvar(param); - if (ret<0) return ret; - sp2 = (pv_spec_t*)(*param); - if (sp2->type!=PVT_AVP && sp2->type!=PVT_SCRIPTVAR) { - LM_ERR("return must be an AVP or SCRIPTVAR!\n"); - return E_SCRIPT; - } - } - - return 0; -} - -static int fixup_get_jsons(void** param, int param_no) -{ - pv_elem_t *model=NULL; - pv_spec_t *sp,*sp2; - str s; - int ret; - - if (param_no==1) { - /* name of the dlg val or profile to look for */ - return fixup_str(param); - } else if (param_no==2) { - /* var with the val contents, or profile value */ - s.s = (char*)*param; - s.len = strlen(s.s); - if(pv_parse_format(&s ,&model) || model==NULL) { - LM_ERR("wrong format [%s] for value param!\n", s.s); - return E_CFG; - } - *param = (void*)model; - } else if (param_no==3) { - /* avp to store the jsons */ - ret = fixup_pvar(param); - if (ret<0) return ret; - sp = (pv_spec_t*)(*param); - if (sp->type!=PVT_AVP) { - LM_ERR("return must be an AVP!\n"); - return E_SCRIPT; - } - } else if (param_no==4) { - /* output variable with number of matched dialogs */ - ret = fixup_pvar(param); - if (ret<0) return ret; - sp2 = (pv_spec_t*)(*param); - if (sp2->type!=PVT_AVP && sp2->type!=PVT_SCRIPTVAR) { - LM_ERR("return must be an AVP or SCRIPTVAR!\n"); - return E_SCRIPT; - } - } + *param=(void *)(unsigned long)(1<type!=PVT_AVP) { - LM_ERR("return must be an AVP!\n"); - return E_SCRIPT; - } - } else if (param_no==3) { - /* the callid of the dialog to be looked up */ - return fixup_sgp(param); - } + *param = (void*)(unsigned long)dlg_match_mode_str_to_int((str*)*param); return 0; } @@ -1155,30 +931,12 @@ static void mod_destroy(void) } -static int w_create_dialog(struct sip_msg *req) -{ - struct cell *t; - - t = d_tmb.t_gett(); - if (dlg_create_dialog( (t==T_UNDEFINED)?NULL:t, req,0)!=0) - return -1; - - return 1; -} - -static int w_create_dialog2(struct sip_msg *req,char *param) +static int w_create_dialog(struct sip_msg *req, str *flags_str) { struct cell *t; - str res = {0,0}; int flags; - if (fixup_get_svalue(req, (gparam_p)param, &res) !=0) - { - LM_ERR("no create dialog flags\n"); - return -1; - } - - flags = parse_create_dlg_flags(res); + flags = parse_create_dlg_flags(flags_str); t = d_tmb.t_gett(); if (dlg_create_dialog( (t==T_UNDEFINED)?NULL:t, req, flags)!=0) @@ -1188,27 +946,14 @@ static int w_create_dialog2(struct sip_msg *req,char *param) } -static int w_match_dialog(struct sip_msg *msg, char *seq_match_mode_gp) +static int w_match_dialog(struct sip_msg *msg, void *seq_match_mode_val) { - str res = STR_NULL; - gparam_p mm_gp = (gparam_p)seq_match_mode_gp; int mm; - if (!seq_match_mode_gp) { + if (!seq_match_mode_val) mm = SEQ_MATCH_DEFAULT; - } else { - if (mm_gp->type == GPARAM_TYPE_STR) { - mm = mm_gp->v.sval.len; - } else { - if (fixup_get_svalue(msg, mm_gp, &res) != 0) { - LM_ERR("failed to extract matching mode pv! " - "using 'DID_FALLBACK'\n"); - mm = SEQ_MATCH_FALLBACK; - } else { - mm = dlg_match_mode_str_to_int(&res); - } - } - } + else + mm = (int)seq_match_mode_val; return api_match_dialog(msg, mm); } @@ -1324,23 +1069,14 @@ static int w_fix_route_dialog(struct sip_msg *req) } -static int w_set_dlg_profile(struct sip_msg *msg, char *prof_name, char *value) +static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value) { struct dlg_cell *dlg; - pv_elem_t *pve = (pv_elem_t *)value; - str val_s; - str prof_name_s; struct dlg_profile_table *profile; - if (fixup_get_svalue(msg, (gparam_p)prof_name, &prof_name_s) != 0 || - prof_name_s.len == 0 || prof_name_s.s == NULL) { - LM_WARN("cannot get profile name\n"); - return -1; - } - - profile = search_dlg_profile(&prof_name_s); + profile = search_dlg_profile(prof_name); if (!profile) { - LM_ERR("profile <%.*s> not defined\n", prof_name_s.len, prof_name_s.s); + LM_ERR("profile <%.*s> not defined\n", prof_name->len, prof_name->s); return -1; } @@ -1350,12 +1086,11 @@ static int w_set_dlg_profile(struct sip_msg *msg, char *prof_name, char *value) } if (profile->has_value) { - if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; + if (!value) { + LM_WARN("missing value\n"); + return -1; } - if ( set_dlg_profile( dlg, &val_s, profile, 0) < 0 ) { + if ( set_dlg_profile( dlg, value, profile, 0) < 0 ) { LM_ERR("failed to set profile\n"); return -1; } @@ -1369,23 +1104,14 @@ static int w_set_dlg_profile(struct sip_msg *msg, char *prof_name, char *value) } -static int w_unset_dlg_profile(struct sip_msg *msg, char *prof_name, char *value) +static int w_unset_dlg_profile(struct sip_msg *msg, str *prof_name, str *value) { struct dlg_cell *dlg; - pv_elem_t *pve = (pv_elem_t *)value; - str val_s; - str prof_name_s; struct dlg_profile_table *profile; - if (fixup_get_svalue(msg, (gparam_p)prof_name, &prof_name_s) != 0 || - prof_name_s.len == 0 || prof_name_s.s == NULL) { - LM_WARN("cannot get profile name\n"); - return -1; - } - - profile = search_dlg_profile(&prof_name_s); + profile = search_dlg_profile(prof_name); if (!profile) { - LM_ERR("profile <%.*s> not defined\n", prof_name_s.len, prof_name_s.s); + LM_ERR("profile <%.*s> not defined\n", prof_name->len, prof_name->s); return -1; } @@ -1395,12 +1121,11 @@ static int w_unset_dlg_profile(struct sip_msg *msg, char *prof_name, char *value } if (profile->has_value) { - if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; + if (!value) { + LM_WARN("missing value\n"); + return -1; } - if ( unset_dlg_profile( dlg, &val_s, profile) < 0 ) { + if ( unset_dlg_profile( dlg, value, profile) < 0 ) { LM_ERR("failed to unset profile\n"); return -1; } @@ -1414,23 +1139,14 @@ static int w_unset_dlg_profile(struct sip_msg *msg, char *prof_name, char *value } -static int w_is_in_profile(struct sip_msg *msg, char *prof_name, char *value) +static int w_is_in_profile(struct sip_msg *msg, str *prof_name, str *value) { struct dlg_cell *dlg; - pv_elem_t *pve = (pv_elem_t *)value; - str val_s; - str prof_name_s; struct dlg_profile_table *profile; - if (fixup_get_svalue(msg, (gparam_p)prof_name, &prof_name_s) != 0 || - prof_name_s.len == 0 || prof_name_s.s == NULL) { - LM_WARN("cannot get profile name\n"); - return -1; - } - - profile = search_dlg_profile(&prof_name_s); + profile = search_dlg_profile(prof_name); if (!profile) { - LM_ERR("profile <%.*s> not defined\n", prof_name_s.len, prof_name_s.s); + LM_ERR("profile <%.*s> not defined\n", prof_name->len, prof_name->s); return -1; } @@ -1439,57 +1155,34 @@ static int w_is_in_profile(struct sip_msg *msg, char *prof_name, char *value) return -1; } - if (pve!=NULL && profile->has_value) { - if ( pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; - } - return is_dlg_in_profile(dlg, profile, &val_s); + if (value && profile->has_value) { + return is_dlg_in_profile(dlg, profile, value); } else { return is_dlg_in_profile(dlg, profile, NULL); } } -static int w_get_profile_size(struct sip_msg *msg, char *prof_name, - char *value, char *result) +static int w_get_profile_size(struct sip_msg *msg, str *prof_name, + str *value, pv_spec_t *result) { - pv_elem_t *pve; - str val_s; - pv_spec_t *sp_dest; pv_value_t size; - str prof_name_s; struct dlg_profile_table *profile; - if (fixup_get_svalue(msg, (gparam_p)prof_name, &prof_name_s) != 0 || - prof_name_s.len == 0 || prof_name_s.s == NULL) { - LM_WARN("cannot get profile name\n"); - return -1; - } - - profile = search_dlg_profile(&prof_name_s); + profile = search_dlg_profile(prof_name); if (!profile) { - LM_ERR("profile <%.*s> not defined\n", prof_name_s.len, prof_name_s.s); + LM_ERR("profile <%.*s> not defined\n", prof_name->len, prof_name->s); return -1; } - pve = (pv_elem_t *)value; - sp_dest = (pv_spec_t *)result; - - if (pve!=NULL && profile->has_value) { - if ( pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; - } - size.ri = get_profile_size(profile, &val_s); + if (value && profile->has_value) { + size.ri = get_profile_size(profile, value); } else { size.ri = get_profile_size(profile, NULL); } size.flags = PV_TYPE_INT|PV_VAL_INT; - if (pv_set_value(msg, sp_dest, 0, &size) != 0) { + if (pv_set_value(msg, result, 0, &size) != 0) { LM_ERR("failed to set the output profile size!\n"); return -1; } @@ -1498,7 +1191,7 @@ static int w_get_profile_size(struct sip_msg *msg, char *prof_name, } -static int w_set_dlg_flag(struct sip_msg *msg, char *mask) +static int w_set_dlg_flag(struct sip_msg *msg, void *mask) { struct dlg_cell *dlg; @@ -1511,7 +1204,7 @@ static int w_set_dlg_flag(struct sip_msg *msg, char *mask) } -static int w_reset_dlg_flag(struct sip_msg *msg, char *mask) +static int w_reset_dlg_flag(struct sip_msg *msg, void *mask) { struct dlg_cell *dlg; @@ -1523,7 +1216,7 @@ static int w_reset_dlg_flag(struct sip_msg *msg, char *mask) } -static int w_is_dlg_flag_set(struct sip_msg *msg, char *mask) +static int w_is_dlg_flag_set(struct sip_msg *msg, void *mask) { struct dlg_cell *dlg; @@ -1533,57 +1226,44 @@ static int w_is_dlg_flag_set(struct sip_msg *msg, char *mask) return (dlg->user_flags&((unsigned int)(unsigned long)mask))?1:-1; } -static int w_tsl_dlg_flag(struct sip_msg *msg, char *_idx, char *_val) +static int w_tsl_dlg_flag(struct sip_msg *msg, int *_idx, int *_val) { struct dlg_cell *dlg; if ( (dlg=get_current_dialog())==NULL ) return -2; - return test_and_set_dlg_flag(dlg, (unsigned long)*(unsigned int *)_idx, - (unsigned long)*(unsigned int *) _val); + return test_and_set_dlg_flag(dlg, *_idx, *_val); } -int w_store_dlg_value(struct sip_msg *msg, char *name, char *val) +static int w_store_dlg_value(struct sip_msg *msg, str *name, str *val) { struct dlg_cell *dlg; - pv_elem_t *pve = (pv_elem_t *)val; - str val_s; if ( (dlg=get_current_dialog())==NULL ) return -1; - if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; - } - - return (store_dlg_value( dlg, (str*)name, &val_s)==0)?1:-1; + return (store_dlg_value( dlg, name, val)==0)?1:-1; } -int w_fetch_dlg_value(struct sip_msg *msg, char *name, char *result) +int w_fetch_dlg_value(struct sip_msg *msg, str *name, pv_spec_t *result) { struct dlg_cell *dlg; - - pv_spec_t *sp_dest; pv_value_t value; - sp_dest = (pv_spec_t *)result; - if ( (dlg=get_current_dialog())==NULL ) return -1; - if (fetch_dlg_value( dlg, (str*)name, &value.rs, 0) ) { + if (fetch_dlg_value( dlg, name, &value.rs, 0) ) { LM_DBG("failed to fetch dialog value <%.*s>\n", ((str*)name)->len, ((str*)name)->s); return -1; } value.flags = PV_VAL_STR; - if (pv_set_value(msg, sp_dest, 0, &value) != 0) { + if (pv_set_value(msg, result, 0, &value) != 0) { LM_ERR("failed to set the fetched dlg value!\n"); return -1; } @@ -1592,26 +1272,16 @@ int w_fetch_dlg_value(struct sip_msg *msg, char *name, char *result) } -static int w_get_dlg_info(struct sip_msg *msg, char *attr, char *attr_val, - char *key, char *key_val,char *number_val) +static int w_get_dlg_info(struct sip_msg *msg, str *attr, pv_spec_t *attr_val, + str *key, str *key_val, pv_spec_t *number_val) { struct dlg_cell *dlg; struct dlg_entry *d_entry; - pv_elem_t *pve = (pv_elem_t *)key_val; - pv_spec_t *dst = (pv_spec_t *)attr_val; - pv_spec_t *no_dlgs = (pv_spec_t *)number_val; pv_value_t val; - str val_s; int n; unsigned int h; unsigned short aux; - if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; - } - /* go through all hash entries (entire table) */ n=0; @@ -1627,22 +1297,22 @@ static int w_get_dlg_info(struct sip_msg *msg, char *attr, char *attr_val, if ( dlg->state>DLG_STATE_CONFIRMED ) continue; - if (check_dlg_value_unsafe( dlg, (str*)key, &val_s)==0) { + if (check_dlg_value_unsafe( dlg, key, key_val)==0) { LM_DBG("dialog found, fetching variable\n"); /* XXX - in lack of an unsafe version of fetch_dlg_value */ aux = dlg->locked_by; dlg->locked_by = process_no; - if (fetch_dlg_value( dlg, (str*)attr, &val.rs, 0) ) { + if (fetch_dlg_value( dlg, attr, &val.rs, 0) ) { dlg->locked_by = aux; dlg_unlock( d_table, d_entry); LM_ERR("failed to fetch dialog value <%.*s>\n", - ((str*)attr)->len, ((str*)attr)->s); + (attr)->len, (attr)->s); return -1; } else { val.flags = PV_VAL_STR; - if (dst->setf( msg, &dst->pvp, 0, &val )!=0) { + if (attr_val->setf( msg, &attr_val->pvp, 0, &val )!=0) { LM_ERR("Failed to set out pvar \n"); dlg->locked_by = aux; dlg_unlock( d_table, d_entry); @@ -1668,7 +1338,7 @@ static int w_get_dlg_info(struct sip_msg *msg, char *attr, char *attr_val, val.rs.len=0; val.rs.s=NULL; - if (no_dlgs->setf( msg, &no_dlgs->pvp, 0, &val )!=0) { + if (number_val->setf( msg, &number_val->pvp, 0, &val )!=0) { LM_ERR("Failed to set dlg_no pvar to %d \n",n); return -1; } @@ -1676,21 +1346,14 @@ static int w_get_dlg_info(struct sip_msg *msg, char *attr, char *attr_val, return n; } -static int w_get_dlg_vals(struct sip_msg *msg, char *v_name, char *v_val, - char *callid) +static int w_get_dlg_vals(struct sip_msg *msg, pv_spec_t *v_name, + pv_spec_t *v_val, str *callid) { struct dlg_cell *dlg; struct dlg_val *dv; pv_value_t val; - str callid_s; - - if (fixup_get_svalue(msg, (gparam_p)callid, &callid_s)!=0 || - callid_s.len == 0 || callid_s.s == NULL) { - LM_WARN("cannot get string for dialog callid\n"); - return -1; - } - dlg = get_dlg_by_callid( &callid_s, 1 ); + dlg = get_dlg_by_callid(callid, 1); if (dlg==NULL) { /* nothing found */ @@ -1707,13 +1370,13 @@ static int w_get_dlg_vals(struct sip_msg *msg, char *v_name, char *v_val, /* add name to AVP */ val.flags = PV_VAL_STR; val.rs = dv->name; - if ( pv_set_value( msg, (pv_spec_p)v_name, 0, &val)<0 ) { + if ( pv_set_value( msg, v_name, 0, &val)<0 ) { LM_ERR("failed to add new name in dlg val list, ignoring\n"); } else { /* add value to AVP */ val.flags = PV_VAL_STR; val.rs = dv->val; - if ( pv_set_value( msg, (pv_spec_p)v_val, 0, &val)<0 ) { + if ( pv_set_value( msg, v_val, 0, &val)<0 ) { LM_ERR("failed to add new value in dlg val list, ignoring\n"); /* better exit here, as we will desync the lists */ unref_dlg(dlg, 1); @@ -1728,9 +1391,8 @@ static int w_get_dlg_vals(struct sip_msg *msg, char *v_name, char *v_val, return 1; } -static int w_set_dlg_shtag(struct sip_msg *msg, char *shtag) +static int w_set_dlg_shtag(struct sip_msg *msg, str *shtag) { - str tag_name; struct dlg_cell *dlg; if (!dialog_repl_cluster) { @@ -1738,17 +1400,12 @@ static int w_set_dlg_shtag(struct sip_msg *msg, char *shtag) return 1; } - if (fixup_get_svalue(msg, (gparam_p)shtag, &tag_name) < 0) { - LM_ERR("no sharing tag\n"); - return -1; - } - if ((dlg = get_current_dialog()) == NULL) { LM_ERR("Unable to fetch dialog\n"); return -1; } - if (set_dlg_shtag(dlg, &tag_name) < 0) { + if (set_dlg_shtag(dlg, shtag) < 0) { LM_ERR("Unable to set sharing tag\n"); return -1; } @@ -2244,27 +1901,17 @@ int pv_get_dlg_ctx_json(struct sip_msg *msg, pv_param_t *param, return 0; } -static int w_get_dlg_jsons_by_val(struct sip_msg *msg, char *attr, char *attr_val, - char *out, char *number_val) +static int w_get_dlg_jsons_by_val(struct sip_msg *msg, str *attr, str *attr_val, + pv_spec_t *out, pv_spec_t *number_val) { struct dlg_cell *dlg; struct dlg_entry *d_entry; - pv_elem_t *pve = (pv_elem_t *)attr_val; - pv_spec_t *dst = (pv_spec_t *)out; - pv_spec_t *no_dlgs = (pv_spec_t *)number_val; pv_value_t val; - str val_s; int n; unsigned int h; char *out_json; int out_len; - if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_WARN("cannot get string for value\n"); - return -1; - } - /* go through all hash entries (entire table) */ n=0; @@ -2280,7 +1927,7 @@ static int w_get_dlg_jsons_by_val(struct sip_msg *msg, char *attr, char *attr_va if ( dlg->state>DLG_STATE_CONFIRMED ) continue; - if (check_dlg_value_unsafe( dlg, (str*)attr, &val_s)==0) { + if (check_dlg_value_unsafe( dlg, attr, attr_val)==0) { LM_DBG("dialog found, fetching variable\n"); if ((out_json = dlg_get_json_out(dlg,1,&out_len)) == NULL) { @@ -2292,7 +1939,7 @@ static int w_get_dlg_jsons_by_val(struct sip_msg *msg, char *attr, char *attr_va val.rs.len=out_len; val.flags = PV_VAL_STR; - if (dst->setf( msg, &dst->pvp, 0, &val )!=0) { + if (out->setf( msg, &out->pvp, 0, &val )!=0) { LM_ERR("Failed to set out pvar \n"); dlg_unlock( d_table, d_entry); return -1; @@ -2315,7 +1962,7 @@ static int w_get_dlg_jsons_by_val(struct sip_msg *msg, char *attr, char *attr_va val.rs.len=0; val.rs.s=NULL; - if (no_dlgs->setf( msg, &no_dlgs->pvp, 0, &val )!=0) { + if (number_val->setf( msg, &number_val->pvp, 0, &val )!=0) { LM_ERR("Failed to set dlg_no pvar to %d \n",n); return -1; } @@ -2323,34 +1970,22 @@ static int w_get_dlg_jsons_by_val(struct sip_msg *msg, char *attr, char *attr_va return n; } -static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, char *attr, char *attr_val, - char *out, char *number_val) +static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, str *attr, str *attr_val, + pv_spec_t *out, pv_spec_t *number_val) { struct dlg_cell *dlg; struct dlg_entry *d_entry; - pv_elem_t *pve = (pv_elem_t *)attr_val; - pv_spec_t *dst = (pv_spec_t *)out; - pv_spec_t *no_dlgs = (pv_spec_t *)number_val; pv_value_t val; - str val_s; int n,out_len,found; unsigned int h; char *out_json; struct dlg_profile_table *profile; struct dlg_profile_link *cur_link; - if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || - val_s.len == 0 || val_s.s == NULL) { - LM_DBG("cannot get string for value\n"); - - /* no value enforcing */ - val_s.s = NULL; - } - /* search for the profile */ - profile = search_dlg_profile((str*)attr); + profile = search_dlg_profile(attr); if (profile==NULL) { - LM_ERR("NO such profile <%.*s> \n",((str*)attr)->len,((str*)attr)->s); + LM_ERR("NO such profile <%.*s> \n",attr->len,attr->s); return -1; } @@ -2375,9 +2010,9 @@ static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, char *attr, char *att while(cur_link) { if (cur_link->profile == profile && - ( val_s.s == NULL || - ( val_s.len == cur_link->value.len && - !strncmp(val_s.s,cur_link->value.s, val_s.len)))) { + ( attr_val->s == NULL || + ( attr_val->len == cur_link->value.len && + !strncmp(attr_val->s,cur_link->value.s, attr_val->len)))) { found = 1; break; } @@ -2394,7 +2029,7 @@ static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, char *attr, char *att val.rs.len=out_len; val.flags = PV_VAL_STR; - if (dst->setf( msg, &dst->pvp, 0, &val )!=0) { + if (out->setf( msg, &out->pvp, 0, &val )!=0) { LM_ERR("Failed to set out pvar \n"); dlg_unlock( d_table, d_entry); return -1; @@ -2417,7 +2052,7 @@ static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, char *attr, char *att val.rs.len=0; val.rs.s=NULL; - if (no_dlgs->setf( msg, &no_dlgs->pvp, 0, &val )!=0) { + if (number_val->setf( msg, &number_val->pvp, 0, &val )!=0) { LM_ERR("Failed to set dlg_no pvar to %d \n",n); return -1; } @@ -2429,23 +2064,16 @@ static int w_get_dlg_jsons_by_profile(struct sip_msg *msg, char *attr, char *att static struct dlg_cell *load_ctx_backup = NULL; static int dlg_ctx_loaded = 0; -static int load_dlg_ctx(struct sip_msg *msg, char *callid) +static int load_dlg_ctx(struct sip_msg *msg, str *callid) { struct dlg_cell *dlg; - str callid_s; if (dlg_ctx_loaded) { LM_ERR("nested call of load dlg ctx\n"); return -1; } - if (fixup_get_svalue(msg, (gparam_p)callid, &callid_s)!=0 || - callid_s.len == 0 || callid_s.s == NULL) { - LM_WARN("cannot get string for dialog callid\n"); - return -1; - } - - dlg = get_dlg_by_callid( &callid_s, 0 ); + dlg = get_dlg_by_callid(callid, 0); if (dlg==NULL) { /* nothing found */ diff --git a/modules/dialog/dlg_hash.h b/modules/dialog/dlg_hash.h index ea89e059e92..43e8d1cfecf 100644 --- a/modules/dialog/dlg_hash.h +++ b/modules/dialog/dlg_hash.h @@ -307,7 +307,7 @@ void destroy_dlg(struct dlg_cell *dlg); ({ \ char *___p; \ int ___flags = 0; \ - for (___p=(input).s; ___p < (input).s + (input).len; ___p++) \ + for (___p=(input)->s; ___p < (input)->s + (input)->len; ___p++) \ { \ switch (*___p) \ { \ diff --git a/modules/dialog/dlg_load.h b/modules/dialog/dlg_load.h index 034cd8c13ca..1d36da71a35 100644 --- a/modules/dialog/dlg_load.h +++ b/modules/dialog/dlg_load.h @@ -72,7 +72,7 @@ static inline int load_dlg_api( struct dlg_binds *dlgb ) load_dlg_f load_dlg; /* import the DLG auto-loading function */ - if ( !(load_dlg=(load_dlg_f)find_export("load_dlg", 0, 0))) + if ( !(load_dlg=(load_dlg_f)find_export("load_dlg", 0))) return -1; /* let the auto-loading function load all DLG stuff */