Beispiel #1
0
static pj_status_t sipclf_add_index(pj_str_t* line1, int value)
{
    value += 61; /*the headers index length + \n*/
    pj_val_to_hex_digit( (value & 0xFF00) >> 8, line1->ptr + line1->slen);
    pj_val_to_hex_digit( (value & 0x00FF),          line1->ptr + line1->slen + 2);
    line1->slen += 4;
}
Beispiel #2
0
PJ_DEF(pj_ssize_t) pj_strncpy2_escape( char *dst_str, const pj_str_t *src_str,
				       pj_ssize_t max, const pj_cis_t *unres)
{
    const char *src = src_str->ptr;
    const char *src_end = src + src_str->slen;
    char *dst = dst_str;
    char *dst_end = dst + max;

    if (max < src_str->slen)
	return -1;

    while (src != src_end && dst != dst_end) {
	if (pj_cis_match(unres, *src)) {
	    *dst++ = *src++;
	} else {
	    if (dst < dst_end-2) {
		*dst++ = '%';
		pj_val_to_hex_digit(*src, dst);
		dst+=2;
		++src;
	    } else {
		break;
	    }
	}
    }

    return src==src_end ? dst-dst_str : -1;
}
Beispiel #3
0
/* Transform digest to string.
 * output must be at least PJSIP_MD5STRLEN+1 bytes.
 *
 * NOTE: THE OUTPUT STRING IS NOT NULL TERMINATED!
 */
static void digest2str(const unsigned char digest[], char *output)
{
    int i;
    for (i = 0; i<16; ++i) {
	pj_val_to_hex_digit(digest[i], output);
	output += 2;
    }
}
Beispiel #4
0
static pj_status_t write_string_escaped(const pj_str_t *value,
                                        struct write_state *st)
{
    const char *ip = value->ptr;
    const char *iend = value->ptr + value->slen;
    char buf[ESC_BUF_LEN];
    char *op = buf;
    char *oend = buf + ESC_BUF_LEN;
    pj_status_t status;

    while (ip != iend) {
	/* Write to buffer to speedup writing instead of calling
	 * the callback one by one for each character.
	 */
	while (ip != iend && op != oend) {
	    if (oend - op < 2)
		break;

	    if (*ip == '"') {
		*op++ = '\\';
		*op++ = '"';
		ip++;
	    } else if (*ip == '\\') {
		*op++ = '\\';
		*op++ = '\\';
		ip++;
	    } else if (*ip == '/') {
		*op++ = '\\';
		*op++ = '/';
		ip++;
	    } else if (*ip == '\b') {
		*op++ = '\\';
		*op++ = 'b';
		ip++;
	    } else if (*ip == '\f') {
		*op++ = '\\';
		*op++ = 'f';
		ip++;
	    } else if (*ip == '\n') {
		*op++ = '\\';
		*op++ = 'n';
		ip++;
	    } else if (*ip == '\r') {
		*op++ = '\\';
		*op++ = 'r';
		ip++;
	    } else if (*ip == '\t') {
		*op++ = '\\';
		*op++ = 't';
		ip++;
	    } else if ((*ip >= 32 && *ip < 127)) {
		/* unescaped */
		*op++ = *ip++;
	    } else {
		/* escaped */
		if (oend - op < 6)
		    break;
		*op++ = '\\';
		*op++ = 'u';
		*op++ = '0';
		*op++ = '0';
		pj_val_to_hex_digit(*ip, op);
		op+=2;
		ip++;
	    }
	}

	CHECK( st->writer( buf, (unsigned)(op-buf), st->user_data) );
	op = buf;
    }

    return PJ_SUCCESS;
}