author | wimpie <wimpie> | 2004-08-12 12:46:55 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-08-12 12:46:55 (UTC) |
commit | 8f215ba9ceb395f262517855a99d7d2d303ca760 (patch) (side-by-side diff) | |
tree | aa5f9b14c249217b4d3fc30f4771bdaf1c3545d3 /noncore/settings/networksettings2/nsdata.cpp | |
parent | ef64880308b5035cc8ca2e4e79325db613af525b (diff) | |
download | opie-8f215ba9ceb395f262517855a99d7d2d303ca760.zip opie-8f215ba9ceb395f262517855a99d7d2d303ca760.tar.gz opie-8f215ba9ceb395f262517855a99d7d2d303ca760.tar.bz2 |
MANY changes
- now generates peers/pap-chap secrets files
(no chatscript yet)
(not all usefull ppp options included yet)
- still not ready for prime time yet
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 416 |
1 files changed, 218 insertions, 198 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 3b17548..d709c0a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -17,13 +17,12 @@ NetworkSettingsData::NetworkSettingsData( void ) { CfgFile.sprintf( "%s/Settings/NS2.conf", NSResources->currentUser().HomeDir.latin1() ); Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings - Force = 0; IsModified = 0; loadSettings(); } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { @@ -215,172 +214,294 @@ QString NetworkSettingsData::saveSettings( void ) { // setModified( 0 ); return ErrS; } -QString NetworkSettingsData::generateSettings( bool ForceReq ) { - bool ForceIt; +QString NetworkSettingsData::generateSettings( void ) { QString S = ""; - - // include own force flag - ForceIt = (Force) ? 1 : ForceReq; - - if( ! ForceIt && ! isModified() ) - return S; - - // regenerate system files - Log( ( "Generating settings from %s\n", CfgFile.latin1() )); - - { Name2SystemFile_t & SFM = NSResources->systemFiles(); + Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; ANetNodeInstance * NNI; + ANetNodeInstance * FirstWithData; SystemFile * SF; AsDevice * CurDev; - ANetNode * CurDevNN; - bool needToRegenerate = ForceIt; + ANetNode * NN, * CurDevNN = 0; + long NoOfDevs; + long DevCtStart; + bool needToGenerate; - // - // check if we need to generate at least one of the system files - // - if( ! ForceIt ) { - for( QDictIterator<SystemFile> sfit(SFM); - sfit.current(); - ++sfit ) { - SF = sfit.current(); - - // check if there are nodes that are modified and require - // data for this system file - - // for all connections - for( QDictIterator<NodeCollection> ncit(M); - ncit.current(); - ++ncit ) { - NC = ncit.current(); - - if( NC->isModified() ) { - // does this connection 'touch' this system file ? - for( QListIterator<ANetNodeInstance> cncit(*NC); - cncit.current(); - ++cncit ) { - NNI = cncit.current(); - if( ( NNI->nodeClass()->hasDataFor( SF->name() ) || - NNI->hasDataFor( SF->name() ) - ) && - NNI->isModified() ) { - needToRegenerate = 1; - break; - } - } - } - if( needToRegenerate ) - break; - } - if( needToRegenerate ) - break; - } - } + // regenerate system files + Log( ( "Generating settings from %s\n", CfgFile.latin1() )); // // generate files proper to each netnodeinstance // { Name2Instance_t & NNIs = NSResources->netNodeInstances(); for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); NNIIt.current(); - ++NNIIt - ){ + ++NNIIt ) { // for all nodes find those that are modified NNI = NNIIt.current(); - if( ForceIt || NNI->isModified() ) { - if( NNI->nodeClass()->generateProperFilesFor( NNI ) ) { + { // get list of proper files for this nodeclass (if any) + QStringList * PF = NNI->nodeClass()->properFiles(); + + if( PF ) { + for ( QStringList::Iterator it = PF->begin(); + it != PF->end(); + ++it ) { + QFile * F = NNI->openFile( (*it) ); + if( F ) { + QTextStream TS( F ); + if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { // problem generating S = qApp->translate( "NetworkSettings", "<p>Cannot generate files proper to \"%1\"</p>" ). arg(NNI->nodeClass()->name()) ; + delete F; return S; } + delete F; + } + } + } } } } // // generate all system files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SF = sfit.current(); - Log( ( "Generating %s\n", SF->name().latin1() )); - SF->open(); + // reset all + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + nnit.current(); + ++nnit ) { + nnit.current()->NetNode->setDone(0); + } - do { // so we can break; + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + nniit.current(); + ++nniit ) { + nniit.current()->setDone(0); + } - // global presection for this system file - if( SF->preSection() ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in preSection for file \"%1\"</p>" ). - arg( SF->name() ); - return S; + for( QDictIterator<NodeCollection> ncit(M); + ncit.current(); + ++ncit ) { + ncit.current()->setDone(0); } - // find all netnodes and figure out if - // for that node there are instances - for( QDictIterator<NetNode_t> nnit( - NSResources->netNodes() ); - nnit.current(); + Log( ( "Generating %s\n", SF->name().latin1() )); + + needToGenerate = 0; + + // are there netnodes that have instances and need + // to write data in this system file ? + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + ! needToGenerate && nnit.current(); ++nnit ) { - CurDevNN = nnit.current()->NetNode; + NN = nnit.current()->NetNode; + + if( NN->hasDataForFile( SF->name() ) ) { + // netnode can have data - // are there instances for this netnode ? - NNI = 0; + // are there instances of this node ? for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); - nniit.current(); + ! needToGenerate && nniit.current(); ++nniit ) { - if( nniit.current()->nodeClass() == CurDevNN ) { - NNI = nniit.current(); + if( nniit.current()->nodeClass() == NN ) { + // yes + Log(("Node %s has data\n", + nniit.current()->name() )); + needToGenerate = 1; break; } } + } + } - if( ! NNI ) - // no instances -> next netnode type + if( ! needToGenerate ) { + // no instances found that might need to write data + // in this systemfile + Log(("No nodes for systemfile %s\n", SF->name().latin1() )); continue; + } + + // ok generate this system file + SF->open(); - // has this node data for this system file ? - if( (CurDev = NNI->runtime()->asDevice() ) ) { - // generate start for this nodetype for all possible devices of this type - for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) { - S = generateSystemFileNode( *SF, CurDev, NNI, i ); - if( ! S.isEmpty() ) + // global presection for this system file + if( ! SF->preSection() ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). + arg( SF->name() ); return S; } - } else { - S = generateSystemFileNode( *SF, 0, NNI, -1 ); - if( ! S.isEmpty() ) + + // find connections that want to write to this file + for( QDictIterator<NodeCollection> ncit(M); + ncit.current(); + ++ncit ) { + + NC = ncit.current(); + + if( NC->done() ) { + // already done + continue; + } + + if( ! NC->hasDataForFile( SF->name() ) ) { + // no data + continue; + } + + Log(("Generating %s for connection %s\n", + SF->name().latin1(), NC->name().latin1() )); + // find highest item that wants to write data to this file + FirstWithData = NC->firstWithDataForFile( SF->name() ); + + // find device on which this connection works + CurDev = NC->device(); + // class of that node + CurDevNN = CurDev->netNode()->nodeClass(); + + Log(( "%s is done %d\n", + FirstWithData->nodeClass()->name(), + FirstWithData->nodeClass()->done() )); + + if( ! FirstWithData->nodeClass()->done() ) { + // generate fixed part + if( ! SF->preDeviceSection( CurDevNN ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). + arg( SF->name() ); return S; } + + if( FirstWithData->nodeClass()->generateFile( + SF->name(), SF->path(), *SF, -1 ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + FirstWithData->nodeClass()->setDone( 1 ); + } + + NoOfDevs = 0; + DevCtStart = -1; + + if( SF->knowsDeviceInstances() ) { + DevCtStart = 0; + NoOfDevs = CurDevNN->instanceCount(); } - if( SF->postSection() ) { + Log(( "Node %s is done %d\n", + CurDev->netNode()->nodeClass()->name(), + CurDev->netNode()->nodeClass()->done() )); + + if( ! CurDev->netNode()->nodeClass()->done() ) { + // first time this device is handled + // generate common device specific part + for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { + + if( FirstWithData->nodeClass()->generateFile( + SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { S = qApp->translate( "NetworkSettings", - "<p>Error in postSection for file \"%1\"</p>" ). + "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + } + CurDev->netNode()->nodeClass()->setDone( 1 ); + } + + // generate profile specific info + // for all nodeconnections that work on the same device + for( QDictIterator<NodeCollection> ncit2(M); + ncit2.current(); + ++ncit2 ) { + + if( ncit2.current()->device() != CurDev ) { + // different device + continue; + } + + Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); + // generate + NNI = ncit2.current()->firstWithDataForFile( SF->name() ); + for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { + if( ! SF->preNodeSection( NNI, i ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + + switch( NNI->generateFile( + SF->name(), SF->path(), *SF, i ) ) { + case 0 : + (*SF) << endl; + break; + case 1 : + break; + case 2 : + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + + if( ! SF->postNodeSection( NNI, i ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + } + + ncit2.current()->setDone( 1 ); + + } + } + + if( ! SF->postDeviceSection( CurDevNN ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + + + if( ! SF->postSection() ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Closure\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } - } while( 0 ); + // end of file SF->close(); } - } - Force = 0; return S; } QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { // collect connections that can work on top of this interface NodeCollection * NC; @@ -460,114 +581,13 @@ bool NetworkSettingsData::canStart( const char * Interface ) { /* Called by the system to regenerate config files */ bool NetworkSettingsData::regenerate( void ) { - QString S; - // load situation - S = generateSettings( TRUE ); + QString S = generateSettings(); if( ! S.isEmpty() ) { fprintf( stdout, "%s\n", S.latin1() ); return 1; } return 0; } - -QString NetworkSettingsData::generateSystemFileNode( - SystemFile &SF, - AsDevice * CurDev, - ANetNodeInstance * DevNNI, - long DevInstNr ) { - - QString S=""; - ANetNode * CurDevNN = DevNNI->nodeClass(); - Name2Connection_t & M = NSResources->connections(); - - if( SF.preDeviceSection( CurDevNN ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Pre-Device Part\" for file \"%1\" and nodetype \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - - if( CurDevNN->hasDataFor( SF.name() ) ) { - if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Device Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - } - - // now generate profile specific data for all - // connections working on a device of the current - // netnode type - for( QDictIterator<NodeCollection> ncit(M); - ncit.current(); - ++ncit ) { - NodeCollection * NC = ncit.current(); - - // currenly only those connections that work on - // the current device (or on no device if no current) - AsDevice * Dev = NC->device(); - - if( CurDev ) { - if( CurDevNN != Dev->netNode()->nodeClass() ) { - // other device type -> later - continue; - } - } else { - if( Dev ) { - // other - continue; - } - } - - // generate 'entry' - if( SF.preNodeSection( DevNNI, DevInstNr ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - - // ask all nodes in connection - for( QListIterator<ANetNodeInstance> cncit(*NC); - cncit.current(); - ++cncit ) { - ANetNodeInstance * NNI = cncit.current(); - - if( NNI->hasDataFor( SF.name() ) ) { - if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Node Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( NNI->nodeClass()->name() ); - return S; - } - } - } - - if( SF.postNodeSection( DevNNI, DevInstNr ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - SF << endl; - } - - if( SF.postDeviceSection( CurDevNN ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Post-Device Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - - return S; -} |