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:
Thu Apr 19 09:19:58 2012 +0000
Parent:
5:d0be6af2d1db
Child:
7:d97a4fc01c86
Commit message:
First test commit

Changed in this revision

HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
IHTTPData.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/HTTPClient.ar Show diff for this revision Revisions of this file
LPC1768/dbg/dbg.h Show diff for this revision Revisions of this file
LPC1768/services/http/client/HTTPClient.h Show diff for this revision Revisions of this file
LPC1768/services/http/client/HTTPData.h Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPFile.h Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPMap.h Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPStream.h Show diff for this revision Revisions of this file
LPC1768/services/http/client/data/HTTPText.h Show diff for this revision Revisions of this file
LPC1768/services/http/util/base64.h Show diff for this revision Revisions of this file
LPC1768/services/http/util/url.h Show diff for this revision Revisions of this file
LPC2368/HTTPClient.ar Show diff for this revision Revisions of this file
LPC2368/dbg/dbg.h Show diff for this revision Revisions of this file
LPC2368/services/http/client/HTTPClient.h Show diff for this revision Revisions of this file
LPC2368/services/http/client/HTTPData.h Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPFile.h Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPMap.h Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPStream.h Show diff for this revision Revisions of this file
LPC2368/services/http/client/data/HTTPText.h Show diff for this revision Revisions of this file
LPC2368/services/http/util/base64.h Show diff for this revision Revisions of this file
LPC2368/services/http/util/url.h Show diff for this revision Revisions of this file
data/HTTPMap.cpp Show annotated file Show diff for this revision Revisions of this file
data/HTTPMap.h Show annotated file Show diff for this revision Revisions of this file
data/HTTPText.cpp Show annotated file Show diff for this revision Revisions of this file
data/HTTPText.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.cpp	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,628 @@
+/* HTTPClient.cpp */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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.
+*/
+
+#define __DEBUG__ 4 //Maximum verbosity
+#ifndef __MODULE__
+#define __MODULE__ "HTTPClient.cpp"
+#endif
+
+#include "core/fwk.h"
+
+#include "HTTPClient.h"
+
+#define HTTP_REQUEST_TIMEOUT 30000
+#define HTTP_PORT 80
+
+#define CHUNK_SIZE 256
+
+#include <cstring>
+
+HTTPClient::HTTPClient() :
+m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0)
+{
+
+}
+
+HTTPClient::~HTTPClient()
+{
+
+}
+
+#if 0
+void HTTPClient::basicAuth(const char* user, const char* password) //Basic Authentification
+{
+  m_basicAuthUser = user;
+  m_basicAuthPassword = password;
+}
+#endif
+
+int HTTPClient::get(const char* url, IHTTPDataIn* pDataIn, uint32_t timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking
+{
+  return connect(url, HTTP_GET, NULL, pDataIn, timeout);
+}
+
+int HTTPClient::get(const char* url, char* result, size_t maxResultLen, uint32_t timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking
+{
+  HTTPText str(result, maxResultLen);
+  return get(url, &str, timeout);
+}
+
+int HTTPClient::post(const char* url, const IHTTPDataOut& dataOut, IHTTPDataIn* pDataIn, uint32_t timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking
+{
+  return connect(url, HTTP_POST, (IHTTPDataOut*)&dataOut, pDataIn, timeout);
+}
+
+int HTTPClient::getHTTPResponseCode()
+{
+  return m_httpResponseCode;
+}
+
+
+int HTTPClient::connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, uint32_t timeout) //Execute request
+{
+  m_httpResponseCode = 0; //Invalidate code
+  m_timeout = timeout;
+
+  char scheme[8];
+  uint16_t port;
+  char host[32];
+  char path[64];
+  //First we need to parse the url (http[s]://host[:port][/[path]]) -- HTTPS not supported (yet?)
+  int ret = parseURL(url, scheme, sizeof(scheme), host, sizeof(host), &port, path, sizeof(path));
+  if(ret != OK)
+  {
+    ERR("parseURL returned %d", ret);
+    return ret;
+  }
+
+  if(port == 0) //TODO do handle HTTPS->443
+  {
+    port = 80;
+  }
+
+  DBG("Scheme: %s", scheme);
+  DBG("Host: %s", host);
+  DBG("Port: %d", port);
+  DBG("Path: %s", path);
+
+  //Now populate structure
+  std::memset(&m_serverAddr, 0, sizeof(struct sockaddr_in));
+
+  //Resolve DNS if needed
+
+  DBG("Resolving DNS address or populate hard-coded IP address");
+  struct hostent *server = socket::gethostbyname(host);
+  if(server == NULL)
+  {
+    return NET_NOTFOUND; //Fail
+  }
+  memcpy((char*)&m_serverAddr.sin_addr.s_addr, (char*)server->h_addr_list[0], server->h_length);
+
+  m_serverAddr.sin_family = AF_INET;
+  m_serverAddr.sin_port = htons(port);
+
+  //Create socket
+  DBG("Creating socket");
+  m_sock = socket::socket(AF_INET, SOCK_STREAM, 0); //UDP socket
+  if (m_sock < 0)
+  {
+    ERR("Could not create socket");
+    return NET_OOM;
+  }
+  DBG("Handle is %d", m_sock);
+
+  //Connect it
+  DBG("Connecting socket to %s:%d", inet_ntoa(m_serverAddr.sin_addr), ntohs(m_serverAddr.sin_port));
+  ret = socket::connect(m_sock, (const struct sockaddr *)&m_serverAddr, sizeof(m_serverAddr));
+  if (ret < 0)
+  {
+    socket::close(m_sock);
+    ERR("Could not connect");
+    return NET_CONN;
+  }
+
+  //Send request
+  DBG("Sending request");
+  char line[128];
+  const char* meth = (method==HTTP_GET)?"GET":(method==HTTP_POST)?"POST":"";
+  snprintf(line, sizeof(line), "%s %s HTTP/1.1\r\nHost: %s\r\n", meth, path, host); //Write request
+  ret = send(line);
+  if(ret)
+  {
+    socket::close(m_sock);
+    ERR("Could not write request");
+    return NET_CONN;
+  }
+
+  //Send all headers
+
+  //Send default headers
+  DBG("Sending headers");
+  if( (method == HTTP_POST) && (pDataOut != NULL) )
+  {
+    if( pDataOut->getIsChunked() )
+    {
+      ret = send("Transfer-Encoding: chunked\r\n");
+      if(ret != OK) goto connerr;
+    }
+    else
+    {
+      snprintf(line, sizeof(line), "Content-Length: %d\r\n", pDataOut->getDataLen());
+      ret = send(line);
+      if(ret != OK) goto connerr;
+    }
+    char type[48];
+    if( pDataOut->getDataType(type, 48) == OK )
+    {
+      snprintf(line, sizeof(line), "Content-Type: %s\r\n", type);
+      ret = send(line);
+      if(ret != OK) goto connerr;
+    }
+  }
+
+  //Close headers
+  DBG("Headers sent");
+  ret = send("\r\n");
+  if(ret != OK) goto connerr;
+
+  char buf[CHUNK_SIZE];
+  size_t trfLen;
+
+  //Send data (if POST)
+  if( (method == HTTP_POST) && (pDataOut != NULL) )
+  {
+    DBG("Sending data");
+    while(true)
+    {
+      size_t writtenLen = 0;
+      pDataOut->read(buf, CHUNK_SIZE, &trfLen);
+      if( pDataOut->getIsChunked() )
+      {
+        //Write chunk header
+        snprintf(line, sizeof(line), "%X\r\n", trfLen); //In hex encoding
+        ret = send(line);
+        if(ret != OK) goto connerr;
+      }
+      else if( trfLen == 0 )
+      {
+        break;
+      }
+      if( trfLen != 0 )
+      {
+        ret = send(buf, trfLen);
+        if(ret != OK) goto connerr;
+      }
+
+      if( pDataOut->getIsChunked()  )
+      {
+        ret = send("\r\n"); //Chunk-terminating CRLF
+        if(ret != OK) goto connerr;
+      }
+      else
+      {
+        writtenLen += trfLen;
+        if( writtenLen >= pDataOut->getDataLen() )
+        {
+          break;
+        }
+      }
+
+      if( trfLen == 0 )
+      {
+        break;
+      }
+    }
+
+  }
+
+  //Receive response
+  DBG("Receiving response");
+  ret = recv(buf, CHUNK_SIZE, CHUNK_SIZE, &trfLen); //Read n bytes
+  if(ret != OK) goto connerr;
+
+  buf[trfLen] = '\0';
+
+  char* crlfPtr = strstr(buf, "\r\n");
+  if(crlfPtr == NULL)
+  {
+    goto prtclerr;
+  }
+
+  int crlfPos = crlfPtr - buf;
+  buf[crlfPos] = '\0';
+
+  //Parse HTTP response
+  if( sscanf(buf, "HTTP/%*d.%*d %d %*[^\r\n]", &m_httpResponseCode) != 1 )
+  {
+    //Cannot match string, error
+    ERR("Not a correct HTTP answer : %s\n", buf);
+    goto prtclerr;
+  }
+
+  if(m_httpResponseCode != 200)
+  {
+    //Cannot match string, error
+    WARN("Response code %d", m_httpResponseCode);
+    goto prtclerr;
+  }
+
+  DBG("Reading headers");
+
+  memmove(buf, &buf[crlfPos+2], trfLen - (crlfPos + 2));
+  trfLen -= (crlfPos + 2);
+
+  size_t recvContentLength = 0;
+  bool recvChunked = false;
+  //Now get headers
+  while( true )
+  {
+    crlfPtr = strstr(buf, "\r\n");
+    if(crlfPtr == NULL)
+    {
+      if( trfLen < CHUNK_SIZE )
+      {
+        size_t newTrfLen;
+        ret = recv(buf + trfLen, 1, CHUNK_SIZE - trfLen - 1, &newTrfLen);
+        trfLen += newTrfLen;
+        buf[trfLen] = '\0';
+        DBG("In buf: [%s]", buf);
+        if(ret != OK) goto connerr;
+        continue;
+      }
+      else
+      {
+        goto prtclerr;
+      }
+    }
+
+    crlfPos = crlfPtr - buf;
+
+    if(crlfPos == 0) //End of headers
+    {
+      DBG("Headers read");
+      memmove(buf, &buf[2], trfLen - 2);
+      trfLen -= 2;
+      break;
+    }
+
+    buf[crlfPos] = '\0';
+
+    char key[16];
+    char value[16];
+
+    int n = sscanf(buf, "%16[^:]: %16[^\r\n]", key, value);
+    if ( n == 2 )
+    {
+      DBG("Read header : %s: %s\n", key, value);
+      if( !strcmp(key, "Content-Length") )
+      {
+        sscanf(value, "%d", &recvContentLength);
+        pDataIn->setDataLen(recvContentLength);
+      }
+      else if( !strcmp(key, "Transfer-Encoding") )
+      {
+        if( !strcmp(value, "Chunked") || !strcmp(value, "chunked") )
+        {
+          recvChunked = true;
+          pDataIn->setIsChunked(true);
+        }
+      }
+      else if( !strcmp(key, "Content-Type") )
+      {
+        pDataIn->setDataType(value);
+      }
+
+      memmove(buf, &buf[crlfPos+2], trfLen - (crlfPos + 2));
+      trfLen -= (crlfPos + 2);
+
+    }
+    else
+    {
+      ERR("Could not parse header");
+      goto prtclerr;
+    }
+
+  }
+
+  //Receive data
+  DBG("Receiving data");
+  while(true)
+  {
+    size_t readLen = 0;
+
+    if( recvChunked )
+    {
+      //Read chunk header
+      crlfPos=0;
+      for(crlfPos++; crlfPos < trfLen - 2; crlfPos++)
+      {
+        if( buf[crlfPos] == '\r' && buf[crlfPos + 1] == '\n' )
+        {
+          break;
+        }
+      }
+      if(crlfPos >= trfLen - 2) //Try to read more
+      {
+        if( trfLen < CHUNK_SIZE )
+        {
+          size_t newTrfLen;
+          ret = recv(buf + trfLen, 0, CHUNK_SIZE - trfLen - 1, &newTrfLen);
+          trfLen += newTrfLen;
+          if(ret != OK) goto connerr;
+          continue;
+        }
+        else
+        {
+          goto prtclerr;
+        }
+      }
+      buf[crlfPos] = '\0';
+      int n = sscanf(buf, "%x", &readLen);
+      if(n!=1)
+      {
+        ERR("Could not read chunk length");
+        goto prtclerr;
+      }
+
+      memmove(buf, &buf[crlfPos+2], trfLen - (crlfPos + 2));
+      trfLen -= (crlfPos + 2);
+
+      if( readLen == 0 )
+      {
+        //Last chunk
+        break;
+      }
+    }
+    else
+    {
+      readLen = recvContentLength;
+    }
+
+    DBG("Retrieving %d bytes", readLen);
+
+    do
+    {
+      pDataIn->write(buf, MIN(trfLen, readLen));
+      if( trfLen > readLen )
+      {
+        memmove(buf, &buf[readLen], trfLen - readLen);
+        trfLen -= readLen;
+        readLen = 0;
+      }
+      else
+      {
+        readLen -= trfLen;
+      }
+
+      if(readLen)
+      {
+        ret = recv(buf, 1, CHUNK_SIZE - trfLen - 1, &trfLen);
+        if(ret != OK) goto connerr;
+
+      }
+    } while(readLen);
+
+    if( recvChunked )
+    {
+      if(trfLen < 2)
+      {
+        size_t newTrfLen;
+        //Read missing chars to find end of chunk
+        ret = recv(buf, 2 - trfLen, CHUNK_SIZE, &newTrfLen);
+        if(ret != OK) goto connerr;
+        trfLen += newTrfLen;
+      }
+      if( (buf[0] != '\r') || (buf[1] != '\n') )
+      {
+        ERR("Format error");
+        goto prtclerr;
+      }
+      memmove(buf, &buf[2], trfLen - 2);
+      trfLen -= 2;
+    }
+    else
+    {
+      break;
+    }
+
+  }
+
+  socket::close(m_sock);
+  DBG("Completed HTTP transaction");
+
+  return OK;
+
+  connerr:
+    socket::close(m_sock);
+    ERR("Connection error (%d)", ret);
+  return NET_CONN;
+
+  prtclerr:
+    socket::close(m_sock);
+    ERR("Protocol error");
+  return NET_PROTOCOL;
+
+}
+
+int HTTPClient::recv(char* buf, size_t minLen, size_t maxLen, size_t* pReadLen) //0 on success, err code on failure
+{
+  DBG("Trying to read between %d and %d bytes", minLen, maxLen);
+  size_t readLen = 0;
+  while(readLen < minLen)
+  {
+    //Wait for socket to be readable
+    //Creating FS set
+    fd_set socksSet;
+    FD_ZERO(&socksSet);
+    FD_SET(m_sock, &socksSet);
+    struct timeval t_val;
+    t_val.tv_sec = m_timeout / 1000;
+    t_val.tv_usec = (m_timeout - (t_val.tv_sec * 1000)) * 1000;
+    int ret = socket::select(FD_SETSIZE, &socksSet, NULL, NULL, &t_val);
+    if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+    {
+      WARN("Timeout");
+      return NET_TIMEOUT; //Timeout
+    }
+
+    ret = socket::recv(m_sock, buf + readLen, maxLen - readLen, 0);
+    if( ret > 0)
+    {
+      readLen += ret;
+      continue;
+    }
+    else if( ret == 0 )
+    {
+      WARN("Connection was closed by server");
+      return NET_CLOSED; //Connection was closed by server
+    }
+    else
+    {
+      ERR("Connection error (recv returned %d)", ret);
+      return NET_CONN;
+    }
+  }
+  *pReadLen = readLen;
+  DBG("Read %d bytes", readLen);
+  return OK;
+}
+
+int HTTPClient::send(char* buf, size_t len) //0 on success, err code on failure
+{
+  if(len == 0)
+  {
+    len = strlen(buf);
+  }
+  DBG("Trying to write %d bytes", len);
+  size_t writtenLen = 0;
+  while(writtenLen < len)
+  {
+    //Wait for socket to be writeable
+    //Creating FS set
+    fd_set socksSet;
+    FD_ZERO(&socksSet);
+    FD_SET(m_sock, &socksSet);
+    struct timeval t_val;
+    t_val.tv_sec = m_timeout / 1000;
+    t_val.tv_usec = (m_timeout - (t_val.tv_sec * 1000)) * 1000;
+    int ret = socket::select(FD_SETSIZE, NULL, &socksSet, NULL, &t_val);
+    if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+    {
+      WARN("Timeout");
+      return NET_TIMEOUT; //Timeout
+    }
+
+    ret = socket::send(m_sock, buf + writtenLen, len - writtenLen, 0);
+    if( ret > 0)
+    {
+      writtenLen += ret;
+      continue;
+    }
+    else if( ret == 0 )
+    {
+      WARN("Connection was closed by server");
+      return NET_CLOSED; //Connection was closed by server
+    }
+    else
+    {
+      ERR("Connection error (recv returned %d)", ret);
+      return NET_CONN;
+    }
+  }
+  DBG("Written %d bytes", writtenLen);
+  return OK;
+}
+
+int HTTPClient::parseURL(const char* url, char* scheme, size_t maxSchemeLen, char* host, size_t maxHostLen, uint16_t* port, char* path, size_t maxPathLen) //Parse URL
+{
+  char* schemePtr = (char*) url;
+  char* hostPtr = (char*) strstr(url, "://");
+  if(hostPtr == NULL)
+  {
+    WARN("Could not find host");
+    return NET_INVALID; //URL is invalid
+  }
+
+  if( maxSchemeLen < hostPtr - schemePtr + 1 ) //including NULL-terminating char
+  {
+    WARN("Scheme str is too small (%d >= %d)", maxSchemeLen, hostPtr - schemePtr + 1);
+    return NET_TOOSMALL;
+  }
+  memcpy(scheme, schemePtr, hostPtr - schemePtr);
+  scheme[hostPtr - schemePtr] = '\0';
+
+  hostPtr+=3;
+
+  size_t hostLen = 0;
+
+  char* portPtr = strchr(hostPtr, ':');
+  if( portPtr != NULL )
+  {
+    hostLen = portPtr - hostPtr;
+    portPtr++;
+    if( sscanf(portPtr, "%d", &port) != 1)
+    {
+      WARN("Could not find port");
+      return NET_INVALID;
+    }
+  }
+  else
+  {
+    *port=0;
+  }
+  char* pathPtr = strchr(hostPtr, '/');
+  if( hostLen == 0 )
+  {
+    hostLen = pathPtr - hostPtr;
+  }
+
+  if( maxHostLen < hostLen + 1 ) //including NULL-terminating char
+  {
+    WARN("Host str is too small (%d >= %d)", maxHostLen, hostLen + 1);
+    return NET_TOOSMALL;
+  }
+  memcpy(host, hostPtr, hostLen);
+  host[hostLen] = '\0';
+
+  size_t pathLen;
+  char* fragmentPtr = strchr(hostPtr, '#');
+  if(fragmentPtr != NULL)
+  {
+    pathLen = fragmentPtr - pathPtr;
+  }
+  else
+  {
+    pathLen = strlen(pathPtr);
+  }
+
+  if( maxPathLen < pathLen + 1 ) //including NULL-terminating char
+  {
+    WARN("Path str is too small (%d >= %d)", maxPathLen, pathLen + 1);
+    return NET_TOOSMALL;
+  }
+  memcpy(path, pathPtr, pathLen);
+  path[pathLen] = '\0';
+
+  return OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.h	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,153 @@
+/* HTTPClient.h */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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
+
+#include "api/socket.h"
+
+#define HTTP_CLIENT_DEFAULT_TIMEOUT 4000
+
+class HTTPData;
+
+#include "IHTTPData.h"
+#include "mbed.h"
+
+///HTTP client results
+enum HTTPResult
+{
+  HTTP_OK, ///<Success
+  HTTP_PROCESSING, ///<Processing
+  HTTP_PARSE, ///<url 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
+};
+
+///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
+{
+public:
+  ///Instantiates the HTTP client
+  HTTPClient();
+  ~HTTPClient();
+  
+#if 0 //TODO add header handlers
+  /**
+  Provides a basic authentification feature (Base64 encoded username and password)
+  Pass two NULL pointers to switch back to no authentication
+  @param user username to use for authentication, must remain valid durlng the whole HTTP session
+  @param user password to use for authentication, must remain valid durlng the whole HTTP session
+  */
+  void basicAuth(const char* user, const char* password); //Basic Authentification
+#endif
+  
+  //High Level setup functions
+  ///Executes a GET Request (blocking)
+  /**
+  Executes a GET request on the url url
+  @param url : url on which to execute the request
+  @param pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL
+  @param timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
+  @return 0 on success, NET error on failure
+  Blocks until completion
+  */
+  int get(const char* url, IHTTPDataIn* pDataIn, uint32_t timeout = HTTP_CLIENT_DEFAULT_TIMEOUT); //Blocking
+  
+  ///Executes a GET Request (blocking)
+  /**
+  Executes a GET request on the url url
+  @param url : url on which to execute the request
+  @param result : pointer to a char array in which the result will be stored
+  @param maxResultLen : length of the char array (including space for the NULL-terminating char)
+  @param timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
+  @return 0 on success, NET error on failure
+  Blocks until completion
+  */
+  int get(const char* url, char* result, size_t maxResultLen, uint32_t timeout = HTTP_CLIENT_DEFAULT_TIMEOUT); //Blocking
+
+  ///Executes a POST Request (blocking)
+  /**
+  Executes a POST request on the url url
+  @param url : url on which to execute the request
+  @param dataOut : a IHTTPDataOut instance that contains the data that will be posted
+  @param pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL
+  @param timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
+  @return 0 on success, NET error on failure
+  Blocks until completion
+  */
+  int post(const char* url, const IHTTPDataOut& dataOut, IHTTPDataIn* pDataIn, uint32_t timeout = HTTP_CLIENT_DEFAULT_TIMEOUT); //Blocking
+  
+  ///Gets last request's HTTP response code
+  /**
+  @return The HTTP response code of the last request
+  */
+  int getHTTPResponseCode();
+  
+private:
+  enum HTTP_METH
+  {
+    HTTP_GET,
+    HTTP_POST,
+    HTTP_HEAD
+  };
+
+  int connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, uint32_t timeout); //Execute request
+  int recv(char* buf, size_t minLen, size_t maxLen, size_t* pReadLen); //0 on success, err code on failure
+  int send(char* buf, size_t len = 0); //0 on success, err code on failure
+  int parseURL(const char* url, char* scheme, size_t maxSchemeLen, char* host, size_t maxHostLen, uint16_t* port, char* path, size_t maxPathLen); //Parse URL
+
+  //Parameters
+  int m_sock;
+  uint32_t m_timeout;
+
+  const char* m_basicAuthUser;
+  const char* m_basicAuthPassword;
+/*
+  HTTPData* m_pDataOut;
+  HTTPData* m_pDataIn;
+*/
+  int m_httpResponseCode;
+
+  struct sockaddr_in m_serverAddr;
+
+};
+
+//Including data containers here for more convenience
+#include "data/HTTPText.h"
+#include "data/HTTPMap.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IHTTPData.h	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,57 @@
+/* IHTTPData.h */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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 IHTTPDATA_H
+#define IHTTPDATA_H
+
+class IHTTPDataOut //This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
+{
+protected:
+  friend class HTTPClient;
+
+  virtual int read(char* buf, size_t len, size_t* pReadLen) = 0;
+  
+  virtual int getDataType(char* type, size_t maxTypeLen) = 0; //Internet media type for Content-Type header
+  
+  virtual bool getIsChunked() = 0; //For Transfer-Encoding header
+  
+  virtual size_t getDataLen() = 0; //For Content-Length header
+
+};
+
+class IHTTPDataIn //This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
+{
+protected:
+  friend class HTTPClient;
+
+  virtual int write(const char* buf, size_t len) = 0;
+
+  virtual void setDataType(const char* type) = 0; //Internet media type from Content-Type header
+
+  virtual void setIsChunked(bool chunked) = 0; //From Transfer-Encoding header
+  
+  virtual void setDataLen(size_t len) = 0; //From Content-Length header, or if the transfer is chunked, next chunk length
+
+};
+
+#endif
Binary file LPC1768/HTTPClient.ar has changed
--- a/LPC1768/dbg/dbg.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-
-/*
-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
-
--- a/LPC1768/services/http/client/HTTPClient.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,306 +0,0 @@
-
-/*
-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
--- a/LPC1768/services/http/client/HTTPData.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-
-/*
-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
--- a/LPC1768/services/http/client/data/HTTPFile.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-
-/*
-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
--- a/LPC1768/services/http/client/data/HTTPMap.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-
-/*
-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
--- a/LPC1768/services/http/client/data/HTTPStream.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-
-/*
-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
--- a/LPC1768/services/http/client/data/HTTPText.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-
-/*
-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
--- a/LPC1768/services/http/util/base64.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-
-/*
-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 */
--- a/LPC1768/services/http/util/url.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-
-/*
-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 */
Binary file LPC2368/HTTPClient.ar has changed
--- a/LPC2368/dbg/dbg.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-
-/*
-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
-
--- a/LPC2368/services/http/client/HTTPClient.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,306 +0,0 @@
-
-/*
-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
--- a/LPC2368/services/http/client/HTTPData.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-
-/*
-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
--- a/LPC2368/services/http/client/data/HTTPFile.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-
-/*
-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
--- a/LPC2368/services/http/client/data/HTTPMap.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-
-/*
-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
--- a/LPC2368/services/http/client/data/HTTPStream.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-
-/*
-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
--- a/LPC2368/services/http/client/data/HTTPText.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-
-/*
-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
--- a/LPC2368/services/http/util/base64.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-
-/*
-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 */
--- a/LPC2368/services/http/util/url.h	Thu Aug 05 15:09:46 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-
-/*
-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 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPMap.cpp	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,198 @@
+/* HTTPMap.cpp */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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.
+*/
+
+#include "core/fwk.h"
+
+#include "HTTPMap.h"
+
+#include <cstring>
+
+#include <cctype>
+
+HTTPMap::HTTPMap() : m_pos(0), m_count(0)
+{
+
+}
+
+void HTTPMap::put(const char* key, const char* value)
+{
+  if(m_count >= HTTPMAP_TABLE_SIZE)
+  {
+    return;
+  }
+  m_keys[m_count] = key;
+  m_values[m_count] = value;
+  m_count++;
+}
+
+void HTTPMap::clear()
+{
+  m_count = 0;
+  m_pos = 0;
+}
+
+
+/*virtual*/ int HTTPMap::read(char* buf, size_t len, size_t* pReadLen)
+{
+  if(m_pos >= m_count)
+  {
+    *pReadLen = 0;
+    m_pos = 0;
+    return OK;
+  }
+
+  //URL encode
+  char* out = buf;
+  const char* in = m_keys[m_pos];
+  if( (m_pos != 0) && (out - buf < len - 1) )
+  {
+    *out='&';
+    out++;
+  }
+
+  while( (*in != '\0') && (out - buf < len - 3) )
+  {
+    if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+    {
+      *out = *in;
+      out++;
+    }
+    else if( *in == ' ' )
+    {
+      *out='+';
+      out++;
+    }
+    else
+    {
+      char hex[] = "0123456789abcdef";
+      *out='%';
+      out++;
+      *out=hex[(*in>>4)&0xf];
+      out++;
+      *out=hex[(*in)&0xf];
+      out++;
+    }
+    in++;
+  }
+
+  if( out - buf < len - 1 )
+  {
+    *out='=';
+    out++;
+  }
+
+  in = m_values[m_pos];
+  while( (*in != '\0') && (out - buf < len - 3) )
+  {
+    if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+    {
+      *out = *in;
+      out++;
+    }
+    else if( *in == ' ' )
+    {
+      *out='+';
+      out++;
+    }
+    else
+    {
+      char hex[] = "0123456789abcdef";
+      *out='%';
+      out++;
+      *out=hex[(*in>>4)&0xf];
+      out++;
+      *out=hex[(*in)&0xf];
+      out++;
+    }
+    in++;
+  }
+
+  *pReadLen = out - buf;
+
+  m_pos++;
+  return OK;
+}
+
+/*virtual*/ int HTTPMap::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
+{
+  strncpy(type, "application/x-www-form-urlencoded", maxTypeLen-1);
+  type[maxTypeLen-1] = '\0';
+  return OK;
+}
+
+/*virtual*/ bool HTTPMap::getIsChunked() //For Transfer-Encoding header
+{
+  return false; ////Data is computed one key/value pair at a time
+}
+
+/*virtual*/ size_t HTTPMap::getDataLen() //For Content-Length header
+{
+  size_t count = 0;
+  for(size_t i = 0; i< m_count; i++)
+  {
+    //URL encode
+    const char* in = m_keys[i];
+    if( i != 0 )
+    {
+      count++;
+    }
+
+    while( (*in != '\0') )
+    {
+      if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+      {
+        count++;
+      }
+      else if( *in == ' ' )
+      {
+        count++;
+      }
+      else
+      {
+        count+=3;
+      }
+      in++;
+    }
+
+    count ++;
+
+    in = m_values[i];
+    while( (*in != '\0') )
+    {
+      if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
+      {
+        count++;
+      }
+      else if( *in == ' ' )
+      {
+        count++;
+      }
+      else
+      {
+        count+=3;
+      }
+      in++;
+    }
+  }
+  return count;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPMap.h	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,70 @@
+/* HTTPMap.h */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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 HTTPMAP_H_
+#define HTTPMAP_H_
+
+#include "../IHTTPData.h"
+
+#define HTTPMAP_TABLE_SIZE 32
+
+class HTTPMap: public IHTTPDataOut
+{
+public:
+  /**
+   Instantiates HTTPMap
+   It supports at most 32 key/values pairs
+   */
+  HTTPMap();
+
+  /** Put Key/Value pair
+   The references to the parameters must remain valid as long as the clear() function is not called
+   @param key The key to use
+   @param value The corresponding value
+   */
+  void put(const char* key, const char* value);
+
+  /** Clear table
+   */
+  void clear();
+
+protected:
+  //IHTTPDataIn
+  virtual int read(char* buf, size_t len, size_t* pReadLen);
+
+  virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
+
+  virtual bool getIsChunked(); //For Transfer-Encoding header
+
+  virtual size_t getDataLen(); //For Content-Length header
+
+private:
+  const char* m_keys[HTTPMAP_TABLE_SIZE];
+  const char* m_values[HTTPMAP_TABLE_SIZE];
+
+  size_t m_pos;
+  size_t m_count;
+};
+
+#endif /* HTTPMAP_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPText.cpp	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,92 @@
+/* HTTPText.cpp */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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.
+*/
+
+#include "core/fwk.h"
+
+#include "HTTPText.h"
+
+#include <cstring>
+
+HTTPText::HTTPText(char* str) : m_str(str), m_pos(0)
+{
+  m_size = strlen(str) + 1;
+}
+
+HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0)
+{
+
+}
+
+//IHTTPDataIn
+/*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen)
+{
+  *pReadLen = MIN(len, m_size - 1 - m_pos);
+  memcpy(buf, m_str + m_pos, *pReadLen);
+  m_pos += *pReadLen;
+  return OK;
+}
+
+/*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header
+{
+  strncpy(type, "text/plain", maxTypeLen-1);
+  type[maxTypeLen-1] = '\0';
+  return OK;
+}
+
+/*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header
+{
+  return false;
+}
+
+/*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header
+{
+  return m_size - 1;
+}
+
+//IHTTPDataOut
+/*virtual*/ int HTTPText::write(const char* buf, size_t len)
+{
+  size_t writeLen = MIN(len, m_size - 1 - m_pos);
+  memcpy(m_str + m_pos, buf, writeLen);
+  m_pos += writeLen;
+  m_str[m_pos] = '\0';
+  return OK;
+}
+
+/*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header
+{
+
+}
+
+/*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header
+{
+
+}
+
+/*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length
+{
+
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPText.h	Thu Apr 19 09:19:58 2012 +0000
@@ -0,0 +1,62 @@
+/* HTTPText.h */
+/*
+Copyright (C) 2012 ARM Limited.
+
+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 HTTPTEXT_H_
+#define HTTPTEXT_H_
+
+#include "../IHTTPData.h"
+
+class HTTPText : public IHTTPDataIn, public IHTTPDataOut
+{
+public:
+  HTTPText(char* str);
+  HTTPText(char* str, size_t size);
+
+protected:
+  //IHTTPDataIn
+  virtual int read(char* buf, size_t len, size_t* pReadLen);
+
+  virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
+
+  virtual bool getIsChunked(); //For Transfer-Encoding header
+
+  virtual size_t getDataLen(); //For Content-Length header
+
+  //IHTTPDataOut
+  virtual int write(const char* buf, size_t len);
+
+  virtual void setDataType(const char* type); //Internet media type from Content-Type header
+
+  virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
+
+  virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
+
+private:
+  char* m_str;
+  size_t m_size;
+
+  size_t m_pos;
+};
+
+#endif /* HTTPTEXT_H_ */