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

Entry.h « core « src - github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99c0e60247922ba4553faa0a91517fad3aa20129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
 *  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 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

#include <QImage>
#include <QPointer>
#include <QUuid>

#include "core/AutoTypeAssociations.h"
#include "core/CustomData.h"
#include "core/EntryAttachments.h"
#include "core/EntryAttributes.h"
#include "core/Global.h"
#include "core/TimeInfo.h"

class Database;
class Group;
class PasswordHealth;

namespace Totp
{
    struct Settings;
}

enum class EntryReferenceType
{
    Unknown,
    Title,
    UserName,
    Password,
    Url,
    Notes,
    QUuid,
    CustomAttributes
};

struct EntryData
{
    int iconNumber;
    QUuid customIcon;
    QString foregroundColor;
    QString backgroundColor;
    QString overrideUrl;
    QString tags;
    bool autoTypeEnabled;
    int autoTypeObfuscation;
    QString defaultAutoTypeSequence;
    TimeInfo timeInfo;
    QSharedPointer<Totp::Settings> totpSettings;
    QSharedPointer<PasswordHealth> passwordHealth;

    bool operator==(const EntryData& other) const;
    bool operator!=(const EntryData& other) const;
    bool equals(const EntryData& other, CompareItemOptions options) const;
};

class Entry : public ModifiableObject
{
    Q_OBJECT

public:
    Entry();
    ~Entry();
    const QUuid& uuid() const;
    const QString uuidToHex() const;
    QImage icon() const;
    QPixmap iconPixmap(IconSize size = IconSize::Default) const;
    int iconNumber() const;
    const QUuid& iconUuid() const;
    QString foregroundColor() const;
    QString backgroundColor() const;
    QString overrideUrl() const;
    QString tags() const;
    const TimeInfo& timeInfo() const;
    bool autoTypeEnabled() const;
    int autoTypeObfuscation() const;
    QString defaultAutoTypeSequence() const;
    QString effectiveAutoTypeSequence() const;
    QList<QString> autoTypeSequences(const QString& pattern = {}) const;
    AutoTypeAssociations* autoTypeAssociations();
    const AutoTypeAssociations* autoTypeAssociations() const;
    QString title() const;
    QString url() const;
    QString webUrl() const;
    QString displayUrl() const;
    QString username() const;
    QString password() const;
    QString notes() const;
    QString attribute(const QString& key) const;
    QString totp() const;
    QString totpSettingsString() const;
    QSharedPointer<Totp::Settings> totpSettings() const;
    int size() const;
    QString path() const;
    const QSharedPointer<PasswordHealth>& passwordHealth();
    bool excludeFromReports() const;
    void setExcludeFromReports(bool state);

    bool hasTotp() const;
    bool isExpired() const;
    bool isRecycled() const;
    bool isAttributeReference(const QString& key) const;
    bool isAttributeReferenceOf(const QString& key, const QUuid& uuid) const;
    void replaceReferencesWithValues(const Entry* other);
    bool hasReferences() const;
    bool hasReferencesTo(const QUuid& uuid) const;
    EntryAttributes* attributes();
    const EntryAttributes* attributes() const;
    EntryAttachments* attachments();
    const EntryAttachments* attachments() const;
    CustomData* customData();
    const CustomData* customData() const;

    void setUuid(const QUuid& uuid);
    void setIcon(int iconNumber);
    void setIcon(const QUuid& uuid);
    void setForegroundColor(const QString& color);
    void setBackgroundColor(const QString& color);
    void setOverrideUrl(const QString& url);
    void setTags(const QString& tags);
    void setTimeInfo(const TimeInfo& timeInfo);
    void setAutoTypeEnabled(bool enable);
    void setAutoTypeObfuscation(int obfuscation);
    void setDefaultAutoTypeSequence(const QString& sequence);
    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);
    void setDefaultAttribute(const QString& attribute, const QString& value);
    void setExpires(const bool& value);
    void setExpiryTime(const QDateTime& dateTime);
    void setTotp(QSharedPointer<Totp::Settings> settings);

    QList<Entry*> historyItems();
    const QList<Entry*>& historyItems() const;
    void addHistoryItem(Entry* entry);
    void removeHistoryItems(const QList<Entry*>& historyEntries);
    void truncateHistory();

    bool equals(const Entry* other, CompareItemOptions options = CompareItemDefault) const;

    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
        CloneDefault = CloneNewUuid | CloneResetTimeInfo,
        CloneCopy = CloneNewUuid | CloneResetTimeInfo | CloneIncludeHistory,
        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
    };
    Q_DECLARE_FLAGS(CloneFlags, CloneFlag)

    enum class PlaceholderType
    {
        NotPlaceholder,
        Unknown,
        Title,
        UserName,
        Password,
        Notes,
        Totp,
        Url,
        UrlWithoutScheme,
        UrlScheme,
        UrlHost,
        UrlPort,
        UrlPath,
        UrlQuery,
        UrlFragment,
        UrlUserInfo,
        UrlUserName,
        UrlPassword,
        Reference,
        CustomAttribute,
        DateTimeSimple,
        DateTimeYear,
        DateTimeMonth,
        DateTimeDay,
        DateTimeHour,
        DateTimeMinute,
        DateTimeSecond,
        DateTimeUtcSimple,
        DateTimeUtcYear,
        DateTimeUtcMonth,
        DateTimeUtcDay,
        DateTimeUtcHour,
        DateTimeUtcMinute,
        DateTimeUtcSecond,
        DbDir
    };

    static const int DefaultIconNumber;
    static const int ResolveMaximumDepth;
    static const QString AutoTypeSequenceUsername;
    static const QString AutoTypeSequencePassword;

    /**
     * Creates a duplicate of this entry except that the returned entry isn't
     * part of any group.
     * Note that you need to copy the custom icons manually when inserting the
     * new entry into another database.
     */
    Entry* clone(CloneFlags flags = CloneDefault) const;
    void copyDataFrom(const Entry* other);
    QString maskPasswordPlaceholders(const QString& str) const;
    Entry* resolveReference(const QString& str) const;
    QString resolveMultiplePlaceholders(const QString& str) const;
    QString resolvePlaceholder(const QString& str) const;
    QString resolveUrlPlaceholder(const QString& str, PlaceholderType placeholderType) const;
    QString resolveDateTimePlaceholder(PlaceholderType placeholderType) const;
    PlaceholderType placeholderType(const QString& placeholder) const;
    QString resolveUrl(const QString& url) const;

    /**
     * Call before and after set*() methods to create a history item
     * if the entry has been changed.
     */
    void beginUpdate();
    bool endUpdate();

    void moveUp();
    void moveDown();

    Group* group();
    const Group* group() const;
    void setGroup(Group* group);
    const Database* database() const;
    Database* database();

    bool canUpdateTimeinfo() const;
    void setUpdateTimeinfo(bool value);

signals:
    /**
     * Emitted when a default attribute has been changed.
     */
    void entryDataChanged(Entry* entry);

private slots:
    void emitDataChanged();
    void updateTimeinfo();
    void updateModifiedSinceBegin();
    void updateTotp();

private:
    QString resolveMultiplePlaceholdersRecursive(const QString& str, int maxDepth) const;
    QString resolvePlaceholderRecursive(const QString& placeholder, int maxDepth) const;
    QString resolveReferencePlaceholderRecursive(const QString& placeholder, int maxDepth) const;
    QString referenceFieldValue(EntryReferenceType referenceType) const;

    static QString buildReference(const QUuid& uuid, const QString& field);
    static EntryReferenceType referenceType(const QString& referenceStr);

    template <class T> bool set(T& property, const T& value);

    QUuid m_uuid;
    EntryData m_data;
    QPointer<EntryAttributes> m_attributes;
    QPointer<EntryAttachments> m_attachments;
    QPointer<AutoTypeAssociations> m_autoTypeAssociations;
    QPointer<CustomData> m_customData;
    QList<Entry*> m_history; // Items sorted from oldest to newest

    QScopedPointer<Entry> m_tmpHistoryItem;
    bool m_modifiedSinceBegin;
    QPointer<Group> m_group;
    bool m_updateTimeinfo;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Entry::CloneFlags)

#endif // KEEPASSX_ENTRY_H