summaryrefslogtreecommitdiff
path: root/src/WebSocketSession.cc
diff options
context:
space:
mode:
authorNils Maier <maierman@web.de>2014-07-15 08:15:46 +0200
committerNils Maier <maierman@web.de>2014-07-22 21:58:30 +0200
commit8f2af33b6dd33e7937480e37f06d325e812dee8f (patch)
treeb74350f9d538150246e22551ac65b20c92cf466c /src/WebSocketSession.cc
parent24ae459523e4a41c711990b04bd9ed6f1222f559 (diff)
Delay auth failures instead of PBKDF2
Closes GH-256
Diffstat (limited to 'src/WebSocketSession.cc')
-rw-r--r--src/WebSocketSession.cc37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/WebSocketSession.cc b/src/WebSocketSession.cc
index aced5622..b035eb18 100644
--- a/src/WebSocketSession.cc
+++ b/src/WebSocketSession.cc
@@ -43,6 +43,8 @@
#include "RecoverableException.h"
#include "message.h"
#include "DownloadEngine.h"
+#include "DelayedCommand.h"
+#include "WebSocketInteractionCommand.h"
#include "rpc_helper.h"
#include "RpcResponse.h"
#include "json.h"
@@ -111,8 +113,9 @@ ssize_t recvCallback(wslay_event_context_ptr wsctx,
namespace {
void addResponse(WebSocketSession* wsSession, const RpcResponse& res)
{
+ bool notauthorized = rpc::not_authorized(res);
std::string response = toJson(res, "", false);
- wsSession->addTextMessage(response);
+ wsSession->addTextMessage(response, notauthorized);
}
} // namespace
@@ -120,8 +123,9 @@ namespace {
void addResponse(WebSocketSession* wsSession,
const std::vector<RpcResponse>& results)
{
+ bool notauthorized = rpc::any_not_authorized(results.begin(), results.end());
std::string response = toJsonBatch(results, "", false);
- wsSession->addTextMessage(response);
+ wsSession->addTextMessage(response, notauthorized);
}
} // namespace
@@ -264,8 +268,35 @@ int WebSocketSession::onWriteEvent()
}
}
-void WebSocketSession::addTextMessage(const std::string& msg)
+namespace {
+class TextMessageCommand : public Command
{
+private:
+ std::shared_ptr<WebSocketSession> session_;
+ const std::string msg_;
+public:
+ TextMessageCommand(cuid_t cuid, std::shared_ptr<WebSocketSession> session,
+ const std::string& msg)
+ : Command(cuid), session_{std::move(session)}, msg_{msg}
+ {}
+ virtual bool execute() CXX11_OVERRIDE
+ {
+ session_->addTextMessage(msg_, false);
+ return true;
+ }
+};
+} // namespace
+
+void WebSocketSession::addTextMessage(const std::string& msg, bool delayed)
+{
+ if (delayed) {
+ auto e = getDownloadEngine();
+ auto cuid = command_->getCuid();
+ auto c = make_unique<TextMessageCommand>(cuid, command_->getSession(), msg);
+ e->addCommand(make_unique<DelayedCommand>(cuid, e, 1, std::move(c), false));
+ return;
+ }
+
// TODO Don't add text message if the size of outbound queue in
// wsctx_ exceeds certain limit.
wslay_event_msg arg = {