| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 | 11 |
| 12 #ifndef WEBRTC_BASE_HTTPBASE_H__ | 12 #ifndef WEBRTC_RTC_BASE_HTTPBASE_H_ |
| 13 #define WEBRTC_BASE_HTTPBASE_H__ | 13 #define WEBRTC_RTC_BASE_HTTPBASE_H_ |
| 14 | 14 |
| 15 #include "webrtc/base/httpcommon.h" | 15 #include "webrtc/base/httpcommon.h" |
| 16 | 16 |
| 17 namespace rtc { | 17 namespace rtc { |
| 18 | 18 |
| 19 class StreamInterface; | 19 class StreamInterface; |
| 20 | 20 |
| 21 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
| 22 // HttpParser - Parses an HTTP stream provided via Process and end_of_input, and | 22 // HttpParser - Parses an HTTP stream provided via Process and end_of_input, and |
| 23 // generates events for: | 23 // generates events for: |
| 24 // Structural Elements: Leader, Headers, Document Data | 24 // Structural Elements: Leader, Headers, Document Data |
| 25 // Events: End of Headers, End of Document, Errors | 25 // Events: End of Headers, End of Document, Errors |
| 26 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
| 28 class HttpParser { | 28 class HttpParser { |
| 29 public: | 29 public: |
| 30 enum ProcessResult { PR_CONTINUE, PR_BLOCK, PR_COMPLETE }; | 30 enum ProcessResult { PR_CONTINUE, PR_BLOCK, PR_COMPLETE }; |
| 31 HttpParser(); | 31 HttpParser(); |
| 32 virtual ~HttpParser(); | 32 virtual ~HttpParser(); |
| 33 | 33 |
| 34 void reset(); | 34 void reset(); |
| 35 ProcessResult Process(const char* buffer, size_t len, size_t* processed, | 35 ProcessResult Process(const char* buffer, size_t len, size_t* processed, |
| 36 HttpError* error); | 36 HttpError* error); |
| 37 bool is_valid_end_of_input() const; | 37 bool is_valid_end_of_input() const; |
| 38 void complete(HttpError err); | 38 void complete(HttpError err); |
| 39 | 39 |
| 40 size_t GetDataRemaining() const { return data_size_; } | 40 size_t GetDataRemaining() const { return data_size_; } |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 ProcessResult ProcessLine(const char* line, size_t len, HttpError* error); | 43 ProcessResult ProcessLine(const char* line, size_t len, HttpError* error); |
| 44 | 44 |
| 45 // HttpParser Interface | 45 // HttpParser Interface |
| 46 virtual ProcessResult ProcessLeader(const char* line, size_t len, | 46 virtual ProcessResult ProcessLeader(const char* line, size_t len, |
| 47 HttpError* error) = 0; | 47 HttpError* error) = 0; |
| 48 virtual ProcessResult ProcessHeader(const char* name, size_t nlen, | 48 virtual ProcessResult ProcessHeader(const char* name, size_t nlen, |
| 49 const char* value, size_t vlen, | 49 const char* value, size_t vlen, |
| 50 HttpError* error) = 0; | 50 HttpError* error) = 0; |
| 51 virtual ProcessResult ProcessHeaderComplete(bool chunked, size_t& data_size, | 51 virtual ProcessResult ProcessHeaderComplete(bool chunked, size_t& data_size, |
| 52 HttpError* error) = 0; | 52 HttpError* error) = 0; |
| 53 virtual ProcessResult ProcessData(const char* data, size_t len, size_t& read, | 53 virtual ProcessResult ProcessData(const char* data, size_t len, size_t& read, |
| 54 HttpError* error) = 0; | 54 HttpError* error) = 0; |
| 55 virtual void OnComplete(HttpError err) = 0; | 55 virtual void OnComplete(HttpError err) = 0; |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 enum State { | 58 enum State { |
| 59 ST_LEADER, ST_HEADERS, | 59 ST_LEADER, ST_HEADERS, |
| 60 ST_CHUNKSIZE, ST_CHUNKTERM, ST_TRAILERS, | 60 ST_CHUNKSIZE, ST_CHUNKTERM, ST_TRAILERS, |
| 61 ST_DATA, ST_COMPLETE | 61 ST_DATA, ST_COMPLETE |
| 62 } state_; | 62 } state_; |
| 63 bool chunked_; | 63 bool chunked_; |
| 64 size_t data_size_; | 64 size_t data_size_; |
| 65 }; | 65 }; |
| 66 | 66 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 size_t len_; | 177 size_t len_; |
| 178 | 178 |
| 179 bool ignore_data_, chunk_data_; | 179 bool ignore_data_, chunk_data_; |
| 180 HttpData::const_iterator header_; | 180 HttpData::const_iterator header_; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
| 184 | 184 |
| 185 } // namespace rtc | 185 } // namespace rtc |
| 186 | 186 |
| 187 #endif // WEBRTC_BASE_HTTPBASE_H__ | 187 #endif // WEBRTC_RTC_BASE_HTTPBASE_H_ |
| OLD | NEW |