Dependencies:   mbed

Dependents:   TCP

Committer:
slowness
Date:
Tue Sep 06 18:05:46 2011 +0000
Revision:
0:58c3d014a4e7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
slowness 0:58c3d014a4e7 1
slowness 0:58c3d014a4e7 2 /*
slowness 0:58c3d014a4e7 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
slowness 0:58c3d014a4e7 4
slowness 0:58c3d014a4e7 5 Permission is hereby granted, free of charge, to any person obtaining a copy
slowness 0:58c3d014a4e7 6 of this software and associated documentation files (the "Software"), to deal
slowness 0:58c3d014a4e7 7 in the Software without restriction, including without limitation the rights
slowness 0:58c3d014a4e7 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
slowness 0:58c3d014a4e7 9 copies of the Software, and to permit persons to whom the Software is
slowness 0:58c3d014a4e7 10 furnished to do so, subject to the following conditions:
slowness 0:58c3d014a4e7 11
slowness 0:58c3d014a4e7 12 The above copyright notice and this permission notice shall be included in
slowness 0:58c3d014a4e7 13 all copies or substantial portions of the Software.
slowness 0:58c3d014a4e7 14
slowness 0:58c3d014a4e7 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
slowness 0:58c3d014a4e7 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
slowness 0:58c3d014a4e7 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
slowness 0:58c3d014a4e7 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
slowness 0:58c3d014a4e7 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
slowness 0:58c3d014a4e7 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
slowness 0:58c3d014a4e7 21 THE SOFTWARE.
slowness 0:58c3d014a4e7 22 */
slowness 0:58c3d014a4e7 23
slowness 0:58c3d014a4e7 24 /** \file
slowness 0:58c3d014a4e7 25 HTTP Map data source/sink header file
slowness 0:58c3d014a4e7 26 */
slowness 0:58c3d014a4e7 27
slowness 0:58c3d014a4e7 28 #ifndef HTTP_MAP_H
slowness 0:58c3d014a4e7 29 #define HTTP_MAP_H
slowness 0:58c3d014a4e7 30
slowness 0:58c3d014a4e7 31 #include "../HTTPData.h"
slowness 0:58c3d014a4e7 32 #include "mbed.h"
slowness 0:58c3d014a4e7 33
slowness 0:58c3d014a4e7 34 #include <map>
slowness 0:58c3d014a4e7 35 using std::map;
slowness 0:58c3d014a4e7 36
slowness 0:58c3d014a4e7 37 typedef map<string, string> Dictionary;
slowness 0:58c3d014a4e7 38
slowness 0:58c3d014a4e7 39 ///HTTP Client data container for key/value pairs
slowness 0:58c3d014a4e7 40 /**
slowness 0:58c3d014a4e7 41 This class simplifies the use of key/value pairs requests and responses used widely among web APIs.
slowness 0:58c3d014a4e7 42 Note that HTTPMap inherits from std::map<std::string,std::string>.
slowness 0:58c3d014a4e7 43 You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value.
slowness 0:58c3d014a4e7 44
slowness 0:58c3d014a4e7 45 The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding.
slowness 0:58c3d014a4e7 46 */
slowness 0:58c3d014a4e7 47 class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs
slowness 0:58c3d014a4e7 48 {
slowness 0:58c3d014a4e7 49 public:
slowness 0:58c3d014a4e7 50 ///Instantiates map
slowness 0:58c3d014a4e7 51 /**
slowness 0:58c3d014a4e7 52 @param keyValueSep Key/Value separator (defaults to "=")
slowness 0:58c3d014a4e7 53 @param pairSep Pairs separator (defaults to "&")
slowness 0:58c3d014a4e7 54 */
slowness 0:58c3d014a4e7 55 HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&");
slowness 0:58c3d014a4e7 56 virtual ~HTTPMap();
slowness 0:58c3d014a4e7 57
slowness 0:58c3d014a4e7 58 /* string& operator[](const string& key);
slowness 0:58c3d014a4e7 59 int count();*/
slowness 0:58c3d014a4e7 60
slowness 0:58c3d014a4e7 61 ///Clears the content
slowness 0:58c3d014a4e7 62 virtual void clear();
slowness 0:58c3d014a4e7 63
slowness 0:58c3d014a4e7 64 protected:
slowness 0:58c3d014a4e7 65 virtual int read(char* buf, int len);
slowness 0:58c3d014a4e7 66 virtual int write(const char* buf, int len);
slowness 0:58c3d014a4e7 67
slowness 0:58c3d014a4e7 68 virtual string getDataType(); //Internet media type for Content-Type header
slowness 0:58c3d014a4e7 69 virtual void setDataType(const string& type); //Internet media type from Content-Type header
slowness 0:58c3d014a4e7 70
slowness 0:58c3d014a4e7 71 virtual bool getIsChunked(); //For Transfer-Encoding header
slowness 0:58c3d014a4e7 72 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
slowness 0:58c3d014a4e7 73
slowness 0:58c3d014a4e7 74 virtual int getDataLen(); //For Content-Length header
slowness 0:58c3d014a4e7 75 virtual void setDataLen(int len); //From Content-Length header
slowness 0:58c3d014a4e7 76
slowness 0:58c3d014a4e7 77 private:
slowness 0:58c3d014a4e7 78 void generateString();
slowness 0:58c3d014a4e7 79 void parseString();
slowness 0:58c3d014a4e7 80 //map<string, string> m_map;
slowness 0:58c3d014a4e7 81 string m_buf;
slowness 0:58c3d014a4e7 82 int m_len;
slowness 0:58c3d014a4e7 83 bool m_chunked;
slowness 0:58c3d014a4e7 84
slowness 0:58c3d014a4e7 85 string m_keyValueSep;
slowness 0:58c3d014a4e7 86 string m_pairSep;
slowness 0:58c3d014a4e7 87 };
slowness 0:58c3d014a4e7 88
slowness 0:58c3d014a4e7 89 #endif