diff --git a/KShare.pro b/KShare.pro index 74d2d48..432fc3e 100644 --- a/KShare.pro +++ b/KShare.pro @@ -66,7 +66,8 @@ SOURCES += main.cpp\ cropeditor/drawing/arrowitem.cpp \ uploaders/default/imgursettingsdialog.cpp \ uploaders/default/imgplusuploader.cpp \ - filenamevalidator.cpp + filenamevalidator.cpp \ + logs/requestlogging.cpp HEADERS += mainwindow.hpp \ cropeditor/cropeditor.hpp \ @@ -111,7 +112,8 @@ HEADERS += mainwindow.hpp \ cropeditor/drawing/arrowitem.hpp \ uploaders/default/imgursettingsdialog.hpp \ uploaders/default/imgplusuploader.hpp \ - filenamevalidator.hpp + filenamevalidator.hpp \ + logs/requestlogging.hpp nopkg { # win32 { diff --git a/io/ioutils.cpp b/io/ioutils.cpp index 2d190e6..c66bbc8 100644 --- a/io/ioutils.cpp +++ b/io/ioutils.cpp @@ -94,3 +94,22 @@ void ioutils::postData(QUrl target, delete reply; }); } + + +QString ioutils::methodString(QNetworkAccessManager::Operation operation) { + switch (operation) { + case QNetworkAccessManager::GetOperation: + return "GET"; + case QNetworkAccessManager::PostOperation: + return "POST"; + case QNetworkAccessManager::PutOperation: + return "PUT"; + case QNetworkAccessManager::DeleteOperation: + return "DELETE"; + case QNetworkAccessManager::HeadOperation: + return "HEAD"; + default: + // return "Dunno"; + return "Unknown"; + } +} diff --git a/io/ioutils.hpp b/io/ioutils.hpp index d4e50c7..4bef7a3 100644 --- a/io/ioutils.hpp +++ b/io/ioutils.hpp @@ -24,6 +24,7 @@ void postMultipartData(QUrl target, QList> headers, QHttpMultiPart *body, std::function callback); +QString methodString(QNetworkAccessManager::Operation operation); } #endif // IOUTILS_HPP diff --git a/logs/requestlogging.cpp b/logs/requestlogging.cpp new file mode 100644 index 0000000..a0d6e34 --- /dev/null +++ b/logs/requestlogging.cpp @@ -0,0 +1,33 @@ +#include "requestlogging.hpp" +#include +#include +#include +#include + +QDir responses(settings::dir().absoluteFilePath("response")); +void requestlogging::addEntry(RequestContext context) { + if (!responses.exists()) responses.mkpath("."); + QFile responseFile(responses.absoluteFilePath(context.sender + "-" + QDateTime().toString("yyyy-MM-dd HH-mm-ss"))); + if (!responseFile.open(QIODevice::WriteOnly)) { + qCritical().noquote() << "Could not save response! " + responseFile.errorString(); + return; + } + responseFile.write(( // + ioutils::methodString(context.reply->operation()) + // write method + " " + // space + context.reply->url().toString() + // write url + " " + // space + QString::number(context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute)) + + // write status + "\n" // newline + ) + .toUtf8()); + for (auto header : context.reply->rawHeaderList()) responseFile.write(header + "\n"); + responseFile.write("\n\n" + context.response); + responseFile.close(); + + addGUIEntry(context, QFileInfo(responseFile).absoluteFilePath()); +} + +void requestlogging::addGUIEntry(RequestContext context, QString file) { +} diff --git a/logs/requestlogging.hpp b/logs/requestlogging.hpp new file mode 100644 index 0000000..fe6da48 --- /dev/null +++ b/logs/requestlogging.hpp @@ -0,0 +1,18 @@ +#ifndef REQUESTLOGGING_HPP +#define REQUESTLOGGING_HPP + +#include +#include + +struct RequestContext { + QByteArray response; + QString sender; + QNetworkReply *reply; +}; + +namespace requestlogging { +void addEntry(RequestContext context); +void addGUIEntry(RequestContext context, QString file); +} + +#endif // REQUESTLOGGING_HPP diff --git a/main.cpp b/main.cpp index a1ed9af..3c3a892 100644 --- a/main.cpp +++ b/main.cpp @@ -26,7 +26,7 @@ bool verbose = false; bool stillAlive = true; #define LOGACT(lvl) \ - std::cout << lvl << stdMsg << "\n"; \ + std::cout << lvl << stdMsg << "\n" << std::flush; \ if (stillAlive && MainWindow::inst() && MainWindow::inst()->valid()) { \ MainWindow::inst()->ui->logBox->addItem(lvl + msg); \ } @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) { Worker::init(); a.connect(&a, &QApplication::aboutToQuit, Worker::end); a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; }); - screenshotutil::renderText("DICKS").save("/home/arsen/test.png"); + if (!parser.isSet(h)) w.show(); return a.exec(); } diff --git a/uploaders/customuploader.cpp b/uploaders/customuploader.cpp index 84973d6..f83f05b 100644 --- a/uploaders/customuploader.cpp +++ b/uploaders/customuploader.cpp @@ -318,6 +318,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) { part.setBody(QJsonDocument::fromVariant(result.toVariantMap()).toJson()); multipart->append(part); } + QByteArray cdh("form-data"); for (QString headerVal : valo.keys()) { if (headerVal.startsWith("__")) { headerVal = headerVal.mid(2); @@ -325,8 +326,10 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) { if (str.startsWith("/") && str.endsWith("/")) str = str.mid(1, str.length() - 1).replace("%contenttype", mime); part.setRawHeader(headerVal.toLatin1(), str.toLatin1()); - } + } else + cdh += "; " + headerVal + ": \"" + valo[headerVal].toString().replace("\"", "\\\"") + "\""; } + part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh) } switch (method) { case HttpMethod::POST: