Пример #1
0
static int eval_xlstr(struct sip_msg* msg, struct xlstr* s) {
	static char* null_str = "";
	int len;
	if (s->xlfmt) {
		len = xlbuf_size - (xlbuf_tail-xlbuf);
		if (xl_print(msg, s->xlfmt, xlbuf_tail, &len) < 0) {
			ERR(MODULE_NAME": eval_xlstr: Error while formatting result\n");
			return E_UNSPEC;
		}

		/* note: xl_null value is returned as "<null>" string. It's pretty useless checking "if xlbuf_tail==xl_null then xlbuf_tail="";" because xl_null may be also inside string. What about implementing xl_set_nullstr to xl_lib? */
		if ((xl_nul) && (xl_nul->len==len) && strncmp(xl_nul->s, xlbuf_tail, len)==0) {
			s->s = null_str;
		}
		else {
			s->s = xlbuf_tail;
			s->s[len] = '\0';
			xlbuf_tail += len+1;
		}
	}
	else {
		if (!s->s)
			s->s = null_str;
	}
	return 0;
}
Пример #2
0
static int xl_printstr(struct sip_msg* msg, xl_elog_t* format, char** res, int* res_len)
{
    int len;
    
    if (!format || !res) {
	LOG(L_ERR, "xl_printstr: Called with null format or res\n");
	return -1;
    }
    
    if (!xlbuf) {
	xlbuf = pkg_malloc((xlbuf_size+1)*sizeof(char));
	if (!xlbuf) {
	    LOG(L_CRIT, "xl_printstr: No memory left for format buffer\n");
	    return -1;
	}
    }
    
    len = xlbuf_size;
    if (xl_print(msg, format, xlbuf, &len)<0) {
	LOG(L_ERR, "xl_printstr: Error while formating result\n");
	return -1;
    }
    
    if ((xl_nul) && (xl_nul->len == len) && !strncmp(xl_nul->s, xlbuf, len)) {
	return 0;
    }

    *res = xlbuf;
    if (res_len) {
	*res_len=len;
    }
    return len;
}