Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPMap.h Source File

HTTPMap.h

00001 /* HTTPMap.h */
00002 /*
00003 Copyright (C) 2012 ARM Limited.
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy of
00006 this software and associated documentation files (the "Software"), to deal in
00007 the Software without restriction, including without limitation the rights to
00008 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
00009 of the Software, and to permit persons to whom the Software is furnished to do
00010 so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in all
00013 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 THE
00021 SOFTWARE.
00022 */
00023 
00024 
00025 #ifndef HTTPMAP_H_
00026 #define HTTPMAP_H_
00027 
00028 #include "../IHTTPData.h"
00029 
00030 #define HTTPMAP_TABLE_SIZE 32
00031 
00032 /** Map of key/value pairs
00033  * Used to transmit POST data using the application/x-www-form-urlencoded encoding
00034  */
00035 class HTTPMap: public IHTTPDataOut
00036 {
00037 public:
00038   /**
00039    Instantiates HTTPMap
00040    It supports at most 32 key/values pairs
00041    */
00042   HTTPMap();
00043 
00044   /** Put Key/Value pair
00045    The references to the parameters must remain valid as long as the clear() function is not called
00046    @param key The key to use
00047    @param value The corresponding value
00048    */
00049   void put(const char* key, const char* value);
00050 
00051   /** Clear table
00052    */
00053   void clear();
00054 
00055 protected:
00056   //IHTTPDataIn
00057   virtual int read(char* buf, size_t len, size_t* pReadLen);
00058 
00059   virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
00060 
00061   virtual bool getIsChunked(); //For Transfer-Encoding header
00062 
00063   virtual size_t getDataLen(); //For Content-Length header
00064 
00065 private:
00066   const char* m_keys[HTTPMAP_TABLE_SIZE];
00067   const char* m_values[HTTPMAP_TABLE_SIZE];
00068 
00069   size_t m_pos;
00070   size_t m_count;
00071 };
00072 
00073 #endif /* HTTPMAP_H_ */