Oct122012mbedLab
Fork of HTTPClient by
Revision 1:b77740c0a846, committed 2012-10-12
- Comitter:
- psawant9
- Date:
- Fri Oct 12 16:02:09 2012 +0000
- Parent:
- 0:62fac7f06c8d
- Commit message:
- Done
Changed in this revision
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/dbg/dbg.h --- a/LPC1768/dbg/dbg.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/dbg/dbg.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,94 +1,94 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -Debugging helpers header file -*/ - -//#ifdef DBG_H -//#define DBG_H - -#ifdef __LWIP_DEBUG -#define __DEBUG -#endif - -/*! - \def __DEBUG - To define to enable debugging in one file -*/ - -#ifdef __DEBUG - -#ifndef __DEBUGSTREAM -#define __DEBUGSTREAM - - -class DebugStream -{ -public: -static void debug(const char* format, ...); -static void release(); -static void breakPoint(const char* file, int line); -private: - -}; - -#undef DBG -#undef DBG_END -#undef BREAK - -///Debug output (if enabled), same syntax as printf, with heading info -#define DBG(...) do{ DebugStream::debug("[%s:%s@%d] ", __FILE__, __FUNCTION__, __LINE__); DebugStream::debug(__VA_ARGS__); } while(0); - -///Debug output (if enabled), same syntax as printf, no heading info -#define DBGL(...) do{ DebugStream::debug(__VA_ARGS__); } while(0); -#define DBG_END DebugStream::release - -///Break point usin serial debug interface (if debug enbaled) -#define BREAK() DebugStream::breakPoint(__FILE__, __LINE__) -#endif - -#else -#undef DBG -#undef DBG_END -#undef BREAK -#define DBG(...) -#define DBG_END() -#define BREAK() -#endif - -#ifdef __LWIP_DEBUG -#ifndef __SNPRINTF -#define __SNPRINTF -#include "mbed.h" - -//int snprintf(char *str, int size, const char *format, ...); -#endif -#endif - -#ifdef __LWIP_DEBUG -#undef __DEBUG -#endif - -//#endif - + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +Debugging helpers header file +*/ + +//#ifdef DBG_H +//#define DBG_H + +#ifdef __LWIP_DEBUG +#define __DEBUG +#endif + +/*! + \def __DEBUG + To define to enable debugging in one file +*/ + +#ifdef __DEBUG + +#ifndef __DEBUGSTREAM +#define __DEBUGSTREAM + + +class DebugStream +{ +public: +static void debug(const char* format, ...); +static void release(); +static void breakPoint(const char* file, int line); +private: + +}; + +#undef DBG +#undef DBG_END +#undef BREAK + +///Debug output (if enabled), same syntax as printf, with heading info +#define DBG(...) do{ DebugStream::debug("[%s:%s@%d] ", __FILE__, __FUNCTION__, __LINE__); DebugStream::debug(__VA_ARGS__); } while(0); + +///Debug output (if enabled), same syntax as printf, no heading info +#define DBGL(...) do{ DebugStream::debug(__VA_ARGS__); } while(0); +#define DBG_END DebugStream::release + +///Break point usin serial debug interface (if debug enbaled) +#define BREAK() DebugStream::breakPoint(__FILE__, __LINE__) +#endif + +#else +#undef DBG +#undef DBG_END +#undef BREAK +#define DBG(...) +#define DBG_END() +#define BREAK() +#endif + +#ifdef __LWIP_DEBUG +#ifndef __SNPRINTF +#define __SNPRINTF +#include "mbed.h" + +//int snprintf(char *str, int size, const char *format, ...); +#endif +#endif + +#ifdef __LWIP_DEBUG +#undef __DEBUG +#endif + +//#endif +
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/client/HTTPClient.h --- a/LPC1768/services/http/client/HTTPClient.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/client/HTTPClient.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,306 +1,306 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP Client header file -*/ - -#ifndef HTTP_CLIENT_H -#define HTTP_CLIENT_H - -class HTTPData; - -#include "core/net.h" -#include "api/TCPSocket.h" -#include "api/DNSRequest.h" -#include "HTTPData.h" -#include "mbed.h" - -#include <string> -using std::string; - -#include <map> -using std::map; - -///HTTP client results -enum HTTPResult -{ - HTTP_OK, ///<Success - HTTP_PROCESSING, ///<Processing - HTTP_PARSE, ///<URI Parse error - HTTP_DNS, ///<Could not resolve name - HTTP_PRTCL, ///<Protocol error - HTTP_NOTFOUND, ///<HTTP 404 Error - HTTP_REFUSED, ///<HTTP 403 Error - HTTP_ERROR, ///<HTTP xxx error - HTTP_TIMEOUT, ///<Connection timeout - HTTP_CONN ///<Connection error -}; - -#include "core/netservice.h" - -///A simple HTTP Client -/** -The HTTPClient is composed of: -- The actual client (HTTPClient) -- Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes) -*/ -class HTTPClient : protected NetService -{ -public: - ///Instantiates the HTTP client - HTTPClient(); - virtual ~HTTPClient(); - - ///Provides a basic authentification feature (Base64 encoded username and password) - void basicAuth(const char* user, const char* password); //Basic Authentification - - //High Level setup functions - ///Executes a GET Request (blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - Blocks until completion - */ - HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking - - ///Executes a GET Request (non blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pMethod : callback function - The function returns immediately and calls the callback on completion or error - */ - HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking - - ///Executes a GET Request (non blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pItem : instance of class on which to execute the callback method - @param pMethod : callback method - The function returns immediately and calls the callback on completion or error - */ - template<class T> - HTTPResult get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking - { - setOnResult(pItem, pMethod); - doGet(uri, pDataIn); - return HTTP_PROCESSING; - } - - ///Executes a POST Request (blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - Blocks until completion - */ - HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking - - ///Executes a POST Request (non blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pMethod : callback function - The function returns immediately and calls the callback on completion or error - */ - HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking - - ///Executes a POST Request (non blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pItem : instance of class on which to execute the callback method - @param pMethod : callback method - The function returns immediately and calls the callback on completion or error - */ - template<class T> - HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking - { - setOnResult(pItem, pMethod); - doPost(uri, dataOut, pDataIn); - return HTTP_PROCESSING; - } - - ///Executes a GET Request (non blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - The function returns immediately and calls the previously set callback on completion or error - */ - void doGet(const char* uri, HTTPData* pDataIn); - - ///Executes a POST Request (non blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pMethod : callback function - The function returns immediately and calls the previously set callback on completion or error - */ - void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); - - ///Setups the result callback - /** - @param pMethod : callback function - */ - void setOnResult( void (*pMethod)(HTTPResult) ); - - ///Setups the result callback - /** - @param pItem : instance of class on which to execute the callback method - @param pMethod : callback method - */ - class CDummy; - template<class T> - void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) ) - { - m_pCb = NULL; - m_pCbItem = (CDummy*) pItem; - m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod; - } - - ///Setups timeout - /** - @param ms : time of connection inactivity in ms after which the request should timeout - */ - void setTimeout(int ms); - - virtual void poll(); //Called by NetServices - - ///Gets last request's HTTP response code - /** - @return The HTTP response code of the last request - */ - int getHTTPResponseCode(); - - ///Sets a specific request header - void setRequestHeader(const string& header, const string& value); - - ///Gets a response header - string& getResponseHeader(const string& header); - - ///Clears request headers - void resetRequestHeaders(); - -protected: - void resetTimeout(); - - void init(); - void close(); - - void setup(const char* uri, HTTPData* pDataOut, HTTPData* pDataIn); //Setup request, make DNS Req if necessary - void connect(); //Start Connection - - int tryRead(); //Read data and try to feed output - void readData(); //Data has been read - void writeData(); //Data has been written & buf is free - - void onTCPSocketEvent(TCPSocketEvent e); - void onDNSReply(DNSReply r); - void onResult(HTTPResult r); //Called when exchange completed or on failure - void onTimeout(); //Connection has timed out - -private: - HTTPResult blockingProcess(); //Called in blocking mode, calls Net::poll() until return code is available - - bool readHeaders(); //Called first when receiving data - bool writeHeaders(); //Called to create req - int readLine(char* str, int maxLen, bool* pIncomplete = NULL); - - enum HTTP_METH - { - HTTP_GET, - HTTP_POST, - HTTP_HEAD - }; - - HTTP_METH m_meth; - - CDummy* m_pCbItem; - void (CDummy::*m_pCbMeth)(HTTPResult); - - void (*m_pCb)(HTTPResult); - - TCPSocket* m_pTCPSocket; - map<string, string> m_reqHeaders; - map<string, string> m_respHeaders; - - Timer m_watchdog; - int m_timeout; - - DNSRequest* m_pDnsReq; - - Host m_server; - string m_path; - - bool m_closed; - - enum HTTPStep - { - // HTTP_INIT, - HTTP_WRITE_HEADERS, - HTTP_WRITE_DATA, - HTTP_READ_HEADERS, - HTTP_READ_DATA, - HTTP_READ_DATA_INCOMPLETE, - HTTP_DONE, - HTTP_CLOSED - }; - - HTTPStep m_state; - - HTTPData* m_pDataOut; - HTTPData* m_pDataIn; - - bool m_dataChunked; //Data is encoded as chunks - int m_dataPos; //Position in data - int m_dataLen; //Data length - char* m_buf; - char* m_pBufRemaining; //Remaining - int m_bufRemainingLen; //Data length in m_pBufRemaining - - int m_httpResponseCode; - - HTTPResult m_blockingResult; //Result if blocking mode - -}; - -//Including data containers here for more convenience -#include "data/HTTPFile.h" -#include "data/HTTPStream.h" -#include "data/HTTPText.h" -#include "data/HTTPMap.h" - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP Client header file +*/ + +#ifndef HTTP_CLIENT_H +#define HTTP_CLIENT_H + +class HTTPData; + +#include "core/net.h" +#include "api/TCPSocket.h" +#include "api/DNSRequest.h" +#include "HTTPData.h" +#include "mbed.h" + +#include <string> +using std::string; + +#include <map> +using std::map; + +///HTTP client results +enum HTTPResult +{ + HTTP_OK, ///<Success + HTTP_PROCESSING, ///<Processing + HTTP_PARSE, ///<URI Parse error + HTTP_DNS, ///<Could not resolve name + HTTP_PRTCL, ///<Protocol error + HTTP_NOTFOUND, ///<HTTP 404 Error + HTTP_REFUSED, ///<HTTP 403 Error + HTTP_ERROR, ///<HTTP xxx error + HTTP_TIMEOUT, ///<Connection timeout + HTTP_CONN ///<Connection error +}; + +#include "core/netservice.h" + +///A simple HTTP Client +/** +The HTTPClient is composed of: +- The actual client (HTTPClient) +- Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes) +*/ +class HTTPClient : protected NetService +{ +public: + ///Instantiates the HTTP client + HTTPClient(); + virtual ~HTTPClient(); + + ///Provides a basic authentification feature (Base64 encoded username and password) + void basicAuth(const char* user, const char* password); //Basic Authentification + + //High Level setup functions + ///Executes a GET Request (blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + Blocks until completion + */ + HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking + + ///Executes a GET Request (non blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pMethod : callback function + The function returns immediately and calls the callback on completion or error + */ + HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking + + ///Executes a GET Request (non blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pItem : instance of class on which to execute the callback method + @param pMethod : callback method + The function returns immediately and calls the callback on completion or error + */ + template<class T> + HTTPResult get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking + { + setOnResult(pItem, pMethod); + doGet(uri, pDataIn); + return HTTP_PROCESSING; + } + + ///Executes a POST Request (blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + Blocks until completion + */ + HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking + + ///Executes a POST Request (non blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pMethod : callback function + The function returns immediately and calls the callback on completion or error + */ + HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking + + ///Executes a POST Request (non blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pItem : instance of class on which to execute the callback method + @param pMethod : callback method + The function returns immediately and calls the callback on completion or error + */ + template<class T> + HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking + { + setOnResult(pItem, pMethod); + doPost(uri, dataOut, pDataIn); + return HTTP_PROCESSING; + } + + ///Executes a GET Request (non blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + The function returns immediately and calls the previously set callback on completion or error + */ + void doGet(const char* uri, HTTPData* pDataIn); + + ///Executes a POST Request (non blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pMethod : callback function + The function returns immediately and calls the previously set callback on completion or error + */ + void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); + + ///Setups the result callback + /** + @param pMethod : callback function + */ + void setOnResult( void (*pMethod)(HTTPResult) ); + + ///Setups the result callback + /** + @param pItem : instance of class on which to execute the callback method + @param pMethod : callback method + */ + class CDummy; + template<class T> + void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) ) + { + m_pCb = NULL; + m_pCbItem = (CDummy*) pItem; + m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod; + } + + ///Setups timeout + /** + @param ms : time of connection inactivity in ms after which the request should timeout + */ + void setTimeout(int ms); + + virtual void poll(); //Called by NetServices + + ///Gets last request's HTTP response code + /** + @return The HTTP response code of the last request + */ + int getHTTPResponseCode(); + + ///Sets a specific request header + void setRequestHeader(const string& header, const string& value); + + ///Gets a response header + string& getResponseHeader(const string& header); + + ///Clears request headers + void resetRequestHeaders(); + +protected: + void resetTimeout(); + + void init(); + void close(); + + void setup(const char* uri, HTTPData* pDataOut, HTTPData* pDataIn); //Setup request, make DNS Req if necessary + void connect(); //Start Connection + + int tryRead(); //Read data and try to feed output + void readData(); //Data has been read + void writeData(); //Data has been written & buf is free + + void onTCPSocketEvent(TCPSocketEvent e); + void onDNSReply(DNSReply r); + void onResult(HTTPResult r); //Called when exchange completed or on failure + void onTimeout(); //Connection has timed out + +private: + HTTPResult blockingProcess(); //Called in blocking mode, calls Net::poll() until return code is available + + bool readHeaders(); //Called first when receiving data + bool writeHeaders(); //Called to create req + int readLine(char* str, int maxLen, bool* pIncomplete = NULL); + + enum HTTP_METH + { + HTTP_GET, + HTTP_POST, + HTTP_HEAD + }; + + HTTP_METH m_meth; + + CDummy* m_pCbItem; + void (CDummy::*m_pCbMeth)(HTTPResult); + + void (*m_pCb)(HTTPResult); + + TCPSocket* m_pTCPSocket; + map<string, string> m_reqHeaders; + map<string, string> m_respHeaders; + + Timer m_watchdog; + int m_timeout; + + DNSRequest* m_pDnsReq; + + Host m_server; + string m_path; + + bool m_closed; + + enum HTTPStep + { + // HTTP_INIT, + HTTP_WRITE_HEADERS, + HTTP_WRITE_DATA, + HTTP_READ_HEADERS, + HTTP_READ_DATA, + HTTP_READ_DATA_INCOMPLETE, + HTTP_DONE, + HTTP_CLOSED + }; + + HTTPStep m_state; + + HTTPData* m_pDataOut; + HTTPData* m_pDataIn; + + bool m_dataChunked; //Data is encoded as chunks + int m_dataPos; //Position in data + int m_dataLen; //Data length + char* m_buf; + char* m_pBufRemaining; //Remaining + int m_bufRemainingLen; //Data length in m_pBufRemaining + + int m_httpResponseCode; + + HTTPResult m_blockingResult; //Result if blocking mode + +}; + +//Including data containers here for more convenience +#include "data/HTTPFile.h" +#include "data/HTTPStream.h" +#include "data/HTTPText.h" +#include "data/HTTPMap.h" + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/client/HTTPData.h --- a/LPC1768/services/http/client/HTTPData.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/client/HTTPData.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,58 +1,58 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef HTTP_DATA_H -#define HTTP_DATA_H - -#include "core/net.h" - -#include <string> -using std::string; - -class HTTPData //This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...) -{ -public: - HTTPData(); - virtual ~HTTPData(); - - virtual void clear() = 0; - -protected: - friend class HTTPClient; - virtual int read(char* buf, int len) = 0; - virtual int write(const char* buf, int len) = 0; - - virtual string getDataType() = 0; //Internet media type for Content-Type header - virtual void setDataType(const string& type) = 0; //Internet media type from Content-Type header - - virtual bool getIsChunked() = 0; //For Transfer-Encoding header - virtual void setIsChunked(bool chunked) = 0; //From Transfer-Encoding header - - virtual int getDataLen() = 0; //For Content-Length header - virtual void setDataLen(int len) = 0; //From Content-Length header, or if the transfer is chunked, next chunk length - -private: - -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HTTP_DATA_H +#define HTTP_DATA_H + +#include "core/net.h" + +#include <string> +using std::string; + +class HTTPData //This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...) +{ +public: + HTTPData(); + virtual ~HTTPData(); + + virtual void clear() = 0; + +protected: + friend class HTTPClient; + virtual int read(char* buf, int len) = 0; + virtual int write(const char* buf, int len) = 0; + + virtual string getDataType() = 0; //Internet media type for Content-Type header + virtual void setDataType(const string& type) = 0; //Internet media type from Content-Type header + + virtual bool getIsChunked() = 0; //For Transfer-Encoding header + virtual void setIsChunked(bool chunked) = 0; //From Transfer-Encoding header + + virtual int getDataLen() = 0; //For Content-Length header + virtual void setDataLen(int len) = 0; //From Content-Length header, or if the transfer is chunked, next chunk length + +private: + +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/client/data/HTTPFile.h --- a/LPC1768/services/http/client/data/HTTPFile.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/client/data/HTTPFile.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,81 +1,81 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP File data source/sink header file -*/ - -#ifndef HTTP_FILE_H -#define HTTP_FILE_H - -#include "../HTTPData.h" -#include "mbed.h" - -///HTTP Client data container for files -/** -This class provides file access/storage for HTTP requests and responses' data payloads. - - -*/ -class HTTPFile : public HTTPData //Read or Write data from a file -{ -public: - ///Instantiates data source/sink with file in param. - /** - Uses file at path @a path. - It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance. - Note that the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing. - - @note - Note that to use this you must instantiate a proper file system (such as the LocalFileSystem or the SDFileSystem). - */ - HTTPFile(const char* path); - virtual ~HTTPFile(); - - ///Forces file closure - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header virtual - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header - -private: - bool openFile(const char* mode); //true on success, false otherwise - void closeFile(); - - FILE* m_fp; - string m_path; - int m_len; - bool m_chunked; -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP File data source/sink header file +*/ + +#ifndef HTTP_FILE_H +#define HTTP_FILE_H + +#include "../HTTPData.h" +#include "mbed.h" + +///HTTP Client data container for files +/** +This class provides file access/storage for HTTP requests and responses' data payloads. + + +*/ +class HTTPFile : public HTTPData //Read or Write data from a file +{ +public: + ///Instantiates data source/sink with file in param. + /** + Uses file at path @a path. + It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance. + Note that the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing. + + @note + Note that to use this you must instantiate a proper file system (such as the LocalFileSystem or the SDFileSystem). + */ + HTTPFile(const char* path); + virtual ~HTTPFile(); + + ///Forces file closure + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header virtual + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header + +private: + bool openFile(const char* mode); //true on success, false otherwise + void closeFile(); + + FILE* m_fp; + string m_path; + int m_len; + bool m_chunked; +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/client/data/HTTPMap.h --- a/LPC1768/services/http/client/data/HTTPMap.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/client/data/HTTPMap.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,89 +1,89 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP Map data source/sink header file -*/ - -#ifndef HTTP_MAP_H -#define HTTP_MAP_H - -#include "../HTTPData.h" -#include "mbed.h" - -#include <map> -using std::map; - -typedef map<string, string> Dictionary; - -///HTTP Client data container for key/value pairs -/** -This class simplifies the use of key/value pairs requests and responses used widely among web APIs. -Note that HTTPMap inherits from std::map<std::string,std::string>. -You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value. - -The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding. -*/ -class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs -{ -public: - ///Instantiates map - /** - @param keyValueSep Key/Value separator (defaults to "=") - @param pairSep Pairs separator (defaults to "&") - */ - HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&"); - virtual ~HTTPMap(); - - /* string& operator[](const string& key); - int count();*/ - - ///Clears the content - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header - -private: - void generateString(); - void parseString(); - //map<string, string> m_map; - string m_buf; - int m_len; - bool m_chunked; - - string m_keyValueSep; - string m_pairSep; -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP Map data source/sink header file +*/ + +#ifndef HTTP_MAP_H +#define HTTP_MAP_H + +#include "../HTTPData.h" +#include "mbed.h" + +#include <map> +using std::map; + +typedef map<string, string> Dictionary; + +///HTTP Client data container for key/value pairs +/** +This class simplifies the use of key/value pairs requests and responses used widely among web APIs. +Note that HTTPMap inherits from std::map<std::string,std::string>. +You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value. + +The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding. +*/ +class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs +{ +public: + ///Instantiates map + /** + @param keyValueSep Key/Value separator (defaults to "=") + @param pairSep Pairs separator (defaults to "&") + */ + HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&"); + virtual ~HTTPMap(); + + /* string& operator[](const string& key); + int count();*/ + + ///Clears the content + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header + +private: + void generateString(); + void parseString(); + //map<string, string> m_map; + string m_buf; + int m_len; + bool m_chunked; + + string m_keyValueSep; + string m_pairSep; +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/client/data/HTTPStream.h --- a/LPC1768/services/http/client/data/HTTPStream.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/client/data/HTTPStream.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,83 +1,83 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef HTTP_STREAM_H -#define HTTP_STREAM_H - -#include "../HTTPData.h" -#include "mbed.h" - -/** \file -HTTP Stream data source/sink header file -*/ - -typedef uint8_t byte; - -///HTTP Client Streaming tool -/** -This class allows you to stream data from the web using a persisting HTTP connection. -To use it properly you must use a non-blocking HTTPClient method. -*/ -class HTTPStream : public HTTPData //Streaming buf -{ -public: - ///Instantiates the object - HTTPStream(); - virtual ~HTTPStream(); - - ///Starts to read into buffer - /** - Passes a buffer of address @a buf and size @a size to the instance. - When it receives data it will be stored in this buffer. - When the buffer is full it throttles the client until this function is called again. - */ - void readNext(byte* buf, int size); - - ///Returns whether there is data available to read - bool readable(); - - ///Returns the actual length of the payload written in the buffer - int readLen(); - - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length - -private: - byte* m_buf; - int m_size; //Capacity - int m_len; //Length -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HTTP_STREAM_H +#define HTTP_STREAM_H + +#include "../HTTPData.h" +#include "mbed.h" + +/** \file +HTTP Stream data source/sink header file +*/ + +typedef uint8_t byte; + +///HTTP Client Streaming tool +/** +This class allows you to stream data from the web using a persisting HTTP connection. +To use it properly you must use a non-blocking HTTPClient method. +*/ +class HTTPStream : public HTTPData //Streaming buf +{ +public: + ///Instantiates the object + HTTPStream(); + virtual ~HTTPStream(); + + ///Starts to read into buffer + /** + Passes a buffer of address @a buf and size @a size to the instance. + When it receives data it will be stored in this buffer. + When the buffer is full it throttles the client until this function is called again. + */ + void readNext(byte* buf, int size); + + ///Returns whether there is data available to read + bool readable(); + + ///Returns the actual length of the payload written in the buffer + int readLen(); + + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length + +private: + byte* m_buf; + int m_size; //Capacity + int m_len; //Length +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/client/data/HTTPText.h --- a/LPC1768/services/http/client/data/HTTPText.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/client/data/HTTPText.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,101 +1,101 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP Text data source/sink header file -*/ - -#ifndef HTTP_TEXT_H -#define HTTP_TEXT_H - -#include "../HTTPData.h" -#include "mbed.h" - -#define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems - -///HTTP Client data container for text -/** -This is a simple "Text" data repository for HTTP requests. -*/ -class HTTPText : public HTTPData //Simple Text I/O -{ -public: - ///Instantiates the object. - /** - @param encoding encoding of the data, it defaults to text/html. - @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes. - */ - HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC); - virtual ~HTTPText(); - - ///Gets text - /** - Returns the text in the container as a zero-terminated char*. - The array returned points to the internal buffer of the object and remains owned by the object. - */ - const char* gets() const; - - //Puts text - /** - Sets the text in the container using a zero-terminated char*. - */ - void puts(const char* str); - - ///Gets text - /** - Returns the text in the container as string. - */ - string& get(); - - ///Puts text - /** - Sets the text in the container as string. - */ - void set(const string& str); - - ///Clears the content. - /** - If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request. - */ - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length - -private: - string m_buf; - string m_encoding; - int m_maxSize; -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP Text data source/sink header file +*/ + +#ifndef HTTP_TEXT_H +#define HTTP_TEXT_H + +#include "../HTTPData.h" +#include "mbed.h" + +#define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems + +///HTTP Client data container for text +/** +This is a simple "Text" data repository for HTTP requests. +*/ +class HTTPText : public HTTPData //Simple Text I/O +{ +public: + ///Instantiates the object. + /** + @param encoding encoding of the data, it defaults to text/html. + @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes. + */ + HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC); + virtual ~HTTPText(); + + ///Gets text + /** + Returns the text in the container as a zero-terminated char*. + The array returned points to the internal buffer of the object and remains owned by the object. + */ + const char* gets() const; + + //Puts text + /** + Sets the text in the container using a zero-terminated char*. + */ + void puts(const char* str); + + ///Gets text + /** + Returns the text in the container as string. + */ + string& get(); + + ///Puts text + /** + Sets the text in the container as string. + */ + void set(const string& str); + + ///Clears the content. + /** + If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request. + */ + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length + +private: + string m_buf; + string m_encoding; + int m_maxSize; +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/util/base64.h --- a/LPC1768/services/http/util/base64.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/util/base64.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,57 +1,57 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef BASE64_H -#define BASE64_H - -#include <string> -using std::string; - -#ifdef __cplusplus -extern "C" { -#endif - -//Originaly from Rolf's iputil.h - -unsigned int base64enc_len(const char *str); - -void base64enc(const char *input, unsigned int length, char *output); - -#ifdef __cplusplus -} -#endif - -class Base64 -{ -public: - static string encode(const string& str) - { - char* out = new char[ base64enc_len(str.c_str()) ]; - base64enc(str.c_str(), str.length(), out); - string res(out); - delete[] out; - return res; - } -}; - -#endif /* LWIP_UTILS_H */ + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef BASE64_H +#define BASE64_H + +#include <string> +using std::string; + +#ifdef __cplusplus +extern "C" { +#endif + +//Originaly from Rolf's iputil.h + +unsigned int base64enc_len(const char *str); + +void base64enc(const char *input, unsigned int length, char *output); + +#ifdef __cplusplus +} +#endif + +class Base64 +{ +public: + static string encode(const string& str) + { + char* out = new char[ base64enc_len(str.c_str()) ]; + base64enc(str.c_str(), str.length(), out); + string res(out); + delete[] out; + return res; + } +}; + +#endif /* LWIP_UTILS_H */
diff -r 62fac7f06c8d -r b77740c0a846 LPC1768/services/http/util/url.h --- a/LPC1768/services/http/util/url.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC1768/services/http/util/url.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,88 +1,88 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef URL_H -#define URL_H - -#include "core/ipaddr.h" - -#include <string> -using std::string; - -#include "mbed.h" - -#ifdef __cplusplus -extern "C" { -#endif - -char *url_encode(char *str); -char *url_decode(char *str); - -#ifdef __cplusplus -} -#endif - -class Url -{ -public: - static string encode(const string& url) - { - char* c_res = url_encode( (char*) url.c_str() ); - string res(c_res); - free(c_res); //Alloc'ed in url_encode() - return res; - } - - static string decode(const string& url) - { - char* c_res = url_decode( (char*) url.c_str() ); - string res(c_res); - free(c_res); //Alloc'ed in url_decode() - return res; - } - - Url(); - - string getProtocol(); - string getHost(); - bool getHostIp(IpAddr* ip); //If host is in IP form, return true & proper object by ptr - uint16_t getPort(); - string getPath(); - - void setProtocol(string protocol); - void setHost(string host); - void setPort(uint16_t port); - void setPath(string path); - - void fromString(string str); - string toString(); - -private: - string m_protocol; - string m_host; - uint16_t m_port; - string m_path; - -}; - -#endif /* LWIP_UTILS_H */ + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef URL_H +#define URL_H + +#include "core/ipaddr.h" + +#include <string> +using std::string; + +#include "mbed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +char *url_encode(char *str); +char *url_decode(char *str); + +#ifdef __cplusplus +} +#endif + +class Url +{ +public: + static string encode(const string& url) + { + char* c_res = url_encode( (char*) url.c_str() ); + string res(c_res); + free(c_res); //Alloc'ed in url_encode() + return res; + } + + static string decode(const string& url) + { + char* c_res = url_decode( (char*) url.c_str() ); + string res(c_res); + free(c_res); //Alloc'ed in url_decode() + return res; + } + + Url(); + + string getProtocol(); + string getHost(); + bool getHostIp(IpAddr* ip); //If host is in IP form, return true & proper object by ptr + uint16_t getPort(); + string getPath(); + + void setProtocol(string protocol); + void setHost(string host); + void setPort(uint16_t port); + void setPath(string path); + + void fromString(string str); + string toString(); + +private: + string m_protocol; + string m_host; + uint16_t m_port; + string m_path; + +}; + +#endif /* LWIP_UTILS_H */
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/dbg/dbg.h --- a/LPC2368/dbg/dbg.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/dbg/dbg.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,94 +1,94 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -Debugging helpers header file -*/ - -//#ifdef DBG_H -//#define DBG_H - -#ifdef __LWIP_DEBUG -#define __DEBUG -#endif - -/*! - \def __DEBUG - To define to enable debugging in one file -*/ - -#ifdef __DEBUG - -#ifndef __DEBUGSTREAM -#define __DEBUGSTREAM - - -class DebugStream -{ -public: -static void debug(const char* format, ...); -static void release(); -static void breakPoint(const char* file, int line); -private: - -}; - -#undef DBG -#undef DBG_END -#undef BREAK - -///Debug output (if enabled), same syntax as printf, with heading info -#define DBG(...) do{ DebugStream::debug("[%s:%s@%d] ", __FILE__, __FUNCTION__, __LINE__); DebugStream::debug(__VA_ARGS__); } while(0); - -///Debug output (if enabled), same syntax as printf, no heading info -#define DBGL(...) do{ DebugStream::debug(__VA_ARGS__); } while(0); -#define DBG_END DebugStream::release - -///Break point usin serial debug interface (if debug enbaled) -#define BREAK() DebugStream::breakPoint(__FILE__, __LINE__) -#endif - -#else -#undef DBG -#undef DBG_END -#undef BREAK -#define DBG(...) -#define DBG_END() -#define BREAK() -#endif - -#ifdef __LWIP_DEBUG -#ifndef __SNPRINTF -#define __SNPRINTF -#include "mbed.h" - -//int snprintf(char *str, int size, const char *format, ...); -#endif -#endif - -#ifdef __LWIP_DEBUG -#undef __DEBUG -#endif - -//#endif - + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +Debugging helpers header file +*/ + +//#ifdef DBG_H +//#define DBG_H + +#ifdef __LWIP_DEBUG +#define __DEBUG +#endif + +/*! + \def __DEBUG + To define to enable debugging in one file +*/ + +#ifdef __DEBUG + +#ifndef __DEBUGSTREAM +#define __DEBUGSTREAM + + +class DebugStream +{ +public: +static void debug(const char* format, ...); +static void release(); +static void breakPoint(const char* file, int line); +private: + +}; + +#undef DBG +#undef DBG_END +#undef BREAK + +///Debug output (if enabled), same syntax as printf, with heading info +#define DBG(...) do{ DebugStream::debug("[%s:%s@%d] ", __FILE__, __FUNCTION__, __LINE__); DebugStream::debug(__VA_ARGS__); } while(0); + +///Debug output (if enabled), same syntax as printf, no heading info +#define DBGL(...) do{ DebugStream::debug(__VA_ARGS__); } while(0); +#define DBG_END DebugStream::release + +///Break point usin serial debug interface (if debug enbaled) +#define BREAK() DebugStream::breakPoint(__FILE__, __LINE__) +#endif + +#else +#undef DBG +#undef DBG_END +#undef BREAK +#define DBG(...) +#define DBG_END() +#define BREAK() +#endif + +#ifdef __LWIP_DEBUG +#ifndef __SNPRINTF +#define __SNPRINTF +#include "mbed.h" + +//int snprintf(char *str, int size, const char *format, ...); +#endif +#endif + +#ifdef __LWIP_DEBUG +#undef __DEBUG +#endif + +//#endif +
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/client/HTTPClient.h --- a/LPC2368/services/http/client/HTTPClient.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/client/HTTPClient.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,306 +1,306 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP Client header file -*/ - -#ifndef HTTP_CLIENT_H -#define HTTP_CLIENT_H - -class HTTPData; - -#include "core/net.h" -#include "api/TCPSocket.h" -#include "api/DNSRequest.h" -#include "HTTPData.h" -#include "mbed.h" - -#include <string> -using std::string; - -#include <map> -using std::map; - -///HTTP client results -enum HTTPResult -{ - HTTP_OK, ///<Success - HTTP_PROCESSING, ///<Processing - HTTP_PARSE, ///<URI Parse error - HTTP_DNS, ///<Could not resolve name - HTTP_PRTCL, ///<Protocol error - HTTP_NOTFOUND, ///<HTTP 404 Error - HTTP_REFUSED, ///<HTTP 403 Error - HTTP_ERROR, ///<HTTP xxx error - HTTP_TIMEOUT, ///<Connection timeout - HTTP_CONN ///<Connection error -}; - -#include "core/netservice.h" - -///A simple HTTP Client -/** -The HTTPClient is composed of: -- The actual client (HTTPClient) -- Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes) -*/ -class HTTPClient : protected NetService -{ -public: - ///Instantiates the HTTP client - HTTPClient(); - virtual ~HTTPClient(); - - ///Provides a basic authentification feature (Base64 encoded username and password) - void basicAuth(const char* user, const char* password); //Basic Authentification - - //High Level setup functions - ///Executes a GET Request (blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - Blocks until completion - */ - HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking - - ///Executes a GET Request (non blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pMethod : callback function - The function returns immediately and calls the callback on completion or error - */ - HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking - - ///Executes a GET Request (non blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pItem : instance of class on which to execute the callback method - @param pMethod : callback method - The function returns immediately and calls the callback on completion or error - */ - template<class T> - HTTPResult get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking - { - setOnResult(pItem, pMethod); - doGet(uri, pDataIn); - return HTTP_PROCESSING; - } - - ///Executes a POST Request (blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - Blocks until completion - */ - HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking - - ///Executes a POST Request (non blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pMethod : callback function - The function returns immediately and calls the callback on completion or error - */ - HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking - - ///Executes a POST Request (non blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pItem : instance of class on which to execute the callback method - @param pMethod : callback method - The function returns immediately and calls the callback on completion or error - */ - template<class T> - HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking - { - setOnResult(pItem, pMethod); - doPost(uri, dataOut, pDataIn); - return HTTP_PROCESSING; - } - - ///Executes a GET Request (non blocking) - /** - Executes a GET request on the URI uri - @param uri : URI on which to execute the request - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - The function returns immediately and calls the previously set callback on completion or error - */ - void doGet(const char* uri, HTTPData* pDataIn); - - ///Executes a POST Request (non blocking) - /** - Executes a POST request on the URI uri - @param uri : URI on which to execute the request - @param dataOut : a HTTPData instance that contains the data that will be posted - @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL - @param pMethod : callback function - The function returns immediately and calls the previously set callback on completion or error - */ - void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); - - ///Setups the result callback - /** - @param pMethod : callback function - */ - void setOnResult( void (*pMethod)(HTTPResult) ); - - ///Setups the result callback - /** - @param pItem : instance of class on which to execute the callback method - @param pMethod : callback method - */ - class CDummy; - template<class T> - void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) ) - { - m_pCb = NULL; - m_pCbItem = (CDummy*) pItem; - m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod; - } - - ///Setups timeout - /** - @param ms : time of connection inactivity in ms after which the request should timeout - */ - void setTimeout(int ms); - - virtual void poll(); //Called by NetServices - - ///Gets last request's HTTP response code - /** - @return The HTTP response code of the last request - */ - int getHTTPResponseCode(); - - ///Sets a specific request header - void setRequestHeader(const string& header, const string& value); - - ///Gets a response header - string& getResponseHeader(const string& header); - - ///Clears request headers - void resetRequestHeaders(); - -protected: - void resetTimeout(); - - void init(); - void close(); - - void setup(const char* uri, HTTPData* pDataOut, HTTPData* pDataIn); //Setup request, make DNS Req if necessary - void connect(); //Start Connection - - int tryRead(); //Read data and try to feed output - void readData(); //Data has been read - void writeData(); //Data has been written & buf is free - - void onTCPSocketEvent(TCPSocketEvent e); - void onDNSReply(DNSReply r); - void onResult(HTTPResult r); //Called when exchange completed or on failure - void onTimeout(); //Connection has timed out - -private: - HTTPResult blockingProcess(); //Called in blocking mode, calls Net::poll() until return code is available - - bool readHeaders(); //Called first when receiving data - bool writeHeaders(); //Called to create req - int readLine(char* str, int maxLen, bool* pIncomplete = NULL); - - enum HTTP_METH - { - HTTP_GET, - HTTP_POST, - HTTP_HEAD - }; - - HTTP_METH m_meth; - - CDummy* m_pCbItem; - void (CDummy::*m_pCbMeth)(HTTPResult); - - void (*m_pCb)(HTTPResult); - - TCPSocket* m_pTCPSocket; - map<string, string> m_reqHeaders; - map<string, string> m_respHeaders; - - Timer m_watchdog; - int m_timeout; - - DNSRequest* m_pDnsReq; - - Host m_server; - string m_path; - - bool m_closed; - - enum HTTPStep - { - // HTTP_INIT, - HTTP_WRITE_HEADERS, - HTTP_WRITE_DATA, - HTTP_READ_HEADERS, - HTTP_READ_DATA, - HTTP_READ_DATA_INCOMPLETE, - HTTP_DONE, - HTTP_CLOSED - }; - - HTTPStep m_state; - - HTTPData* m_pDataOut; - HTTPData* m_pDataIn; - - bool m_dataChunked; //Data is encoded as chunks - int m_dataPos; //Position in data - int m_dataLen; //Data length - char* m_buf; - char* m_pBufRemaining; //Remaining - int m_bufRemainingLen; //Data length in m_pBufRemaining - - int m_httpResponseCode; - - HTTPResult m_blockingResult; //Result if blocking mode - -}; - -//Including data containers here for more convenience -#include "data/HTTPFile.h" -#include "data/HTTPStream.h" -#include "data/HTTPText.h" -#include "data/HTTPMap.h" - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP Client header file +*/ + +#ifndef HTTP_CLIENT_H +#define HTTP_CLIENT_H + +class HTTPData; + +#include "core/net.h" +#include "api/TCPSocket.h" +#include "api/DNSRequest.h" +#include "HTTPData.h" +#include "mbed.h" + +#include <string> +using std::string; + +#include <map> +using std::map; + +///HTTP client results +enum HTTPResult +{ + HTTP_OK, ///<Success + HTTP_PROCESSING, ///<Processing + HTTP_PARSE, ///<URI Parse error + HTTP_DNS, ///<Could not resolve name + HTTP_PRTCL, ///<Protocol error + HTTP_NOTFOUND, ///<HTTP 404 Error + HTTP_REFUSED, ///<HTTP 403 Error + HTTP_ERROR, ///<HTTP xxx error + HTTP_TIMEOUT, ///<Connection timeout + HTTP_CONN ///<Connection error +}; + +#include "core/netservice.h" + +///A simple HTTP Client +/** +The HTTPClient is composed of: +- The actual client (HTTPClient) +- Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes) +*/ +class HTTPClient : protected NetService +{ +public: + ///Instantiates the HTTP client + HTTPClient(); + virtual ~HTTPClient(); + + ///Provides a basic authentification feature (Base64 encoded username and password) + void basicAuth(const char* user, const char* password); //Basic Authentification + + //High Level setup functions + ///Executes a GET Request (blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + Blocks until completion + */ + HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking + + ///Executes a GET Request (non blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pMethod : callback function + The function returns immediately and calls the callback on completion or error + */ + HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking + + ///Executes a GET Request (non blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pItem : instance of class on which to execute the callback method + @param pMethod : callback method + The function returns immediately and calls the callback on completion or error + */ + template<class T> + HTTPResult get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking + { + setOnResult(pItem, pMethod); + doGet(uri, pDataIn); + return HTTP_PROCESSING; + } + + ///Executes a POST Request (blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + Blocks until completion + */ + HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking + + ///Executes a POST Request (non blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pMethod : callback function + The function returns immediately and calls the callback on completion or error + */ + HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking + + ///Executes a POST Request (non blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pItem : instance of class on which to execute the callback method + @param pMethod : callback method + The function returns immediately and calls the callback on completion or error + */ + template<class T> + HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking + { + setOnResult(pItem, pMethod); + doPost(uri, dataOut, pDataIn); + return HTTP_PROCESSING; + } + + ///Executes a GET Request (non blocking) + /** + Executes a GET request on the URI uri + @param uri : URI on which to execute the request + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + The function returns immediately and calls the previously set callback on completion or error + */ + void doGet(const char* uri, HTTPData* pDataIn); + + ///Executes a POST Request (non blocking) + /** + Executes a POST request on the URI uri + @param uri : URI on which to execute the request + @param dataOut : a HTTPData instance that contains the data that will be posted + @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL + @param pMethod : callback function + The function returns immediately and calls the previously set callback on completion or error + */ + void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); + + ///Setups the result callback + /** + @param pMethod : callback function + */ + void setOnResult( void (*pMethod)(HTTPResult) ); + + ///Setups the result callback + /** + @param pItem : instance of class on which to execute the callback method + @param pMethod : callback method + */ + class CDummy; + template<class T> + void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) ) + { + m_pCb = NULL; + m_pCbItem = (CDummy*) pItem; + m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod; + } + + ///Setups timeout + /** + @param ms : time of connection inactivity in ms after which the request should timeout + */ + void setTimeout(int ms); + + virtual void poll(); //Called by NetServices + + ///Gets last request's HTTP response code + /** + @return The HTTP response code of the last request + */ + int getHTTPResponseCode(); + + ///Sets a specific request header + void setRequestHeader(const string& header, const string& value); + + ///Gets a response header + string& getResponseHeader(const string& header); + + ///Clears request headers + void resetRequestHeaders(); + +protected: + void resetTimeout(); + + void init(); + void close(); + + void setup(const char* uri, HTTPData* pDataOut, HTTPData* pDataIn); //Setup request, make DNS Req if necessary + void connect(); //Start Connection + + int tryRead(); //Read data and try to feed output + void readData(); //Data has been read + void writeData(); //Data has been written & buf is free + + void onTCPSocketEvent(TCPSocketEvent e); + void onDNSReply(DNSReply r); + void onResult(HTTPResult r); //Called when exchange completed or on failure + void onTimeout(); //Connection has timed out + +private: + HTTPResult blockingProcess(); //Called in blocking mode, calls Net::poll() until return code is available + + bool readHeaders(); //Called first when receiving data + bool writeHeaders(); //Called to create req + int readLine(char* str, int maxLen, bool* pIncomplete = NULL); + + enum HTTP_METH + { + HTTP_GET, + HTTP_POST, + HTTP_HEAD + }; + + HTTP_METH m_meth; + + CDummy* m_pCbItem; + void (CDummy::*m_pCbMeth)(HTTPResult); + + void (*m_pCb)(HTTPResult); + + TCPSocket* m_pTCPSocket; + map<string, string> m_reqHeaders; + map<string, string> m_respHeaders; + + Timer m_watchdog; + int m_timeout; + + DNSRequest* m_pDnsReq; + + Host m_server; + string m_path; + + bool m_closed; + + enum HTTPStep + { + // HTTP_INIT, + HTTP_WRITE_HEADERS, + HTTP_WRITE_DATA, + HTTP_READ_HEADERS, + HTTP_READ_DATA, + HTTP_READ_DATA_INCOMPLETE, + HTTP_DONE, + HTTP_CLOSED + }; + + HTTPStep m_state; + + HTTPData* m_pDataOut; + HTTPData* m_pDataIn; + + bool m_dataChunked; //Data is encoded as chunks + int m_dataPos; //Position in data + int m_dataLen; //Data length + char* m_buf; + char* m_pBufRemaining; //Remaining + int m_bufRemainingLen; //Data length in m_pBufRemaining + + int m_httpResponseCode; + + HTTPResult m_blockingResult; //Result if blocking mode + +}; + +//Including data containers here for more convenience +#include "data/HTTPFile.h" +#include "data/HTTPStream.h" +#include "data/HTTPText.h" +#include "data/HTTPMap.h" + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/client/HTTPData.h --- a/LPC2368/services/http/client/HTTPData.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/client/HTTPData.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,58 +1,58 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef HTTP_DATA_H -#define HTTP_DATA_H - -#include "core/net.h" - -#include <string> -using std::string; - -class HTTPData //This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...) -{ -public: - HTTPData(); - virtual ~HTTPData(); - - virtual void clear() = 0; - -protected: - friend class HTTPClient; - virtual int read(char* buf, int len) = 0; - virtual int write(const char* buf, int len) = 0; - - virtual string getDataType() = 0; //Internet media type for Content-Type header - virtual void setDataType(const string& type) = 0; //Internet media type from Content-Type header - - virtual bool getIsChunked() = 0; //For Transfer-Encoding header - virtual void setIsChunked(bool chunked) = 0; //From Transfer-Encoding header - - virtual int getDataLen() = 0; //For Content-Length header - virtual void setDataLen(int len) = 0; //From Content-Length header, or if the transfer is chunked, next chunk length - -private: - -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HTTP_DATA_H +#define HTTP_DATA_H + +#include "core/net.h" + +#include <string> +using std::string; + +class HTTPData //This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...) +{ +public: + HTTPData(); + virtual ~HTTPData(); + + virtual void clear() = 0; + +protected: + friend class HTTPClient; + virtual int read(char* buf, int len) = 0; + virtual int write(const char* buf, int len) = 0; + + virtual string getDataType() = 0; //Internet media type for Content-Type header + virtual void setDataType(const string& type) = 0; //Internet media type from Content-Type header + + virtual bool getIsChunked() = 0; //For Transfer-Encoding header + virtual void setIsChunked(bool chunked) = 0; //From Transfer-Encoding header + + virtual int getDataLen() = 0; //For Content-Length header + virtual void setDataLen(int len) = 0; //From Content-Length header, or if the transfer is chunked, next chunk length + +private: + +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/client/data/HTTPFile.h --- a/LPC2368/services/http/client/data/HTTPFile.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/client/data/HTTPFile.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,81 +1,81 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP File data source/sink header file -*/ - -#ifndef HTTP_FILE_H -#define HTTP_FILE_H - -#include "../HTTPData.h" -#include "mbed.h" - -///HTTP Client data container for files -/** -This class provides file access/storage for HTTP requests and responses' data payloads. - - -*/ -class HTTPFile : public HTTPData //Read or Write data from a file -{ -public: - ///Instantiates data source/sink with file in param. - /** - Uses file at path @a path. - It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance. - Note that the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing. - - @note - Note that to use this you must instantiate a proper file system (such as the LocalFileSystem or the SDFileSystem). - */ - HTTPFile(const char* path); - virtual ~HTTPFile(); - - ///Forces file closure - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header virtual - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header - -private: - bool openFile(const char* mode); //true on success, false otherwise - void closeFile(); - - FILE* m_fp; - string m_path; - int m_len; - bool m_chunked; -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP File data source/sink header file +*/ + +#ifndef HTTP_FILE_H +#define HTTP_FILE_H + +#include "../HTTPData.h" +#include "mbed.h" + +///HTTP Client data container for files +/** +This class provides file access/storage for HTTP requests and responses' data payloads. + + +*/ +class HTTPFile : public HTTPData //Read or Write data from a file +{ +public: + ///Instantiates data source/sink with file in param. + /** + Uses file at path @a path. + It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance. + Note that the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing. + + @note + Note that to use this you must instantiate a proper file system (such as the LocalFileSystem or the SDFileSystem). + */ + HTTPFile(const char* path); + virtual ~HTTPFile(); + + ///Forces file closure + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header virtual + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header + +private: + bool openFile(const char* mode); //true on success, false otherwise + void closeFile(); + + FILE* m_fp; + string m_path; + int m_len; + bool m_chunked; +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/client/data/HTTPMap.h --- a/LPC2368/services/http/client/data/HTTPMap.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/client/data/HTTPMap.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,89 +1,89 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP Map data source/sink header file -*/ - -#ifndef HTTP_MAP_H -#define HTTP_MAP_H - -#include "../HTTPData.h" -#include "mbed.h" - -#include <map> -using std::map; - -typedef map<string, string> Dictionary; - -///HTTP Client data container for key/value pairs -/** -This class simplifies the use of key/value pairs requests and responses used widely among web APIs. -Note that HTTPMap inherits from std::map<std::string,std::string>. -You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value. - -The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding. -*/ -class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs -{ -public: - ///Instantiates map - /** - @param keyValueSep Key/Value separator (defaults to "=") - @param pairSep Pairs separator (defaults to "&") - */ - HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&"); - virtual ~HTTPMap(); - - /* string& operator[](const string& key); - int count();*/ - - ///Clears the content - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header - -private: - void generateString(); - void parseString(); - //map<string, string> m_map; - string m_buf; - int m_len; - bool m_chunked; - - string m_keyValueSep; - string m_pairSep; -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP Map data source/sink header file +*/ + +#ifndef HTTP_MAP_H +#define HTTP_MAP_H + +#include "../HTTPData.h" +#include "mbed.h" + +#include <map> +using std::map; + +typedef map<string, string> Dictionary; + +///HTTP Client data container for key/value pairs +/** +This class simplifies the use of key/value pairs requests and responses used widely among web APIs. +Note that HTTPMap inherits from std::map<std::string,std::string>. +You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value. + +The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding. +*/ +class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs +{ +public: + ///Instantiates map + /** + @param keyValueSep Key/Value separator (defaults to "=") + @param pairSep Pairs separator (defaults to "&") + */ + HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&"); + virtual ~HTTPMap(); + + /* string& operator[](const string& key); + int count();*/ + + ///Clears the content + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header + +private: + void generateString(); + void parseString(); + //map<string, string> m_map; + string m_buf; + int m_len; + bool m_chunked; + + string m_keyValueSep; + string m_pairSep; +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/client/data/HTTPStream.h --- a/LPC2368/services/http/client/data/HTTPStream.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/client/data/HTTPStream.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,83 +1,83 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef HTTP_STREAM_H -#define HTTP_STREAM_H - -#include "../HTTPData.h" -#include "mbed.h" - -/** \file -HTTP Stream data source/sink header file -*/ - -typedef uint8_t byte; - -///HTTP Client Streaming tool -/** -This class allows you to stream data from the web using a persisting HTTP connection. -To use it properly you must use a non-blocking HTTPClient method. -*/ -class HTTPStream : public HTTPData //Streaming buf -{ -public: - ///Instantiates the object - HTTPStream(); - virtual ~HTTPStream(); - - ///Starts to read into buffer - /** - Passes a buffer of address @a buf and size @a size to the instance. - When it receives data it will be stored in this buffer. - When the buffer is full it throttles the client until this function is called again. - */ - void readNext(byte* buf, int size); - - ///Returns whether there is data available to read - bool readable(); - - ///Returns the actual length of the payload written in the buffer - int readLen(); - - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length - -private: - byte* m_buf; - int m_size; //Capacity - int m_len; //Length -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HTTP_STREAM_H +#define HTTP_STREAM_H + +#include "../HTTPData.h" +#include "mbed.h" + +/** \file +HTTP Stream data source/sink header file +*/ + +typedef uint8_t byte; + +///HTTP Client Streaming tool +/** +This class allows you to stream data from the web using a persisting HTTP connection. +To use it properly you must use a non-blocking HTTPClient method. +*/ +class HTTPStream : public HTTPData //Streaming buf +{ +public: + ///Instantiates the object + HTTPStream(); + virtual ~HTTPStream(); + + ///Starts to read into buffer + /** + Passes a buffer of address @a buf and size @a size to the instance. + When it receives data it will be stored in this buffer. + When the buffer is full it throttles the client until this function is called again. + */ + void readNext(byte* buf, int size); + + ///Returns whether there is data available to read + bool readable(); + + ///Returns the actual length of the payload written in the buffer + int readLen(); + + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length + +private: + byte* m_buf; + int m_size; //Capacity + int m_len; //Length +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/client/data/HTTPText.h --- a/LPC2368/services/http/client/data/HTTPText.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/client/data/HTTPText.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,101 +1,101 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** \file -HTTP Text data source/sink header file -*/ - -#ifndef HTTP_TEXT_H -#define HTTP_TEXT_H - -#include "../HTTPData.h" -#include "mbed.h" - -#define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems - -///HTTP Client data container for text -/** -This is a simple "Text" data repository for HTTP requests. -*/ -class HTTPText : public HTTPData //Simple Text I/O -{ -public: - ///Instantiates the object. - /** - @param encoding encoding of the data, it defaults to text/html. - @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes. - */ - HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC); - virtual ~HTTPText(); - - ///Gets text - /** - Returns the text in the container as a zero-terminated char*. - The array returned points to the internal buffer of the object and remains owned by the object. - */ - const char* gets() const; - - //Puts text - /** - Sets the text in the container using a zero-terminated char*. - */ - void puts(const char* str); - - ///Gets text - /** - Returns the text in the container as string. - */ - string& get(); - - ///Puts text - /** - Sets the text in the container as string. - */ - void set(const string& str); - - ///Clears the content. - /** - If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request. - */ - virtual void clear(); - -protected: - virtual int read(char* buf, int len); - virtual int write(const char* buf, int len); - - virtual string getDataType(); //Internet media type for Content-Type header - virtual void setDataType(const string& type); //Internet media type from Content-Type header - - virtual bool getIsChunked(); //For Transfer-Encoding header - virtual void setIsChunked(bool chunked); //From Transfer-Encoding header - - virtual int getDataLen(); //For Content-Length header - virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length - -private: - string m_buf; - string m_encoding; - int m_maxSize; -}; - -#endif + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** \file +HTTP Text data source/sink header file +*/ + +#ifndef HTTP_TEXT_H +#define HTTP_TEXT_H + +#include "../HTTPData.h" +#include "mbed.h" + +#define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems + +///HTTP Client data container for text +/** +This is a simple "Text" data repository for HTTP requests. +*/ +class HTTPText : public HTTPData //Simple Text I/O +{ +public: + ///Instantiates the object. + /** + @param encoding encoding of the data, it defaults to text/html. + @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes. + */ + HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC); + virtual ~HTTPText(); + + ///Gets text + /** + Returns the text in the container as a zero-terminated char*. + The array returned points to the internal buffer of the object and remains owned by the object. + */ + const char* gets() const; + + //Puts text + /** + Sets the text in the container using a zero-terminated char*. + */ + void puts(const char* str); + + ///Gets text + /** + Returns the text in the container as string. + */ + string& get(); + + ///Puts text + /** + Sets the text in the container as string. + */ + void set(const string& str); + + ///Clears the content. + /** + If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request. + */ + virtual void clear(); + +protected: + virtual int read(char* buf, int len); + virtual int write(const char* buf, int len); + + virtual string getDataType(); //Internet media type for Content-Type header + virtual void setDataType(const string& type); //Internet media type from Content-Type header + + virtual bool getIsChunked(); //For Transfer-Encoding header + virtual void setIsChunked(bool chunked); //From Transfer-Encoding header + + virtual int getDataLen(); //For Content-Length header + virtual void setDataLen(int len); //From Content-Length header, or if the transfer is chunked, next chunk length + +private: + string m_buf; + string m_encoding; + int m_maxSize; +}; + +#endif
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/util/base64.h --- a/LPC2368/services/http/util/base64.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/util/base64.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,57 +1,57 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef BASE64_H -#define BASE64_H - -#include <string> -using std::string; - -#ifdef __cplusplus -extern "C" { -#endif - -//Originaly from Rolf's iputil.h - -unsigned int base64enc_len(const char *str); - -void base64enc(const char *input, unsigned int length, char *output); - -#ifdef __cplusplus -} -#endif - -class Base64 -{ -public: - static string encode(const string& str) - { - char* out = new char[ base64enc_len(str.c_str()) ]; - base64enc(str.c_str(), str.length(), out); - string res(out); - delete[] out; - return res; - } -}; - -#endif /* LWIP_UTILS_H */ + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef BASE64_H +#define BASE64_H + +#include <string> +using std::string; + +#ifdef __cplusplus +extern "C" { +#endif + +//Originaly from Rolf's iputil.h + +unsigned int base64enc_len(const char *str); + +void base64enc(const char *input, unsigned int length, char *output); + +#ifdef __cplusplus +} +#endif + +class Base64 +{ +public: + static string encode(const string& str) + { + char* out = new char[ base64enc_len(str.c_str()) ]; + base64enc(str.c_str(), str.length(), out); + string res(out); + delete[] out; + return res; + } +}; + +#endif /* LWIP_UTILS_H */
diff -r 62fac7f06c8d -r b77740c0a846 LPC2368/services/http/util/url.h --- a/LPC2368/services/http/util/url.h Thu Dec 09 01:36:34 2010 +0000 +++ b/LPC2368/services/http/util/url.h Fri Oct 12 16:02:09 2012 +0000 @@ -1,88 +1,88 @@ - -/* -Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef URL_H -#define URL_H - -#include "core/ipaddr.h" - -#include <string> -using std::string; - -#include "mbed.h" - -#ifdef __cplusplus -extern "C" { -#endif - -char *url_encode(char *str); -char *url_decode(char *str); - -#ifdef __cplusplus -} -#endif - -class Url -{ -public: - static string encode(const string& url) - { - char* c_res = url_encode( (char*) url.c_str() ); - string res(c_res); - free(c_res); //Alloc'ed in url_encode() - return res; - } - - static string decode(const string& url) - { - char* c_res = url_decode( (char*) url.c_str() ); - string res(c_res); - free(c_res); //Alloc'ed in url_decode() - return res; - } - - Url(); - - string getProtocol(); - string getHost(); - bool getHostIp(IpAddr* ip); //If host is in IP form, return true & proper object by ptr - uint16_t getPort(); - string getPath(); - - void setProtocol(string protocol); - void setHost(string host); - void setPort(uint16_t port); - void setPath(string path); - - void fromString(string str); - string toString(); - -private: - string m_protocol; - string m_host; - uint16_t m_port; - string m_path; - -}; - -#endif /* LWIP_UTILS_H */ + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef URL_H +#define URL_H + +#include "core/ipaddr.h" + +#include <string> +using std::string; + +#include "mbed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +char *url_encode(char *str); +char *url_decode(char *str); + +#ifdef __cplusplus +} +#endif + +class Url +{ +public: + static string encode(const string& url) + { + char* c_res = url_encode( (char*) url.c_str() ); + string res(c_res); + free(c_res); //Alloc'ed in url_encode() + return res; + } + + static string decode(const string& url) + { + char* c_res = url_decode( (char*) url.c_str() ); + string res(c_res); + free(c_res); //Alloc'ed in url_decode() + return res; + } + + Url(); + + string getProtocol(); + string getHost(); + bool getHostIp(IpAddr* ip); //If host is in IP form, return true & proper object by ptr + uint16_t getPort(); + string getPath(); + + void setProtocol(string protocol); + void setHost(string host); + void setPort(uint16_t port); + void setPath(string path); + + void fromString(string str); + string toString(); + +private: + string m_protocol; + string m_host; + uint16_t m_port; + string m_path; + +}; + +#endif /* LWIP_UTILS_H */