Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HTTPServer by
RpcHandler.cpp
00001 /* FsHandler.cpp */ 00002 #include "mbed.h" 00003 #include "RpcHandler.h" 00004 #include "mbed_rpc.h" 00005 00006 00007 #define DEBUG 1 00008 #include "hl_debug.h" 00009 00010 RPC rpc("rpc"); 00011 00012 00013 HTTPRpcRequestHandler::HTTPRpcRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp) 00014 : HTTPRequestHandler(Msg, Tcp) 00015 { 00016 m_rootPath = rootPath; 00017 m_localPath = localPath; 00018 00019 handleRequest(); 00020 } 00021 00022 00023 HTTPRpcRequestHandler::~HTTPRpcRequestHandler() 00024 { 00025 } 00026 00027 00028 int HTTPRpcRequestHandler::handleGetRequest() 00029 { 00030 char outBuf[256] = {}; 00031 bool retval = false; 00032 int err = 404; 00033 string rpc_args(""); 00034 00035 INFO("Handling RPC Get Requesst."); 00036 // This version of the RPC handler does only accept native RPC commands in the format 00037 // /<class>/<method> <argument1> [<argument2> [<argument3> ...]] 00038 // So we can simply pass our local pathg to our rpc 00039 00040 // Append missing slash if needed 00041 if (m_localPath.c_str()[0] != '/') { 00042 rpc_args = "/"; 00043 } 00044 // replace the HTTP strings with ascii strings 00045 for (int i = 0 ; i < m_localPath.length() ; i++) { 00046 if (m_localPath.substr(i,3) == "%20") { 00047 rpc_args += " "; 00048 i+=2; 00049 } 00050 else { 00051 rpc_args += m_localPath.substr(i,1); 00052 } 00053 } 00054 INFO("RPC to %s", rpc_args.c_str()); 00055 retval = rpc.call(rpc_args.c_str(),outBuf); 00056 INFO("RPC Request returned %d with args : %s", retval==true ? 200 : 0, outBuf); 00057 if (retval) { 00058 // No error 00059 startResponse(200, strlen(outBuf)); 00060 processResponse(strlen(outBuf), outBuf); 00061 endResponse(); 00062 err = 0; 00063 } 00064 00065 return err; 00066 } 00067 00068 int HTTPRpcRequestHandler::handlePutRequest() 00069 { 00070 return 404; 00071 } 00072 00073 int HTTPRpcRequestHandler::handlePostRequest() 00074 { 00075 return 404; 00076 }
Generated on Tue Jul 12 2022 19:23:50 by
1.7.2
