| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_BASE_MULTIPART_H__ | |
| 12 #define WEBRTC_BASE_MULTIPART_H__ | |
| 13 | |
| 14 #include <string> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "webrtc/base/constructormagic.h" | |
| 18 #include "webrtc/base/sigslot.h" | |
| 19 #include "webrtc/base/stream.h" | |
| 20 | |
| 21 namespace rtc { | |
| 22 | |
| 23 /////////////////////////////////////////////////////////////////////////////// | |
| 24 // MultipartStream - Implements an RFC2046 multipart stream by concatenating | |
| 25 // the supplied parts together, and adding the correct boundaries. | |
| 26 /////////////////////////////////////////////////////////////////////////////// | |
| 27 | |
| 28 class MultipartStream : public StreamInterface, public sigslot::has_slots<> { | |
| 29 public: | |
| 30 MultipartStream(const std::string& type, const std::string& boundary); | |
| 31 ~MultipartStream() override; | |
| 32 | |
| 33 void GetContentType(std::string* content_type); | |
| 34 | |
| 35 // Note: If content_disposition and/or content_type are the empty string, | |
| 36 // they will be omitted. | |
| 37 bool AddPart(StreamInterface* data_stream, | |
| 38 const std::string& content_disposition, | |
| 39 const std::string& content_type); | |
| 40 bool AddPart(const std::string& data, | |
| 41 const std::string& content_disposition, | |
| 42 const std::string& content_type); | |
| 43 void EndParts(); | |
| 44 | |
| 45 // Calculates the size of a part before actually adding the part. | |
| 46 size_t GetPartSize(const std::string& data, | |
| 47 const std::string& content_disposition, | |
| 48 const std::string& content_type) const; | |
| 49 size_t GetEndPartSize() const; | |
| 50 | |
| 51 // StreamInterface | |
| 52 StreamState GetState() const override; | |
| 53 StreamResult Read(void* buffer, | |
| 54 size_t buffer_len, | |
| 55 size_t* read, | |
| 56 int* error) override; | |
| 57 StreamResult Write(const void* data, | |
| 58 size_t data_len, | |
| 59 size_t* written, | |
| 60 int* error) override; | |
| 61 void Close() override; | |
| 62 bool SetPosition(size_t position) override; | |
| 63 bool GetPosition(size_t* position) const override; | |
| 64 bool GetSize(size_t* size) const override; | |
| 65 bool GetAvailable(size_t* size) const override; | |
| 66 | |
| 67 private: | |
| 68 typedef std::vector<StreamInterface*> PartList; | |
| 69 | |
| 70 // StreamInterface Slots | |
| 71 void OnEvent(StreamInterface* stream, int events, int error); | |
| 72 | |
| 73 std::string type_, boundary_; | |
| 74 PartList parts_; | |
| 75 bool adding_; | |
| 76 size_t current_; // The index into parts_ of the current read position. | |
| 77 size_t position_; // The current read position in bytes. | |
| 78 | |
| 79 RTC_DISALLOW_COPY_AND_ASSIGN(MultipartStream); | |
| 80 }; | |
| 81 | |
| 82 } // namespace rtc | |
| 83 | |
| 84 #endif // WEBRTC_BASE_MULTIPART_H__ | |
| OLD | NEW |