]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/protocols/HTTPClient_HelloWorld/HTTPClient/IHTTPData.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / tests / net / protocols / HTTPClient_HelloWorld / HTTPClient / IHTTPData.h
1 /* IHTTPData.h */
2 /* Copyright (C) 2012 mbed.org, MIT License
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5  * and associated documentation files (the "Software"), to deal in the Software without restriction,
6  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
7  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all copies or
11  * substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18  */
19
20 #ifndef IHTTPDATA_H
21 #define IHTTPDATA_H
22
23 #include <cstring>
24
25 using std::size_t;
26
27 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
28 class IHTTPDataOut
29 {
30 protected:
31   friend class HTTPClient;
32
33   /** Read a piece of data to be transmitted
34    * @param buf Pointer to the buffer on which to copy the data
35    * @param len Length of the buffer
36    * @param pReadLen Pointer to the variable on which the actual copied data length will be stored
37    */
38   virtual int read(char* buf, size_t len, size_t* pReadLen) = 0;
39
40   /** Get MIME type
41    * @param type Internet media type from Content-Type header
42    */
43   virtual int getDataType(char* type, size_t maxTypeLen) = 0; //Internet media type for Content-Type header
44
45   /** Determine whether the HTTP client should chunk the data
46    *  Used for Transfer-Encoding header
47    */
48   virtual bool getIsChunked() = 0;
49
50   /** If the data is not chunked, get its size
51    *  Used for Content-Length header
52    */
53   virtual size_t getDataLen() = 0;
54
55 };
56
57 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
58 class IHTTPDataIn
59 {
60 protected:
61   friend class HTTPClient;
62
63   /** Write a piece of data transmitted by the server
64    * @param buf Pointer to the buffer from which to copy the data
65    * @param len Length of the buffer
66    */
67   virtual int write(const char* buf, size_t len) = 0;
68
69   /** Set MIME type
70    * @param type Internet media type from Content-Type header
71    */
72   virtual void setDataType(const char* type) = 0;
73
74   /** Determine whether the data is chunked
75    *  Recovered from Transfer-Encoding header
76    */
77   virtual void setIsChunked(bool chunked) = 0;
78
79   /** If the data is not chunked, set its size
80    * From Content-Length header
81    */
82   virtual void setDataLen(size_t len) = 0;
83
84 };
85
86 #endif