author | tille <tille> | 2003-05-30 15:06:17 (UTC) |
---|---|---|
committer | tille <tille> | 2003-05-30 15:06:17 (UTC) |
commit | 8699d02f6c152afed9490e7e7a4315044261e6e8 (patch) (unidiff) | |
tree | d2ee2ba401c7a9db0e33beaf0617a1456fe01d50 /noncore/settings/networksettings/ppp/pppdata.cpp | |
parent | d8cec07fe5e54a68afe4feca574f9f4d2433e0c1 (diff) | |
download | opie-8699d02f6c152afed9490e7e7a4315044261e6e8.zip opie-8699d02f6c152afed9490e7e7a4315044261e6e8.tar.gz opie-8699d02f6c152afed9490e7e7a4315044261e6e8.tar.bz2 |
modem and pppdata is now member of interfaceppp
Diffstat (limited to 'noncore/settings/networksettings/ppp/pppdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/pppdata.cpp | 244 |
1 files changed, 134 insertions, 110 deletions
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp index 3f1675c..59d68c9 100644 --- a/noncore/settings/networksettings/ppp/pppdata.cpp +++ b/noncore/settings/networksettings/ppp/pppdata.cpp | |||
@@ -35,47 +35,23 @@ | |||
35 | // #include <klocale.h> | 35 | // #include <klocale.h> |
36 | // #include <kconfig.h> | 36 | // #include <kconfig.h> |
37 | // #include <kmessagebox.h> | 37 | // #include <kmessagebox.h> |
38 | // #include <kapplication.h> | 38 | // #include <kapplication.h> |
39 | #include <assert.h> | 39 | #include <assert.h> |
40 | 40 | ||
41 | PPPData *PPPData::_data = 0; | 41 | #define SEPARATOR -sseepp- |
42 | Config *PPPData::config = 0; | 42 | #define SEP QString("%1SEPARATOR%1") |
43 | |||
44 | PPPData* PPPData::data() | ||
45 | { | ||
46 | if (!_data){ | ||
47 | qDebug("PPPData::data() creates new Instance"); | ||
48 | _data = new PPPData(); | ||
49 | } | ||
50 | if (!_data->config){ | ||
51 | qDebug("PPPData::data() opens conffile"); | ||
52 | _data->open(); | ||
53 | } | ||
54 | return _data; | ||
55 | } | ||
56 | 43 | ||
57 | PPPData::PPPData() | 44 | PPPData::PPPData() |
58 | : modemDeviceGroup(-1), | 45 | : modemDeviceGroup(-1), |
59 | highcount(-1), // start out with no entries | 46 | highcount(-1), // start out with no entries |
60 | caccount(-1), // set the current account index also | 47 | caccount(-1), // set the current account index also |
61 | suidprocessid(-1), // process ID of setuid child | 48 | suidprocessid(-1), // process ID of setuid child |
62 | pppdisrunning(false), | 49 | pppdisrunning(false), |
63 | pppderror(0) | 50 | pppderror(0) |
64 | { | 51 | { |
65 | } | ||
66 | |||
67 | |||
68 | // | ||
69 | // open configuration file | ||
70 | // | ||
71 | bool PPPData::open() { | ||
72 | qDebug("opening configfile NetworkSetupPPP"); | ||
73 | if (config) return true; | ||
74 | config = new Config("NetworkSetupPPP"); | ||
75 | |||
76 | highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; | 52 | highcount = readNumConfig(GENERAL_GRP, NUMACCOUNTS_KEY, 0) - 1; |
77 | 53 | ||
78 | if (highcount > MAX_ACCOUNTS) | 54 | if (highcount > MAX_ACCOUNTS) |
79 | highcount = MAX_ACCOUNTS; | 55 | highcount = MAX_ACCOUNTS; |
80 | 56 | ||
81 | if(highcount >= 0 && defaultAccount().isEmpty()) { | 57 | if(highcount >= 0 && defaultAccount().isEmpty()) { |
@@ -87,114 +63,157 @@ bool PPPData::open() { | |||
87 | // start out with internal debugging disabled | 63 | // start out with internal debugging disabled |
88 | // the user is still free to specify `debug' on his own | 64 | // the user is still free to specify `debug' on his own |
89 | setPPPDebug(false); | 65 | setPPPDebug(false); |
90 | 66 | ||
91 | ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch); | 67 | ::pppdVersion(&pppdVer, &pppdMod, &pppdPatch); |
92 | 68 | ||
93 | return true; | ||
94 | } | 69 | } |
95 | 70 | ||
71 | Config PPPData::config() | ||
72 | { | ||
73 | return Config("NetworkSetupPPP"); | ||
74 | } | ||
96 | 75 | ||
97 | // | 76 | // |
98 | // save configuration | 77 | // save configuration |
99 | // | 78 | // |
100 | void PPPData::save() { | 79 | void PPPData::save() |
101 | 80 | { | |
102 | if (config) { | 81 | qDebug("PPPData saving data"); |
103 | writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); | 82 | writeConfig(GENERAL_GRP, NUMACCOUNTS_KEY, count()); |
104 | delete config; | 83 | QString key; |
105 | config = 0; | 84 | QStringList keys; |
106 | qDebug("worte confi NetworkSetupPPP"); | 85 | Config cfg = config(); |
107 | } | 86 | for( QMap<QString,QString>::Iterator it = stringEntries.begin(); |
108 | if (_data){ | 87 | it != stringEntries.end(); ++it ){ |
109 | delete _data; | 88 | QString val = it.data(); |
110 | _data = 0; | 89 | key = it.key(); |
90 | // qDebug("saving %s -> %s", key.latin1(), val.latin1() ); | ||
91 | keys = QStringList::split( "SEPARATOR", key ); | ||
92 | qDebug("group >%s< key >%s< value >%s<", keys[0].latin1(), keys[1].latin1(), val.latin1() ); | ||
93 | cfg.setGroup(keys[0]); | ||
94 | cfg.writeEntry(keys[1], val); | ||
95 | } | ||
96 | for( QMap<QString,int>::Iterator it = intEntries.begin(); | ||
97 | it != intEntries.end(); ++it ){ | ||
98 | int val = it.data(); | ||
99 | key = it.key(); | ||
100 | // qDebug("saving %s -> %i", key.latin1(), val ); | ||
101 | keys = QStringList::split( "SEPARATOR", key ); | ||
102 | qDebug("group >%s< key >%s< val %i", keys[0].latin1(), keys[1].latin1(), val ); | ||
103 | cfg.setGroup(keys[0]); | ||
104 | cfg.writeEntry(keys[1], val); | ||
105 | } | ||
106 | for( QMap<QString,QStringList>::Iterator it = listEntries.begin(); | ||
107 | it != listEntries.end(); ++it ){ | ||
108 | QStringList val = it.data(); | ||
109 | key = it.key(); | ||
110 | QChar sep = sepEntries[key]; | ||
111 | // qDebug("saving %s -> %s", key.latin1(), val.join(sep).latin1() ); | ||
112 | keys = QStringList::split( "SEPARATOR", key ); | ||
113 | qDebug("group >%s< key >%s<values >%s<", keys[0].latin1(), keys[1].latin1(), val.join(sep).latin1() ); | ||
114 | cfg.setGroup(keys[0]); | ||
115 | cfg.writeEntry(keys[1], val, sep); | ||
111 | } | 116 | } |
112 | |||
113 | } | 117 | } |
114 | 118 | ||
115 | 119 | ||
116 | // | 120 | // |
117 | // cancel changes | 121 | // cancel changes |
118 | // | 122 | // |
119 | void PPPData::cancel() { | 123 | void PPPData::cancel() { |
120 | 124 | stringEntries.clear(); | |
121 | // if (config) { | 125 | intEntries.clear(); |
122 | // config->rollback(); | 126 | listEntries.clear(); |
123 | // config->reparseConfiguration(); | ||
124 | // } | ||
125 | |||
126 | } | 127 | } |
127 | 128 | ||
128 | |||
129 | // // currently differentiates between READWRITE and NONE only | ||
130 | // int PPPData::access() const { | ||
131 | |||
132 | // return 1;//config->getConfigState(); | ||
133 | // } | ||
134 | |||
135 | |||
136 | // functions to read/write date to configuration file | 129 | // functions to read/write date to configuration file |
137 | QString PPPData::readConfig(const QString &group, const QString &key, | 130 | QString PPPData::readConfig(const QString &group, const QString &key, |
138 | const QString &defvalue = "") | 131 | const QString &defvalue = "") |
139 | { | 132 | { |
140 | // qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1()); | 133 | // qDebug("PPPData::readConfig key >%s< group >%s<",key.latin1(), group.latin1()); |
141 | if (config) { | 134 | QString idx = SEP.arg(group).arg(key); |
142 | config->setGroup(group); | 135 | if (stringEntries.find(idx) != stringEntries.end()) |
143 | return config->readEntry(key, defvalue); | 136 | return stringEntries[idx]; |
144 | } else | 137 | Config cfg = config(); |
145 | return defvalue; | 138 | cfg.setGroup(group); |
139 | return cfg.readEntry(key, defvalue); | ||
146 | } | 140 | } |
147 | 141 | ||
148 | 142 | ||
149 | int PPPData::readNumConfig(const QString &group, const QString &key, | 143 | int PPPData::readNumConfig(const QString &group, const QString &key, |
150 | int defvalue) { | 144 | int defvalue) |
151 | if (config) { | 145 | { |
152 | config->setGroup(group); | 146 | QString idx = SEP.arg(group).arg(key); |
153 | return config->readNumEntry(key, defvalue); | 147 | if (intEntries.find(idx) != intEntries.end()) |
154 | } else | 148 | return intEntries[idx]; |
155 | return defvalue; | 149 | Config cfg = config(); |
150 | cfg.setGroup(group); | ||
151 | return cfg.readNumEntry(key, defvalue); | ||
152 | |||
153 | // if (config) { | ||
154 | // config->setGroup(group); | ||
155 | // return config->readNumEntry(key, defvalue); | ||
156 | // } else | ||
157 | // return defvalue; | ||
156 | 158 | ||
157 | } | 159 | } |
158 | 160 | ||
159 | 161 | ||
160 | bool PPPData::readListConfig(const QString &group, const QString &key, | 162 | bool PPPData::readListConfig(const QString &group, const QString &key, |
161 | QStringList &list, char sep) { | 163 | QStringList &list, char sep) { |
162 | list.clear(); | 164 | list.clear(); |
163 | if (config) { | 165 | QString idx = SEP.arg(group).arg(key); |
164 | config->setGroup(group); | 166 | if (listEntries.find(idx) != listEntries.end()){ |
165 | list = config->readListEntry(key, sep); | 167 | list = listEntries[idx]; |
166 | return true; | 168 | return true; |
167 | } else | 169 | } |
170 | Config cfg = config(); | ||
171 | cfg.setGroup(group); | ||
172 | list = cfg.readListEntry(key, sep); | ||
173 | if (list.count() > 0) return true; | ||
168 | return false; | 174 | return false; |
175 | |||
176 | // if (config) { | ||
177 | // config->setGroup(group); | ||
178 | // list = config->readListEntry(key, sep); | ||
179 | // return true; | ||
180 | // } else | ||
181 | // return false; | ||
169 | } | 182 | } |
170 | 183 | ||
171 | 184 | ||
172 | void PPPData::writeConfig(const QString &group, const QString &key, | 185 | void PPPData::writeConfig(const QString &group, const QString &key, |
173 | const QString &value) { | 186 | const QString &value) { |
174 | if (config) { | 187 | stringEntries.insert( SEP.arg(group).arg(key), value ); |
175 | config->setGroup(group); | 188 | // if (config) { |
176 | config->writeEntry(key, value); | 189 | // config->setGroup(group); |
177 | } | 190 | // config->writeEntry(key, value); |
191 | // } | ||
178 | } | 192 | } |
179 | 193 | ||
180 | 194 | ||
181 | void PPPData::writeConfig(const QString &group, const QString &key, int value) { | 195 | void PPPData::writeConfig(const QString &group, const QString &key, int value) |
182 | if (config) { | 196 | { |
183 | config->setGroup(group); | 197 | intEntries.insert( SEP.arg(group).arg(key), value ); |
184 | config->writeEntry(key, value); | 198 | // if (config) { |
185 | } | 199 | // config->setGroup(group); |
200 | // config->writeEntry(key, value); | ||
201 | // } | ||
186 | } | 202 | } |
187 | 203 | ||
188 | 204 | ||
189 | void PPPData::writeListConfig(const QString &group, const QString &key, | 205 | void PPPData::writeListConfig(const QString &group, const QString &key, |
190 | QStringList &list, char sep) { | 206 | QStringList &list, char sep) |
191 | if (config) { | 207 | { |
192 | config->setGroup(group); | 208 | listEntries.insert( SEP.arg(group).arg(key), list ); |
193 | config->writeEntry(key, list, sep); | 209 | sepEntries.insert( SEP.arg(group).arg(key), sep ); |
194 | } | 210 | // if (config) { |
211 | // config->setGroup(group); | ||
212 | // config->writeEntry(key, list, sep); | ||
213 | // } | ||
195 | } | 214 | } |
196 | 215 | ||
197 | 216 | ||
198 | // | 217 | // |
199 | // functions to set/return general information | 218 | // functions to set/return general information |
200 | // | 219 | // |
@@ -278,30 +297,30 @@ bool PPPData::automatic_redial() { | |||
278 | 297 | ||
279 | void PPPData::set_automatic_redial(bool set) { | 298 | void PPPData::set_automatic_redial(bool set) { |
280 | writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set); | 299 | writeConfig(GENERAL_GRP, AUTOREDIAL_KEY, (int) set); |
281 | } | 300 | } |
282 | 301 | ||
283 | 302 | ||
284 | bool PPPData::get_iconify_on_connect() { | 303 | // bool PPPData::get_iconify_on_connect() { |
285 | return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE); | 304 | // return (bool) readNumConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, TRUE); |
286 | } | 305 | // } |
287 | 306 | ||
288 | 307 | ||
289 | void PPPData::set_iconify_on_connect(bool set) { | 308 | // void PPPData::set_iconify_on_connect(bool set) { |
290 | writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set); | 309 | // writeConfig(GENERAL_GRP, ICONIFY_ON_CONNECT_KEY, (int) set); |
291 | } | 310 | // } |
292 | 311 | ||
293 | 312 | ||
294 | bool PPPData::get_dock_into_panel() { | 313 | // bool PPPData::get_dock_into_panel() { |
295 | return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false); | 314 | // return (bool) readNumConfig(GENERAL_GRP, DOCKING_KEY, false); |
296 | } | 315 | // } |
297 | 316 | ||
298 | 317 | ||
299 | void PPPData::set_dock_into_panel(bool set) { | 318 | // void PPPData::set_dock_into_panel(bool set) { |
300 | writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set); | 319 | // writeConfig(GENERAL_GRP, DOCKING_KEY, (int) set); |
301 | } | 320 | // } |
302 | 321 | ||
303 | 322 | ||
304 | QString PPPData::pppdVersion() { | 323 | QString PPPData::pppdVersion() { |
305 | return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch); | 324 | return QString("%1.%2.%3").arg(pppdVer).arg(pppdMod).arg(pppdPatch); |
306 | } | 325 | } |
307 | 326 | ||
@@ -787,13 +806,13 @@ bool PPPData::deleteAccount(const QString &aname) { | |||
787 | } | 806 | } |
788 | 807 | ||
789 | 808 | ||
790 | int PPPData::newaccount() { | 809 | int PPPData::newaccount() { |
791 | 810 | ||
792 | qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); | 811 | qDebug("PPPData::newaccount highcount %i/%i",highcount,MAX_ACCOUNTS); |
793 | if(!config) open(); | 812 | // if(!config) open(); |
794 | if (highcount >= MAX_ACCOUNTS) return -1; | 813 | if (highcount >= MAX_ACCOUNTS) return -1; |
795 | 814 | ||
796 | highcount++; | 815 | highcount++; |
797 | setAccountbyIndex(highcount); | 816 | setAccountbyIndex(highcount); |
798 | 817 | ||
799 | setpppdArgumentDefaults(); | 818 | setpppdArgumentDefaults(); |
@@ -987,20 +1006,20 @@ bool PPPData::AcctEnabled() { | |||
987 | 1006 | ||
988 | void PPPData::setAcctEnabled(bool set) { | 1007 | void PPPData::setAcctEnabled(bool set) { |
989 | writeConfig(cgroup, ACCTENABLED_KEY, (int) set); | 1008 | writeConfig(cgroup, ACCTENABLED_KEY, (int) set); |
990 | } | 1009 | } |
991 | 1010 | ||
992 | 1011 | ||
993 | int PPPData::VolAcctEnabled() { | 1012 | // int PPPData::VolAcctEnabled() { |
994 | return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0); | 1013 | // return readNumConfig(cgroup, VOLACCTENABLED_KEY, 0); |
995 | } | 1014 | // } |
996 | 1015 | ||
997 | 1016 | ||
998 | void PPPData::setVolAcctEnabled(int set) { | 1017 | // void PPPData::setVolAcctEnabled(int set) { |
999 | writeConfig(cgroup, VOLACCTENABLED_KEY, set); | 1018 | // writeConfig(cgroup, VOLACCTENABLED_KEY, set); |
1000 | } | 1019 | // } |
1001 | 1020 | ||
1002 | 1021 | ||
1003 | const QString PPPData::gateway() { | 1022 | const QString PPPData::gateway() { |
1004 | return readConfig(cgroup, GATEWAY_KEY); | 1023 | return readConfig(cgroup, GATEWAY_KEY); |
1005 | } | 1024 | } |
1006 | 1025 | ||
@@ -1020,13 +1039,13 @@ void PPPData::setDefaultroute(bool set) { | |||
1020 | writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set); | 1039 | writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set); |
1021 | } | 1040 | } |
1022 | 1041 | ||
1023 | 1042 | ||
1024 | bool PPPData::autoDNS() { | 1043 | bool PPPData::autoDNS() { |
1025 | bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true); | 1044 | bool set = (bool) readNumConfig(cgroup, AUTODNS_KEY, true); |
1026 | return (set && PPPData::data()->pppdVersionMin(2, 3, 7)); | 1045 | return (set && pppdVersionMin(2, 3, 7)); |
1027 | } | 1046 | } |
1028 | 1047 | ||
1029 | 1048 | ||
1030 | void PPPData::setAutoDNS(bool set) { | 1049 | void PPPData::setAutoDNS(bool set) { |
1031 | writeConfig(cgroup, AUTODNS_KEY, (int) set); | 1050 | writeConfig(cgroup, AUTODNS_KEY, (int) set); |
1032 | } | 1051 | } |
@@ -1223,30 +1242,35 @@ QString PPPData::modemGroup() | |||
1223 | } | 1242 | } |
1224 | 1243 | ||
1225 | 1244 | ||
1226 | QMap<QString,QString> PPPData::getConfiguredInterfaces() | 1245 | QMap<QString,QString> PPPData::getConfiguredInterfaces() |
1227 | { | 1246 | { |
1228 | QMap<QString,QString> ifaces; | 1247 | QMap<QString,QString> ifaces; |
1229 | int count = readNumConfig( ACCLIST_GRP, ACCOUNTS_COUNT, -1 ); | 1248 | Config config = PPPData::config(); |
1230 | QString accGrp; | 1249 | config.setGroup(ACCLIST_GRP); |
1250 | int count = config.readNumEntry( ACCOUNTS_COUNT, -1 ); | ||
1251 | QString accGrp, dev, acc; | ||
1231 | for (int i = 0; i < count; i++){ | 1252 | for (int i = 0; i < count; i++){ |
1232 | accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); | 1253 | accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); |
1233 | ifaces.insert( readConfig( accGrp, ACOUNTS_DEV, "error" ), | 1254 | config.setGroup(accGrp); |
1234 | readConfig( accGrp, ACOUNTS_ACC, "error" ) ); | 1255 | dev = config.readEntry( ACOUNTS_DEV, "error" ); |
1256 | acc = config.readEntry( ACOUNTS_ACC, "error" ); | ||
1257 | ifaces.insert( dev, acc ); | ||
1235 | } | 1258 | } |
1236 | 1259 | ||
1237 | return ifaces; | 1260 | return ifaces; |
1238 | } | 1261 | } |
1239 | 1262 | ||
1240 | void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) | 1263 | void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) |
1241 | { | 1264 | { |
1242 | QMap<QString,QString>::Iterator it; | 1265 | QMap<QString,QString>::Iterator it; |
1243 | QString accGrp; | ||
1244 | int i = 0; | 1266 | int i = 0; |
1267 | Config cfg = config(); | ||
1245 | for( it = ifaces.begin(); it != ifaces.end(); ++it, ++i ){ | 1268 | for( it = ifaces.begin(); it != ifaces.end(); ++it, ++i ){ |
1246 | accGrp = QString("%1_%1").arg(ACCLIST_GRP).arg(i); | 1269 | cfg.setGroup(QString("%1_%1").arg(ACCLIST_GRP).arg(i)); |
1247 | writeConfig( accGrp, ACOUNTS_DEV, it.key() ); | 1270 | cfg.writeEntry( ACOUNTS_DEV, it.key() ); |
1248 | writeConfig( accGrp, ACOUNTS_ACC, it.data() ); | 1271 | cfg.writeEntry( ACOUNTS_ACC, it.data() ); |
1249 | } | 1272 | } |
1250 | writeConfig( ACCLIST_GRP, ACCOUNTS_COUNT, i ); | 1273 | cfg.setGroup( ACCLIST_GRP ); |
1274 | cfg.writeEntry( ACCOUNTS_COUNT, i ); | ||
1251 | 1275 | ||
1252 | } | 1276 | } |