Dependencies:   mbed

Dependents:   TCP

Committer:
slowness
Date:
Tue Sep 06 18:05:46 2011 +0000
Revision:
0:58c3d014a4e7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
slowness 0:58c3d014a4e7 1
slowness 0:58c3d014a4e7 2 /*
slowness 0:58c3d014a4e7 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
slowness 0:58c3d014a4e7 4
slowness 0:58c3d014a4e7 5 Permission is hereby granted, free of charge, to any person obtaining a copy
slowness 0:58c3d014a4e7 6 of this software and associated documentation files (the "Software"), to deal
slowness 0:58c3d014a4e7 7 in the Software without restriction, including without limitation the rights
slowness 0:58c3d014a4e7 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
slowness 0:58c3d014a4e7 9 copies of the Software, and to permit persons to whom the Software is
slowness 0:58c3d014a4e7 10 furnished to do so, subject to the following conditions:
slowness 0:58c3d014a4e7 11
slowness 0:58c3d014a4e7 12 The above copyright notice and this permission notice shall be included in
slowness 0:58c3d014a4e7 13 all copies or substantial portions of the Software.
slowness 0:58c3d014a4e7 14
slowness 0:58c3d014a4e7 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
slowness 0:58c3d014a4e7 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
slowness 0:58c3d014a4e7 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
slowness 0:58c3d014a4e7 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
slowness 0:58c3d014a4e7 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
slowness 0:58c3d014a4e7 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
slowness 0:58c3d014a4e7 21 THE SOFTWARE.
slowness 0:58c3d014a4e7 22 */
slowness 0:58c3d014a4e7 23
slowness 0:58c3d014a4e7 24 /** \file
slowness 0:58c3d014a4e7 25 HTTP Text data source/sink header file
slowness 0:58c3d014a4e7 26 */
slowness 0:58c3d014a4e7 27
slowness 0:58c3d014a4e7 28 #ifndef HTTP_TEXT_H
slowness 0:58c3d014a4e7 29 #define HTTP_TEXT_H
slowness 0:58c3d014a4e7 30
slowness 0:58c3d014a4e7 31 #include "../HTTPData.h"
slowness 0:58c3d014a4e7 32 #include "mbed.h"
slowness 0:58c3d014a4e7 33
slowness 0:58c3d014a4e7 34 #define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems
slowness 0:58c3d014a4e7 35
slowness 0:58c3d014a4e7 36 ///HTTP Client data container for text
slowness 0:58c3d014a4e7 37 /**
slowness 0:58c3d014a4e7 38 This is a simple "Text" data repository for HTTP requests.
slowness 0:58c3d014a4e7 39 */
slowness 0:58c3d014a4e7 40 class HTTPText : public HTTPData //Simple Text I/O
slowness 0:58c3d014a4e7 41 {
slowness 0:58c3d014a4e7 42 public:
slowness 0:58c3d014a4e7 43 ///Instantiates the object.
slowness 0:58c3d014a4e7 44 /**
slowness 0:58c3d014a4e7 45 @param encoding encoding of the data, it defaults to text/html.
slowness 0:58c3d014a4e7 46 @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes.
slowness 0:58c3d014a4e7 47 */
slowness 0:58c3d014a4e7 48 HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC);
slowness 0:58c3d014a4e7 49 virtual ~HTTPText();
slowness 0:58c3d014a4e7 50
slowness 0:58c3d014a4e7 51 ///Gets text
slowness 0:58c3d014a4e7 52 /**
slowness 0:58c3d014a4e7 53 Returns the text in the container as a zero-terminated char*.
slowness 0:58c3d014a4e7 54 The array returned points to the internal buffer of the object and remains owned by the object.
slowness 0:58c3d014a4e7 55 */
slowness 0:58c3d014a4e7 56 const char* gets() const;
slowness 0:58c3d014a4e7 57
slowness 0:58c3d014a4e7 58 //Puts text
slowness 0:58c3d014a4e7 59 /**
slowness 0:58c3d014a4e7 60 Sets the text in the container using a zero-terminated char*.
slowness 0:58c3d014a4e7 61 */
slowness 0:58c3d014a4e7 62 void puts(const char* str);
slowness 0:58c3d014a4e7 63
slowness 0:58c3d014a4e7 64 ///Gets text
slowness 0:58c3d014a4e7 65 /**
slowness 0:58c3d014a4e7 66 Returns the text in the container as string.
slowness 0:58c3d014a4e7 67 */
slowness 0:58c3d014a4e7 68 string& get();
slowness 0:58c3d014a4e7 69
slowness 0:58c3d014a4e7 70 ///Puts text
slowness 0:58c3d014a4e7 71 /**
slowness 0:58c3d014a4e7 72 Sets the text in the container as string.
slowness 0:58c3d014a4e7 73 */
slowness 0:58c3d014a4e7 74 void set(const string& str);
slowness 0:58c3d014a4e7 75
slowness 0:58c3d014a4e7 76 ///Clears the content.
slowness 0:58c3d014a4e7 77 /**
slowness 0:58c3d014a4e7 78 If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request.
slowness 0:58c3d014a4e7 79 */
slowness 0:58c3d014a4e7 80 virtual void clear();
slowness 0:58c3d014a4e7 81
slowness 0:58c3d014a4e7 82 protected:
slowness 0:58c3d014a4e7 83 virtual int read(char* buf, int len);
slowness 0:58c3d014a4e7 84 virtual int write(const char* buf, int len);
slowness 0:58c3d014a4e7 85
slowness 0:58c3d014a4e7 86 virtual string getDataType(); //Internet media type for Content-Type header
slowness 0:58c3d014a4e7 87 virtual void setDataType(const string& type); //Internet media type from Content-Type header
slowness 0:58c3d014a4e7 88
slowness 0:58c3d014a4e7 89 virtual bool getIsChunked(); //For Transfer-Encoding header
slowness 0:58c3d014a4e7 90 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
slowness 0:58c3d014a4e7 91
slowness 0:58c3d014a4e7 92 virtual int getDataLen(); //For Content-Length header
slowness 0:58c3d014a4e7 93 virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length
slowness 0:58c3d014a4e7 94
slowness 0:58c3d014a4e7 95 private:
slowness 0:58c3d014a4e7 96 string m_buf;
slowness 0:58c3d014a4e7 97 string m_encoding;
slowness 0:58c3d014a4e7 98 int m_maxSize;
slowness 0:58c3d014a4e7 99 };
slowness 0:58c3d014a4e7 100
slowness 0:58c3d014a4e7 101 #endif