Michiel Berckvens / Mbed 2 deprecated ProjectHTTP

Dependencies:   DS1307 TextLCD mbed

Committer:
Michielber
Date:
Thu Dec 04 10:36:40 2014 +0000
Revision:
0:f615d151a72c
Berckvens Michiel & Basteyns Jonas 4/12/2014

Who changed what in which revision?

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