| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SPDY_SPDY_FRAMER_H_ | 5 #ifndef NET_SPDY_SPDY_FRAMER_H_ | 
| 6 #define NET_SPDY_SPDY_FRAMER_H_ | 6 #define NET_SPDY_SPDY_FRAMER_H_ | 
| 7 | 7 | 
| 8 #include <stddef.h> | 8 #include <stddef.h> | 
| 9 #include <stdint.h> | 9 #include <stdint.h> | 
| 10 | 10 | 
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 312     SPDY_INVALID_DATA_FRAME_FLAGS,     // Data frame has invalid flags. | 312     SPDY_INVALID_DATA_FRAME_FLAGS,     // Data frame has invalid flags. | 
| 313     SPDY_INVALID_CONTROL_FRAME_FLAGS,  // Control frame has invalid flags. | 313     SPDY_INVALID_CONTROL_FRAME_FLAGS,  // Control frame has invalid flags. | 
| 314     SPDY_UNEXPECTED_FRAME,             // Frame received out of order. | 314     SPDY_UNEXPECTED_FRAME,             // Frame received out of order. | 
| 315     SPDY_INTERNAL_FRAMER_ERROR,        // SpdyFramer was used incorrectly. | 315     SPDY_INTERNAL_FRAMER_ERROR,        // SpdyFramer was used incorrectly. | 
| 316     SPDY_INVALID_CONTROL_FRAME_SIZE,   // Control frame not sized to spec | 316     SPDY_INVALID_CONTROL_FRAME_SIZE,   // Control frame not sized to spec | 
| 317     SPDY_OVERSIZED_PAYLOAD,            // Payload size was too large | 317     SPDY_OVERSIZED_PAYLOAD,            // Payload size was too large | 
| 318 | 318 | 
| 319     LAST_ERROR,  // Must be the last entry in the enum. | 319     LAST_ERROR,  // Must be the last entry in the enum. | 
| 320   }; | 320   }; | 
| 321 | 321 | 
|  | 322   enum CompressionOption { | 
|  | 323     ENABLE_COMPRESSION, | 
|  | 324     DISABLE_COMPRESSION, | 
|  | 325   }; | 
|  | 326 | 
| 322   // Typedef for a function used to create SpdyFramerDecoderAdapter's. | 327   // Typedef for a function used to create SpdyFramerDecoderAdapter's. | 
| 323   // Defined in support of evaluating an alternate HTTP/2 decoder. | 328   // Defined in support of evaluating an alternate HTTP/2 decoder. | 
| 324   typedef std::unique_ptr<SpdyFramerDecoderAdapter> (*DecoderAdapterFactoryFn)( | 329   typedef std::unique_ptr<SpdyFramerDecoderAdapter> (*DecoderAdapterFactoryFn)( | 
| 325       SpdyFramer* outer); | 330       SpdyFramer* outer); | 
| 326 | 331 | 
| 327   // Constant for invalid (or unknown) stream IDs. | 332   // Constant for invalid (or unknown) stream IDs. | 
| 328   static const SpdyStreamId kInvalidStream; | 333   static const SpdyStreamId kInvalidStream; | 
| 329 | 334 | 
| 330   // The maximum size of header data decompressed/delivered at once to the | 335   // The maximum size of header data decompressed/delivered at once to the | 
| 331   // header block parser. (Exposed here for unit test purposes.) | 336   // header block parser. (Exposed here for unit test purposes.) | 
| 332   static const size_t kHeaderDataChunkMaxSize; | 337   static const size_t kHeaderDataChunkMaxSize; | 
| 333 | 338 | 
| 334   void SerializeHeaderBlockWithoutCompression( | 339   void SerializeHeaderBlockWithoutCompression( | 
| 335       SpdyFrameBuilder* builder, | 340       SpdyFrameBuilder* builder, | 
| 336       const SpdyHeaderBlock& header_block) const; | 341       const SpdyHeaderBlock& header_block) const; | 
| 337 | 342 | 
| 338   // Retrieve serialized length of SpdyHeaderBlock. | 343   // Retrieve serialized length of SpdyHeaderBlock. | 
| 339   static size_t GetSerializedLength(const SpdyHeaderBlock* headers); | 344   static size_t GetSerializedLength(const SpdyHeaderBlock* headers); | 
| 340 | 345 | 
| 341   SpdyFramer(); | 346   explicit SpdyFramer(CompressionOption option); | 
| 342 | 347 | 
| 343   // Used recursively from the above constructor in order to support | 348   // Used recursively from the above constructor in order to support | 
| 344   // instantiating a SpdyFramerDecoderAdapter selected via flags or some other | 349   // instantiating a SpdyFramerDecoderAdapter selected via flags or some other | 
| 345   // means. | 350   // means. | 
| 346   explicit SpdyFramer(DecoderAdapterFactoryFn adapter_factory); | 351   SpdyFramer(DecoderAdapterFactoryFn adapter_factory, CompressionOption option); | 
| 347 | 352 | 
| 348   virtual ~SpdyFramer(); | 353   virtual ~SpdyFramer(); | 
| 349 | 354 | 
| 350   // Set callbacks to be called from the framer.  A visitor must be set, or | 355   // Set callbacks to be called from the framer.  A visitor must be set, or | 
| 351   // else the framer will likely crash.  It is acceptable for the visitor | 356   // else the framer will likely crash.  It is acceptable for the visitor | 
| 352   // to do nothing.  If this is called multiple times, only the last visitor | 357   // to do nothing.  If this is called multiple times, only the last visitor | 
| 353   // will be used. | 358   // will be used. | 
| 354   void set_visitor(SpdyFramerVisitorInterface* visitor); | 359   void set_visitor(SpdyFramerVisitorInterface* visitor); | 
| 355 | 360 | 
| 356   // Set debug callbacks to be called from the framer. The debug visitor is | 361   // Set debug callbacks to be called from the framer. The debug visitor is | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 468   // availability of an alternative service to the client. | 473   // availability of an alternative service to the client. | 
| 469   SpdySerializedFrame SerializeAltSvc(const SpdyAltSvcIR& altsvc); | 474   SpdySerializedFrame SerializeAltSvc(const SpdyAltSvcIR& altsvc); | 
| 470 | 475 | 
| 471   // Serializes a PRIORITY frame. The PRIORITY frame advises a change in | 476   // Serializes a PRIORITY frame. The PRIORITY frame advises a change in | 
| 472   // the relative priority of the given stream. | 477   // the relative priority of the given stream. | 
| 473   SpdySerializedFrame SerializePriority(const SpdyPriorityIR& priority) const; | 478   SpdySerializedFrame SerializePriority(const SpdyPriorityIR& priority) const; | 
| 474 | 479 | 
| 475   // Serialize a frame of unknown type. | 480   // Serialize a frame of unknown type. | 
| 476   SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame); | 481   SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame); | 
| 477 | 482 | 
| 478   // For ease of testing and experimentation we can tweak compression on/off. | 483   // Returns whether this SpdyFramer will compress header blocks using HPACK. | 
| 479   bool enable_compression() const { return enable_compression_; } | 484   bool compression_enabled() const { | 
| 480   void set_enable_compression(bool value) { | 485     return compression_option_ == ENABLE_COMPRESSION; | 
| 481     enable_compression_ = value; |  | 
| 482   } | 486   } | 
| 483 | 487 | 
| 484   void SetHpackIndexingPolicy(HpackEncoder::IndexingPolicy policy) { | 488   void SetHpackIndexingPolicy(HpackEncoder::IndexingPolicy policy) { | 
| 485     GetHpackEncoder()->SetIndexingPolicy(std::move(policy)); | 489     GetHpackEncoder()->SetIndexingPolicy(std::move(policy)); | 
| 486   } | 490   } | 
| 487 | 491 | 
| 488   // Returns the (minimum) size of frames (sans variable-length portions). | 492   // Returns the (minimum) size of frames (sans variable-length portions). | 
| 489   size_t GetDataFrameMinimumSize() const; | 493   size_t GetDataFrameMinimumSize() const; | 
| 490   size_t GetFrameHeaderSize() const; | 494   size_t GetFrameHeaderSize() const; | 
| 491   size_t GetRstStreamMinimumSize() const; | 495   size_t GetRstStreamMinimumSize() const; | 
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 759   std::unique_ptr<SpdyHeadersBlockParser> header_parser_; | 763   std::unique_ptr<SpdyHeadersBlockParser> header_parser_; | 
| 760   SpdyHeadersHandlerInterface* header_handler_; | 764   SpdyHeadersHandlerInterface* header_handler_; | 
| 761 | 765 | 
| 762   // Optional decoder to use instead of this instance. | 766   // Optional decoder to use instead of this instance. | 
| 763   std::unique_ptr<SpdyFramerDecoderAdapter> decoder_adapter_; | 767   std::unique_ptr<SpdyFramerDecoderAdapter> decoder_adapter_; | 
| 764 | 768 | 
| 765   // The flags field of the frame currently being read. | 769   // The flags field of the frame currently being read. | 
| 766   uint8_t current_frame_flags_; | 770   uint8_t current_frame_flags_; | 
| 767 | 771 | 
| 768   // Determines whether HPACK compression is used. | 772   // Determines whether HPACK compression is used. | 
| 769   bool enable_compression_; | 773   const CompressionOption compression_option_; | 
| 770 | 774 | 
| 771   // On the first read, we check to see if the data starts with HTTP. | 775   // On the first read, we check to see if the data starts with HTTP. | 
| 772   // If it does, we likely have an HTTP response.   This isn't guaranteed | 776   // If it does, we likely have an HTTP response.   This isn't guaranteed | 
| 773   // though: we could have gotten a settings frame and then corrupt data that | 777   // though: we could have gotten a settings frame and then corrupt data that | 
| 774   // just looks like HTTP, but deterministic checking requires a lot more state. | 778   // just looks like HTTP, but deterministic checking requires a lot more state. | 
| 775   bool probable_http_response_; | 779   bool probable_http_response_; | 
| 776 | 780 | 
| 777   // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM | 781   // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM | 
| 778   // flag is still carried in the HEADERS frame. If it's set, flip this so that | 782   // flag is still carried in the HEADERS frame. If it's set, flip this so that | 
| 779   // we know to terminate the stream when the entire header block has been | 783   // we know to terminate the stream when the entire header block has been | 
| 780   // processed. | 784   // processed. | 
| 781   bool end_stream_when_done_; | 785   bool end_stream_when_done_; | 
| 782 | 786 | 
| 783   // If true, then ProcessInput returns after processing a full frame, | 787   // If true, then ProcessInput returns after processing a full frame, | 
| 784   // rather than reading all available input. | 788   // rather than reading all available input. | 
| 785   bool process_single_input_frame_ = false; | 789   bool process_single_input_frame_ = false; | 
| 786 }; | 790 }; | 
| 787 | 791 | 
| 788 }  // namespace net | 792 }  // namespace net | 
| 789 | 793 | 
| 790 #endif  // NET_SPDY_SPDY_FRAMER_H_ | 794 #endif  // NET_SPDY_SPDY_FRAMER_H_ | 
| OLD | NEW | 
|---|