Skip to content

Commit

Permalink
Fixed various Qt5 changes in the http code
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Feb 28, 2016
1 parent aba4fa9 commit 7f7753a
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 71 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ find_package(Gcrypt 1.6.0 REQUIRED)

find_package(LibMicroHTTPD REQUIRED)

find_package(QJSON REQUIRED)

find_package(ZLIB REQUIRED)

check_cxx_source_compiles("
Expand Down
11 changes: 1 addition & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,6 @@ set(keepassx_SOURCES_MAINEXE
main.cpp
)

set(keepassx_MOC
http/AccessControlDialog.h
http/EntryConfig.h
http/HttpPasswordGeneratorWidget.h
http/OptionDialog.h
http/Protocol.h
http/Server.h
http/Service.h
)

set(keepassx_FORMS
gui/AboutDialog.ui
gui/ChangeMasterKeyWidget.ui
Expand Down Expand Up @@ -189,6 +179,7 @@ target_link_libraries(keepassx_core Qt5::Core Qt5::Concurrent Qt5::Widgets)
add_executable(${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES_MAINEXE})
target_link_libraries(${PROGNAME}
keepassx_core
${MHD_LIBRARIES}
Qt5::Core
Qt5::Concurrent
Qt5::Widgets
Expand Down
2 changes: 1 addition & 1 deletion src/core/Uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Uuid Uuid::fromBase64(const QString& str)

Uuid Uuid::fromHex(const QString& str)
{
QByteArray data = QByteArray::fromHex(str.toAscii());
QByteArray data = QByteArray::fromHex(str.toLatin1());
return Uuid(data);
}

Expand Down
3 changes: 1 addition & 2 deletions src/http/AccessControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

AccessControlDialog::AccessControlDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AccessControlDialog)
ui(new Ui::AccessControlDialog())
{
ui->setupUi(this);
connect(ui->allowButton, SIGNAL(clicked()), this, SLOT(accept()));
Expand All @@ -26,7 +26,6 @@ AccessControlDialog::AccessControlDialog(QWidget *parent) :

AccessControlDialog::~AccessControlDialog()
{
delete ui;
}

void AccessControlDialog::setUrl(const QString &url)
Expand Down
7 changes: 4 additions & 3 deletions src/http/AccessControlDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#ifndef ACCESSCONTROLDIALOG_H
#define ACCESSCONTROLDIALOG_H

#include <QtGui/QDialog>
#include <QDialog>
#include <QScopedPointer>

class Entry;

Expand All @@ -27,7 +28,7 @@ class AccessControlDialog : public QDialog
Q_OBJECT

public:
explicit AccessControlDialog(QWidget *parent = 0);
explicit AccessControlDialog(QWidget *parent = nullptr);
~AccessControlDialog();

void setUrl(const QString & url);
Expand All @@ -36,7 +37,7 @@ class AccessControlDialog : public QDialog
void setRemember(bool r);

private:
Ui::AccessControlDialog *ui;
QScopedPointer<Ui::AccessControlDialog> ui;
};

#endif // ACCESSCONTROLDIALOG_H
21 changes: 11 additions & 10 deletions src/http/EntryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
*/

#include "EntryConfig.h"
#include <QtCore>
#include "core/Entry.h"
#include "core/EntryAttributes.h"
#include "qjson/parser.h"
#include "qjson/qobjecthelper.h"
#include "qjson/serializer.h"
#include "http/Protocol.h"

static const char KEEPASSHTTP_NAME[] = "KeePassHttp Settings"; //TODO: duplicated string (also in Service.cpp)

Expand Down Expand Up @@ -83,19 +82,21 @@ bool EntryConfig::load(const Entry *entry)
if (s.isEmpty())
return false;

bool isOk = false;
QVariant v = QJson::Parser().parse(s.toUtf8(), &isOk);
if (!isOk || v.type() != QVariant::Map)
QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8());
if (doc.isNull())
return false;

QJson::QObjectHelper::qvariant2qobject(v.toMap(), this);
QVariantMap map = doc.object().toVariantMap();
for(QVariantMap::iterator iter = map.begin(); iter != map.end(); ++iter) {
setProperty(iter.key().toLatin1(), iter.value());
}
return true;
}

void EntryConfig::save(Entry *entry)
{
//QVariant v = QJson::QObjectHelper::qobject2qvariant(this, QJson::QObjectHelper::Flag_None);
QVariant v = QJson::QObjectHelper::qobject2qvariant(this);
QByteArray json = QJson::Serializer().serialize(v);
QVariantMap v = qobject2qvariant(this);
QJsonObject o = QJsonObject::fromVariantMap(v);
QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact);
entry->attributes()->set(KEEPASSHTTP_NAME, json);
}
11 changes: 4 additions & 7 deletions src/http/HttpPasswordGeneratorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KEEPASSX_PASSWORDGENERATORWIDGET_H
#define KEEPASSX_PASSWORDGENERATORWIDGET_H
#ifndef KEEPASSX_HTTPPASSWORDGENERATORWIDGET_H
#define KEEPASSX_HTTPPASSWORDGENERATORWIDGET_H

#include <QWidget>
#include <QComboBox>
#include <QScopedPointer>

#include "core/Global.h"
#include "core/PasswordGenerator.h"

namespace Ui {
class HttpPasswordGeneratorWidget;
}

class PasswordGenerator;

class HttpPasswordGeneratorWidget : public QWidget
{
Q_OBJECT

public:
explicit HttpPasswordGeneratorWidget(QWidget* parent = Q_NULLPTR);
explicit HttpPasswordGeneratorWidget(QWidget* parent = nullptr);
~HttpPasswordGeneratorWidget();
void loadSettings();
void reset();
Expand Down
3 changes: 1 addition & 2 deletions src/http/OptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

OptionDialog::OptionDialog(QWidget *parent) :
QWidget(parent),
ui(new Ui::OptionDialog)
ui(new Ui::OptionDialog())
{
ui->setupUi(this);
connect(ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SIGNAL(removeSharedEncryptionKeys()));
Expand All @@ -26,7 +26,6 @@ OptionDialog::OptionDialog(QWidget *parent) :

OptionDialog::~OptionDialog()
{
delete ui;
}

void OptionDialog::loadSettings()
Expand Down
7 changes: 4 additions & 3 deletions src/http/OptionDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#ifndef OPTIONDIALOG_H
#define OPTIONDIALOG_H

#include <QtGui/QWidget>
#include <QWidget>
#include <QScopedPointer>

namespace Ui {
class OptionDialog;
Expand All @@ -25,7 +26,7 @@ class OptionDialog : public QWidget
Q_OBJECT

public:
explicit OptionDialog(QWidget *parent = 0);
explicit OptionDialog(QWidget *parent = nullptr);
~OptionDialog();

public Q_SLOTS:
Expand All @@ -37,7 +38,7 @@ public Q_SLOTS:
void removeStoredPermissions();

private:
Ui::OptionDialog *ui;
QScopedPointer<Ui::OptionDialog> ui;
};

#endif // OPTIONDIALOG_H
59 changes: 39 additions & 20 deletions src/http/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
*/

#include "Protocol.h"

#include <QtCore/QMetaProperty>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

#include "qjson/parser.h"
#include "qjson/qobjecthelper.h"
#include "qjson/serializer.h"
#include <QtCore>

#include "crypto/Random.h"
#include "crypto/SymmetricCipher.h"
Expand All @@ -40,6 +33,24 @@ static const char * const STR_VERSION = "1.8.4.0";

using namespace KeepassHttpProtocol;

QVariantMap qobject2qvariant( const QObject* object, const QStringList& ignoredProperties )
{
QVariantMap result;
const QMetaObject *metaobject = object->metaObject();
int count = metaobject->propertyCount();
for (int i=0; i<count; ++i) {
QMetaProperty metaproperty = metaobject->property(i);
const char *name = metaproperty.name();

if (ignoredProperties.contains(QLatin1String(name)) || (!metaproperty.isReadable()))
continue;

QVariant value = object->property(name);
result[QLatin1String(name)] = value;
}
return result;
}

static QHash<QString, RequestType> createStringHash()
{
QHash<QString, RequestType> hash;
Expand All @@ -61,12 +72,12 @@ static RequestType parseRequest(const QString &str)

static QByteArray decode64(QString s)
{
return QByteArray::fromBase64(s.toAscii());
return QByteArray::fromBase64(s.toLatin1());
}

static QString encode64(QByteArray b)
{
return QString::fromAscii(b.toBase64());
return QString::fromLatin1(b.toBase64());
}

static QByteArray decrypt2(const QByteArray & data, SymmetricCipherGcrypt & cipher)
Expand Down Expand Up @@ -263,13 +274,15 @@ bool Request::CheckVerifier(const QString &key) const

bool Request::fromJson(QString text)
{
bool isok = false;
QVariant v = QJson::Parser().parse(text.toUtf8(), &isok);
if (!isok)
QJsonDocument doc = QJsonDocument::fromJson(text.toUtf8());
if (doc.isNull())
return false;

m_requestType.clear();
QJson::QObjectHelper::qvariant2qobject(v.toMap(), this);
QVariantMap map = doc.object().toVariantMap();
for(QVariantMap::iterator iter = map.begin(); iter != map.end(); ++iter) {
setProperty(iter.key().toLatin1(), iter.value());
}

return requestType() != INVALID;
}
Expand Down Expand Up @@ -307,11 +320,17 @@ void Response::setVerifier(QString key)

QString Response::toJson()
{
QVariant result = QJson::QObjectHelper::qobject2qvariant(this);
QJsonObject json;

int count = metaObject()->propertyCount();
for (int i=0; i<count; ++i) {
QMetaProperty metaproperty = metaObject()->property(i);
const char *name = metaproperty.name();
json.insert(QString(name), QJsonValue::fromVariant(this->property(name)));
}

QJson::Serializer s;
s.setIndentMode(QJson::IndentCompact);
return s.serialize(result);
QJsonDocument doc(json);
return doc.toJson(QJsonDocument::Compact);
}

KeepassHttpProtocol::RequestType Response::requestType() const
Expand Down Expand Up @@ -352,7 +371,7 @@ QVariant Response::getEntries() const
QList<QVariant> res;
res.reserve(m_entries.size());
Q_FOREACH (const Entry &entry, m_entries)
res.append(QJson::QObjectHelper::qobject2qvariant(&entry));
res.append(qobject2qvariant(&entry));
return res;
}

Expand Down Expand Up @@ -490,7 +509,7 @@ QVariant Entry::getStringFields() const
QList<QVariant> res;
res.reserve(m_stringFields.size());
Q_FOREACH (const StringField &stringfield, m_stringFields)
res.append(QJson::QObjectHelper::qobject2qvariant(&stringfield));
res.append(qobject2qvariant(&stringfield));
return res;
}

Expand Down
7 changes: 3 additions & 4 deletions src/http/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
#ifndef RESPONSE_H
#define RESPONSE_H

#include <QtCore/QObject>
#include <QtCore/QCryptographicHash>
#include <QtCore/QMetaType>
#include <QtCore/QVariant>
#include <QtCore>
#include "crypto/SymmetricCipherGcrypt.h"

QVariantMap qobject2qvariant( const QObject* object, const QStringList& ignoredProperties = QStringList(QString(QLatin1String("objectName"))) );

namespace KeepassHttpProtocol {

enum RequestType {
Expand Down
2 changes: 1 addition & 1 deletion src/http/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void Server::handleRequest(const QByteArray in, QByteArray *out)
(getDatabaseRootUuid() + getDatabaseRecycleBinUuid()).toUtf8(),
QCryptographicHash::Sha1).toHex();

Response protocolResp(r, QString::fromAscii(hash));
Response protocolResp(r, QString::fromLatin1(hash));
switch(r.requestType()) {
case INVALID: break;
case GET_LOGINS: getLogins(r, &protocolResp); break;
Expand Down
8 changes: 4 additions & 4 deletions src/http/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
***************************************************************************
*/

#include <QtGui/QInputDialog>
#include <QtGui/QMessageBox>
#include <QtGui/QProgressDialog>
#include <QtCore/QDebug>
#include <QInputDialog>
#include <QMessageBox>
#include <QProgressDialog>
#include <QDebug>

#include "Service.h"
#include "Protocol.h"
Expand Down
2 changes: 1 addition & 1 deletion src/http/Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#ifndef SERVICE_H
#define SERVICE_H

#include <QtCore/QObject>
#include <QObject>
#include "gui/DatabaseTabWidget.h"
#include "Server.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ set(TEST_LIBRARIES

set(testsupport_SOURCES modeltest.cpp FailDevice.cpp)
add_library(testsupport STATIC ${testsupport_SOURCES})
target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test)
target_link_libraries(testsupport ${MHD_LIBRARIES} Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test)

add_unit_test(NAME testgroup SOURCES TestGroup.cpp
LIBS ${TEST_LIBRARIES})
Expand Down
1 change: 1 addition & 0 deletions utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include_directories(../src)
add_executable(kdbx-extract kdbx-extract.cpp)
target_link_libraries(kdbx-extract
keepassx_core
${MHD_LIBRARIES}
Qt5::Core
Qt5::Concurrent
Qt5::Widgets
Expand Down

0 comments on commit 7f7753a

Please sign in to comment.