summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-07 21:22:42 (UTC)
committer alwin <alwin>2005-03-07 21:22:42 (UTC)
commitca82c064ab8834546c55b29c6b2f5c922075b450 (patch) (unidiff)
tree5a7a097400cfb4388c3b742d3d4f517209789740
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 (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
@@ -26,6 +26,7 @@
26#include <qtabwidget.h> // in order to disable the profiles tab 26#include <qtabwidget.h> // in order to disable the profiles tab
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qregexp.h>
29 30
30 31
31#if QT_VERSION < 0x030000 32#if QT_VERSION < 0x030000
@@ -726,28 +727,43 @@ void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
726 727
727void MainWindowImp::setHostname() 728void MainWindowImp::setHostname()
728{ 729{
729 QFile f(_HOSTFILE); 730 static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
731 if (filter.match(m_Nameinput->text())!=-1) {
732 odebug << "Wrong hostname" << oendl;
733 QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
734 return;
735 }
730 736
731 OProcess*h = new OProcess; 737 OProcess h;
732 _procTemp=""; 738 _procTemp="";
733 *h << "hostname" << m_Nameinput->text(); 739 h << "hostname" << m_Nameinput->text();
734 connect(h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 740 connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
735 h->start(OProcess::Block,OProcess::Stderr); 741 h.start(OProcess::Block,OProcess::Stderr);
736 odebug << "Got " << _procTemp << " - " << h->exitStatus() << oendl; 742 odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
743 if (h.exitStatus()!=0) {
744 QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
745 return;
746 }
737 _procTemp=""; 747 _procTemp="";
738 delete h;
739 748
749 QFile f(_HOSTFILE);
740 if (f.open(IO_Truncate|IO_WriteOnly)) 750 if (f.open(IO_Truncate|IO_WriteOnly))
741 { 751 {
742 QTextStream s(&f); 752 QTextStream s(&f);
743 s << m_Nameinput->text(); 753 s << m_Nameinput->text();
754 } else {
755 QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
756 return;
744 } 757 }
758
745 f.close(); 759 f.close();
746 f.setName(_IRDANAME); 760 f.setName(_IRDANAME);
747 if (f.open(IO_WriteOnly)) 761 if (f.open(IO_WriteOnly))
748 { 762 {
749 QTextStream s(&f); 763 QTextStream s(&f);
750 s << m_Nameinput->text(); 764 s << m_Nameinput->text();
765 } else {
766 QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
751 } 767 }
752} 768}
753 769
@@ -760,7 +776,7 @@ void MainWindowImp::initHostname()
760 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 776 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
761 h.start(OProcess::Block,OProcess::AllOutput); 777 h.start(OProcess::Block,OProcess::AllOutput);
762 odebug << "Got " << _procTemp <<oendl; 778 odebug << "Got " << _procTemp <<oendl;
763 m_Nameinput->setText(_procTemp); 779 m_Nameinput->setText(_procTemp.stripWhiteSpace());
764 _procTemp=""; 780 _procTemp="";
765} 781}
766 782