summaryrefslogtreecommitdiff
path: root/noncore/settings
authoralwin <alwin>2005-03-07 21:22:42 (UTC)
committer alwin <alwin>2005-03-07 21:22:42 (UTC)
commitca82c064ab8834546c55b29c6b2f5c922075b450 (patch) (side-by-side diff)
tree5a7a097400cfb4388c3b742d3d4f517209789740 /noncore/settings
parentb9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2 (diff)
downloadopie-ca82c064ab8834546c55b29c6b2f5c922075b450.zip
opie-ca82c064ab8834546c55b29c6b2f5c922075b450.tar.gz
opie-ca82c064ab8834546c55b29c6b2f5c922075b450.tar.bz2
hostname should be filtered. Check return value of setting the hostname
and write operations.
Diffstat (limited to 'noncore/settings') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index 0a3312c..3222e50 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -28,2 +28,3 @@
#include <qtextstream.h>
+#include <qregexp.h>
@@ -728,13 +729,22 @@ void MainWindowImp::setHostname()
{
- QFile f(_HOSTFILE);
+ static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
+ if (filter.match(m_Nameinput->text())!=-1) {
+ odebug << "Wrong hostname" << oendl;
+ QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
+ return;
+ }
- OProcess*h = new OProcess;
+ OProcess h;
_procTemp="";
- *h << "hostname" << m_Nameinput->text();
- connect(h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
- h->start(OProcess::Block,OProcess::Stderr);
- odebug << "Got " << _procTemp << " - " << h->exitStatus() << oendl;
+ h << "hostname" << m_Nameinput->text();
+ connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
+ h.start(OProcess::Block,OProcess::Stderr);
+ odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
+ if (h.exitStatus()!=0) {
+ QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
+ return;
+ }
_procTemp="";
- delete h;
+ QFile f(_HOSTFILE);
if (f.open(IO_Truncate|IO_WriteOnly))
@@ -743,3 +753,7 @@ void MainWindowImp::setHostname()
s << m_Nameinput->text();
+ } else {
+ QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
+ return;
}
+
f.close();
@@ -750,2 +764,4 @@ void MainWindowImp::setHostname()
s << m_Nameinput->text();
+ } else {
+ QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
}
@@ -762,3 +778,3 @@ void MainWindowImp::initHostname()
odebug << "Got " << _procTemp <<oendl;
- m_Nameinput->setText(_procTemp);
+ m_Nameinput->setText(_procTemp.stripWhiteSpace());
_procTemp="";