Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HttpText.cpp
00001 /* 00002 * HttpText.cpp 00003 * 00004 * Created on: Aug 16, 2016 00005 * Author: Faheem Inayat 00006 * Created for: Renesas Electronics America HQ, Santa Clara, CA, USA 00007 * 00008 * Copyright (c) 2016 Renesas Electronics America (REA) and Faheem Inayat 00009 */ 00010 00011 /* Copyright (C) 2012 mbed.org, MIT License 00012 * 00013 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00014 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00015 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00016 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00017 * furnished to do so, subject to the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be included in all copies or 00020 * substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00023 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00024 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00025 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00027 */ 00028 00029 #include "HttpText.h" 00030 00031 #include <cstring> 00032 00033 #define OK 0 00034 00035 using std::memcpy; 00036 using std::strncpy; 00037 using std::strlen; 00038 00039 #define MIN(x,y) (((x)<(y))?(x):(y)) 00040 00041 HttpText::HttpText ( char* str ) 00042 : m_str ( str ), m_pos ( 0 ) 00043 { 00044 m_size = strlen ( str ) + 1; 00045 m_isChunked = false; 00046 } 00047 00048 HttpText::HttpText ( char* str, size_t size ) 00049 : m_str ( str ), m_size ( size ), m_pos ( 0 ) 00050 { 00051 m_isChunked = false; 00052 } 00053 00054 HttpText::~HttpText () 00055 { 00056 } 00057 00058 HttpText::HttpText ( const HttpText & ) 00059 { 00060 m_str = NULL; 00061 m_pos = 0; 00062 m_size = 0; 00063 m_isChunked = false; 00064 } 00065 00066 //IHTTPDataIn 00067 void HttpText::readReset () 00068 { 00069 m_pos = 0; 00070 } 00071 00072 int HttpText::read ( char* buf, size_t len, size_t* pReadLen ) 00073 { 00074 *pReadLen = MIN( len, m_size - 1 - m_pos ); 00075 memcpy ( buf, m_str + m_pos, *pReadLen ); 00076 m_pos += *pReadLen; 00077 return OK; 00078 } 00079 00080 int HttpText::getDataType ( char* type, size_t maxTypeLen ) //Internet media type for Content-Type header 00081 { 00082 strncpy ( type, "text/plain", maxTypeLen - 1 ); 00083 type [ maxTypeLen - 1 ] = '\0'; 00084 return OK; 00085 } 00086 00087 bool HttpText::getIsChunked () //For Transfer-Encoding header 00088 { 00089 return m_isChunked; 00090 } 00091 00092 size_t HttpText::getDataLen () //For Content-Length header 00093 { 00094 return m_size - 1; 00095 } 00096 00097 //IHTTPDataOut 00098 void HttpText::writeReset () 00099 { 00100 m_pos = 0; 00101 } 00102 00103 int HttpText::write ( const char* buf, size_t len ) 00104 { 00105 size_t writeLen = MIN( len, m_size - 1 - m_pos ); 00106 memcpy ( m_str + m_pos, buf, writeLen ); 00107 m_pos += writeLen; 00108 m_str [ m_pos ] = '\0'; 00109 return OK; 00110 } 00111 00112 void HttpText::setDataType ( const char * ) //Internet media type from Content-Type header 00113 { 00114 00115 } 00116 00117 void HttpText::setIsChunked ( bool chunked ) //From Transfer-Encoding header 00118 { 00119 m_isChunked = chunked; 00120 } 00121 00122 void HttpText::setDataLen ( size_t ) //From Content-Length header, or if the transfer is chunked, next chunk length 00123 { 00124 // m_pos = len; 00125 } 00126
Generated on Tue Jul 12 2022 15:55:18 by
1.7.2