diff options
Diffstat (limited to 'kit/ChildSession.cpp')
-rw-r--r-- | kit/ChildSession.cpp | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 4ceb931962..6abe8ef5f7 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -270,16 +270,10 @@ bool ChildSession::_handleInput(const char *buffer, int length) // Just ignore these. // FIXME: We probably should do something for "canceltiles" at least? } - else if (tokens.equals(0, "freemiumstatus")) + else if (tokens.equals(0, "blockingcommandstatus")) { -#ifdef ENABLE_FREEMIUM - return updateBlockingCommandStatus(buffer, length, tokens, "freemium"); -#endif - } - else if (tokens.equals(0, "restrictionstatus")) - { -#ifdef ENABLE_FEATURE_RESTRICTION - return updateBlockingCommandStatus(buffer, length, tokens, "restricted"); +#if defined(ENABLE_FREEMIUM) || defined(ENABLE_FEATURE_RESTRICTION) + return updateBlockingCommandStatus(buffer, length, tokens); #endif } else @@ -2567,27 +2561,42 @@ int ChildSession::getSpeed() } #if defined(ENABLE_FEATURE_RESTRICTION) || defined(ENABLE_FREEMIUM) -bool ChildSession::updateBlockingCommandStatus(const char* /*buffer*/, int /*length*/, const StringVector& tokens, std::string type) +bool ChildSession::updateBlockingCommandStatus(const char* /*buffer*/, int /*length*/, const StringVector& tokens) { - std::string status; - if (tokens.size() < 2 || (type == "freemium" && !getTokenString(tokens[1], "isFreemiumUser", status))) + std::string freemiumStatus, restrictedStatus; + if (tokens.size() < 2 || !getTokenString(tokens[1], "isRestrictedUser", restrictedStatus)) { - sendTextFrameAndLogError("error: cmd=freemiumstatus kind=failure"); + sendTextFrameAndLogError("error: cmd=restrictionstatus kind=failure"); return false; } - else if (tokens.size() < 2 || (type == "restricted" && !getTokenString(tokens[1], "isRestrictedUser", status))) + else if (tokens.size() < 2 || !getTokenString(tokens[2], "isFreemiumUser", freemiumStatus)) { - sendTextFrameAndLogError("error: cmd=restrictionstatus kind=failure"); + sendTextFrameAndLogError("error: cmd=freemiumstatus kind=failure"); return false; } + std::string blockedCommands = ""; + if (restrictedStatus == "true") + blockedCommands += CommandControl::RestrictionManager::getRestrictedCommandListString(); + if (freemiumStatus == "true") + blockedCommands += blockedCommands.empty() ? CommandControl::FreemiumManager::getFreemiumDenyListString() : + " " + CommandControl::FreemiumManager::getFreemiumDenyListString(); - if(type == "freemium") - getLOKitDocument()->setBlockedCommandList((type + '-' + CommandControl::FreemiumManager::getFreemiumDenyListString()).c_str()); - else if(type == "restricted") - getLOKitDocument()->setBlockedCommandList((type + '-' + CommandControl::RestrictionManager::getRestrictedCommandListString()).c_str()); - getLOKitDocument()->setBlockedCommandView(_viewId, type.c_str(), status == "true"); + getLOKitDocument()->setBlockedCommandList(_viewId, blockedCommands.c_str()); return true; } + +std::string ChildSession::getBlockedCommandType(std::string command) +{ + if(CommandControl::RestrictionManager::getRestrictedCommandList().find(command) + != CommandControl::RestrictionManager::getRestrictedCommandList().end()) + return "restricted"; + + if(CommandControl::FreemiumManager::getFreemiumDenyList().find(command) + != CommandControl::FreemiumManager::getFreemiumDenyList().end()) + return "freemiumdeny"; + + return ""; +} #endif void ChildSession::loKitCallback(const int type, const std::string& payload) @@ -2894,6 +2903,20 @@ void ChildSession::loKitCallback(const int type, const std::string& payload) case LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR: sendTextFrame("documentbackgroundcolor: " + payload); break; + case LOK_COMMAND_BLOCKED: + { +#if defined(ENABLE_FREEMIUM) || defined(ENABLE_FEATURE_RESTRICTION) + LOG_INF("COMMAND_BLOCKED: " << payload); + Parser parser; + Poco::Dynamic::Var var = parser.parse(payload); + Object::Ptr object = var.extract<Object::Ptr>(); + + std::string cmd = object->get("cmd").toString(); + sendTextFrame("blockedcommand: cmd=" + cmd + + " kind=" + getBlockedCommandType(cmd) + " code=" + object->get("code").toString()); +#endif + } + break; default: LOG_ERR("Unknown callback event (" << lokCallbackTypeToString(type) << "): " << payload); } |