http-response-parser.c revision b72c3363092b73cab1da2de4a9d75592e7d8fd6b
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "istream.h"
#include "http-parser.h"
#include "http-message-parser.h"
#include "http-response-parser.h"
#include <ctype.h>
enum http_response_parser_state {
};
struct http_response_parser {
struct http_message_parser parser;
struct http_response response;
};
{
struct http_response_parser *parser;
return parser;
}
{
}
static void
{
}
{
/* status-code = 3DIGIT
*/
if (size < 3)
return 0;
return -1;
(p[0] - '0')*100 + (p[1] - '0')*10 + (p[2] - '0');
return 1;
}
{
/* reason-phrase = *( HTAB / SP / VCHAR / obs-text )
*/
p++;
return 0;
return 1;
}
static inline const char *_chr_sanitize(unsigned char c)
{
if (c >= 0x20 && c < 0x7F)
return t_strdup_printf("'%c'", c);
return t_strdup_printf("0x%02x", c);
}
const char **error_r)
{
int ret;
/* status-line = HTTP-version SP status-code SP reason-phrase CRLF
status-code = 3DIGIT
reason-phrase = *( HTAB / SP / VCHAR / obs-text )
*/
for (;;) {
/* fall through */
if (ret < 0)
*error_r = "Invalid HTTP version in response";
return ret;
}
return 0;
/* fall through */
("Expected ' ' after response version, but found %s",
return -1;
}
return 0;
/* fall through */
if (ret < 0)
*error_r = "Invalid HTTP status code in response";
return ret;
}
return 0;
/* fall through */
("Expected ' ' after response status code, but found %s",
return -1;
}
return 0;
/* fall through */
return 0;
}
return 0;
/* fall through */
return 0;
/* fall through */
("Expected line end after response, but found %s",
return -1;
}
return 1;
default:
i_unreached();
}
}
i_unreached();
return -1;
}
const char **error_r)
{
const unsigned char *begin;
int ret;
old_bytes)) > 0) {
return -1;
if (ret > 0)
return 1;
}
if (ret < 0) {
return 0;
*error_r = "Stream error";
return -1;
}
return 0;
}
const char **error_r)
{
int ret;
/* make sure we finished streaming payload from previous response
before we continue. */
return ret;
/* HTTP-message = start-line
*( header-field CRLF )
CRLF
[ message-body ]
*/
return ret;
}
return ret;
Section 3.3.2:
A server MUST NOT send a Content-Length header field in any response
with a status code of 1xx (Informational) or 204 (No Content). [...]
*/
"Unexpected Content-Length header field for %u response "
return -1;
}
Section 3.3.3:
Any response to a HEAD request and any response with a 1xx
(Informational), 204 (No Content), or 304 (Not Modified) status
code is always terminated by the first empty line after the
header fields, regardless of the header fields present in the
message, and thus cannot contain a message body.
*/
no_payload = TRUE;
}
if (!no_payload) {
/* [ message-body ] */
return -1;
}
return 1;
}