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;
53 /*virtual*/ int HTTPMap::read(char* buf, size_t len, size_t* pReadLen)
64 const char* in = m_keys[m_pos];
65 if( (m_pos != 0) && (out - buf < len - 1) )
71 while( (*in != '\0') && (out - buf < len - 3) )
73 if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
85 char hex[] = "0123456789abcdef";
88 *out=hex[(*in>>4)&0xf];
96 if( out - buf < len - 1 )
102 in = m_values[m_pos];
103 while( (*in != '\0') && (out - buf < len - 3) )
105 if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
110 else if( *in == ' ' )
117 char hex[] = "0123456789abcdef";
120 *out=hex[(*in>>4)&0xf];
128 *pReadLen = out - buf;
134 /*virtual*/ int HTTPMap::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
136 strncpy(type, "application/x-www-form-urlencoded", maxTypeLen-1);
137 type[maxTypeLen-1] = '\0';
141 /*virtual*/ bool HTTPMap::getIsChunked() //For Transfer-Encoding header
143 return false; ////Data is computed one key/value pair at a time
146 /*virtual*/ size_t HTTPMap::getDataLen() //For Content-Length header
149 for(size_t i = 0; i< m_count; i++)
152 const char* in = m_keys[i];
158 while( (*in != '\0') )
160 if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
164 else if( *in == ' ' )
178 while( (*in != '\0') )
180 if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
184 else if( *in == ' ' )