From 97716977c93a53688f9be972649c1a95d7cd7f11 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Wed, 16 Jan 2013 15:22:29 -0800 Subject: [PATCH] Report an error if RPC subscribe specifies no streams. --- src/cpp/ripple/RPCHandler.cpp | 53 ++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 9f4efee100..bbab259213 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2347,40 +2347,47 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest) if (jvRequest.isMember("streams")) { - for (Json::Value::iterator it = jvRequest["streams"].begin(); it != jvRequest["streams"].end(); it++) + if (jvRequest["streams"].empty()) { - if ((*it).isString()) + jvResult["error"] = "noStreams"; + } + else + { + for (Json::Value::iterator it = jvRequest["streams"].begin(); it != jvRequest["streams"].end(); it++) { - std::string streamName=(*it).asString(); - - if (streamName=="server") + if ((*it).isString()) { - mNetOps->subServer(ispSub, jvResult); + std::string streamName=(*it).asString(); - } - else if (streamName=="ledger") - { - mNetOps->subLedger(ispSub, jvResult); + if (streamName=="server") + { + mNetOps->subServer(ispSub, jvResult); - } - else if (streamName=="transactions") - { - mNetOps->subTransactions(ispSub); + } + else if (streamName=="ledger") + { + mNetOps->subLedger(ispSub, jvResult); - } - else if (streamName=="rt_transactions") - { - mNetOps->subRTTransactions(ispSub); + } + else if (streamName=="transactions") + { + mNetOps->subTransactions(ispSub); + + } + else if (streamName=="rt_transactions") + { + mNetOps->subRTTransactions(ispSub); + } + else + { + jvResult["error"] = str(boost::format("Unknown stream: %s") % streamName); + } } else { - jvResult["error"] = str(boost::format("Unknown stream: %s") % streamName); + jvResult["error"] = "malformedStream"; } } - else - { - jvResult["error"] = "malformedSteam"; - } } }