コード例 #1
0
ファイル: ht_var.c プロジェクト: AndreyRybkin/kamailio
int pv_get_ht_cell_expire(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	str htname;
	ht_pv_t *hpv;
	unsigned int now;

	hpv = (ht_pv_t*)param->pvn.u.dname;

	if(hpv->ht==NULL)
	{
		hpv->ht = ht_get_table(&hpv->htname);
		if(hpv->ht==NULL)
			return pv_get_null(msg, param, res);
	}
	if(pv_printf_s(msg, hpv->pve, &htname)!=0)
	{
		LM_ERR("cannot get $ht name\n");
		return -1;
	}
	if(ht_get_cell_expire(hpv->ht, &htname, &now)!=0)
		return pv_get_null(msg, param, res);
	/* integer */
	return pv_get_uintval(msg, param, res, now);
}
コード例 #2
0
ファイル: tls_select.c プロジェクト: kamailio/kamailio
static int pv_comp(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
    int ind_local, local = 0, issuer = 0, nid = NID_commonName;

    /* copy callback value as we modify it */
    ind_local = param->pvn.u.isname.name.n;
    DBG("ind_local = %x", ind_local);

    if (ind_local & PV_CERT_PEER) {
        local = 0;
        ind_local = ind_local ^ PV_CERT_PEER;
    } else if (ind_local & PV_CERT_LOCAL) {
        local = 1;
        ind_local = ind_local ^ PV_CERT_LOCAL;
    } else {
        BUG("could not determine certificate\n");
        return pv_get_null(msg, param, res);
    }

    if (ind_local & PV_CERT_SUBJECT) {
        issuer = 0;
        ind_local = ind_local ^ PV_CERT_SUBJECT;
    } else if (ind_local & PV_CERT_ISSUER) {
        issuer = 1;
        ind_local = ind_local ^ PV_CERT_ISSUER;
    } else {
        BUG("could not determine subject or issuer\n");
        return pv_get_null(msg, param, res);
    }

    switch(ind_local) {
    case PV_COMP_CN:
        nid = NID_commonName;
        break;
    case PV_COMP_O:
        nid = NID_organizationName;
        break;
    case PV_COMP_OU:
        nid = NID_organizationalUnitName;
        break;
    case PV_COMP_C:
        nid = NID_countryName;
        break;
    case PV_COMP_ST:
        nid = NID_stateOrProvinceName;
        break;
    case PV_COMP_L:
        nid = NID_localityName;
        break;
    default:
        nid = NID_undef;
    }

    if (get_comp(&res->rs, local, issuer, nid, msg) < 0) {
        return pv_get_null(msg, param, res);
    }

    res->flags = PV_VAL_STR;
    return 0;
}
コード例 #3
0
ファイル: tls_select.c プロジェクト: Drooids/openser-xmlrpc
int tlsops_sn(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	static char buf[INT2STR_MAX_LEN];
	X509* cert;
	struct tcp_connection* c;
	int my, serial;
	char* sn;

	if (param->pvn.u.isname.name.n & CERT_PEER) {
		my = 0;
	} else if (param->pvn.u.isname.name.n & CERT_LOCAL) {
		my = 1;
	} else {
		LM_CRIT("could not determine certificate\n");
		return pv_get_null(msg, param, res);
	}
	
	if (get_cert(&cert, &c, msg, my) < 0)
		return pv_get_null(msg, param, res);
	
	serial = ASN1_INTEGER_get(X509_get_serialNumber(cert));
	sn = int2str( serial, &res->rs.len);
	memcpy(buf, sn, res->rs.len);
	res->rs.s = buf;
	res->ri = serial;
	res->flags = PV_VAL_STR | PV_VAL_INT;	
	
	if (!my) X509_free(cert);
	tcpconn_put(c);
	return 0;
}
コード例 #4
0
ファイル: sdpops_mod.c プロジェクト: barchandune/kamailio
static int pv_get_sdp(sip_msg_t *msg, pv_param_t *param,
		pv_value_t *res)
{
	sdp_info_t *sdp = NULL;

	if(msg==NULL || param==NULL)
		return -1;

	if(parse_sdp(msg) < 0) {
		LM_INFO("Unable to parse sdp\n");
		return pv_get_null(msg, param, res);
	}
	sdp = (sdp_info_t*)msg->body;

	if (sdp==NULL) {
		LM_DBG("No SDP\n");
		return pv_get_null(msg, param, res);
	}

	switch(param->pvn.u.isname.name.n)
	{
		case 0:
			return pv_get_strval(msg, param, res, &sdp->raw_sdp);
		default:
			return pv_get_null(msg, param, res);
	}
}
コード例 #5
0
ファイル: rr_mod.c プロジェクト: apogrebennyk/kamailio
static int pv_get_from_tag_initial(sip_msg_t *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct to_body *xto;
	if(msg==NULL)
		return -1;

	if(parse_from_header(msg)<0) {
		LM_ERR("cannot parse From header\n");
		return pv_get_null(msg, param, res);
	}
	if(msg->from==NULL || get_from(msg)==NULL) {
		LM_DBG("no From header\n");
		return pv_get_null(msg, param, res);
	}
	xto = get_from(msg);

	if(is_direction(msg, RR_FLOW_UPSTREAM)==0) {
		if(msg->to==NULL && parse_headers(msg, HDR_TO_F, 0)==-1) {
			LM_ERR("cannot parse To header\n");
			return pv_get_null(msg, param, res);
		}
		if(msg->to==NULL || get_to(msg)==NULL) {
			LM_DBG("no To header\n");
			return pv_get_null(msg, param, res);
		}
		xto = get_to(msg);
	}

	if (xto->tag_value.s==NULL || xto->tag_value.len<=0) {
		LM_DBG("no Tag parameter\n");
		return pv_get_null(msg, param, res);
	}
	return pv_get_strval(msg, param, res, &xto->tag_value);
}
コード例 #6
0
ファイル: ndb_mongodb_mod.c プロジェクト: 4N7HR4X/kamailio
static int pv_get_mongodb(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	mongodbc_pv_t *rpv;

	rpv = (mongodbc_pv_t*)param->pvn.u.dname;
	if(rpv->reply==NULL)
	{
		rpv->reply = mongodbc_get_reply(&rpv->rname);
		if(rpv->reply==NULL)
			return pv_get_null(msg, param, res);
	}


	switch(rpv->rkeyid) {
		case 1:
			/* value */
			if(rpv->reply->jsonrpl.s==NULL)
				return pv_get_null(msg, param, res);
			return pv_get_strval(msg, param, res, &rpv->reply->jsonrpl);
		case 2:
			/* info */
			return pv_get_null(msg, param, res);
		case 3:
			/* size */
			return pv_get_null(msg, param, res);
		case 0:
			/* type */
			return pv_get_sintval(msg, param, res, 0);
		default:
			/* We do nothing. */
			return pv_get_null(msg, param, res);
	}
}
コード例 #7
0
ファイル: tls_select.c プロジェクト: alezzandro/kamailio
static int pv_alt(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
	int ind_local, local = 0, type = GEN_URI;
	
	ind_local = param->pvn.u.isname.name.n;

	if (ind_local & PV_CERT_PEER) {
		local = 0;
		ind_local = ind_local ^ PV_CERT_PEER;
	} else if (ind_local & PV_CERT_LOCAL) {
		local = 1;
		ind_local = ind_local ^ PV_CERT_LOCAL;
	} else {
		BUG("could not determine certificate\n");
		return pv_get_null(msg, param, res);
	}

	switch(ind_local) {
		case PV_COMP_E:    type = GEN_EMAIL; break;
		case PV_COMP_HOST: type = GEN_DNS;   break;
		case PV_COMP_URI:  type = GEN_URI;   break;
		case PV_COMP_IP:   type = GEN_IPADD; break;
		default:
			BUG("ind_local=%d\n", ind_local);
			return pv_get_null(msg, param, res);
	}

	if (get_alt(&res->rs, local, type, msg) < 0) {
		return pv_get_null(msg, param, res);
	}
	
	res->flags = PV_VAL_STR;
	return 0;
}
コード例 #8
0
ファイル: tls_select.c プロジェクト: kamailio/kamailio
static int pv_check_cert(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
    int err;

    switch (param->pvn.u.isname.name.n) {
    case PV_CERT_VERIFIED:
        err = X509_V_OK;
        break;
    case PV_CERT_REVOKED:
        err = X509_V_ERR_CERT_REVOKED;
        break;
    case PV_CERT_EXPIRED:
        err = X509_V_ERR_CERT_HAS_EXPIRED;
        break;
    case PV_CERT_SELFSIGNED:
        err = X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
        break;
    default:
        BUG("unexpected parameter value \"%d\"\n", param->pvn.u.isname.name.n);
        return pv_get_null(msg, param, res);
    }


    if (check_cert(&res->rs, &res->ri, 0, err, msg) < 0) {
        return pv_get_null(msg, param, res);
    }

    res->flags = PV_VAL_STR | PV_VAL_INT;
    return 0;
}
コード例 #9
0
ファイル: json.c プロジェクト: ZRouter/ZRouter
int pv_get_json (struct sip_msg* msg,  pv_param_t* pvp, pv_value_t* val)
{

	pv_json_t * var ;
	json_t * obj;
	json_name * id = (json_name *) pvp->pvn.u.dname;
	UNUSED(id);


	if( expand_tag_list( msg, ((json_name *)pvp->pvn.u.dname)->tags ) < 0)
	{
		LM_ERR("Cannot expand variables in path\n");
		return pv_get_null( msg, pvp, val);
	}


	var = get_pv_json(pvp);

	if( var == NULL )
	{
		/* this is not an error - we simply came across a json spec
		 * pointing a json var which was never set/init */
		LM_DBG("Variable named:%.*s not found\n",id->name.len,id->name.s);
		return pv_get_null( msg, pvp, val);
	}

	obj = get_object(var, pvp, NULL, 0);
	memset(val, 0, sizeof(pv_value_t));

	if( obj == NULL )
		return pv_get_null( msg, pvp, val);

	if( json_object_is_type(obj, json_type_int) )
	{
		val->rs.s = sint2str(json_object_get_int(obj), &val->rs.len);
		val->ri = json_object_get_int(obj);;
		val->flags |= PV_VAL_INT|PV_TYPE_INT|PV_VAL_STR;

	}
	else if( json_object_is_type(obj, json_type_string))
	{
		val->flags = PV_VAL_STR;
		val->rs.s = (char*)json_object_get_string( obj );
#if JSON_LIB_VERSION >= 10
		val->rs.len = json_object_get_string_len( obj );
#else
		val->rs.len = strlen(val->rs.s);
#endif
	} else {
		val->flags = PV_VAL_STR;
		val->rs.s = (char*)json_object_to_json_string( obj );
		val->rs.len = strlen(val->rs.s);
	}

	return 0;
}
コード例 #10
0
ファイル: pv_branch.c プロジェクト: GreenfieldTech/kamailio
int pv_get_nh(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct sip_uri parsed_uri;
	str uri;

	if(msg==NULL || res==NULL)
		return -1;

	if(msg->first_line.type == SIP_REPLY)	/* REPLY doesnt have r/d-uri */
		return pv_get_null(msg, param, res);

    if (msg->dst_uri.s != NULL && msg->dst_uri.len>0)
	{
		uri = msg->dst_uri;
	} else {
		if (msg->new_uri.s!=NULL && msg->new_uri.len>0)
		{
			uri = msg->new_uri;
		} else {
			uri = msg->first_line.u.request.uri;
		}
	}
	if(param->pvn.u.isname.name.n==0) /* uri */
	{
		return pv_get_strval(msg, param, res, &uri);
	}
	if(parse_uri(uri.s, uri.len, &parsed_uri)!=0)
	{
		LM_ERR("failed to parse nh uri [%.*s]\n", uri.len, uri.s);
		return pv_get_null(msg, param, res);
	}
	if(param->pvn.u.isname.name.n==1) /* username */
	{
		if(parsed_uri.user.s==NULL || parsed_uri.user.len<=0)
			return pv_get_null(msg, param, res);
		return pv_get_strval(msg, param, res, &parsed_uri.user);
	} else if(param->pvn.u.isname.name.n==2) /* domain */ {
		if(parsed_uri.host.s==NULL || parsed_uri.host.len<=0)
			return pv_get_null(msg, param, res);
		return pv_get_strval(msg, param, res, &parsed_uri.host);
	} else if(param->pvn.u.isname.name.n==3) /* port */ {
		if(parsed_uri.port.s==NULL)
			return pv_get_5060(msg, param, res);
		return pv_get_strintval(msg, param, res, &parsed_uri.port,
				(int)parsed_uri.port_no);
	} else if(param->pvn.u.isname.name.n==4) /* protocol */ {
		if(parsed_uri.transport_val.s==NULL)
			return pv_get_udp(msg, param, res);
		return pv_get_strintval(msg, param, res, &parsed_uri.transport_val,
				(int)parsed_uri.proto);
	}
	LM_ERR("unknown specifier\n");
	return pv_get_null(msg, param, res);
}
コード例 #11
0
ファイル: t_var.c プロジェクト: adubovikov/kamailio
int pv_get_t(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	tm_cell_t *t;

	if(msg==NULL || param==NULL)
		return -1;

	/* aliases to old TM pvs */
	switch(param->pvn.u.isname.name.n)
	{
		case 2:
			return pv_get_tm_reply_code(msg, param, res);
		case 4:
			return pv_get_tm_branch_idx(msg, param, res);
	}

	t = _tmx_tmb.t_gett();
	if(t==NULL || t==T_UNDEFINED) {
		/* no T */
		if(param->pvn.u.isname.name.n==8 || param->pvn.u.isname.name.n==9) {
			/* id_label_n or id_index_n - attempt to create transaction */
			if(_tmx_tmb.t_newtran(msg)<0) {
				LM_ERR("cannot create the transaction\n");
				return pv_get_null(msg, param, res);
			}
			t = _tmx_tmb.t_gett();
			if (t==NULL || t==T_UNDEFINED) {
				return pv_get_null(msg, param, res);
			}
		} else {
			return pv_get_null(msg, param, res);
		}
	}
	switch(param->pvn.u.isname.name.n)
	{
		case 1:
			return pv_get_uintval(msg, param, res, t->hash_index);
		case 3:
			if(get_route_type()==FAILURE_ROUTE) {
				if(_tmx_tmb.t_get_picked_branch()<0 )
					return pv_get_uintval(msg, param, res, 0);
				if(t->uac[_tmx_tmb.t_get_picked_branch()].reply==FAKED_REPLY)
					return pv_get_uintval(msg, param, res, 1);
			}
			return pv_get_uintval(msg, param, res, 0);
		case 8:
			return pv_get_uintval(msg, param, res, t->label);
		case 9:
			return pv_get_uintval(msg, param, res, t->hash_index);
		default:
			return pv_get_uintval(msg, param, res, t->label);
	}
}
コード例 #12
0
static int ah_get_err(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) {
	if (ah_reply) {
		if (ah_error.s) {
			return pv_get_strval(msg, param, res, &ah_error);
		} else {
			return pv_get_null(msg, param, res);
		}
	} else {
		LM_ERR("the async variables can only be read from an async http worker\n");
		return pv_get_null(msg, param, res);
	}
}
コード例 #13
0
ファイル: evrexec_mod.c プロジェクト: adubovikov/kamailio
static int pv_get_evr(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
{
	if(param==NULL || pv_evr_data==NULL) {
		return pv_get_null(msg, param, res);
	}

	switch(param->pvn.u.isname.name.n) {
		case 0: /* data */
			return pv_get_strval(msg, param, res, pv_evr_data);
		default:
			return pv_get_null(msg, param, res);
	}
}
コード例 #14
0
ファイル: t_var.c プロジェクト: adubovikov/kamailio
int pv_get_t_var_inv(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	pv_spec_t *pv=NULL;

	if(pv_t_update_inv(msg))
		return pv_get_null(msg, param, res);

	pv = (pv_spec_t*)param->pvn.u.dname;
	if(pv==NULL || pv_alter_context(pv))
		return pv_get_null(msg, param, res);

	return pv_get_spec_value(&_pv_tinv.msg, pv, res);
}
コード例 #15
0
ファイル: shvar.c プロジェクト: GeorgeShaw/opensips
int pv_get_shvar(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	int len = 0;
	char *sval = NULL;
	sh_var_t *shv=NULL;

	if(msg==NULL || res==NULL)
		return -1;

	if(param==NULL || param->pvn.u.dname==0)
		return pv_get_null(msg, param, res);

	shv= (sh_var_t*)param->pvn.u.dname;

	lock_shvar(shv);
	if(shv->v.flags&VAR_VAL_STR)
	{
		if(param->pvv.s==NULL || param->pvv.len < shv->v.value.s.len)
		{
			if(param->pvv.s!=NULL)
				pkg_free(param->pvv.s);
			param->pvv.s = (char*)pkg_malloc(shv->v.value.s.len*sizeof(char));
			if(param->pvv.s==NULL)
			{
				unlock_shvar(shv);
				LM_ERR("no more pkg mem\n");
				return pv_get_null(msg, param, res);
			}
		}
		strncpy(param->pvv.s, shv->v.value.s.s, shv->v.value.s.len);
		param->pvv.len = shv->v.value.s.len;

		unlock_shvar(shv);

		res->rs = param->pvv;
		res->flags = PV_VAL_STR;
	} else {
		res->ri = shv->v.value.n;

		unlock_shvar(shv);

		sval = sint2str(res->ri, &len);
		res->rs.s = sval;
		res->rs.len = len;
		res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
	}
	return 0;
}
コード例 #16
0
ファイル: tls_select.c プロジェクト: alezzandro/kamailio
static int pv_tlsext_sn(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
	if (param->pvn.u.isname.name.n != PV_TLSEXT_SNI) {
		BUG("unexpected parameter value \"%d\"\n",
			param->pvn.u.isname.name.n);
		return pv_get_null(msg, param, res);
	}
	
	if (get_tlsext_sn(&res->rs, msg) < 0) {
		return pv_get_null(msg, param, res);
	}
	
	res->flags = PV_VAL_STR;
	return 0;
}
コード例 #17
0
ファイル: tls_select.c プロジェクト: Drooids/openser-xmlrpc
/*
 * Check whether peer certificate exists and verify the result
 * of certificate verification
 */
int tlsops_check_cert(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	static str succ = str_init("1");
	static str fail = str_init("0");

	int err;
	struct tcp_connection* c;
	SSL* ssl;
	X509* cert = 0;

	switch (param->pvn.u.isname.name.n) {
	case CERT_VERIFIED:   err = X509_V_OK;                              break;
	case CERT_REVOKED:    err = X509_V_ERR_CERT_REVOKED;                break;
	case CERT_EXPIRED:    err = X509_V_ERR_CERT_HAS_EXPIRED;            break;
	case CERT_SELFSIGNED: err = X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; break;
	default:
		LM_CRIT("unexpected parameter value \"%d\"\n",
				param->pvn.u.isname.name.n);
		return pv_get_null(msg, param, res);
	}   

	c = get_cur_connection(msg);
	if (!c) return -1;

	ssl = get_ssl(c);
	if (!ssl) goto err;

	if ((cert = SSL_get_peer_certificate(ssl)) && SSL_get_verify_result(ssl) == err) {
		res->rs.s = succ.s;
		res->rs.len = succ.len;
		res->ri   = 1;
	} else {
		res->rs.s = fail.s;
		res->rs.len = fail.len;
		res->ri   = 0;
	}
	res->flags = PV_VAL_STR | PV_VAL_INT;

	if (cert) X509_free(cert);
	tcpconn_put(c);

	return 0;
err:
	if (cert) X509_free(cert);
	if (c) tcpconn_put(c);
	return pv_get_null(msg, param, res);
}
コード例 #18
0
ファイル: tls_select.c プロジェクト: Drooids/openser-xmlrpc
int tlsops_cipher(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	str cipher;
	static char buf[1024];

	struct tcp_connection* c;
	SSL* ssl;

	c = get_cur_connection(msg);
	if (!c) {
		LM_INFO("TLS connection not found in select_cipher\n");
		goto err;
	}
	ssl = get_ssl(c);
	if (!ssl) goto err;

	cipher.s = (char*)SSL_CIPHER_get_name(SSL_get_current_cipher(ssl));
	cipher.len = cipher.s ? strlen(cipher.s) : 0;
	if (cipher.len >= 1024) {
		LM_ERR("cipher name too long\n");
		goto err;
	}
	memcpy(buf, cipher.s, cipher.len);
	res->rs.s = buf;
	res->rs.len = cipher.len;
	res->flags = PV_VAL_STR;
	tcpconn_put(c);

	return 0;
err:
	if (c) tcpconn_put(c);
	return pv_get_null(msg, param, res);
}
コード例 #19
0
ファイル: pv_time.c プロジェクト: AndreyRybkin/kamailio
/**
 * return strftime() formatted time
 */
int pv_get_strftime(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	str s;
#define PV_STRFTIME_BUF_SIZE	64
	static char _pv_strftime_buf[PV_STRFTIME_BUF_SIZE];

	if(msg==NULL || param==NULL)
		return -1;

	if(msg_ctx_id_match(msg, &_cfgutils_msgid)!=1)
	{
		msg_set_time(msg);
		msg_ctx_id_set(msg, &_cfgutils_msgid);
		if(localtime_r(&msg->tval.tv_sec, &_cfgutils_ts) == NULL)
		{
			LM_ERR("unable to break time to attributes\n");
			return -1;
		}
	}
	s.len = strftime(_pv_strftime_buf, PV_STRFTIME_BUF_SIZE,
			param->pvn.u.isname.name.s.s,  &_cfgutils_ts);
	if(s.len<=0)
		return pv_get_null(msg, param, res);
	s.s = _pv_strftime_buf;
	return pv_get_strval(msg, param, res, &s);
}
コード例 #20
0
ファイル: tls_select.c プロジェクト: Drooids/openser-xmlrpc
int tlsops_cert_version(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	static char buf[INT2STR_MAX_LEN];
	X509* cert;
	struct tcp_connection* c;
	char* version;
	int my;

	if (param->pvn.u.isname.name.n & CERT_PEER) {
		my = 0;
	} else if (param->pvn.u.isname.name.n & CERT_LOCAL) {
		my = 1;
	} else {
		LM_CRIT("bug in call to tlsops_cert_version\n");
		return pv_get_null(msg, param, res);
	}

	if (get_cert(&cert, &c, msg, my) < 0) return -1;
	version = int2str(X509_get_version(cert), &res->rs.len);
	memcpy(buf, version, res->rs.len);
	res->rs.s = buf;
	res->flags = PV_VAL_STR;
	if (!my) X509_free(cert);
	tcpconn_put(c);
	return 0;
}
コード例 #21
0
ファイル: tm.c プロジェクト: Deni90/opensips
static int pv_get_tm_ruri(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct cell *t;

	if(msg==NULL || res==NULL)
		return -1;

	/* first get the transaction */
	if (t_check( msg , 0 )==-1) return -1;
	if ( (t=get_t())==0) {
		/* no T */
		if (msg!=NULL&&msg!=FAKED_REPLY && msg->first_line.type==SIP_REQUEST){
			res->rs = *GET_RURI(msg);
			res->flags = PV_VAL_STR;
			return 0;
		}
		return pv_get_null(msg, param,res);
	}

	/* return the RURI for the current branch */
	if (_tm_branch_index>=t->nr_of_outgoings) {
		LM_ERR("BUG: _tm_branch_index greater than nr_of_outgoings\n");
		return -1;
	}

	res->rs = t->uac[_tm_branch_index].uri;

	res->flags = PV_VAL_STR;

	return 0;
}
コード例 #22
0
ファイル: tls_select.c プロジェクト: Drooids/openser-xmlrpc
int tlsops_desc(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	static char buf[128];

	struct tcp_connection* c;
	SSL* ssl;

	c = get_cur_connection(msg);
	if (!c) {
		LM_INFO("TLS connection not found in select_desc\n");
		goto err;
	}
	ssl = get_ssl(c);
	if (!ssl) goto err;

	buf[0] = '\0';
	SSL_CIPHER_description(SSL_get_current_cipher(ssl), buf, 128);
	res->rs.s = buf;
	res->rs.len = strlen(buf);
	res->flags = PV_VAL_STR;

	tcpconn_put(c);

	return 0;
err:
	if (c) tcpconn_put(c);
	return pv_get_null(msg, param, res);
}
コード例 #23
0
ファイル: ht_var.c プロジェクト: AndreyRybkin/kamailio
int pv_get_ht_cv(struct sip_msg *msg,  pv_param_t *param,
		pv_value_t *res)
{
	str htname;
	ht_pv_t *hpv;
	int cnt = 0;

	hpv = (ht_pv_t*)param->pvn.u.dname;

	if(hpv->ht==NULL)
	{
		hpv->ht = ht_get_table(&hpv->htname);
		if(hpv->ht==NULL)
			return pv_get_null(msg, param, res);
	}
	if(pv_printf_s(msg, hpv->pve, &htname)!=0)
	{
		LM_ERR("cannot get $ht name\n");
		return -1;
	}
	
	cnt = ht_count_cells_re(&htname, hpv->ht, 1);

	/* integer */
	return pv_get_sintval(msg, param, res, cnt);
}
コード例 #24
0
ファイル: json.c プロジェクト: OpenSIPS/opensips
int pv_json_iterate(json_t **obj, pv_param_t *pvp, json_name *id, pv_value_t *val)
{
	json_iter_t iter_end;

	if (json_object_is_type(*obj, json_type_object)) {

		if (pvp->pvi.u.ival != id->iter_prev_idx + 1) {
			id->iter_prev_idx = 0;
			id->iter = json_object_iter_begin(*obj);
		} else
			id->iter_prev_idx++;

		iter_end = json_object_iter_end(*obj);
		if (json_object_iter_equal(&id->iter, &iter_end))
			return pv_get_null(NULL, pvp, val);

		if (id->iter_type == ITER_KEYS) {
			val->flags = PV_VAL_STR;
			val->rs.s = (char *)json_object_iter_peek_name(&id->iter);
			val->rs.len = strlen(val->rs.s);
		} else
			*obj = json_object_iter_peek_value(&id->iter);

		json_object_iter_next(&id->iter);	

	} else if (json_object_is_type(*obj, json_type_array)) {

		if (id->iter_type != ITER_NONE) {
			LM_DBG("Invalid object-like iteration for arrays\n");
			return -1;
		}

		if (pvp->pvi.u.ival == json_object_array_length(*obj)) {
			id->iter_prev_idx = 0;
			return pv_get_null(NULL, pvp, val);
		}

		*obj = json_object_array_get_idx(*obj, pvp->pvi.u.ival);

	} else {
		LM_DBG("Can only iterate over arrays or objects\n");
		return -1;
	}

	return 0;
}
コード例 #25
0
ファイル: topology_hiding.c プロジェクト: SimleCat/opensips
static int pv_topo_callee_callid(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
	struct dlg_cell *dlg;
	int req_len = 0,i;
	char *p;

	if(res==NULL)
		return -1;

	if ( (dlg=dlg_api.get_dlg())==NULL || 
	(!dlg_api.is_mod_flag_set(dlg,TOPOH_HIDE_CALLID))) {
		return pv_get_null( msg, param, res);
	}


	req_len = calc_base64_encode_len(dlg->callid.len) + topo_hiding_prefix.len;

	if (req_len*2 > callid_buf_len) {
		callid_buf = pkg_realloc(callid_buf,req_len*2);
		if (callid_buf == NULL) {
			LM_ERR("No more pkg\n");
			return pv_get_null( msg, param, res);
		}

		callid_buf_len = req_len*2;
	}

	memcpy(callid_buf+req_len,topo_hiding_prefix.s,topo_hiding_prefix.len);
	for (i=0;i<dlg->callid.len;i++)
		callid_buf[i] = dlg->callid.s[i] ^ topo_hiding_seed.s[i%topo_hiding_seed.len];

	base64encode((unsigned char *)(callid_buf+topo_hiding_prefix.len+req_len),
		     (unsigned char *)(callid_buf),dlg->callid.len);

	p = callid_buf+ 2*req_len - 1;
	while (*p == '=') {
		*p = '-';
		p--;
	}

	res->rs.s = callid_buf+req_len;
	res->rs.len = req_len;
	res->flags = PV_VAL_STR;

	return 0;
}
コード例 #26
0
ファイル: tls_select.c プロジェクト: alezzandro/kamailio
static int pv_bits(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
	if (get_bits(&res->rs, &res->ri, msg) < 0) {
		return pv_get_null(msg, param, res);
	}
	res->flags = PV_VAL_STR | PV_VAL_INT;
	return 0;
}
コード例 #27
0
ファイル: tls_select.c プロジェクト: alezzandro/kamailio
static int pv_desc(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
	if (get_desc(&res->rs, msg) < 0) {
		return pv_get_null(msg, param, res);
	}
	res->flags = PV_VAL_STR;
	return 0;
}
コード例 #28
0
ファイル: kex_mod.c プロジェクト: 4N7HR4X/kamailio
static int pv_get_sruid_val(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	if(res==NULL)
		return -1;
	if(sruid_next(&_kex_sruid)<0)
		return pv_get_null(msg, param, res);
	return pv_get_strval(msg, param, res, &_kex_sruid.uid);
}
コード例 #29
0
ファイル: pv_branch.c プロジェクト: GreenfieldTech/kamailio
int pv_get_sndto(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	struct onsend_info* snd_inf;
	struct ip_addr ip;
	str s;

	snd_inf=get_onsend_info();
	if (! likely(snd_inf && snd_inf->send_sock))
		return pv_get_null(msg, param, res);

	switch(param->pvn.u.isname.name.n)
	{
		case 1: /* af */
			return pv_get_uintval(msg, param, res,
					(int)snd_inf->send_sock->address.af);
		case 2: /* port */
			return pv_get_uintval(msg, param, res,
					(int)su_getport(snd_inf->to));
		case 3: /* proto */
			return pv_get_uintval(msg, param, res,
					(int)snd_inf->send_sock->proto);
		case 4: /* buf */
			s.s   = snd_inf->buf;
			s.len = snd_inf->len;
			return pv_get_strval(msg, param, res, &s);
		case 5: /* len */
			return pv_get_uintval(msg, param, res,
					(int)snd_inf->len);
		case 6: /* sproto */
			if(get_valid_proto_string((int)snd_inf->send_sock->proto,
						0, 0, &s)<0)
				return pv_get_null(msg, param, res);
			return pv_get_strval(msg, param, res, &s);
		default:
			/* 0 - ip */
			su2ip_addr(&ip, snd_inf->to);
			s.s = ip_addr2a(&ip);
			s.len = strlen(s.s);
			return pv_get_strval(msg, param, res, &s);
	}

	return 0;
}
コード例 #30
0
ファイル: tls_select.c プロジェクト: alezzandro/kamailio
static int pv_validity(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
	int bound;
	
	switch (param->pvn.u.isname.name.n) {
	case PV_CERT_NOTBEFORE: bound = NOT_BEFORE; break;
	case PV_CERT_NOTAFTER:  bound = NOT_AFTER;  break;
	default:
		BUG("unexpected parameter value \"%d\"\n", param->pvn.u.isname.name.n);
		return pv_get_null(msg, param, res);
	}

	if (get_validity(&res->rs, 0, bound, msg) < 0) {
		return pv_get_null(msg, param, res);
	}
	
	res->flags = PV_VAL_STR;
	return 0;
}