]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / net / cellular / http / common / 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*/ void HTTPText::readReset()
44 {
45 m_pos = 0;
46 }
47
48 /*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
49 {
50 *pReadLen = MIN(len, m_size - 1 - m_pos);
51 memcpy(buf, m_str + m_pos, *pReadLen);
52 m_pos += *pReadLen;
53 return OK;
54 }
55
56 /*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
57 {
58 strncpy(type, "text/plain", maxTypeLen-1);
59 type[maxTypeLen-1] = '\0';
60 return OK;
61 }
62
63 /*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
64 {
65 return false;
66 }
67
68 /*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
69 {
70 return m_size - 1;
71 }
72
73 //IHTTPDataOut
74 /*virtual*/ void HTTPText::writeReset()
75 {
76 m_pos = 0;
77 }
78
79 /*virtual*/ int HTTPText::write(const char* buf, size_t len)
80 {
81 size_t writeLen = MIN(len, m_size - 1 - m_pos);
82 memcpy(m_str + m_pos, buf, writeLen);
83 m_pos += writeLen;
84 m_str[m_pos] = '\0';
85 return OK;
86 }
87
88 /*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
89 {
90
91 }
92
93 /*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
94 {
95
96 }
97
98 /*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
99 {
100
101 }
102
103
104
Imprint / Impressum