Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPStream.cpp Source File

HTTPStream.cpp

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all 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
00021 THE SOFTWARE.
00022 */
00023 
00024 #include "HTTPStream.h"
00025 
00026 #define MIN(a,b) ((a)<(b)?(a):(b))
00027 
00028 HTTPStream::HTTPStream() : HTTPData(), m_buf(NULL), m_size(0), m_len(0)
00029 {
00030 
00031 }
00032 
00033 HTTPStream::~HTTPStream()
00034 {
00035 
00036 }
00037 
00038 
00039 void HTTPStream::readNext(byte* buf, int size)
00040 {
00041   m_buf = buf;
00042   m_size = size;
00043   m_len = 0;
00044 }
00045   
00046 bool HTTPStream::readable()
00047 {
00048   return (m_len>0);
00049 }
00050   
00051 int HTTPStream::readLen()
00052 {
00053   return m_len;
00054 }
00055 
00056 void HTTPStream::clear()
00057 {
00058   //Do nothing here since it is a stream and not a buffer
00059 }
00060 
00061 int HTTPStream::read(char* buf, int len)
00062 {
00063   return 0; //Unsupported yet
00064 }
00065 
00066 int HTTPStream::write(const char* buf, int len)
00067 {
00068   if(!m_buf)
00069     return 0;
00070   len = MIN( m_size - m_len, len );
00071   memcpy(m_buf + m_len, buf, len);
00072   m_len += len;
00073   return len;
00074 }
00075   
00076 string HTTPStream::getDataType() //Internet media type for Content-Type header
00077 {
00078   return "";
00079 }
00080 
00081 void HTTPStream::setDataType(const string& type) //Internet media type from Content-Type header
00082 {
00083   //Do not really care here
00084 }
00085 
00086 bool HTTPStream::getIsChunked() //For Transfer-Encoding header
00087 {
00088   return false; //We don't want to chunk this
00089 }
00090 
00091 void HTTPStream::setIsChunked(bool chunked) //From Transfer-Encoding header
00092 {
00093   //Nothing to do
00094 }
00095   
00096 int HTTPStream::getDataLen() //For Content-Length header
00097 {
00098   return 0;
00099 }
00100 
00101 void HTTPStream::setDataLen(int len) //From Content-Length header, or if the transfer is chunked, next chunk length
00102 {
00103 
00104 }