Dependents:   Lab3Translator lab3_Radio_design Sync WeatherPlatform_20110408 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPMap.h Source File

HTTPMap.h

Go to the documentation of this file.
00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 /** \file
00025 HTTP Map data source/sink header file
00026 */
00027 
00028 #ifndef HTTP_MAP_H
00029 #define HTTP_MAP_H
00030 
00031 #include "../HTTPData.h"
00032 #include "mbed.h"
00033 
00034 #include <map>
00035 using std::map;
00036 
00037 typedef map<string, string> Dictionary;
00038 
00039 ///HTTP Client data container for key/value pairs
00040 /**
00041 This class simplifies the use of key/value pairs requests and responses used widely among web APIs.
00042 Note that HTTPMap inherits from std::map<std::string,std::string>.
00043 You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value.
00044 
00045 The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding.
00046 */
00047 class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs
00048 {
00049 public:
00050   ///Instantiates map
00051   /**
00052   @param keyValueSep Key/Value separator (defaults to "=")
00053   @param pairSep Pairs separator (defaults to "&")
00054   */
00055   HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&");
00056   virtual ~HTTPMap();
00057   
00058  /* string& operator[](const string& key);
00059   int count();*/
00060 
00061   ///Clears the content
00062   virtual void clear();  
00063   
00064 protected:
00065   virtual int read(char* buf, int len);
00066   virtual int write(const char* buf, int len);
00067   
00068   virtual string getDataType(); //Internet media type for Content-Type header
00069   virtual void setDataType(const string& type); //Internet media type from Content-Type header
00070   
00071   virtual bool getIsChunked(); //For Transfer-Encoding header
00072   virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
00073   
00074   virtual int getDataLen(); //For Content-Length header
00075   virtual void setDataLen(int len); //From Content-Length header
00076   
00077 private:
00078   void generateString();
00079   void parseString();
00080   //map<string, string> m_map;
00081   string m_buf;
00082   int m_len;
00083   bool m_chunked;
00084   
00085   string m_keyValueSep;
00086   string m_pairSep;
00087 };
00088 
00089 #endif