HTTP Client library

Dependents:   weather_LCD_display News_LCD_display TwitterExample_1 GeoLocation_LCD_Display ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPText.cpp Source File

HTTPText.cpp

00001 /* HTTPText.cpp */
00002 /*
00003 Copyright (C) 2012 ARM Limited.
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy of
00006 this software and associated documentation files (the "Software"), to deal in
00007 the Software without restriction, including without limitation the rights to
00008 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
00009 of the Software, and to permit persons to whom the Software is furnished to do
00010 so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in all
00013 copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00021 SOFTWARE.
00022 */
00023 
00024 #include "core/fwk.h"
00025 
00026 #include "HTTPText.h"
00027 
00028 #include <cstring>
00029 
00030 HTTPText::HTTPText(char* str) : m_str(str), m_pos(0)
00031 {
00032   m_size = strlen(str) + 1;
00033 }
00034 
00035 HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
00036 {
00037 
00038 }
00039 
00040 //IHTTPDataIn
00041 /*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
00042 {
00043   *pReadLen = MIN(len, m_size - 1 - m_pos);
00044   memcpy(buf, m_str + m_pos, *pReadLen);
00045   m_pos += *pReadLen;
00046   return OK;
00047 }
00048 
00049 /*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
00050 {
00051   strncpy(type, "text/plain", maxTypeLen-1);
00052   type[maxTypeLen-1] = '\0';
00053   return OK;
00054 }
00055 
00056 /*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
00057 {
00058   return false;
00059 }
00060 
00061 /*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
00062 {
00063   return m_size - 1;
00064 }
00065 
00066 //IHTTPDataOut
00067 /*virtual*/ int HTTPText::write(const char* buf, size_t len)
00068 {
00069   size_t writeLen = MIN(len, m_size - 1 - m_pos);
00070   memcpy(m_str + m_pos, buf, writeLen);
00071   m_pos += writeLen;
00072   m_str[m_pos] = '\0';
00073   return OK;
00074 }
00075 
00076 /*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
00077 {
00078 
00079 }
00080 
00081 /*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
00082 {
00083 
00084 }
00085 
00086 /*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
00087 {
00088 
00089 }
00090 
00091 
00092