示例#1
0
char* decode_mime_type(char* const start, const char* const end, unsigned int* const mime_type)
{
	int node;
	char *mark;
	char *p;
	unsigned int type_candidate;

	p = start;

	/* search the begining of the type */
	while ( p<end && (*p==' ' || *p=='\t' ||
	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
		p++;
	if (p==end)
		goto error;

	/* parse the type */
	if (*p=='*') {
		*mime_type = TYPE_ALL<<16;
		p++;
	} else {
		node = 0;
		mark = p;
		type_candidate = TYPE_UNKNOWN;
		while (p<end && is_mime_char(*p)  ) {
			while ( node!=-1 && !is_char_equal(*p,type_tree[node].c) ){
				node = type_tree[node].next;
			}
			if (node!=-1) {
				type_candidate = type_tree[node].final;
				if (type_tree[node].nr_sons)
					node++;
				else
					node = -1;
			} else {
				/* end of the type tree has reached,
				but the type has still some remaining
				characters (Miklos) */
				type_candidate = TYPE_UNKNOWN;
			}
			p++;
		}
示例#2
0
char* decode_mime_type(char *start, char *end, unsigned int *mime_type, content_t * con)
{
	int node;
	char *mark;
	char *p;

	p = start;

	LM_DBG("Decoding MIME type for:[%.*s]\n",(int)(end-start),start);

	/* search the begining of the type */
	while ( p<end && (*p==' ' || *p=='\t' ||
	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
		p++;
	if (p==end)
		goto error;

	/* parse the type */
	if (*p=='*') {
		*mime_type = TYPE_ALL<<16;
		p++;
	} else {
		node = 0;
		mark = p;
		while (p<end && is_mime_char(*p)  ) {
			while ( node!=-1 && !is_char_equal(*p,type_tree[node].c) ){
				node = type_tree[node].next;
			}
			if (node!=-1 && type_tree[node].nr_sons)
				node++;
			p++;
		}
		if (p==end || mark==p)
			goto error;
		if (node!=-1)
			*mime_type = type_tree[node].final<<16;
		else
			*mime_type = TYPE_UNKNOWN<<16;
	}