author | korovkin <korovkin> | 2006-04-04 12:16:09 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-04-04 12:16:09 (UTC) |
commit | 76276b77e99897ae264aa5b171191521edada420 (patch) (side-by-side diff) | |
tree | b182f312ecac405b3eff0938272692cb414d51fe /noncore/net/opietooth | |
parent | 57f97a65fc7ce932231585895f358f1089900879 (diff) | |
download | opie-76276b77e99897ae264aa5b171191521edada420.zip opie-76276b77e99897ae264aa5b171191521edada420.tar.gz opie-76276b77e99897ae264aa5b171191521edada420.tar.bz2 |
Modified parser so it ignores lines like something_key_something.
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.cpp | 45 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.h | 10 |
2 files changed, 43 insertions, 12 deletions
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.cpp b/noncore/net/opietooth/manager/hciconfwrapper.cpp index 47e170e..2413f2b 100644 --- a/noncore/net/opietooth/manager/hciconfwrapper.cpp +++ b/noncore/net/opietooth/manager/hciconfwrapper.cpp @@ -1,24 +1,34 @@ +/* $Id$ */ +/* hcid.conf parser */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ #include "hciconfwrapper.h" #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> #include <opie2/odebug.h> using namespace Opie::Core; namespace OpieTooth { HciConfWrapper::HciConfWrapper( const QString &fileName) { m_fileName = fileName; } HciConfWrapper::~HciConfWrapper() { } void HciConfWrapper::setPinHelper( const QString& app ) { setValue( "pin_helper" , app ); } @@ -29,92 +39,103 @@ namespace OpieTooth { void HciConfWrapper::setIscan( bool enable) { if ( enable ) { setValue( "iscan" , "enable" ); } else { setValue( "iscan" , "disable" ); } } void HciConfWrapper::setPscan( bool enable) { if ( enable ) { setValue( "pscan" , "enable" ); } else { setValue( "pscan" , "disable" ); } } void HciConfWrapper::setAuth( bool enable) { if ( enable ) { setValue( "auth" , "enable" ); + setValue( "security" , "auto" ); } else { setValue( "auth" , "disable" ); + setValue( "security" , "none" ); } } void HciConfWrapper::setEncrypt( bool enable) { if ( enable ) { setValue( "encrypt" , "enable" ); } else { setValue( "encrypt" , "disable" ); } } void HciConfWrapper::setValue(const QString &key, const QString &value ) { if (m_file.isEmpty() ) // load first return; QStringList::Iterator it; QString str; + QString tmpLine; + bool wasCommented = false; //If the optin string was commented out + QRegExp rx1("^" + key + "[ ]+"); //Regexp fo key searching + QRegExp rx2(";[ ]*" + key + "[ ]+"); //Regexp fo key searching for (it = m_file.begin(); it != m_file.end(); ++it ) { + wasCommented = false; str = (*it); - if( (str.contains(key)) > 0 ) { - odebug << "Found" << oendl; - // still need to look if its commented out!!! - str.simplifyWhiteSpace(); - odebug << key << oendl; - if (str.startsWith("#")) { - str = (key + " " + value + ";"); - } else { - str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); - } + tmpLine = str.simplifyWhiteSpace(); + //If it's commented out, remove the comment and check again + //Now, let's check if this is a real keyword (not word_keyword) + if (tmpLine.startsWith("#")) { + tmpLine.remove(0, 1); + tmpLine = tmpLine.simplifyWhiteSpace(); + wasCommented = true; + } + if( (tmpLine.contains(rx1)) > 0 || (tmpLine.contains(rx2)) > 0) { + odebug << "Found " + key << oendl; + + if (wasCommented) + str = ("\t" + key + " " + value + ";"); + else + str = str.replace(QRegExp("\\s*" + key + "\\s+[^\\s][^;]*;"), + "\t" + key + " " + value + ";"); odebug << str << oendl; it = m_file.remove( it ); it = m_file.insert( it, str ); //return; the regexp is too wide -zecke // all set } } - - } /** * This loads the config file and stores it inside * the m_file */ void HciConfWrapper::load() { owarn << "loaded" << oendl; m_file.clear(); QFile file( m_fileName ); if (!file.open( IO_ReadOnly ) ) { odebug << "Could not open" << oendl; return; } /** * readAll() into a QByteArray * QStringList::split('\n', array ) * would this be faster? -zecke */ QTextStream stream(&file ); QString tmp; while ( !stream.atEnd() ) { tmp = stream.readLine(); diff --git a/noncore/net/opietooth/manager/hciconfwrapper.h b/noncore/net/opietooth/manager/hciconfwrapper.h index 0c4b290..5bf483c 100644 --- a/noncore/net/opietooth/manager/hciconfwrapper.h +++ b/noncore/net/opietooth/manager/hciconfwrapper.h @@ -1,24 +1,34 @@ +/* $Id$ */ +/* hcid.conf parser */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ #ifndef HCICONFWRAPPER_H #define HCICONFWRAPPER_H #include <qstring.h> #include <qstringlist.h> namespace OpieTooth { class HciConfWrapper { public: HciConfWrapper( const QString &fileName ); ~HciConfWrapper(); void load(); void save(); void setPinHelper( const QString& app ); void setName( const QString& name ); void setIscan( bool enable ); void setPscan( bool enable ); void setAuth( bool enable); void setEncrypt( bool enable); private: |