version 2.13.2

This commit is contained in:
2025-03-24 00:52:46 +08:00
parent a235d2f745
commit 470b88f422
6 changed files with 115 additions and 79 deletions
+84 -65
View File
@@ -101,15 +101,15 @@ MainWindow::MainWindow(QWidget *parent)
// if last server exists in settings
if (this->settings.contains("connexion/lastServer"))
{
info(DEBUGMACRO, "Setting previous server");
// set window to previous server/port configuration
ui->portEdit->setText(this->settings.value("connexion/lastPort").toString());
ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString());
info(DEBUGMACRO, "Setting previous server");
// set window to previous server/port configuration
ui->portEdit->setText(this->settings.value("connexion/lastPort").toString());
ui->khistorycombobox->setCurrentText(this->settings.value("connexion/lastServer").toString());
}else
{
info(DEBUGMACRO, "No previous server, so setting only default port");
ui->portEdit->setText(QString::number(this->connexion.port));
ui->khistorycombobox->clear();
info(DEBUGMACRO, "No previous server, so setting only default port");
ui->portEdit->setText(QString::number(this->connexion.port));
ui->khistorycombobox->clear();
}
// connectors
@@ -146,11 +146,11 @@ void MainWindow::init()
info(DEBUGMACRO, "reply text is : " + reply->text());
if(reply == yes)
{
loadDownloadList();
loadDownloadList();
}else if (reply == deleteButton)
{
// delete saved download list
deleteDownloadList();
// delete saved download list
deleteDownloadList();
}
}
}
@@ -320,7 +320,7 @@ void MainWindow::populateTree()
info(DEBUGMACRO, "Validating server");
// validating server's address
this->connexion.ipversion = validateServer(this->connexion.server);
this->connexion.ipversion = validateServer(&this->connexion.server);
if (this->connexion.ipversion != 0)
{
// server is validated, scanning directory
@@ -347,18 +347,22 @@ void MainWindow::populateList(QString server, uint port)
info(DEBUGMACRO, "populateList() => Populating list of services");
info(DEBUGMACRO, "port: " + QString::number(port) + " - server: " + server);
if (server.isEmpty())
{
ui->listWidget->clear();
ui->treeWidget->clear();
return;
}
if ((server != this->connexion.server))
if (server != this->connexion.server)
{
// Determine version of Ip Protocol
info(DEBUGMACRO, "Server changed");
this->connexion.ipversion = validateServer(&server);
this->connexion.server = server;
if (port != false)
{
this->connexion.port = port;
@@ -400,7 +404,7 @@ void MainWindow::populateList(QString server, uint port)
{
if (this->connexion.ipversion == 0)
{
this->connexion.ipversion = validateServer(server);
this->connexion.ipversion = validateServer(&server);
info(DEBUGMACRO, "IP version : " + QString::number(this->connexion.ipversion));
}
@@ -779,76 +783,89 @@ uint MainWindow::validateServer(QString *server)
QHostAddress serverAddress;
info(DEBUGMACRO, "ValidateServer() => Validating server address");
ipversion = whatIpVersion(*server);
if (ipversion == 0) // not an Ip address, perhaps a server name
//if (ipversion == 0) // not an Ip address, perhaps a server name
//{
serverAddress = searchHosts(*server);
if (!serverAddress.isNull())
{
serverAddress = searchHosts(*server);
if (!serverAddress.isNull())
server->clear();
server->append(serverAddress.toString());
info(DEBUGMACRO, "Server address : " + *server);
}else
{
if (!serverAddress.setAddress(*server))
{
server->clear();
server->append(serverAddress.toString());
}
info(DEBUGMACRO, "Digging server name");
info(DEBUGMACRO, "Digging server name");
cmd = "dig";
param << server->trimmed() ;
param << "A"; // IP V4 query
param << server->trimmed() ;
param << "AAAA"; // IP V6 query
info(DEBUGMACRO, cmd + " " + param.join(" "));
myProcess = new QProcess(this);
myProcess->start(cmd, param);
// making a dig on the server's address
while(myProcess->waitForReadyRead())
{
while (1) //!bflag)
cmd = "dig";
param << server->trimmed() ;
if (ipversion == IPV4)
{
line = QString::fromUtf8(myProcess->readAllStandardOutput());
info(DEBUGMACRO, line);
// line empty then buffer is empty so returning to wait new datas
if (line.isEmpty())
{
break;
}else
{
answerFound = line.indexOf(";; ANSWER SECTION:") + 19;
info(DEBUGMACRO, "Position of answer line is : " + QString::number(answerFound));
param << "A"; // IP V4 query
}else if (ipversion == IPV6)
{
param << "AAAA"; // IP V6 query
}else
{
error("Protocol is not IPV4 or IPV6 !!");
}
if (answerFound != -1)
info(DEBUGMACRO, cmd + " " + param.join(" "));
myProcess = new QProcess(this);
myProcess->start(cmd, param);
// making a dig on the server's address
while(myProcess->waitForReadyRead())
{
while (1) //!bflag)
{
line = QString::fromUtf8(myProcess->readAllStandardOutput());
info(DEBUGMACRO, line);
// line empty then buffer is empty so returning to wait new datas
if (line.isEmpty())
{
info(DEBUGMACRO, "Serching IP address");
queryPos = line.indexOf(";; Query");
info(DEBUGMACRO, "Position of Query line is : " + QString::number(queryPos));
if (answerFound < queryPos)
break;
}else
{
answerFound = line.indexOf(";; ANSWER SECTION:") + 19;
info(DEBUGMACRO, "Position of answer line is : " + QString::number(answerFound));
if (answerFound != -1)
{
line = line.mid(answerFound, queryPos - answerFound);
info(DEBUGMACRO, "line is:\n" + line);
responseList = line.split(QRegExp("\\s+"));
info(DEBUGMACRO, "ip Address is => " + responseList.at(4));
if(responseList.at(3) == "A")
info(DEBUGMACRO, "Serching IP address");
queryPos = line.indexOf(";; Query");
info(DEBUGMACRO, "Position of Query line is : " + QString::number(queryPos));
if (answerFound < queryPos)
{
return 4;
}else if(responseList.at(3) == "AAAA")
{
return 6;
line = line.mid(answerFound, queryPos - answerFound);
info(DEBUGMACRO, "line is:\n" + line);
responseList = line.split(QRegExp("\\s+"));
info(DEBUGMACRO, "ip Address is => " + responseList.at(4));
if (serverAddress.setAddress(responseList.at(4)))
{
//error ("Address " + responseList.at(4) + " is bad");
server->clear();
server->append(serverAddress.toString());
}
}
}
}
}
}
myProcess->close();
}
myProcess->close();
}
info(DEBUGMACRO, "Returning ip version: " + QString::number(ipversion));
return ipversion;
//ipversion = whatIpVersion(*server);
ipversion = serverAddress.protocol();
return (ipversion==IPV4?4:6);
}
@@ -857,12 +874,14 @@ void MainWindow::on_connectButton_clicked()
{
QString server;
uint port;
//uint ipversion;
info(DEBUGMACRO, "on_connectButton_clicked() => Connexion button clicked");
port = ui->portEdit->text().toUInt();
if (port > 0 and port < 65535)
{
server = ui->khistorycombobox->currentText();
//ipversion = validateServer(&server);
populateList(server, port);
}else
{