HTTP Client library

Dependents:   weather_LCD_display News_LCD_display TwitterExample_1 GeoLocation_LCD_Display ... more

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Fri Jun 11 16:25:51 2010 +0000
Child:
1:ffc6159cc5d5
Commit message:

Changed in this revision

LPC1768/HTTPClient.ar Show annotated file Show diff for this revision Revisions of this file
LPC1768/dbg/dbg.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/client/HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/client/HTTPData.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPFile.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPMap.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPStream.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPText.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/util/base64.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/util/url.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/HTTPClient.ar Show annotated file Show diff for this revision Revisions of this file
LPC2368/dbg/dbg.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/client/HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/client/HTTPData.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPFile.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPMap.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPStream.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPText.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/util/base64.h Show annotated file Show diff for this revision Revisions of this file
LPC2368/services/http/util/url.h Show annotated file Show diff for this revision Revisions of this file
Binary file LPC1768/HTTPClient.ar has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/dbg/dbg.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,73 @@
+
+/*
+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.
+*/
+
+//#ifdef DBG_H
+//#define DBG_H
+
+#ifdef __LWIP_DEBUG
+#define __DEBUG
+#endif
+
+#ifdef __DEBUG
+
+#ifndef __DEBUGSTREAM
+#define __DEBUGSTREAM
+
+
+class DebugStream
+{
+public:
+static void debug(const char* format, ...);
+static void release();
+private:
+
+};
+
+#undef DBG
+#undef DBG_END
+#define DBG DebugStream::debug
+#define DBG_END DebugStream::release
+#endif
+
+#else
+#undef DBG
+#undef DBG_END
+#define DBG(...)
+#define DBG_END()
+#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
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/client/HTTPClient.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,198 @@
+
+/*
+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_CLIENT_H
+#define HTTP_CLIENT_H
+
+class HTTPData;
+
+#include "if/net/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;
+
+enum HTTPResult
+{
+  HTTP_OK,
+  HTTP_PROCESSING,
+  HTTP_PARSE, //URI Parse error
+  HTTP_DNS, //Could not resolve name
+  HTTP_PRTCL, //Protocol error
+  HTTP_NOTFOUND, //404 Error
+  HTTP_REFUSED, //403 Error
+  HTTP_ERROR, //xxx error
+  HTTP_TIMEOUT, //Connection timeout
+  HTTP_CONN //Connection error
+};
+
+
+
+class HTTPClient : protected NetService
+{
+public:
+  HTTPClient();
+  virtual ~HTTPClient();
+  
+  void basicAuth(const char* user, const char* password); //Basic Authentification
+  
+  //High Level setup functions
+  HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking
+  HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking
+  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;
+  }
+  
+  HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking
+  HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking
+  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;
+  }
+  
+  void doGet(const char* uri, HTTPData* pDataIn);  
+  void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); 
+  
+  void setOnResult( void (*pMethod)(HTTPResult) );
+  class CDummy;
+  template<class T> 
+  //Linker bug : Must be defined here :(
+  void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) )
+  {
+    m_pCb = NULL;
+    m_pCbItem = (CDummy*) pItem;
+    m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod;
+  }
+  
+  void setTimeout(int ms);
+  
+  virtual void poll(); //Called by NetServices
+  
+  int getHTTPResponseCode();
+  void setRequestHeader(const string& header, const string& value);
+  string& getResponseHeader(const string& header);
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/client/HTTPData.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +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 "if/net/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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/client/data/HTTPFile.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,61 @@
+
+/*
+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_FILE_H
+#define HTTP_FILE_H
+
+#include "../HTTPData.h"
+#include "mbed.h"
+
+class HTTPFile : public HTTPData //Read or Write data from a file
+{
+public:
+  HTTPFile(const char* path);
+  virtual ~HTTPFile();
+  
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/client/data/HTTPMap.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,71 @@
+
+/*
+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_MAP_H
+#define HTTP_MAP_H
+
+#include "../HTTPData.h"
+#include "mbed.h"
+
+#include <map>
+using std::map;
+
+typedef map<string, string> Dictionary;
+
+class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs
+{
+public:
+  HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&");
+  virtual ~HTTPMap();
+  
+ /* string& operator[](const string& key);
+  int count();*/
+
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/client/data/HTTPStream.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,65 @@
+
+/*
+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"
+
+typedef uint8_t byte;
+
+class HTTPStream : public HTTPData //Streaming buf
+{
+public:
+  HTTPStream();
+  virtual ~HTTPStream();
+  
+  void readNext(byte* buf, int size);
+  
+  bool readable();
+  
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/client/data/HTTPText.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,65 @@
+
+/*
+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_TEXT_H
+#define HTTP_TEXT_H
+
+#include "../HTTPData.h"
+#include "mbed.h"
+
+#define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems
+
+class HTTPText : public HTTPData //Simple Text I/O
+{
+public:
+  HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC);
+  virtual ~HTTPText();
+  
+  const char* gets() const;
+  void puts(const char* str);
+  
+  string& get();
+  void set(const string& str);
+  
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/util/base64.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +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 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/util/url.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +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 "if/net/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 */
Binary file LPC2368/HTTPClient.ar has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/dbg/dbg.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,73 @@
+
+/*
+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.
+*/
+
+//#ifdef DBG_H
+//#define DBG_H
+
+#ifdef __LWIP_DEBUG
+#define __DEBUG
+#endif
+
+#ifdef __DEBUG
+
+#ifndef __DEBUGSTREAM
+#define __DEBUGSTREAM
+
+
+class DebugStream
+{
+public:
+static void debug(const char* format, ...);
+static void release();
+private:
+
+};
+
+#undef DBG
+#undef DBG_END
+#define DBG DebugStream::debug
+#define DBG_END DebugStream::release
+#endif
+
+#else
+#undef DBG
+#undef DBG_END
+#define DBG(...)
+#define DBG_END()
+#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
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/client/HTTPClient.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,198 @@
+
+/*
+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_CLIENT_H
+#define HTTP_CLIENT_H
+
+class HTTPData;
+
+#include "if/net/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;
+
+enum HTTPResult
+{
+  HTTP_OK,
+  HTTP_PROCESSING,
+  HTTP_PARSE, //URI Parse error
+  HTTP_DNS, //Could not resolve name
+  HTTP_PRTCL, //Protocol error
+  HTTP_NOTFOUND, //404 Error
+  HTTP_REFUSED, //403 Error
+  HTTP_ERROR, //xxx error
+  HTTP_TIMEOUT, //Connection timeout
+  HTTP_CONN //Connection error
+};
+
+
+
+class HTTPClient : protected NetService
+{
+public:
+  HTTPClient();
+  virtual ~HTTPClient();
+  
+  void basicAuth(const char* user, const char* password); //Basic Authentification
+  
+  //High Level setup functions
+  HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking
+  HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking
+  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;
+  }
+  
+  HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking
+  HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking
+  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;
+  }
+  
+  void doGet(const char* uri, HTTPData* pDataIn);  
+  void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); 
+  
+  void setOnResult( void (*pMethod)(HTTPResult) );
+  class CDummy;
+  template<class T> 
+  //Linker bug : Must be defined here :(
+  void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) )
+  {
+    m_pCb = NULL;
+    m_pCbItem = (CDummy*) pItem;
+    m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod;
+  }
+  
+  void setTimeout(int ms);
+  
+  virtual void poll(); //Called by NetServices
+  
+  int getHTTPResponseCode();
+  void setRequestHeader(const string& header, const string& value);
+  string& getResponseHeader(const string& header);
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/client/HTTPData.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +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 "if/net/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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/client/data/HTTPFile.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,61 @@
+
+/*
+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_FILE_H
+#define HTTP_FILE_H
+
+#include "../HTTPData.h"
+#include "mbed.h"
+
+class HTTPFile : public HTTPData //Read or Write data from a file
+{
+public:
+  HTTPFile(const char* path);
+  virtual ~HTTPFile();
+  
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/client/data/HTTPMap.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,71 @@
+
+/*
+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_MAP_H
+#define HTTP_MAP_H
+
+#include "../HTTPData.h"
+#include "mbed.h"
+
+#include <map>
+using std::map;
+
+typedef map<string, string> Dictionary;
+
+class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs
+{
+public:
+  HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&");
+  virtual ~HTTPMap();
+  
+ /* string& operator[](const string& key);
+  int count();*/
+
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/client/data/HTTPStream.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,65 @@
+
+/*
+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"
+
+typedef uint8_t byte;
+
+class HTTPStream : public HTTPData //Streaming buf
+{
+public:
+  HTTPStream();
+  virtual ~HTTPStream();
+  
+  void readNext(byte* buf, int size);
+  
+  bool readable();
+  
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/client/data/HTTPText.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +1,65 @@
+
+/*
+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_TEXT_H
+#define HTTP_TEXT_H
+
+#include "../HTTPData.h"
+#include "mbed.h"
+
+#define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems
+
+class HTTPText : public HTTPData //Simple Text I/O
+{
+public:
+  HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC);
+  virtual ~HTTPText();
+  
+  const char* gets() const;
+  void puts(const char* str);
+  
+  string& get();
+  void set(const string& str);
+  
+  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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/util/base64.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +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 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC2368/services/http/util/url.h	Fri Jun 11 16:25:51 2010 +0000
@@ -0,0 +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 "if/net/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 */