]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/net/protocols/HTTPClient_HelloWorld/HTTPClient/data/HTTPText.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / net / protocols / HTTPClient_HelloWorld / HTTPClient / data / HTTPText.h
1 /* HTTPText.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
21 #ifndef HTTPTEXT_H_
22 #define HTTPTEXT_H_
23
24 #include "../IHTTPData.h"
25
26 /** A data endpoint to store text
27 */
28 class HTTPText : public IHTTPDataIn, public IHTTPDataOut
29 {
30 public:
31   /** Create an HTTPText instance for output
32    * @param str String to be transmitted
33    */
34   HTTPText(char* str);
35
36   /** Create an HTTPText instance for input
37    * @param str Buffer to store the incoming string
38    * @param size Size of the buffer
39    */
40   HTTPText(char* str, size_t size);
41
42 protected:
43   //IHTTPDataIn
44   virtual int read(char* buf, size_t len, size_t* pReadLen);
45
46   virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
47
48   virtual bool getIsChunked(); //For Transfer-Encoding header
49
50   virtual size_t getDataLen(); //For Content-Length header
51
52   //IHTTPDataOut
53   virtual int write(const char* buf, size_t len);
54
55   virtual void setDataType(const char* type); //Internet media type from Content-Type header
56
57   virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
58
59   virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
60
61 private:
62   char* m_str;
63   size_t m_size;
64
65   size_t m_pos;
66 };
67
68 #endif /* HTTPTEXT_H_ */