diff --git a/QCommsy.pro b/QCommsy.pro index 14d2b52..246d72b 100644 --- a/QCommsy.pro +++ b/QCommsy.pro @@ -16,6 +16,7 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + curlreq.cpp \ libcommsy.cpp \ main.cpp diff --git a/curlreq.cpp b/curlreq.cpp new file mode 100644 index 0000000..e738352 --- /dev/null +++ b/curlreq.cpp @@ -0,0 +1,28 @@ +#include + +#include +#include +#include +#include + +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; + // Set the writer callback to enable cURL to write result in a memory area + request.setOpt(new curlpp::options::WriteStream(&responsebuffer)); + // Setting the URL to retrive. + request.setOpt(new curlpp::options::Url(URL)); + // Set SID cookie + std::list header; + header.push_back("Cookie: SID=" + SID); + request.setOpt(new curlpp::options::HttpHeader(header)); + // Perform request + request.perform(); + // Return result + return curlpp::infos::ResponseCode::get(request); +} diff --git a/libcommsy.cpp b/libcommsy.cpp index 63aff80..a144db1 100644 --- a/libcommsy.cpp +++ b/libcommsy.cpp @@ -11,11 +11,6 @@ #include #include -#include -#include -#include -#include - #include #include "libcommsy.hpp" @@ -25,10 +20,6 @@ class parsingNoSuchTagError {}; class descDownloadError {}; -static std::string server_url; -static std::string server_sid; -static std::string room; - std::string ltrim(const std::string& s) { static const std::regex lws{"^[[:space:]]*", std::regex_constants::extended}; @@ -59,27 +50,7 @@ std::vector merge_strvects(std::vector base, const std return base; } -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; - // Set the writer callback to enable cURL to write result in a memory area - request.setOpt(new curlpp::options::WriteStream(&responsebuffer)); - // Setting the URL to retrive. - request.setOpt(new curlpp::options::Url(URL)); - // Set SID cookie - std::list header; - header.push_back("Cookie: SID=" + SID); - request.setOpt(new curlpp::options::HttpHeader(header)); - // Perform request - request.perform(); - // Return result - return curlpp::infos::ResponseCode::get(request); -} +extern long curlreq(std::stringstream &responsebuffer, std::string SID, std::string URL); void gumbo_search_by_attr(std::vector &elemvect, GumboNode* node, std::string attrname, std::string searchword, GumboTag expectedtag) { if (node->type != GUMBO_NODE_ELEMENT) { @@ -292,7 +263,7 @@ std::vector> get_post_files(GumboNode *node) return filenameurlmap; } -std::string get_post_desc(std::string post_url) { +std::string get_post_desc(const std::string& post_url, const std::string& server_sid) { std::string material_id; std::stringstream httpcontent; GumboOutput *post_document; @@ -326,7 +297,7 @@ std::string get_post_desc(std::string post_url) { } -// Functions +// Class functions bool libCommsy::postExists(unsigned long postID) { return postID < numposts; } @@ -347,18 +318,17 @@ std::string *libCommsy::getDescription(unsigned long postID) { // Check if post description was downloaded already if (thispost->description == "\xFF") { // Download post - thispost->description = get_post_desc(server_url + thispost->url); + thispost->description = get_post_desc(server_url + thispost->url, server_sid); } // Return it return &thispost->description; } -libCommsy::libCommsy(const std::string& _server_url, const std::string& _server_sid, const std::string& _room, const std::string start_id, const unsigned long max_posts) { +libCommsy::libCommsy(const std::string& _server_url, const std::string& _server_sid, const std::string& room, const std::string start_id, const unsigned long max_posts) { // Define required variables server_url = _server_url; server_sid = _server_sid; - room = _room; lastID = start_id; std::stringstream httpcontent; GumboOutput *document; diff --git a/libcommsy.hpp b/libcommsy.hpp index 5dd9bd0..076197a 100644 --- a/libcommsy.hpp +++ b/libcommsy.hpp @@ -26,12 +26,14 @@ struct commsyPost { #define libCommsy_NAME "libcommsy" -#define libCommsy_VERSION "1.3-stable" +#define libCommsy_VERSION "1.4-stable" class libCommsy { public: std::vector posts; unsigned long numposts; std::string lastID; + std::string server_url; + std::string server_sid; bool postExists(unsigned long postID);