Beispiel #1
0
char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
{
	register char* p;
	register unsigned int val;

	if ((end - begin) < 4) {
		hdr->type = HDR_ERROR_T;
		return begin;
	}

	p = begin;

	val = LOWER_DWORD(READ(p));
	hdr->name.s = begin;

	switch(val) {
	FIRST_QUATERNIONS;

	default:
		switch(LOWER_BYTE(*p)) {
		case 't':
			switch(LOWER_BYTE(*(p + 1))) {
			case 'o':
			case ' ':
				hdr->type = HDR_TO_T;
				p += 2;
				goto dc_end;

			case ':':
				hdr->type = HDR_TO_T;
				hdr->name.len = 1;
				return (p + 2);
			}
			break;

		case 'v': PARSE_COMPACT(HDR_VIA_T);           break;
		case 'f': PARSE_COMPACT(HDR_FROM_T);          break;
		case 'i': PARSE_COMPACT(HDR_CALLID_T);        break;
		case 'm': PARSE_COMPACT(HDR_CONTACT_T);       break;
		case 'l': PARSE_COMPACT(HDR_CONTENTLENGTH_T); break;
		case 'k': PARSE_COMPACT(HDR_SUPPORTED_T);     break;
		case 'c': PARSE_COMPACT(HDR_CONTENTTYPE_T);   break;
		case 'o': PARSE_COMPACT(HDR_EVENT_T);         break;
		case 'x': PARSE_COMPACT(HDR_SESSIONEXPIRES_T);break;
		case 'a': PARSE_COMPACT(HDR_ACCEPTCONTACT_T); break;
		case 'u': PARSE_COMPACT(HDR_ALLOWEVENTS_T);   break;
		case 'e': PARSE_COMPACT(HDR_CONTENTENCODING_T); break;
		case 'b': PARSE_COMPACT(HDR_REFERREDBY_T);    break;
		case 'j': PARSE_COMPACT(HDR_REJECTCONTACT_T); break;
		case 'd': PARSE_COMPACT(HDR_REQUESTDISPOSITION_T); break;
		case 's': PARSE_COMPACT(HDR_SUBJECT_T);       break;
		case 'r': PARSE_COMPACT(HDR_REFER_TO_T);      break;
		}
		goto other;
        }

	     /* Double colon hasn't been found yet */
 dc_end:
       	p = skip_ws(p, end - p);
	if (*p != ':') {
	        goto other;
	} else {
		hdr->name.len = p - hdr->name.s;
		return (p + 1);
	}

	     /* Unknown header type */
 other:
	p = q_memchr(p, ':', end - p);
	if (!p) {        /* No double colon found, error.. */
		hdr->type = HDR_ERROR_T;
		hdr->name.s = 0;
		hdr->name.len = 0;
		return 0;
	} else {
		hdr->type = HDR_OTHER_T;
		hdr->name.len = p - hdr->name.s;
		return (p + 1);
	}
}
Beispiel #2
0
char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
{
	register char* p;
	register unsigned int val;

	if ((end - begin) < 4) {
		hdr->type = HDR_ERROR_T;
		return begin;
	}

	p = begin;

	val = LOWER_DWORD(READ(p));
	hdr->name.s = begin;

	switch(val) {

		FIRST_QUATERNIONS;

		default:
			switch(LOWER_BYTE(*p)) {
				case 't':
					switch(LOWER_BYTE(*(p + 1))) {
						case 'o':
							p += 2;
							hdr->type = HDR_TO_T;
							hdr->name.len = 2;
							goto dc_cont;
						case ' ':
						case '\t':
							p += 2;
							hdr->type = HDR_TO_T;
							hdr->name.len = 1;
							goto dc_end;
						case ':':
							hdr->type = HDR_TO_T;
							hdr->name.len = 1;
							return (p + 2);
					}
					break;
				case 'v': PARSE_COMPACT(HDR_VIA_T);           break;
				case 'f': PARSE_COMPACT(HDR_FROM_T);          break;
				case 'i': PARSE_COMPACT(HDR_CALLID_T);        break;
				case 'm': PARSE_COMPACT(HDR_CONTACT_T);       break;
				case 'l': PARSE_COMPACT(HDR_CONTENTLENGTH_T); break;
				case 'k': PARSE_COMPACT(HDR_SUPPORTED_T);     break;
				case 'c': PARSE_COMPACT(HDR_CONTENTTYPE_T);   break;
				case 'o': PARSE_COMPACT(HDR_EVENT_T);         break;
				case 'x': PARSE_COMPACT(HDR_SESSION_EXPIRES_T); break;
			}
			goto other;
	}
	/* the above swtich will never continue here */


 dc_end:
	/* HDR name entirely found, consume WS till colon */
	/* overflow during the "switch-case" parsing ? */
	if (p>=end)
		goto error;
	p = skip_ws(p, end);
	if (*p != ':')
		goto error;
	/* hdr type, name should be already set at this point */
	return (p+1);
	/*done*/


 dc_cont:
	/* HDR name partially found, see what's next */
	/* overflow during the "switch-case" parsing ? */
	if (p>=end)
		goto error;
	/* hdr type, name should be already set at this point (for partial finding) */
	switch (*p) {
		case ':' :
			return (p+1);
		case ' ':
		case '\t':
			/* consume spaces to the end of name */
			p = skip_ws( p+1, end);
			if (*p != ':')
				goto error;
			return (p+1);
		/* default: it seems the hdr name continues, fall to "other" */
	}


 other:
	/* Unknown header type */
	hdr->type = HDR_OTHER_T;
	/* if overflow during the "switch-case" parsing, the "while" will
	 * exit and we will fall in the "error" section */
	while ( p < end ) {
		switch (*p) {
			case ':' :
				hdr->name.len = p - hdr->name.s;
				return (p + 1);
			case ' ' :
			case '\t':
				hdr->name.len = p - hdr->name.s;
				p = skip_ws(p+1, end);
				if (*p != ':')
					goto error;
				return (p+1);
		}
		p++;
	}

 error:
	/* No double colon found, error.. */
	hdr->type = HDR_ERROR_T;
	hdr->name.s = 0;
	hdr->name.len = 0;
	return 0;
}