diff --git a/RsyncUI.spec b/RsyncUI.spec index 4c63d7d..64b2a4a 100644 --- a/RsyncUI.spec +++ b/RsyncUI.spec @@ -2,7 +2,7 @@ Name: rsyncui Summary: Client for rsync server -Version: 2.13.1 +Version: 2.13.2 Release: %mkrel 1 License: GPLv3 Group: Networking/Remote access diff --git a/downloadfile.cpp b/downloadfile.cpp index 25cdc3b..9ca89ce 100644 --- a/downloadfile.cpp +++ b/downloadfile.cpp @@ -64,7 +64,7 @@ void MainWindow::download() param << "--bwlimit=" + QString::number(this->connexion.bandwidthLimit) + bwUnitChar[this->connexion.bandwidthLimitUnit]; } - ipversion = validateServer(server); + ipversion = validateServer(&server); if (downloading.ipversion == 4 || downloading.ipversion == 6) { diff --git a/mainwindow.cpp b/mainwindow.cpp index ecbf919..e1eea30 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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 { diff --git a/tools.cpp b/tools.cpp index a580da9..b33729b 100644 --- a/tools.cpp +++ b/tools.cpp @@ -63,12 +63,23 @@ QString preparePath(QString path) int whatIpVersion(QString ipAddress) { QStringList fieldList; - ulong field; - uint i; +// ulong field; +// uint i; + uint ipversion; + QHostAddress serverAddress; info(DEBUGMACRO, "ipVersion of server at " + ipAddress); - fieldList = ipAddress.split(":"); + if (!serverAddress.setAddress(ipAddress)) + { + error ("Address " + ipAddress + " is bad"); + } + ipversion = serverAddress.protocol(); + + return (ipversion==IPV4?4:6); + + + /*fieldList = ipAddress.split(":"); if (fieldList.count() == 8) { for (i=0;i<8;i++) @@ -95,15 +106,14 @@ int whatIpVersion(QString ipAddress) } info(DEBUGMACRO, "Address is ip V4"); return 4; - } - return 0; + }*/ } QHostAddress searchHosts(QString server) { QString line = ""; QStringList hosts; - QFile fileHandle; + QFile fileHandle("/etc/hosts"); QHostAddress serverAddress; info(DEBUGMACRO, "reading /etc/hosts"); @@ -117,16 +127,20 @@ QHostAddress searchHosts(QString server) while(!in.atEnd()) { line = in.readLine(); - hosts = line.split(' '); + hosts = line.split(QRegularExpression("\\s+")); if (hosts.contains(server)) { - if (!serverAddress.isNull() and serverAddress.protocol() == QAbstractSocket::IPv4Protocol) - { - serverAddress.setAddress(hosts.first()); - } + //if (!serverAddress.isNull()) // and serverAddress.protocol() == QAbstractSocket::IPv4Protocol) + //{ + if (!serverAddress.setAddress(hosts.first())) + { + error("Error setting address " + hosts.first()); + } + //} } } } + return serverAddress; } void warning(QString message) diff --git a/tools.h b/tools.h index 39b0190..272a753 100644 --- a/tools.h +++ b/tools.h @@ -3,6 +3,9 @@ #define DEBUGMACRO QString(__FILE__) + "->" + QString(Q_FUNC_INFO) + ": " + QString::number(__LINE__) + " -" +#define IPV4 0 +#define IPV6 1 + #include #include #include diff --git a/version.h b/version.h index edac2e7..7f18196 100644 --- a/version.h +++ b/version.h @@ -3,6 +3,6 @@ #include -QString version = "2.13.1"; +QString version = "2.13.2"; #endif // VERSION_H