1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_TOOLS_BALSA_BALSA_ENUMS_H_
6 #define NET_TOOLS_BALSA_BALSA_ENUMS_H_
10 struct BalsaFrameEnums
{
13 READING_HEADER_AND_FIRSTLINE
,
15 READING_CHUNK_EXTENSION
,
18 READING_LAST_CHUNK_TERM
,
28 // On Windows, <WinError.h> defines the NO_ERROR macro as 0L, which
29 // breaks the compilation of the "NO_ERROR = 0" line.
32 NO_ERROR
= 0, // A sentinel value for convenience, none of the callbacks
33 // should ever see this error code.
34 // Header parsing errors
35 // Note that adding one to many of the REQUEST errors yields the
36 // appropriate RESPONSE error.
37 // Particularly, when parsing the first line of a request or response,
38 // there are three sequences of non-whitespace regardless of whether or
39 // not it is a request or response. These are listed below, in order.
41 // firstline_a firstline_b firstline_c
42 // REQ: method request_uri version
43 // RESP: version statuscode reason
45 // As you can see, the first token is the 'method' field for a request,
46 // and 'version' field for a response. We call the first non whitespace
47 // token firstline_a, the second firstline_b, and the third token
48 // followed by [^\r\n]*) firstline_c.
50 // This organization is important, as it lets us determine the error code
51 // to use without a branch based on is_response. Instead, we simply add
52 // is_response to the response error code-- If is_response is true, then
53 // we'll get the response error code, thanks to the fact that the error
54 // code numbers are organized to ensure that response error codes always
55 // precede request error codes.
60 NO_STATUS_LINE_IN_RESPONSE
, // |
61 NO_REQUEST_LINE_IN_REQUEST
, // |
62 FAILED_TO_FIND_WS_AFTER_RESPONSE_VERSION
, // | firstline_a
63 FAILED_TO_FIND_WS_AFTER_REQUEST_METHOD
, // | firstline_a
64 FAILED_TO_FIND_WS_AFTER_RESPONSE_STATUSCODE
, // | firstline_b
65 FAILED_TO_FIND_WS_AFTER_REQUEST_REQUEST_URI
, // | firstline_b
66 FAILED_TO_FIND_NL_AFTER_RESPONSE_REASON_PHRASE
, // | firstline_c
67 FAILED_TO_FIND_NL_AFTER_REQUEST_HTTP_VERSION
, // | firstline_c
69 FAILED_CONVERTING_STATUS_CODE_TO_INT
,
70 REQUEST_URI_TOO_LONG
, // Request URI greater than kMaxUrlLen.
73 UNPARSABLE_CONTENT_LENGTH
,
74 // Warning: there may be a body but there was no content-length/chunked
76 MAYBE_BODY_BUT_NO_CONTENT_LENGTH
,
78 // This is used if a body is required for a request.
79 REQUIRED_BODY_BUT_NO_CONTENT_LENGTH
,
85 CHUNK_LENGTH_OVERFLOW
,
88 CALLED_BYTES_SPLICED_WHEN_UNSAFE_TO_DO_SO
,
89 CALLED_BYTES_SPLICED_AND_EXCEEDED_SAFE_SPLICE_AMOUNT
,
90 MULTIPLE_CONTENT_LENGTH_KEYS
,
91 MULTIPLE_TRANSFER_ENCODING_KEYS
,
92 UNKNOWN_TRANSFER_ENCODING
,
93 INVALID_HEADER_FORMAT
,
95 // A detected internal inconsistency was found.
100 static const char* ParseStateToString(ParseState error_code
);
101 static const char* ErrorCodeToString(ErrorCode error_code
);
104 struct BalsaHeadersEnums
{
105 enum ContentLengthStatus
{
106 INVALID_CONTENT_LENGTH
,
107 CONTENT_LENGTH_OVERFLOW
,
109 VALID_CONTENT_LENGTH
,
115 #endif // NET_TOOLS_BALSA_BALSA_ENUMS_H_