Exemplo n.º 1
0
void http_response_parse_header(HttpResponse* http_response)
{
	int count;
	char* line;
	char* name;
	char* value;
	char* separator;

	http_response_parse_header_status_line(http_response, http_response->lines[0]);

	for (count = 1; count < http_response->count; count++)
	{
		line = http_response->lines[count];

		separator = strstr(line, ": ");

		if (separator == NULL)
			continue;

		separator[0] = '\0';
		separator[1] = '\0';

		name = line;
		value = separator + 2;

		http_response_parse_header_field(http_response, name, value);

		separator[0] = ':';
		separator[1] = ' ';
	}
}
Exemplo n.º 2
0
BOOL http_response_parse_header(HttpResponse* http_response)
{
	int count;
	char* line;
	char* name;
	char* value;
	char* colon_pos;
	char* end_of_header;
	char end_of_header_char;
	char c;

	if (!http_response_parse_header_status_line(http_response, http_response->lines[0]))
		return FALSE;

	for (count = 1; count < http_response->count; count++)
	{
		line = http_response->lines[count];

		/**
		 * name         end_of_header
		 * |            |
		 * v            v
		 * <header name>   :     <header value>
		 *                 ^     ^
		 *                 |     |
		 *         colon_pos     value
		 */
		colon_pos = strchr(line, ':');
		if ((colon_pos == NULL) || (colon_pos == line))
			return FALSE;

		/* retrieve the position just after header name */
		for(end_of_header = colon_pos; end_of_header != line; end_of_header--)
		{
			c = end_of_header[-1];
			if (c != ' ' && c != '\t' && c != ':')
				break;
		}
		if (end_of_header == line)
			return FALSE;
		end_of_header_char = *end_of_header;
		*end_of_header = '\0';

		name = line;

		/* eat space and tabs before header value */
		for (value = colon_pos + 1; *value; value++)
		{
			if ((*value != ' ') && (*value != '\t'))
				break;
		}

		http_response_parse_header_field(http_response, name, value);

		*end_of_header = end_of_header_char;
	}
	return TRUE;
}
Exemplo n.º 3
0
static BOOL http_response_parse_header(HttpResponse* response)
{
	BOOL rc = FALSE;
	char c;
	size_t count;
	char* line;
	char* name;
	char* value;
	char* colon_pos;
	char* end_of_header;
	char end_of_header_char;

	if (!response)
		goto fail;

	if (!response->lines)
		goto fail;

	if (!http_response_parse_header_status_line(response, response->lines[0]))
		goto fail;

	for (count = 1; count < response->count; count++)
	{
		line = response->lines[count];

		/**
		 * name         end_of_header
		 * |            |
		 * v            v
		 * <header name>   :     <header value>
		 *                 ^     ^
		 *                 |     |
		 *         colon_pos     value
		 */
		if (line)
			colon_pos = strchr(line, ':');
		else
			colon_pos = NULL;

		if ((colon_pos == NULL) || (colon_pos == line))
			return FALSE;

		/* retrieve the position just after header name */
		for (end_of_header = colon_pos; end_of_header != line; end_of_header--)
		{
			c = end_of_header[-1];

			if (c != ' ' && c != '\t' && c != ':')
				break;
		}

		if (end_of_header == line)
			goto fail;

		end_of_header_char = *end_of_header;
		*end_of_header = '\0';
		name = line;

		/* eat space and tabs before header value */
		for (value = colon_pos + 1; *value; value++)
		{
			if ((*value != ' ') && (*value != '\t'))
				break;
		}

		if (!http_response_parse_header_field(response, name, value))
			goto fail;

		*end_of_header = end_of_header_char;
	}

	rc = TRUE;
fail:

	if (!rc)
		WLog_ERR(TAG, "%s: parsing failed", __FUNCTION__);

	return rc;
}