It is the new miniTLS program which build the connect with the website httpbin.org

Fork of MiniTLS-HTTPSClient by Donatien Garnier

Committer:
MiniTLS
Date:
Tue Jun 10 14:23:22 2014 +0000
Revision:
0:62a4a8ec4ab5
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MiniTLS 0:62a4a8ec4ab5 1 /* HTTPText.cpp */
MiniTLS 0:62a4a8ec4ab5 2 /* Copyright (C) 2012 mbed.org, MIT License
MiniTLS 0:62a4a8ec4ab5 3 *
MiniTLS 0:62a4a8ec4ab5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
MiniTLS 0:62a4a8ec4ab5 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
MiniTLS 0:62a4a8ec4ab5 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
MiniTLS 0:62a4a8ec4ab5 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
MiniTLS 0:62a4a8ec4ab5 8 * furnished to do so, subject to the following conditions:
MiniTLS 0:62a4a8ec4ab5 9 *
MiniTLS 0:62a4a8ec4ab5 10 * The above copyright notice and this permission notice shall be included in all copies or
MiniTLS 0:62a4a8ec4ab5 11 * substantial portions of the Software.
MiniTLS 0:62a4a8ec4ab5 12 *
MiniTLS 0:62a4a8ec4ab5 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
MiniTLS 0:62a4a8ec4ab5 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
MiniTLS 0:62a4a8ec4ab5 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
MiniTLS 0:62a4a8ec4ab5 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MiniTLS 0:62a4a8ec4ab5 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MiniTLS 0:62a4a8ec4ab5 18 */
MiniTLS 0:62a4a8ec4ab5 19
MiniTLS 0:62a4a8ec4ab5 20 #include "HTTPText.h"
MiniTLS 0:62a4a8ec4ab5 21
MiniTLS 0:62a4a8ec4ab5 22 #include <cstring>
MiniTLS 0:62a4a8ec4ab5 23
MiniTLS 0:62a4a8ec4ab5 24 #include "core/fwk.h"
MiniTLS 0:62a4a8ec4ab5 25
MiniTLS 0:62a4a8ec4ab5 26 #define OK 0
MiniTLS 0:62a4a8ec4ab5 27
MiniTLS 0:62a4a8ec4ab5 28 HTTPText::HTTPText(char* str) : m_str(str), m_pos(0)
MiniTLS 0:62a4a8ec4ab5 29 {
MiniTLS 0:62a4a8ec4ab5 30 m_size = strlen(str) + 1;
MiniTLS 0:62a4a8ec4ab5 31 }
MiniTLS 0:62a4a8ec4ab5 32
MiniTLS 0:62a4a8ec4ab5 33 HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
MiniTLS 0:62a4a8ec4ab5 34 {
MiniTLS 0:62a4a8ec4ab5 35
MiniTLS 0:62a4a8ec4ab5 36 }
MiniTLS 0:62a4a8ec4ab5 37
MiniTLS 0:62a4a8ec4ab5 38 //IHTTPDataIn
MiniTLS 0:62a4a8ec4ab5 39 /*virtual*/ void HTTPText::readReset()
MiniTLS 0:62a4a8ec4ab5 40 {
MiniTLS 0:62a4a8ec4ab5 41 m_pos = 0;
MiniTLS 0:62a4a8ec4ab5 42 }
MiniTLS 0:62a4a8ec4ab5 43
MiniTLS 0:62a4a8ec4ab5 44 /*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
MiniTLS 0:62a4a8ec4ab5 45 {
MiniTLS 0:62a4a8ec4ab5 46 *pReadLen = MIN(len, m_size - 1 - m_pos);
MiniTLS 0:62a4a8ec4ab5 47 memcpy(buf, m_str + m_pos, *pReadLen);
MiniTLS 0:62a4a8ec4ab5 48 m_pos += *pReadLen;
MiniTLS 0:62a4a8ec4ab5 49 return OK;
MiniTLS 0:62a4a8ec4ab5 50 }
MiniTLS 0:62a4a8ec4ab5 51
MiniTLS 0:62a4a8ec4ab5 52 /*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
MiniTLS 0:62a4a8ec4ab5 53 {
MiniTLS 0:62a4a8ec4ab5 54 strncpy(type, "text/plain", maxTypeLen-1);
MiniTLS 0:62a4a8ec4ab5 55 type[maxTypeLen-1] = '\0';
MiniTLS 0:62a4a8ec4ab5 56 return OK;
MiniTLS 0:62a4a8ec4ab5 57 }
MiniTLS 0:62a4a8ec4ab5 58
MiniTLS 0:62a4a8ec4ab5 59 /*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
MiniTLS 0:62a4a8ec4ab5 60 {
MiniTLS 0:62a4a8ec4ab5 61 return false;
MiniTLS 0:62a4a8ec4ab5 62 }
MiniTLS 0:62a4a8ec4ab5 63
MiniTLS 0:62a4a8ec4ab5 64 /*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
MiniTLS 0:62a4a8ec4ab5 65 {
MiniTLS 0:62a4a8ec4ab5 66 return m_size - 1;
MiniTLS 0:62a4a8ec4ab5 67 }
MiniTLS 0:62a4a8ec4ab5 68
MiniTLS 0:62a4a8ec4ab5 69 //IHTTPDataOut
MiniTLS 0:62a4a8ec4ab5 70 /*virtual*/ void HTTPText::writeReset()
MiniTLS 0:62a4a8ec4ab5 71 {
MiniTLS 0:62a4a8ec4ab5 72 m_pos = 0;
MiniTLS 0:62a4a8ec4ab5 73 }
MiniTLS 0:62a4a8ec4ab5 74
MiniTLS 0:62a4a8ec4ab5 75 /*virtual*/ int HTTPText::write(const char* buf, size_t len)
MiniTLS 0:62a4a8ec4ab5 76 {
MiniTLS 0:62a4a8ec4ab5 77 size_t writeLen = MIN(len, m_size - 1 - m_pos);
MiniTLS 0:62a4a8ec4ab5 78 memcpy(m_str + m_pos, buf, writeLen);
MiniTLS 0:62a4a8ec4ab5 79 m_pos += writeLen;
MiniTLS 0:62a4a8ec4ab5 80 m_str[m_pos] = '\0';
MiniTLS 0:62a4a8ec4ab5 81 return OK;
MiniTLS 0:62a4a8ec4ab5 82 }
MiniTLS 0:62a4a8ec4ab5 83
MiniTLS 0:62a4a8ec4ab5 84 /*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
MiniTLS 0:62a4a8ec4ab5 85 {
MiniTLS 0:62a4a8ec4ab5 86
MiniTLS 0:62a4a8ec4ab5 87 }
MiniTLS 0:62a4a8ec4ab5 88
MiniTLS 0:62a4a8ec4ab5 89 /*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
MiniTLS 0:62a4a8ec4ab5 90 {
MiniTLS 0:62a4a8ec4ab5 91
MiniTLS 0:62a4a8ec4ab5 92 }
MiniTLS 0:62a4a8ec4ab5 93
MiniTLS 0:62a4a8ec4ab5 94 /*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
MiniTLS 0:62a4a8ec4ab5 95 {
MiniTLS 0:62a4a8ec4ab5 96
MiniTLS 0:62a4a8ec4ab5 97 }
MiniTLS 0:62a4a8ec4ab5 98
MiniTLS 0:62a4a8ec4ab5 99
MiniTLS 0:62a4a8ec4ab5 100