Oct122012mbedLab

Dependents:   Lab3_VoiceMeter

Fork of HTTPClient by masa haru

Committer:
psawant9
Date:
Fri Oct 12 16:02:09 2012 +0000
Revision:
1:b77740c0a846
Parent:
0:62fac7f06c8d
Done

Who changed what in which revision?

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