Fix small buglets.

This commit is contained in:
JoelKatz
2012-12-06 18:59:34 -08:00
parent 2e425d60fd
commit a17babcfaf
2 changed files with 7 additions and 107 deletions

View File

@@ -1,102 +0,0 @@
//
// WSConnection
//
#include "Log.h"
SETUP_LOG();
#include "CallRPC.h" // XXX Remove this, don't provide support for RPC syntax.
#include "WSConnection.h"
#include "WSHandler.h"
#include "../json/reader.h"
#include "../json/writer.h"
//template <typename endpoint_type>
//WSConnection::~WSConnection()
//template WSConnection::~WSConnection<server>();
//template WSConnection::~WSConnection<server_tls>();
template <typename endpoint_type>
void WSConnection<endpoint_type>::send(const Json::Value& jvObj)
{
mHandler->send(mConnection, jvObj);
}
template void WSConnection::send<server>(const Json::Value& jvObj);
template void WSConnection::send<server_tls>(const Json::Value& jvObj);
//
// Utilities
//
template <typename endpoint_type>
Json::Value WSConnection::invokeCommand(Json::Value& jvRequest)
{
if (!jvRequest.isMember("command"))
{
Json::Value jvResult(Json::objectValue);
jvResult["type"] = "response";
jvResult["result"] = "error";
jvResult["error"] = "missingCommand";
jvResult["command"] = jvRequest;
return jvResult;
}
RPCHandler mRPCHandler(&mNetwork, this);
Json::Value jvResult(Json::objectValue);
// XXX Temporarily support RPC style commands over websocket. Remove this.
if (jvRequest.isMember("params"))
{
RPCParser rpParser;
Json::Value jvRpcRequest = rpParser.parseCommand(jvRequest["command"].asString(), jvRequest["params"]);
if (jvRpcRequest.isMember("error"))
{
jvResult = jvRpcRequest;
}
else
{
jvResult["result"] = mRPCHandler.doCommand(
jvRpcRequest,
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
}
}
else
{
jvResult["result"] = mRPCHandler.doCommand(
jvRequest,
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
}
// Currently we will simply unwrap errors returned by the RPC
// API, in the future maybe we can make the responses
// consistent.
//
// Regularize result. This is duplicate code.
if (jvResult["result"].isMember("error"))
{
jvResult = jvResult["result"];
jvResult["status"] = "error";
jvResult["request"] = jvRequest;
} else {
jvResult["status"] = "success";
}
if (jvRequest.isMember("id"))
{
jvResult["id"] = jvRequest["id"];
}
jvResult["type"] = "response";
return jvResult;
}
// vim:ts=4

View File

@@ -76,7 +76,7 @@ public:
{
boost::mutex::scoped_lock sl(mMapLock);
mMap[cpClient] = boost::make_shared<WSConnection>(this, cpClient);
mMap[cpClient] = boost::make_shared< WSConnection<endpoint_type> >(this, cpClient);
}
void on_close(connection_ptr cpClient)
@@ -115,7 +115,7 @@ public:
}
else
{
boost::shared_ptr<WSConnection> conn;
boost::shared_ptr< WSConnection<endpoint_type> > conn;
{
boost::mutex::scoped_lock sl(mMapLock);
conn = mMap[cpClient];
@@ -136,9 +136,11 @@ public:
context->set_options(boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::single_dh_use);
context->set_password_callback(boost::bind(&type::get_password, this));
context->use_certificate_chain_file(theConfig.WEBSOCKET_SSL_CERT);
context->use_private_key_file(theConfig.WEBSOCKET_SSL_CERT, boost::asio::ssl::context::pem);
// context->set_password_callback(boost::bind(&type::get_password, this));
if (!theConfig.WEBSOCKET_SSL_CERT.empty())
context->use_private_key_file(theConfig.WEBSOCKET_SSL_CERT, boost::asio::ssl::context::pem);
if (!theConfig.WEBSOCKET_SSL_CHAIN.empty())
context->use_certificate_chain_file(theConfig.WEBSOCKET_SSL_CHAIN);
//context->use_tmp_dh_file("../../src/ssl/dh512.pem");
} catch (std::exception& e) {
std::cout << e.what() << std::endl;