ersetzte alle tests für proxy mit function

This commit is contained in:
Markus 2019-08-31 20:08:59 +02:00
parent 9cd5f8f18d
commit c7bb9702db

View File

@ -139,7 +139,7 @@ int loadDefaulOptions(Settings &settings)


} else if (what == "Socks5Proxy") { } else if (what == "Socks5Proxy") {
if(setS5ProxytoSettings(settings, data) != 0) if(setS5ProxytoSettings(settings, data) != 0)
return 140; return 2;


} else if (what == "DefaultFileVersion") { } else if (what == "DefaultFileVersion") {
if(data != settings.defaultFileVersion) if(data != settings.defaultFileVersion)
@ -573,29 +573,9 @@ int unterOption_url(Settings *settings, int argc, char **argv)


while( ( c = getopt_long (argc, argv, "p:o:hcd", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "p:o:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'p': { case 'p':
if(!optarg || std::string(optarg) == "") if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
break; return 2;
std::string optarg = ::optarg;
if(optarg.find(":") == std::string::npos) {
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
return 31;
}
std::string ip = optarg.substr(0, optarg.find(":"));
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
int port = atoi(portStr.c_str());
if(std::to_string(port) != portStr || port <= 0) {
std::cout << " => Error: [-p]: Invalid Port: " << portStr << std::endl;
return 32;
} else if (ip == "") {
std::cout << " => Error: [-p]: Invalid Ip Addresse: " << ip << std::endl;
return 34;
} else if(settings->debugMode) {
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
}
settings->proxy_ip = ip;
settings->proxy_port = port;
}
break; break;
case 'o': case 'o':
if(optarg) if(optarg)
@ -690,29 +670,9 @@ int unterOption_search(Settings *settings, int argc, char **argv)


while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'p': { case 'p':
if(!optarg || std::string(optarg) == "") if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
break; return 2;
std::string optarg = ::optarg;
if(optarg.find(":") == std::string::npos) {
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
return 31;
}
std::string ip = optarg.substr(0, optarg.find(":"));
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
int port = atoi(portStr.c_str());
if(std::to_string(port) != portStr || port <= 0) {
std::cout << " => Error: [-p]: Invalid Port: " << portStr << std::endl;
return 32;
} else if (ip == "") {
std::cout << " => Error: [-p]: Invalid Ip Addresse: " << ip << std::endl;
return 34;
} else if(settings->debugMode) {
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
}
settings->proxy_ip = ip;
settings->proxy_port = port;
}
break; break;
case 'h': case 'h':
unterOption_search_help(); unterOption_search_help();
@ -814,29 +774,9 @@ int unterOption_info(Settings *settings, int argc, char **argv)


while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'p': { case 'p':
if(!optarg || std::string(optarg) == "") if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
break; return 2;
std::string optarg = ::optarg;
if(optarg.find(":") == std::string::npos) {
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
return 31;
}
std::string ip = optarg.substr(0, optarg.find(":"));
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
int port = atoi(portStr.c_str());
if(std::to_string(port) != portStr || port <= 0) {
std::cout << " => Error: [-p]: Invalid Port: " << portStr << std::endl;
return 32;
} else if (ip == "") {
std::cout << " => Error: [-p]: Invalid Ip Addresse: " << ip << std::endl;
return 34;
} else if(settings->debugMode) {
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
}
settings->proxy_ip = ip;
settings->proxy_port = port;
}
break; break;
case 'h': case 'h':
unterOption_info_help(); unterOption_info_help();
@ -1028,7 +968,7 @@ int setS5ProxytoSettings(Settings &settings, std::string Optarg)
settings.proxy_ip = optarg; settings.proxy_ip = optarg;
// Sonst error: // Sonst error:
} else { } else {
std::cout << " => Error: Ungültige Socks5 Proxy Addresse: " << Optarg << std::endl; std::cout << " => Error: Ungültige Socks5 Proxy Addresse: '" << Optarg << "'." << std::endl;
return 1; return 1;
} }
// Wenn vollständige Addr: // Wenn vollständige Addr:
@ -1040,7 +980,7 @@ int setS5ProxytoSettings(Settings &settings, std::string Optarg)
if(isNumber(tmpPort)) if(isNumber(tmpPort))
settings.proxy_port = atoi(optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":")).c_str()); settings.proxy_port = atoi(optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":")).c_str());
else { else {
std::cout << " => Error: Ungültiger Socks5 Proxy Port: " << tmpPort << std::endl; std::cout << " => Error: Ungültiger Socks5 Proxy Port: '" << tmpPort << "'."<< std::endl;
return 2; return 2;
} }
} }
@ -1051,18 +991,17 @@ int setS5ProxytoSettings(Settings &settings, std::string Optarg)
tmpIp.erase(static_cast<size_t>(tmpIp.find(".")), 1); tmpIp.erase(static_cast<size_t>(tmpIp.find(".")), 1);
} }
else { else {
std::cout << " => Error: Ungültige Socks5 Proxy Ip Addresse: " << settings.proxy_ip << std::endl; std::cout << " => Error: Ungültige Socks5 Proxy Ip Addresse: '" << settings.proxy_ip << "'." << std::endl;
return 3; return 3;
} }
} }
std::cout << " nach Loop: " << tmpIp << std::endl;


if(!isNumber(tmpIp)) { if(!isNumber(tmpIp)) {
std::cout << " => Error: Ungültige Socks5 Proxy Ip Addresse: " << settings.proxy_ip << std::endl; std::cout << " => Error: Ungültige Socks5 Proxy Ip Addresse: '" << settings.proxy_ip << "'." << std::endl;
return 4; return 4;
// Überprüfe ob Port Positiv oder 0 und kliner als 2 Byte ist: // Überprüfe ob Port Positiv oder 0 und kliner als 2 Byte ist:
} else if (settings.proxy_port < 0 || settings.proxy_port > 65535) { } else if (settings.proxy_port < 0 || settings.proxy_port > 65535) {
std::cout << " => Error: Ungültiger Socks5 Proxy Port: " << settings.proxy_port << std::endl; std::cout << " => Error: Ungültiger Socks5 Proxy Port ( 0 bis 65535): " << settings.proxy_port << std::endl;
return 5; return 5;
//Debug Nachricht: //Debug Nachricht:
} else if(settings.debugMode) } else if(settings.debugMode)