Mbed asked me to commit the library. Probably because it's an older version

Dependents:   ece4180_project

Fork of HTTPServer by Sarah Marsh

Committer:
leihen
Date:
Sun Jun 02 00:33:56 2013 +0000
Revision:
9:c2a1462b9b71
Parent:
5:dc88012caef1
Child:
16:cc3f5c53d0d5
Some small simplifications and improvements.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leihen 5:dc88012caef1 1 /* FsHandler.cpp */
leihen 5:dc88012caef1 2 #include "mbed.h"
leihen 5:dc88012caef1 3 #include "RpcHandler.h"
leihen 5:dc88012caef1 4 #include "mbed_rpc.h"
leihen 5:dc88012caef1 5
leihen 5:dc88012caef1 6
leihen 9:c2a1462b9b71 7 #define _DEBUG 0
leihen 5:dc88012caef1 8
leihen 5:dc88012caef1 9 #if (_DEBUG && !defined(TARGET_LPC11U24))
leihen 5:dc88012caef1 10 #define INFO(x, ...) std::printf("[HTTPRpcHandler : DBG]"x"\r\n", ##__VA_ARGS__);
leihen 5:dc88012caef1 11 #define WARN(x, ...) std::printf("[HTTPRpcHandler : DBG]"x"\r\n", ##__VA_ARGS__);
leihen 5:dc88012caef1 12 #define ERR(x, ...) std::printf("[HTTPRpcHandler : DBG]"x"\r\n", ##__VA_ARGS__);
leihen 5:dc88012caef1 13 #else
leihen 5:dc88012caef1 14 #define INFO(x, ...)
leihen 5:dc88012caef1 15 #define WARN(x, ...)
leihen 5:dc88012caef1 16 #define ERR(x, ...)
leihen 5:dc88012caef1 17 #endif
leihen 5:dc88012caef1 18
leihen 5:dc88012caef1 19 RPC rpc("rpc");
leihen 5:dc88012caef1 20
leihen 5:dc88012caef1 21
leihen 5:dc88012caef1 22 HTTPRpcRequestHandler::HTTPRpcRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp)
leihen 5:dc88012caef1 23 : HTTPRequestHandler(Msg, Tcp)
leihen 5:dc88012caef1 24 {
leihen 5:dc88012caef1 25 m_rootPath = rootPath;
leihen 5:dc88012caef1 26 m_localPath = localPath;
leihen 5:dc88012caef1 27
leihen 5:dc88012caef1 28 handleRequest();
leihen 5:dc88012caef1 29 }
leihen 5:dc88012caef1 30
leihen 5:dc88012caef1 31
leihen 5:dc88012caef1 32 HTTPRpcRequestHandler::~HTTPRpcRequestHandler()
leihen 5:dc88012caef1 33 {
leihen 5:dc88012caef1 34 }
leihen 5:dc88012caef1 35
leihen 5:dc88012caef1 36
leihen 5:dc88012caef1 37 int HTTPRpcRequestHandler::handleGetRequest()
leihen 5:dc88012caef1 38 {
leihen 5:dc88012caef1 39 char outBuf[256] = {};
leihen 5:dc88012caef1 40 bool retval = false;
leihen 5:dc88012caef1 41 int err = 404;
leihen 5:dc88012caef1 42 string rpc_args("");
leihen 5:dc88012caef1 43
leihen 5:dc88012caef1 44 INFO("Handling RPC Get Requesst.");
leihen 5:dc88012caef1 45 // This version of the RPC handler does only accept native RPC commands in the format
leihen 5:dc88012caef1 46 // /<class>/<method> <argument1> [<argument2> [<argument3> ...]]
leihen 5:dc88012caef1 47 // So we can simply pass our local pathg to our rpc
leihen 5:dc88012caef1 48
leihen 5:dc88012caef1 49 // Append missing slash if needed
leihen 5:dc88012caef1 50 if (m_localPath.c_str()[0] != '/') {
leihen 5:dc88012caef1 51 rpc_args = "/";
leihen 5:dc88012caef1 52 }
leihen 5:dc88012caef1 53 // replace the HTTP strings with ascii strings
leihen 5:dc88012caef1 54 for (int i = 0 ; i < m_localPath.length() ; i++) {
leihen 5:dc88012caef1 55 if (m_localPath.substr(i,3) == "%20") {
leihen 5:dc88012caef1 56 rpc_args += " ";
leihen 5:dc88012caef1 57 i+=2;
leihen 5:dc88012caef1 58 }
leihen 5:dc88012caef1 59 else {
leihen 5:dc88012caef1 60 rpc_args += m_localPath.substr(i,1);
leihen 5:dc88012caef1 61 }
leihen 5:dc88012caef1 62 }
leihen 5:dc88012caef1 63 INFO("RPC to %s", rpc_args.c_str());
leihen 5:dc88012caef1 64 retval = rpc.call(rpc_args.c_str(),outBuf);
leihen 5:dc88012caef1 65 INFO("RPC Request returned %d with args : %s", retval==true ? 1 : 0, outBuf);
leihen 5:dc88012caef1 66 if (retval) {
leihen 5:dc88012caef1 67 // No error
leihen 5:dc88012caef1 68 startResponse(retval, strlen(outBuf));
leihen 5:dc88012caef1 69 processResponse(strlen(outBuf), outBuf);
leihen 5:dc88012caef1 70 endResponse();
leihen 5:dc88012caef1 71 err = 0;
leihen 5:dc88012caef1 72 }
leihen 5:dc88012caef1 73
leihen 5:dc88012caef1 74 return err;
leihen 5:dc88012caef1 75 }
leihen 5:dc88012caef1 76
leihen 5:dc88012caef1 77 int HTTPRpcRequestHandler::handlePutRequest()
leihen 5:dc88012caef1 78 {
leihen 5:dc88012caef1 79 return 404;
leihen 5:dc88012caef1 80 }
leihen 5:dc88012caef1 81
leihen 5:dc88012caef1 82 int HTTPRpcRequestHandler::handlePostRequest()
leihen 5:dc88012caef1 83 {
leihen 5:dc88012caef1 84 return 404;
leihen 5:dc88012caef1 85 }