Home | History | Annotate | Download | only in balsa
      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.
      4 
      5 #ifndef NET_TOOLS_BALSA_BALSA_ENUMS_H_
      6 #define NET_TOOLS_BALSA_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 #if defined(_WIN32)
     28     // On Windows, <WinError.h> defines the NO_ERROR macro as 0L, which
     29     // breaks the compilation of the "NO_ERROR = 0" line.
     30 #undef NO_ERROR
     31 #endif
     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.
     40     //
     41     //        firstline_a     firstline_b    firstline_c
     42     //    REQ: method         request_uri    version
     43     //   RESP: version        statuscode     reason
     44     //
     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.
     49     //
     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.
     56     //                                                  | Triggered
     57     //                                                  | while processing
     58     //                                                  | this NONWS
     59     //                                                  | sequence...
     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
     68 
     69     FAILED_CONVERTING_STATUS_CODE_TO_INT,
     70     REQUEST_URI_TOO_LONG,  // Request URI greater than kMaxUrlLen.
     71 
     72     HEADERS_TOO_LONG,
     73     UNPARSABLE_CONTENT_LENGTH,
     74     // Warning: there may be a body but there was no content-length/chunked
     75     // encoding
     76     MAYBE_BODY_BUT_NO_CONTENT_LENGTH,
     77 
     78     // This is used if a body is required for a request.
     79     REQUIRED_BODY_BUT_NO_CONTENT_LENGTH,
     80 
     81     HEADER_MISSING_COLON,
     82 
     83     // Chunking errors
     84     INVALID_CHUNK_LENGTH,
     85     CHUNK_LENGTH_OVERFLOW,
     86 
     87     // Other errors.
     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,
     94 
     95     // A detected internal inconsistency was found.
     96     INTERNAL_LOGIC_ERROR,
     97 
     98     NUM_ERROR_CODES
     99   };
    100   static const char* ParseStateToString(ParseState error_code);
    101   static const char* ErrorCodeToString(ErrorCode error_code);
    102 };
    103 
    104 struct BalsaHeadersEnums {
    105   enum ContentLengthStatus {
    106     INVALID_CONTENT_LENGTH,
    107     CONTENT_LENGTH_OVERFLOW,
    108     NO_CONTENT_LENGTH,
    109     VALID_CONTENT_LENGTH,
    110   };
    111 };
    112 
    113 }  // namespace net
    114 
    115 #endif  // NET_TOOLS_BALSA_BALSA_ENUMS_H_
    116 
    117