2013-05-14 17:25:55 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#ifndef PASSWORDMANAGER_H
|
|
|
|
#define PASSWORDMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include "qz_namespace.h"
|
|
|
|
|
|
|
|
class PasswordBackend;
|
|
|
|
class DatabasePasswordBackend;
|
2013-06-08 15:11:38 +02:00
|
|
|
class DatabaseEncryptedPasswordBackend;
|
2013-05-14 17:25:55 +02:00
|
|
|
|
2013-05-15 20:05:45 +02:00
|
|
|
struct QT_QUPZILLA_EXPORT PasswordEntry {
|
2013-05-14 17:25:55 +02:00
|
|
|
QVariant id;
|
2013-05-14 22:45:20 +02:00
|
|
|
QString host;
|
2013-05-14 17:25:55 +02:00
|
|
|
QString username;
|
|
|
|
QString password;
|
|
|
|
QByteArray data;
|
2013-05-20 11:05:54 +02:00
|
|
|
int updated;
|
|
|
|
|
|
|
|
PasswordEntry() : updated(-1) { }
|
2013-05-14 17:25:55 +02:00
|
|
|
|
|
|
|
bool isValid() const {
|
2013-05-22 15:43:44 +02:00
|
|
|
return !password.isEmpty() && !host.isEmpty();
|
2013-05-14 17:25:55 +02:00
|
|
|
}
|
2013-05-15 20:05:45 +02:00
|
|
|
|
|
|
|
bool operator==(const PasswordEntry &other) const {
|
|
|
|
return id == other.id;
|
|
|
|
}
|
|
|
|
|
2013-05-20 11:05:54 +02:00
|
|
|
bool operator<(const PasswordEntry &other) const {
|
|
|
|
return updated > other.updated;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const PasswordEntry &entry);
|
|
|
|
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, PasswordEntry &entry);
|
2013-05-14 17:25:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class QT_QUPZILLA_EXPORT PasswordManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PasswordManager(QObject* parent = 0);
|
|
|
|
~PasswordManager();
|
|
|
|
|
|
|
|
void loadSettings();
|
|
|
|
|
|
|
|
QVector<PasswordEntry> getEntries(const QUrl &url);
|
2013-05-14 22:45:20 +02:00
|
|
|
QVector<PasswordEntry> getAllEntries();
|
2013-05-14 17:25:55 +02:00
|
|
|
|
|
|
|
void addEntry(const PasswordEntry &entry);
|
2013-06-08 13:14:00 +02:00
|
|
|
bool updateEntry(const PasswordEntry &entry);
|
2013-05-20 11:05:54 +02:00
|
|
|
void updateLastUsed(PasswordEntry &entry);
|
2013-05-14 17:25:55 +02:00
|
|
|
|
2013-05-14 22:45:20 +02:00
|
|
|
void removeEntry(const PasswordEntry &entry);
|
|
|
|
void removeAllEntries();
|
2013-05-14 17:25:55 +02:00
|
|
|
|
2013-06-05 00:06:23 +02:00
|
|
|
QHash<QString, PasswordBackend*> availableBackends();
|
|
|
|
PasswordBackend* activeBackend();
|
2013-06-08 14:58:36 +02:00
|
|
|
void switchBackend(const QString &backendID);
|
2013-05-17 15:42:06 +02:00
|
|
|
|
2013-05-14 17:25:55 +02:00
|
|
|
bool registerBackend(const QString &id, PasswordBackend* backend);
|
|
|
|
void unregisterBackend(PasswordBackend* backend);
|
|
|
|
|
2013-05-14 22:45:20 +02:00
|
|
|
static QString createHost(const QUrl &url);
|
2013-05-20 13:33:13 +02:00
|
|
|
static QByteArray urlEncodePassword(const QString &password);
|
2013-05-14 22:45:20 +02:00
|
|
|
|
2013-05-14 17:25:55 +02:00
|
|
|
private:
|
|
|
|
void ensureLoaded();
|
|
|
|
|
|
|
|
bool m_loaded;
|
|
|
|
|
2013-05-15 20:05:45 +02:00
|
|
|
PasswordBackend* m_backend;
|
2013-05-14 17:25:55 +02:00
|
|
|
DatabasePasswordBackend* m_databaseBackend;
|
2013-06-08 15:11:38 +02:00
|
|
|
DatabaseEncryptedPasswordBackend* m_databaseEncryptedBackend;
|
|
|
|
|
2013-05-14 17:25:55 +02:00
|
|
|
QHash<QString, PasswordBackend*> m_backends;
|
2013-06-08 14:58:36 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void passwordBackendChanged();
|
2013-05-14 17:25:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Hint to QVector to use std::realloc on item moving
|
|
|
|
Q_DECLARE_TYPEINFO(PasswordEntry, Q_MOVABLE_TYPE);
|
|
|
|
|
2013-05-14 22:45:20 +02:00
|
|
|
Q_DECLARE_METATYPE(PasswordEntry)
|
|
|
|
|
2013-05-14 17:25:55 +02:00
|
|
|
#endif // PASSWORDMANAGER_H
|