]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp
2 /* Copyright (C) 2012 mbed.org, MIT License
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:
10 * The above copyright notice and this permission notice shall be included in all copies or
11 * substantial portions of the Software.
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.
30 HTTPMap::HTTPMap() : m_pos(0), m_count(0)
35 void HTTPMap::put(const char* key
, const char* value
)
37 if(m_count
>= HTTPMAP_TABLE_SIZE
)
41 m_keys
[m_count
] = key
;
42 m_values
[m_count
] = value
;
52 /*virtual*/ void HTTPMap::readReset()
57 /*virtual*/ int HTTPMap::read(char* buf
, size_t len
, size_t* pReadLen
)
68 const char* in
= m_keys
[m_pos
];
69 if( (m_pos
!= 0) && (out
- buf
< len
- 1) )
75 while( (*in
!= '\0') && (out
- buf
< len
- 3) )
77 if (std::isalnum(*in
) || *in
== '-' || *in
== '_' || *in
== '.' || *in
== '~')
89 char hex
[] = "0123456789abcdef";
92 *out
=hex
[(*in
>>4)&0xf];
100 if( out
- buf
< len
- 1 )
106 in
= m_values
[m_pos
];
107 while( (*in
!= '\0') && (out
- buf
< len
- 3) )
109 if (std::isalnum(*in
) || *in
== '-' || *in
== '_' || *in
== '.' || *in
== '~')
114 else if( *in
== ' ' )
121 char hex
[] = "0123456789abcdef";
124 *out
=hex
[(*in
>>4)&0xf];
132 *pReadLen
= out
- buf
;
138 /*virtual*/ int HTTPMap::getDataType(char* type
, size_t maxTypeLen
) //Internet media type for Content-Type header
140 strncpy(type
, "application/x-www-form-urlencoded", maxTypeLen
-1);
141 type
[maxTypeLen
-1] = '\0';
145 /*virtual*/ bool HTTPMap::getIsChunked() //For Transfer-Encoding header
147 return false; ////Data is computed one key/value pair at a time
150 /*virtual*/ size_t HTTPMap::getDataLen() //For Content-Length header
153 for(size_t i
= 0; i
< m_count
; i
++)
156 const char* in
= m_keys
[i
];
162 while( (*in
!= '\0') )
164 if (std::isalnum(*in
) || *in
== '-' || *in
== '_' || *in
== '.' || *in
== '~')
168 else if( *in
== ' ' )
182 while( (*in
!= '\0') )
184 if (std::isalnum(*in
) || *in
== '-' || *in
== '_' || *in
== '.' || *in
== '~')
188 else if( *in
== ' ' )