Michael Spencer / Mbed 2 deprecated LaOS

Dependencies:   mbed

Committer:
Michael J. Spencer
Date:
Wed Mar 05 06:14:02 2014 -0800
Revision:
1:f5ac63519541
Initial commit.

Who changed what in which revision?

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