author | wimpie <wimpie> | 2004-08-12 12:46:55 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-08-12 12:46:55 (UTC) |
commit | 8f215ba9ceb395f262517855a99d7d2d303ca760 (patch) (unidiff) | |
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 | |||
@@ -20,7 +20,6 @@ NetworkSettingsData::NetworkSettingsData( void ) { | |||
20 | Log(( "Cfg from %s\n", CfgFile.latin1() )); | 20 | Log(( "Cfg from %s\n", CfgFile.latin1() )); |
21 | 21 | ||
22 | // load settings | 22 | // load settings |
23 | Force = 0; | ||
24 | IsModified = 0; | 23 | IsModified = 0; |
25 | loadSettings(); | 24 | loadSettings(); |
26 | } | 25 | } |
@@ -218,68 +217,22 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
218 | return ErrS; | 217 | return ErrS; |
219 | } | 218 | } |
220 | 219 | ||
221 | QString NetworkSettingsData::generateSettings( bool ForceReq ) { | 220 | QString NetworkSettingsData::generateSettings( void ) { |
222 | bool ForceIt; | ||
223 | QString S = ""; | 221 | QString S = ""; |
224 | 222 | Name2SystemFile_t & SFM = NSResources->systemFiles(); | |
225 | // include own force flag | ||
226 | ForceIt = (Force) ? 1 : ForceReq; | ||
227 | |||
228 | if( ! ForceIt && ! isModified() ) | ||
229 | return S; | ||
230 | |||
231 | // regenerate system files | ||
232 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | ||
233 | |||
234 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); | ||
235 | Name2Connection_t & M = NSResources->connections(); | 223 | Name2Connection_t & M = NSResources->connections(); |
236 | NodeCollection * NC; | 224 | NodeCollection * NC; |
237 | ANetNodeInstance * NNI; | 225 | ANetNodeInstance * NNI; |
226 | ANetNodeInstance * FirstWithData; | ||
238 | SystemFile * SF; | 227 | SystemFile * SF; |
239 | AsDevice * CurDev; | 228 | AsDevice * CurDev; |
240 | ANetNode * CurDevNN; | 229 | ANetNode * NN, * CurDevNN = 0; |
241 | bool needToRegenerate = ForceIt; | 230 | long NoOfDevs; |
231 | long DevCtStart; | ||
232 | bool needToGenerate; | ||
242 | 233 | ||
243 | // | 234 | // regenerate system files |
244 | // check if we need to generate at least one of the system files | 235 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
245 | // | ||
246 | if( ! ForceIt ) { | ||
247 | for( QDictIterator<SystemFile> sfit(SFM); | ||
248 | sfit.current(); | ||
249 | ++sfit ) { | ||
250 | SF = sfit.current(); | ||
251 | |||
252 | // check if there are nodes that are modified and require | ||
253 | // data for this system file | ||
254 | |||
255 | // for all connections | ||
256 | for( QDictIterator<NodeCollection> ncit(M); | ||
257 | ncit.current(); | ||
258 | ++ncit ) { | ||
259 | NC = ncit.current(); | ||
260 | |||
261 | if( NC->isModified() ) { | ||
262 | // does this connection 'touch' this system file ? | ||
263 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
264 | cncit.current(); | ||
265 | ++cncit ) { | ||
266 | NNI = cncit.current(); | ||
267 | if( ( NNI->nodeClass()->hasDataFor( SF->name() ) || | ||
268 | NNI->hasDataFor( SF->name() ) | ||
269 | ) && | ||
270 | NNI->isModified() ) { | ||
271 | needToRegenerate = 1; | ||
272 | break; | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | if( needToRegenerate ) | ||
277 | break; | ||
278 | } | ||
279 | if( needToRegenerate ) | ||
280 | break; | ||
281 | } | ||
282 | } | ||
283 | 236 | ||
284 | // | 237 | // |
285 | // generate files proper to each netnodeinstance | 238 | // generate files proper to each netnodeinstance |
@@ -288,19 +241,32 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
288 | 241 | ||
289 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | 242 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); |
290 | NNIIt.current(); | 243 | NNIIt.current(); |
291 | ++NNIIt | 244 | ++NNIIt ) { |
292 | ){ | ||
293 | // for all nodes find those that are modified | 245 | // for all nodes find those that are modified |
294 | NNI = NNIIt.current(); | 246 | NNI = NNIIt.current(); |
295 | 247 | ||
296 | if( ForceIt || NNI->isModified() ) { | 248 | { // get list of proper files for this nodeclass (if any) |
297 | if( NNI->nodeClass()->generateProperFilesFor( NNI ) ) { | 249 | QStringList * PF = NNI->nodeClass()->properFiles(); |
250 | |||
251 | if( PF ) { | ||
252 | for ( QStringList::Iterator it = PF->begin(); | ||
253 | it != PF->end(); | ||
254 | ++it ) { | ||
255 | QFile * F = NNI->openFile( (*it) ); | ||
256 | if( F ) { | ||
257 | QTextStream TS( F ); | ||
258 | if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { | ||
298 | // problem generating | 259 | // problem generating |
299 | S = qApp->translate( "NetworkSettings", | 260 | S = qApp->translate( "NetworkSettings", |
300 | "<p>Cannot generate files proper to \"%1\"</p>" ). | 261 | "<p>Cannot generate files proper to \"%1\"</p>" ). |
301 | arg(NNI->nodeClass()->name()) ; | 262 | arg(NNI->nodeClass()->name()) ; |
263 | delete F; | ||
302 | return S; | 264 | return S; |
303 | } | 265 | } |
266 | delete F; | ||
267 | } | ||
268 | } | ||
269 | } | ||
304 | } | 270 | } |
305 | } | 271 | } |
306 | } | 272 | } |
@@ -313,71 +279,226 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
313 | ++sfit ) { | 279 | ++sfit ) { |
314 | SF = sfit.current(); | 280 | SF = sfit.current(); |
315 | 281 | ||
316 | Log( ( "Generating %s\n", SF->name().latin1() )); | 282 | // reset all |
317 | SF->open(); | 283 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); |
284 | nnit.current(); | ||
285 | ++nnit ) { | ||
286 | nnit.current()->NetNode->setDone(0); | ||
287 | } | ||
318 | 288 | ||
319 | do { // so we can break; | 289 | for( QDictIterator<ANetNodeInstance> nniit( |
290 | NSResources->netNodeInstances() ); | ||
291 | nniit.current(); | ||
292 | ++nniit ) { | ||
293 | nniit.current()->setDone(0); | ||
294 | } | ||
320 | 295 | ||
321 | // global presection for this system file | 296 | for( QDictIterator<NodeCollection> ncit(M); |
322 | if( SF->preSection() ) { | 297 | ncit.current(); |
323 | S = qApp->translate( "NetworkSettings", | 298 | ++ncit ) { |
324 | "<p>Error in preSection for file \"%1\"</p>" ). | 299 | ncit.current()->setDone(0); |
325 | arg( SF->name() ); | ||
326 | return S; | ||
327 | } | 300 | } |
328 | 301 | ||
329 | // find all netnodes and figure out if | 302 | Log( ( "Generating %s\n", SF->name().latin1() )); |
330 | // for that node there are instances | 303 | |
331 | for( QDictIterator<NetNode_t> nnit( | 304 | needToGenerate = 0; |
332 | NSResources->netNodes() ); | 305 | |
333 | nnit.current(); | 306 | // are there netnodes that have instances and need |
307 | // to write data in this system file ? | ||
308 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | ||
309 | ! needToGenerate && nnit.current(); | ||
334 | ++nnit ) { | 310 | ++nnit ) { |
335 | 311 | ||
336 | CurDevNN = nnit.current()->NetNode; | 312 | NN = nnit.current()->NetNode; |
313 | |||
314 | if( NN->hasDataForFile( SF->name() ) ) { | ||
315 | // netnode can have data | ||
337 | 316 | ||
338 | // are there instances for this netnode ? | 317 | // are there instances of this node ? |
339 | NNI = 0; | ||
340 | for( QDictIterator<ANetNodeInstance> nniit( | 318 | for( QDictIterator<ANetNodeInstance> nniit( |
341 | NSResources->netNodeInstances() ); | 319 | NSResources->netNodeInstances() ); |
342 | nniit.current(); | 320 | ! needToGenerate && nniit.current(); |
343 | ++nniit ) { | 321 | ++nniit ) { |
344 | if( nniit.current()->nodeClass() == CurDevNN ) { | 322 | if( nniit.current()->nodeClass() == NN ) { |
345 | NNI = nniit.current(); | 323 | // yes |
324 | Log(("Node %s has data\n", | ||
325 | nniit.current()->name() )); | ||
326 | needToGenerate = 1; | ||
346 | break; | 327 | break; |
347 | } | 328 | } |
348 | } | 329 | } |
330 | } | ||
331 | } | ||
349 | 332 | ||
350 | if( ! NNI ) | 333 | if( ! needToGenerate ) { |
351 | // no instances -> next netnode type | 334 | // no instances found that might need to write data |
335 | // in this systemfile | ||
336 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); | ||
352 | continue; | 337 | continue; |
338 | } | ||
339 | |||
340 | // ok generate this system file | ||
341 | SF->open(); | ||
353 | 342 | ||
354 | // has this node data for this system file ? | 343 | // global presection for this system file |
355 | if( (CurDev = NNI->runtime()->asDevice() ) ) { | 344 | if( ! SF->preSection() ) { |
356 | // generate start for this nodetype for all possible devices of this type | 345 | S = qApp->translate( "NetworkSettings", |
357 | for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) { | 346 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). |
358 | S = generateSystemFileNode( *SF, CurDev, NNI, i ); | 347 | arg( SF->name() ); |
359 | if( ! S.isEmpty() ) | ||
360 | return S; | 348 | return S; |
361 | } | 349 | } |
362 | } else { | 350 | |
363 | S = generateSystemFileNode( *SF, 0, NNI, -1 ); | 351 | // find connections that want to write to this file |
364 | if( ! S.isEmpty() ) | 352 | for( QDictIterator<NodeCollection> ncit(M); |
353 | ncit.current(); | ||
354 | ++ncit ) { | ||
355 | |||
356 | NC = ncit.current(); | ||
357 | |||
358 | if( NC->done() ) { | ||
359 | // already done | ||
360 | continue; | ||
361 | } | ||
362 | |||
363 | if( ! NC->hasDataForFile( SF->name() ) ) { | ||
364 | // no data | ||
365 | continue; | ||
366 | } | ||
367 | |||
368 | Log(("Generating %s for connection %s\n", | ||
369 | SF->name().latin1(), NC->name().latin1() )); | ||
370 | // find highest item that wants to write data to this file | ||
371 | FirstWithData = NC->firstWithDataForFile( SF->name() ); | ||
372 | |||
373 | // find device on which this connection works | ||
374 | CurDev = NC->device(); | ||
375 | // class of that node | ||
376 | CurDevNN = CurDev->netNode()->nodeClass(); | ||
377 | |||
378 | Log(( "%s is done %d\n", | ||
379 | FirstWithData->nodeClass()->name(), | ||
380 | FirstWithData->nodeClass()->done() )); | ||
381 | |||
382 | if( ! FirstWithData->nodeClass()->done() ) { | ||
383 | // generate fixed part | ||
384 | if( ! SF->preDeviceSection( CurDevNN ) ) { | ||
385 | S = qApp->translate( "NetworkSettings", | ||
386 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). | ||
387 | arg( SF->name() ); | ||
365 | return S; | 388 | return S; |
366 | } | 389 | } |
390 | |||
391 | if( FirstWithData->nodeClass()->generateFile( | ||
392 | SF->name(), SF->path(), *SF, -1 ) == 2 ) { | ||
393 | S = qApp->translate( "NetworkSettings", | ||
394 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). | ||
395 | arg( SF->name() ). | ||
396 | arg( CurDevNN->name() ); | ||
397 | return S; | ||
398 | } | ||
399 | FirstWithData->nodeClass()->setDone( 1 ); | ||
400 | } | ||
401 | |||
402 | NoOfDevs = 0; | ||
403 | DevCtStart = -1; | ||
404 | |||
405 | if( SF->knowsDeviceInstances() ) { | ||
406 | DevCtStart = 0; | ||
407 | NoOfDevs = CurDevNN->instanceCount(); | ||
367 | } | 408 | } |
368 | 409 | ||
369 | if( SF->postSection() ) { | 410 | Log(( "Node %s is done %d\n", |
411 | CurDev->netNode()->nodeClass()->name(), | ||
412 | CurDev->netNode()->nodeClass()->done() )); | ||
413 | |||
414 | if( ! CurDev->netNode()->nodeClass()->done() ) { | ||
415 | // first time this device is handled | ||
416 | // generate common device specific part | ||
417 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | ||
418 | |||
419 | if( FirstWithData->nodeClass()->generateFile( | ||
420 | SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { | ||
370 | S = qApp->translate( "NetworkSettings", | 421 | S = qApp->translate( "NetworkSettings", |
371 | "<p>Error in postSection for file \"%1\"</p>" ). | 422 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). |
423 | arg( SF->name() ). | ||
424 | arg( CurDevNN->name() ); | ||
425 | return S; | ||
426 | } | ||
427 | } | ||
428 | CurDev->netNode()->nodeClass()->setDone( 1 ); | ||
429 | } | ||
430 | |||
431 | // generate profile specific info | ||
432 | // for all nodeconnections that work on the same device | ||
433 | for( QDictIterator<NodeCollection> ncit2(M); | ||
434 | ncit2.current(); | ||
435 | ++ncit2 ) { | ||
436 | |||
437 | if( ncit2.current()->device() != CurDev ) { | ||
438 | // different device | ||
439 | continue; | ||
440 | } | ||
441 | |||
442 | Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); | ||
443 | // generate | ||
444 | NNI = ncit2.current()->firstWithDataForFile( SF->name() ); | ||
445 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | ||
446 | if( ! SF->preNodeSection( NNI, i ) ) { | ||
447 | S = qApp->translate( "NetworkSettings", | ||
448 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
449 | arg( SF->name() ). | ||
450 | arg( CurDevNN->name() ); | ||
451 | return S; | ||
452 | } | ||
453 | |||
454 | switch( NNI->generateFile( | ||
455 | SF->name(), SF->path(), *SF, i ) ) { | ||
456 | case 0 : | ||
457 | (*SF) << endl; | ||
458 | break; | ||
459 | case 1 : | ||
460 | break; | ||
461 | case 2 : | ||
462 | S = qApp->translate( "NetworkSettings", | ||
463 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). | ||
464 | arg( SF->name() ). | ||
465 | arg( CurDevNN->name() ); | ||
466 | return S; | ||
467 | } | ||
468 | |||
469 | if( ! SF->postNodeSection( NNI, i ) ) { | ||
470 | S = qApp->translate( "NetworkSettings", | ||
471 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
472 | arg( SF->name() ). | ||
473 | arg( CurDevNN->name() ); | ||
474 | return S; | ||
475 | } | ||
476 | } | ||
477 | |||
478 | ncit2.current()->setDone( 1 ); | ||
479 | |||
480 | } | ||
481 | } | ||
482 | |||
483 | if( ! SF->postDeviceSection( CurDevNN ) ) { | ||
484 | S = qApp->translate( "NetworkSettings", | ||
485 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). | ||
486 | arg( SF->name() ). | ||
487 | arg( CurDevNN->name() ); | ||
488 | return S; | ||
489 | } | ||
490 | |||
491 | |||
492 | if( ! SF->postSection() ) { | ||
493 | S = qApp->translate( "NetworkSettings", | ||
494 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). | ||
372 | arg( SF->name() ); | 495 | arg( SF->name() ); |
373 | return S; | 496 | return S; |
374 | } | 497 | } |
375 | 498 | ||
376 | } while( 0 ); | 499 | // end of file |
377 | SF->close(); | 500 | SF->close(); |
378 | } | 501 | } |
379 | } | ||
380 | Force = 0; | ||
381 | return S; | 502 | return S; |
382 | } | 503 | } |
383 | 504 | ||
@@ -463,111 +584,10 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
463 | */ | 584 | */ |
464 | 585 | ||
465 | bool NetworkSettingsData::regenerate( void ) { | 586 | bool NetworkSettingsData::regenerate( void ) { |
466 | QString S; | 587 | QString S = generateSettings(); |
467 | // load situation | ||
468 | S = generateSettings( TRUE ); | ||
469 | if( ! S.isEmpty() ) { | 588 | if( ! S.isEmpty() ) { |
470 | fprintf( stdout, "%s\n", S.latin1() ); | 589 | fprintf( stdout, "%s\n", S.latin1() ); |
471 | return 1; | 590 | return 1; |
472 | } | 591 | } |
473 | return 0; | 592 | return 0; |
474 | } | 593 | } |
475 | |||
476 | QString NetworkSettingsData::generateSystemFileNode( | ||
477 | SystemFile &SF, | ||
478 | AsDevice * CurDev, | ||
479 | ANetNodeInstance * DevNNI, | ||
480 | long DevInstNr ) { | ||
481 | |||
482 | QString S=""; | ||
483 | ANetNode * CurDevNN = DevNNI->nodeClass(); | ||
484 | Name2Connection_t & M = NSResources->connections(); | ||
485 | |||
486 | if( SF.preDeviceSection( CurDevNN ) ) { | ||
487 | S = qApp->translate( "NetworkSettings", | ||
488 | "<p>Error in \"Pre-Device Part\" for file \"%1\" and nodetype \"%2\"</p>" ). | ||
489 | arg( SF.name() ). | ||
490 | arg( CurDevNN->name() ); | ||
491 | return S; | ||
492 | } | ||
493 | |||
494 | if( CurDevNN->hasDataFor( SF.name() ) ) { | ||
495 | if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { | ||
496 | S = qApp->translate( "NetworkSettings", | ||
497 | "<p>Error in \"Device Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
498 | arg( SF.name() ). | ||
499 | arg( CurDevNN->name() ); | ||
500 | return S; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | // now generate profile specific data for all | ||
505 | // connections working on a device of the current | ||
506 | // netnode type | ||
507 | for( QDictIterator<NodeCollection> ncit(M); | ||
508 | ncit.current(); | ||
509 | ++ncit ) { | ||
510 | NodeCollection * NC = ncit.current(); | ||
511 | |||
512 | // currenly only those connections that work on | ||
513 | // the current device (or on no device if no current) | ||
514 | AsDevice * Dev = NC->device(); | ||
515 | |||
516 | if( CurDev ) { | ||
517 | if( CurDevNN != Dev->netNode()->nodeClass() ) { | ||
518 | // other device type -> later | ||
519 | continue; | ||
520 | } | ||
521 | } else { | ||
522 | if( Dev ) { | ||
523 | // other | ||
524 | continue; | ||
525 | } | ||
526 | } | ||
527 | |||
528 | // generate 'entry' | ||
529 | if( SF.preNodeSection( DevNNI, DevInstNr ) ) { | ||
530 | S = qApp->translate( "NetworkSettings", | ||
531 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
532 | arg( SF.name() ). | ||
533 | arg( CurDevNN->name() ); | ||
534 | return S; | ||
535 | } | ||
536 | |||
537 | // ask all nodes in connection | ||
538 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
539 | cncit.current(); | ||
540 | ++cncit ) { | ||
541 | ANetNodeInstance * NNI = cncit.current(); | ||
542 | |||
543 | if( NNI->hasDataFor( SF.name() ) ) { | ||
544 | if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { | ||
545 | S = qApp->translate( "NetworkSettings", | ||
546 | "<p>Error in \"Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
547 | arg( SF.name() ). | ||
548 | arg( NNI->nodeClass()->name() ); | ||
549 | return S; | ||
550 | } | ||
551 | } | ||
552 | } | ||
553 | |||
554 | if( SF.postNodeSection( DevNNI, DevInstNr ) ) { | ||
555 | S = qApp->translate( "NetworkSettings", | ||
556 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
557 | arg( SF.name() ). | ||
558 | arg( CurDevNN->name() ); | ||
559 | return S; | ||
560 | } | ||
561 | SF << endl; | ||
562 | } | ||
563 | |||
564 | if( SF.postDeviceSection( CurDevNN ) ) { | ||
565 | S = qApp->translate( "NetworkSettings", | ||
566 | "<p>Error in \"Post-Device Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
567 | arg( SF.name() ). | ||
568 | arg( CurDevNN->name() ); | ||
569 | return S; | ||
570 | } | ||
571 | |||
572 | return S; | ||
573 | } | ||