diff --git a/pageManager.cpp b/pageManager.cpp index 0222bd1..697b7cb 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -8,8 +8,8 @@ PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath) PageManager::~PageManager() { - remove(cookieFilePath.c_str()); curl_global_cleanup(); + std::cout << "des" << std::endl; } void PageManager::setProxy(std::string ip, int port) @@ -42,7 +42,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin char *url; std::string returnUrl; - std::cout << "\33[2K\r" << "Lade: '" << Url << "'..." << std::flush; + std::cout << ( "\33[2K\rLade: '" + Url + "'..." ) << std::flush; curl = curl_easy_init(); if(!curl) { @@ -68,14 +68,13 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin for (int timeout = 1; timeout <= maxTimeout; ++timeout) { /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); - std::cout << "\33[2K\r" << std::flush; if(res != CURLE_OK) { if(timeout == maxTimeout) { - perror((std::string(" => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str()); + perror((std::string("\33[2K\r => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str()); return Reply("-1"); } else { - std::cout << "\33[2K\r" << " => Warning: Versuch " << timeout << " von " << maxTimeout << ": curl_easy_perform() failed: " << curl_easy_strerror(res) << std::flush; + std::cout << std::string( "\33[2K\r => Warning: Versuch " + std::to_string(timeout) + " von " + std::to_string(maxTimeout) + ": curl_easy_perform() failed: " + curl_easy_strerror(res) )<< std::flush; sleep(1); } } else { @@ -87,7 +86,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin //Get Url res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); if( res != CURLE_OK || !url ) { - perror((std::string(" => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str()); + perror((std::string("\33[2K\r => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str()); return Reply("-1"); } else returnUrl=url; diff --git a/pageManager.h b/pageManager.h index 5e41e2c..679b8d4 100644 --- a/pageManager.h +++ b/pageManager.h @@ -1,16 +1,14 @@ #ifndef MANAGEPAGE_H #define MANAGEPAGE_H -#include -// if complied for windows; everything is in */projectfolder/curl/ +#include "accountManager.h" + #include #include #include #include - #include -#include "accountManager.h" struct Reply { Reply() {} diff --git a/parameterManager.cpp b/parameterManager.cpp index 2bf1eed..ac01e68 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -32,7 +32,7 @@ int manageParameter(Settings &settings, int argc, char **argv) return 1; } - int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo", argv[1]); + int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); if(res != 1) { std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" : std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl; @@ -65,6 +65,11 @@ int manageParameter(Settings &settings, int argc, char **argv) argv[1][0] = '\0'; return unterOption_info(&settings, argc, argv); + } else if (strncmp(argv[1], "clean", strlen(argv[1])) == 0) { + argv[1][0] = '\0'; + unterOption_clean(&settings, argc, argv); + return -1; + } else { std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; return 3; @@ -80,7 +85,8 @@ int unterOption_help() << "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl << "\t„default“\tModus um Links von Serien zu bekommen." << std::endl << "\t„search“\tModus um Serien zu suchen." << std::endl - << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl; + << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl + << "\t„clean“\tModus um Cookie-Files zu löschen." << std::endl; return -1; } @@ -717,3 +723,44 @@ void setPathSymbol(Settings &settings) settings.pathSymbol = '\\'; #endif } + +bool fileExists (const std::string& name) { + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode)); +} + +void unterOption_clean(Settings * settings, int argc, char **argv) +{ + if(argc > 1) + if(strcmp(argv[1], "--help") == 0) { + std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl; + std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl; + return; + } + + unsigned count = 0; + if(fileExists(settings->cookieFilePath)) { + if(remove(settings->cookieFilePath.c_str()) != 0) { + std::cout << "Das löschen von " << settings->cookieFilePath << " ist fehlgeschlagen: " << errno << std::endl; + return; + } else { + count++; + } + } + + for (unsigned i = 0; i < UINT_MAX && fileExists(settings->cookieFilePath + std::to_string(i)); i++) { + if(remove( (settings->cookieFilePath + std::to_string(i)).c_str() ) != 0) { + std::cout << "Das löschen von " << settings->cookieFilePath + std::to_string(i) << " ist fehlgeschlagen: " << errno << std::endl; + return; + } else { + count++; + } + } + + if(count == 0) + std::cout << " => Nichts zu tun: Keine Cookies vorhanden." << std::endl; + else + std::cout << " => " << count << " Cookie-Files gelöscht." << std::endl; + + return; +} diff --git a/parameterManager.h b/parameterManager.h index f218d7c..340d7e6 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -81,5 +81,7 @@ void unterOption_search_help(); int unterOption_info(Settings * settings, int argc, char **argv); void unterOption_info_help(); +void unterOption_clean(Settings * settings, int argc, char **argv); + #endif // PARAMETERMANAGER_H diff --git a/programManager.cpp b/programManager.cpp index 600fdc6..a5d30d9 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -9,7 +9,11 @@ ProgramManager::ProgramManager() ProgramManager::~ProgramManager() { - + for(auto e : threadList) { + delete e->pageManager; + delete e; + e = nullptr; + } } int ProgramManager::start(Settings *settings) @@ -162,18 +166,13 @@ int ProgramManager::defaultModus(Settings *settings) return 29; } else { for (unsigned i = 0; i < settings->maxThreads; ++i) { - ka * newKa = new ka(i); - PageManager * pm = new PageManager; - pm->setProxy(settings->proxy_ip, settings->proxy_port); - pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + PageManager * pm = new PageManager("socks5://" + settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i )); pm->setDebugMode(settings->debugMode); - newKa->pageManager = pm; - newKa->settings = settings; - newKa->accountManager = &accountManager; - newKa->nameInUrl = nameInUrl; - newKa->thread = 0; // Sonst error wenn join & nicht gesetzt - newKa->exitState = -1; + //pm->setProxy(settings->proxy_ip, settings->proxy_port); + //pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + + ka * newKa = new ka(i, 0, nameInUrl, -1, settings, &accountManager, pm); threadList.push_back(newKa); } } @@ -286,11 +285,11 @@ int ProgramManager::waitForThreads() for( auto &e : threadList) { if( e->exitState != -1 && pthread_join(e->thread, nullptr) == 0) { if(e->exitState != 0) { - std::cout << "Error: Thread gab error zurück." << std::endl; + std::cout << "\33[2K\r => Error: Thread gab error zurück." << std::endl; return e->exitState; } else if(e->returnValue != "") - std::cout << "(T" << e->id << ")" << e->returnValue << std::endl; + std::cout << ("\33[2K\r(T" + std::to_string(e->id) + ")" + e->returnValue ) << std::endl; } e->exitState = -1; e->returnValue = ""; diff --git a/programManager.h b/programManager.h index 8067407..5673f86 100644 --- a/programManager.h +++ b/programManager.h @@ -4,18 +4,16 @@ #include "pageManager.h" #include "parameterManager.h" #include "accountManager.h" -#include - #include -#include +#include #include struct ka { - ka(unsigned id) : id(id) {} - ~ka() { std::cout << "Deskrtuktor" << std::endl; } + ka(unsigned id, pthread_t init, std::string nameinUrl,int exitStateInit, Settings * settings, AccountManager * accountMg, PageManager * pM) + : id(id), thread(init), nameInUrl(nameinUrl), exitState(exitStateInit), settings(settings), accountManager(accountMg), pageManager(pM) {} unsigned id; pthread_t thread;