summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/pppdata.cpp
authortille <tille>2003-05-30 15:06:17 (UTC)
committer tille <tille>2003-05-30 15:06:17 (UTC)
commit8699d02f6c152afed9490e7e7a4315044261e6e8 (patch) (unidiff)
treed2ee2ba401c7a9db0e33beaf0617a1456fe01d50 /noncore/settings/networksettings/ppp/pppdata.cpp
parentd8cec07fe5e54a68afe4feca574f9f4d2433e0c1 (diff)
downloadopie-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) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.cpp250
1 files changed, 137 insertions, 113 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
@@ -29,178 +29,197 @@
29#include "devices.h" 29#include "devices.h"
30//#include <klocale.h> 30//#include <klocale.h>
31#define i18n QObject::tr 31#define i18n QObject::tr
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <qmessagebox.h> 33#include <qmessagebox.h>
34#include <qapplication.h> 34#include <qapplication.h>
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
41PPPData *PPPData::_data = 0; 41#define SEPARATOR -sseepp-
42Config *PPPData::config = 0; 42#define SEP QString("%1SEPARATOR%1")
43
44PPPData* 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
57PPPData::PPPData() 44PPPData::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//
71bool 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()) {
82 setAccountbyIndex(0); 58 setAccountbyIndex(0);
83 setDefaultAccount(accname()); 59 setDefaultAccount(accname());
84 } else if(!setAccount(defaultAccount())) 60 } else if(!setAccount(defaultAccount()))
85 setDefaultAccount(accname()); 61 setDefaultAccount(accname());
86 62
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
71Config PPPData::config()
72{
73 return Config("NetworkSetupPPP");
74}
96 75
97// 76//
98// save configuration 77// save configuration
99// 78//
100void PPPData::save() { 79void 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();
111 } 90// qDebug("saving %s -> %s", key.latin1(), val.latin1() );
112 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);
116 }
113} 117}
114 118
115 119
116// 120//
117// cancel changes 121// cancel changes
118// 122//
119void PPPData::cancel() { 123void 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
137QString PPPData::readConfig(const QString &group, const QString &key, 130QString 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
149int PPPData::readNumConfig(const QString &group, const QString &key, 143int 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
160bool PPPData::readListConfig(const QString &group, const QString &key, 162bool 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 }
168 return false; 170 Config cfg = config();
171 cfg.setGroup(group);
172 list = cfg.readListEntry(key, sep);
173 if (list.count() > 0) return true;
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
172void PPPData::writeConfig(const QString &group, const QString &key, 185void 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
181void PPPData::writeConfig(const QString &group, const QString &key, int value) { 195void 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
189void PPPData::writeListConfig(const QString &group, const QString &key, 205void 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//
201QString PPPData::password() const { 220QString PPPData::password() const {
202 return passwd; 221 return passwd;
203} 222}
204 223
205 224
206void PPPData::setPassword(const QString &pw) { 225void PPPData::setPassword(const QString &pw) {
@@ -272,42 +291,42 @@ void PPPData::set_show_log_window(bool set) {
272 291
273 292
274bool PPPData::automatic_redial() { 293bool PPPData::automatic_redial() {
275 return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, FALSE); 294 return (bool) readNumConfig(GENERAL_GRP, AUTOREDIAL_KEY, FALSE);
276} 295}
277 296
278 297
279void PPPData::set_automatic_redial(bool set) { 298void 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
284bool 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
289void 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
294bool 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
299void 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
304QString PPPData::pppdVersion() { 323QString 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
308bool PPPData::pppdVersionMin(int ver, int mod, int patch) { 327bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
309 // check if pppd version fulfills minimum requirement 328 // check if pppd version fulfills minimum requirement
310 return (pppdVer > ver 329 return (pppdVer > ver
311 || (pppdVer == ver && pppdMod > mod) 330 || (pppdVer == ver && pppdMod > mod)
312 || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch)); 331 || (pppdVer == ver && pppdMod == mod && pppdPatch >= patch));
313} 332}
@@ -781,25 +800,25 @@ bool PPPData::deleteAccount(const QString &aname) {
781 if(!setAccount(aname)) 800 if(!setAccount(aname))
782 return false; 801 return false;
783 802
784 deleteAccount(); 803 deleteAccount();
785 804
786 return true; 805 return true;
787} 806}
788 807
789 808
790int PPPData::newaccount() { 809int 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();
800 qDebug("PPPData::newaccount -> %i",caccount); 819 qDebug("PPPData::newaccount -> %i",caccount);
801 return caccount; 820 return caccount;
802} 821}
803 822
804int PPPData::copyaccount(int i) { 823int PPPData::copyaccount(int i) {
805// FIXME 824// FIXME
@@ -981,32 +1000,32 @@ void PPPData::setAutoname(bool set) {
981 1000
982 1001
983bool PPPData::AcctEnabled() { 1002bool PPPData::AcctEnabled() {
984 return (bool) readNumConfig(cgroup, ACCTENABLED_KEY, false); 1003 return (bool) readNumConfig(cgroup, ACCTENABLED_KEY, false);
985} 1004}
986 1005
987 1006
988void PPPData::setAcctEnabled(bool set) { 1007void PPPData::setAcctEnabled(bool set) {
989 writeConfig(cgroup, ACCTENABLED_KEY, (int) set); 1008 writeConfig(cgroup, ACCTENABLED_KEY, (int) set);
990} 1009}
991 1010
992 1011
993int 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
998void 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
1003const QString PPPData::gateway() { 1022const QString PPPData::gateway() {
1004 return readConfig(cgroup, GATEWAY_KEY); 1023 return readConfig(cgroup, GATEWAY_KEY);
1005} 1024}
1006 1025
1007 1026
1008void PPPData::setGateway(const QString &n ) { 1027void PPPData::setGateway(const QString &n ) {
1009 writeConfig(cgroup, GATEWAY_KEY, n); 1028 writeConfig(cgroup, GATEWAY_KEY, n);
1010} 1029}
1011 1030
1012 1031
@@ -1014,25 +1033,25 @@ bool PPPData::defaultroute() {
1014 // default route is by default 'on'. 1033 // default route is by default 'on'.
1015 return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true); 1034 return (bool) readNumConfig(cgroup, DEFAULTROUTE_KEY, true);
1016} 1035}
1017 1036
1018 1037
1019void PPPData::setDefaultroute(bool set) { 1038void PPPData::setDefaultroute(bool set) {
1020 writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set); 1039 writeConfig(cgroup, DEFAULTROUTE_KEY, (int) set);
1021} 1040}
1022 1041
1023 1042
1024bool PPPData::autoDNS() { 1043bool 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
1030void PPPData::setAutoDNS(bool set) { 1049void PPPData::setAutoDNS(bool set) {
1031 writeConfig(cgroup, AUTODNS_KEY, (int) set); 1050 writeConfig(cgroup, AUTODNS_KEY, (int) set);
1032} 1051}
1033 1052
1034 1053
1035void PPPData::setExDNSDisabled(bool set) { 1054void PPPData::setExDNSDisabled(bool set) {
1036 writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set); 1055 writeConfig(cgroup, EXDNSDISABLED_KEY, (int) set);
1037} 1056}
1038 1057
@@ -1217,36 +1236,41 @@ void PPPData::setpppdError(int err) {
1217} 1236}
1218 1237
1219QString PPPData::modemGroup() 1238QString PPPData::modemGroup()
1220{ 1239{
1221 if (modemDeviceGroup<0)qFatal("wrong modem %i",modemDeviceGroup); 1240 if (modemDeviceGroup<0)qFatal("wrong modem %i",modemDeviceGroup);
1222 return QString("%1_%1").arg(MODEM_GRP).arg(modemDeviceGroup); 1241 return QString("%1_%1").arg(MODEM_GRP).arg(modemDeviceGroup);
1223} 1242}
1224 1243
1225 1244
1226QMap<QString,QString> PPPData::getConfiguredInterfaces() 1245QMap<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
1240void PPPData::setConfiguredInterfaces( QMap<QString,QString> ifaces ) 1263void 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}