コード例 #1
0
ファイル: dp_db.c プロジェクト: adubovikov/kamailio
/**
 * check if string has pvs
 * returns -1 if error, 0 if found, 1 if not found
 */
int dpl_check_pv(str *in)
{
	char *p;
	pv_spec_t *spec = NULL;
	str s;
	int len;

	if(in==NULL || in->s==NULL)
		return -1;

	LM_DBG("parsing [%.*s]\n", in->len, in->s);

	if(in->len == 0)
		return 1;

	p = in->s;

	while(is_in_str(p,in))
	{
		while(is_in_str(p,in) && *p!=PV_MARKER)
			p++;
		if(*p == '\0' || !is_in_str(p,in))
			break;
		/* last char is $ ? */
		if(!is_in_str(p+1, in))
			break;
		s.s = p;
		s.len = in->s+in->len-p;
		len = 0;
		spec = pv_spec_lookup(&s, &len);
		if(spec!=NULL) {
			/* found a variable */
			LM_DBG("string [%.*s] has variables\n", in->len, in->s);
			return 0;
		}
		if(len) p += len;
		else p++;
	}

	/* not found */
	return 1;
}
コード例 #2
0
ファイル: auth_db_mod.c プロジェクト: lbalaceanu/kamailio
/*
 * Parse extra credentials list
 */
int parse_aaa_pvs(char *definition, pv_elem_t **pv_def, int *cnt)
{
	pv_elem_t *pve;
	str pv;
	char *p;
	char *end;
	char *sep;

	p = definition;
	if (p==0 || *p==0)
		return 0;

	*pv_def = 0;
	*cnt = 0;

	/* get element by element */
	while ( (end=strchr(p,';'))!=0 || (end=p+strlen(p))!=p ) {
		/* new pv_elem_t */
		if ( (pve=(pv_elem_t*)pkg_malloc(sizeof(pv_elem_t)))==0 ) {
			LM_ERR("no more pkg mem\n");
			goto error;
		}
		memset( pve, 0, sizeof(pv_elem_t));

		/* definition is between p and e */
		/* search backwards because PV definition may contain '=' characters */
		for (sep = end; sep >= p && *sep != '='; sep--);
		if (sep > p) {
			/* pv=column style */
			/* set column name */
			pve->text.s = sep + 1;
			pve->text.len = end - pve->text.s;
			trim(&pve->text);
			if (pve->text.len == 0) {
				goto parse_error;
			}
			/* set pv spec */
			pv.s = p;
			pv.len = sep - p;
			trim(&pv);
			if (pv.len == 0) {
				goto parse_error;
			}
		} else {
			/* no pv, only column name */
			pve->text.s = p;
			pve->text.len = end - pve->text.s;
			trim(&pve->text);
			if (pve->text.len == 0) {
				goto parse_error;
			}
			/* create an avp definition for the spec parser */
			pv.s = (char*)pkg_malloc(pve->text.len + 7);
			if (pv.s == NULL) {
				LM_ERR("no more pkg mem\n");
				goto parse_error;
			}
			pv.len = snprintf(pv.s, pve->text.len + 7, "$avp(%.*s)",
					pve->text.len, pve->text.s);
		}

		/* create a pv spec */
		LM_DBG("column: %.*s  pv: %.*s\n", pve->text.len, pve->text.s, pv.len, pv.s);
		pve->spec = pv_spec_lookup(&pv, NULL);
		if(pve->spec==NULL || pve->spec->setf == NULL) {
			LM_ERR("PV is not writeable: %.*s\n", pv.len, pv.s);
			goto parse_error;
		}

		/* link the element */
		pve->next = *pv_def;
		*pv_def = pve;
		(*cnt)++;
		pve = 0;
		/* go to the end */
		p = end;
		if (*p==';') {
			p++;
		}
		if (*p==0) {
			break;
		}
	}

	return 0;
parse_error:
	LM_ERR("parse failed in \"%s\" at pos %d(%s)\n",
		definition, (int)(long)(p-definition),p);
error:
	pkg_free( pve );
	pv_elem_free_all( *pv_def );
	*pv_def = 0;
	*cnt = 0;
	return -1;
}
コード例 #3
0
ファイル: pvapi.c プロジェクト: btriller/kamailio
int pv_parse_format(str *in, pv_elem_p *el)
{
	char *p, *p0;
	int n = 0;
	pv_elem_p e, e0;
	str s;
	int len;

	if(in==NULL || in->s==NULL || el==NULL)
		return -1;

	/*LM_DBG("parsing [%.*s]\n", in->len, in->s);*/

	if(in->len == 0)
	{
		*el = pkg_malloc(sizeof(pv_elem_t));
		if(*el == NULL)
			goto error;
		memset(*el, 0, sizeof(pv_elem_t));
		(*el)->text = *in;
		return 0;
	}

	p = in->s;
	*el = NULL;
	e = e0 = NULL;

	while(is_in_str(p,in))
	{
		e0 = e;
		e = pkg_malloc(sizeof(pv_elem_t));
		if(!e)
			goto error;
		memset(e, 0, sizeof(pv_elem_t));
		n++;
		if(*el == NULL)
			*el = e;
		if(e0)
			e0->next = e;

		e->text.s = p;
		while(is_in_str(p,in) && *p!=PV_MARKER)
			p++;
		e->text.len = p - e->text.s;

		if(*p == '\0' || !is_in_str(p,in))
			break;
		s.s = p;
		s.len = in->s+in->len-p;
		e->spec = pv_spec_lookup(&s, &len);
		if(e->spec==NULL)
			goto error;
		p0 = p + len;

		if(*p0 == '\0')
			break;
		p = p0;
	}
	/*LM_DBG("format parsed OK: [%d] items\n", n);*/

	if(*el == NULL)
		return -1;

	return 0;

error:
	pv_elem_free_all(*el);
	*el = NULL;
	return -1;
}