]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/net/protocols/HTTPClient_HelloWorld/HTTPClient/data/HTTPText.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / net / protocols / HTTPClient_HelloWorld / HTTPClient / data / HTTPText.cpp
1 /* HTTPText.cpp */
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 #include "HTTPText.h"
21
22 #include <cstring>
23
24 #define OK 0
25
26 using std::memcpy;
27 using std::strncpy;
28 using std::strlen;
29
30 #define MIN(x,y) (((x)<(y))?(x):(y))
31
32 HTTPText::HTTPText(char* str) : m_str(str), m_pos(0)
33 {
34 m_size = strlen(str) + 1;
35 }
36
37 HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
38 {
39
40 }
41
42 //IHTTPDataIn
43 /*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
44 {
45 *pReadLen = MIN(len, m_size - 1 - m_pos);
46 memcpy(buf, m_str + m_pos, *pReadLen);
47 m_pos += *pReadLen;
48 return OK;
49 }
50
51 /*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
52 {
53 strncpy(type, "text/plain", maxTypeLen-1);
54 type[maxTypeLen-1] = '\0';
55 return OK;
56 }
57
58 /*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
59 {
60 return false;
61 }
62
63 /*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
64 {
65 return m_size - 1;
66 }
67
68 //IHTTPDataOut
69 /*virtual*/ int HTTPText::write(const char* buf, size_t len)
70 {
71 size_t writeLen = MIN(len, m_size - 1 - m_pos);
72 memcpy(m_str + m_pos, buf, writeLen);
73 m_pos += writeLen;
74 m_str[m_pos] = '\0';
75 return OK;
76 }
77
78 /*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
79 {
80
81 }
82
83 /*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
84 {
85
86 }
87
88 /*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
89 {
90
91 }
92
93
94
Imprint / Impressum