HttpServer Library for "mbed classic" which added a snapshot handler.
Dependents: GR-PEACH_WebCamera_OV5642_fixedIP GR-PEACH_WebCamera_AP
Fork of HttpServer by
RPCHandler.cpp
00001 /* 00002 Permission is hereby granted, free of charge, to any person obtaining a copy 00003 of this software and associated documentation files (the "Software"), to deal 00004 in the Software without restriction, including without limitation the rights 00005 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00006 copies of the Software, and to permit persons to whom the Software is 00007 furnished to do so, subject to the following conditions: 00008 00009 The above copyright notice and this permission notice shall be included in 00010 all copies or substantial portions of the Software. 00011 00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00018 THE SOFTWARE. 00019 */ 00020 00021 //#define _DEBUG_RPC_HANDLER 00022 00023 #include "RPCHandler.h" 00024 #include "mbed_rpc.h" 00025 00026 #define RPC_DATA_LEN 128 00027 00028 RPCHandler::RPCHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : HTTPRequestHandler(rootPath, path, pTCPSocketConnection) 00029 {} 00030 00031 RPCHandler::~RPCHandler() 00032 { 00033 #ifdef _DEBUG_RPC_HANDLER 00034 printf("++++(RPC Handler)Handler destroyed\r\n"); 00035 #endif 00036 } 00037 00038 void RPCHandler::doGet() 00039 { 00040 #ifdef _DEBUG_RPC_HANDLER 00041 printf("++++(RPC Handler)doGet\r\n"); 00042 #endif 00043 char resp[RPC_DATA_LEN] = {0}; 00044 char req[RPC_DATA_LEN] = {0}; 00045 00046 #ifdef _DEBUG_RPC_HANDLER 00047 printf("++++(RPC Handler)Path : %s\r\n", path().c_str()); 00048 printf("++++(RPC Handler)Root Path : %s\r\n", rootPath().c_str()); 00049 #endif 00050 //Remove path 00051 strncpy(req, path().c_str(), RPC_DATA_LEN-1); 00052 #ifdef _DEBUG_RPC_HANDLER 00053 printf("++++(RPC Handler)RPC req(before) : %s\r\n", req); 00054 #endif 00055 //Remove "%20", "+", "," from req 00056 cleanReq(req); 00057 #ifdef _DEBUG_RPC_HANDLER 00058 printf("++++(RPC Handler)RPC req(after) : %s\r\n", req); 00059 #endif 00060 //Do RPC Call 00061 RPC::call(req, resp); //FIXME: Use bool result 00062 #ifdef _DEBUG_RPC_HANDLER 00063 printf("++++(RPC Handler)Response %s \r\n",resp); 00064 #endif 00065 //Response 00066 setContentLen( strlen(resp) ); 00067 00068 //Make sure that the browser won't cache this request 00069 respHeaders()["Cache-control"]="no-cache;no-store"; 00070 respHeaders()["Pragma"]="no-cache"; 00071 respHeaders()["Expires"]="0"; 00072 00073 //Write data 00074 respHeaders()["Connection"] = "close"; 00075 writeData(resp, strlen(resp)); 00076 #ifdef _DEBUG_RPC_HANDLER 00077 printf("++++(RPC Handler)Exit RPCHandler::doGet()\r\n"); 00078 #endif 00079 } 00080 00081 void RPCHandler::doPost() 00082 { 00083 00084 } 00085 00086 void RPCHandler::doHead() 00087 { 00088 00089 } 00090 00091 00092 void RPCHandler::onReadable() //Data has been read 00093 { 00094 00095 } 00096 00097 void RPCHandler::onWriteable() //Data has been written & buf is free 00098 { 00099 #ifdef _DEBUG_RPC_HANDLER 00100 printf("++++(RPC Handler)onWriteable event\r\n"); 00101 #endif 00102 // close(); //Data written, we can close the connection 00103 } 00104 00105 void RPCHandler::onClose() //Connection is closing 00106 { 00107 //Nothing to do 00108 } 00109 00110 void RPCHandler::cleanReq(char* data) 00111 { 00112 char* p; 00113 if((p = strstr(data, "+"))!=NULL)memset((void*) p, ' ', 1); 00114 else if((p = strstr(data, ","))!=NULL)memset((void*) p, ' ', 1); 00115 else if((p = strstr(data, "%20"))!=NULL) { 00116 memset((void*) p, ' ', 1); 00117 while(*(p+2)!=NULL) { 00118 p++; 00119 memset((void*) p,*(p+2),1); 00120 } 00121 } 00122 00123 if((p = strstr(data, "+"))!=NULL)memset((void*) p, ' ', 1); 00124 else if((p = strstr(data, ","))!=NULL)memset((void*) p, ' ', 1); 00125 else if((p = strstr(data, "%20"))!=NULL) { 00126 memset((void*) p, ' ', 1); 00127 while(*(p+2)!=NULL) { 00128 p++; 00129 memset((void*) p,*(p+2),1); 00130 } 00131 } 00132 } 00133 00134
Generated on Sat Jul 16 2022 00:30:13 by 1.7.2