summaryrefslogtreecommitdiff
path: root/src/HttpServerBodyCommand.cc
diff options
context:
space:
mode:
authorNils Maier <maierman@web.de>2014-05-17 17:31:21 +0200
committerNils Maier <maierman@web.de>2014-05-20 12:53:39 +0200
commit855dfa0e2f8ca7869d28d2afc21fed2e3790549a (patch)
treee156bebeee259fa0213611a54d3ed169c1c04ad7 /src/HttpServerBodyCommand.cc
parent88b61f2eb97faa5fad1a0dd882ef1d1ade48c8df (diff)
Authorize RPC multicalls only once.
Cache the auth status afterwards and just assume the token still matches (within the same request, of course).
Diffstat (limited to 'src/HttpServerBodyCommand.cc')
-rw-r--r--src/HttpServerBodyCommand.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc
index 6c0b58e0..8479f3f8 100644
--- a/src/HttpServerBodyCommand.cc
+++ b/src/HttpServerBodyCommand.cc
@@ -243,6 +243,7 @@ bool HttpServerBodyCommand::execute()
case RPC_TYPE_JSONP: {
std::string callback;
std::unique_ptr<ValueBase> json;
+ auto preauthorized = rpc::RpcRequest::MUST_AUTHORIZE;
ssize_t error = 0;
if(httpServer_->getRequestType() == RPC_TYPE_JSONP) {
json::JsonGetParam param = json::decodeGetParams(query);
@@ -273,7 +274,8 @@ bool HttpServerBodyCommand::execute()
}
Dict* jsondict = downcast<Dict>(json);
if(jsondict) {
- rpc::RpcResponse res = rpc::processJsonRpcRequest(jsondict, e_);
+ rpc::RpcResponse res =
+ rpc::processJsonRpcRequest(jsondict, e_, preauthorized);
sendJsonRpcResponse(res, callback);
} else {
List* jsonlist = downcast<List>(json);
@@ -283,8 +285,13 @@ bool HttpServerBodyCommand::execute()
for(List::ValueType::const_iterator i = jsonlist->begin(),
eoi = jsonlist->end(); i != eoi; ++i) {
Dict* jsondict = downcast<Dict>(*i);
- if(jsondict) {
- results.push_back(rpc::processJsonRpcRequest(jsondict, e_));
+ if (jsondict) {
+ auto resp =
+ rpc::processJsonRpcRequest(jsondict, e_, preauthorized);
+ if (resp.code == 0) {
+ preauthorized = rpc::RpcRequest::PREAUTHORIZED;
+ }
+ results.push_back(std::move(resp));
}
}
sendJsonRpcBatchResponse(results, callback);