2010-08-07 15:10:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2017-06-09 23:40:36 +02:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2010-08-07 15:10:44 +02:00
|
|
|
*
|
|
|
|
* 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 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* 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 KEEPASSX_ENTRY_H
|
|
|
|
#define KEEPASSX_ENTRY_H
|
|
|
|
|
2013-10-03 15:18:16 +02:00
|
|
|
#include <QColor>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QUrl>
|
2018-03-22 22:56:05 +01:00
|
|
|
#include <QUuid>
|
2010-08-12 21:38:59 +02:00
|
|
|
|
2012-07-16 09:54:04 +02:00
|
|
|
#include "core/AutoTypeAssociations.h"
|
2018-02-06 16:37:06 +01:00
|
|
|
#include "core/CustomData.h"
|
2012-04-14 15:38:20 +02:00
|
|
|
#include "core/EntryAttachments.h"
|
|
|
|
#include "core/EntryAttributes.h"
|
2011-07-08 14:51:14 +02:00
|
|
|
#include "core/TimeInfo.h"
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2010-08-14 12:24:35 +02:00
|
|
|
class Database;
|
2010-08-12 21:38:59 +02:00
|
|
|
class Group;
|
2018-09-05 16:20:57 -04:00
|
|
|
namespace Totp {
|
|
|
|
struct Settings;
|
|
|
|
}
|
2010-08-12 21:38:59 +02:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
enum class EntryReferenceType
|
|
|
|
{
|
2017-11-12 17:35:54 +02:00
|
|
|
Unknown,
|
|
|
|
Title,
|
|
|
|
UserName,
|
|
|
|
Password,
|
|
|
|
Url,
|
|
|
|
Notes,
|
2018-03-22 22:56:05 +01:00
|
|
|
QUuid,
|
2017-11-12 17:35:54 +02:00
|
|
|
CustomAttributes
|
|
|
|
};
|
|
|
|
|
2012-04-23 21:06:04 +02:00
|
|
|
struct EntryData
|
|
|
|
{
|
|
|
|
int iconNumber;
|
2018-03-22 22:56:05 +01:00
|
|
|
QUuid customIcon;
|
2012-04-23 21:06:04 +02:00
|
|
|
QColor foregroundColor;
|
|
|
|
QColor backgroundColor;
|
|
|
|
QString overrideUrl;
|
|
|
|
QString tags;
|
|
|
|
bool autoTypeEnabled;
|
|
|
|
int autoTypeObfuscation;
|
|
|
|
QString defaultAutoTypeSequence;
|
|
|
|
TimeInfo timeInfo;
|
2018-09-05 16:20:57 -04:00
|
|
|
QSharedPointer<Totp::Settings> totpSettings;
|
2018-09-30 08:45:06 -04:00
|
|
|
|
|
|
|
bool operator==(const EntryData& other) const;
|
|
|
|
bool operator!=(const EntryData& other) const;
|
|
|
|
bool equals(const EntryData& other, CompareItemOptions options) const;
|
2012-04-23 21:06:04 +02:00
|
|
|
};
|
|
|
|
|
2010-08-12 21:38:59 +02:00
|
|
|
class Entry : public QObject
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2010-08-12 21:38:59 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
public:
|
|
|
|
Entry();
|
2010-08-18 16:22:48 +02:00
|
|
|
~Entry();
|
2018-03-22 22:56:05 +01:00
|
|
|
const QUuid& uuid() const;
|
2018-09-30 08:45:06 -04:00
|
|
|
const QString uuidToHex() const;
|
2012-01-01 21:52:54 +01:00
|
|
|
QImage icon() const;
|
|
|
|
QPixmap iconPixmap() const;
|
2016-01-24 18:45:10 +01:00
|
|
|
QPixmap iconScaledPixmap() const;
|
2010-08-18 22:57:26 +02:00
|
|
|
int iconNumber() const;
|
2018-03-22 22:56:05 +01:00
|
|
|
const QUuid& iconUuid() const;
|
2010-08-12 21:38:59 +02:00
|
|
|
QColor foregroundColor() const;
|
|
|
|
QColor backgroundColor() const;
|
|
|
|
QString overrideUrl() const;
|
2010-09-25 12:41:00 +02:00
|
|
|
QString tags() const;
|
2018-09-30 08:45:06 -04:00
|
|
|
const TimeInfo& timeInfo() const;
|
2010-08-12 21:38:59 +02:00
|
|
|
bool autoTypeEnabled() const;
|
|
|
|
int autoTypeObfuscation() const;
|
|
|
|
QString defaultAutoTypeSequence() const;
|
2016-11-11 22:26:07 +01:00
|
|
|
QString effectiveAutoTypeSequence() const;
|
2018-01-18 23:45:09 +01:00
|
|
|
QString effectiveNewAutoTypeSequence() const;
|
2012-07-16 09:54:04 +02:00
|
|
|
AutoTypeAssociations* autoTypeAssociations();
|
|
|
|
const AutoTypeAssociations* autoTypeAssociations() const;
|
2010-08-18 15:08:17 +02:00
|
|
|
QString title() const;
|
|
|
|
QString url() const;
|
2017-06-29 19:54:49 +02:00
|
|
|
QString webUrl() const;
|
2017-10-25 23:29:01 -04:00
|
|
|
QString displayUrl() const;
|
2010-08-18 15:08:17 +02:00
|
|
|
QString username() const;
|
|
|
|
QString password() const;
|
|
|
|
QString notes() const;
|
2017-04-13 07:05:36 -03:00
|
|
|
QString totp() const;
|
2018-09-05 16:20:57 -04:00
|
|
|
QSharedPointer<Totp::Settings> totpSettings() const;
|
2017-04-13 07:05:36 -03:00
|
|
|
|
|
|
|
bool hasTotp() const;
|
2012-05-15 19:58:10 +02:00
|
|
|
bool isExpired() const;
|
2017-03-05 23:47:08 +01:00
|
|
|
bool hasReferences() const;
|
2012-04-14 15:38:20 +02:00
|
|
|
EntryAttributes* attributes();
|
|
|
|
const EntryAttributes* attributes() const;
|
|
|
|
EntryAttachments* attachments();
|
|
|
|
const EntryAttachments* attachments() const;
|
2018-02-18 21:01:22 +01:00
|
|
|
CustomData* customData();
|
|
|
|
const CustomData* customData() const;
|
2010-08-12 21:38:59 +02:00
|
|
|
|
2012-05-15 16:47:46 +02:00
|
|
|
static const int DefaultIconNumber;
|
2017-10-16 10:35:40 +03:00
|
|
|
static const int ResolveMaximumDepth;
|
2018-01-18 23:45:09 +01:00
|
|
|
static const QString AutoTypeSequenceUsername;
|
|
|
|
static const QString AutoTypeSequencePassword;
|
2012-05-15 16:47:46 +02:00
|
|
|
|
2018-03-22 22:56:05 +01:00
|
|
|
void setUuid(const QUuid& uuid);
|
2010-08-12 21:38:59 +02:00
|
|
|
void setIcon(int iconNumber);
|
2018-03-22 22:56:05 +01:00
|
|
|
void setIcon(const QUuid& uuid);
|
2010-08-12 21:38:59 +02:00
|
|
|
void setForegroundColor(const QColor& color);
|
|
|
|
void setBackgroundColor(const QColor& color);
|
|
|
|
void setOverrideUrl(const QString& url);
|
2010-09-25 12:41:00 +02:00
|
|
|
void setTags(const QString& tags);
|
2010-08-12 21:38:59 +02:00
|
|
|
void setTimeInfo(const TimeInfo& timeInfo);
|
|
|
|
void setAutoTypeEnabled(bool enable);
|
|
|
|
void setAutoTypeObfuscation(int obfuscation);
|
|
|
|
void setDefaultAutoTypeSequence(const QString& sequence);
|
2010-08-18 15:08:17 +02:00
|
|
|
void setTitle(const QString& title);
|
|
|
|
void setUrl(const QString& url);
|
|
|
|
void setUsername(const QString& username);
|
|
|
|
void setPassword(const QString& password);
|
|
|
|
void setNotes(const QString& notes);
|
2012-04-17 02:27:38 +02:00
|
|
|
void setExpires(const bool& value);
|
|
|
|
void setExpiryTime(const QDateTime& dateTime);
|
2018-09-05 16:20:57 -04:00
|
|
|
void setTotp(QSharedPointer<Totp::Settings> settings);
|
2010-08-12 21:38:59 +02:00
|
|
|
|
2010-08-25 13:52:59 +02:00
|
|
|
QList<Entry*> historyItems();
|
|
|
|
const QList<Entry*>& historyItems() const;
|
|
|
|
void addHistoryItem(Entry* entry);
|
2013-03-26 23:53:34 +01:00
|
|
|
void removeHistoryItems(const QList<Entry*>& historyEntries);
|
2012-05-04 22:45:34 +01:00
|
|
|
void truncateHistory();
|
2013-11-22 13:27:49 +01:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
bool equals(const Entry* other, CompareItemOptions options = CompareItemDefault) const;
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
enum CloneFlag
|
|
|
|
{
|
|
|
|
CloneNoFlags = 0,
|
|
|
|
CloneNewUuid = 1, // generate a random uuid for the clone
|
|
|
|
CloneResetTimeInfo = 2, // set all TimeInfo attributes to the current time
|
|
|
|
CloneIncludeHistory = 4, // clone the history items
|
|
|
|
CloneRenameTitle = 8, // add "-Clone" after the original title
|
|
|
|
CloneUserAsRef = 16, // Add the user as a reference to the original entry
|
|
|
|
ClonePassAsRef = 32, // Add the password as a reference to the original entry
|
2013-11-22 13:27:49 +01:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(CloneFlags, CloneFlag)
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
enum class PlaceholderType
|
|
|
|
{
|
2017-10-14 19:23:22 +03:00
|
|
|
NotPlaceholder,
|
|
|
|
Unknown,
|
|
|
|
Title,
|
2017-10-14 15:41:45 +03:00
|
|
|
UserName,
|
|
|
|
Password,
|
2017-10-14 19:23:22 +03:00
|
|
|
Notes,
|
|
|
|
Totp,
|
|
|
|
Url,
|
|
|
|
UrlWithoutScheme,
|
|
|
|
UrlScheme,
|
|
|
|
UrlHost,
|
|
|
|
UrlPort,
|
|
|
|
UrlPath,
|
|
|
|
UrlQuery,
|
|
|
|
UrlFragment,
|
|
|
|
UrlUserInfo,
|
|
|
|
UrlUserName,
|
|
|
|
UrlPassword,
|
|
|
|
Reference,
|
|
|
|
CustomAttribute
|
2017-10-14 15:41:45 +03:00
|
|
|
};
|
|
|
|
|
2013-07-04 13:59:32 +02:00
|
|
|
/**
|
2013-11-22 13:27:49 +01:00
|
|
|
* Creates a duplicate of this entry except that the returned entry isn't
|
|
|
|
* part of any group.
|
2013-07-04 13:59:32 +02:00
|
|
|
* Note that you need to copy the custom icons manually when inserting the
|
|
|
|
* new entry into another database.
|
|
|
|
*/
|
2013-11-22 13:27:49 +01:00
|
|
|
Entry* clone(CloneFlags flags) const;
|
2013-04-14 14:21:42 +02:00
|
|
|
void copyDataFrom(const Entry* other);
|
2017-09-29 14:10:54 -04:00
|
|
|
QString maskPasswordPlaceholders(const QString& str) const;
|
2016-11-25 18:26:59 +01:00
|
|
|
QString resolveMultiplePlaceholders(const QString& str) const;
|
|
|
|
QString resolvePlaceholder(const QString& str) const;
|
2017-11-19 21:06:09 +02:00
|
|
|
QString resolveUrlPlaceholder(const QString& str, PlaceholderType placeholderType) const;
|
2017-10-14 19:23:22 +03:00
|
|
|
PlaceholderType placeholderType(const QString& placeholder) const;
|
2017-06-29 19:54:49 +02:00
|
|
|
QString resolveUrl(const QString& url) const;
|
2012-05-04 22:45:34 +01:00
|
|
|
|
2012-04-23 21:06:04 +02:00
|
|
|
/**
|
|
|
|
* Call before and after set*() methods to create a history item
|
|
|
|
* if the entry has been changed.
|
|
|
|
*/
|
|
|
|
void beginUpdate();
|
2016-07-31 23:49:38 +02:00
|
|
|
bool endUpdate();
|
2010-08-25 13:52:59 +02:00
|
|
|
|
2010-10-06 22:54:07 +02:00
|
|
|
Group* group();
|
2012-07-23 18:06:04 +02:00
|
|
|
const Group* group() const;
|
2010-08-12 21:38:59 +02:00
|
|
|
void setGroup(Group* group);
|
2018-09-30 08:45:06 -04:00
|
|
|
const Database* database() const;
|
|
|
|
Database* database();
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
bool canUpdateTimeinfo() const;
|
2012-04-11 19:51:54 +02:00
|
|
|
void setUpdateTimeinfo(bool value);
|
|
|
|
|
2017-03-10 15:58:42 +01:00
|
|
|
signals:
|
2011-07-08 13:57:02 +02:00
|
|
|
/**
|
|
|
|
* Emitted when a default attribute has been changed.
|
|
|
|
*/
|
2010-08-23 21:30:20 +02:00
|
|
|
void dataChanged(Entry* entry);
|
2010-08-18 16:22:48 +02:00
|
|
|
|
2012-04-11 19:51:54 +02:00
|
|
|
void modified();
|
|
|
|
|
2017-03-10 15:58:42 +01:00
|
|
|
private slots:
|
2012-04-14 15:38:20 +02:00
|
|
|
void emitDataChanged();
|
2012-04-17 01:02:02 +02:00
|
|
|
void updateTimeinfo();
|
2012-04-23 21:06:04 +02:00
|
|
|
void updateModifiedSinceBegin();
|
2018-01-22 21:42:22 +01:00
|
|
|
void updateTotp();
|
2012-04-14 15:38:20 +02:00
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
private:
|
2017-10-16 10:35:40 +03:00
|
|
|
QString resolveMultiplePlaceholdersRecursive(const QString& str, int maxDepth) const;
|
|
|
|
QString resolvePlaceholderRecursive(const QString& placeholder, int maxDepth) const;
|
2017-11-12 17:35:54 +02:00
|
|
|
QString resolveReferencePlaceholderRecursive(const QString& placeholder, int maxDepth) const;
|
|
|
|
QString referenceFieldValue(EntryReferenceType referenceType) const;
|
|
|
|
|
|
|
|
static EntryReferenceType referenceType(const QString& referenceStr);
|
2017-10-16 10:35:40 +03:00
|
|
|
|
2012-08-01 10:40:38 +02:00
|
|
|
template <class T> bool set(T& property, const T& value);
|
2012-04-18 13:57:57 +02:00
|
|
|
|
2018-03-22 22:56:05 +01:00
|
|
|
QUuid m_uuid;
|
2012-04-23 21:06:04 +02:00
|
|
|
EntryData m_data;
|
2018-02-18 21:01:22 +01:00
|
|
|
QPointer<EntryAttributes> m_attributes;
|
|
|
|
QPointer<EntryAttachments> m_attachments;
|
|
|
|
QPointer<AutoTypeAssociations> m_autoTypeAssociations;
|
|
|
|
QPointer<CustomData> m_customData;
|
2018-09-30 08:45:06 -04:00
|
|
|
QList<Entry*> m_history; // Items sorted from oldest to newest
|
2018-02-06 16:37:06 +01:00
|
|
|
|
2012-04-23 21:06:04 +02:00
|
|
|
Entry* m_tmpHistoryItem;
|
|
|
|
bool m_modifiedSinceBegin;
|
2011-07-09 21:54:01 +02:00
|
|
|
QPointer<Group> m_group;
|
2012-04-11 19:51:54 +02:00
|
|
|
bool m_updateTimeinfo;
|
2010-08-07 15:10:44 +02:00
|
|
|
};
|
|
|
|
|
2013-11-22 13:27:49 +01:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Entry::CloneFlags)
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
#endif // KEEPASSX_ENTRY_H
|