Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser/BrowserEntryConfig.cpp')
-rw-r--r--src/browser/BrowserEntryConfig.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/browser/BrowserEntryConfig.cpp b/src/browser/BrowserEntryConfig.cpp
new file mode 100644
index 000000000..36d0c7339
--- /dev/null
+++ b/src/browser/BrowserEntryConfig.cpp
@@ -0,0 +1,109 @@
+/*
+* Copyright (C) 2013 Francois Ferrand
+* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "BrowserEntryConfig.h"
+#include <QtCore>
+#include "core/Entry.h"
+#include "core/EntryAttributes.h"
+
+static const char KEEPASSBROWSER_NAME[] = "KeePassXC-Browser Settings";
+
+
+BrowserEntryConfig::BrowserEntryConfig(QObject* parent) :
+ QObject(parent)
+{
+}
+
+QStringList BrowserEntryConfig::allowedHosts() const
+{
+ return m_allowedHosts.toList();
+}
+
+void BrowserEntryConfig::setAllowedHosts(const QStringList& allowedHosts)
+{
+ m_allowedHosts = allowedHosts.toSet();
+}
+
+QStringList BrowserEntryConfig::deniedHosts() const
+{
+ return m_deniedHosts.toList();
+}
+
+void BrowserEntryConfig::setDeniedHosts(const QStringList& deniedHosts)
+{
+ m_deniedHosts = deniedHosts.toSet();
+}
+
+bool BrowserEntryConfig::isAllowed(const QString& host) const
+{
+ return m_allowedHosts.contains(host);
+}
+
+void BrowserEntryConfig::allow(const QString& host)
+{
+ m_allowedHosts.insert(host);
+ m_deniedHosts.remove(host);
+}
+
+bool BrowserEntryConfig::isDenied(const QString& host) const
+{
+ return m_deniedHosts.contains(host);
+}
+
+void BrowserEntryConfig::deny(const QString& host)
+{
+ m_deniedHosts.insert(host);
+ m_allowedHosts.remove(host);
+}
+
+QString BrowserEntryConfig::realm() const
+{
+ return m_realm;
+}
+
+void BrowserEntryConfig::setRealm(const QString& realm)
+{
+ m_realm = realm;
+}
+
+bool BrowserEntryConfig::load(const Entry* entry)
+{
+ QString s = entry->attributes()->value(KEEPASSBROWSER_NAME);
+ if (s.isEmpty()) {
+ return false;
+ }
+
+ QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8());
+ if (doc.isNull()) {
+ return false;
+ }
+
+ QVariantMap map = doc.object().toVariantMap();
+ for (QVariantMap::const_iterator iter = map.cbegin(); iter != map.cend(); ++iter) {
+ setProperty(iter.key().toLatin1(), iter.value());
+ }
+ return true;
+}
+
+void BrowserEntryConfig::save(Entry* entry)
+{
+ QVariantMap v = qo2qv(this);
+ QJsonObject o = QJsonObject::fromVariantMap(v);
+ QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact);
+ entry->attributes()->set(KEEPASSBROWSER_NAME, json);
+}