Example #1
0
string ExposerConfig::extract_token(string response_string) {
	try
	{
		//Try to extract token
		Poco::JSON::Parser parser;
		Poco::Dynamic::Var result = parser.parse(response_string);
		Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
		string tmptoken = object->get("token");

		ostringstream tmpmsg;
		//tmpmsg << " ===== Got a token: " << tmptoken;
		tmpmsg << " ===== Got a token.";
		Log::log(Log::INFO, tmpmsg.str());

		return tmptoken;
	}
	catch (std::exception &ex)
	{
		ostringstream tmpmsg;
		tmpmsg << "Exception when trying to read token: " << ex.what();
		Log::log(Log::ERROR, tmpmsg.str());
		return "";
	}

}
Example #2
0
void ProxyBlockEval::handleCall(const Poco::JSON::Object::Ptr &callObj)
{
    auto env = Pothos::ProxyEnvironment::make("managed");
    const auto callName = callObj->get("name").extract<std::string>();
    std::vector<Pothos::Proxy> callArgs;
    for (auto arg : *callObj->getArray("args"))
    {
        const auto obj = this->lookupOrEvalAsType(arg);
        callArgs.push_back(env->convertObjectToProxy(obj));
    }
    try
    {
        _proxyBlock.getHandle()->call(callName, callArgs.data(), callArgs.size());
    }
    catch (const Pothos::Exception &ex)
    {
        throw Pothos::Exception("ProxyBlockEval call("+callName+")", ex);
    }
}
Example #3
0
bool BlockTreeWidget::blockDescMatchesFilter(const Poco::JSON::Object::Ptr &blockDesc)
{
    if (_filter.isEmpty()) return true;

    const auto path = blockDesc->get("path").extract<std::string>();
    const auto name = blockDesc->get("name").extract<std::string>();

    //construct a candidate string from path, name, categories, and keywords.
    std::string candidate = path+name;
    if (blockDesc->isArray("categories")) for (auto categoryObj : *blockDesc->getArray("categories"))
    {
        candidate += categoryObj.extract<std::string>();
    }
    if(blockDesc->isArray("keywords"))
    {
        const auto keywords = blockDesc->getArray("keywords");
        for(auto keyword : *keywords) candidate += keyword.extract<std::string>();
    }

    //reject if filter string not found in candidate
    candidate = Poco::toLower(candidate);
    const auto searchToken = Poco::toLower(_filter.toStdString());
    return (candidate.find(searchToken) != std::string::npos);
}
Example #4
0
string ExposerConfig::extract_sessionid(string json_string) {
	try
	{
		//Try to extract sessionid
		Poco::JSON::Parser parser;
		Poco::Dynamic::Var result = parser.parse(json_string);
		Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
		string tmpsessionid = object->get("id");

		ostringstream tmpmsg;
		tmpmsg << " ===== Got a sessionid: " << tmpsessionid;
		Log::log(Log::INFO, tmpmsg.str());

		return tmpsessionid;

	}
	catch (Poco::Exception &ex)
	{
		ostringstream tmpmsg;
		tmpmsg << "Exception when trying to read sessionid: " << ex.displayText();
		Log::log(Log::ERROR, tmpmsg.str());
		return "";
	}
}
Example #5
0
bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTokenizer& tokens)
{
    Poco::Mutex::ScopedLock lock(_mutex);

    int part = -1;
    if (tokens.count() < 2)
    {
        sendTextFrame("error: cmd=load kind=syntax");
        return false;
    }

    std::string timestamp;
    parseDocOptions(tokens, part, timestamp);

    assert(!_docURL.empty());
    assert(!_jailedFilePath.empty());

    if (_loKitDocument == nullptr)
        Log::info("Loading new document from URI: [" + _jailedFilePath + "].");
    else
        Log::info("Loading view to document from URI: [" + _jailedFilePath + "].");

    if (_loKitDocument != nullptr)
    {
        _viewId = _loKitDocument->pClass->createView(_loKitDocument);
    }
    else
    {
        if ( LIBREOFFICEKIT_HAS(_loKit, registerCallback))
            _loKit->pClass->registerCallback(_loKit, myCallback, this);

        if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, _jailedFilePath.c_str())) == nullptr)
        {
            Log::error("Failed to load: " + _jailedFilePath + ", error: " + _loKit->pClass->getError(_loKit));
            sendTextFrame("error: cmd=load kind=failed");
            return false;
        }
    }

    _loKitDocument->pClass->setView(_loKitDocument, _viewId);

    std::string renderingOptions;
    if (!_docOptions.empty())
    {
        Poco::JSON::Parser parser;
        Poco::Dynamic::Var var = parser.parse(_docOptions);
        Poco::JSON::Object::Ptr object = var.extract<Poco::JSON::Object::Ptr>();
        renderingOptions = object->get("rendering").toString();
    }

    _loKitDocument->pClass->initializeForRendering(_loKitDocument, (renderingOptions.empty() ? nullptr : renderingOptions.c_str()));

    if (_docType != "text" && part != -1)
    {
        _clientPart = part;
        _loKitDocument->pClass->setPart(_loKitDocument, part);
    }

    _loKitDocument->pClass->registerCallback(_loKitDocument, myCallback, this);

    if (!getStatus(buffer, length))
        return false;

    _onLoad(_loKitDocument, _viewId);

    return true;
}