NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Revision:
1:abb442332fa8
Parent:
0:632c9925f013
Child:
2:a4f97773c90f
--- 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;