author | benmeyer <benmeyer> | 2002-11-13 16:25:04 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-11-13 16:25:04 (UTC) |
commit | d3301ad9a74fdf693551bd70bc3cf34b311eaa49 (patch) (side-by-side diff) | |
tree | fdc7ee3650af3e7225e1a8966e12bc2c1007b986 | |
parent | 2bc05c54b2ff1a9b2af7d6bd4d55428cfe0d8db3 (diff) | |
download | opie-d3301ad9a74fdf693551bd70bc3cf34b311eaa49.zip opie-d3301ad9a74fdf693551bd70bc3cf34b311eaa49.tar.gz opie-d3301ad9a74fdf693551bd70bc3cf34b311eaa49.tar.bz2 |
code cleanup const's placed in code
-rw-r--r-- | noncore/net/networksetup/TODO | 6 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces/interface.cpp | 2 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces/interface.h | 39 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces/interfaces.cpp | 6 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces/interfaces.h | 8 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces/interfaces.pro | 2 | ||||
-rw-r--r-- | noncore/net/networksetup/ppp/pppmodule.cpp | 21 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/infoimp.cpp | 3 | ||||
-rw-r--r-- | noncore/settings/networksettings/TODO | 6 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.h | 39 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.cpp | 6 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.h | 8 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.pro | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/ppp/pppmodule.cpp | 21 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/infoimp.cpp | 3 |
16 files changed, 90 insertions, 84 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO index 04b3a7c..020339f 100644 --- a/noncore/net/networksetup/TODO +++ b/noncore/net/networksetup/TODO @@ -1,16 +1,14 @@ -AndyQ - Fixed a bug in wlanimp.cpp : accept method - put braces round key - field if so that settings get saved if WEP is enabled - -CLEAN UP +test WEP +WEP key in file wireless.conf is not encrypted !, therefore it is very easy to get the key out of the zaurus.. udchcp needs to output the dhcp information so interfaces can read it interfacesetupimp really doesn't need a interface* pointer Possible other modules to write: ppp, ipsec, bluetooth, ipchains PPP module needs to scan pppd.tdb to see what is currently active WLAN - add possiblity to input text or hex without knowing "s:" Interface setupimp needs to use kernel calls. diff --git a/noncore/net/networksetup/interfaces/interface.cpp b/noncore/net/networksetup/interfaces/interface.cpp index 4129b3d..7ffa76f 100644 --- a/noncore/net/networksetup/interfaces/interface.cpp +++ b/noncore/net/networksetup/interfaces/interface.cpp @@ -1,297 +1,297 @@ #include "interface.h" #include <qdatetime.h> #include <qfile.h> #include <qdir.h> #include <qfileinfo.h> #include <qtextstream.h> #define IFCONFIG "/sbin/ifconfig" #define DHCP_INFO_DIR "/etc/dhcpc" #include <stdio.h> #include <stdlib.h> -Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ +Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ refresh(); } /** * Set status * @param newStatus - the new status * emit updateInterface */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; refresh(); } }; /** * Set if attached or not (802.11 card pulled out for example) * @param isAttached - if attached * emit updateInterface */ void Interface::setAttached(bool isAttached){ attached = isAttached; emit(updateInterface(this)); }; /** * Set Hardware name * @param name - the new name * emit updateInterface */ void Interface::setHardwareName(const QString &name){ hardwareName = name; emit(updateInterface(this)); }; /** * Set Module owner * @param owner - the new owner * emit updateInterface */ void Interface::setModuleOwner(Module *owner){ moduleOwner = owner; emit(updateInterface(this)); }; /** * Try to start the interface. */ void Interface::start(){ // check to see if we are already running. if(true == status){ emit (updateMessage("Unable to start interface,\n already started")); return; } int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); // See if it was successfull... if(ret != 0){ emit (updateMessage("Starting interface failed.")); return; } status = true; refresh(); emit (updateMessage("Start successfull")); } /** * Try to stop the interface. */ void Interface::stop(){ // check to see if we are already stopped. if(false == status){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); if(ret != 0){ emit (updateMessage("Stopping interface failed.")); return; } status = false; refresh(); emit (updateMessage("Stop successfull")); } /** * Try to restart the interface. */ void Interface::restart(){ stop(); start(); } /** * Try to refresh the information about the interface. * First call ifconfig, then check the dhcp-info file * @return bool true if successfull. */ bool Interface::refresh(){ // See if we are up. if(status == false){ macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; dhcp = false; dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; emit(updateInterface(this)); return true; } QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); return false; } QFile file(fileName); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } // Set to the defaults macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("HWaddr")){ int mac = line.find("HWaddr"); macAddress = line.mid(mac+7, line.length()); } if(line.contains("inet addr")){ int ipl = line.find("inet addr"); int space = line.find(" ", ipl+10); ip = line.mid(ipl+10, space-ipl-10); } if(line.contains("Mask")){ int mask = line.find("Mask"); subnetMask = line.mid(mask+5, line.length()); } if(line.contains("Bcast")){ int mask = line.find("Bcast"); int space = line.find(" ", mask+6); broadcast = line.mid(mask+6, space-mask-6); } } file.close(); QFile::remove(fileName); // DHCP TESTING // reset DHCP info dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; dhcp = false; QString dhcpDirectory(DHCP_INFO_DIR); QDir d(dhcpDirectory); if(!d.exists(dhcpDirectory)) dhcpDirectory = "/var/run"; // See if we have QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); // If there is no DHCP information then exit now with no errors. if(!QFile::exists(dhcpFile)){ emit(updateInterface(this)); return true; } file.setName(dhcpFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); return false; } // leaseTime and renewalTime and used if pid and deamon exe can be accessed. int leaseTime = 0; int renewalTime = 0; stream.setDevice( &file ); while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("DHCPSIADDR=")) dhcpServerIp = line.mid(11, line.length()); if(line.contains("LEASETIME=")) leaseTime = line.mid(10, line.length()).toInt(); if(line.contains("RENEWALTIME=")) renewalTime = line.mid(12, line.length()).toInt(); } file.close(); //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); // Get the pid of the deamond dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); file.setName(dhcpFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); return false; } int pid = -1; stream.setDevice( &file ); while ( !stream.eof() ) { line = stream.readLine(); pid = line.toInt(); } file.close(); if( pid == -1){ qDebug("Interface: Could not get pid of dhcpc deamon."); return false; } // Get the start running time of the deamon fileName = (QString("/proc/%1/stat").arg(pid)); file.setName(fileName); stream.setDevice( &file ); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } while ( !stream.eof() ) { line = stream.readLine(); } file.close(); long time = 0; // Grab the start time // pid com state ppid pgrp session tty_nr tpgid flags sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " // minflt cminflt majflt cmajflt utime stime cutime cstime priority "%*u %*u %*u %*u %*u %*u %*d %*d %*d " // nice 0 itrealvalue starttime "%*d %*d %*d %lu", (long*) &time); time = time/100; QDateTime datetime(QDateTime::currentDateTime()); // Get the uptime of the computer. QFile f("/proc/uptime"); if ( f.open(IO_ReadOnly) ) { // file opened successfully QTextStream t( &f ); // use a text stream int sec = 0; t >> sec; datetime = datetime.addSecs((-1*sec)); f.close(); } else{ qDebug("Interface: Can't open /proc/uptime to retrive uptime."); return false; } datetime = datetime.addSecs(time); //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); // Calculate the start and renew times leaseObtained = datetime.toString(); // Calculate the start and renew times datetime = datetime.addSecs(leaseTime); leaseExpires = datetime.toString(); dhcp = true; emit(updateInterface(this)); return true; } // interface.cpp diff --git a/noncore/net/networksetup/interfaces/interface.h b/noncore/net/networksetup/interfaces/interface.h index 989d6d8..d37834a 100644 --- a/noncore/net/networksetup/interfaces/interface.h +++ b/noncore/net/networksetup/interfaces/interface.h @@ -1,71 +1,72 @@ #ifndef INTERFACE_H #define INTERFACE_H #include <qstring.h> #include <qobject.h> class Module; class Interface : public QObject{ Q_OBJECT signals: void updateInterface(Interface *i); void updateMessage(const QString &message); public: Interface(QObject * parent=0, const char * name= "unknown", bool status = false); - QString getInterfaceName(){ QString n(this->name()); return n; }; + QString getInterfaceName() const { QString n(this->name()); return n; }; - bool getStatus(){ return status; }; + bool getStatus() const { return status; }; void setStatus(bool newStatus); - bool isAttached(){ return attached; }; + bool isAttached() const { return attached; }; void setAttached(bool isAttached=false); - QString getHardwareName(){ return hardwareName; }; + QString getHardwareName() const { return hardwareName; }; void setHardwareName(const QString &name="Unknown"); - Module* getModuleOwner(){ return moduleOwner; }; + Module* getModuleOwner() const { return moduleOwner; }; void setModuleOwner(Module *owner=NULL); // inet information. - QString getMacAddress(){ return macAddress; }; - QString getIp(){ return ip; }; - QString getSubnetMask(){ return subnetMask; }; - QString getBroadcast(){ return broadcast; }; - bool isDhcp(){ return dhcp; }; - QString getDhcpServerIp(){ return dhcpServerIp; }; - QString getLeaseObtained(){ return leaseObtained; }; - QString getLeaseExpires(){ return leaseExpires; }; + QString getMacAddress() const { return macAddress; }; + QString getIp() const { return ip; }; + QString getSubnetMask() const { return subnetMask; }; + QString getBroadcast() const { return broadcast; }; + bool isDhcp() const { return dhcp; }; + QString getDhcpServerIp() const { return dhcpServerIp; }; + QString getLeaseObtained() const { return leaseObtained; }; + QString getLeaseExpires() const { return leaseExpires; }; public slots: bool refresh(); void start(); void stop(); void restart(); private: // Interface information - bool status; - bool attached; QString hardwareName; Module *moduleOwner; + bool status; + bool attached; // Network information - QString macAddress; - QString ip; - QString broadcast; - QString subnetMask; bool dhcp; QString dhcpServerIp; QString leaseObtained; QString leaseExpires; + QString macAddress; + QString ip; + QString broadcast; + QString subnetMask; + }; #endif // interface.h diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp index e49998e..8f685fe 100644 --- a/noncore/net/networksetup/interfaces/interfaces.cpp +++ b/noncore/net/networksetup/interfaces/interfaces.cpp @@ -1,527 +1,527 @@ #include "interfaces.h" #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> // The three stanza's #define AUTO "auto" #define IFACE "iface" #define MAPPING "mapping" /** * Constructor. Reads in the interfaces file and then split the file up by * the \n for interfaces variable. * @param useInterfacesFile if an interface file other then the default is * desired to be used it should be passed in. */ Interfaces::Interfaces(QString useInterfacesFile){ acceptedFamily.append(INTERFACES_FAMILY_INET); acceptedFamily.append(INTERFACES_FAMILY_IPX); acceptedFamily.append(INTERFACES_FAMILY_INET6); interfacesFile = useInterfacesFile; QFile file(interfacesFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); currentIface = interfaces.end(); currentMapping = interfaces.end(); return; } QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line += stream.readLine(); line += "\n"; } file.close(); interfaces = QStringList::split("\n", line, true); currentIface = interfaces.end(); currentMapping = interfaces.end(); } /** * Get a list of all interfaces in the interface file. Usefull for * hardware that is not currently connected such as an 802.11b card * not plugged in, but configured for when it is plugged in. * @return Return string list of interfaces. **/ QStringList Interfaces::getInterfaceList(){ QStringList list; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains(IFACE) && line.at(0) != '#'){ line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace >= 0){ line = line.mid(0, findSpace); list.append(line); } } } return list; } /** * Find out if interface is in an "auto" group or not. * Report any duplicates such as eth0 being in two differnt auto's * @param interface interface to check to see if it is on or not. * @return true is interface is in auto */ -bool Interfaces::isAuto(const QString &interface){ +bool Interfaces::isAuto(const QString &interface) const { QStringList autoLines = interfaces.grep(QRegExp(AUTO)); QStringList awi = autoLines.grep(QRegExp(interface)); if(awi.count() > 1) qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); if(awi.count() < 1) return false; return true; } /** * Attempt to set the auto option for interface to setAuto. * @param interface the interface to set * @param setAuto the value to set interface to. * @return false if already set to setAuto. * */ bool Interfaces::setAuto(const QString &interface, bool setAuto){ // Don't need to set it if it is already set. if(isAuto(interface) == setAuto) return false; bool changed = false; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { if((*it).contains(AUTO)){ //We know that they are not in any group so let add to this auto. if(setAuto){ (*it) = (*it) += " " + interface; // Don't care to have such thins as: auto eth0 lo usb0 (*it) = (*it).simplifyWhiteSpace(); changed = true; break; } // else see if we need to remove from this one else{ if((*it).contains(interface)){ (*it) = (*it).replace(QRegExp(interface), ""); // if AUTO is the only thing left clear the line if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) (*it) = ""; changed = true; // Don't break because we want to make sure we remove all cases. } } } } // In the case where there is no AUTO field add one. if(!changed && setAuto) interfaces.append(QString(AUTO" %1").arg(interface)); return true; } /** * Set the current interface to interface. This needs to be done before you * can call getFamily(), getMethod, and get/setOption(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setInterface(QString interface){ interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); return setStanza(IFACE, interface, currentIface); } /** * A quick helper funtion to see if the current interface is set. * @return bool true if set, false otherwise. */ -bool Interfaces::isInterfaceSet(){ - return (currentIface != interfaces.end()); +bool Interfaces::isInterfaceSet() const { + return (interfaces.end() != currentIface); } /** * Add a new interface of with the settings - family and method * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @param family the family of this interface inet or inet, ipx or inet6 * Must of one of the families defined in interfaces.h * @param method for the family. see interfaces man page for family methods. * @return true if successfull. */ bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ if(0 == acceptedFamily.contains(family)) return false; QString newInterface = interface.simplifyWhiteSpace(); newInterface = newInterface.replace(QRegExp(" "), ""); interfaces.append(""); interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); return true; } /** * Copies interface with name interface to name newInterface * @param newInterface name of the new interface. * @return bool true if successfull */ bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ if(!setInterface(interface)) return false; // Store the old interface and bump past the stanza line. QStringList::Iterator it = currentIface; it++; // Add the new interface bool error; addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); if(!setInterface(newInterface)) return false; QStringList::Iterator newIface = currentIface; newIface++; // Copy all of the lines for ( ; it != interfaces.end(); ++it ){ if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) break; newIface = interfaces.insert(newIface, *it); } return true; } /** * Remove the currently selected interface and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeInterface(){ return removeStanza(currentIface); } /** * Gets the hardware name of the interface that is currently selected. * @return QString name of the hardware interface (eth0, usb2, wlan1...). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceName(bool &error){ if(currentIface == interfaces.end()){ error = true; return QString(); } QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); } error = false; return line.mid(0, findSpace); } /** * Gets the family name of the interface that is currently selected. * @return QString name of the family (inet, inet6, ipx). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceFamily(bool &error){ QString name = getInterfaceName(error); if(error) return QString(); QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); } error = false; return line.mid(0, findSpace); } /** * Gets the method of the interface that is currently selected. * @return QString name of the method such as staic or dhcp. * See the man page of interfaces for possible methods depending on the family. * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceMethod(bool &error){ QString name = getInterfaceName(error); if(error) return QString(); QString family = getInterfaceFamily(error); if(error) return QString(); QString line = (*currentIface); line = line.mid(QString(IFACE).length()+1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.mid(family.length()+1, line.length()); line = line.simplifyWhiteSpace(); error = false; return line; } /** * Sets the interface name to newName. * @param newName the new name of the interface. All whitespace is removed. * @return bool true if successfull. */ bool Interfaces::setInterfaceName(const QString &newName){ if(currentIface == interfaces.end()) return false; QString name = newName.simplifyWhiteSpace(); name = name.replace(QRegExp(" "), ""); bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface family to newName. * @param newName the new name of the interface. Must be one of the families * defined in the interfaces.h file. * @return bool true if successfull. */ bool Interfaces::setInterfaceFamily(const QString &newName){ if(currentIface == interfaces.end()) return false; if(acceptedFamily.contains(newName)==0) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface method to newName * @param newName the new name of the interface * @return bool true if successfull. */ bool Interfaces::setInterfaceMethod(const QString &newName){ if(currentIface == interfaces.end()) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); return !returnValue; } /** * Get a value for an option in the currently selected interface. For example * calling getInterfaceOption("address") on the following stanza would * return 192.168.1.1. * iface eth0 static * address 192.168.1.1 * @param option the options to get the value. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ QString Interfaces::getInterfaceOption(const QString &option, bool &error){ return getOption(currentIface, option, error); } /** * Set a value for an option in the currently selected interface. If option * doesn't exist then it is added along with the value. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ return setOption(currentIface, option, value); } /** * Removes a value for an option in the currently selected interface. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ return removeOption(currentIface, option, value); } /** * Removes all of the options from the currently selected interface. * @return bool error if if successfull */ bool Interfaces::removeAllInterfaceOptions(){ return removeAllOptions(currentIface); } /** * Set the current map to interface's map. This needs to be done before you * can call addMapping(), set/getMap(), and get/setScript(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setMapping(const QString &interface){ QString interfaceName = interface.simplifyWhiteSpace(); interfaceName = interfaceName.replace(QRegExp(" "), ""); return setStanza(MAPPING, interfaceName, currentMapping); } /** * Adds a new Mapping to the interfaces file with interfaces. * @param interface the name(s) of the interfaces to set to this mapping */ void Interfaces::addMapping(const QString &option){ interfaces.append(""); interfaces.append(QString(MAPPING " %1").arg(option)); } /** * Remove the currently selected map and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeMapping(){ return removeStanza(currentMapping); } /** * Set a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::setMap(const QString &map, const QString &value){ return setOption(currentMapping, map, value); } /** * Removes a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::removeMap(const QString &map, const QString &value){ return removeOption(currentMapping, map, value); } /** * Get a map value within a mapping. * @param map map to get value of * @param bool true if it is successfull. * @return value that goes to the map */ QString Interfaces::getMap(const QString &map, bool &error){ return getOption(currentMapping, map, error); } /** * Sets a script value of the current mapping to argument. * @param argument the script name. * @return true if successfull. */ bool Interfaces::setScript(const QString &argument){ return setOption(currentMapping, "script", argument); } /** * @param error true if could not retrieve the current script argument. * @return QString the argument of the script for the current mapping. */ QString Interfaces::getScript(bool &error){ return getOption(currentMapping, "script", error); } /** * Helper function used to parse through the QStringList and put pointers in * the correct place. * @param stanza The stanza (auto, iface, mapping) to look for. * @param option string that must be in the stanza's main line. * @param interator interator to place at location of stanza if successfull. * @return bool true if the stanza is found. */ bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ bool found = false; iterator = interfaces.end(); for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ uint point = line.find(option); bool valid = true; if(point > 0){ // There are more chars in the line. check +1 if(line.at(point-1) != ' ') valid = false; } point += option.length(); if(point < line.length()-1){ // There are more chars in the line. check -1 if(line.at(point) != ' ') valid = false; } if(valid){ if(found == true){ qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); } found = true; iterator = it; } } } return found; } /** * Sets a value of an option in a stanza * @param start the start of the stanza * @param option the option to use when setting value. * @return bool true if successfull, false otherwise. */ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ if(start == interfaces.end()) return false; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ if(!found && value != ""){ // Got to the end of the stanza without finding it, so append it. interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); } found = true; break; } if((*it).contains(option) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; (*it) = QString("\t%1 %2").arg(option).arg(value); } } if(!found){ QStringList::Iterator p = start; interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); found = true; } return found; } /** * Removes a stanza and all of its options * @param stanza the stanza to remove * @return bool true if successfull. */ bool Interfaces::removeStanza(QStringList::Iterator &stanza){ if(stanza == interfaces.end()) return false; (*stanza) = ""; return removeAllOptions(stanza); } /** * Removes a option in a stanza diff --git a/noncore/net/networksetup/interfaces/interfaces.h b/noncore/net/networksetup/interfaces/interfaces.h index d662919..bac2a7e 100644 --- a/noncore/net/networksetup/interfaces/interfaces.h +++ b/noncore/net/networksetup/interfaces/interfaces.h @@ -1,77 +1,77 @@ #ifndef INTERFACES_H #define INTERFACES_H #include <qstring.h> #include <qstringlist.h> #define INTERFACES_LOOPBACK "loopback" #define INTERFACES_FAMILY_INET "inet" #define INTERFACES_FAMILY_IPX "ipx" #define INTERFACES_FAMILY_INET6 "inet6" #define INTERFACES_METHOD_DHCP "dhcp" #define INTERFACES_METHOD_STATIC "static" #define INTERFACES_METHOD_PPP "ppp" /** * This class provides a clean frontend for parsing the network interfaces file. * It provides helper functions to minipulate the options within the file. * See the interfaces man page for the syntax rules. */ class Interfaces { public: Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); QStringList getInterfaceList(); - bool isAuto(const QString &interface); + bool isAuto(const QString &interface) const ; bool setAuto(const QString &interface, bool setAuto); bool removeInterface(); bool addInterface(const QString &interface, const QString &family, const QString &method); bool copyInterface(const QString &oldInterface, const QString &newInterface); bool setInterface(QString interface); - bool isInterfaceSet(); + bool isInterfaceSet() const ; QString getInterfaceName(bool &error); bool setInterfaceName(const QString &newName); QString getInterfaceFamily(bool &error); bool setInterfaceFamily(const QString &newName); QString getInterfaceMethod(bool &error); bool setInterfaceMethod(const QString &newName); QString getInterfaceOption(const QString &option, bool &error); bool setInterfaceOption(const QString &option, const QString &value); bool removeInterfaceOption(const QString &option, const QString &value); bool removeAllInterfaceOptions(); bool setMapping(const QString &interface); bool removeMapping(); void addMapping(const QString &options); bool setMap(const QString &map, const QString &value); bool removeMap(const QString &map, const QString &value); QString getMap(const QString &map, bool &error); bool setScript(const QString &argument); QString getScript(bool &error); bool write(); private: bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); + bool removeStanza(QStringList::Iterator &stanza); bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); + bool removeAllOptions(const QStringList::Iterator &start); bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); - bool removeStanza(QStringList::Iterator &stanza); - bool removeAllOptions(const QStringList::Iterator &start); QString interfacesFile; QStringList interfaces; QStringList::Iterator currentIface; QStringList::Iterator currentMapping; QStringList acceptedFamily; }; #endif // interfaces diff --git a/noncore/net/networksetup/interfaces/interfaces.pro b/noncore/net/networksetup/interfaces/interfaces.pro index 9a024f6..d6b43fb 100644 --- a/noncore/net/networksetup/interfaces/interfaces.pro +++ b/noncore/net/networksetup/interfaces/interfaces.pro @@ -1,12 +1,12 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug -DESTDIR = $(QTDIR)/lib$(PROJMAK) +#DESTDIR = $(QTDIR)/lib$(PROJMAK) HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp INCLUDEPATH += $(OPIEDIR)/include ../ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe INTERFACES = interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui TARGET = interfaces VERSION = 1.0.0 diff --git a/noncore/net/networksetup/ppp/pppmodule.cpp b/noncore/net/networksetup/ppp/pppmodule.cpp index 68bb0a0..72cd45e 100644 --- a/noncore/net/networksetup/ppp/pppmodule.cpp +++ b/noncore/net/networksetup/ppp/pppmodule.cpp @@ -1,104 +1,107 @@ #include "pppmodule.h" +#include "pppimp.h" #include "interfaceinformationimp.h" /** * Constructor, find all of the possible interfaces */ PPPModule::PPPModule() : Module() { } /** * Delete any interfaces that we own. */ PPPModule::~PPPModule(){ Interface *i; for ( i=list.first(); i != 0; i=list.next() ) delete i; } /** * Change the current profile */ void PPPModule::setProfile(const QString &newProfile){ profile = newProfile; } /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ QString PPPModule::getPixmapName(Interface* ){ return "ppp"; } /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ bool PPPModule::isOwner(Interface *i){ - // Scan the ppp database + if(!i->getInterfaceName().upper().contains("PPP")) return false; i->setHardwareName("PPP"); list.append(i); return true; } /** * Create, and return the WLANConfigure Module * @return QWidget* pointer to this modules configure. */ QWidget *PPPModule::configure(Interface *i){ return NULL; //PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", i, false, Qt::WDestructiveClose); //pppconfig->setProfile(profile); //return wlanconfig; } /** * Create, and return the Information Module * @return QWidget* pointer to this modules info. */ QWidget *PPPModule::information(Interface *i){ - return NULL; - - //WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); - //InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); - //info->tabWidget->insertTab(information, "TCP/IP"); - //return info; + // We don't have any advanced pppd information widget yet :-D + // TODO ^ + InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i); + return information; } /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ QList<Interface> PPPModule::getInterfaces(){ + // List all of the files in the peer directory return list; } /** * Attempt to add a new interface as defined by name * @param name the name of the type of interface that should be created given * by possibleNewInterfaces(); * @return Interface* NULL if it was unable to be created. */ Interface *PPPModule::addNewInterface(const QString &newInterface){ - // We can't add a 802.11 interface, either the hardware will be there - // or it wont. + // If the + PPPConfigureImp imp(0, "PPPConfigImp"); + if(imp.exec() == QDialog::Accepted ){ + + } return NULL; } /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ bool PPPModule::remove(Interface*){ // Can't remove a hardware device, you can stop it though. return false; } // pppmodule.cpp diff --git a/noncore/net/networksetup/wlan/infoimp.cpp b/noncore/net/networksetup/wlan/infoimp.cpp index e1eef81..6d3e167 100644 --- a/noncore/net/networksetup/wlan/infoimp.cpp +++ b/noncore/net/networksetup/wlan/infoimp.cpp @@ -1,55 +1,56 @@ #include "infoimp.h" #include "wextensions.h" + #include <qtimer.h> #include <qprogressbar.h> #include <qlabel.h> /** * Constructor. If wireless extensions are enabled on device name then * start a timer that every second will update the information. */ WlanInfoImp::WlanInfoImp( QWidget* parent, const char* name, WFlags fl): WlanInfo(parent, name, fl){ WExtensions *wExtensions = new WExtensions(name); if(!wExtensions->doesHaveWirelessExtensions()){ delete wExtensions; - qDebug("No extension"); + qDebug("WlanInfoImp::No wireless extension"); return; } delete wExtensions; timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(update())); timer->start( 1000, false ); } /** * Updates the information about the wireless device. */ void WlanInfoImp::update(){ WExtensions *wExtensions = new WExtensions(this->name()); if(!wExtensions->doesHaveWirelessExtensions()){ qDebug("No extension"); delete wExtensions; timer->stop(); return; } essidLabel->setText(wExtensions->essid()); apLabel->setText(wExtensions->ap()); stationLabel->setText(wExtensions->station()); modeLabel->setText(wExtensions->mode()); freqLabel->setText(QString("%1 GHz").arg(wExtensions->frequency())); int signal = 0; int noise = 0; int quality = 0; wExtensions->stats(signal, noise, quality); if(signalProgressBar->progress() != signal) signalProgressBar->setProgress(signal); if(noiseProgressBar->progress() != noise) noiseProgressBar->setProgress(noise); if(qualityProgressBar->progress() != quality) qualityProgressBar->setProgress(quality); rateLabel->setText(QString("%1 Mb/s").arg(wExtensions->rate())); delete wExtensions; } // infoimp.cpp diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO index 04b3a7c..020339f 100644 --- a/noncore/settings/networksettings/TODO +++ b/noncore/settings/networksettings/TODO @@ -1,16 +1,14 @@ -AndyQ - Fixed a bug in wlanimp.cpp : accept method - put braces round key - field if so that settings get saved if WEP is enabled - -CLEAN UP +test WEP +WEP key in file wireless.conf is not encrypted !, therefore it is very easy to get the key out of the zaurus.. udchcp needs to output the dhcp information so interfaces can read it interfacesetupimp really doesn't need a interface* pointer Possible other modules to write: ppp, ipsec, bluetooth, ipchains PPP module needs to scan pppd.tdb to see what is currently active WLAN - add possiblity to input text or hex without knowing "s:" Interface setupimp needs to use kernel calls. diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index 4129b3d..7ffa76f 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp @@ -1,297 +1,297 @@ #include "interface.h" #include <qdatetime.h> #include <qfile.h> #include <qdir.h> #include <qfileinfo.h> #include <qtextstream.h> #define IFCONFIG "/sbin/ifconfig" #define DHCP_INFO_DIR "/etc/dhcpc" #include <stdio.h> #include <stdlib.h> -Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ +Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ refresh(); } /** * Set status * @param newStatus - the new status * emit updateInterface */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; refresh(); } }; /** * Set if attached or not (802.11 card pulled out for example) * @param isAttached - if attached * emit updateInterface */ void Interface::setAttached(bool isAttached){ attached = isAttached; emit(updateInterface(this)); }; /** * Set Hardware name * @param name - the new name * emit updateInterface */ void Interface::setHardwareName(const QString &name){ hardwareName = name; emit(updateInterface(this)); }; /** * Set Module owner * @param owner - the new owner * emit updateInterface */ void Interface::setModuleOwner(Module *owner){ moduleOwner = owner; emit(updateInterface(this)); }; /** * Try to start the interface. */ void Interface::start(){ // check to see if we are already running. if(true == status){ emit (updateMessage("Unable to start interface,\n already started")); return; } int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); // See if it was successfull... if(ret != 0){ emit (updateMessage("Starting interface failed.")); return; } status = true; refresh(); emit (updateMessage("Start successfull")); } /** * Try to stop the interface. */ void Interface::stop(){ // check to see if we are already stopped. if(false == status){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); if(ret != 0){ emit (updateMessage("Stopping interface failed.")); return; } status = false; refresh(); emit (updateMessage("Stop successfull")); } /** * Try to restart the interface. */ void Interface::restart(){ stop(); start(); } /** * Try to refresh the information about the interface. * First call ifconfig, then check the dhcp-info file * @return bool true if successfull. */ bool Interface::refresh(){ // See if we are up. if(status == false){ macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; dhcp = false; dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; emit(updateInterface(this)); return true; } QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); return false; } QFile file(fileName); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } // Set to the defaults macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("HWaddr")){ int mac = line.find("HWaddr"); macAddress = line.mid(mac+7, line.length()); } if(line.contains("inet addr")){ int ipl = line.find("inet addr"); int space = line.find(" ", ipl+10); ip = line.mid(ipl+10, space-ipl-10); } if(line.contains("Mask")){ int mask = line.find("Mask"); subnetMask = line.mid(mask+5, line.length()); } if(line.contains("Bcast")){ int mask = line.find("Bcast"); int space = line.find(" ", mask+6); broadcast = line.mid(mask+6, space-mask-6); } } file.close(); QFile::remove(fileName); // DHCP TESTING // reset DHCP info dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; dhcp = false; QString dhcpDirectory(DHCP_INFO_DIR); QDir d(dhcpDirectory); if(!d.exists(dhcpDirectory)) dhcpDirectory = "/var/run"; // See if we have QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); // If there is no DHCP information then exit now with no errors. if(!QFile::exists(dhcpFile)){ emit(updateInterface(this)); return true; } file.setName(dhcpFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); return false; } // leaseTime and renewalTime and used if pid and deamon exe can be accessed. int leaseTime = 0; int renewalTime = 0; stream.setDevice( &file ); while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("DHCPSIADDR=")) dhcpServerIp = line.mid(11, line.length()); if(line.contains("LEASETIME=")) leaseTime = line.mid(10, line.length()).toInt(); if(line.contains("RENEWALTIME=")) renewalTime = line.mid(12, line.length()).toInt(); } file.close(); //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); // Get the pid of the deamond dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); file.setName(dhcpFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); return false; } int pid = -1; stream.setDevice( &file ); while ( !stream.eof() ) { line = stream.readLine(); pid = line.toInt(); } file.close(); if( pid == -1){ qDebug("Interface: Could not get pid of dhcpc deamon."); return false; } // Get the start running time of the deamon fileName = (QString("/proc/%1/stat").arg(pid)); file.setName(fileName); stream.setDevice( &file ); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } while ( !stream.eof() ) { line = stream.readLine(); } file.close(); long time = 0; // Grab the start time // pid com state ppid pgrp session tty_nr tpgid flags sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " // minflt cminflt majflt cmajflt utime stime cutime cstime priority "%*u %*u %*u %*u %*u %*u %*d %*d %*d " // nice 0 itrealvalue starttime "%*d %*d %*d %lu", (long*) &time); time = time/100; QDateTime datetime(QDateTime::currentDateTime()); // Get the uptime of the computer. QFile f("/proc/uptime"); if ( f.open(IO_ReadOnly) ) { // file opened successfully QTextStream t( &f ); // use a text stream int sec = 0; t >> sec; datetime = datetime.addSecs((-1*sec)); f.close(); } else{ qDebug("Interface: Can't open /proc/uptime to retrive uptime."); return false; } datetime = datetime.addSecs(time); //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); // Calculate the start and renew times leaseObtained = datetime.toString(); // Calculate the start and renew times datetime = datetime.addSecs(leaseTime); leaseExpires = datetime.toString(); dhcp = true; emit(updateInterface(this)); return true; } // interface.cpp diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h index 989d6d8..d37834a 100644 --- a/noncore/settings/networksettings/interfaces/interface.h +++ b/noncore/settings/networksettings/interfaces/interface.h @@ -1,71 +1,72 @@ #ifndef INTERFACE_H #define INTERFACE_H #include <qstring.h> #include <qobject.h> class Module; class Interface : public QObject{ Q_OBJECT signals: void updateInterface(Interface *i); void updateMessage(const QString &message); public: Interface(QObject * parent=0, const char * name= "unknown", bool status = false); - QString getInterfaceName(){ QString n(this->name()); return n; }; + QString getInterfaceName() const { QString n(this->name()); return n; }; - bool getStatus(){ return status; }; + bool getStatus() const { return status; }; void setStatus(bool newStatus); - bool isAttached(){ return attached; }; + bool isAttached() const { return attached; }; void setAttached(bool isAttached=false); - QString getHardwareName(){ return hardwareName; }; + QString getHardwareName() const { return hardwareName; }; void setHardwareName(const QString &name="Unknown"); - Module* getModuleOwner(){ return moduleOwner; }; + Module* getModuleOwner() const { return moduleOwner; }; void setModuleOwner(Module *owner=NULL); // inet information. - QString getMacAddress(){ return macAddress; }; - QString getIp(){ return ip; }; - QString getSubnetMask(){ return subnetMask; }; - QString getBroadcast(){ return broadcast; }; - bool isDhcp(){ return dhcp; }; - QString getDhcpServerIp(){ return dhcpServerIp; }; - QString getLeaseObtained(){ return leaseObtained; }; - QString getLeaseExpires(){ return leaseExpires; }; + QString getMacAddress() const { return macAddress; }; + QString getIp() const { return ip; }; + QString getSubnetMask() const { return subnetMask; }; + QString getBroadcast() const { return broadcast; }; + bool isDhcp() const { return dhcp; }; + QString getDhcpServerIp() const { return dhcpServerIp; }; + QString getLeaseObtained() const { return leaseObtained; }; + QString getLeaseExpires() const { return leaseExpires; }; public slots: bool refresh(); void start(); void stop(); void restart(); private: // Interface information - bool status; - bool attached; QString hardwareName; Module *moduleOwner; + bool status; + bool attached; // Network information - QString macAddress; - QString ip; - QString broadcast; - QString subnetMask; bool dhcp; QString dhcpServerIp; QString leaseObtained; QString leaseExpires; + QString macAddress; + QString ip; + QString broadcast; + QString subnetMask; + }; #endif // interface.h diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index e49998e..8f685fe 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp @@ -1,527 +1,527 @@ #include "interfaces.h" #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> // The three stanza's #define AUTO "auto" #define IFACE "iface" #define MAPPING "mapping" /** * Constructor. Reads in the interfaces file and then split the file up by * the \n for interfaces variable. * @param useInterfacesFile if an interface file other then the default is * desired to be used it should be passed in. */ Interfaces::Interfaces(QString useInterfacesFile){ acceptedFamily.append(INTERFACES_FAMILY_INET); acceptedFamily.append(INTERFACES_FAMILY_IPX); acceptedFamily.append(INTERFACES_FAMILY_INET6); interfacesFile = useInterfacesFile; QFile file(interfacesFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); currentIface = interfaces.end(); currentMapping = interfaces.end(); return; } QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line += stream.readLine(); line += "\n"; } file.close(); interfaces = QStringList::split("\n", line, true); currentIface = interfaces.end(); currentMapping = interfaces.end(); } /** * Get a list of all interfaces in the interface file. Usefull for * hardware that is not currently connected such as an 802.11b card * not plugged in, but configured for when it is plugged in. * @return Return string list of interfaces. **/ QStringList Interfaces::getInterfaceList(){ QStringList list; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains(IFACE) && line.at(0) != '#'){ line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace >= 0){ line = line.mid(0, findSpace); list.append(line); } } } return list; } /** * Find out if interface is in an "auto" group or not. * Report any duplicates such as eth0 being in two differnt auto's * @param interface interface to check to see if it is on or not. * @return true is interface is in auto */ -bool Interfaces::isAuto(const QString &interface){ +bool Interfaces::isAuto(const QString &interface) const { QStringList autoLines = interfaces.grep(QRegExp(AUTO)); QStringList awi = autoLines.grep(QRegExp(interface)); if(awi.count() > 1) qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); if(awi.count() < 1) return false; return true; } /** * Attempt to set the auto option for interface to setAuto. * @param interface the interface to set * @param setAuto the value to set interface to. * @return false if already set to setAuto. * */ bool Interfaces::setAuto(const QString &interface, bool setAuto){ // Don't need to set it if it is already set. if(isAuto(interface) == setAuto) return false; bool changed = false; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { if((*it).contains(AUTO)){ //We know that they are not in any group so let add to this auto. if(setAuto){ (*it) = (*it) += " " + interface; // Don't care to have such thins as: auto eth0 lo usb0 (*it) = (*it).simplifyWhiteSpace(); changed = true; break; } // else see if we need to remove from this one else{ if((*it).contains(interface)){ (*it) = (*it).replace(QRegExp(interface), ""); // if AUTO is the only thing left clear the line if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) (*it) = ""; changed = true; // Don't break because we want to make sure we remove all cases. } } } } // In the case where there is no AUTO field add one. if(!changed && setAuto) interfaces.append(QString(AUTO" %1").arg(interface)); return true; } /** * Set the current interface to interface. This needs to be done before you * can call getFamily(), getMethod, and get/setOption(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setInterface(QString interface){ interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); return setStanza(IFACE, interface, currentIface); } /** * A quick helper funtion to see if the current interface is set. * @return bool true if set, false otherwise. */ -bool Interfaces::isInterfaceSet(){ - return (currentIface != interfaces.end()); +bool Interfaces::isInterfaceSet() const { + return (interfaces.end() != currentIface); } /** * Add a new interface of with the settings - family and method * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @param family the family of this interface inet or inet, ipx or inet6 * Must of one of the families defined in interfaces.h * @param method for the family. see interfaces man page for family methods. * @return true if successfull. */ bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ if(0 == acceptedFamily.contains(family)) return false; QString newInterface = interface.simplifyWhiteSpace(); newInterface = newInterface.replace(QRegExp(" "), ""); interfaces.append(""); interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); return true; } /** * Copies interface with name interface to name newInterface * @param newInterface name of the new interface. * @return bool true if successfull */ bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ if(!setInterface(interface)) return false; // Store the old interface and bump past the stanza line. QStringList::Iterator it = currentIface; it++; // Add the new interface bool error; addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); if(!setInterface(newInterface)) return false; QStringList::Iterator newIface = currentIface; newIface++; // Copy all of the lines for ( ; it != interfaces.end(); ++it ){ if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) break; newIface = interfaces.insert(newIface, *it); } return true; } /** * Remove the currently selected interface and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeInterface(){ return removeStanza(currentIface); } /** * Gets the hardware name of the interface that is currently selected. * @return QString name of the hardware interface (eth0, usb2, wlan1...). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceName(bool &error){ if(currentIface == interfaces.end()){ error = true; return QString(); } QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); } error = false; return line.mid(0, findSpace); } /** * Gets the family name of the interface that is currently selected. * @return QString name of the family (inet, inet6, ipx). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceFamily(bool &error){ QString name = getInterfaceName(error); if(error) return QString(); QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); } error = false; return line.mid(0, findSpace); } /** * Gets the method of the interface that is currently selected. * @return QString name of the method such as staic or dhcp. * See the man page of interfaces for possible methods depending on the family. * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceMethod(bool &error){ QString name = getInterfaceName(error); if(error) return QString(); QString family = getInterfaceFamily(error); if(error) return QString(); QString line = (*currentIface); line = line.mid(QString(IFACE).length()+1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.mid(family.length()+1, line.length()); line = line.simplifyWhiteSpace(); error = false; return line; } /** * Sets the interface name to newName. * @param newName the new name of the interface. All whitespace is removed. * @return bool true if successfull. */ bool Interfaces::setInterfaceName(const QString &newName){ if(currentIface == interfaces.end()) return false; QString name = newName.simplifyWhiteSpace(); name = name.replace(QRegExp(" "), ""); bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface family to newName. * @param newName the new name of the interface. Must be one of the families * defined in the interfaces.h file. * @return bool true if successfull. */ bool Interfaces::setInterfaceFamily(const QString &newName){ if(currentIface == interfaces.end()) return false; if(acceptedFamily.contains(newName)==0) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface method to newName * @param newName the new name of the interface * @return bool true if successfull. */ bool Interfaces::setInterfaceMethod(const QString &newName){ if(currentIface == interfaces.end()) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); return !returnValue; } /** * Get a value for an option in the currently selected interface. For example * calling getInterfaceOption("address") on the following stanza would * return 192.168.1.1. * iface eth0 static * address 192.168.1.1 * @param option the options to get the value. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ QString Interfaces::getInterfaceOption(const QString &option, bool &error){ return getOption(currentIface, option, error); } /** * Set a value for an option in the currently selected interface. If option * doesn't exist then it is added along with the value. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ return setOption(currentIface, option, value); } /** * Removes a value for an option in the currently selected interface. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ return removeOption(currentIface, option, value); } /** * Removes all of the options from the currently selected interface. * @return bool error if if successfull */ bool Interfaces::removeAllInterfaceOptions(){ return removeAllOptions(currentIface); } /** * Set the current map to interface's map. This needs to be done before you * can call addMapping(), set/getMap(), and get/setScript(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setMapping(const QString &interface){ QString interfaceName = interface.simplifyWhiteSpace(); interfaceName = interfaceName.replace(QRegExp(" "), ""); return setStanza(MAPPING, interfaceName, currentMapping); } /** * Adds a new Mapping to the interfaces file with interfaces. * @param interface the name(s) of the interfaces to set to this mapping */ void Interfaces::addMapping(const QString &option){ interfaces.append(""); interfaces.append(QString(MAPPING " %1").arg(option)); } /** * Remove the currently selected map and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeMapping(){ return removeStanza(currentMapping); } /** * Set a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::setMap(const QString &map, const QString &value){ return setOption(currentMapping, map, value); } /** * Removes a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::removeMap(const QString &map, const QString &value){ return removeOption(currentMapping, map, value); } /** * Get a map value within a mapping. * @param map map to get value of * @param bool true if it is successfull. * @return value that goes to the map */ QString Interfaces::getMap(const QString &map, bool &error){ return getOption(currentMapping, map, error); } /** * Sets a script value of the current mapping to argument. * @param argument the script name. * @return true if successfull. */ bool Interfaces::setScript(const QString &argument){ return setOption(currentMapping, "script", argument); } /** * @param error true if could not retrieve the current script argument. * @return QString the argument of the script for the current mapping. */ QString Interfaces::getScript(bool &error){ return getOption(currentMapping, "script", error); } /** * Helper function used to parse through the QStringList and put pointers in * the correct place. * @param stanza The stanza (auto, iface, mapping) to look for. * @param option string that must be in the stanza's main line. * @param interator interator to place at location of stanza if successfull. * @return bool true if the stanza is found. */ bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ bool found = false; iterator = interfaces.end(); for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ uint point = line.find(option); bool valid = true; if(point > 0){ // There are more chars in the line. check +1 if(line.at(point-1) != ' ') valid = false; } point += option.length(); if(point < line.length()-1){ // There are more chars in the line. check -1 if(line.at(point) != ' ') valid = false; } if(valid){ if(found == true){ qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); } found = true; iterator = it; } } } return found; } /** * Sets a value of an option in a stanza * @param start the start of the stanza * @param option the option to use when setting value. * @return bool true if successfull, false otherwise. */ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ if(start == interfaces.end()) return false; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ if(!found && value != ""){ // Got to the end of the stanza without finding it, so append it. interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); } found = true; break; } if((*it).contains(option) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; (*it) = QString("\t%1 %2").arg(option).arg(value); } } if(!found){ QStringList::Iterator p = start; interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); found = true; } return found; } /** * Removes a stanza and all of its options * @param stanza the stanza to remove * @return bool true if successfull. */ bool Interfaces::removeStanza(QStringList::Iterator &stanza){ if(stanza == interfaces.end()) return false; (*stanza) = ""; return removeAllOptions(stanza); } /** * Removes a option in a stanza diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h index d662919..bac2a7e 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.h +++ b/noncore/settings/networksettings/interfaces/interfaces.h @@ -1,77 +1,77 @@ #ifndef INTERFACES_H #define INTERFACES_H #include <qstring.h> #include <qstringlist.h> #define INTERFACES_LOOPBACK "loopback" #define INTERFACES_FAMILY_INET "inet" #define INTERFACES_FAMILY_IPX "ipx" #define INTERFACES_FAMILY_INET6 "inet6" #define INTERFACES_METHOD_DHCP "dhcp" #define INTERFACES_METHOD_STATIC "static" #define INTERFACES_METHOD_PPP "ppp" /** * This class provides a clean frontend for parsing the network interfaces file. * It provides helper functions to minipulate the options within the file. * See the interfaces man page for the syntax rules. */ class Interfaces { public: Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); QStringList getInterfaceList(); - bool isAuto(const QString &interface); + bool isAuto(const QString &interface) const ; bool setAuto(const QString &interface, bool setAuto); bool removeInterface(); bool addInterface(const QString &interface, const QString &family, const QString &method); bool copyInterface(const QString &oldInterface, const QString &newInterface); bool setInterface(QString interface); - bool isInterfaceSet(); + bool isInterfaceSet() const ; QString getInterfaceName(bool &error); bool setInterfaceName(const QString &newName); QString getInterfaceFamily(bool &error); bool setInterfaceFamily(const QString &newName); QString getInterfaceMethod(bool &error); bool setInterfaceMethod(const QString &newName); QString getInterfaceOption(const QString &option, bool &error); bool setInterfaceOption(const QString &option, const QString &value); bool removeInterfaceOption(const QString &option, const QString &value); bool removeAllInterfaceOptions(); bool setMapping(const QString &interface); bool removeMapping(); void addMapping(const QString &options); bool setMap(const QString &map, const QString &value); bool removeMap(const QString &map, const QString &value); QString getMap(const QString &map, bool &error); bool setScript(const QString &argument); QString getScript(bool &error); bool write(); private: bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); + bool removeStanza(QStringList::Iterator &stanza); bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); + bool removeAllOptions(const QStringList::Iterator &start); bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); - bool removeStanza(QStringList::Iterator &stanza); - bool removeAllOptions(const QStringList::Iterator &start); QString interfacesFile; QStringList interfaces; QStringList::Iterator currentIface; QStringList::Iterator currentMapping; QStringList acceptedFamily; }; #endif // interfaces diff --git a/noncore/settings/networksettings/interfaces/interfaces.pro b/noncore/settings/networksettings/interfaces/interfaces.pro index 9a024f6..d6b43fb 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.pro +++ b/noncore/settings/networksettings/interfaces/interfaces.pro @@ -1,12 +1,12 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug -DESTDIR = $(QTDIR)/lib$(PROJMAK) +#DESTDIR = $(QTDIR)/lib$(PROJMAK) HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp INCLUDEPATH += $(OPIEDIR)/include ../ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe INTERFACES = interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui TARGET = interfaces VERSION = 1.0.0 diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp index 68bb0a0..72cd45e 100644 --- a/noncore/settings/networksettings/ppp/pppmodule.cpp +++ b/noncore/settings/networksettings/ppp/pppmodule.cpp @@ -1,104 +1,107 @@ #include "pppmodule.h" +#include "pppimp.h" #include "interfaceinformationimp.h" /** * Constructor, find all of the possible interfaces */ PPPModule::PPPModule() : Module() { } /** * Delete any interfaces that we own. */ PPPModule::~PPPModule(){ Interface *i; for ( i=list.first(); i != 0; i=list.next() ) delete i; } /** * Change the current profile */ void PPPModule::setProfile(const QString &newProfile){ profile = newProfile; } /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ QString PPPModule::getPixmapName(Interface* ){ return "ppp"; } /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ bool PPPModule::isOwner(Interface *i){ - // Scan the ppp database + if(!i->getInterfaceName().upper().contains("PPP")) return false; i->setHardwareName("PPP"); list.append(i); return true; } /** * Create, and return the WLANConfigure Module * @return QWidget* pointer to this modules configure. */ QWidget *PPPModule::configure(Interface *i){ return NULL; //PPPConfigureImp *pppconfig = new PPPConfigureImp(0, "PPPConfig", i, false, Qt::WDestructiveClose); //pppconfig->setProfile(profile); //return wlanconfig; } /** * Create, and return the Information Module * @return QWidget* pointer to this modules info. */ QWidget *PPPModule::information(Interface *i){ - return NULL; - - //WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); - //InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); - //info->tabWidget->insertTab(information, "TCP/IP"); - //return info; + // We don't have any advanced pppd information widget yet :-D + // TODO ^ + InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i); + return information; } /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ QList<Interface> PPPModule::getInterfaces(){ + // List all of the files in the peer directory return list; } /** * Attempt to add a new interface as defined by name * @param name the name of the type of interface that should be created given * by possibleNewInterfaces(); * @return Interface* NULL if it was unable to be created. */ Interface *PPPModule::addNewInterface(const QString &newInterface){ - // We can't add a 802.11 interface, either the hardware will be there - // or it wont. + // If the + PPPConfigureImp imp(0, "PPPConfigImp"); + if(imp.exec() == QDialog::Accepted ){ + + } return NULL; } /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ bool PPPModule::remove(Interface*){ // Can't remove a hardware device, you can stop it though. return false; } // pppmodule.cpp diff --git a/noncore/settings/networksettings/wlan/infoimp.cpp b/noncore/settings/networksettings/wlan/infoimp.cpp index e1eef81..6d3e167 100644 --- a/noncore/settings/networksettings/wlan/infoimp.cpp +++ b/noncore/settings/networksettings/wlan/infoimp.cpp @@ -1,55 +1,56 @@ #include "infoimp.h" #include "wextensions.h" + #include <qtimer.h> #include <qprogressbar.h> #include <qlabel.h> /** * Constructor. If wireless extensions are enabled on device name then * start a timer that every second will update the information. */ WlanInfoImp::WlanInfoImp( QWidget* parent, const char* name, WFlags fl): WlanInfo(parent, name, fl){ WExtensions *wExtensions = new WExtensions(name); if(!wExtensions->doesHaveWirelessExtensions()){ delete wExtensions; - qDebug("No extension"); + qDebug("WlanInfoImp::No wireless extension"); return; } delete wExtensions; timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(update())); timer->start( 1000, false ); } /** * Updates the information about the wireless device. */ void WlanInfoImp::update(){ WExtensions *wExtensions = new WExtensions(this->name()); if(!wExtensions->doesHaveWirelessExtensions()){ qDebug("No extension"); delete wExtensions; timer->stop(); return; } essidLabel->setText(wExtensions->essid()); apLabel->setText(wExtensions->ap()); stationLabel->setText(wExtensions->station()); modeLabel->setText(wExtensions->mode()); freqLabel->setText(QString("%1 GHz").arg(wExtensions->frequency())); int signal = 0; int noise = 0; int quality = 0; wExtensions->stats(signal, noise, quality); if(signalProgressBar->progress() != signal) signalProgressBar->setProgress(signal); if(noiseProgressBar->progress() != noise) noiseProgressBar->setProgress(noise); if(qualityProgressBar->progress() != quality) qualityProgressBar->setProgress(quality); rateLabel->setText(QString("%1 Mb/s").arg(wExtensions->rate())); delete wExtensions; } // infoimp.cpp |