aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data')
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp200
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.h71
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp104
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.h72
4 files changed, 447 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp
new file mode 100644
index 000000000..5eb4c52e6
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp
@@ -0,0 +1,200 @@
+/* HTTPMap.cpp */
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "HTTPMap.h"
+
+#include <cstring>
+
+#include <cctype>
+
+#define OK 0
+
+using std::strncpy;
+
+HTTPMap::HTTPMap() : m_pos(0), m_count(0)
+{
+
+}
+
+void HTTPMap::put(const char* key, const char* value)
+{
+ if(m_count >= HTTPMAP_TABLE_SIZE)
+ {
+ return;
+ }
+ m_keys[m_count] = key;
+ m_values[m_count] = value;
+ m_count++;
+}
+
+void HTTPMap::clear()
+{
+ m_count = 0;
+ m_pos = 0;
+}
+
+/*virtual*/ void HTTPMap::readReset()
+{
+ m_pos = 0;
+}
+
+/*virtual*/ int HTTPMap::read(char* buf, size_t len, size_t* pReadLen)
+{
+ if(m_pos >= m_count)
+ {
+ *pReadLen = 0;
+ m_pos = 0;
+ return OK;
+ }
+
+ //URL encode
+ char* out = buf;
+ const char* in = m_keys[m_pos];
+ if( (m_pos != 0) && (out - buf < len - 1) )
+ {
+ *out='&';
+ out++;
+ }
+
+ while( (*in != '\0') && (out - buf < len - 3) )
+ {
+ if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+ {
+ *out = *in;
+ out++;
+ }
+ else if( *in == ' ' )
+ {
+ *out='+';
+ out++;
+ }
+ else
+ {
+ char hex[] = "0123456789abcdef";
+ *out='%';
+ out++;
+ *out=hex[(*in>>4)&0xf];
+ out++;
+ *out=hex[(*in)&0xf];
+ out++;
+ }
+ in++;
+ }
+
+ if( out - buf < len - 1 )
+ {
+ *out='=';
+ out++;
+ }
+
+ in = m_values[m_pos];
+ while( (*in != '\0') && (out - buf < len - 3) )
+ {
+ if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+ {
+ *out = *in;
+ out++;
+ }
+ else if( *in == ' ' )
+ {
+ *out='+';
+ out++;
+ }
+ else
+ {
+ char hex[] = "0123456789abcdef";
+ *out='%';
+ out++;
+ *out=hex[(*in>>4)&0xf];
+ out++;
+ *out=hex[(*in)&0xf];
+ out++;
+ }
+ in++;
+ }
+
+ *pReadLen = out - buf;
+
+ m_pos++;
+ return OK;
+}
+
+/*virtual*/ int HTTPMap::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
+{
+ strncpy(type, "application/x-www-form-urlencoded", maxTypeLen-1);
+ type[maxTypeLen-1] = '\0';
+ return OK;
+}
+
+/*virtual*/ bool HTTPMap::getIsChunked() //For Transfer-Encoding header
+{
+ return false; ////Data is computed one key/value pair at a time
+}
+
+/*virtual*/ size_t HTTPMap::getDataLen() //For Content-Length header
+{
+ size_t count = 0;
+ for(size_t i = 0; i< m_count; i++)
+ {
+ //URL encode
+ const char* in = m_keys[i];
+ if( i != 0 )
+ {
+ count++;
+ }
+
+ while( (*in != '\0') )
+ {
+ if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+ {
+ count++;
+ }
+ else if( *in == ' ' )
+ {
+ count++;
+ }
+ else
+ {
+ count+=3;
+ }
+ in++;
+ }
+
+ count ++;
+
+ in = m_values[i];
+ while( (*in != '\0') )
+ {
+ if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+ {
+ count++;
+ }
+ else if( *in == ' ' )
+ {
+ count++;
+ }
+ else
+ {
+ count+=3;
+ }
+ in++;
+ }
+ }
+ return count;
+}
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.h b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.h
new file mode 100644
index 000000000..c8433778f
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.h
@@ -0,0 +1,71 @@
+/* HTTPMap.h */
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef HTTPMAP_H_
+#define HTTPMAP_H_
+
+#include "../IHTTPData.h"
+
+#define HTTPMAP_TABLE_SIZE 32
+
+/** Map of key/value pairs
+ * Used to transmit POST data using the application/x-www-form-urlencoded encoding
+ */
+class HTTPMap: public IHTTPDataOut
+{
+public:
+ /**
+ Instantiates HTTPMap
+ It supports at most 32 key/values pairs
+ */
+ HTTPMap();
+
+ /** Put Key/Value pair
+ The references to the parameters must remain valid as long as the clear() function is not called
+ @param key The key to use
+ @param value The corresponding value
+ */
+ void put(const char* key, const char* value);
+
+ /** Clear table
+ */
+ void clear();
+
+protected:
+ //IHTTPDataIn
+ virtual void readReset();
+
+ virtual int read(char* buf, size_t len, size_t* pReadLen);
+
+ virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
+
+ virtual bool getIsChunked(); //For Transfer-Encoding header
+
+ virtual size_t getDataLen(); //For Content-Length header
+
+private:
+ const char* m_keys[HTTPMAP_TABLE_SIZE];
+ const char* m_values[HTTPMAP_TABLE_SIZE];
+
+ size_t m_pos;
+ size_t m_count;
+};
+
+#endif /* HTTPMAP_H_ */
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp
new file mode 100644
index 000000000..18cd42070
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp
@@ -0,0 +1,104 @@
+/* HTTPText.cpp */
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "HTTPText.h"
+
+#include <cstring>
+
+#define OK 0
+
+using std::memcpy;
+using std::strncpy;
+using std::strlen;
+
+#define MIN(x,y) (((x)<(y))?(x):(y))
+
+HTTPText::HTTPText(char* str) : m_str(str), m_pos(0)
+{
+ m_size = strlen(str) + 1;
+}
+
+HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
+{
+
+}
+
+//IHTTPDataIn
+/*virtual*/ void HTTPText::readReset()
+{
+ m_pos = 0;
+}
+
+/*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
+{
+ *pReadLen = MIN(len, m_size - 1 - m_pos);
+ memcpy(buf, m_str + m_pos, *pReadLen);
+ m_pos += *pReadLen;
+ return OK;
+}
+
+/*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
+{
+ strncpy(type, "text/plain", maxTypeLen-1);
+ type[maxTypeLen-1] = '\0';
+ return OK;
+}
+
+/*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
+{
+ return false;
+}
+
+/*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
+{
+ return m_size - 1;
+}
+
+//IHTTPDataOut
+/*virtual*/ void HTTPText::writeReset()
+{
+ m_pos = 0;
+}
+
+/*virtual*/ int HTTPText::write(const char* buf, size_t len)
+{
+ size_t writeLen = MIN(len, m_size - 1 - m_pos);
+ memcpy(m_str + m_pos, buf, writeLen);
+ m_pos += writeLen;
+ m_str[m_pos] = '\0';
+ return OK;
+}
+
+/*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
+{
+
+}
+
+/*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
+{
+
+}
+
+/*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
+{
+
+}
+
+
+
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.h b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.h
new file mode 100644
index 000000000..cb76c6fda
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.h
@@ -0,0 +1,72 @@
+/* HTTPText.h */
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef HTTPTEXT_H_
+#define HTTPTEXT_H_
+
+#include "../IHTTPData.h"
+
+/** A data endpoint to store text
+*/
+class HTTPText : public IHTTPDataIn, public IHTTPDataOut
+{
+public:
+ /** Create an HTTPText instance for output
+ * @param str String to be transmitted
+ */
+ HTTPText(char* str);
+
+ /** Create an HTTPText instance for input
+ * @param str Buffer to store the incoming string
+ * @param size Size of the buffer
+ */
+ HTTPText(char* str, size_t size);
+
+protected:
+ //IHTTPDataIn
+ virtual void readReset();
+
+ virtual int read(char* buf, size_t len, size_t* pReadLen);
+
+ virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
+
+ virtual bool getIsChunked(); //For Transfer-Encoding header
+
+ virtual size_t getDataLen(); //For Content-Length header
+
+ //IHTTPDataOut
+ virtual void writeReset();
+
+ virtual int write(const char* buf, size_t len);
+
+ virtual void setDataType(const char* type); //Internet media type from Content-Type header
+
+ virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
+
+ virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
+
+private:
+ char* m_str;
+ size_t m_size;
+
+ size_t m_pos;
+};
+
+#endif /* HTTPTEXT_H_ */