Single instance HTTP Server using WiFly Interface.

Dependents:   WiFlyHTTPServerSample MultiThreadingHTTPServer

This is my implementation for a HTTP Server using the WiFly Interface. Please note that this is still under development.

It may still contain several bugs. I have tested it using a 1768 on an application board plus RN-XV board.

Currently there is only a FileSystem implemented. Also it is limited to GET request.

I try to extend it further so it will be more useful.

Btw, it does NOT work with RTOS, which seems not to be the Problem of my library.

Do not Forget to Import the WiFly Interface into your Project when using this library.

Change History:

REV5: - added support for basic RPC GET request functionality.

REV4: - added argument parsing from the request uri. - documentation extended and updated.

Handler/RpcHandler.cpp

Committer:
leihen
Date:
2013-06-26
Revision:
14:7f9fbfc18623
Parent:
13:93ff322420b0

File content as of revision 14:7f9fbfc18623:

/* FsHandler.cpp */
#include "mbed.h"
#include "RpcHandler.h"
#include "mbed_rpc.h"


#define DEBUG
#include "debug.h"


RPC rpc("rpc");


HTTPRpcRequestHandler::HTTPRpcRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg)
    : HTTPRequestHandler(Msg)
{
    m_rootPath = rootPath;
    m_localPath = localPath;
    
    handleRequest();
}


HTTPRpcRequestHandler::~HTTPRpcRequestHandler()
{
}


int HTTPRpcRequestHandler::handleGetRequest()
{
    char outBuf[256] = {};
    bool retval = false;
    int err = 404;
    string rpc_args("");
    
    INFO("Handling RPC Get Requesst.");
    // This version of the RPC handler does only accept native RPC commands in the format
    //  /<class>/<method> <argument1> [<argument2> [<argument3> ...]]
    // So we can simply pass our local pathg to our rpc

    //  Append missing slash if needed
    if (m_localPath.c_str()[0] != '/') {
        rpc_args = "/";
    }
    // replace the HTTP strings with ascii strings
    for (int i = 0 ; i < m_localPath.length() ; i++) {
        if (m_localPath.substr(i,3) == "%20") {
            rpc_args += " ";
            i+=2;
        }
        else {
            rpc_args += m_localPath.substr(i,1);
        }
    }
    INFO("RPC to %s", rpc_args.c_str());
    retval = rpc.call(rpc_args.c_str(),outBuf);
    INFO("RPC Request returned %d with args : %s", retval==true ? 1 : 0, outBuf);
    if (retval) {
        //  No error
        startResponse(retval, strlen(outBuf));
        processResponse(strlen(outBuf), outBuf);
        endResponse();
        err = 0;
    }
    
    return err;
}

int HTTPRpcRequestHandler::handlePutRequest()
{
    return 404;
}

int HTTPRpcRequestHandler::handlePostRequest()
{
    return 404;
}