author | korovkin <korovkin> | 2006-04-04 12:16:09 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-04-04 12:16:09 (UTC) |
commit | 76276b77e99897ae264aa5b171191521edada420 (patch) (unidiff) | |
tree | b182f312ecac405b3eff0938272692cb414d51fe | |
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 @@ | |||
1 | /* $Id$ */ | ||
2 | /* hcid.conf parser */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
1 | #include "hciconfwrapper.h" | 11 | #include "hciconfwrapper.h" |
2 | 12 | ||
3 | #include <qfile.h> | 13 | #include <qfile.h> |
4 | #include <qtextstream.h> | 14 | #include <qtextstream.h> |
5 | #include <qregexp.h> | 15 | #include <qregexp.h> |
6 | 16 | ||
7 | #include <opie2/odebug.h> | 17 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 18 | using namespace Opie::Core; |
9 | 19 | ||
10 | namespace OpieTooth { | 20 | namespace OpieTooth { |
11 | 21 | ||
12 | 22 | ||
13 | HciConfWrapper::HciConfWrapper( const QString &fileName) { | 23 | HciConfWrapper::HciConfWrapper( const QString &fileName) { |
14 | m_fileName = fileName; | 24 | m_fileName = fileName; |
15 | } | 25 | } |
16 | 26 | ||
17 | HciConfWrapper::~HciConfWrapper() { | 27 | HciConfWrapper::~HciConfWrapper() { |
18 | } | 28 | } |
19 | 29 | ||
20 | 30 | ||
21 | void HciConfWrapper::setPinHelper( const QString& app ) { | 31 | void HciConfWrapper::setPinHelper( const QString& app ) { |
22 | setValue( "pin_helper" , app ); | 32 | setValue( "pin_helper" , app ); |
23 | } | 33 | } |
24 | 34 | ||
@@ -29,92 +39,103 @@ namespace OpieTooth { | |||
29 | 39 | ||
30 | void HciConfWrapper::setIscan( bool enable) { | 40 | void HciConfWrapper::setIscan( bool enable) { |
31 | 41 | ||
32 | if ( enable ) { | 42 | if ( enable ) { |
33 | setValue( "iscan" , "enable" ); | 43 | setValue( "iscan" , "enable" ); |
34 | } else { | 44 | } else { |
35 | setValue( "iscan" , "disable" ); | 45 | setValue( "iscan" , "disable" ); |
36 | } | 46 | } |
37 | } | 47 | } |
38 | 48 | ||
39 | void HciConfWrapper::setPscan( bool enable) { | 49 | void HciConfWrapper::setPscan( bool enable) { |
40 | 50 | ||
41 | if ( enable ) { | 51 | if ( enable ) { |
42 | setValue( "pscan" , "enable" ); | 52 | setValue( "pscan" , "enable" ); |
43 | } else { | 53 | } else { |
44 | setValue( "pscan" , "disable" ); | 54 | setValue( "pscan" , "disable" ); |
45 | } | 55 | } |
46 | } | 56 | } |
47 | 57 | ||
48 | 58 | ||
49 | void HciConfWrapper::setAuth( bool enable) { | 59 | void HciConfWrapper::setAuth( bool enable) { |
50 | 60 | ||
51 | if ( enable ) { | 61 | if ( enable ) { |
52 | setValue( "auth" , "enable" ); | 62 | setValue( "auth" , "enable" ); |
63 | setValue( "security" , "auto" ); | ||
53 | } else { | 64 | } else { |
54 | setValue( "auth" , "disable" ); | 65 | setValue( "auth" , "disable" ); |
66 | setValue( "security" , "none" ); | ||
55 | } | 67 | } |
56 | } | 68 | } |
57 | 69 | ||
58 | 70 | ||
59 | void HciConfWrapper::setEncrypt( bool enable) { | 71 | void HciConfWrapper::setEncrypt( bool enable) { |
60 | 72 | ||
61 | if ( enable ) { | 73 | if ( enable ) { |
62 | setValue( "encrypt" , "enable" ); | 74 | setValue( "encrypt" , "enable" ); |
63 | } else { | 75 | } else { |
64 | setValue( "encrypt" , "disable" ); | 76 | setValue( "encrypt" , "disable" ); |
65 | } | 77 | } |
66 | } | 78 | } |
67 | 79 | ||
68 | 80 | ||
69 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { | 81 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { |
70 | 82 | ||
71 | if (m_file.isEmpty() ) // load first | 83 | if (m_file.isEmpty() ) // load first |
72 | return; | 84 | return; |
73 | 85 | ||
74 | QStringList::Iterator it; | 86 | QStringList::Iterator it; |
75 | 87 | ||
76 | QString str; | 88 | QString str; |
89 | QString tmpLine; | ||
90 | bool wasCommented = false; //If the optin string was commented out | ||
91 | QRegExp rx1("^" + key + "[ ]+"); //Regexp fo key searching | ||
92 | QRegExp rx2(";[ ]*" + key + "[ ]+"); //Regexp fo key searching | ||
77 | for (it = m_file.begin(); it != m_file.end(); ++it ) { | 93 | for (it = m_file.begin(); it != m_file.end(); ++it ) { |
94 | wasCommented = false; | ||
78 | str = (*it); | 95 | str = (*it); |
79 | if( (str.contains(key)) > 0 ) { | 96 | tmpLine = str.simplifyWhiteSpace(); |
80 | odebug << "Found" << oendl; | 97 | //If it's commented out, remove the comment and check again |
81 | // still need to look if its commented out!!! | 98 | //Now, let's check if this is a real keyword (not word_keyword) |
82 | str.simplifyWhiteSpace(); | 99 | if (tmpLine.startsWith("#")) { |
83 | odebug << key << oendl; | 100 | tmpLine.remove(0, 1); |
84 | if (str.startsWith("#")) { | 101 | tmpLine = tmpLine.simplifyWhiteSpace(); |
85 | str = (key + " " + value + ";"); | 102 | wasCommented = true; |
86 | } else { | 103 | } |
87 | str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); | 104 | if( (tmpLine.contains(rx1)) > 0 || (tmpLine.contains(rx2)) > 0) { |
88 | } | 105 | odebug << "Found " + key << oendl; |
106 | |||
107 | if (wasCommented) | ||
108 | str = ("\t" + key + " " + value + ";"); | ||
109 | else | ||
110 | str = str.replace(QRegExp("\\s*" + key + "\\s+[^\\s][^;]*;"), | ||
111 | "\t" + key + " " + value + ";"); | ||
89 | odebug << str << oendl; | 112 | odebug << str << oendl; |
90 | it = m_file.remove( it ); | 113 | it = m_file.remove( it ); |
91 | it = m_file.insert( it, str ); | 114 | it = m_file.insert( it, str ); |
92 | //return; the regexp is too wide -zecke // all set | 115 | //return; the regexp is too wide -zecke // all set |
93 | } | 116 | } |
94 | } | 117 | } |
95 | |||
96 | |||
97 | } | 118 | } |
98 | 119 | ||
99 | /** | 120 | /** |
100 | * This loads the config file and stores it inside | 121 | * This loads the config file and stores it inside |
101 | * the m_file | 122 | * the m_file |
102 | */ | 123 | */ |
103 | void HciConfWrapper::load() { | 124 | void HciConfWrapper::load() { |
104 | owarn << "loaded" << oendl; | 125 | owarn << "loaded" << oendl; |
105 | m_file.clear(); | 126 | m_file.clear(); |
106 | QFile file( m_fileName ); | 127 | QFile file( m_fileName ); |
107 | if (!file.open( IO_ReadOnly ) ) { | 128 | if (!file.open( IO_ReadOnly ) ) { |
108 | odebug << "Could not open" << oendl; | 129 | odebug << "Could not open" << oendl; |
109 | return; | 130 | return; |
110 | } | 131 | } |
111 | 132 | ||
112 | /** | 133 | /** |
113 | * readAll() into a QByteArray | 134 | * readAll() into a QByteArray |
114 | * QStringList::split('\n', array ) | 135 | * QStringList::split('\n', array ) |
115 | * would this be faster? -zecke | 136 | * would this be faster? -zecke |
116 | */ | 137 | */ |
117 | QTextStream stream(&file ); | 138 | QTextStream stream(&file ); |
118 | QString tmp; | 139 | QString tmp; |
119 | while ( !stream.atEnd() ) { | 140 | while ( !stream.atEnd() ) { |
120 | tmp = stream.readLine(); | 141 | 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 @@ | |||
1 | /* $Id$ */ | ||
2 | /* hcid.conf parser */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
1 | #ifndef HCICONFWRAPPER_H | 11 | #ifndef HCICONFWRAPPER_H |
2 | #define HCICONFWRAPPER_H | 12 | #define HCICONFWRAPPER_H |
3 | 13 | ||
4 | #include <qstring.h> | 14 | #include <qstring.h> |
5 | #include <qstringlist.h> | 15 | #include <qstringlist.h> |
6 | 16 | ||
7 | namespace OpieTooth { | 17 | namespace OpieTooth { |
8 | 18 | ||
9 | class HciConfWrapper { | 19 | class HciConfWrapper { |
10 | 20 | ||
11 | public: | 21 | public: |
12 | HciConfWrapper( const QString &fileName ); | 22 | HciConfWrapper( const QString &fileName ); |
13 | ~HciConfWrapper(); | 23 | ~HciConfWrapper(); |
14 | void load(); | 24 | void load(); |
15 | void save(); | 25 | void save(); |
16 | 26 | ||
17 | void setPinHelper( const QString& app ); | 27 | void setPinHelper( const QString& app ); |
18 | void setName( const QString& name ); | 28 | void setName( const QString& name ); |
19 | void setIscan( bool enable ); | 29 | void setIscan( bool enable ); |
20 | void setPscan( bool enable ); | 30 | void setPscan( bool enable ); |
21 | void setAuth( bool enable); | 31 | void setAuth( bool enable); |
22 | void setEncrypt( bool enable); | 32 | void setEncrypt( bool enable); |
23 | 33 | ||
24 | private: | 34 | private: |