Refactor database extraction (#2698)

Previously, extracting the XML from a database was done with the
`saveXml` attribute in the `KeePass2Reader` class.

This had several unfortunate consequences:
* The `KdbxReader` class had to import the `KdbxXmlWriter` class
in order to perform the export (bad separation of concerns);
* The CLI database unlocking logic had to be duplicated only
for the `Extract` command;
* The `xmlData` had to be stored in the `KeePass2Reader` as
a temporary result.
* Lots of `setSaveXml` functions were implemented only
to trickle down this functionality.

Also, the naming of the `saveXml` variable was not really
helpful to understand it's role.

Overall, this change will make it easier to maintain and expand
the CLI database unlocking logic (for example, adding a `--no-password`
option as requested in https://github.com/keepassxreboot/keepassxc/issues/1873)
It also opens to door to other types of extraction/exporting (for
example exporting to CSV, as requested in
https://github.com/keepassxreboot/keepassxc/issues/2572)
This commit is contained in:
louib 2019-02-13 13:24:55 -05:00 committed by Janek Bevendorff
parent 8bfc539234
commit 504904a414
15 changed files with 79 additions and 130 deletions

View file

@ -52,6 +52,13 @@ public:
*/
virtual bool writeDatabase(QIODevice* device, Database* db) = 0;
/**
* Get the database format version for the writer.
*/
virtual quint32 formatVersion() = 0;
void extractDatabase(QByteArray& xmlOutput, Database* db);
bool hasError() const;
QString errorString() const;