From aadc303cea991f096c704e839c6343c6e06240c5 Mon Sep 17 00:00:00 2001 From: niansa Date: Sun, 16 Aug 2020 14:54:54 +0200 Subject: [PATCH] Fixed all current bugs (I suppose) --- libcommsy.hpp | 12 +++++++++++- libcommsyauth.hpp | 1 + main.cpp | 12 +++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libcommsy.hpp b/libcommsy.hpp index 3f0b4f4..29f6f78 100644 --- a/libcommsy.hpp +++ b/libcommsy.hpp @@ -67,6 +67,10 @@ std::vector merge_strvects(std::vector base, const std } static long curlreq(std::stringstream &responsebuffer, std::string SID, std::string URL) { + std::cout << "Connection details begin" << std::endl; + std::cout << "URL: " << URL << std::endl; + std::cout << "SID: " << SID << std::endl; + std::cout << "Connection details end" << std::endl; // Initialise variables curlpp::Cleanup cleaner; curlpp::Easy request; @@ -349,7 +353,7 @@ public: return &thispost->description; } - libCommsy(std::string _server_url, std::string _server_sid, std::string _room) { + libCommsy(const std::string& _server_url, const std::string& _server_sid, const std::string& _room) { // Define required variables server_url = _server_url; server_sid = _server_sid; @@ -360,6 +364,11 @@ public: long statuscode; numposts = 0; + // Make sure the server_url doesn't end with / + if (*(server_url.end() - 1) == '/') { + server_url.pop_back(); + } + while (1) { // Check connection and download feed try { @@ -372,6 +381,7 @@ public: } else if (statuscode == 500) { throw invalidRoomError(); } else if (statuscode != 200) { + std::cout << "Unhandled status code " << statuscode << std::endl; throw connectionFailError(); } diff --git a/libcommsyauth.hpp b/libcommsyauth.hpp index 3d92cf9..dee80b2 100644 --- a/libcommsyauth.hpp +++ b/libcommsyauth.hpp @@ -65,6 +65,7 @@ public: // Create request mNetReq->setUrl(authUrl + "&mod=context&fct=login"); mNetReq->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + mNetReq->setAttribute(QNetworkRequest::FollowRedirectsAttribute, false); // Perform the request std::cout << mNetReq->url().toString().toStdString() << std::endl; diff --git a/main.cpp b/main.cpp index ab26b16..f8d1a1b 100644 --- a/main.cpp +++ b/main.cpp @@ -28,14 +28,10 @@ QSettings *settings; class _UILoader { libCommsy *connector = nullptr; - libCommsyAuth *auther; + libCommsyAuth *auther = nullptr; bool cacheInvalidate = true; public: - _UILoader() { - auther = new libCommsyAuth(); - } - void reconnect() { // Destroy old connector if (connector != nullptr) { @@ -47,7 +43,6 @@ public: } cacheInvalidate = false; // Connect to commsy - std::cout << "Connecting using: " << settings->value("server_url").toString().toStdString() << "..." << std::endl; connector = new libCommsy(settings->value("server_url").toString().toStdString(), settings->value("server_sid").toString().toStdString(), settings->value("server_room").toString().toStdString()); } @@ -116,6 +111,9 @@ void _UILoader::offlineWindow(QMainWindow *w) { void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { Ui::loginWindow *thisui = new Ui::loginWindow; + // Create new auther + auther = new libCommsyAuth(); + // Check if logged in already if (settings->contains("server_sid")) { return overviewWindow(w); @@ -140,6 +138,7 @@ void _UILoader::loginWindow(QMainWindow *w, const QString& failure) { // Login try { settings->setValue("server_sid", auther->getSID(netReply)); + auther->deleteLater(); cacheInvalidate = true; overviewWindow(w, false); } catch (authFailureError&) { @@ -231,7 +230,6 @@ int main(int argc, char *argv[]) { _UILoader UILoader; // Set theme - settings->clear(); a.setStyle(QStyleFactory::create("windows")); // Load initial window