Initial import.

This commit is contained in:
Felix Geyer 2010-08-07 15:10:44 +02:00
commit 3e3c23e4ad
23 changed files with 2446 additions and 0 deletions

42
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,42 @@
# 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/>.
set(keepassx_SOURCES
main.cpp
core/Database.cpp
core/DbAttribute.cpp
core/Entry.cpp
core/Group.cpp
core/Metadata.cpp
core/Parser.cpp
core/TimeInfo.cpp
core/Uuid.cpp
)
set(keepassx_HEADERS
core/Database.h
core/DbAttribute.h
core/Entry.h
core/Group.h
core/Metadata.h
core/Parser.h
core/TimeInfo.h
core/Uuid.h
)
qt4_wrap_cpp( keepassx_MOC ${keepassx_HEADERS} )
add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES} ${keepassx_MOC} )
target_link_libraries( ${PROGNAME} ${QT_LIBRARIES} )

35
src/core/Database.cpp Normal file
View file

@ -0,0 +1,35 @@
/*
* 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 "Database.h"
#include <QtCore/QFile>
#include <QtCore/QXmlStreamReader>
#include "Parser.h"
Database::Database(const QString& filename)
{
m_filename = filename;
}
void Database::open()
{
Parser* parser = new Parser(this);
parser->parse(m_filename);
}

46
src/core/Database.h Normal file
View file

@ -0,0 +1,46 @@
/*
* 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_DATABASE_H
#define KEEPASSX_DATABASE_H
#include "Group.h"
#include "DbAttribute.h"
#include <QtCore/QHash>
#include <QtGui/QImage>
class Metadata;
class Database
{
public:
Database(const QString& filename);
Group* rootGroup();
private:
void open();
QString m_filename;
Metadata* m_metadata;
Group* m_rootGroup;
QHash<Uuid, QImage> customImages;
DbAttribute unhandledAttirbute;
};
#endif // KEEPASSX_DATABASE_H

22
src/core/DbAttribute.cpp Normal file
View file

@ -0,0 +1,22 @@
/*
* 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()
{
}

33
src/core/DbAttribute.h Normal file
View file

@ -0,0 +1,33 @@
/*
* 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

22
src/core/Entry.cpp Normal file
View file

@ -0,0 +1,22 @@
/*
* 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 "Entry.h"
Entry::Entry()
{
}

38
src/core/Entry.h Normal file
View file

@ -0,0 +1,38 @@
/*
* 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_ENTRY_H
#define KEEPASSX_ENTRY_H
#include "Uuid.h"
#include <QtCore/QHash>
class Entry
{
public:
Entry();
private:
Uuid m_uuid;
int m_icon;
Uuid m_customIcon;
QHash<QString, QString> m_attributes;
QHash<QString, QByteArray> m_binaries;
};
#endif // KEEPASSX_ENTRY_H

22
src/core/Group.cpp Normal file
View file

@ -0,0 +1,22 @@
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "Group.h"

36
src/core/Group.h Normal file
View file

@ -0,0 +1,36 @@
/*
* 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_GROUP_H
#define KEEPASSX_GROUP_H
#include "Entry.h"
#include "Uuid.h"
class Group {
private:
Uuid m_uuid;
QString m_name;
QString m_notes;
int m_icon;
Uuid m_customIcon;
bool m_isExpanded;
QList<Entry> m_children;
};
#endif // KEEPASSX_GROUP_H

260
src/core/Metadata.cpp Normal file
View file

@ -0,0 +1,260 @@
/*
* 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 "Metadata.h"
Metadata::Metadata()
{
}
QString Metadata::generator() const
{
return m_generator;
};
QString Metadata::name() const
{
return m_name;
};
QDateTime Metadata::nameChanged() const
{
return m_nameChanged;
};
QString Metadata::description() const
{
return m_description;
};
QDateTime Metadata::descriptionChanged() const
{
return m_descriptionChanged;
};
QString Metadata::defaultUserName() const
{
return m_defaultUserName;
};
int Metadata::maintenanceHistoryDays() const
{
return m_maintenanceHistoryDays;
};
bool Metadata::protectTitle() const
{
return m_protectTitle;
};
bool Metadata::protectUsername() const
{
return m_protectUsername;
};
bool Metadata::protectPassword() const
{
return m_protectPassword;
};
bool Metadata::protectUrl() const
{
return m_protectUrl;
};
bool Metadata::protectNotes() const
{
return m_protectNotes;
};
bool Metadata::autoEnableVisualHiding() const
{
return m_autoEnableVisualHiding;
};
QHash<Uuid, QImage> Metadata::customIcons() const
{
return m_customIcons;
};
bool Metadata::recycleBinEnabled() const
{
return m_recycleBinEnabled;
};
Uuid Metadata::recycleBinUuid() const
{
return m_recycleBinUuid;
};
QDateTime Metadata::recycleBinChanged() const
{
return m_recycleBinChanged;
};
Uuid Metadata::entryTemplatesGroup() const
{
return m_entryTemplatesGroup;
};
QDateTime Metadata::entryTemplatesGroupChanged() const
{
return m_entryTemplatesGroupChanged;
};
Uuid Metadata::lastSelectedGroup() const
{
return m_lastSelectedGroup;
};
Uuid Metadata::lastTopVisibleGroup() const
{
return m_lastTopVisibleGroup;
};
QHash<QString, QString> Metadata::customFields() const
{
return m_customFields;
};
void Metadata::setGenerator(const QString& value)
{
m_generator = value;
}
void Metadata::setName(const QString& value)
{
m_name = value;
}
void Metadata::setNameChanged(const QDateTime& value)
{
m_nameChanged = value;
}
void Metadata::setDescription(const QString& value)
{
m_description = value;
}
void Metadata::setDescriptionChanged(const QDateTime& value)
{
m_descriptionChanged = value;
}
void Metadata::setDefaultUserName(const QString& value)
{
m_defaultUserName = value;
}
void Metadata::setMaintenanceHistoryDays(int value)
{
m_maintenanceHistoryDays = value;
}
void Metadata::setProtectTitle(bool value)
{
m_protectTitle = value;
}
void Metadata::setProtectUsername(bool value)
{
m_protectUsername = value;
}
void Metadata::setProtectPassword(bool value)
{
m_protectPassword = value;
}
void Metadata::setProtectUrl(bool value)
{
m_protectUrl = value;
}
void Metadata::setProtectNotes(bool value)
{
m_protectNotes = value;
}
void Metadata::setAutoEnableVisualHiding(bool value)
{
m_autoEnableVisualHiding = value;
}
void Metadata::addCustomIcon(const Uuid& uuid, const QImage& image)
{
Q_ASSERT(!m_customIcons.contains(uuid));
m_customIcons.insert(uuid, image);
}
void Metadata::removeCustomIcon(const Uuid& uuid)
{
Q_ASSERT(m_customIcons.contains(uuid));
m_customIcons.remove(uuid);
}
void Metadata::setRecycleBinEnabled(bool value)
{
m_recycleBinEnabled = value;
}
void Metadata::setRecycleBinUuid(const Uuid& value)
{
m_recycleBinUuid = value;
}
void Metadata::setRecycleBinChanged(const QDateTime& value)
{
m_recycleBinChanged = value;
}
void Metadata::setEntryTemplatesGroup(const Uuid& value)
{
m_entryTemplatesGroup = value;
}
void Metadata::setEntryTemplatesGroupChanged(const QDateTime& value)
{
m_entryTemplatesGroupChanged = value;
}
void Metadata::setLastSelectedGroup(const Uuid& value)
{
m_lastSelectedGroup = value;
}
void Metadata::setLastTopVisibleGroup(const Uuid& value)
{
m_lastTopVisibleGroup = value;
}
void Metadata::addCustomField(const QString& key, const QString& value)
{
Q_ASSERT(!m_customFields.contains(key));
m_customFields.insert(key, value);
}
void Metadata::removeCustomField(const QString& key)
{
Q_ASSERT(m_customFields.contains(key));
m_customFields.remove(key);
}

109
src/core/Metadata.h Normal file
View file

@ -0,0 +1,109 @@
/*
* 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_METADATA_H
#define KEEPASSX_METADATA_H
#include "Uuid.h"
#include <QtCore/QDateTime>
#include <QtCore/QHash>
#include <QtGui/QImage>
class Metadata
{
public:
Metadata();
QString generator() const;
QString name() const;
QDateTime nameChanged() const;
QString description() const;
QDateTime descriptionChanged() const;
QString defaultUserName() const;
int maintenanceHistoryDays() const;
bool protectTitle() const;
bool protectUsername() const;
bool protectPassword() const;
bool protectUrl() const;
bool protectNotes() const;
bool autoEnableVisualHiding() const;
QHash<Uuid, QImage> customIcons() const;
bool recycleBinEnabled() const;
Uuid recycleBinUuid() const;
QDateTime recycleBinChanged() const;
Uuid entryTemplatesGroup() const;
QDateTime entryTemplatesGroupChanged() const;
Uuid lastSelectedGroup() const;
Uuid lastTopVisibleGroup() const;
QHash<QString, QString> customFields() const;
void setGenerator(const QString& value);
void setName(const QString& value);
void setNameChanged(const QDateTime& value);
void setDescription(const QString& value);
void setDescriptionChanged(const QDateTime& value);
void setDefaultUserName(const QString& value);
void setMaintenanceHistoryDays(int value);
void setProtectTitle(bool value);
void setProtectUsername(bool value);
void setProtectPassword(bool value);
void setProtectUrl(bool value);
void setProtectNotes(bool value);
void setAutoEnableVisualHiding(bool value);
void addCustomIcon(const Uuid& uuid, const QImage& image);
void removeCustomIcon(const Uuid& uuid);
void setRecycleBinEnabled(bool value);
void setRecycleBinUuid(const Uuid& value);
void setRecycleBinChanged(const QDateTime& value);
void setEntryTemplatesGroup(const Uuid& value);
void setEntryTemplatesGroupChanged(const QDateTime& value);
void setLastSelectedGroup(const Uuid& value);
void setLastTopVisibleGroup(const Uuid& value);
void addCustomField(const QString& key, const QString& value);
void removeCustomField(const QString& key);
private:
QString m_generator;
QString m_name;
QDateTime m_nameChanged;
QString m_description;
QDateTime m_descriptionChanged;
QString m_defaultUserName;
int m_maintenanceHistoryDays;
bool m_protectTitle;
bool m_protectUsername;
bool m_protectPassword;
bool m_protectUrl;
bool m_protectNotes;
bool m_autoEnableVisualHiding;
QHash<Uuid, QImage> m_customIcons;
bool m_recycleBinEnabled;
Uuid m_recycleBinUuid;
QDateTime m_recycleBinChanged;
Uuid m_entryTemplatesGroup;
QDateTime m_entryTemplatesGroupChanged;
Uuid m_lastSelectedGroup;
Uuid m_lastTopVisibleGroup;
QHash<QString, QString> m_customFields;
};
#endif // KEEPASSX_METADATA_H

465
src/core/Parser.cpp Normal file
View file

@ -0,0 +1,465 @@
/*
* 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 "Parser.h"
#include <QtCore/QFile>
Parser::Parser(Database* db)
{
m_db = db;
}
bool Parser::parse(const QString& filename)
{
QFile file(filename);
file.open(QIODevice::ReadOnly | QIODevice::Text);
m_xml.setDevice(&file);
if (m_xml.readNextStartElement()) {
if (m_xml.name() == "KeePassFile") {
parseKeePassFile();
}
else {
m_xml.raiseError(tr("Invalid database file"));
}
}
return !m_xml.error();
}
void Parser::parseKeePassFile()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "KeePassFile");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Meta") {
parseMeta();
}
else if (m_xml.name() == "Root") {
parseRoot();
}
else {
m_xml.raiseError(tr("Invalid database file"));
}
}
}
void Parser::parseMeta()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Meta");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Generator") {
}
else if (m_xml.name() == "DatabaseName") {
}
else if (m_xml.name() == "DatabaseNameChanged") {
}
else if (m_xml.name() == "DatabaseDescription") {
}
else if (m_xml.name() == "DatabaseDescriptionChanged") {
}
else if (m_xml.name() == "DefaultUserName") {
}
else if (m_xml.name() == "DefaultUserNameChanged") {
}
else if (m_xml.name() == "MaintenanceHistoryDays") {
}
else if (m_xml.name() == "MemoryProtection") {
parseMemoryProtection();
}
else if (m_xml.name() == "CustomIcons") {
parseCustomIcons();
}
else if (m_xml.name() == "RecycleBinEnabled") {
}
else if (m_xml.name() == "RecycleBinUUID") {
}
else if (m_xml.name() == "RecycleBinChanged") {
}
else if (m_xml.name() == "EntryTemplatesGroup") {
}
else if (m_xml.name() == "EntryTemplatesGroupChanged") {
}
else if (m_xml.name() == "LastSelectedGroup") {
}
else if (m_xml.name() == "LastTopVisibleGroup") {
}
else if (m_xml.name() == "CustomData") {
parseCustomData();
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseMemoryProtection()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "MemoryProtection");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "ProtectTitle") {
}
else if (m_xml.name() == "ProtectUserName") {
}
else if (m_xml.name() == "ProtectPassword") {
}
else if (m_xml.name() == "ProtectURL") {
}
else if (m_xml.name() == "ProtectNotes") {
}
else if (m_xml.name() == "AutoEnableVisualHiding") {
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseCustomIcons()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "CustomIcons");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Icon") {
parseIcon();
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseIcon()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Icon");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") {
}
else if (m_xml.name() == "Data") {
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseCustomData()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "CustomData");
// TODO
}
void Parser::parseRoot()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Root");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Group") {
parseGroup();
}
else if (m_xml.name() == "DeletedObjects") {
// ?????????????????
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseGroup()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Group");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") {
}
else if (m_xml.name() == "Name") {
}
else if (m_xml.name() == "Notes") {
}
else if (m_xml.name() == "IconID") {
}
else if (m_xml.name() == "Times") {
parseTimes();
}
else if (m_xml.name() == "IsExpanded") {
}
else if (m_xml.name() == "DefaultAutoTypeSequence") {
}
else if (m_xml.name() == "EnableAutoType") {
}
else if (m_xml.name() == "EnableSearching") {
}
else if (m_xml.name() == "LastTopVisibleEntry") {
}
else if (m_xml.name() == "Group") {
parseGroup();
}
else if (m_xml.name() == "Entry") {
parseEntry();
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseEntry()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Entry");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") {
}
else if (m_xml.name() == "IconID") {
}
else if (m_xml.name() == "CustomIconUUID") {
}
else if (m_xml.name() == "ForegroundColor") {
}
else if (m_xml.name() == "BackgroundColor") {
}
else if (m_xml.name() == "OverrideURL") {
}
else if (m_xml.name() == "Times") {
parseTimes();
}
else if (m_xml.name() == "String") {
parseEntryString();
}
else if (m_xml.name() == "Binary") {
parseEntryBinary();
}
else if (m_xml.name() == "AutoType") {
parseAutoType();
}
else if (m_xml.name() == "History") {
parseEntryHistory();
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseEntryString()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "String");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Key") {
}
else if (m_xml.name() == "Value") {
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseEntryBinary()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Binary");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Key") {
}
else if (m_xml.name() == "Value") {
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseAutoType()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "AutoType");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Enabled") {
}
else if (m_xml.name() == "DataTransferObfuscation") {
}
else if (m_xml.name() == "Association") {
parseAutoTypeAssoc();
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseAutoTypeAssoc()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Association");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Window") {
}
else if (m_xml.name() == "KeystrokeSequence") {
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseEntryHistory()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "History");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "Entry") {
parseEntry();
}
else {
m_xml.skipCurrentElement();
}
}
}
void Parser::parseTimes()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Times");
while (m_xml.readNextStartElement()) {
if (m_xml.name() == "LastModificationTime") {
}
else if (m_xml.name() == "CreationTime") {
}
else if (m_xml.name() == "LastAccessTime") {
}
else if (m_xml.name() == "ExpiryTime") {
}
else if (m_xml.name() == "Expires") {
}
else if (m_xml.name() == "UsageCount") {
}
else if (m_xml.name() == "LocationChanged") {
}
else {
m_xml.skipCurrentElement();
}
}
}
QString Parser::readString()
{
return m_xml.readElementText();
}
bool Parser::readBool()
{
QString str = readString();
if (str == "True") {
return true;
}
else if (str == "False") {
return false;
}
else {
// TODO error
}
}
QDateTime Parser::readDateTime()
{
QString str = readString();
QDateTime dt = QDateTime::fromString(str, Qt::ISODate);
if (!dt.isValid()) {
// TODO error
}
return dt;
}
int Parser::readInt()
{
// TODO
}
Uuid Parser::readUuid()
{
// TODO
}
QByteArray Parser::readBinary()
{
// TODO
}

64
src/core/Parser.h Normal file
View file

@ -0,0 +1,64 @@
/*
* 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_PARSER_H
#define KEEPASSX_PARSER_H
#include <QtCore/QDateTime>
#include <QtCore/QXmlStreamReader>
#include "Uuid.h"
class Database;
class Parser : public QObject
{
Q_OBJECT
public:
Parser(Database* db);
bool parse(const QString& filename);
private:
void parseKeePassFile();
void parseMeta();
void parseMemoryProtection();
void parseCustomIcons();
void parseIcon();
void parseCustomData();
void parseRoot();
void parseGroup();
void parseEntry();
void parseEntryString();
void parseEntryBinary();
void parseAutoType();
void parseAutoTypeAssoc();
void parseEntryHistory();
void parseTimes();
QString readString();
bool readBool();
QDateTime readDateTime();
int readInt();
Uuid readUuid();
QByteArray readBinary();
QXmlStreamReader m_xml;
Database* m_db;
};
#endif // KEEPASSX_PARSER_H

22
src/core/TimeInfo.cpp Normal file
View file

@ -0,0 +1,22 @@
/*
* 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 "TimeInfo.h"
TimeInfo::TimeInfo()
{
}

27
src/core/TimeInfo.h Normal file
View file

@ -0,0 +1,27 @@
/*
* 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_DBTIMEINFO_H
#define KEEPASSX_DBTIMEINFO_H
class TimeInfo
{
public:
TimeInfo();
};
#endif // KEEPASSX_DBTIMEINFO_H

74
src/core/Uuid.cpp Normal file
View file

@ -0,0 +1,74 @@
/*
* 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 "Uuid.h"
Uuid::Uuid() : m_data(16, 0)
{
}
Uuid::Uuid(bool generate) : m_data(16, 0)
{
if (generate) {
while (isNull()) {
// TODO
}
}
}
Uuid::Uuid(const QByteArray& data)
{
Q_ASSERT(data.size() == 16);
m_data = data;
}
QString Uuid::toString() const
{
return m_data.toHex();
}
QByteArray Uuid::toByteArray() const
{
return m_data;
}
bool Uuid::isNull() const
{
for (int i=0; i<m_data.size(); ++i) {
if (m_data[i] != 0)
return false;
}
return true;
}
bool Uuid::operator==(const Uuid& other) const
{
return m_data == other.m_data;
}
bool Uuid::operator!=(const Uuid& other) const
{
return !operator==(other);
}
uint qHash(const Uuid& key)
{
return qHash(key.toByteArray());
}

42
src/core/Uuid.h Normal file
View file

@ -0,0 +1,42 @@
/*
* 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_UUID_H
#define KEEPASSX_UUID_H
#include <QtCore/QByteArray>
#include <QtCore/QString>
class Uuid
{
public:
Uuid();
Uuid(bool generate);
Uuid(const QByteArray& data);
QString toString() const;
QByteArray toByteArray() const;
bool isNull() const;
bool operator==(const Uuid& other) const;
bool operator!=(const Uuid& other) const;
private:
QByteArray m_data;
};
uint qHash(const Uuid& key);
#endif // KEEPASSX_UUID_H

23
src/main.cpp Normal file
View file

@ -0,0 +1,23 @@
/*
* 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 "core/Database.h"
int main(int argc, char **argv)
{
}