MultiIoTBoard library

Dependencies:   BME280 SB1602E

Dependents:   MITB_Sample

Committer:
jksoft
Date:
Fri Jul 28 02:23:25 2017 +0000
Revision:
0:bad9495b4215
First edition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:bad9495b4215 1 /* IHTTPData.h */
jksoft 0:bad9495b4215 2 /* Copyright (C) 2012 mbed.org, MIT License
jksoft 0:bad9495b4215 3 *
jksoft 0:bad9495b4215 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
jksoft 0:bad9495b4215 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
jksoft 0:bad9495b4215 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
jksoft 0:bad9495b4215 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
jksoft 0:bad9495b4215 8 * furnished to do so, subject to the following conditions:
jksoft 0:bad9495b4215 9 *
jksoft 0:bad9495b4215 10 * The above copyright notice and this permission notice shall be included in all copies or
jksoft 0:bad9495b4215 11 * substantial portions of the Software.
jksoft 0:bad9495b4215 12 *
jksoft 0:bad9495b4215 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
jksoft 0:bad9495b4215 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
jksoft 0:bad9495b4215 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
jksoft 0:bad9495b4215 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 0:bad9495b4215 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
jksoft 0:bad9495b4215 18 */
jksoft 0:bad9495b4215 19
jksoft 0:bad9495b4215 20 #ifndef IHTTPDATA_H
jksoft 0:bad9495b4215 21 #define IHTTPDATA_H
jksoft 0:bad9495b4215 22
jksoft 0:bad9495b4215 23 #include <cstring>
jksoft 0:bad9495b4215 24
jksoft 0:bad9495b4215 25 using std::size_t;
jksoft 0:bad9495b4215 26
jksoft 0:bad9495b4215 27 class IHTTPData
jksoft 0:bad9495b4215 28 {
jksoft 0:bad9495b4215 29 protected:
jksoft 0:bad9495b4215 30 /** Get a specific header
jksoft 0:bad9495b4215 31 *
jksoft 0:bad9495b4215 32 */
jksoft 0:bad9495b4215 33 virtual bool getHeader(char* header, size_t maxHeaderLen) { return false; }
jksoft 0:bad9495b4215 34 };
jksoft 0:bad9495b4215 35
jksoft 0:bad9495b4215 36 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
jksoft 0:bad9495b4215 37 class IHTTPDataOut : public IHTTPData
jksoft 0:bad9495b4215 38 {
jksoft 0:bad9495b4215 39 protected:
jksoft 0:bad9495b4215 40 friend class HTTPClient;
jksoft 0:bad9495b4215 41
jksoft 0:bad9495b4215 42 /** Reset stream to its beginning
jksoft 0:bad9495b4215 43 * Called by the HTTPClient on each new request
jksoft 0:bad9495b4215 44 */
jksoft 0:bad9495b4215 45 virtual void readReset() = 0;
jksoft 0:bad9495b4215 46
jksoft 0:bad9495b4215 47 /** Read a piece of data to be transmitted
jksoft 0:bad9495b4215 48 * @param buf Pointer to the buffer on which to copy the data
jksoft 0:bad9495b4215 49 * @param len Length of the buffer
jksoft 0:bad9495b4215 50 * @param pReadLen Pointer to the variable on which the actual copied data length will be stored
jksoft 0:bad9495b4215 51 */
jksoft 0:bad9495b4215 52 virtual int read(char* buf, size_t len, size_t* pReadLen) = 0;
jksoft 0:bad9495b4215 53
jksoft 0:bad9495b4215 54 /** Get MIME type
jksoft 0:bad9495b4215 55 * @param type Internet media type from Content-Type header
jksoft 0:bad9495b4215 56 */
jksoft 0:bad9495b4215 57 virtual int getDataType(char* type, size_t maxTypeLen) = 0; //Internet media type for Content-Type header
jksoft 0:bad9495b4215 58
jksoft 0:bad9495b4215 59 /** Determine whether the HTTP client should chunk the data
jksoft 0:bad9495b4215 60 * Used for Transfer-Encoding header
jksoft 0:bad9495b4215 61 */
jksoft 0:bad9495b4215 62 virtual bool getIsChunked() = 0;
jksoft 0:bad9495b4215 63
jksoft 0:bad9495b4215 64 /** If the data is not chunked, get its size
jksoft 0:bad9495b4215 65 * Used for Content-Length header
jksoft 0:bad9495b4215 66 */
jksoft 0:bad9495b4215 67 virtual size_t getDataLen() = 0;
jksoft 0:bad9495b4215 68
jksoft 0:bad9495b4215 69 };
jksoft 0:bad9495b4215 70
jksoft 0:bad9495b4215 71 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
jksoft 0:bad9495b4215 72 class IHTTPDataIn : public IHTTPData
jksoft 0:bad9495b4215 73 {
jksoft 0:bad9495b4215 74 protected:
jksoft 0:bad9495b4215 75 friend class HTTPClient;
jksoft 0:bad9495b4215 76
jksoft 0:bad9495b4215 77 /** Reset stream to its beginning
jksoft 0:bad9495b4215 78 * Called by the HTTPClient on each new request
jksoft 0:bad9495b4215 79 */
jksoft 0:bad9495b4215 80 virtual void writeReset() = 0;
jksoft 0:bad9495b4215 81
jksoft 0:bad9495b4215 82 /** Write a piece of data transmitted by the server
jksoft 0:bad9495b4215 83 * @param buf Pointer to the buffer from which to copy the data
jksoft 0:bad9495b4215 84 * @param len Length of the buffer
jksoft 0:bad9495b4215 85 */
jksoft 0:bad9495b4215 86 virtual int write(const char* buf, size_t len) = 0;
jksoft 0:bad9495b4215 87
jksoft 0:bad9495b4215 88 /** Set MIME type
jksoft 0:bad9495b4215 89 * @param type Internet media type from Content-Type header
jksoft 0:bad9495b4215 90 */
jksoft 0:bad9495b4215 91 virtual void setDataType(const char* type) = 0;
jksoft 0:bad9495b4215 92
jksoft 0:bad9495b4215 93 /** Determine whether the data is chunked
jksoft 0:bad9495b4215 94 * Recovered from Transfer-Encoding header
jksoft 0:bad9495b4215 95 */
jksoft 0:bad9495b4215 96 virtual void setIsChunked(bool chunked) = 0;
jksoft 0:bad9495b4215 97
jksoft 0:bad9495b4215 98 /** If the data is not chunked, set its size
jksoft 0:bad9495b4215 99 * From Content-Length header
jksoft 0:bad9495b4215 100 */
jksoft 0:bad9495b4215 101 virtual void setDataLen(size_t len) = 0;
jksoft 0:bad9495b4215 102
jksoft 0:bad9495b4215 103 };
jksoft 0:bad9495b4215 104
jksoft 0:bad9495b4215 105 #endif