diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-29 15:27:44 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-29 15:27:44 +0000 |
commit | 6c7e65208cedc0ff790738a67794474c679ee578 (patch) | |
tree | 71ac7941a02e76e13705e75e712679286931326a /net/tools/balsa/balsa_enums.h | |
parent | 29239893bfafc535339be2adf7845a5010213a51 (diff) | |
download | chromium_src-6c7e65208cedc0ff790738a67794474c679ee578.zip chromium_src-6c7e65208cedc0ff790738a67794474c679ee578.tar.gz chromium_src-6c7e65208cedc0ff790738a67794474c679ee578.tar.bz2 |
Break out balsa and epoll_server from net/tools/flip_server.
balsa is an HTTP headers/framing abstraction used by code in net/tools/flip_server and net/tools/quic.
epoll_server is a event-driven server abstraction based on (as the name suggested) epoll. It is also used by code in net/tools/flip_server and net/tools/quic.
Since these are both shared across different layers, it makes sense to split them into different directories.
Review URL: https://codereview.chromium.org/25085002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools/balsa/balsa_enums.h')
-rw-r--r-- | net/tools/balsa/balsa_enums.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/net/tools/balsa/balsa_enums.h b/net/tools/balsa/balsa_enums.h new file mode 100644 index 0000000..a59dcda --- /dev/null +++ b/net/tools/balsa/balsa_enums.h @@ -0,0 +1,111 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_TOOLS_BALSA_BALSA_ENUMS_H_ +#define NET_TOOLS_BALSA_BALSA_ENUMS_H_ + +namespace net { + +struct BalsaFrameEnums { + enum ParseState { + PARSE_ERROR, + READING_HEADER_AND_FIRSTLINE, + READING_CHUNK_LENGTH, + READING_CHUNK_EXTENSION, + READING_CHUNK_DATA, + READING_CHUNK_TERM, + READING_LAST_CHUNK_TERM, + READING_TRAILER, + READING_UNTIL_CLOSE, + READING_CONTENT, + MESSAGE_FULLY_READ, + NUM_STATES, + }; + + enum ErrorCode { + NO_ERROR = 0, // A sentinel value for convenience, none of the callbacks + // should ever see this error code. + // Header parsing errors + // Note that adding one to many of the REQUEST errors yields the + // appropriate RESPONSE error. + // Particularly, when parsing the first line of a request or response, + // there are three sequences of non-whitespace regardless of whether or + // not it is a request or response. These are listed below, in order. + // + // firstline_a firstline_b firstline_c + // REQ: method request_uri version + // RESP: version statuscode reason + // + // As you can see, the first token is the 'method' field for a request, + // and 'version' field for a response. We call the first non whitespace + // token firstline_a, the second firstline_b, and the third token + // followed by [^\r\n]*) firstline_c. + // + // This organization is important, as it lets us determine the error code + // to use without a branch based on is_response. Instead, we simply add + // is_response to the response error code-- If is_response is true, then + // we'll get the response error code, thanks to the fact that the error + // code numbers are organized to ensure that response error codes always + // precede request error codes. + // | Triggered + // | while processing + // | this NONWS + // | sequence... + NO_STATUS_LINE_IN_RESPONSE, // | + NO_REQUEST_LINE_IN_REQUEST, // | + FAILED_TO_FIND_WS_AFTER_RESPONSE_VERSION, // | firstline_a + FAILED_TO_FIND_WS_AFTER_REQUEST_METHOD, // | firstline_a + FAILED_TO_FIND_WS_AFTER_RESPONSE_STATUSCODE, // | firstline_b + FAILED_TO_FIND_WS_AFTER_REQUEST_REQUEST_URI, // | firstline_b + FAILED_TO_FIND_NL_AFTER_RESPONSE_REASON_PHRASE, // | firstline_c + FAILED_TO_FIND_NL_AFTER_REQUEST_HTTP_VERSION, // | firstline_c + + FAILED_CONVERTING_STATUS_CODE_TO_INT, + REQUEST_URI_TOO_LONG, // Request URI greater than kMaxUrlLen. + + HEADERS_TOO_LONG, + UNPARSABLE_CONTENT_LENGTH, + // Warning: there may be a body but there was no content-length/chunked + // encoding + MAYBE_BODY_BUT_NO_CONTENT_LENGTH, + + // This is used if a body is required for a request. + REQUIRED_BODY_BUT_NO_CONTENT_LENGTH, + + HEADER_MISSING_COLON, + + // Chunking errors + INVALID_CHUNK_LENGTH, + CHUNK_LENGTH_OVERFLOW, + + // Other errors. + CALLED_BYTES_SPLICED_WHEN_UNSAFE_TO_DO_SO, + CALLED_BYTES_SPLICED_AND_EXCEEDED_SAFE_SPLICE_AMOUNT, + MULTIPLE_CONTENT_LENGTH_KEYS, + MULTIPLE_TRANSFER_ENCODING_KEYS, + UNKNOWN_TRANSFER_ENCODING, + INVALID_HEADER_FORMAT, + + // A detected internal inconsistency was found. + INTERNAL_LOGIC_ERROR, + + NUM_ERROR_CODES + }; + static const char* ParseStateToString(ParseState error_code); + static const char* ErrorCodeToString(ErrorCode error_code); +}; + +struct BalsaHeadersEnums { + enum ContentLengthStatus { + INVALID_CONTENT_LENGTH, + CONTENT_LENGTH_OVERFLOW, + NO_CONTENT_LENGTH, + VALID_CONTENT_LENGTH, + }; +}; + +} // namespace net + +#endif // NET_TOOLS_BALSA_BALSA_ENUMS_H_ + |