NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Mon Jun 14 10:33:54 2010 +0000
Parent:
0:632c9925f013
Child:
2:a4f97773c90f
Commit message:

Changed in this revision

if/lwip/lwipNetUdpSocket.cpp Show annotated file Show diff for this revision Revisions of this file
netCfg.h Show annotated file Show diff for this revision Revisions of this file
services/email/emailMessage.cpp Show annotated file Show diff for this revision Revisions of this file
services/email/emailMessage.h Show annotated file Show diff for this revision Revisions of this file
services/email/smtp/SMTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPRequestDispatcher.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPRequestDispatcher.h Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPServer.h Show annotated file Show diff for this revision Revisions of this file
services/http/server/impl/FSHandler.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/server/impl/FSHandler.h Show annotated file Show diff for this revision Revisions of this file
services/http/server/impl/RPCHandler.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/if/lwip/lwipNetUdpSocket.cpp	Fri Jun 11 16:05:15 2010 +0000
+++ b/if/lwip/lwipNetUdpSocket.cpp	Mon Jun 14 10:33:54 2010 +0000
@@ -35,11 +35,11 @@
   DBG("\r\nNew NetUdpSocket %p\r\n", (void*)this);
   if(!m_pPcb)
     m_pPcb = udp_new();
-  if(m_pPcb)
+ /* if(m_pPcb)
   {
     //Setup callback
    // udp_recv( (udp_pcb*) m_pPcb, LwipNetUdpSocket::sRecvCb, (void*) this );
-  }
+  }*/
 }
 
 LwipNetUdpSocket::~LwipNetUdpSocket()
@@ -52,9 +52,9 @@
   if(!m_pPcb)
     return NETUDPSOCKET_MEM; //NetUdpSocket was not properly initialised, should destroy it & retry
     
-/*  err_t err = udp_bind( (udp_pcb*) m_pPcb, IP_ADDR_ANY, me.getPort()); //IP_ADDR_ANY : Bind the connection to all local addresses
+  err_t err = udp_bind( (udp_pcb*) m_pPcb, IP_ADDR_ANY, me.getPort()); //IP_ADDR_ANY : Bind the connection to all local addresses
   if(err)
-    return NETUDPSOCKET_INUSE;*/
+    return NETUDPSOCKET_INUSE;
     
   //Setup callback
   udp_recv( (udp_pcb*) m_pPcb, LwipNetUdpSocket::sRecvCb, (void*) this );
--- a/netCfg.h	Fri Jun 11 16:05:15 2010 +0000
+++ b/netCfg.h	Mon Jun 14 10:33:54 2010 +0000
@@ -1,26 +1,12 @@
 #ifndef NET_CFG_H
-#define NET_CFG_H
-
-//Configure build params for TCP/IP Stack
-
-//Build GPRS Module (eg Telit Module) If
-#define NET_GPRS 0
-
-#define NET_TELIT 0
-
-//Build PPP If
-#define NET_PPP 0
-
-//Build Usb Host Stack
-#define NET_USB 0
-
-//Build Usb Virtual Serial Port
+#define NET_TELIT_STACK 0
+#define NET_GPRS 1
+#define NET_PPP 1
+#define NET_ZG2100 0
+#define NET_ETH 1
 #define NET_USB_SERIAL 0
-
-//Build Ethernet If
-#define NET_ETH 0
-
-//Build LWIP Stack
-#define NET_LWIP_STACK 0
-
-#endif
\ No newline at end of file
+#define NET_TELIT 1
+#define NET_CFG_H 1
+#define NET_USB 1
+#define NET_LWIP_STACK 1
+#endif
--- a/services/email/emailMessage.cpp	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/email/emailMessage.cpp	Mon Jun 14 10:33:54 2010 +0000
@@ -30,7 +30,7 @@
 
 #define BUF_SIZE 512
 
-EmailMessage::EmailMessage(SmtpClient* pClient) : m_lTo(), m_from(), m_content(), m_pClient(pClient)
+EmailMessage::EmailMessage(SMTPClient* pClient) : m_lTo(), m_from(), m_content(), m_pClient(pClient)
 {
 
 }
--- a/services/email/emailMessage.h	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/email/emailMessage.h	Mon Jun 14 10:33:54 2010 +0000
@@ -24,9 +24,9 @@
 #ifndef EMAIL_MESSAGE_H
 #define EMAIL_MESSAGE_H
 
-class SmtpClient;
+class SMTPClient;
 
-#include "smtp/smtpClient.h"
+#include "smtp/SMTPClient.h"
 
 #include <queue>
 using std::queue;
@@ -37,7 +37,7 @@
 class EmailMessage
 {
 public:
-  EmailMessage(SmtpClient* pClient);
+  EmailMessage(SMTPClient* pClient);
   ~EmailMessage();
   
   void setFrom(const char* from);
@@ -50,13 +50,13 @@
   //int scanf(const char* format, ... ); 
   
 private:
-  friend class SmtpClient;
+  friend class SMTPClient;
   queue<string> m_lTo;
   string m_from;
   
   string m_content;
   
-  SmtpClient* m_pClient;
+  SMTPClient* m_pClient;
 
 };
 
--- a/services/email/smtp/SMTPClient.cpp	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/email/smtp/SMTPClient.cpp	Mon Jun 14 10:33:54 2010 +0000
@@ -21,7 +21,7 @@
 THE SOFTWARE.
 */
 
-#include "smtpClient.h"
+#include "SMTPClient.h"
 
 #if 0
 
--- a/services/http/server/HTTPRequestDispatcher.cpp	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/http/server/HTTPRequestDispatcher.cpp	Mon Jun 14 10:33:54 2010 +0000
@@ -42,13 +42,13 @@
 void HTTPRequestDispatcher::dispatchRequest()
 {
   string rootPath;
-  string fullPath;
+  string subPath;
   string meth;
   HTTP_METH methCode;
   
   DBG("\r\nDispatching req\r\n");
   
-  if( !getRequest(&rootPath, &fullPath, &meth ) )
+  if( !getRequest(&rootPath, &subPath, &meth ) )
   {
     close();
     return; //Invalid request
@@ -88,7 +88,7 @@
   
   DBG("\r\nHandler found.\r\n");
   
-  HTTPRequestHandler* pHdlr = (*it).second(rootPath.c_str(), fullPath.c_str(), m_pTCPSocket);
+  HTTPRequestHandler* pHdlr = (*it).second(rootPath.c_str(), subPath.c_str(), m_pTCPSocket);
   m_pTCPSocket = NULL; //We don't own it anymore
   
   switch(methCode)
@@ -129,7 +129,7 @@
   close();
 }
 
-bool HTTPRequestDispatcher::getRequest(string* rootPath, string* fullPath, string* meth)
+bool HTTPRequestDispatcher::getRequest(string* rootPath, string* subPath, string* meth)
 {
   char req[128];
   char c_path[128];
@@ -169,18 +169,29 @@
     return false;
     
   *meth = string(c_meth);
-  *fullPath = string(c_path);
+  *subPath = string(c_path);
   
   c_path[0]= '/';
-  ret = sscanf(req, "%*s /%[^/ ]%*s HTTP/%*d.%*d", c_path+1);
-  if(ret !=1)
+  if(!strchr(c_path+1, '/'))
+  {
+    //Not found, so this is the root path
+    c_path[1]=0;
+    *rootPath = string(c_path); 
+  } 
+  else
   {
-    //This is the root path
+    ret = sscanf(req, "%*s /%[^/ ]/%*s HTTP/%*d.%*d", c_path+1);
+    if(ret !=1)
+    {
+      //This is the root path
+      DBG("Default path\n");
+    }
+    *rootPath = string(c_path); 
+    subPath->erase(0,rootPath->length());
   }
-       
-  *rootPath = string(c_path);
+  
   
-  DBG("\r\nParse OK :\r\nRoot Path : %s\r\nFull Path : %s\r\nMethod Path : %s\r\n", rootPath->c_str(), fullPath->c_str(), meth->c_str());
+  DBG("\r\nParse OK :\r\nRoot Path: %s\r\nSub Path: %s\r\nMethod: %s\r\n", rootPath->c_str(), subPath->c_str(), meth->c_str());
   
   return true;
 
--- a/services/http/server/HTTPRequestDispatcher.h	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/http/server/HTTPRequestDispatcher.h	Mon Jun 14 10:33:54 2010 +0000
@@ -60,7 +60,7 @@
   
   void onTimeout(); //Connection has timed out
 
-  bool getRequest(string* rootPath, string* fullPath, string* meth);
+  bool getRequest(string* rootPath, string* subPath, string* meth);
   
   HTTPServer* m_pSvr;
   TCPSocket* m_pTCPSocket;
--- a/services/http/server/HTTPServer.h	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/http/server/HTTPServer.h	Mon Jun 14 10:33:54 2010 +0000
@@ -60,7 +60,7 @@
 };
 
 //Including handlers here for more convenience
-#include "impl/RpcHandler.h"
+#include "impl/RPCHandler.h"
 #include "impl/FSHandler.h"
 #include "impl/SimpleHandler.h"
 
--- a/services/http/server/impl/FSHandler.cpp	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/http/server/impl/FSHandler.cpp	Mon Jun 14 10:33:54 2010 +0000
@@ -28,9 +28,6 @@
 
 #define CHUNK_SIZE 512//128
 
-//LocalFileSystem local("webfs");
-//LocalFileSystem FSHandler_fs("webfs");
-
 FSHandler::FSHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket), m_err404(false)
 {}
 
@@ -41,11 +38,20 @@
   DBG("\r\nHandler destroyed\r\n");
 }
 
+//static init
+map<string,string> FSHandler::m_lFsPath = map<string,string>();
+
+void FSHandler::mount(const string& fsPath, const string& rootPath)
+{
+  m_lFsPath[rootPath]=fsPath;
+}
+
 void FSHandler::doGet()
 {
   DBG("\r\nIn FSHandler::doGet()\r\n");
   //FIXME: Translate path to local/path
-  m_fp = fopen(path().c_str(), "r"); //FIXME: if null, error 404
+  string filePath = m_lFsPath[rootPath()] + path();
+  m_fp = fopen(filePath.c_str(), "r"); //FIXME: if null, error 404
   
   if(!m_fp)
   {
--- a/services/http/server/impl/FSHandler.h	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/http/server/impl/FSHandler.h	Mon Jun 14 10:33:54 2010 +0000
@@ -27,11 +27,19 @@
 #include "../HTTPRequestHandler.h"
 #include "mbed.h"
 
+#include <map>
+using std::map;
+
+#include <string>
+using std::string;
+
 class FSHandler : public HTTPRequestHandler
 {
 public:
   FSHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
   virtual ~FSHandler();
+  
+  static void mount(const string& fsPath, const string& rootPath);
 
 //protected:
   static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new FSHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one
@@ -47,6 +55,7 @@
 private:
   FILE* m_fp;
   bool m_err404;
+  static map<string,string> m_lFsPath;
 };
 
 #endif
--- a/services/http/server/impl/RPCHandler.cpp	Fri Jun 11 16:05:15 2010 +0000
+++ b/services/http/server/impl/RPCHandler.cpp	Mon Jun 14 10:33:54 2010 +0000
@@ -47,7 +47,7 @@
   DBG("\r\nRoot Path : %s\r\n", rootPath().c_str());
   
   //Remove path
-  strncpy(req, path().c_str() + rootPath().length(), RPC_DATA_LEN-1);
+  strncpy(req, path().c_str(), RPC_DATA_LEN-1);
   DBG("\r\nRPC req : %s\r\n", req);
   
   //Remove %20, +, from req