std::string getSessionData(SSL_SESSION* s, size_t expectedLength) { std::unique_ptr<unsigned char[]> sessionData(new unsigned char[expectedLength]); auto p = sessionData.get(); auto len = i2d_SSL_SESSION(s, &p); CHECK(expectedLength == len); return std::string(reinterpret_cast<const char*>(sessionData.get()), len); }
boost::shared_ptr<AuthProvider> createSignonAuthProvider(const InitStateString &username, const InitStateString &password) { // Expected content of parameter GVariant. boost::shared_ptr<GVariantType> hashtype(g_variant_type_new("a{sv}"), g_variant_type_free); // 'username' is the part after signon: which we can parse directly. GErrorCXX gerror; GVariantCXX parametersVar(g_variant_parse(hashtype.get(), username.c_str(), NULL, NULL, gerror), TRANSFER_REF); if (!parametersVar) { gerror.throwError(SE_HERE, "parsing 'signon:' username"); } GHashTableCXX parameters(Variant2HashTable(parametersVar)); // Extract the values that we expect in the parameters hash. guint32 signonID; const char *method; const char *mechanism; GVariant *value; value = (GVariant *)g_hash_table_lookup(parameters, "identity"); if (!value || !g_variant_type_equal(G_VARIANT_TYPE_UINT32, g_variant_get_type(value))) { SE_THROW("need 'identity: <numeric ID>' in 'signon:' parameters"); } signonID = g_variant_get_uint32(value); value = (GVariant *)g_hash_table_lookup(parameters, "method"); if (!value || !g_variant_type_equal(G_VARIANT_TYPE_STRING, g_variant_get_type(value))) { SE_THROW("need 'method: <string>' in 'signon:' parameters"); } method = g_variant_get_string(value, NULL); value = (GVariant *)g_hash_table_lookup(parameters, "mechanism"); if (!value || !g_variant_type_equal(G_VARIANT_TYPE_STRING, g_variant_get_type(value))) { SE_THROW("need 'mechanism: <string>' in 'signon:' parameters"); } mechanism = g_variant_get_string(value, NULL); value = (GVariant *)g_hash_table_lookup(parameters, "session"); if (!value || !g_variant_type_equal(hashtype.get(), g_variant_get_type(value))) { SE_THROW("need 'session: <hash>' in 'signon:' parameters"); } GHashTableCXX sessionData(Variant2HashTable(value)); SE_LOG_DEBUG(NULL, "using identity %u, method %s, mechanism %s", signonID, method, mechanism); SignonIdentityCXX identity(signon_identity_new_from_db(signonID), TRANSFER_REF); SE_LOG_DEBUG(NULL, "using signond identity %d", signonID); SignonAuthSessionCXX authSession(signon_identity_create_session(identity, method, gerror), TRANSFER_REF); boost::shared_ptr<AuthProvider> provider(new SignonAuthProvider(authSession, sessionData, mechanism)); return provider; }
std::vector<std::string> HTTPFrontEndObj::onQuery(std::unique_ptr<cv::Mat> &&image, std::unique_ptr<CameraModel> &&camera) { std::unique_ptr<Session> session(new Session); session->overallStart = getTime(); // log start of processing session->type = HTTP_POST; std::unique_ptr<SessionData> sessionData(new SessionData); QSemaphore &detected = sessionData->detected; _mutex.lock(); long id = _dis(_gen); // this is not thread safe _sessionMap.emplace(id, std::move(sessionData)); _mutex.unlock(); session->id = id; QCoreApplication::postEvent( _identObj.get(), new QueryEvent(std::move(image), std::move(camera), std::move(session))); // TODO use condition variable? detected.acquire(); _mutex.lock(); auto iter = _sessionMap.find(id); sessionData = std::move(iter->second); _sessionMap.erase(id); _mutex.unlock(); assert(sessionData != nullptr); assert(sessionData->session != nullptr); session = std::move(sessionData->session); // print time session->overallEnd = getTime(); // log processing end time std::cout << "Time overall: " << session->overallEnd - session->overallStart << " ms" << std::endl; std::cout << "Time features: " << session->featuresEnd - session->featuresStart << " ms" << std::endl; std::cout << "Time words: " << session->wordsEnd - session->wordsStart << " ms" << std::endl; std::cout << "Time perspective: " << session->perspectiveEnd - session->perspectiveStart << " ms" << std::endl; return *(sessionData->names); }
SessionInformation SessionsManager::getSession(const QString &path) { const QString sessionPath = getSessionPath(path); QSettings sessionData(sessionPath, QSettings::IniFormat); sessionData.setIniCodec("UTF-8"); const int windows = sessionData.value(QLatin1String("Session/windows"), 0).toInt(); SessionInformation session; session.path = path; session.title = sessionData.value(QLatin1String("Session/title"), ((path == QLatin1String("default")) ? tr("Default") : tr("(Untitled)"))).toString(); session.index = (sessionData.value(QLatin1String("Session/index"), 1).toInt() - 1); session.clean = sessionData.value(QLatin1String("Session/clean"), true).toBool(); for (int i = 1; i <= windows; ++i) { const int tabs = sessionData.value(QStringLiteral("%1/Properties/windows").arg(i), 0).toInt(); SessionMainWindow sessionEntry; sessionEntry.index = (sessionData.value(QStringLiteral("%1/Properties/index").arg(i), 1).toInt() - 1); for (int j = 1; j <= tabs; ++j) { const int history = sessionData.value(QStringLiteral("%1/%2/Properties/history").arg(i).arg(j), 0).toInt(); SessionWindow sessionWindow; sessionWindow.searchEngine = sessionData.value(QStringLiteral("%1/%2/Properties/searchEngine").arg(i).arg(j), QString()).toString(); sessionWindow.userAgent = sessionData.value(QStringLiteral("%1/%2/Properties/userAgent").arg(i).arg(j), QString()).toString(); sessionWindow.group = sessionData.value(QStringLiteral("%1/%2/Properties/group").arg(i).arg(j), 0).toInt(); sessionWindow.index = (sessionData.value(QStringLiteral("%1/%2/Properties/index").arg(i).arg(j), 1).toInt() - 1); sessionWindow.pinned = sessionData.value(QStringLiteral("%1/%2/Properties/pinned").arg(i).arg(j), false).toBool(); for (int k = 1; k <= history; ++k) { const QStringList position = sessionData.value(QStringLiteral("%1/%2/History/%3/position").arg(i).arg(j).arg(k), 1).toStringList(); WindowHistoryEntry historyEntry; historyEntry.url = sessionData.value(QStringLiteral("%1/%2/History/%3/url").arg(i).arg(j).arg(k), 0).toString(); historyEntry.title = sessionData.value(QStringLiteral("%1/%2/History/%3/title").arg(i).arg(j).arg(k), 1).toString(); historyEntry.position = QPoint(position.value(0, QString::number(0)).toInt(), position.value(1, QString::number(0)).toInt()); historyEntry.zoom = sessionData.value(QStringLiteral("%1/%2/History/%3/zoom").arg(i).arg(j).arg(k), 100).toInt(); sessionWindow.history.append(historyEntry); } sessionEntry.windows.append(sessionWindow); } session.windows.append(sessionEntry); } return session; }
//---------------------------------------------------------------------------------------- // UpdateUserName //---------------------------------------------------------------------------------------- void CZPAssetsPanelObserver::UpdateUserName() { #if defined(InDnCS5) || defined(InDnCS5_5) const IExecutionContext* ec = GetExecutionContext(); ISession* gSession = ec->GetSession(); #endif InterfacePtr<const IZPDefaultSession> defaultSession( gSession, UseDefaultIID() ); ASSERT( defaultSession ); const IZPUserCredentials * defaultCredentials = defaultSession->GetUserCredentials(); InterfacePtr<const IZPSessionData> sessionData( defaultCredentials, UseDefaultIID() ); InterfacePtr<const IBoolData> isValidData( defaultCredentials, IID_IZPISVALID ); //Set User Name if( sessionData && isValidData && isValidData->Get()) this->SetTextControlData( kZPUIAssetsPanelUsernameWidgetID, sessionData->GetUserDisplayName() ); else this->SetTextControlData( kZPUIAssetsPanelUsernameWidgetID, kNullString ); }
void CreateAccount::processSession() { m_account = m_manager->createAccount(m_providerName); Accounts::Service service; if (m_account->services().size() == 1) { service = m_account->services().at(0); } m_accInfo = new Accounts::AccountService(m_account, service, this); const QString pluginName = m_account->provider().pluginName(); qDebug() << "Looking for plugin" << pluginName; if (!pluginName.isEmpty()) { loadPluginAndShowDialog(pluginName); } else { SignOn::IdentityInfo info; info.setCaption(m_providerName); info.setAccessControlList(QStringList("*")); info.setType(SignOn::IdentityInfo::Application); info.setStoreSecret(true); m_identity = SignOn::Identity::newIdentity(info, this); m_identity->storeCredentials(); connect(m_identity, SIGNAL(info(SignOn::IdentityInfo)), SLOT(info(SignOn::IdentityInfo))); connect(m_identity, &SignOn::Identity::error, [=](const SignOn::Error &err) { qDebug() << "Error storing identity:" << err.message(); }); QVariantMap data = m_accInfo->authData().parameters(); data.insert("Embedded", false); SignOn::SessionData sessionData(data); SignOn::AuthSessionP session = m_identity->createSession(m_accInfo->authData().method()); qDebug() << "Starting auth session with" << m_accInfo->authData().method(); connect(session, SIGNAL(error(SignOn::Error)), SLOT(sessionError(SignOn::Error))); connect(session, SIGNAL(response(SignOn::SessionData)), SLOT(sessionResponse(SignOn::SessionData))); session->process(sessionData, m_accInfo->authData().mechanism()); } }
bool SessionsManager::saveSession(const QString &path, const QString &title, MainWindow *window, bool clean) { QList<MainWindow*> windows; if (window) { windows.append(window); } else { windows = Application::getInstance()->getWindows(); } if (windows.isEmpty()) { return false; } QDir().mkpath(m_profilePath + QLatin1String("/sessions/")); const QString sessionPath = getSessionPath(path); QString sessionTitle = title; if (title.isEmpty()) { QSettings sessionData(sessionPath, QSettings::IniFormat); sessionData.setIniCodec("UTF-8"); sessionTitle = sessionData.value(QLatin1String("Session/title")).toString();; } QSaveFile file(sessionPath); if (!file.open(QIODevice::WriteOnly)) { return false; } int tabs = 0; const QString defaultSearchEngine = SettingsManager::getValue(QLatin1String("Search/DefaultSearchEngine")).toString(); const QString defaultUserAgent = SettingsManager::getValue(QLatin1String("Network/UserAgent")).toString(); QTextStream stream(&file); stream.setCodec("UTF-8"); stream << QLatin1String("[Session]\n"); stream << Utils::formatConfigurationEntry(QLatin1String("title"), sessionTitle, true); if (!clean) { stream << QLatin1String("clean=false\n"); } stream << QLatin1String("windows=") << windows.count() << QLatin1Char('\n'); stream << QLatin1String("index=1\n\n"); for (int i = 0; i < windows.count(); ++i) { const SessionMainWindow sessionEntry = windows.at(i)->getWindowsManager()->getSession(); tabs += sessionEntry.windows.count(); stream << QStringLiteral("[%1/Properties]\n").arg(i + 1); stream << QLatin1String("groups=0\n"); stream << QLatin1String("windows=") << sessionEntry.windows.count() << QLatin1Char('\n'); stream << QLatin1String("index=") << (sessionEntry.index + 1) << QLatin1String("\n\n"); for (int j = 0; j < sessionEntry.windows.count(); ++j) { stream << QStringLiteral("[%1/%2/Properties]\n").arg(i + 1).arg(j + 1); if (sessionEntry.windows.at(j).searchEngine != defaultSearchEngine) { stream << Utils::formatConfigurationEntry(QLatin1String("searchEngine"), sessionEntry.windows.at(j).searchEngine); } if (sessionEntry.windows.at(j).userAgent != defaultUserAgent) { stream << Utils::formatConfigurationEntry(QLatin1String("userAgent"), sessionEntry.windows.at(j).userAgent); } if (sessionEntry.windows.at(j).pinned) { stream << QLatin1String("pinned=true\n"); } stream << QLatin1String("history=") << sessionEntry.windows.at(j).history.count() << QLatin1Char('\n'); stream << QLatin1String("index=") << (sessionEntry.windows.at(j).index + 1) << QLatin1String("\n\n"); for (int k = 0; k < sessionEntry.windows.at(j).history.count(); ++k) { stream << QStringLiteral("[%1/%2/History/%3]\n").arg(i + 1).arg(j + 1).arg(k + 1); stream << Utils::formatConfigurationEntry(QLatin1String("url"), sessionEntry.windows.at(j).history.at(k).url, true); stream << Utils::formatConfigurationEntry(QLatin1String("title"), sessionEntry.windows.at(j).history.at(k).title, true); stream << QLatin1String("position=") << sessionEntry.windows.at(j).history.at(k).position.x() << ',' << sessionEntry.windows.at(j).history.at(k).position.y() << QLatin1Char('\n'); stream << QLatin1String("zoom=") << sessionEntry.windows.at(j).history.at(k).zoom << QLatin1String("\n\n"); } } } if (tabs == 0) { file.cancelWriting(); return false; } return file.commit(); }
SessionInformation SessionsManager::getSession(const QString &path) { const QString sessionPath = getSessionPath(path); QSettings sessionData(sessionPath, QSettings::IniFormat); sessionData.setIniCodec("UTF-8"); SessionInformation session; session.path = path; session.title = sessionData.value(QLatin1String("Session/title"), ((path == QLatin1String("default")) ? tr("Default") : tr("(Untitled)"))).toString(); session.index = (sessionData.value(QLatin1String("Session/index"), 1).toInt() - 1); session.isClean = sessionData.value(QLatin1String("Session/clean"), true).toBool(); const int windows = sessionData.value(QLatin1String("Session/windows"), 0).toInt(); const int defaultZoom = SettingsManager::getValue(QLatin1String("Content/DefaultZoom")).toInt(); for (int i = 1; i <= windows; ++i) { const int tabs = sessionData.value(QStringLiteral("%1/Properties/windows").arg(i), 0).toInt(); SessionMainWindow sessionEntry; sessionEntry.geometry = QByteArray::fromBase64(sessionData.value(QStringLiteral("%1/Properties/geometry").arg(i), 1).toString().toLatin1()); sessionEntry.index = (sessionData.value(QStringLiteral("%1/Properties/index").arg(i), 1).toInt() - 1); for (int j = 1; j <= tabs; ++j) { const QString state = sessionData.value(QStringLiteral("%1/%2/Properties/state").arg(i).arg(j), QString()).toString(); const QString searchEngine = sessionData.value(QStringLiteral("%1/%2/Properties/searchEngine").arg(i).arg(j), QString()).toString(); const QString userAgent = sessionData.value(QStringLiteral("%1/%2/Properties/userAgent").arg(i).arg(j), QString()).toString(); const QStringList geometry = sessionData.value(QStringLiteral("%1/%2/Properties/geometry").arg(i).arg(j), QString()).toString().split(QLatin1Char(',')); const int history = sessionData.value(QStringLiteral("%1/%2/Properties/history").arg(i).arg(j), 0).toInt(); const int reloadTime = (sessionData.value(QStringLiteral("%1/%2/Properties/reloadTime").arg(i).arg(j), -1).toInt()); SessionWindow sessionWindow; sessionWindow.geometry = ((geometry.count() == 4) ? QRect(geometry.at(0).toInt(), geometry.at(1).toInt(), geometry.at(2).toInt(), geometry.at(3).toInt()) : QRect()); sessionWindow.state = ((state == QLatin1String("maximized")) ? MaximizedWindowState : ((state == QLatin1String("minimized")) ? MinimizedWindowState : NormalWindowState)); sessionWindow.parentGroup = sessionData.value(QStringLiteral("%1/%2/Properties/group").arg(i).arg(j), 0).toInt(); sessionWindow.historyIndex = (sessionData.value(QStringLiteral("%1/%2/Properties/index").arg(i).arg(j), 1).toInt() - 1); sessionWindow.isAlwaysOnTop = sessionData.value(QStringLiteral("%1/%2/Properties/alwaysOnTop").arg(i).arg(j), false).toBool(); sessionWindow.isPinned = sessionData.value(QStringLiteral("%1/%2/Properties/pinned").arg(i).arg(j), false).toBool(); if (!searchEngine.isEmpty()) { sessionWindow.overrides[QLatin1String("Search/DefaultSearchEngine")] = searchEngine; } if (!userAgent.isEmpty()) { sessionWindow.overrides[QLatin1String("Network/UserAgent")] = userAgent; } if (reloadTime >= 0) { sessionWindow.overrides[QLatin1String("Content/PageReloadTime")] = reloadTime; } for (int k = 1; k <= history; ++k) { const QStringList position = sessionData.value(QStringLiteral("%1/%2/History/%3/position").arg(i).arg(j).arg(k), 1).toStringList(); WindowHistoryEntry historyEntry; historyEntry.url = sessionData.value(QStringLiteral("%1/%2/History/%3/url").arg(i).arg(j).arg(k), 0).toString(); historyEntry.title = sessionData.value(QStringLiteral("%1/%2/History/%3/title").arg(i).arg(j).arg(k), 1).toString(); historyEntry.position = QPoint(position.value(0, QString::number(0)).toInt(), position.value(1, QString::number(0)).toInt()); historyEntry.zoom = sessionData.value(QStringLiteral("%1/%2/History/%3/zoom").arg(i).arg(j).arg(k), defaultZoom).toInt(); sessionWindow.history.append(historyEntry); } sessionEntry.windows.append(sessionWindow); } session.windows.append(sessionEntry); } return session; }