Ejemplo n.º 1
0
static int fixup_replace_disp_uri(void** param)
{
	char *p;
	str *s = (str*)*param;
	str repl;

	/* check to see if it is already quoted */
	if ((s->s[0] == '\"' && s->s[s->len - 1] == '\"') ||
			str_check_token(s)) {
		if (pkg_nt_str_dup(&repl, s) < 0)
			return E_OUT_OF_MEM;
		*s = repl;
		return 0;
	}

	/* put " around display name */
	p = (char*)pkg_malloc(s->len+3);
	if (p==0) {
		LM_CRIT("no more pkg mem\n");
		return E_OUT_OF_MEM;
	}
	p[0] = '\"';
	memcpy(p+1, s->s, s->len);
	p[s->len+1] = '\"';
	p[s->len+2] = '\0';
	s->s = p;
	s->len += 2;

	return 0;
}
Ejemplo n.º 2
0
/*! \brief Return true if the argument matches the regular expression parameter */
static int w_pcre_match(struct sip_msg* _msg, str* string, str* _regex_s)
{
	pcre *pcre_re = NULL;
	int pcre_rc;
	const char *pcre_error;
	int pcre_erroffset;
	str regex;

	if (pkg_nt_str_dup(&regex, _regex_s) < 0)
		return -1;

	pcre_re = pcre_compile(regex.s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
	if (pcre_re == NULL) {
		LM_ERR("pcre_re compilation of '%s' failed at offset %d: %s\n", regex.s, pcre_erroffset, pcre_error);
		pkg_free(regex.s);
		return -4;
	}

	pcre_rc = pcre_exec(
		pcre_re,                    /* the compiled pattern */
		NULL,                       /* no extra data - we didn't study the pattern */
		string->s,                   /* the matching string */
		(int)(string->len),          /* the length of the subject */
		0,                          /* start at offset 0 in the string */
		0,                          /* default options */
		NULL,                       /* output vector for substring information */
		0);                         /* number of elements in the output vector */

	/* Matching failed: handle error cases */
	if (pcre_rc < 0) {
		switch(pcre_rc) {
			case PCRE_ERROR_NOMATCH:
				LM_DBG("'%s' doesn't match '%s'\n", string->s, regex.s);
				break;
			default:
				LM_DBG("matching error '%d'\n", pcre_rc);
				break;
		}
		pcre_free(pcre_re);
		pkg_free(regex.s);
		return -1;
	}

	pcre_free(pcre_re);
	pkg_free(regex.s);
	LM_DBG("'%s' matches '%s'\n", string->s, regex.s);
	return 1;
}
Ejemplo n.º 3
0
static int fixup_str(void **param)
{
	str *s;

	s = pkg_malloc(sizeof *s);
	if (!s) {
		LM_ERR("no more pkg mem\n");
		return E_OUT_OF_MEM;
	}

	if (pkg_nt_str_dup(s, (str*)*param) < 0)
		return E_OUT_OF_MEM;

	*param = s;

	return 0;
}