[PC-BSD Commits] r17612 - pcbsd/current/src-qt4/libpcbsd
svn at pcbsd.org
svn at pcbsd.org
Tue Jul 3 11:54:48 PDT 2012
Author: kris
Date: 2012-07-03 18:54:47 +0000 (Tue, 03 Jul 2012)
New Revision: 17612
Modified:
pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:
Add two new functions to Utils::
validateIPV4(QString)
validateIPV6(QString)
Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h 2012-07-03 18:34:30 UTC (rev 17611)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h 2012-07-03 18:54:47 UTC (rev 17612)
@@ -134,6 +134,8 @@
static void restartNetworking();
static void runInTerminal(QString command, QString windowTitle=QString());
static void openInFileManager(QString location);
+ static bool validateIPV6(QString);
+ static bool validateIPV4(QString);
};
Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp 2012-07-03 18:34:30 UTC (rev 17611)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp 2012-07-03 18:54:47 UTC (rev 17612)
@@ -706,6 +706,8 @@
}
args<<terminal_comm.trimmed()<<comm;
+ qDebug() << terminal_app.trimmed() << args;
+
QProcess::startDetached(terminal_app.trimmed(), args);
}
@@ -767,6 +769,64 @@
return outputList; //Ouput will be empty if an error or if box cancelled
}
+bool Utils::validateIPV6( QString IP )
+{
+ bool ok;
+
+ if ( IP.count(":") < 2)
+ return false;
+
+ // Validate the V6 blocks
+ for ( int i = 0; i <= 7; ++i )
+ {
+ if ( IP.section(":", i, i).isEmpty() )
+ continue;
+
+ // Check if valid hex
+ IP.section(":", i,i).toInt(&ok, 16);
+ if (!ok)
+ return false;
+ }
+
+ return true;
+}
+
+bool Utils::validateIPV4( QString IP )
+{
+ int num;
+ bool ok;
+
+ if ( IP.indexOf(".") == -1 )
+ return false;
+
+ // Make sure this is a number after the . is taken out
+ QString tmp;
+ tmp = IP;
+ tmp.replace(".", "");
+ tmp.toInt(&ok);
+ if (!ok)
+ return false;
+
+ if ( IP.count(".") != 3)
+ return false;
+
+ // Validate the V4 blocks
+ for ( int i = 0; i <= 3; ++i )
+ {
+ if ( IP.section(".", i, i).isEmpty() )
+ return false;
+
+ num = IP.section(".", i,i).toInt(&ok);
+ if (!ok)
+ return false;
+
+ if ( num > 255 || num < 0)
+ return false;
+ }
+
+ return TRUE;
+}
+
// PLMPL class for dialogInfoBox
dialogInfo::dialogInfo() {
d_p = new dialogInfoBox;
More information about the Commits
mailing list