summaryrefslogtreecommitdiff
authorwimpie <wimpie>2004-08-19 21:48:46 (UTC)
committer wimpie <wimpie>2004-08-19 21:48:46 (UTC)
commit45616f57d3871827a247c1962e7c88699d111002 (patch) (unidiff)
tree7ad9cbe10eb624cb08a7a41944e59f0371547517
parentf58fb0a08321b6d8a9ce1bac2ce4b7eb67c27347 (diff)
downloadopie-45616f57d3871827a247c1962e7c88699d111002.zip
opie-45616f57d3871827a247c1962e7c88699d111002.tar.gz
opie-45616f57d3871827a247c1962e7c88699d111002.tar.bz2
Network_NN.cpp : had to generate full path to networksettings since
ifup (when run from hotplug) does not know about QPEDIR ... main.cpp : a bit more logging nsdata.cpp resources : optimized user detection code, report error when user could not be detected (instead of gracefull crash)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/main.cpp4
-rw-r--r--noncore/settings/networksettings2/network/network_NN.cpp5
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp109
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.h5
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp12
5 files changed, 77 insertions, 58 deletions
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp
index 200e31b..9004d19 100644
--- a/noncore/settings/networksettings2/main.cpp
+++ b/noncore/settings/networksettings2/main.cpp
@@ -74,64 +74,68 @@ int main( int argc, char * argv[] ) {
74 // TheApp anymore ... 74 // TheApp anymore ...
75 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); 75 TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType );
76 } else { 76 } else {
77 TheApp = new QPEApplication( argc, argv, GuiType ); 77 TheApp = new QPEApplication( argc, argv, GuiType );
78 } 78 }
79#else 79#else
80 TheApp = new QApplication( argc, argv, GuiType ); 80 TheApp = new QApplication( argc, argv, GuiType );
81#endif 81#endif
82 82
83 // init qt with app widget 83 // init qt with app widget
84 84
85 switch( Action ) { 85 switch( Action ) {
86 case ACT_REQUEST : 86 case ACT_REQUEST :
87 { NetworkSettingsData NS; 87 { NetworkSettingsData NS;
88 if( NS.canStart( argv[1] ) ) { 88 if( NS.canStart( argv[1] ) ) {
89 QString S; 89 QString S;
90 S.sprintf( QPEApplication::qpeDir()+ 90 S.sprintf( QPEApplication::qpeDir()+
91 "/bin/networksettings2" ); 91 "/bin/networksettings2" );
92 char * MyArgv[4]; 92 char * MyArgv[4];
93 MyArgv[0] = "networksettings2"; 93 MyArgv[0] = "networksettings2";
94 MyArgv[1] = "--prompt"; 94 MyArgv[1] = "--prompt";
95 MyArgv[2] = argv[1]; 95 MyArgv[2] = argv[1];
96 MyArgv[3] = NULL; 96 MyArgv[3] = NULL;
97 NSResources->system().execAsUser( S, MyArgv ); 97 NSResources->system().execAsUser( S, MyArgv );
98 Log(("FAILED %s-cNN-allowed\n", argv[1] ));
98 // if we come here , failed 99 // if we come here , failed
99 printf( "%s-cNN-disallowed", argv[1] ); 100 printf( "%s-cNN-disallowed", argv[1] );
100 } 101 }
101 } 102 }
102 break; 103 break;
103 case ACT_REGEN : 104 case ACT_REGEN :
104 { NetworkSettingsData NS; 105 { NetworkSettingsData NS;
105 // regen returns 0 if OK 106 // regen returns 0 if OK
106 rv = (NS.regenerate()) ? 1 : 0; 107 rv = (NS.regenerate()) ? 1 : 0;
107 } 108 }
108 break; 109 break;
109 case ACT_PROMPT : 110 case ACT_PROMPT :
110 { ActivateProfile AP(argv[1]); 111 { ActivateProfile AP(argv[1]);
111 if( AP.exec() == QDialog::Accepted ) { 112 if( AP.exec() == QDialog::Accepted ) {
113 Log(("%s-c%ld-allowed\n",
114 argv[1], AP.selectedProfile() ));
112 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); 115 printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() );
113 } else { 116 } else {
117 Log(("%s-c%NN-disallowed\n", argv[1] ));
114 printf( "%s-cNN-disallowed", argv[1] ); 118 printf( "%s-cNN-disallowed", argv[1] );
115 } 119 }
116 } 120 }
117 break; 121 break;
118 case ACT_VPN : 122 case ACT_VPN :
119 { ActivateVPN AVPN; 123 { ActivateVPN AVPN;
120 AVPN.exec(); 124 AVPN.exec();
121 } 125 }
122 break; 126 break;
123 case ACT_GUI : 127 case ACT_GUI :
124 { QWidget * W = new NetworkSettings(0); 128 { QWidget * W = new NetworkSettings(0);
125 TheApp->setMainWidget( W ); 129 TheApp->setMainWidget( W );
126 W->show(); 130 W->show();
127#ifdef _WS_QWS_ 131#ifdef _WS_QWS_
128 W->showMaximized(); 132 W->showMaximized();
129#else 133#else
130 W->resize( W->sizeHint() ); 134 W->resize( W->sizeHint() );
131#endif 135#endif
132 rv = TheApp->exec(); 136 rv = TheApp->exec();
133 delete W; 137 delete W;
134 } 138 }
135 break; 139 break;
136 } 140 }
137 141
diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp
index 1feffdb..b5c41bf 100644
--- a/noncore/settings/networksettings2/network/network_NN.cpp
+++ b/noncore/settings/networksettings2/network/network_NN.cpp
@@ -1,24 +1,25 @@
1#include <qpe/qpeapplication.h>
1#include <asdevice.h> 2#include <asdevice.h>
2#include "network_NN.h" 3#include "network_NN.h"
3#include "network_NNI.h" 4#include "network_NNI.h"
4 5
5static const char * NetworkNeeds[] = 6static const char * NetworkNeeds[] =
6 { "device", 7 { "device",
7 0 8 0
8 }; 9 };
9 10
10/** 11/**
11 * Constructor, find all of the possible interfaces 12 * Constructor, find all of the possible interfaces
12 */ 13 */
13NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { 14NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) {
14} 15}
15 16
16/** 17/**
17 * Delete any interfaces that we own. 18 * Delete any interfaces that we own.
18 */ 19 */
19NetworkNetNode::~NetworkNetNode(){ 20NetworkNetNode::~NetworkNetNode(){
20} 21}
21 22
22const QString NetworkNetNode::nodeDescription(){ 23const QString NetworkNetNode::nodeDescription(){
23 return tr("\ 24 return tr("\
24<p>Sets up TCP/IP options.</p>\ 25<p>Sets up TCP/IP options.</p>\
@@ -32,49 +33,51 @@ ANetNodeInstance * NetworkNetNode::createInstance( void ) {
32} 33}
33 34
34bool NetworkNetNode::hasDataForFile( const QString & S ) { 35bool NetworkNetNode::hasDataForFile( const QString & S ) {
35 return S == "interfaces"; 36 return S == "interfaces";
36} 37}
37 38
38short NetworkNetNode::generateFile( const QString & ID, 39short NetworkNetNode::generateFile( const QString & ID,
39 const QString & , 40 const QString & ,
40 QTextStream & TS, 41 QTextStream & TS,
41 ANetNodeInstance * NNI, 42 ANetNodeInstance * NNI,
42 long DevNr ) { 43 long DevNr ) {
43 44
44 QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); 45 QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr );
45 46
46 if( ID == "interfaces" ) { 47 if( ID == "interfaces" ) {
47 Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() )); 48 Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() ));
48 // generate mapping stanza for this interface 49 // generate mapping stanza for this interface
49 TS << "# check if " 50 TS << "# check if "
50 << NIC 51 << NIC
51 << " can be brought UP" 52 << " can be brought UP"
52 << endl; 53 << endl;
53 TS << "mapping " 54 TS << "mapping "
54 << NIC 55 << NIC
55 << endl; 56 << endl;
56 TS << " script networksettings2-request" 57 TS << " script "
58 << QPEApplication::qpeDir()
59 << "/bin/networksettings2-request"
57 << endl 60 << endl
58 << endl; 61 << endl;
59 return 0; 62 return 0;
60 } 63 }
61 return 1; 64 return 1;
62} 65}
63 66
64const char ** NetworkNetNode::needs( void ) { 67const char ** NetworkNetNode::needs( void ) {
65 return NetworkNeeds; 68 return NetworkNeeds;
66} 69}
67 70
68const char * NetworkNetNode::provides( void ) { 71const char * NetworkNetNode::provides( void ) {
69 return "connection"; 72 return "connection";
70} 73}
71 74
72void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { 75void NetworkNetNode::setSpecificAttribute( QString & , QString & ) {
73} 76}
74 77
75void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { 78void NetworkNetNode::saveSpecificAttribute( QTextStream & ) {
76} 79}
77 80
78extern "C" { 81extern "C" {
79void create_plugin( QList<ANetNode> & PNN ) { 82void create_plugin( QList<ANetNode> & PNN ) {
80 PNN.append( new NetworkNetNode() ); 83 PNN.append( new NetworkNetNode() );
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 7ece817..2f17693 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -273,63 +273,66 @@ NodeCollection * TheNSResources::findConnection( const QString & S ) {
273void TheNSResources::renumberConnections( void ) { 273void TheNSResources::renumberConnections( void ) {
274 Name2Connection_t & M = NSResources->connections(); 274 Name2Connection_t & M = NSResources->connections();
275 NodeCollection * NC; 275 NodeCollection * NC;
276 276
277 // for all connections 277 // for all connections
278 NodeCollection::resetMaxNr(); 278 NodeCollection::resetMaxNr();
279 for( QDictIterator<NodeCollection> it(M); 279 for( QDictIterator<NodeCollection> it(M);
280 it.current(); 280 it.current();
281 ++it ) { 281 ++it ) {
282 NC = it.current(); 282 NC = it.current();
283 NC->setNumber( NC->maxConnectionNumber()+1 ); 283 NC->setNumber( NC->maxConnectionNumber()+1 );
284 NC->setModified( 1 ); 284 NC->setModified( 1 );
285 } 285 }
286} 286}
287*/ 287*/
288 288
289typedef struct EnvVars { 289typedef struct EnvVars {
290 char * Name; 290 char * Name;
291 int Len; 291 int Len;
292} EnvVar_t; 292} EnvVar_t;
293 293
294#define AnEV(x) x, sizeof(x)-1 294#define AnEV(x) x, sizeof(x)-1
295 295
296static EnvVar_t EV[] = { 296static EnvVar_t EV[] = {
297 // AnEV( "HOME=" ), -> SPECIAL 297 AnEV( "HOME" ),
298 // AnEV( "LOGNAME=" ), -> SPECIAL 298 AnEV( "LOGNAME" ),
299 AnEV( "USER=" ), 299 AnEV( "USER" ),
300 AnEV( "LD_LIBRARY_PATH=" ), 300 AnEV( "LD_LIBRARY_PATH" ),
301 AnEV( "PATH=" ), 301 AnEV( "PATH" ),
302 AnEV( "QTDIR=" ), 302 AnEV( "QTDIR" ),
303 AnEV( "OPIEDIR=" ), 303 AnEV( "OPIEDIR" ),
304 AnEV( "SHELL=" ), 304 AnEV( "SHELL" ),
305 { NULL, 0 } 305 { NULL, 0 }
306}; 306};
307 307
308void TheNSResources::detectCurrentUser( void ) { 308void TheNSResources::detectCurrentUser( void ) {
309 // find current running qpe 309 // find current running qpe
310 QString QPEEnvFile = ""; 310 QString QPEEnvFile = "";
311 311
312 CurrentUser.UserName = "";
313 CurrentUser.HomeDir = "";
314
312 if( getenv( "OPIEDIR" ) == 0 ) { 315 if( getenv( "OPIEDIR" ) == 0 ) {
313 // nothing known 316 // nothing known
314 { // open proc dir and find all dirs in it 317 { // open proc dir and find all dirs in it
315 QRegExp R("[0-9]+"); 318 QRegExp R("[0-9]+");
316 QDir ProcDir( "/proc" ); 319 QDir ProcDir( "/proc" );
317 QFileInfo FI; 320 QFileInfo FI;
318 QStringList EL = ProcDir.entryList( QDir::Dirs ); 321 QStringList EL = ProcDir.entryList( QDir::Dirs );
319 322
320 // print it out 323 // print it out
321 for ( QStringList::Iterator it = EL.begin(); 324 for ( QStringList::Iterator it = EL.begin();
322 it != EL.end(); 325 it != EL.end();
323 ++it ) { 326 ++it ) {
324 if( R.match( (*it) ) >= 0 ) { 327 if( R.match( (*it) ) >= 0 ) {
325 QString S = ProcDir.path()+"/"+ (*it); 328 QString S = ProcDir.path()+"/"+ (*it);
326 S.append( "/exe" ); 329 S.append( "/exe" );
327 FI.setFile( S ); 330 FI.setFile( S );
328 // get the link 331 // get the link
329 S = FI.readLink(); 332 S = FI.readLink();
330 if( S.right( 8 ) == "/bin/qpe" ) { 333 if( S.right( 8 ) == "/bin/qpe" ) {
331 // found running qpe 334 // found running qpe
332 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); 335 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" );
333 break; 336 break;
334 } 337 }
335 } 338 }
@@ -346,108 +349,102 @@ void TheNSResources::detectCurrentUser( void ) {
346 { char * Buf = 0; 349 { char * Buf = 0;
347 char TB[1024]; 350 char TB[1024];
348 long BufSize = 0; 351 long BufSize = 0;
349 int fd; 352 int fd;
350 int rd; 353 int rd;
351 354
352 fd = open( QPEEnvFile.latin1(), O_RDONLY ); 355 fd = open( QPEEnvFile.latin1(), O_RDONLY );
353 if( fd < 0 ) { 356 if( fd < 0 ) {
354 Log(("Could not open %s : %d\n", 357 Log(("Could not open %s : %d\n",
355 QPEEnvFile.latin1(), errno )); 358 QPEEnvFile.latin1(), errno ));
356 return; 359 return;
357 } 360 }
358 361
359 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { 362 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) {
360 Buf = (char *)realloc( Buf, BufSize+rd ); 363 Buf = (char *)realloc( Buf, BufSize+rd );
361 memcpy( Buf+BufSize, TB, rd ); 364 memcpy( Buf+BufSize, TB, rd );
362 BufSize += rd; 365 BufSize += rd;
363 } 366 }
364 367
365 char * Data = Buf; 368 char * Data = Buf;
366 char * DataEnd = Data+BufSize-1; 369 char * DataEnd = Data+BufSize-1;
367 370
368 // get env items out of list 371 // get env items out of list
369 while( Data < DataEnd ) { 372 while( Data < DataEnd ) {
370 if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) {
371 CurrentUser.UserName = Data+8;
372 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
373 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
374 strdup( Data );
375 } else if( strncmp( Data, "HOME=", 5 ) == 0 ) {
376 CurrentUser.HomeDir = Data+5;
377 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
378 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
379 strdup( Data );
380 } else {
381 EnvVar_t * Run = EV;
382 while( Run->Name ) {
383 if( strncmp( Data, Run->Name, Run->Len ) == 0 ) {
384 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
385 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
386 strdup( Data );
387 // put OPIEDIR in env
388 if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) {
389 putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] );
390 373
391 } 374 EnvVar_t * Run = EV;
392 break; 375 while( Run->Name ) {
376 if( strncmp( Data, Run->Name, Run->Len ) == 0 &&
377 Data[Run->Len] == '='
378 ) {
379 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
380 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
381 strdup( Data );
382
383 if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) {
384 // put OPIEDIR in env
385 putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] );
386 } else if( strcmp( Run->Name, "HOME" ) == 0 ) {
387 CurrentUser.HomeDir = Data+5;
388 } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) {
389 CurrentUser.UserName = Data+8;
393 } 390 }
394 Run ++; 391 break;
395 } 392 }
393 Run ++;
396 } 394 }
397 395
398 Data += strlen( Data )+1; 396 Data += strlen( Data )+1;
399 } 397 }
400 398
401 free( Buf ); 399 free( Buf );
402 400
403 if( ! CurrentUser.UserName.isEmpty() ) { 401 if( ! CurrentUser.UserName.isEmpty() ) {
404 // find user info 402 // find user info
405 struct passwd pwd; 403 struct passwd pwd;
406 struct passwd * pwdres; 404 struct passwd * pwdres;
407 405
408 if( getpwnam_r( CurrentUser.UserName.latin1(), 406 if( getpwnam_r( CurrentUser.UserName.latin1(),
409 &pwd, TB, sizeof(TB), &pwdres ) || 407 &pwd, TB, sizeof(TB), &pwdres ) ||
410 pwdres == 0 ) { 408 pwdres == 0 ) {
411 Log(("Could not determine user %s : %d\n", 409 Log(("Could not determine user %s : %d\n",
412 CurrentUser.UserName.latin1(), errno )); 410 CurrentUser.UserName.latin1(), errno ));
413 return; 411 return;
414 } 412 }
415 CurrentUser.Uid = pwd.pw_uid; 413 CurrentUser.Uid = pwd.pw_uid;
416 CurrentUser.Gid = pwd.pw_gid; 414 CurrentUser.Gid = pwd.pw_gid;
417 } else{ 415 } else{
418 CurrentUser.Uid = 416 CurrentUser.Uid =
419 CurrentUser.Gid = -1; 417 CurrentUser.Gid = -1;
420 } 418 }
421 } 419 }
422 420
423 } else { 421 } else {
424 CurrentUser.UserName = getenv( "LOGNAME" ); 422 char * X;
425 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 423 QString S;
426 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 424
427 strdup( CurrentUser.UserName ); 425 EnvVar_t * Run = EV;
428 426 while( Run->Name ) {
429 CurrentUser.HomeDir = getenv( "HOME" ); 427
430 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 428 if( ( X = getenv( Run->Name ) ) ) {
431 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 429 Log(( "Env : %s = %s\n", Run->Name, X ));
432 strdup( CurrentUser.HomeDir ); 430
433 431 S.sprintf( "%s=%s", Run->Name, X );
434 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 432 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
435 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER"); 433 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
436 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 434 strdup( S.latin1() );
437 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH"); 435
438 436 if( strcmp( Run->Name, "LOGNAME" ) == 0 ) {
439 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 437 CurrentUser.UserName = X;
440 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH"); 438 } else if( strcmp( Run->Name, "HOME" ) == 0 ) {
441 439 CurrentUser.HomeDir = X;
442 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 440 } // regulare env var
443 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR"); 441 } else {
444 442 Log(("Could not determine %s\n", Run->Name ));
445 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 443 }
446 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR"); 444 Run ++;
447 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 445 }
448 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL");
449 446
450 CurrentUser.Uid = getuid(); 447 CurrentUser.Uid = getuid();
451 CurrentUser.Gid = getgid(); 448 CurrentUser.Gid = getgid();
452 } 449 }
453} 450}
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h
index 16355ba..23b120e 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.h
+++ b/noncore/settings/networksettings2/networksettings2/resources.h
@@ -6,48 +6,51 @@
6#include <qmap.h> 6#include <qmap.h>
7#include <qlist.h> 7#include <qlist.h>
8#include "netnode.h" 8#include "netnode.h"
9#include "systemfile.h" 9#include "systemfile.h"
10#include "system.h" 10#include "system.h"
11 11
12class QLibrary; 12class QLibrary;
13class QPixmap; 13class QPixmap;
14class ANetNode; 14class ANetNode;
15class ANetNodeInstance; 15class ANetNodeInstance;
16 16
17typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); 17typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN );
18 18
19typedef struct NetNode_S { 19typedef struct NetNode_S {
20 ANetNode * NetNode; 20 ANetNode * NetNode;
21 QLibrary * TheLibrary; 21 QLibrary * TheLibrary;
22 long NodeCountInLib; 22 long NodeCountInLib;
23} NetNode_t; 23} NetNode_t;
24 24
25class CurrentQPEUser { 25class CurrentQPEUser {
26 26
27public : 27public :
28 CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} 28 CurrentQPEUser() : UserName(), HomeDir(), EnvList() {}
29 29
30 inline bool known( void )
31 { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); }
32
30 QString UserName; 33 QString UserName;
31 QString HomeDir; 34 QString HomeDir;
32 int Uid; 35 int Uid;
33 int Gid; 36 int Gid;
34 QArray<char *> EnvList; 37 QArray<char *> EnvList;
35}; 38};
36 39
37typedef QDict<NetNode_t> Name2NetNode_t; 40typedef QDict<NetNode_t> Name2NetNode_t;
38typedef QDict<ANetNodeInstance > Name2Instance_t; 41typedef QDict<ANetNodeInstance > Name2Instance_t;
39typedef QDict<NodeCollection> Name2Connection_t; 42typedef QDict<NodeCollection> Name2Connection_t;
40typedef QDict<SystemFile> Name2SystemFile_t; 43typedef QDict<SystemFile> Name2SystemFile_t;
41 44
42class TheNSResources { 45class TheNSResources {
43 46
44public : 47public :
45 48
46 TheNSResources( void ); 49 TheNSResources( void );
47 ~TheNSResources( ); 50 ~TheNSResources( );
48 51
49 // give busy feedback 52 // give busy feedback
50 void busy( bool B ); 53 void busy( bool B );
51 54
52 System & system() 55 System & system()
53 { return *TheSystem; } 56 { return *TheSystem; }
@@ -78,48 +81,50 @@ public :
78 } 81 }
79 NNI = NNT->NetNode->createInstance(); 82 NNI = NNT->NetNode->createInstance();
80 NNI->initialize(); 83 NNI->initialize();
81 return NNI; 84 return NNI;
82 } 85 }
83 86
84 Name2Instance_t & netNodeInstances( void ) 87 Name2Instance_t & netNodeInstances( void )
85 { return AllNodes; } 88 { return AllNodes; }
86 void addNodeInstance( ANetNodeInstance * I ) 89 void addNodeInstance( ANetNodeInstance * I )
87 { AllNodes.insert( I->name(), I ); } 90 { AllNodes.insert( I->name(), I ); }
88 void removeNodeInstance( const QString & N ) 91 void removeNodeInstance( const QString & N )
89 { AllNodes.remove( N );} 92 { AllNodes.remove( N );}
90 ANetNodeInstance * findNodeInstance( const QString & S ) 93 ANetNodeInstance * findNodeInstance( const QString & S )
91 { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } 94 { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; }
92 95
93 const QString & netNode2Name( const char * Type ); 96 const QString & netNode2Name( const char * Type );
94 const QString & netNode2Description( const char * Type ); 97 const QString & netNode2Description( const char * Type );
95 98
96 void addConnection( NodeCollection * NC ); 99 void addConnection( NodeCollection * NC );
97 void removeConnection( const QString & N ); 100 void removeConnection( const QString & N );
98 NodeCollection * findConnection( const QString & N ); 101 NodeCollection * findConnection( const QString & N );
99 Name2Connection_t & connections( void ) 102 Name2Connection_t & connections( void )
100 { return ConnectionsMap; } 103 { return ConnectionsMap; }
101 104
105 inline bool userKnown( void )
106 { return CurrentUser.known(); }
102 CurrentQPEUser & currentUser( void ) 107 CurrentQPEUser & currentUser( void )
103 { return CurrentUser; } 108 { return CurrentUser; }
104 109
105private : 110private :
106 111
107 void detectCurrentUser( void ); 112 void detectCurrentUser( void );
108 QString tr( const char * path ); 113 QString tr( const char * path );
109 void findAvailableNetNodes( const QString &path ); 114 void findAvailableNetNodes( const QString &path );
110 bool loadNetNode( 115 bool loadNetNode(
111 const QString &pluginFileName, 116 const QString &pluginFileName,
112 const QString &resolveString = "create_plugin"); 117 const QString &resolveString = "create_plugin");
113 118
114 QMap< QString, QString> NodeTypeNameMap; 119 QMap< QString, QString> NodeTypeNameMap;
115 QMap< QString, QString> NodeTypeDescriptionMap; 120 QMap< QString, QString> NodeTypeDescriptionMap;
116 Name2Connection_t ConnectionsMap; 121 Name2Connection_t ConnectionsMap;
117 System * TheSystem; 122 System * TheSystem;
118 Name2SystemFile_t SystemFiles; 123 Name2SystemFile_t SystemFiles;
119 124
120 // all node type classes 125 // all node type classes
121 Name2NetNode_t AllNodeTypes; 126 Name2NetNode_t AllNodeTypes;
122 127
123 // all nodes 128 // all nodes
124 Name2Instance_t AllNodes; 129 Name2Instance_t AllNodes;
125 130
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index d709c0a..e2dd5b5 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -1,41 +1,48 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfile.h> 5#include <qfile.h>
6#include <qfileinfo.h> 6#include <qfileinfo.h>
7 7
8#include "nsdata.h" 8#include "nsdata.h"
9#include <asdevice.h> 9#include <asdevice.h>
10#include <resources.h> 10#include <resources.h>
11 11
12static QString CfgFile; 12static QString CfgFile;
13 13
14NetworkSettingsData::NetworkSettingsData( void ) { 14NetworkSettingsData::NetworkSettingsData( void ) {
15 // init global resources structure 15 // init global resources structure
16 new TheNSResources(); 16 new TheNSResources();
17 17
18 if( ! NSResources->userKnown() ) {
19 Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n",
20 NSResources->currentUser().HomeDir.latin1(),
21 NSResources->currentUser().UserName.latin1() ));
22 return;
23 }
24
18 CfgFile.sprintf( "%s/Settings/NS2.conf", 25 CfgFile.sprintf( "%s/Settings/NS2.conf",
19 NSResources->currentUser().HomeDir.latin1() ); 26 NSResources->currentUser().HomeDir.latin1() );
20 Log(( "Cfg from %s\n", CfgFile.latin1() )); 27 Log(( "Cfg from %s\n", CfgFile.latin1() ));
21 28
22 // load settings 29 // load settings
23 IsModified = 0; 30 IsModified = 0;
24 loadSettings(); 31 loadSettings();
25} 32}
26 33
27// saving is done by caller 34// saving is done by caller
28NetworkSettingsData::~NetworkSettingsData( void ) { 35NetworkSettingsData::~NetworkSettingsData( void ) {
29 delete NSResources; 36 delete NSResources;
30} 37}
31 38
32void NetworkSettingsData::loadSettings( void ) { 39void NetworkSettingsData::loadSettings( void ) {
33 QString Line, S; 40 QString Line, S;
34 QString Attr, Value; 41 QString Attr, Value;
35 long idx; 42 long idx;
36 43
37 QFile F( CfgFile ); 44 QFile F( CfgFile );
38 QTextStream TS( &F ); 45 QTextStream TS( &F );
39 46
40 do { 47 do {
41 48
@@ -518,76 +525,79 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa
518 NC->state() != Disabled && // if not enabled 525 NC->state() != Disabled && // if not enabled
519 NC->state() != IsUp // if already used 526 NC->state() != IsUp // if already used
520 ) { 527 ) {
521 Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); 528 Log( ( "Append %s for %s\n", NC->name().latin1(), Interface));
522 PossibleConnections.append( NC ); 529 PossibleConnections.append( NC );
523 } 530 }
524 } 531 }
525 return PossibleConnections; 532 return PossibleConnections;
526} 533}
527 534
528 535
529/* 536/*
530 Called by the system to see if interface can be brought UP 537 Called by the system to see if interface can be brought UP
531 538
532 if allowed, echo Interface-allowed else Interface-disallowed 539 if allowed, echo Interface-allowed else Interface-disallowed
533*/ 540*/
534 541
535bool NetworkSettingsData::canStart( const char * Interface ) { 542bool NetworkSettingsData::canStart( const char * Interface ) {
536 // load situation 543 // load situation
537 NodeCollection * NC = 0; 544 NodeCollection * NC = 0;
538 QList<NodeCollection> PossibleConnections; 545 QList<NodeCollection> PossibleConnections;
539 546
540 PossibleConnections = collectPossible( Interface ); 547 PossibleConnections = collectPossible( Interface );
541 548
542 Log( ( "Possiblilies %d\n", PossibleConnections.count() )); 549 Log( ( "for %s : Possiblilies %d\n",
550 Interface, PossibleConnections.count() ));
543 switch( PossibleConnections.count() ) { 551 switch( PossibleConnections.count() ) {
544 case 0 : // no connections 552 case 0 : // no connections
545 break; 553 break;
546 case 1 : // one connection 554 case 1 : // one connection
547 NC = PossibleConnections.first(); 555 NC = PossibleConnections.first();
548 break; 556 break;
549 default : // need to ask user ? 557 default : // need to ask user ?
550 return 1; 558 return 1;
551 } 559 }
552 560
553 if( NC ) { 561 if( NC ) {
554 switch( NC->state() ) { 562 switch( NC->state() ) {
555 case Unchecked : 563 case Unchecked :
556 case Unknown : 564 case Unknown :
557 case Unavailable : 565 case Unavailable :
558 case Disabled : 566 case Disabled :
559 // this profile does not allow interface to be UP 567 // this profile does not allow interface to be UP
560 // -> try others 568 // -> try others
561 break; 569 break;
562 case Off : 570 case Off :
563 // try to UP the device 571 // try to UP the device
564 if( ! NC->setState( Activate ) ) { 572 if( ! NC->setState( Activate ) ) {
565 // cannot bring device Online -> try other alters 573 // cannot bring device Online -> try other alters
566 break; 574 break;
567 } 575 }
568 // FT 576 // FT
569 case Available : 577 case Available :
570 case IsUp : // also called for 'ifdown' 578 case IsUp : // also called for 'ifdown'
571 // device is ready -> done 579 // device is ready -> done
580 Log(( "%s-c%d-allowed\n", Interface, NC->number() ));
572 printf( "%s-c%d-allowed\n", Interface, NC->number() ); 581 printf( "%s-c%d-allowed\n", Interface, NC->number() );
573 return 0; 582 return 0;
574 } 583 }
575 } 584 }
576 585
577 // if we come here no alternatives are possible 586 // if we come here no alternatives are possible
587 Log(( "%s-cnn-disallowed\n", Interface ));
578 printf( "%s-cnn-disallowed\n", Interface ); 588 printf( "%s-cnn-disallowed\n", Interface );
579 return 0; 589 return 0;
580} 590}
581 591
582/* 592/*
583 Called by the system to regenerate config files 593 Called by the system to regenerate config files
584*/ 594*/
585 595
586bool NetworkSettingsData::regenerate( void ) { 596bool NetworkSettingsData::regenerate( void ) {
587 QString S = generateSettings(); 597 QString S = generateSettings();
588 if( ! S.isEmpty() ) { 598 if( ! S.isEmpty() ) {
589 fprintf( stdout, "%s\n", S.latin1() ); 599 fprintf( stdout, "%s\n", S.latin1() );
590 return 1; 600 return 1;
591 } 601 }
592 return 0; 602 return 0;
593} 603}