Home | History | Annotate | Download | only in flip_server
      1 // Copyright (c) 2009 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.
      4 
      5 #ifndef NET_TOOLS_FLIP_SERVER_BALSA_ENUMS_H_
      6 #define NET_TOOLS_FLIP_SERVER_BALSA_ENUMS_H_
      7 
      8 namespace net {
      9 
     10 struct BalsaFrameEnums {
     11   enum ParseState {
     12     PARSE_ERROR,
     13     READING_HEADER_AND_FIRSTLINE,
     14     READING_CHUNK_LENGTH,
     15     READING_CHUNK_EXTENSION,
     16     READING_CHUNK_DATA,
     17     READING_CHUNK_TERM,
     18     READING_LAST_CHUNK_TERM,
     19     READING_TRAILER,
     20     READING_UNTIL_CLOSE,
     21     READING_CONTENT,
     22     MESSAGE_FULLY_READ,
     23     NUM_STATES,
     24   };
     25 
     26   enum ErrorCode {
     27     NO_ERROR = 0,  // A sentinel value for convenience, none of the callbacks
     28     //                should ever see this error code.
     29     // Header parsing errors
     30     // Note that adding one to many of the REQUEST errors yields the
     31     // appropriate RESPONSE error.
     32     // Particularly, when parsing the first line of a request or response,
     33     // there are three sequences of non-whitespace regardless of whether or
     34     // not it is a request or response. These are listed below, in order.
     35     //
     36     //        firstline_a     firstline_b    firstline_c
     37     //    REQ: method         request_uri    version
     38     //   RESP: version        statuscode     reason
     39     //
     40     // As you can see, the first token is the 'method' field for a request,
     41     // and 'version' field for a response. We call the first non whitespace
     42     // token firstline_a, the second firstline_b, and the third token
     43     // followed by [^\r\n]*) firstline_c.
     44     //
     45     // This organization is important, as it lets us determine the error code
     46     // to use without a branch based on is_response. Instead, we simply add
     47     // is_response to the response error code-- If is_response is true, then
     48     // we'll get the response error code, thanks to the fact that the error
     49     // code numbers are organized to ensure that response error codes always
     50     // precede request error codes.
     51     //                                                  | Triggered
     52     //                                                  | while processing
     53     //                                                  | this NONWS
     54     //                                                  | sequence...
     55     NO_STATUS_LINE_IN_RESPONSE,                      // |
     56     NO_REQUEST_LINE_IN_REQUEST,                      // |
     57     FAILED_TO_FIND_WS_AFTER_RESPONSE_VERSION,        // |  firstline_a
     58     FAILED_TO_FIND_WS_AFTER_REQUEST_METHOD,          // |  firstline_a
     59     FAILED_TO_FIND_WS_AFTER_RESPONSE_STATUSCODE,     // |  firstline_b
     60     FAILED_TO_FIND_WS_AFTER_REQUEST_REQUEST_URI,     // |  firstline_b
     61     FAILED_TO_FIND_NL_AFTER_RESPONSE_REASON_PHRASE,  // |  firstline_c
     62     FAILED_TO_FIND_NL_AFTER_REQUEST_HTTP_VERSION,    // |  firstline_c
     63 
     64     FAILED_CONVERTING_STATUS_CODE_TO_INT,
     65     REQUEST_URI_TOO_LONG,  // Request URI greater than kMaxUrlLen.
     66 
     67     HEADERS_TOO_LONG,
     68     UNPARSABLE_CONTENT_LENGTH,
     69     // Warning: there may be a body but there was no content-length/chunked
     70     // encoding
     71     MAYBE_BODY_BUT_NO_CONTENT_LENGTH,
     72 
     73     // This is used if a body is required for a request.
     74     REQUIRED_BODY_BUT_NO_CONTENT_LENGTH,
     75 
     76     HEADER_MISSING_COLON,
     77 
     78     // Chunking errors
     79     INVALID_CHUNK_LENGTH,
     80     CHUNK_LENGTH_OVERFLOW,
     81 
     82     // Other errors.
     83     CALLED_BYTES_SPLICED_WHEN_UNSAFE_TO_DO_SO,
     84     CALLED_BYTES_SPLICED_AND_EXCEEDED_SAFE_SPLICE_AMOUNT,
     85     MULTIPLE_CONTENT_LENGTH_KEYS,
     86     MULTIPLE_TRANSFER_ENCODING_KEYS,
     87     UNKNOWN_TRANSFER_ENCODING,
     88     INVALID_HEADER_FORMAT,
     89 
     90     // A detected internal inconsistency was found.
     91     INTERNAL_LOGIC_ERROR,
     92 
     93     NUM_ERROR_CODES
     94   };
     95   static const char* ParseStateToString(ParseState error_code);
     96   static const char* ErrorCodeToString(ErrorCode error_code);
     97 };
     98 
     99 struct BalsaHeadersEnums {
    100   enum ContentLengthStatus {
    101     INVALID_CONTENT_LENGTH,
    102     CONTENT_LENGTH_OVERFLOW,
    103     NO_CONTENT_LENGTH,
    104     VALID_CONTENT_LENGTH,
    105   };
    106 };
    107 
    108 }  // namespace net
    109 
    110 #endif  // NET_TOOLS_FLIP_SERVER_BALSA_ENUMS_H_
    111 
    112