Fork of wolfSSL's HTTPClient fork. Fork!

Dependencies:   CyaSSL

Dependents:   exosite_http_example exosite_http_example

Fork of HTTPClient by wolf SSL

Committer:
Patrick Barrett
Date:
Tue Jan 20 14:29:43 2015 -0600
Revision:
34:a34fcee9f204
Parent:
33:bdd333d3939c
missed a couple things

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:2ccb9960a044 1 /* HTTPMap.h */
donatien 10:e1351de84c16 2 /* Copyright (C) 2012 mbed.org, MIT License
donatien 10:e1351de84c16 3 *
donatien 10:e1351de84c16 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 10:e1351de84c16 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
donatien 10:e1351de84c16 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
donatien 10:e1351de84c16 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
donatien 10:e1351de84c16 8 * furnished to do so, subject to the following conditions:
donatien 10:e1351de84c16 9 *
donatien 10:e1351de84c16 10 * The above copyright notice and this permission notice shall be included in all copies or
donatien 10:e1351de84c16 11 * substantial portions of the Software.
donatien 10:e1351de84c16 12 *
donatien 10:e1351de84c16 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 10:e1351de84c16 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 10:e1351de84c16 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 10:e1351de84c16 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 10:e1351de84c16 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 10:e1351de84c16 18 */
donatien 0:2ccb9960a044 19
donatien 0:2ccb9960a044 20
donatien 0:2ccb9960a044 21 #ifndef HTTPMAP_H_
donatien 0:2ccb9960a044 22 #define HTTPMAP_H_
donatien 0:2ccb9960a044 23
donatien 0:2ccb9960a044 24 #include "../IHTTPData.h"
donatien 0:2ccb9960a044 25
donatien 0:2ccb9960a044 26 #define HTTPMAP_TABLE_SIZE 32
donatien 0:2ccb9960a044 27
donatien 0:2ccb9960a044 28 /** Map of key/value pairs
donatien 0:2ccb9960a044 29 * Used to transmit POST data using the application/x-www-form-urlencoded encoding
donatien 0:2ccb9960a044 30 */
Patrick Barrett 33:bdd333d3939c 31 class HTTPMap: public IHTTPDataIn, public IHTTPDataOut
donatien 0:2ccb9960a044 32 {
donatien 0:2ccb9960a044 33 public:
donatien 0:2ccb9960a044 34 /**
donatien 0:2ccb9960a044 35 Instantiates HTTPMap
donatien 0:2ccb9960a044 36 It supports at most 32 key/values pairs
donatien 0:2ccb9960a044 37 */
donatien 0:2ccb9960a044 38 HTTPMap();
donatien 0:2ccb9960a044 39
Patrick Barrett 33:bdd333d3939c 40 /** Create an HTTPMap instance for input
Patrick Barrett 33:bdd333d3939c 41 * @param str Buffer to store the incoming string
Patrick Barrett 33:bdd333d3939c 42 * @param size Size of the buffer
Patrick Barrett 33:bdd333d3939c 43 */
Patrick Barrett 33:bdd333d3939c 44 HTTPMap(char* buf, size_t size);
Patrick Barrett 33:bdd333d3939c 45
donatien 0:2ccb9960a044 46 /** Put Key/Value pair
donatien 0:2ccb9960a044 47 The references to the parameters must remain valid as long as the clear() function is not called
donatien 0:2ccb9960a044 48 @param key The key to use
donatien 0:2ccb9960a044 49 @param value The corresponding value
donatien 0:2ccb9960a044 50 */
donatien 0:2ccb9960a044 51 void put(const char* key, const char* value);
donatien 0:2ccb9960a044 52
Patrick Barrett 33:bdd333d3939c 53 /** Pop one Key/Value pair
Patrick Barrett 33:bdd333d3939c 54 The returned refrences remain valid as long as the original buffer is not modified
Patrick Barrett 33:bdd333d3939c 55 @param key The key
Patrick Barrett 33:bdd333d3939c 56 @param value The corresponding value
Patrick Barrett 33:bdd333d3939c 57 */
Patrick Barrett 33:bdd333d3939c 58 bool pop(char*& key, char*& value);
Patrick Barrett 33:bdd333d3939c 59
Patrick Barrett 33:bdd333d3939c 60 /** Get Value specified in Key
Patrick Barrett 33:bdd333d3939c 61 The value is copied into the provided buffer
Patrick Barrett 33:bdd333d3939c 62 @param key The key of the value to get
Patrick Barrett 33:bdd333d3939c 63 @param val_buf The output buffer into which the value will be copied
Patrick Barrett 33:bdd333d3939c 64 @param max The size of the buffer
Patrick Barrett 33:bdd333d3939c 65 @param len The number of bytes copied into the output buffer
Patrick Barrett 33:bdd333d3939c 66 */
Patrick Barrett 33:bdd333d3939c 67 bool get(const char* key, char* val_buf, const size_t max);
Patrick Barrett 33:bdd333d3939c 68
donatien 0:2ccb9960a044 69 /** Clear table
donatien 0:2ccb9960a044 70 */
donatien 0:2ccb9960a044 71 void clear();
donatien 0:2ccb9960a044 72
donatien 0:2ccb9960a044 73 protected:
Patrick Barrett 33:bdd333d3939c 74 //IHTTPDataOut
donatien 16:1f743885e7de 75 virtual void readReset();
donatien 16:1f743885e7de 76
donatien 0:2ccb9960a044 77 virtual int read(char* buf, size_t len, size_t* pReadLen);
donatien 0:2ccb9960a044 78
donatien 0:2ccb9960a044 79 virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
donatien 0:2ccb9960a044 80
donatien 0:2ccb9960a044 81 virtual bool getIsChunked(); //For Transfer-Encoding header
donatien 0:2ccb9960a044 82
donatien 0:2ccb9960a044 83 virtual size_t getDataLen(); //For Content-Length header
donatien 0:2ccb9960a044 84
Patrick Barrett 33:bdd333d3939c 85 //IHTTPDataIn
Patrick Barrett 33:bdd333d3939c 86 virtual void writeReset();
Patrick Barrett 33:bdd333d3939c 87
Patrick Barrett 33:bdd333d3939c 88 virtual int write(const char* buf, size_t len);
Patrick Barrett 33:bdd333d3939c 89
Patrick Barrett 33:bdd333d3939c 90 virtual void setDataType(const char* type); //Internet media type from Content-Type header
Patrick Barrett 33:bdd333d3939c 91
Patrick Barrett 33:bdd333d3939c 92 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
Patrick Barrett 33:bdd333d3939c 93
Patrick Barrett 33:bdd333d3939c 94 virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
Patrick Barrett 33:bdd333d3939c 95
donatien 0:2ccb9960a044 96 private:
donatien 0:2ccb9960a044 97 const char* m_keys[HTTPMAP_TABLE_SIZE];
donatien 0:2ccb9960a044 98 const char* m_values[HTTPMAP_TABLE_SIZE];
Patrick Barrett 33:bdd333d3939c 99
Patrick Barrett 33:bdd333d3939c 100 char* m_str;
Patrick Barrett 33:bdd333d3939c 101 size_t m_size;
donatien 0:2ccb9960a044 102
donatien 0:2ccb9960a044 103 size_t m_pos;
donatien 0:2ccb9960a044 104 size_t m_count;
Patrick Barrett 33:bdd333d3939c 105
Patrick Barrett 33:bdd333d3939c 106 size_t m_read_pos;
donatien 0:2ccb9960a044 107 };
donatien 0:2ccb9960a044 108
donatien 0:2ccb9960a044 109 #endif /* HTTPMAP_H_ */