Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HttpText.h Source File

HttpText.h

00001 /*
00002  * HttpText.h
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 /* Copyright (C) 2012 mbed.org, MIT License
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00013  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00014  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00015  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00016  * furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included in all copies or
00019  * substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00022  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00023  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00024  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #ifndef HTTPTEXT_H_
00029     #define HTTPTEXT_H_
00030 
00031     #include "IHttpDataIn.h"
00032     #include "IHttpDataOut.h"
00033 
00034 ///This is a basic TEXT/JSON/HTML/XML implementation of IHttpDataIn and IHttpDataOut to work with SecureHttpClient
00035 class HttpText : public IHttpDataIn, public IHttpDataOut
00036 {
00037     public:
00038         /** Create an HttpText instance for output
00039          * @param str String to be transmitted
00040          */
00041         HttpText ( char * );
00042 
00043         /** Create an HttpText instance for input
00044          * @param str Buffer to store the incoming string
00045          * @param size Size of the buffer
00046          */
00047         HttpText(char* str, size_t size);
00048 
00049         virtual ~HttpText ();
00050 
00051     private:
00052         HttpText ( const HttpText & other );
00053 
00054     protected:
00055         //IHTTPDataIn
00056         virtual void readReset();
00057 
00058         virtual int read(char* buf, size_t len, size_t* pReadLen);
00059 
00060         virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
00061 
00062         virtual bool getIsChunked(); //For Transfer-Encoding header
00063 
00064         virtual size_t getDataLen(); //For Content-Length header
00065 
00066         //IHTTPDataOut
00067         virtual void writeReset();
00068 
00069         virtual int write(const char* buf, size_t len);
00070 
00071         virtual void setDataType(const char* type); //Internet media type from Content-Type header
00072 
00073         virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
00074 
00075         virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
00076 
00077     private:
00078         char* m_str;
00079         size_t m_size;
00080         size_t m_pos;
00081         bool m_isChunked;};
00082 
00083 #endif /* HTTPTEXT_H_ */
00084