Changes made for RPC

Revision:
3:d6224049b3bf
Parent:
2:8653bbcf7e58
Child:
4:d065642c32cc
--- a/HTTPServer.cpp	Sun May 26 23:22:36 2013 +0000
+++ b/HTTPServer.cpp	Tue May 28 01:56:14 2013 +0000
@@ -6,7 +6,7 @@
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
-#if (0 && !defined(TARGET_LPC11U24))
+#if (1 && !defined(TARGET_LPC11U24))
 #define INFO(x, ...) if (m_pDbg) m_pDbg->printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__); else printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
 #define WARN(x, ...) if (m_pDbg) m_pDbg->printf("[HttpServer : WARN]"x"\r\n", ##__VA_ARGS__); else printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
 #define ERR(x, ...) if (m_pDbg) m_pDbg->printf("[HttpServer : ERR]"x"\r\n", ##__VA_ARGS__); else printf("[HttpServer : DBG]"x"\r\n", ##__VA_ARGS__);
@@ -16,9 +16,9 @@
 #define ERR(x, ...)
 #endif
 
-HTTPServer::HTTPServer(Serial* pDbg)
+HTTPServer::HTTPServer(Serial *dbg)
 {
-    m_pDbg = pDbg;
+    m_pDbg = dbg;
     m_pSvr = NULL;
     m_bServerListening = false;
     m_pErrorHandler = StdErrorHandler;
@@ -36,7 +36,7 @@
 
 const char* szStdErrorPage = "<HTML><HEAD><META content=\"text/html\" http-equiv=Content-Type></HEAD><BODY><h1>Error 404</h1><P>This resource is not available<P></BODY></HTML>\r\n\r\n";
 
-void HTTPServer::StdErrorHandler(HTTPMessage& msg, TCPSocketConnection& tcp)
+void HTTPServer::StdErrorHandler(HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp)
 {
     char echoHeader[512];
     
@@ -132,7 +132,39 @@
     return 0;
 }
 
-void HTTPServer::HandleRequest(HTTPMessage& msg, TCPSocketConnection& tcp)
+void HTTPServer::HandleRequest(HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp)
+{
+    std::string localPath;
+    std::map<std::string, HTTPRequestHandler*(*)(const char*, const char*, HTTPConnection::HTTPMessage&, TCPSocketConnection&), handlersComp>::const_iterator it;
+
+    for (it = m_lpHandlers.begin() ; it != m_lpHandlers.end() ; it++) {
+        //  check if this entries' path is fully contained at the beginning of the requested path
+        std::string curpth = it->first;
+
+        if (msg.uri.find(curpth) == 0) {
+            // handler found
+            localPath = msg.uri.substr(curpth.length());
+            break;
+        }
+    }
+    
+    if (it == m_lpHandlers.end()) {
+        //  There is no such handler, so return invalid
+
+        m_pErrorHandler(msg, tcp);        
+        INFO("Webrequest left unhandled.");
+    }
+    else {
+        INFO("Routing webrequest !");
+
+        HTTPRequestHandler *phdl = (*it->second)(it->first.c_str(), localPath.c_str(), msg, tcp);
+        if (phdl != NULL)
+            delete phdl;
+    }
+    
+}
+/*
+void HTTPServer::HandleRequest(HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp)
 {
     map<string, HTTPRequestHandlerFunction>::iterator it;
     
@@ -149,4 +181,5 @@
         INFO("Routing webrequest !");
         (it->second)(msg, tcp);
     }
-}
\ No newline at end of file
+}
+*/
\ No newline at end of file