Exemple #1
0
static int lua_sr_pv_unset (lua_State *L)
{
	str pvn;
	pv_spec_t pvs;
    pv_value_t val;
	sr_lua_env_t *env_L;

	env_L = sr_lua_env_get();

	pvn.s = (char*)lua_tostring(L, -1);
	if(pvn.s==NULL || env_L->msg==NULL)
		return 0;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv unset: %s\n", pvn.s);
	if(pv_parse_spec(&pvn, &pvs)<0)
	{
		LM_ERR("unable to parse pv [%s]\n", pvn.s);
		return 0;
	}
	memset(&val, 0, sizeof(pv_value_t));
	val.flags |= PV_VAL_NULL;
	if(pv_set_spec_value(env_L->msg, &pvs, 0, &val)<0)
	{
		LM_ERR("unable to unset pv [%s]\n", pvn.s);
		return 0;
	}

	return 0;
}
Exemple #2
0
static int pv_unset(struct sip_msg* msg, char* pvid, char *foo)
{
	pv_spec_t *sp;
	
	sp = (pv_spec_t*)pvid;
	pv_set_spec_value(msg, sp, 0, NULL);

	return 1;
}
Exemple #3
0
static int lua_sr_pv_sets (lua_State *L)
{
	str pvn;
	pv_spec_t *pvs;
	pv_value_t val;
	sr_lua_env_t *env_L;
	int pl;

	env_L = sr_lua_env_get();

	if(lua_gettop(L)<2)
	{
		LM_ERR("to few parameters [%d]\n",lua_gettop(L));
		return 0;
	}

	if(!lua_isstring(L, -1))
	{
		LM_ERR("Cannot convert to a string when assigning value to variable: %s\n",
				lua_tostring(L, -2));
		return 0;
	}

	memset(&val, 0, sizeof(pv_value_t));
	val.rs.s = (char*)lua_tostring(L, -1);
	val.rs.len = strlen(val.rs.s);
	val.flags |= PV_VAL_STR;

	pvn.s = (char*)lua_tostring(L, -2);
	if(pvn.s==NULL || env_L->msg==NULL)
		return 0;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv set: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		return 0;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		return 0;
	}
	if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to set pv [%s]\n", pvn.s);
		return 0;
	}

	return 0;
}
Exemple #4
0
static int pv_unset(struct sip_msg* msg, char* pvid, char *foo)
{
	pv_spec_t *sp;

	sp = (pv_spec_t*)pvid;
	if(pv_set_spec_value(msg, sp, 0, NULL)<0) {
		LM_ERR("faile to unset variable\n");
		return -1;
	}

	return 1;
}
Exemple #5
0
static int lua_sr_pv_seti (lua_State *L)
{
	str pvn;
	pv_spec_t *pvs;
	pv_value_t val;
	sr_lua_env_t *env_L;
	int pl;

	env_L = sr_lua_env_get();

	if(lua_gettop(L)<2)
	{
		LM_ERR("to few parameters [%d]\n", lua_gettop(L));
		return 0;
	}
	if(!lua_isnumber(L, -1))
	{
		LM_ERR("invalid int parameter\n");
		return 0;
	}
	memset(&val, 0, sizeof(pv_value_t));
	val.ri = lua_tointeger(L, -1);
	val.flags |= PV_TYPE_INT|PV_VAL_INT;

	pvn.s = (char*)lua_tostring(L, -2);
	if(pvn.s==NULL || env_L->msg==NULL)
		return 0;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv set: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		return 0;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		return 0;
	}
	if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to set pv [%s]\n", pvn.s);
		return 0;
	}

	return 0;
}
Exemple #6
0
int  uac_reg_lookup(struct sip_msg *msg, str *src, pv_spec_t *dst, int mode)
{
	char  b_ruri[MAX_URI_SIZE];
	str   s_ruri;
	struct sip_uri puri;
	reg_uac_t *reg = NULL;
	pv_value_t val;

	if(!pv_is_w(dst))
	{
		LM_ERR("dst is not w/\n");
		return -1;
	}
	if(mode==0)
	{
		reg = reg_ht_get_byuuid(src);
		if(reg==NULL)
		{
			LM_DBG("no uuid: %.*s\n", src->len, src->s);
			return -1;
		}
		snprintf(b_ruri, MAX_URI_SIZE, "sip:%.*s@%.*s",
			reg->l_username.len, reg->l_username.s,
			reg->l_domain.len, reg->l_domain.s);
		s_ruri.s = b_ruri; s_ruri.len = strlen(s_ruri.s);
	} else {
		if(parse_uri(src->s, src->len, &puri)!=0)
		{
			LM_ERR("failed to parse uri\n");
			return -2;
		}
		reg = reg_ht_get_byuser(&puri.user, (reg_use_domain)?&puri.host:NULL);
		if(reg==NULL)
		{
			LM_DBG("no user: %.*s\n", src->len, src->s);
			return -1;
		}
		snprintf(b_ruri, MAX_URI_SIZE, "%.*s",
			reg->l_uuid.len, reg->l_uuid.s);
		s_ruri.s = b_ruri; s_ruri.len = strlen(s_ruri.s);
	}
	memset(&val, 0, sizeof(pv_value_t));
	val.flags |= PV_VAL_STR;
	val.rs = s_ruri;
	if(pv_set_spec_value(msg, dst, 0, &val)!=0)
		return -1;

	return 1;
}
Exemple #7
0
static int sr_mono_pv_sets (MonoString *pv, MonoString *sv)
{
	str pvn = {0};
	pv_spec_t *pvs;
    pv_value_t val;
	int pl;
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	pvn.s = mono_string_to_utf8(pv);

	if(pvn.s==NULL || env_M->msg==NULL)
		goto error;

	memset(&val, 0, sizeof(pv_value_t));
	val.rs.s = mono_string_to_utf8(sv);
	if(val.rs.s == NULL)
		goto error;

	val.rs.len = strlen(val.rs.s);
	val.flags |= PV_VAL_STR;
	
	pvn.len = strlen(pvn.s);
	LM_DBG("pv set: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		goto error;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		goto error;
	}
	if(pv_set_spec_value(env_M->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to set pv [%s]\n", pvn.s);
		return -1;
	}

	mono_free(pvn.s);
	return 0;
error:
	if(pvn.s!=NULL)
		mono_free(pvn.s);
	return -1;
}
static SQInteger sqlang_sr_pv_sets (HSQUIRRELVM J)
{
	str pvn;
	pv_spec_t *pvs;
	pv_value_t val;
	sr_sqlang_env_t *env_J;
	int pl;

	env_J = sqlang_sr_env_get();

	if(sqlang_gettop(J)<2) {
		LM_ERR("too few parameters [%d]\n", sqlang_gettop(J));
		return 0;
	}

	if(!sqlang_isstring(J, 1)) {
		LM_ERR("invalid str parameter\n");
		return 0;
	}

	pvn.s = (char*)sqlang_to_string(J, 0);
	if(pvn.s==NULL || env_J->msg==NULL)
		return 0;

	memset(&val, 0, sizeof(pv_value_t));
	val.rs.s = (char*)sqlang_to_string(J, 1);
	val.rs.len = strlen(val.rs.s);
	val.flags |= PV_VAL_STR;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv set: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len) {
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		return 0;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL) {
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		return 0;
	}
	if(pv_set_spec_value(env_J->msg, pvs, 0, &val)<0) {
		LM_ERR("unable to set pv [%s]\n", pvn.s);
		return 0;
	}

	return 0;
}
Exemple #9
0
int set_alias_to_pvar(struct sip_msg* _msg, str *alias, int no, void *p)
{
	pv_value_t val;
	pv_spec_t *pvs=(pv_spec_t*)p;

	if(no && !ald_append_branches)
		return 0;

	/* set the PVAR */
	val.flags = PV_VAL_STR;
	val.ri = 0;
	val.rs = *alias;

	if(pv_set_spec_value(_msg, pvs, (int)(no?EQ_T:ASSIGN_T), &val)<0)
	{
		LM_ERR("setting PV AVP failed\n");
		return -1;
	}
	return 0;
}
Exemple #10
0
static int lua_sr_pv_unset (lua_State *L)
{
	str pvn;
	pv_spec_t *pvs;
	pv_value_t val;
	sr_lua_env_t *env_L;
	int pl;

	env_L = sr_lua_env_get();

	pvn.s = (char*)lua_tostring(L, -1);
	if(pvn.s==NULL || env_L->msg==NULL)
		return 0;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv unset: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		return 0;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		return 0;
	}
	memset(&val, 0, sizeof(pv_value_t));
	val.flags |= PV_VAL_NULL;
	if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to unset pv [%s]\n", pvn.s);
		return 0;
	}

	return 0;
}
Exemple #11
0
static SQInteger sqlang_sr_pv_unset (HSQUIRRELVM J)
{
	str pvn;
	pv_spec_t *pvs;
	pv_value_t val;
	sr_sqlang_env_t *env_J;
	int pl;

	env_J = sqlang_sr_env_get();

	pvn.s = (char*)sqlang_to_string(J, 0);
	if(pvn.s==NULL || env_J->msg==NULL)
		return 0;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv unset: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len) {
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		return 0;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		return 0;
	}
	memset(&val, 0, sizeof(pv_value_t));
	val.flags |= PV_VAL_NULL;
	if(pv_set_spec_value(env_J->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to unset pv [%s]\n", pvn.s);
		return 0;
	}

	return 0;
}
Exemple #12
0
int uac_reg_request_to(struct sip_msg *msg, str *src, unsigned int mode)
{
	char ruri[MAX_URI_SIZE];
	struct sip_uri puri;
	reg_uac_t *reg = NULL;
	pv_value_t val;
	struct action act;
	struct run_act_ctx ra_ctx;

	switch(mode)
	{
		case 0:
			reg = reg_ht_get_byuuid(src);
			break;
		case 1:
			if(reg_use_domain)
			{
				if (parse_uri(src->s, src->len, &puri)!=0)
				{
					LM_ERR("failed to parse uri\n");
					return -2;
				}
				reg = reg_ht_get_byuser(&puri.user, &puri.host);
			} else {
				reg = reg_ht_get_byuser(src, NULL);
			}
			break;
		default:
			LM_ERR("unknown mode: %d\n", mode);
			return -1;
	}

	if(reg==NULL)
	{
		LM_DBG("no user: %.*s\n", src->len, src->s);
		return -1;
	}

	// Set uri ($ru)
	snprintf(ruri, MAX_URI_SIZE, "sip:%.*s@%.*s",
		reg->r_username.len, reg->r_username.s,
		reg->r_domain.len, reg->r_domain.s);
	memset(&act, 0, sizeof(act));
	act.type = SET_URI_T;
	act.val[0].type = STRING_ST;
	act.val[0].u.string = ruri;
	init_run_actions_ctx(&ra_ctx);
	if (do_action(&ra_ctx, &act, msg) < 0) {
		LM_ERR("error while setting request uri\n");
		return -1;
	}

	// Set auth_proxy ($du)
	if (set_dst_uri(msg, &reg->auth_proxy) < 0) {
		LM_ERR("error while setting outbound proxy\n");
		return -1;
	}

	memset(&val, 0, sizeof(pv_value_t));
	val.flags |= PV_VAL_STR;

	// Set auth_realm
	val.rs = reg->realm;
	if(pv_set_spec_value(msg, &auth_realm_spec, 0, &val)!=0) {
		LM_ERR("error while setting auth_realm\n");
		return -1;
	}

	// Set auth_username
	val.rs = reg->auth_username;
	if(pv_set_spec_value(msg, &auth_username_spec, 0, &val)!=0) {
		LM_ERR("error while setting auth_username\n");
		return -1;
	}

	// Set auth_password
	val.rs = reg->auth_password;
	if(pv_set_spec_value(msg, &auth_password_spec, 0, &val)!=0) {
		LM_ERR("error while setting auth_password\n");
		return -1;
	}

	return 1;
}
Exemple #13
0
/*
 * Convert db_val to pv_spec
 */
int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, pv_spec_t *pvs)
{
	pv_value_t pv;
#define LL_LEN 21   /* sign, 19 digits and \0 */
	static char ll_buf[LL_LEN];

	if(dbval->nul)
	{
		pv.flags = PV_VAL_NULL;
	} else
	{
		switch(dbval->type)
		{
			case DB1_STRING:
				pv.flags = PV_VAL_STR;
				pv.rs.s = (char*)dbval->val.string_val;
				pv.rs.len = strlen(pv.rs.s);
			break;
			case DB1_STR:
				pv.flags = PV_VAL_STR;
				pv.rs.s = (char*)dbval->val.str_val.s;
				pv.rs.len = dbval->val.str_val.len;
			break;
			case DB1_BLOB:
				pv.flags = PV_VAL_STR;
				pv.rs.s = (char*)dbval->val.blob_val.s;
				pv.rs.len = dbval->val.blob_val.len;
			break;
			case DB1_INT:
				pv.flags = PV_VAL_INT | PV_TYPE_INT;
				pv.ri = (int)dbval->val.int_val;
			break;
			case DB1_DATETIME:
				pv.flags = PV_VAL_INT | PV_TYPE_INT;
				pv.ri = (int)dbval->val.time_val;
			break;
			case DB1_BITMAP:
				pv.flags = PV_VAL_INT | PV_TYPE_INT;
				pv.ri = (int)dbval->val.bitmap_val;
			break;
			case DB1_BIGINT:
				/* BIGINT is stored as string */
				pv.flags = PV_VAL_STR;
				pv.rs.len = LL_LEN;
				db_longlong2str(dbval->val.ll_val, ll_buf, &pv.rs.len);
				pv.rs.s = ll_buf;
				/* if it fits, also store as 32 bit integer*/
				if (! ((unsigned long long)dbval->val.ll_val & 0xffffffff00000000ULL)) {
					pv.flags |= PV_VAL_INT | PV_TYPE_INT;
					pv.ri = (int)dbval->val.ll_val;
				}
			break;
			default:
				LM_NOTICE("unknown field type: %d, setting value to null\n",
							dbval->type);
				pv.flags = PV_VAL_NULL;
		}
	}

	/* null values are ignored for avp type PV */
	if (pv.flags == PV_VAL_NULL && pvs->type == PVT_AVP)
		return 0;

	/* add value to result pv */
	if (pv_set_spec_value(msg, pvs, 0, &pv) != 0)
	{
		LM_ERR("Failed to add value to spec\n");
		return -1;
	}

	return 0;
}