Пример #1
0
static int fixup_set_params_free(void** param, int param_no)
{
	if (param_no <= 3) {
		return fixup_free_spve_null(param, 1);
	}

	if (param_no == 4) {
		return fixup_free_pvar_null(param, 1);
	}

	ERR("invalid parameter number <%d>\n", param_no);
	return -1;
}
Пример #2
0
/*
 * Free curl_connect params.
 */
static int fixup_free_curl_connect(void** param, int param_no)
{
	if (param_no == 1) {
		/* Char strings don't need freeing */
		return 0;
	}
	if (param_no == 2) {
		return fixup_free_spve_null(param, 1);
	}

	if (param_no == 3) {
		return fixup_free_pvar_null(param, 1);
	}
	
	LM_ERR("invalid parameter number <%d>\n", param_no);
	return -1;
}
Пример #3
0
int fixup_free_none_spve(void** param, int param_no)
{
	if(param_no==2)
		return fixup_free_spve_null(param, 1);
	return 0;
}
Пример #4
0
int fixup_free_spve_all(void** param, int param_no)
{
	return fixup_free_spve_null(param, 1);
}
Пример #5
0
/*!
 * \brief Evaluate kazoo transformations
 * \param msg SIP message
 * \param tp transformation
 * \param subtype transformation type
 * \param val pseudo-variable
 * \return 0 on success, -1 on error
 */
int kz_tr_eval(struct sip_msg *msg, tr_param_t *tp, int subtype, pv_value_t *val)
{

	str sv;
	pv_value_t* pv;
	pv_value_t v;
    str v2 = {0,0};
	void* v1 = NULL;

	if(val==NULL || (val->flags&PV_VAL_NULL))
		return -1;


	kz_tr_set_crt_buffer();

	switch(subtype)
	{
		case TR_KAZOO_ENCODE:
			if(!(val->flags&PV_VAL_STR))
				return -1;

			pv = kz_alloc_pv_value();
			if(pv == NULL)
			{
				LM_ERR("kazoo encode transform : no more private memory\n");
				return -1;
			}

			if( kz_amqp_encode_ex(&val->rs, pv ) != 1) {
				LM_ERR("error encoding value\n");
				kz_destroy_pv_value(pv);
				return -1;
			}

			strncpy(_kz_tr_buffer, pv->rs.s, pv->rs.len);
			_kz_tr_buffer[pv->rs.len] = '\0';

			val->flags = PV_VAL_STR;
			val->ri = 0;
			val->rs.s = _kz_tr_buffer;
			val->rs.len = pv->rs.len;

			kz_destroy_pv_value(pv);
			kz_free_pv_value(val);

			break;
		case TR_KAZOO_JSON:
			if(!(val->flags&PV_VAL_STR))
				return -1;

			if(tp==NULL)
			{
				LM_ERR("kazoo json transform invalid parameter\n");
				return -1;
			}

			pv = kz_alloc_pv_value();
			if(pv == NULL)
			{
				LM_ERR("kazoo encode transform : no more private memory\n");
				return -1;
			}


			if(tp->type == TR_PARAM_STRING)
			{
				v1 = tp->v.s.s;
				if(fixup_spve_null(&v1, 1) != 0) {
					LM_ERR("cannot get spve_value from TR_PARAM_STRING : %.*s\n", tp->v.s.len, tp->v.s.s);
					return -1;
				}
				if (fixup_get_svalue(msg, (gparam_p)v1, &v2) != 0) {
					LM_ERR("cannot get value from TR_PARAM_STRING\n");
					fixup_free_spve_null(&v1, 1);
					return -1;
				}
				fixup_free_spve_null(&v1, 1);
				sv = v2;
			} else {
				if(pv_get_spec_value(msg, (pv_spec_p)tp->v.data, &v)!=0
						|| (!(v.flags&PV_VAL_STR)) || v.rs.len<=0)
				{
					LM_ERR("value cannot get spec value in json transform\n");
					kz_destroy_pv_value(pv);
					return -1;
				}
				sv = v.rs;
			}


			if(kz_json_get_field_ex(&val->rs, &sv, pv ) != 1) {
				LM_ERR("error getting json\n");
				kz_destroy_pv_value(pv);
				return -1;
			}
            
			strncpy(_kz_tr_buffer, pv->rs.s, pv->rs.len);
			_kz_tr_buffer[pv->rs.len] = '\0';

			val->flags = PV_VAL_STR;
			val->ri = 0;
			val->rs.s = _kz_tr_buffer;
			val->rs.len = pv->rs.len;

			kz_destroy_pv_value(pv);
			kz_free_pv_value(val);

			break;

		default:
			LM_ERR("unknown kazoo transformation subtype %d\n", subtype);
			return -1;
	}
	return 0;
}