From 1b9bf68877522e6cca62c0ccb1df78b7c2910160 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Fri, 1 Feb 2013 19:25:01 -0800 Subject: [PATCH] Have RPCSub use new callRPC. --- src/cpp/ripple/CallRPC.cpp | 41 +++++++++++++++++++--------------- src/cpp/ripple/CallRPC.h | 2 +- src/cpp/ripple/HttpsClient.cpp | 2 +- src/cpp/ripple/RPCSub.cpp | 21 ++++++++++++----- src/cpp/ripple/RPCSub.h | 1 + 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 16c95727ab..7d8ad67e30 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -701,31 +701,36 @@ bool responseRPC( boost::function callbackFuncP, const boost::system::error_code& ecResult, int iStatus, const std::string& strData) { - // Receive reply - if (iStatus == 401) - throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)"); - else if ((iStatus >= 400) && (iStatus != 400) && (iStatus != 404) && (iStatus != 500)) // ? - throw std::runtime_error(strprintf("server returned HTTP error %d", iStatus)); - else if (strData.empty()) - throw std::runtime_error("no response from server"); + if (callbackFuncP) + { + // Only care about the result, if we care to deliver it callbackFuncP. - // Parse reply - cLog(lsDEBUG) << "RPC reply: " << strData << std::endl; + // Receive reply + if (iStatus == 401) + throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)"); + else if ((iStatus >= 400) && (iStatus != 400) && (iStatus != 404) && (iStatus != 500)) // ? + throw std::runtime_error(strprintf("server returned HTTP error %d", iStatus)); + else if (strData.empty()) + throw std::runtime_error("no response from server"); - Json::Reader reader; - Json::Value jvReply; + // Parse reply + cLog(lsDEBUG) << "RPC reply: " << strData << std::endl; - if (!reader.parse(strData, jvReply)) - throw std::runtime_error("couldn't parse reply from server"); + Json::Reader reader; + Json::Value jvReply; - if (jvReply.isNull()) - throw std::runtime_error("expected reply to have result, error and id properties"); + if (!reader.parse(strData, jvReply)) + throw std::runtime_error("couldn't parse reply from server"); - Json::Value jvResult(Json::objectValue); + if (jvReply.isNull()) + throw std::runtime_error("expected reply to have result, error and id properties"); - jvResult["result"] = jvReply; + Json::Value jvResult(Json::objectValue); - (callbackFuncP)(jvResult); + jvResult["result"] = jvReply; + + (callbackFuncP)(jvResult); + } return false; } diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index 939d37a28d..11cf518128 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -55,7 +55,7 @@ extern void callRPC( const std::string& strUsername, const std::string& strPassword, const std::string& strPath, const std::string& strMethod, const Json::Value& jvParams, const bool bSSL, - boost::function callbackFuncP); + boost::function callbackFuncP = 0); #endif // vim:ts=4 diff --git a/src/cpp/ripple/HttpsClient.cpp b/src/cpp/ripple/HttpsClient.cpp index e5b195a645..746e65a92d 100644 --- a/src/cpp/ripple/HttpsClient.cpp +++ b/src/cpp/ripple/HttpsClient.cpp @@ -331,7 +331,7 @@ void HttpsClient::invokeComplete(const boost::system::error_code& ecResult, int // ecResult: !0 = had an error, last entry // iStatus: result, if no error // strData: data, if no error - bAgain = mComplete(ecResult ? ecResult : ecCancel, iStatus, strData); + bAgain = mComplete && mComplete(ecResult ? ecResult : ecCancel, iStatus, strData); } if (!mDeqSites.empty() && bAgain) diff --git a/src/cpp/ripple/RPCSub.cpp b/src/cpp/ripple/RPCSub.cpp index e9369d7b23..28daff00e9 100644 --- a/src/cpp/ripple/RPCSub.cpp +++ b/src/cpp/ripple/RPCSub.cpp @@ -8,7 +8,7 @@ SETUP_LOG(); RPCSub::RPCSub(const std::string& strUrl, const std::string& strUsername, const std::string& strPassword) - : mUrl(strUrl), mUsername(strUsername), mPassword(strPassword) + : mUrl(strUrl), mSSL(false), mUsername(strUsername), mPassword(strPassword) { std::string strScheme; @@ -16,17 +16,22 @@ RPCSub::RPCSub(const std::string& strUrl, const std::string& strUsername, const { throw std::runtime_error("Failed to parse url."); } + else if (strScheme == "https") + { + mSSL = true; + } else if (strScheme != "http") { - throw std::runtime_error("Only http is supported."); + throw std::runtime_error("Only http and https is supported."); } mSeq = 1; if (mPort < 0) - mPort = 80; + mPort = mSSL ? 443 : 80; } +// XXX Could probably create a bunch of send jobs in a single get of the lock. void RPCSub::sendThread() { Json::Value jvEvent; @@ -59,12 +64,18 @@ void RPCSub::sendThread() // Send outside of the lock. if (bSend) { + // XXX Might not need this in a try. try { cLog(lsDEBUG) << boost::str(boost::format("callRPC calling: %s") % mIp); - // Drop result. -// (void) callRPC(theApp->getIOService(), mIp, mPort, mUsername, mPassword, mPath, "event", jvEvent); + callRPC( + theApp->getIOService(), + mIp, mPort, + mUsername, mPassword, + mPath, "event", + jvEvent, + mSSL); } catch (const std::exception& e) { diff --git a/src/cpp/ripple/RPCSub.h b/src/cpp/ripple/RPCSub.h index 8cca3e7f59..dc2270a6da 100644 --- a/src/cpp/ripple/RPCSub.h +++ b/src/cpp/ripple/RPCSub.h @@ -15,6 +15,7 @@ class RPCSub : public InfoSub std::string mUrl; std::string mIp; int mPort; + bool mSSL; std::string mUsername; std::string mPassword; std::string mPath;