diff options
| author | Nils Maier <maierman@web.de> | 2014-05-17 17:31:21 +0200 |
|---|---|---|
| committer | Nils Maier <maierman@web.de> | 2014-05-20 12:53:39 +0200 |
| commit | 855dfa0e2f8ca7869d28d2afc21fed2e3790549a (patch) | |
| tree | e156bebeee259fa0213611a54d3ed169c1c04ad7 /src/WebSocketSession.cc | |
| parent | 88b61f2eb97faa5fad1a0dd882ef1d1ade48c8df (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/WebSocketSession.cc')
| -rw-r--r-- | src/WebSocketSession.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/WebSocketSession.cc b/src/WebSocketSession.cc index 86fb08d2..aced5622 100644 --- a/src/WebSocketSession.cc +++ b/src/WebSocketSession.cc @@ -161,6 +161,7 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx, // TODO Only process text frame ssize_t error = 0; auto json = wsSession->parseFinal(nullptr, 0, error); + auto preauthorized = RpcRequest::MUST_AUTHORIZE; if(error < 0) { A2_LOG_INFO("Failed to parse JSON-RPC request"); RpcResponse res @@ -169,9 +170,10 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx, return; } Dict* jsondict = downcast<Dict>(json); + auto e = wsSession->getDownloadEngine(); if(jsondict) { - RpcResponse res = processJsonRpcRequest(jsondict, - wsSession->getDownloadEngine()); + RpcResponse res = + processJsonRpcRequest(jsondict, e, preauthorized); addResponse(wsSession, res); } else { List* jsonlist = downcast<List>(json); @@ -181,9 +183,12 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx, for(List::ValueType::const_iterator i = jsonlist->begin(), eoi = jsonlist->end(); i != eoi; ++i) { Dict* jsondict = downcast<Dict>(*i); - if(jsondict) { - results.push_back(processJsonRpcRequest - (jsondict, wsSession->getDownloadEngine())); + if (jsondict) { + auto resp = processJsonRpcRequest(jsondict, e, preauthorized); + if (resp.code == 0) { + preauthorized = RpcRequest::PREAUTHORIZED; + } + results.push_back(std::move(resp)); } } addResponse(wsSession, results); |
