test

Dependencies:   BME280 SB1602E

Fork of MultiIoTBoardLib by Junichi Katsu

Committer:
jksoft
Date:
Fri Jul 28 02:23:25 2017 +0000
Revision:
0:bad9495b4215
First edition

Who changed what in which revision?

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