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
path: root/src
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2010-08-26 02:31:07 +0400
committerFelix Geyer <debfx@fobos.de>2010-08-26 02:31:07 +0400
commit3bf0564436475c06e3092c74ab717e4f3d675ab4 (patch)
tree9ceb44d52c20c88c692e4925102a607db5c7f01a /src
parent8df8f69e10da19533c284fa70a0814afd8f580da (diff)
Handle CustomData element.
This should make support for reading and writing KeePass 2 XML files complete (closes #1).
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/core/Database.h3
-rw-r--r--src/core/DbAttribute.cpp22
-rw-r--r--src/core/DbAttribute.h33
-rw-r--r--src/core/Parser.cpp26
-rw-r--r--src/core/Parser.h1
-rw-r--r--src/core/Writer.cpp20
-rw-r--r--src/core/Writer.h1
8 files changed, 43 insertions, 64 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d65755068..5f39d2f90 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,7 +19,6 @@ configure_file( config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepa
set(keepassx_SOURCES
core/Database.cpp
- core/DbAttribute.cpp
core/Entry.cpp
core/Group.cpp
core/Metadata.cpp
diff --git a/src/core/Database.h b/src/core/Database.h
index 19e129948..cb3e299b4 100644
--- a/src/core/Database.h
+++ b/src/core/Database.h
@@ -20,8 +20,6 @@
#include "Group.h"
-#include "DbAttribute.h"
-
#include <QtCore/QHash>
#include <QtGui/QImage>
@@ -64,7 +62,6 @@ private:
Metadata* m_metadata;
Group* m_rootGroup;
QHash<Uuid, QImage> m_customIcons;
- DbAttribute m_unhandledAttirbute;
QList<DeletedObject> m_deletedObjects;
};
diff --git a/src/core/DbAttribute.cpp b/src/core/DbAttribute.cpp
deleted file mode 100644
index 7626e8bda..000000000
--- a/src/core/DbAttribute.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
- *
- * 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/>.
- */
-
-#include "DbAttribute.h"
-
-DbAttribute::DbAttribute()
-{
-}
diff --git a/src/core/DbAttribute.h b/src/core/DbAttribute.h
deleted file mode 100644
index e694b07ef..000000000
--- a/src/core/DbAttribute.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
- *
- * 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_DBATTRIBUTE_H
-#define KEEPASSX_DBATTRIBUTE_H
-
-#include <QtCore/QHash>
-
-class DbAttribute
-{
-public:
- DbAttribute();
-
-private:
- QHash<QString, QString> properties;
- QHash<QString, DbAttribute> children;
-};
-
-#endif // KEEPASSX_DBATTRIBUTE_H
diff --git a/src/core/Parser.cpp b/src/core/Parser.cpp
index 062622523..80a31292a 100644
--- a/src/core/Parser.cpp
+++ b/src/core/Parser.cpp
@@ -210,9 +210,31 @@ void Parser::parseCustomData()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "CustomData");
- // TODO implement
while (!m_xml.error() && m_xml.readNextStartElement()) {
- skipCurrentElement();
+ if (m_xml.name() == "Item") {
+ parseCustomDataItem();
+ }
+ else {
+ skipCurrentElement();
+ }
+ }
+}
+
+void Parser::parseCustomDataItem()
+{
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Item");
+
+ QString key;
+ while (!m_xml.error() && m_xml.readNextStartElement()) {
+ if (m_xml.name() == "Key") {
+ key = readString();
+ }
+ else if (m_xml.name() == "Value") {
+ m_meta->addCustomField(key, readString());
+ }
+ else {
+ skipCurrentElement();
+ }
}
}
diff --git a/src/core/Parser.h b/src/core/Parser.h
index 0d2e5c933..b38bef226 100644
--- a/src/core/Parser.h
+++ b/src/core/Parser.h
@@ -46,6 +46,7 @@ private:
void parseCustomIcons();
void parseIcon();
void parseCustomData();
+ void parseCustomDataItem();
void parseRoot();
Group* parseGroup();
void parseDeletedObjects();
diff --git a/src/core/Writer.cpp b/src/core/Writer.cpp
index 5673b3e2f..0de34fb95 100644
--- a/src/core/Writer.cpp
+++ b/src/core/Writer.cpp
@@ -100,8 +100,9 @@ void Writer::writeCustomIcons()
{
m_xml.writeStartElement("CustomIcons");
- Q_FOREACH (const Uuid& uuid, m_meta->customIcons().keys()) {
- writeIcon(uuid, m_meta->customIcons().value(uuid));
+ QHash<Uuid, QImage> customIcons = m_meta->customIcons();
+ Q_FOREACH (const Uuid& uuid, customIcons.keys()) {
+ writeIcon(uuid, customIcons.value(uuid));
}
m_xml.writeEndElement();
@@ -127,7 +128,20 @@ void Writer::writeCustomData()
{
m_xml.writeStartElement("CustomData");
- // TODO implement
+ QHash<QString, QString> customFields = m_meta->customFields();
+ Q_FOREACH (const QString& key, customFields.keys()) {
+ writeCustomDataItem(key, customFields.value(key));
+ }
+
+ m_xml.writeEndElement();
+}
+
+void Writer::writeCustomDataItem(const QString& key, const QString& value)
+{
+ m_xml.writeStartElement("Item");
+
+ writeString("Key", key);
+ writeString("Value", value);
m_xml.writeEndElement();
}
diff --git a/src/core/Writer.h b/src/core/Writer.h
index eeffe9b2f..62d0fb649 100644
--- a/src/core/Writer.h
+++ b/src/core/Writer.h
@@ -46,6 +46,7 @@ private:
void writeCustomIcons();
void writeIcon(const Uuid& uuid, const QImage& image);
void writeCustomData();
+ void writeCustomDataItem(const QString& key, const QString& value);
void writeRoot();
void writeGroup(const Group* group);
void writeTimes(const TimeInfo& ti);