forked from markus/S_New4
add clen function & delete threadVector & remove remove in desteructor
This commit is contained in:
parent
031a0b2bc9
commit
4194eafb9c
@ -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;
|
||||
|
@ -1,16 +1,14 @@
|
||||
#ifndef MANAGEPAGE_H
|
||||
#define MANAGEPAGE_H
|
||||
|
||||
#include <iostream>
|
||||
// if complied for windows; everything is in */projectfolder/curl/
|
||||
#include "accountManager.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "accountManager.h"
|
||||
|
||||
struct Reply {
|
||||
Reply() {}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 = "";
|
||||
|
@ -4,18 +4,16 @@
|
||||
#include "pageManager.h"
|
||||
#include "parameterManager.h"
|
||||
#include "accountManager.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user