HttpServer Library for "mbed-os" which added a snapshot handler.

Dependents:   GR-PEACH-webcam GR-Boards_WebCamera GR-Boards_WebCamera GR-Boards_WebCamera

Fork of HttpServer_snapshot by Renesas

Revision:
4:1b6b021ee21d
Parent:
3:87c6439f4136
Child:
5:b8f6a11c70db
--- a/Handler/RPCHandler.cpp	Thu Feb 20 13:11:34 2014 +0000
+++ b/Handler/RPCHandler.cpp	Fri Feb 21 07:10:30 2014 +0000
@@ -5,10 +5,10 @@
 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
@@ -17,13 +17,13 @@
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */
+#ifdef _DEBUG_ALL
+#define _DEBUG_RPC_HANDLER
+#endif
 
 #include "RPCHandler.h"
 #include "mbed_rpc.h"
 
-//#define __DEBUG
-//#include "dbg/dbg.h"
-
 #define RPC_DATA_LEN 128
 
 RPCHandler::RPCHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : HTTPRequestHandler(rootPath, path, pTCPSocketConnection)
@@ -31,42 +31,53 @@
 
 RPCHandler::~RPCHandler()
 {
-  printf("\r\nHandler destroyed\r\n");
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nHandler destroyed\r\n");
+#endif
 }
 
 void RPCHandler::doGet()
 {
-  printf("\r\nIn RPCHandler::doGet()\r\n");
-  char resp[RPC_DATA_LEN] = {0};
-  char req[RPC_DATA_LEN] = {0};
-  
-  printf("\r\nPath : %s\r\n", path().c_str());
-  printf("\r\nRoot Path : %s\r\n", rootPath().c_str());
-  
-  //Remove path
-  strncpy(req, path().c_str(), RPC_DATA_LEN-1);
-  printf("\r\nRPC req : %s\r\n", req);
-  
-  //Remove %20, +, from req
-  cleanReq(req);
-  printf("\r\nRPC req : %s\r\n", req);
-  
-  //Do RPC Call
-  RPC::call(req, resp); //FIXME: Use bool result
-  
-  //Response
-  setContentLen( strlen(resp) );
-  
-  //Make sure that the browser won't cache this request
-  respHeaders()["Cache-control"]="no-cache;no-store";
- // respHeaders()["Cache-control"]="no-store";
-  respHeaders()["Pragma"]="no-cache";
-  respHeaders()["Expires"]="0";
-  
-  //Write data
-  respHeaders()["Connection"] = "close";
-  writeData(resp, strlen(resp));
-  printf("\r\nExit RPCHandler::doGet()\r\n");
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nIn RPCHandler::doGet()\r\n");
+#endif
+    char resp[RPC_DATA_LEN] = {0};
+    char req[RPC_DATA_LEN] = {0};
+
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nPath : %s\r\n", path().c_str());
+    printf("\r\nRoot Path : %s\r\n", rootPath().c_str());
+#endif
+    //Remove path
+    strncpy(req, path().c_str(), RPC_DATA_LEN-1);
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nRPC req : %s\r\n", req);
+#endif
+    //Remove %20, +, from req
+    cleanReq(req);
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nRPC req : %s\r\n", req);
+#endif
+    //Do RPC Call
+    RPC::call(req, resp); //FIXME: Use bool result
+#ifdef _DEBUG_RPC_HANDLER
+    printf("RPC Response %s \r\n",resp);
+#endif
+    //Response
+    setContentLen( strlen(resp) );
+
+    //Make sure that the browser won't cache this request
+    respHeaders()["Cache-control"]="no-cache;no-store";
+// respHeaders()["Cache-control"]="no-store";
+    respHeaders()["Pragma"]="no-cache";
+    respHeaders()["Expires"]="0";
+
+    //Write data
+    respHeaders()["Connection"] = "close";
+    writeData(resp, strlen(resp));
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nExit RPCHandler::doGet()\r\n");
+#endif
 }
 
 void RPCHandler::doPost()
@@ -79,7 +90,7 @@
 
 }
 
-  
+
 void RPCHandler::onReadable() //Data has been read
 {
 
@@ -87,26 +98,38 @@
 
 void RPCHandler::onWriteable() //Data has been written & buf is free
 {
-  printf("\r\nRPCHandler::onWriteable() event\r\n");
-  close(); //Data written, we can close the connection
+#ifdef _DEBUG_RPC_HANDLER
+    printf("\r\nRPCHandler::onWriteable() event\r\n");
+#endif
+    close(); //Data written, we can close the connection
 }
 
 void RPCHandler::onClose() //Connection is closing
 {
-  //Nothing to do
+    //Nothing to do
 }
 
 void RPCHandler::cleanReq(char* data)
 {
-  char* p;
-  if((p = strstr(data, "+"))!=NULL)memset((void*) p, ' ', 1);
-  else if((p = strstr(data, "%20"))!=NULL){
-      memset((void*) p, ' ', 1);
-       while(*(p+2)!=NULL){
-           p++;
-      memset((void*) p,*(p+2),1);
-      }
-  }
-  
+    char* p;
+    if((p = strstr(data, "+"))!=NULL)memset((void*) p, ' ', 1);
+    else if((p = strstr(data, ","))!=NULL)memset((void*) p, ' ', 1);
+    else if((p = strstr(data, "%20"))!=NULL) {
+        memset((void*) p, ' ', 1);
+        while(*(p+2)!=NULL) {
+            p++;
+            memset((void*) p,*(p+2),1);
+        }
+    }
+
+    if((p = strstr(data, "+"))!=NULL)memset((void*) p, ' ', 1);
+    else if((p = strstr(data, ","))!=NULL)memset((void*) p, ' ', 1);
+    else if((p = strstr(data, "%20"))!=NULL) {
+        memset((void*) p, ' ', 1);
+        while(*(p+2)!=NULL) {
+            p++;
+            memset((void*) p,*(p+2),1);
+        }
+    }
 }
-  
\ No newline at end of file
+