| 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 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 | 5 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 |
| 6 // The SPDY 3 spec can be found at: | 6 // The SPDY 3 spec can be found at: |
| 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 | 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 |
| 8 | 8 |
| 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ | 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ |
| 10 #define NET_SPDY_SPDY_PROTOCOL_H_ | 10 #define NET_SPDY_SPDY_PROTOCOL_H_ |
| 11 | 11 |
| 12 #include <stddef.h> | 12 #include <stddef.h> |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 | 14 |
| 15 #include <iosfwd> | 15 #include <iosfwd> |
| 16 #include <limits> | 16 #include <limits> |
| 17 #include <map> | 17 #include <map> |
| 18 #include <memory> | 18 #include <memory> |
| 19 #include <string> | |
| 20 #include <utility> | 19 #include <utility> |
| 21 | 20 |
| 22 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
| 23 #include "base/logging.h" | 22 #include "base/logging.h" |
| 24 #include "base/macros.h" | 23 #include "base/macros.h" |
| 25 #include "base/sys_byteorder.h" | 24 #include "base/sys_byteorder.h" |
| 26 #include "net/base/net_export.h" | 25 #include "net/base/net_export.h" |
| 26 #include "net/spdy/platform/api/spdy_string.h" |
| 27 #include "net/spdy/platform/api/spdy_string_piece.h" | 27 #include "net/spdy/platform/api/spdy_string_piece.h" |
| 28 #include "net/spdy/spdy_alt_svc_wire_format.h" | 28 #include "net/spdy/spdy_alt_svc_wire_format.h" |
| 29 #include "net/spdy/spdy_bitmasks.h" | 29 #include "net/spdy/spdy_bitmasks.h" |
| 30 #include "net/spdy/spdy_bug_tracker.h" | 30 #include "net/spdy/spdy_bug_tracker.h" |
| 31 #include "net/spdy/spdy_header_block.h" | 31 #include "net/spdy/spdy_header_block.h" |
| 32 | 32 |
| 33 namespace net { | 33 namespace net { |
| 34 | 34 |
| 35 // A stream id is a 31 bit entity. | 35 // A stream id is a 31 bit entity. |
| 36 typedef uint32_t SpdyStreamId; | 36 typedef uint32_t SpdyStreamId; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 class NET_EXPORT_PRIVATE SpdyDataIR | 457 class NET_EXPORT_PRIVATE SpdyDataIR |
| 458 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) { | 458 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) { |
| 459 public: | 459 public: |
| 460 // Performs a deep copy on data. | 460 // Performs a deep copy on data. |
| 461 SpdyDataIR(SpdyStreamId stream_id, SpdyStringPiece data); | 461 SpdyDataIR(SpdyStreamId stream_id, SpdyStringPiece data); |
| 462 | 462 |
| 463 // Performs a deep copy on data. | 463 // Performs a deep copy on data. |
| 464 SpdyDataIR(SpdyStreamId stream_id, const char* data); | 464 SpdyDataIR(SpdyStreamId stream_id, const char* data); |
| 465 | 465 |
| 466 // Moves data into data_store_. Makes a copy if passed a non-movable string. | 466 // Moves data into data_store_. Makes a copy if passed a non-movable string. |
| 467 SpdyDataIR(SpdyStreamId stream_id, std::string data); | 467 SpdyDataIR(SpdyStreamId stream_id, SpdyString data); |
| 468 | 468 |
| 469 // Use in conjunction with SetDataShallow() for shallow-copy on data. | 469 // Use in conjunction with SetDataShallow() for shallow-copy on data. |
| 470 explicit SpdyDataIR(SpdyStreamId stream_id); | 470 explicit SpdyDataIR(SpdyStreamId stream_id); |
| 471 | 471 |
| 472 ~SpdyDataIR() override; | 472 ~SpdyDataIR() override; |
| 473 | 473 |
| 474 const char* data() const { return data_; } | 474 const char* data() const { return data_; } |
| 475 size_t data_len() const { return data_len_; } | 475 size_t data_len() const { return data_len_; } |
| 476 | 476 |
| 477 bool padded() const { return padded_; } | 477 bool padded() const { return padded_; } |
| 478 | 478 |
| 479 int padding_payload_len() const { return padding_payload_len_; } | 479 int padding_payload_len() const { return padding_payload_len_; } |
| 480 | 480 |
| 481 void set_padding_len(int padding_len) { | 481 void set_padding_len(int padding_len) { |
| 482 DCHECK_GT(padding_len, 0); | 482 DCHECK_GT(padding_len, 0); |
| 483 DCHECK_LE(padding_len, kPaddingSizePerFrame); | 483 DCHECK_LE(padding_len, kPaddingSizePerFrame); |
| 484 padded_ = true; | 484 padded_ = true; |
| 485 // The pad field takes one octet on the wire. | 485 // The pad field takes one octet on the wire. |
| 486 padding_payload_len_ = padding_len - 1; | 486 padding_payload_len_ = padding_len - 1; |
| 487 } | 487 } |
| 488 | 488 |
| 489 // Deep-copy of data (keep private copy). | 489 // Deep-copy of data (keep private copy). |
| 490 void SetDataDeep(SpdyStringPiece data) { | 490 void SetDataDeep(SpdyStringPiece data) { |
| 491 data_store_.reset(new std::string(data.data(), data.size())); | 491 data_store_.reset(new SpdyString(data.data(), data.size())); |
| 492 data_ = data_store_->data(); | 492 data_ = data_store_->data(); |
| 493 data_len_ = data.size(); | 493 data_len_ = data.size(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 // Shallow-copy of data (do not keep private copy). | 496 // Shallow-copy of data (do not keep private copy). |
| 497 void SetDataShallow(SpdyStringPiece data) { | 497 void SetDataShallow(SpdyStringPiece data) { |
| 498 data_store_.reset(); | 498 data_store_.reset(); |
| 499 data_ = data.data(); | 499 data_ = data.data(); |
| 500 data_len_ = data.size(); | 500 data_len_ = data.size(); |
| 501 } | 501 } |
| 502 | 502 |
| 503 // Use this method if we don't have a contiguous buffer and only | 503 // Use this method if we don't have a contiguous buffer and only |
| 504 // need a length. | 504 // need a length. |
| 505 void SetDataShallow(size_t len) { | 505 void SetDataShallow(size_t len) { |
| 506 data_store_.reset(); | 506 data_store_.reset(); |
| 507 data_ = nullptr; | 507 data_ = nullptr; |
| 508 data_len_ = len; | 508 data_len_ = len; |
| 509 } | 509 } |
| 510 | 510 |
| 511 void Visit(SpdyFrameVisitor* visitor) const override; | 511 void Visit(SpdyFrameVisitor* visitor) const override; |
| 512 | 512 |
| 513 SpdyFrameType frame_type() const override; | 513 SpdyFrameType frame_type() const override; |
| 514 | 514 |
| 515 private: | 515 private: |
| 516 // Used to store data that this SpdyDataIR should own. | 516 // Used to store data that this SpdyDataIR should own. |
| 517 std::unique_ptr<std::string> data_store_; | 517 std::unique_ptr<SpdyString> data_store_; |
| 518 const char* data_; | 518 const char* data_; |
| 519 size_t data_len_; | 519 size_t data_len_; |
| 520 | 520 |
| 521 bool padded_; | 521 bool padded_; |
| 522 // padding_payload_len_ = desired padding length - len(padding length field). | 522 // padding_payload_len_ = desired padding length - len(padding length field). |
| 523 int padding_payload_len_; | 523 int padding_payload_len_; |
| 524 | 524 |
| 525 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); | 525 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); |
| 526 }; | 526 }; |
| 527 | 527 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 // References description, doesn't copy it, so description must outlast | 599 // References description, doesn't copy it, so description must outlast |
| 600 // this SpdyGoAwayIR. | 600 // this SpdyGoAwayIR. |
| 601 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 601 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 602 SpdyErrorCode error_code, | 602 SpdyErrorCode error_code, |
| 603 const char* description); | 603 const char* description); |
| 604 | 604 |
| 605 // Moves description into description_store_, so caller doesn't need to | 605 // Moves description into description_store_, so caller doesn't need to |
| 606 // keep description live after constructing this SpdyGoAwayIR. | 606 // keep description live after constructing this SpdyGoAwayIR. |
| 607 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 607 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 608 SpdyErrorCode error_code, | 608 SpdyErrorCode error_code, |
| 609 std::string description); | 609 SpdyString description); |
| 610 | 610 |
| 611 ~SpdyGoAwayIR() override; | 611 ~SpdyGoAwayIR() override; |
| 612 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; } | 612 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; } |
| 613 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) { | 613 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) { |
| 614 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask); | 614 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask); |
| 615 last_good_stream_id_ = last_good_stream_id; | 615 last_good_stream_id_ = last_good_stream_id; |
| 616 } | 616 } |
| 617 SpdyErrorCode error_code() const { return error_code_; } | 617 SpdyErrorCode error_code() const { return error_code_; } |
| 618 void set_error_code(SpdyErrorCode error_code) { | 618 void set_error_code(SpdyErrorCode error_code) { |
| 619 // TODO(hkhalil): Check valid ranges of error_code? | 619 // TODO(hkhalil): Check valid ranges of error_code? |
| 620 error_code_ = error_code; | 620 error_code_ = error_code; |
| 621 } | 621 } |
| 622 | 622 |
| 623 const SpdyStringPiece& description() const { return description_; } | 623 const SpdyStringPiece& description() const { return description_; } |
| 624 | 624 |
| 625 void Visit(SpdyFrameVisitor* visitor) const override; | 625 void Visit(SpdyFrameVisitor* visitor) const override; |
| 626 | 626 |
| 627 SpdyFrameType frame_type() const override; | 627 SpdyFrameType frame_type() const override; |
| 628 | 628 |
| 629 private: | 629 private: |
| 630 SpdyStreamId last_good_stream_id_; | 630 SpdyStreamId last_good_stream_id_; |
| 631 SpdyErrorCode error_code_; | 631 SpdyErrorCode error_code_; |
| 632 const std::string description_store_; | 632 const SpdyString description_store_; |
| 633 const SpdyStringPiece description_; | 633 const SpdyStringPiece description_; |
| 634 | 634 |
| 635 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR); | 635 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR); |
| 636 }; | 636 }; |
| 637 | 637 |
| 638 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { | 638 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { |
| 639 public: | 639 public: |
| 640 explicit SpdyHeadersIR(SpdyStreamId stream_id) | 640 explicit SpdyHeadersIR(SpdyStreamId stream_id) |
| 641 : SpdyHeadersIR(stream_id, SpdyHeaderBlock()) {} | 641 : SpdyHeadersIR(stream_id, SpdyHeaderBlock()) {} |
| 642 SpdyHeadersIR(SpdyStreamId stream_id, SpdyHeaderBlock header_block) | 642 SpdyHeadersIR(SpdyStreamId stream_id, SpdyHeaderBlock header_block) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 public: | 741 public: |
| 742 explicit SpdyContinuationIR(SpdyStreamId stream_id); | 742 explicit SpdyContinuationIR(SpdyStreamId stream_id); |
| 743 ~SpdyContinuationIR() override; | 743 ~SpdyContinuationIR() override; |
| 744 | 744 |
| 745 void Visit(SpdyFrameVisitor* visitor) const override; | 745 void Visit(SpdyFrameVisitor* visitor) const override; |
| 746 | 746 |
| 747 SpdyFrameType frame_type() const override; | 747 SpdyFrameType frame_type() const override; |
| 748 | 748 |
| 749 bool end_headers() const { return end_headers_; } | 749 bool end_headers() const { return end_headers_; } |
| 750 void set_end_headers(bool end_headers) {end_headers_ = end_headers;} | 750 void set_end_headers(bool end_headers) {end_headers_ = end_headers;} |
| 751 const std::string& encoding() const { return *encoding_; } | 751 const SpdyString& encoding() const { return *encoding_; } |
| 752 void take_encoding(std::unique_ptr<std::string> encoding) { | 752 void take_encoding(std::unique_ptr<SpdyString> encoding) { |
| 753 encoding_ = std::move(encoding); | 753 encoding_ = std::move(encoding); |
| 754 } | 754 } |
| 755 | 755 |
| 756 private: | 756 private: |
| 757 std::unique_ptr<std::string> encoding_; | 757 std::unique_ptr<SpdyString> encoding_; |
| 758 bool end_headers_; | 758 bool end_headers_; |
| 759 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR); | 759 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR); |
| 760 }; | 760 }; |
| 761 | 761 |
| 762 class NET_EXPORT_PRIVATE SpdyAltSvcIR : public SpdyFrameWithStreamIdIR { | 762 class NET_EXPORT_PRIVATE SpdyAltSvcIR : public SpdyFrameWithStreamIdIR { |
| 763 public: | 763 public: |
| 764 explicit SpdyAltSvcIR(SpdyStreamId stream_id); | 764 explicit SpdyAltSvcIR(SpdyStreamId stream_id); |
| 765 ~SpdyAltSvcIR() override; | 765 ~SpdyAltSvcIR() override; |
| 766 | 766 |
| 767 std::string origin() const { return origin_; } | 767 SpdyString origin() const { return origin_; } |
| 768 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector() const { | 768 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector() const { |
| 769 return altsvc_vector_; | 769 return altsvc_vector_; |
| 770 } | 770 } |
| 771 | 771 |
| 772 void set_origin(std::string origin) { origin_ = std::move(origin); } | 772 void set_origin(SpdyString origin) { origin_ = std::move(origin); } |
| 773 void add_altsvc(const SpdyAltSvcWireFormat::AlternativeService& altsvc) { | 773 void add_altsvc(const SpdyAltSvcWireFormat::AlternativeService& altsvc) { |
| 774 altsvc_vector_.push_back(altsvc); | 774 altsvc_vector_.push_back(altsvc); |
| 775 } | 775 } |
| 776 | 776 |
| 777 void Visit(SpdyFrameVisitor* visitor) const override; | 777 void Visit(SpdyFrameVisitor* visitor) const override; |
| 778 | 778 |
| 779 SpdyFrameType frame_type() const override; | 779 SpdyFrameType frame_type() const override; |
| 780 | 780 |
| 781 private: | 781 private: |
| 782 std::string origin_; | 782 SpdyString origin_; |
| 783 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector_; | 783 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector_; |
| 784 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR); | 784 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR); |
| 785 }; | 785 }; |
| 786 | 786 |
| 787 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR { | 787 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR { |
| 788 public: | 788 public: |
| 789 explicit SpdyPriorityIR(SpdyStreamId stream_id) | 789 explicit SpdyPriorityIR(SpdyStreamId stream_id) |
| 790 : SpdyFrameWithStreamIdIR(stream_id), | 790 : SpdyFrameWithStreamIdIR(stream_id), |
| 791 parent_stream_id_(0), | 791 parent_stream_id_(0), |
| 792 weight_(1), | 792 weight_(1), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 SpdyFrameVisitor() {} | 917 SpdyFrameVisitor() {} |
| 918 virtual ~SpdyFrameVisitor() {} | 918 virtual ~SpdyFrameVisitor() {} |
| 919 | 919 |
| 920 private: | 920 private: |
| 921 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 921 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
| 922 }; | 922 }; |
| 923 | 923 |
| 924 } // namespace net | 924 } // namespace net |
| 925 | 925 |
| 926 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 926 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
| OLD | NEW |