示例#1
0
static int in_list_fixup(void** param, int param_no)
{
	if (param_no==1) {
		/* the ip to test */
		return fixup_pvar(param);
	} else if (param_no==2) {
		/* the port to test */
		if (*param==NULL) {
			return 0;
		} else if ( *((char*)*param)==0 ) {
			pkg_free(*param);
			*param = NULL;
			return 0;
		}
		return fixup_pvar(param);
	} else if (param_no==3) {
		/* the group to check in */
		return fixup_uint(param);
	} else if (param_no==4) {
		/*  active only check ? */
		return fixup_uint(param);
	} else {
		LM_CRIT("bug - too many params (%d) in is_in_list()\n",param_no);
		return -1;
	}
}
示例#2
0
文件: reg_mod.c 项目: asitm9/opensips
static int registered_fixup(void** param, int param_no)
{
	if (param_no == 1) {
		/* name of the table */
		return domain_fixup(param);
	} else if (param_no == 2) {
		/* AOR - from PVAR */
		return fixup_pvar(param);
	} else if (param_no == 3) {
		/* CALLID - from PVAR */
		return fixup_pvar(param);
	}
	return 0;
}
示例#3
0
static int fixup_get_info(void** param, int param_no)
{
	pv_elem_t *model=NULL;
	pv_spec_t *sp;
	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 && sp->type!=PVT_SCRIPTVAR) {
			LM_ERR("return must be an AVP or SCRIPT VAR!\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;
	}

	return 0;
}
示例#4
0
static int fixup_get_profile2(void** param, int param_no)
{
	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 = list_entry(param, action_elem_t, u.data);
		p++;
		p->u.data = *param;

		*param = NULL;


	}
	return 0;
}
示例#5
0
/*
 * Function that gets the whitelist in the param given
 */
static int set_wh_param(void **param, unsigned char* def_hdrs_mask)
{
	mc_param_p wh_param;

	wh_param = pkg_malloc(sizeof(mc_param_t));

	if (!wh_param) {
		LM_ERR("no more pkg mem\n");
		return -1;
	}

	if (((char*)*param)[0] != PV_MARKER) {
		wh_param->type = WH_TYPE_STR;
		if (parse_whitelist(param, &wh_param->v.lst, def_hdrs_mask)) {
			LM_ERR("cannot parse whitelist\n");
			return -1;
		}
	} else {
		if (fixup_pvar(param)) {
			LM_ERR("parsing pvar whitelist failed\n");
			return -1;
		}
		wh_param->type = WH_TYPE_PVS;
		wh_param->v.pvs = *param;
	}

	*param = (void*)wh_param;

	return 0;
}
示例#6
0
static int check_addr_fixup(void** param, int param_no) {

	if (!db_url.s || db_url.len == 0) {
		LM_ERR("check_address needs db_url to be set!\n");
		return E_UNSPEC;
	}

	/* grp ip port proto info pattern*/
	switch (param_no) {
		case 1:
			return fixup_igp(param);
		case 2:
		case 3:
		case 4:
			return fixup_spve(param);
		case 5:
			if (*param && strlen((char*)*param))
				return fixup_pvar(param);
			*param = NULL;
			return 0;
		case 6:
			if (*param && strlen((char*)*param))
				return fixup_spve(param);
			*param = NULL;
			return 0;
	}
	return E_UNSPEC;
}
示例#7
0
static int fixup_stat(void** param, int param_no)
{
	struct stat_or_pv *sopv;
	str s;
	long n;
	int err;

	s.s = (char*)*param;
	s.len = strlen(s.s);
	if (param_no==1) {
		/* var name - string or pv */
		sopv = (struct stat_or_pv *)pkg_malloc(sizeof(struct stat_or_pv));
		if (sopv==NULL) {
			LM_ERR("no more pkg mem\n");
			return E_OUT_OF_MEM;
		}
		memset( sopv, 0 , sizeof(struct stat_or_pv) );
		/* is it pv? */
		if (s.s[0]=='$') {
			if (fixup_pvar(param)!=0) {
				LM_ERR("invalid pv %.s as parameter\n",s.s);
				return E_CFG;
			}
			sopv->pv = (pv_spec_t*)(*param);
		} else {
			/* it is string */
			sopv->stat = get_stat( &s );
			if (sopv->stat==0) {
				LM_ERR("variable <%s> not defined\n", s.s);
				return E_CFG;
			}
		}
		pkg_free(s.s);
		*param=(void*)sopv;
		return 0;
	} else if (param_no==2) {
		/* update value - integer */
		if (s.s[0]=='-' || s.s[0]=='+') {
			n = str2s( s.s+1, s.len-1, &err);
			if (s.s[0]=='-')
				n = -n;
		} else {
			n = str2s( s.s, s.len, &err);
		}
		if (err==0){
			if (n==0) {
				LM_ERR("update with 0 has no sense\n");
				return E_CFG;
			}
			pkg_free(*param);
			*param=(void*)n;
			return 0;
		}else{
			LM_ERR("bad update number <%s>\n",(char*)(*param));
			return E_CFG;
		}
	}
	return 0;
}
示例#8
0
static int get_src_grp_fixup(void** param, int param_no)
{
	if (!db_url.s || db_url.len == 0) {
		LM_ERR("get_source_group() needs db_url to be set!\n");
		return E_UNSPEC;
	}

	if(param_no==1)
		return fixup_pvar(param);

	return E_UNSPEC;
}
示例#9
0
static int fixup_send(void ** param, int param_no)
{
	if (param_no == 1 || param_no == 2)
		return fixup_igp(param);
	else if (param_no == 3)
		return fixup_spve(param);
	else if (param_no == 4)
		return fixup_pvar(param);

	LM_CRIT("Unknown parameter number %d\n", param_no);
	return E_UNSPEC;
}
示例#10
0
文件: reg_mod.c 项目: asitm9/opensips
/*! \brief
 * Fixup for "save"+"lookup" functions - domain, flags, AOR params
 */
static int registrar_fixup(void** param, int param_no)
{
	if (param_no == 1) {
		/* name of the table */
		return domain_fixup(param);
	} else if (param_no == 2) {
		/* flags */
		return fixup_spve(param);
	} else {
		/* AOR - from PVAR */
		return fixup_pvar(param);
	}
}
示例#11
0
static int fixup_pvar_wpvar(void **param, int param_no)
{
	if (param_no == 1)
	{
		return fixup_pvar(param);
	}
	if (param_no != 2)
	{
		LM_ERR("invalid parameter number %d\n", param_no);
		return E_UNSPEC;
	}
	return fixup_wpvar(param);
}
示例#12
0
static int fixup_rest_get(void **param, int param_no)
{
	switch (param_no) {
	case 1:
		return fixup_spve(param);
	case 2:
	case 3:
	case 4:
		return fixup_pvar(param);

	default:
		LM_ERR("Too many parameters!\n");
		return -1;
	}
}
示例#13
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 (sp->type!=PVT_AVP && sp->type!=PVT_SCRIPTVAR) {
			LM_ERR("return must be an AVP or SCRIPT VAR!\n");
			return E_SCRIPT;
		}
	}

	return 0;
}
示例#14
0
static int fixup_wpvar(void **param)
{
	int ret;
	pv_spec_t *spec;
	ret = fixup_pvar(param);
	if (ret != 0) {
		LM_ERR("cannot parse pvar\n");
		return -1;
	}
	spec = *(pv_spec_t **)param;
	if (!spec) {
		LM_BUG("cannot find spec");
		return -1;
	}
	if (!spec->setf)
	{
		LM_ERR("pvar not writable\n");
		return -1;
	}
	return 0;
}
示例#15
0
static int fixup_get_profile3(void** param, int param_no)
{
	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 (sp->type!=PVT_AVP && sp->type!=PVT_SCRIPTVAR) {
			LM_ERR("return must be an AVP or SCRIPT VAR!\n");
			return E_SCRIPT;
		}


	}
	return 0;
}
示例#16
0
static int
fixup_lookup3(void **param, int param_no)
{
	str s;

	s.s=(char *)(*param);
	s.len=strlen(s.s);
	if(!s.len) {
		LM_ERR("fixup_lookup3:Parameter %d is empty.\n", param_no);
		return E_CFG;
	}
	if(1==param_no || 2==param_no) {
		/* Expecting input pseudo vars --> pv_elem_t */
		pv_elem_t *model=0;
		if(pv_parse_format(&s,&model) || !model) {
			LM_ERR("Bad format for input PV: '%s'.", s.s);
			return E_CFG;
		}
		*param=(void*)model;
		return 0;
	} else if(3==param_no) {
		/* Expecting AVP spec --> pv_spec_t */
		pv_spec_t *spec;
		int ret=fixup_pvar(param);
		if(ret<0) return ret;
		spec=(pv_spec_t*)(*param);
		if(spec->type!=PVT_AVP) {
			LM_ERR("AVP required for return value!\n");
			return E_CFG;
		}
		return 0;
	} else {
		LM_ERR("Invalid parameter number: %d.\n", param_no);
		return E_CFG;
	}
	return 0;
}
示例#17
0
static int fixup_id(void** param, int param_no)
{
	if (param_no)
		return fixup_pvar(param);
	return -1;
}
示例#18
0
/* first param: DPID: type: INT, AVP, SVAR
 * second param: SRC/DST type: RURI, RURI_USERNAME, AVP, SVAR
 * default value for the second param: $ru.user/$ru.user
 */
static int dp_trans_fixup(void ** param, int param_no){

	int dpid;
	dp_param_p dp_par= NULL;
	char *p, *s = NULL;
	str lstr, partition_name;
	dp_connection_list_t *list = NULL;

	if (param_no < 1 || param_no > 3)
		return 0;

	p = (char*)*param;
	if(!p || (*p == '\0')){
		LM_DBG("null param %i\n", param_no);
		return E_CFG;
	}

	dp_par = (dp_param_p)pkg_malloc(sizeof(dp_param_t));
	if(dp_par == NULL){
		LM_ERR("no more pkg memory\n");
		return E_OUT_OF_MEM;
	}
	memset(dp_par, 0, sizeof(dp_param_t));

	switch (param_no) {
	case 1:
		p = parse_dp_command(p, -1, &partition_name);

		if (p == NULL) {
			LM_ERR("Invalid dp command\n");
			return E_CFG;
		}

		if (!partition_name.s && !partition_name.len) {
			partition_name.s = DEFAULT_PARTITION;
			partition_name.len = sizeof(DEFAULT_PARTITION) - 1;
		}

		if (*partition_name.s != PV_MARKER) {
			list = dp_get_connection(&partition_name);

			if(!list){
				LM_ERR("Partition with name [%.*s] is not defined\n",
						partition_name.len, partition_name.s );
				return -1;
			}
			dp_par->type = DP_VAL_STR;

		} else {
			dp_par->type = DP_VAL_SPEC;
		}

		if (*p != PV_MARKER) {
			lstr.s = p; lstr.len = strlen(p);
			if(str2sint(&lstr, &dpid) != 0) {
				LM_ERR("bad number <%s>\n",(char *)(*param));
				pkg_free(dp_par);
				return E_CFG;
			}

			if(dp_par->type == DP_VAL_SPEC){
				/*int dpid and pv partition_name*/
				dp_par->type = DP_VAL_INT;
				dp_par->v.pv_id.id = dpid;
				if( !pv_parse_spec( &partition_name,
						&dp_par->v.pv_id.partition))
					goto error;
			} else {
				/*DP_VAL_STR remains DP_VAL_STR
					   ( int dpid and str partition_name)*/
				dp_par->v.id = dpid;
			}
		} else {
			if (dp_par->type == DP_VAL_STR) {
				/*pv dpid and str partition_name*/
				dp_par->type = DP_VAL_STR_SPEC;
			} else {
				/*DP_VAL_SPEC remains DP_VAL_SPEC
					    ( pv dpid and pv partition_name) */
				if( !pv_parse_spec( &partition_name,
							 &dp_par->v.sp[1]))
					goto error;
			}

			lstr.s = p; lstr.len = strlen(p);
			if (pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
				goto error;

			verify_par_type(dp_par->v.sp[0]);
		}

		dp_par->hash = list;
		break;

	case 2:
		if( ((s = strchr(p, '/')) == 0) ||( *(s+1)=='\0'))
				goto error;
		*s = '\0'; s++;

		lstr.s = p; lstr.len = strlen(p);
		if(pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
			goto error;

		verify_par_type(dp_par->v.sp[0]);

		lstr.s = s; lstr.len = strlen(s);
		if (pv_parse_spec( &lstr, &dp_par->v.sp[1] )==NULL)
			goto error;

		verify_par_type(dp_par->v.sp[1]);
		if (dp_par->v.sp[1].setf==NULL) {
			LM_ERR("the output PV is read-only!!\n");
			return E_CFG;
		}

		dp_par->type = DP_VAL_SPEC;
		break;

	case 3:
		return fixup_pvar(param);
	}

	*param = (void *)dp_par;

	return 0;

error:
	LM_ERR("failed to parse param %i\n", param_no);
	return E_INVALID_PARAMS;
}