示例#1
0
static int xl_get_select(struct sip_msg *msg, str *res, str *hp, int hi, int hf)
{
	int i;
	if ((i=run_select(res, (select_t*)hp->s, msg))==1)
		return xl_get_null(msg, res, hp, hi, hf);
	
	return i;
}
示例#2
0
/** Get the function parameter value as integer.
 *  @return  0 - Success
 *          -1 - Cannot get value
 */
int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
{
	int_str val;
	int ret;
	avp_t* avp;
	str tmp;
	pv_value_t pv_val;

	switch(param->type) {
		case FPARAM_INT:
			*dst = param->v.i;
			return 0;
		case FPARAM_REGEX:
		case FPARAM_UNSPEC:
		case FPARAM_STRING:
		case FPARAM_STR:
			return -1;
		case FPARAM_AVP:
			avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
									&val, 0);
			if (unlikely(!avp)) {
				DBG("Could not find AVP from function parameter '%s'\n",
						param->orig);
				return -1;
			}
			if (avp->flags & AVP_VAL_STR) {
				if (str2int(&val.s, (unsigned int*)dst) < 0) {
					LM_ERR("Could not convert AVP string value to int\n");
					return -1;
				}
			} else {
				*dst = val.n;
			}
			break;
		case FPARAM_SELECT:
			ret = run_select(&tmp, param->v.select, msg);
			if (unlikely(ret < 0 || ret > 0)) return -1;
			if (unlikely(str2int(&tmp, (unsigned int*)dst) < 0)) {
				LM_ERR("Could not convert select result to int\n");
				return -1;
			}
			break;
		case FPARAM_PVS:
			if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) &&
					   ((pv_val.flags&(PV_VAL_NULL|PV_VAL_INT))==PV_VAL_INT))){
					*dst=pv_val.ri;
			}else{
				LM_ERR("Could not convert PV to int\n");
				return -1;
			}
			break;
		case FPARAM_PVE:
			return -1;
	}
	return 0;
}
示例#3
0
int pv_get_select(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
	str s = {0, 0};
	select_t *sel = 0;

	sel = (select_t*)param->pvn.u.dname;

	if(sel==0 || run_select(&s, sel, msg)<0 || s.s==0)
		return pv_get_null(msg, param, res);
	return pv_get_strval(msg, param, res, &s);
}
示例#4
0
文件: avp.c 项目: 2pac/kamailio
static int get_avp_id(avp_ident_t* id, fparam_t* p, struct sip_msg* msg)
{
    str str_id;
    avp_t* avp;
    avp_value_t val;
    int ret;

    switch(p->type) {
    case FPARAM_AVP:
	avp = search_avp(p->v.avp, &val, 0);
	if (!avp) {
	    DBG("get_avp_id: AVP %s does not exist\n", p->orig);
	    return -1;
	}
	if ((avp->flags & AVP_VAL_STR) == 0) {
	    DBG("get_avp_id: Not a string AVP\n");
	    return -1;
	}
	str_id = val.s;
	break;

    case FPARAM_SELECT:
	ret = run_select(&str_id, p->v.select, msg);
	if (ret < 0 || ret > 0) return -1;
	break;

	case FPARAM_STR:
	str_id = p->v.str;
	break;

    default:
	ERR("Invalid parameter type in get_avp_id\n");
	return -1;
    }

    return parse_avp_ident(&str_id, id);
}
示例#5
0
/** Get the function parameter value as string or/and integer (if possible).
 *  @return  0 - Success
 *          -1 - Cannot get value
 */
int get_is_fparam(int* i_dst, str* s_dst, struct sip_msg* msg, fparam_t* param, unsigned int *flags)
{
	int_str val;
	int ret;
	avp_t* avp;
	str tmp;
	pv_value_t pv_val;

	*flags = 0;
	switch(param->type) {
		case FPARAM_INT:
			*i_dst = param->v.i;
			*flags |= PARAM_INT;
			return 0;
		case FPARAM_REGEX:
		case FPARAM_UNSPEC:
		case FPARAM_STRING:
			s_dst->s = param->v.asciiz;
			s_dst->len = strlen(param->v.asciiz);
			*flags |= PARAM_STR;
			break;
		case FPARAM_STR:
			*s_dst = param->v.str;
			*flags |= PARAM_STR;
			break;
		case FPARAM_AVP:
			avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
									&val, 0);
			if (unlikely(!avp)) {
				LM_DBG("Could not find AVP from function parameter '%s'\n",
						param->orig);
				return -1;
			}
			if (avp->flags & AVP_VAL_STR) {
				*s_dst = val.s;
				*flags |= PARAM_STR;
				if (str2int(&val.s, (unsigned int*)i_dst) < 0) {
					LM_ERR("Could not convert AVP string value to int\n");
					return -1;
				}
			} else {
				*i_dst = val.n;
				*flags |= PARAM_INT;
			}
			break;
		case FPARAM_SELECT:
			ret = run_select(&tmp, param->v.select, msg);
			if (unlikely(ret < 0 || ret > 0)) return -1;
			if (unlikely(str2int(&tmp, (unsigned int*)i_dst) < 0)) {
				LM_ERR("Could not convert select result to int\n");
				return -1;
			}
			*flags |= PARAM_INT;
			break;
		case FPARAM_PVS:
			if (likely(pv_get_spec_value(msg, param->v.pvs, &pv_val)==0)) {
				if ((pv_val.flags&(PV_VAL_NULL|PV_VAL_INT))==PV_VAL_INT){
					*i_dst=pv_val.ri;
					*flags |= PARAM_INT;
				}
				if ((pv_val.flags&(PV_VAL_NULL|PV_VAL_STR))==PV_VAL_STR){
					*s_dst=pv_val.rs;
					*flags |= PARAM_STR;
				}
			}else{
				LM_ERR("Could not get PV\n");
				return -1;
			}
			break;
		case FPARAM_PVE:
			s_dst->s=pv_get_buffer();
			s_dst->len=pv_get_buffer_size();
			if (unlikely(pv_printf(msg, param->v.pve, s_dst->s, &s_dst->len)!=0)){
				LM_ERR("Could not convert the PV-formated string to str\n");
				s_dst->len=0;
				return -1;
			}
			*flags |= PARAM_STR;
			break;
	}

	/* Let's convert to int, if possible */
	if (!(*flags & PARAM_INT) && (*flags & PARAM_STR) && str2sint(s_dst, i_dst) == 0)
		*flags |= PARAM_INT;

	if (!*flags) return -1;

	return 0;
}
示例#6
0
/** Get the function parameter value as string.
 *  @return  0 - Success
 *          -1 - Cannot get value
 */
int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
{
	int_str val;
	int ret;
	avp_t* avp;
	pv_value_t pv_val;

	switch(param->type) {
		case FPARAM_REGEX:
		case FPARAM_UNSPEC:
		case FPARAM_INT:
			return -1;
		case FPARAM_STRING:
			dst->s = param->v.asciiz;
			dst->len = strlen(param->v.asciiz);
			break;
		case FPARAM_STR:
			*dst = param->v.str;
			break;
		case FPARAM_AVP:
			avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
									&val, 0);
			if (unlikely(!avp)) {
				LM_DBG("Could not find AVP from function parameter '%s'\n",
						param->orig);
				return -1;
			}
			if (likely(avp->flags & AVP_VAL_STR)) {
				*dst = val.s;
			} else {
				/* The caller does not know of what type the AVP will be so
				 * convert int AVPs into string here
				 */
				dst->s = int2str(val.n, &dst->len);
			}
			break;
		case FPARAM_SELECT:
			ret = run_select(dst, param->v.select, msg);
			if (unlikely(ret < 0 || ret > 0)) return -1;
			break;
		case FPARAM_PVS:
			if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) &&
						((pv_val.flags&(PV_VAL_NULL|PV_VAL_STR))==PV_VAL_STR))){
					*dst=pv_val.rs;
			}else{
				LM_ERR("Could not convert PV to str\n");
				return -1;
			}
			break;
		case FPARAM_PVE:
			dst->s=pv_get_buffer();
			dst->len=pv_get_buffer_size();
			if (unlikely(pv_printf(msg, param->v.pve, dst->s, &dst->len)!=0)){
				LM_ERR("Could not convert the PV-formated string to str\n");
				dst->len=0;
				return -1;
			};
			break;
	}
	return 0;
}