Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#logicmodule/CMakeLists.txt
project(duperagent VERSION 0.1 LANGUAGES CXX)

qt_add_library(${PROJECT_NAME} SHARED
qmldir
)


set(HEADERS duperagent.h qpm.h request.h response.h serialization.h
jsvalueiterator.h config.h cookiejar.h promise.h
promisemodule.h networkactivityindicator.h imageutils.h
multipartsource.h ssl.h
)

set(SOURCES duperagent.cpp request.cpp response.cpp serialization.cpp
config.cpp cookiejar.cpp promise.cpp promisemodule.cpp
networkactivityindicator.cpp imageutils.cpp multipartsource.cpp
ssl.cpp)

qt6_add_qml_module(${PROJECT_NAME}
URI duperagent
VERSION 1.0
NO_PLUGIN
RESOURCE_PREFIX "/qt/qml/"
SOURCES ${HEADERS} ${SOURCES}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
Qt6::Core
Qt6::Gui
Qt6::Qml
Qt6::Quick
)

target_include_directories(${PROJECT_NAME}
PUBLIC
)
16 changes: 16 additions & 0 deletions cookiejar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QTextStream>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QStringConverter>
#endif
#include <QtNetwork/QNetworkCookie>

#include "cookiejar.h"
Expand Down Expand Up @@ -58,12 +61,21 @@ void CookieJar::save() const
}

QTextStream out(&file);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
out.setEncoding( QStringConverter::Utf8 );
#else
out.setCodec("UTF-8");
#endif

QList<QNetworkCookie> cookies = allCookies();
foreach (QNetworkCookie c, cookies) {
if (m_persistSessions || !c.isSessionCookie())
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
out << c.toRawForm() << Qt::endl;
#else
out << c.toRawForm() << endl;
#endif
}

file.close();
Expand All @@ -78,7 +90,11 @@ void CookieJar::load()
}

QTextStream in(&file);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
in.setEncoding( QStringConverter::Utf8 );
#else
in.setCodec("UTF-8");
#endif

QList<QNetworkCookie> cookies;
while (!in.atEnd()) {
Expand Down
3 changes: 2 additions & 1 deletion imageutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Image::Image(QQmlEngine *engine, const QString &filename) :
engine->setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
if (filename.startsWith(QStringLiteral("data:"))) {
int comma = filename.indexOf(QChar(','));
QStringRef data = filename.midRef(comma+1);
// QStringRef data = filename.midRef(comma+1);
QString data = filename.mid(comma+1);
QBuffer *buffer = new QBuffer(this);
buffer->setData(QByteArray::fromBase64(data.toLatin1()));
m_reader = new QImageReader(buffer);
Expand Down
30 changes: 28 additions & 2 deletions response.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// Copyright 2016 Cutehacks AS. All rights reserved.
// License can be found in the LICENSE file.


#include <QtGlobal>

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QRegularExpressionMatch>
#include <QStringConverter>
#include <QStringDecoder>
#else
#include <QtCore/QRegExp>
#include <QtCore/QTextCodec>
#endif



#include <QtNetwork/QNetworkReply>
#include <QtQml/QQmlEngine>
#include <QJsonObject>
Expand All @@ -19,16 +31,30 @@ ResponsePrototype::ResponsePrototype(QQmlEngine *engine, QNetworkReply *reply, i
{
QString type = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QRegularExpression charsetRegexp(".*charset=(.*)[\\s]*", QRegularExpression::CaseInsensitiveOption );
QRegularExpressionMatch matchResult = charsetRegexp.match(type) ;
if ( matchResult.hasMatch() ) {
m_charset = matchResult.captured(1);
}
#else
QRegExp charsetRegexp(".*charset=(.*)[\\s]*", Qt::CaseInsensitive, QRegExp::RegExp2);
if (charsetRegexp.exactMatch(type)) {
m_charset = charsetRegexp.capturedTexts().at(1);
}
#endif


if (m_reply->isReadable()) {
QByteArray data = m_reply->readAll();

QTextCodec *text = QTextCodec::codecForName(m_charset.toLatin1());
m_text = text ? text->makeDecoder()->toUnicode(data) : QString::fromUtf8(data);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringDecoder decoder = QStringDecoder ( qUtf8Printable(m_charset) );
m_text = decoder.isValid() ? decoder.decode(data) : QString::fromUtf8(data);
#else
QTextCodec *text = QTextCodec::codecForName(m_charset.toLatin1());
m_text = text ? text->makeDecoder()->toUnicode(data) : QString::fromUtf8(data);
#endif

switch (responseType)
{
Expand Down
19 changes: 18 additions & 1 deletion ssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,33 @@ QJSValue SecureConnectEvent::getPeerCertificate()
QString SecureConnectEvent::getProtocol()
{
switch (m_ssl.sessionProtocol()) {

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
case QSsl::SslV3:
return QStringLiteral("SSLv3");
return QStringLiteral("SSLv3");
case QSsl::TlsV1_0:
return QStringLiteral("TLSv1");
case QSsl::TlsV1_1:
return QStringLiteral("TLSv1.1");
case QSsl::TlsV1_2:
return QStringLiteral("TLSv1.2");
default:
return QStringLiteral("unknown");
#else
case QSsl::TlsV1_0:
return QStringLiteral("TLSv1");
case QSsl::TlsV1_1:
return QStringLiteral("TLSv1.1");
case QSsl::TlsV1_2:
return QStringLiteral("TLSv1.2");
case QSsl::TlsV1_3:
return QStringLiteral("TLSv1.3");
case QSsl::TlsV1_3OrLater:
return QStringLiteral("TLSv1.3 or later");
default:
return QStringLiteral("unknown");
#endif

}
}

Expand Down