Dependents:   Lab3Translator lab3_Radio_design Sync WeatherPlatform_20110408 ... more

Committer:
mamezu
Date:
Thu Dec 09 01:36:34 2010 +0000
Revision:
0:62fac7f06c8d

        

Who changed what in which revision?

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