| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef NET_TOOLS_BALSA_BALSA_FRAME_H_ | 5 #ifndef NET_TOOLS_BALSA_BALSA_FRAME_H_ | 
| 6 #define NET_TOOLS_BALSA_BALSA_FRAME_H_ | 6 #define NET_TOOLS_BALSA_BALSA_FRAME_H_ | 
| 7 | 7 | 
|  | 8 #include <stddef.h> | 
|  | 9 #include <stdint.h> | 
|  | 10 | 
| 8 #include <utility> | 11 #include <utility> | 
| 9 #include <vector> | 12 #include <vector> | 
| 10 | 13 | 
| 11 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" | 
| 12 #include "net/tools/balsa/balsa_enums.h" | 15 #include "net/tools/balsa/balsa_enums.h" | 
| 13 #include "net/tools/balsa/balsa_headers.h" | 16 #include "net/tools/balsa/balsa_headers.h" | 
| 14 #include "net/tools/balsa/balsa_visitor_interface.h" | 17 #include "net/tools/balsa/balsa_visitor_interface.h" | 
| 15 #include "net/tools/balsa/buffer_interface.h" | 18 #include "net/tools/balsa/buffer_interface.h" | 
| 16 #include "net/tools/balsa/http_message_constants.h" | 19 #include "net/tools/balsa/http_message_constants.h" | 
| 17 #include "net/tools/balsa/simple_buffer.h" | 20 #include "net/tools/balsa/simple_buffer.h" | 
| 18 | 21 | 
| 19 // For additional debug output, uncomment the following: | 22 // For additional debug output, uncomment the following: | 
| 20 // #define DEBUGFRAMER 1 | 23 // #define DEBUGFRAMER 1 | 
| 21 | 24 | 
| 22 namespace net { | 25 namespace net { | 
| 23 | 26 | 
| 24 // BalsaFrame is a 'Model' of a framer (haha). | 27 // BalsaFrame is a 'Model' of a framer (haha). | 
| 25 // It exists as a proof of concept headers framer. | 28 // It exists as a proof of concept headers framer. | 
| 26 class BalsaFrame { | 29 class BalsaFrame { | 
| 27  public: | 30  public: | 
| 28   typedef std::vector<std::pair<size_t, size_t> > Lines; | 31   typedef std::vector<std::pair<size_t, size_t> > Lines; | 
| 29 | 32 | 
| 30   typedef BalsaHeaders::HeaderLineDescription HeaderLineDescription; | 33   typedef BalsaHeaders::HeaderLineDescription HeaderLineDescription; | 
| 31   typedef BalsaHeaders::HeaderLines HeaderLines; | 34   typedef BalsaHeaders::HeaderLines HeaderLines; | 
| 32   typedef BalsaHeaders::HeaderTokenList HeaderTokenList; | 35   typedef BalsaHeaders::HeaderTokenList HeaderTokenList; | 
| 33 | 36 | 
| 34   // TODO(fenix): get rid of the 'kValidTerm*' stuff by using the 'since last | 37   // TODO(fenix): get rid of the 'kValidTerm*' stuff by using the 'since last | 
| 35   // index' strategy.  Note that this implies getting rid of the HeaderFramed() | 38   // index' strategy.  Note that this implies getting rid of the HeaderFramed() | 
| 36 | 39 | 
| 37   static const uint32 kValidTerm1  = '\n' << 16 | | 40   static const uint32_t kValidTerm1 = '\n' << 16 | '\r' << 8 | '\n'; | 
| 38                                      '\r' <<  8 | | 41   static const uint32_t kValidTerm1Mask = 0xFF << 16 | 0xFF << 8 | 0xFF; | 
| 39                                      '\n'; | 42   static const uint32_t kValidTerm2 = '\n' << 8 | '\n'; | 
| 40   static const uint32 kValidTerm1Mask = 0xFF << 16 | | 43   static const uint32_t kValidTerm2Mask = 0xFF << 8 | 0xFF; | 
| 41                                         0xFF <<  8 | |  | 
| 42                                         0xFF; |  | 
| 43   static const uint32 kValidTerm2      = '\n' << 8 | |  | 
| 44                                          '\n'; |  | 
| 45   static const uint32 kValidTerm2Mask = 0xFF << 8 | |  | 
| 46                                         0xFF; |  | 
| 47   BalsaFrame(); | 44   BalsaFrame(); | 
| 48   ~BalsaFrame(); | 45   ~BalsaFrame(); | 
| 49 | 46 | 
| 50   // Reset reinitializes all the member variables of the framer and clears the | 47   // Reset reinitializes all the member variables of the framer and clears the | 
| 51   // attached header object (but doesn't change the pointer value headers_). | 48   // attached header object (but doesn't change the pointer value headers_). | 
| 52   void Reset(); | 49   void Reset(); | 
| 53 | 50 | 
| 54   const BalsaHeaders* const_balsa_headers() const { return headers_; } | 51   const BalsaHeaders* const_balsa_headers() const { return headers_; } | 
| 55   BalsaHeaders* balsa_headers() { return headers_; } | 52   BalsaHeaders* balsa_headers() { return headers_; } | 
| 56   // The method set_balsa_headers clears the headers provided and attaches them | 53   // The method set_balsa_headers clears the headers provided and attaches them | 
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 238   bool is_request_;                // This is not reset in Reset() | 235   bool is_request_;                // This is not reset in Reset() | 
| 239   bool request_was_head_;          // This is not reset in Reset() | 236   bool request_was_head_;          // This is not reset in Reset() | 
| 240   size_t max_header_length_;       // This is not reset in Reset() | 237   size_t max_header_length_;       // This is not reset in Reset() | 
| 241   size_t max_request_uri_length_;  // This is not reset in Reset() | 238   size_t max_request_uri_length_;  // This is not reset in Reset() | 
| 242   BalsaVisitorInterface* visitor_; | 239   BalsaVisitorInterface* visitor_; | 
| 243   size_t chunk_length_remaining_; | 240   size_t chunk_length_remaining_; | 
| 244   size_t content_length_remaining_; | 241   size_t content_length_remaining_; | 
| 245   const char* last_slash_n_loc_; | 242   const char* last_slash_n_loc_; | 
| 246   const char* last_recorded_slash_n_loc_; | 243   const char* last_recorded_slash_n_loc_; | 
| 247   size_t last_slash_n_idx_; | 244   size_t last_slash_n_idx_; | 
| 248   uint32 term_chars_; | 245   uint32_t term_chars_; | 
| 249   BalsaFrameEnums::ParseState parse_state_; | 246   BalsaFrameEnums::ParseState parse_state_; | 
| 250   BalsaFrameEnums::ErrorCode last_error_; | 247   BalsaFrameEnums::ErrorCode last_error_; | 
| 251 | 248 | 
| 252   Lines lines_; | 249   Lines lines_; | 
| 253 | 250 | 
| 254   BalsaHeaders* headers_;  // This is not reset to NULL in Reset(). | 251   BalsaHeaders* headers_;  // This is not reset to NULL in Reset(). | 
| 255   DoNothingBalsaVisitor do_nothing_visitor_; | 252   DoNothingBalsaVisitor do_nothing_visitor_; | 
| 256 }; | 253 }; | 
| 257 | 254 | 
| 258 }  // namespace net | 255 }  // namespace net | 
| 259 | 256 | 
| 260 #endif  // NET_TOOLS_BALSA_BALSA_FRAME_H_ | 257 #endif  // NET_TOOLS_BALSA_BALSA_FRAME_H_ | 
| 261 | 258 | 
| OLD | NEW | 
|---|