summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
blob: 6b873992eeac66841e4758758a01c99762410c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
#include <stdlib.h>
#include <opie2/odebug.h>
#include <qpe/qpeapplication.h>
#include <qtextstream.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>

#include "nsdata.h"
#include <netnode.h>
#include <resources.h>

static QString CfgFile;

NetworkSettingsData::NetworkSettingsData( void ) {
    // init global resources structure
    new TheNSResources();

    if( ! NSResources->userKnown() ) {
      Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n",
          NSResources->currentUser().HomeDir.latin1(),
          NSResources->currentUser().UserName.latin1() ));
      return;
    }

    CfgFile.sprintf( "%s/Settings/NS2.conf", 
          NSResources->currentUser().HomeDir.latin1() );
    Log(( "Cfg from %s\n", CfgFile.latin1() ));

    // load settings
    loadSettings();

    // assign interfaces by scanning /tmp/profile-%s.Up files
    { QDir D( "/tmp" );
      QFile * F = new QFile;
      int profilenr;
      QString interfacename;
      QTextStream TS ( F );

      QStringList SL = D.entryList( "profile-*.up");

      Log(( "System reports %d interfaces. Found %d up\n", 
          NSResources->system().interfaces().count(),
          SL.count() ));

      for ( QStringList::Iterator it = SL.begin(); 
            it != SL.end(); 
            ++it ) {
        profilenr = atol( (*it).mid( 8 ).latin1() );
        // read the interface store int 'up'
        F->setName( D.path() + "/" + (*it) );
        if( F->open( IO_ReadOnly ) ) {
          NetworkSetup * NC;
          interfacename = TS.readLine();
          F->close();

          Log(( "Assign interface %s to Profile nr %d\n", 
                interfacename.latin1(), profilenr ));

          NC = NSResources->getNetworkSetup( profilenr );
          if( NC ) {
            NC->assignInterface( 
                NSResources->system().findInterface( interfacename ) );
            Log(( "Assign interface %p\n", 
                  NC->assignedInterface() ));
          } else {
            Log(( "Profile nr %d no longer defined\n", 
                profilenr ));
          }
        }
      }
    }
}

// saving is done by caller
NetworkSettingsData::~NetworkSettingsData( void ) {
    delete NSResources;
}

void NetworkSettingsData::loadSettings( void ) {
    QString Line, S;
    QString Attr, Value;
    long idx;

    QFile F( CfgFile );
    QTextStream TS( &F );

    ForceModified = 0;

    do {

      if( ! F.open(IO_ReadOnly) )
        break;

      /* load the file ->

         FORMAT :

           [NETNODETYPE] 
           Entries ...
           <EMPTYLINE>
           [NetworkSetup] 
           Name=Name
           Node=Name
           <EMPTYLINE>
      */
      while( ! TS.atEnd() ) {
        S = Line = TS.readLine();

        if ( S.isEmpty() || S[0] != '[' )
          continue;

        S = S.mid( 1, S.length()-2 );

        if( ! NSResources ) {
          continue;
        }

        if( S == "NetworkSetup" ) {
          // load NetworkSetups -> collections of nodes
          bool Dangling;
          NetworkSetup * NC = new NetworkSetup( TS, Dangling );
          NSResources->addNetworkSetup( NC, Dangling );
        } else {
          ANetNode * NN = 0;
          ANetNodeInstance* NNI = 0;
          if( S.startsWith( "nodetype " ) ) {
            S = S.mid( 9, S.length()-9 );
            S = deQuote(S);
            // try to find netnode
            NN = NSResources->findNetNode( S );
          } else {
            // try to find instance
            NNI = NSResources->createNodeInstance( S );
          }

          if( NN == 0 && NNI == 0 ) {
            LeftOvers.append( Line );
            do {
              Line = TS.readLine();
              // store even delimiter
              LeftOvers.append( Line );
            } while ( ! Line.isEmpty() );

            //next section 
            continue;
          } 

          // read entries of this section
          do {
            S = Line = TS.readLine();

            if( S.isEmpty() ) {
              // empty line
              break;
            }
            idx = S.find( '=' );
            if( idx > 0 ) {
              Attr = S.left( idx );
              Value = S.mid( idx+1, S.length() );
            } else {
              Value="";
              Attr = S;
            }

            Value.stripWhiteSpace();
            Attr.stripWhiteSpace();
            Attr.lower();
            // dequote Attr
            Value = deQuote(Value);

            if( NN ) {
              // set the attribute
              NN->setAttribute( Attr, Value );
            } else {
              // set the attribute
              NNI->setAttribute( Attr, Value );
            }
          } while( 1 );

          if( NNI ) {
            // loading from file -> exists
            Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI  ));
            NNI->setNew( FALSE );
            NSResources->addNodeInstance( NNI );
          }

          if( NN ) {
            Log( ( "Node %s : %p\n", NN->name(), NN ) );
          }
        }
      }

    } while( 0 );

}

QString NetworkSettingsData::saveSettings( void ) {
    QString ErrS = "";

    if( ! isModified() )
      return ErrS;

    QString S;
    QFile F( CfgFile + ".bup" );

    Log( ( "Saving settings to %s\n", CfgFile.latin1()  ));
    if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
      ErrS = qApp->translate( "NetworkSettings", 
              "<p>Could not save setup to \"%1\" !</p>" ).
        arg(CfgFile);
      // problem
      return ErrS;
    }

    QTextStream TS( &F );

    // save global configs
    for( QDictIterator<ANetNode> it( NSResources->netNodes() );
        it.current();
        ++it ) {
        TS << "[nodetype "
           << quote( QString( it.current()->name() ) )
           << "]" 
           << endl;

        it.current()->saveAttributes( TS );
        TS << endl;
    }

    // save leftovers
    for ( QStringList::Iterator it = LeftOvers.begin(); 
          it != LeftOvers.end(); ++it ) {
      TS << (*it) << endl;
    }

    // save all netnode instances
    { ANetNodeInstance * NNI;
      for( QDictIterator<ANetNodeInstance> nit( 
                          NSResources->netNodeInstances()); 
           nit.current();
           ++nit ) {
        // header
        NNI = nit.current();
        TS << '[' 
           << QString(NNI->nodeClass()->name()) 
           << ']' 
           << endl;
        NNI->saveAttributes( TS );
        TS << endl;
      }
    }

    // good NetworkSetups
    { Name2NetworkSetup_t & M = NSResources->networkSetups();

      // for all NetworkSetups
      for( QDictIterator<NetworkSetup> it(M);
           it.current();
           ++it ) {
        TS << "[NetworkSetup]" << endl;
        it.current()->save(TS);
      }
    }

    // save dangling NetworkSetups
    { Name2NetworkSetup_t & M = NSResources->danglingNetworkSetups();

      // for all NetworkSetups
      for( QDictIterator<NetworkSetup> it(M);
           it.current();
           ++it ) {
        TS << "[NetworkSetup]" << endl;
        it.current()->save(TS);
      }
    }

    QDir D(".");
    D.rename( CfgFile + ".bup", CfgFile );

    //
    // proper files AND system files regenerated
    //


    for( QDictIterator<NetworkSetup> it(NSResources->networkSetups());
         it.current();
         ++it ) {
      it.current()->setModified( 0 );
    }

    return ErrS;
}

QString NetworkSettingsData::generateSettings( void ) {
    QString S = "";
    Name2SystemFile_t & SFM = NSResources->systemFiles();
    Name2NetworkSetup_t & M = NSResources->networkSetups();
    NetworkSetup * NC;
    ANetNodeInstance * NNI;
    ANetNodeInstance * FirstWithData;
    RuntimeInfo * CurDev;
    ANetNode * NN, * CurDevNN = 0;
    long NoOfDevs;
    long DevCtStart;
    bool needToGenerate;

    // regenerate system files
    Log( ( "Generating settings from %s\n", CfgFile.latin1()  ));

    for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
         nnit.current();
         ++nnit ) {
      bool FirstItem = 1;
      bool Generated = 0;

      CurDevNN = nnit.current();

      { QStringList SL;
        SL = CurDevNN->properFiles();

        for ( QStringList::Iterator it = SL.begin(); 
              it != SL.end(); 
              ++it ) {

          Generated = 0;
          FirstItem = 1;
          // iterate over NNI's of this class
          for( QDictIterator<ANetNodeInstance> nniit(
                                 NSResources->netNodeInstances() );
               nniit.current();
               ++nniit ) {
            if( nniit.current()->nodeClass() != CurDevNN )
              // different class
              continue;

            // open proper file
            { SystemFile SF( (*it) );
              QStringList SL;

              if( ! CurDevNN->openFile( SF, nniit.current(), SL) ) {
                // cannot open
                S = qApp->translate( "NetworkSettings", 
                  "<p>Cannot build proper file \"%1\" for node \"%2\"</p>" ).
                    arg( (*it) ).
                    arg( CurDevNN->name() );
                return S;
              }

              if( ! createPath( SL ) ) {
                S = qApp->translate( "NetworkSettings", 
                  "<p>Cannot create path \"%1\" for proper file \"%2\" for node \"%3\"</p>" ).
                    arg( SL.join("/") ).
                    arg( (*it) ).
                    arg( CurDevNN->name() );
                return S;
              }

              if( ! SF.open() ) {
                S = qApp->translate( "NetworkSettings", 
                  "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ).
                    arg( (*it) ).arg( CurDevNN->name() );
                return S;
              }

              // preamble on first
              if( FirstItem ) {
                if( CurDevNN->generatePreamble( SF ) == 2 ) {
                  S = qApp->translate( "NetworkSettings", 
                    "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ).
                      arg( (*it) ).
                      arg( CurDevNN->name() );
                  return S;
                }
              }
              FirstItem = 0;
              Generated = 1;

              // item specific
              if( nniit.current()->generateFile( SF, -1 ) == 2 ) {
                S = qApp->translate( "NetworkSettings", 
                  "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ).
                    arg( nniit.current()->name() ).
                    arg( (*it) ).
                    arg( CurDevNN->name() );
                return S;
              }
            }
          }

          if( Generated ) {
            SystemFile SF( (*it) );
            QStringList SL;

            if( CurDevNN->openFile( SF, 0, SL ) &&
                ! SF.path().isEmpty()
              ) {

              if( ! createPath( SL ) ) {
                S = qApp->translate( "NetworkSettings", 
                  "<p>Cannot create path \"%1\" for proper file \"%2\" for node \"%3\"</p>" ).
                    arg( SL.join("/") ).
                    arg( (*it) ).
                    arg( CurDevNN->name() );
                return S;
              }

              if( ! SF.open() ) {
                S = qApp->translate( "NetworkSettings", 
                  "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ).
                    arg( (*it) ).
                    arg( CurDevNN->name() );
                return S;
              }

              if( CurDevNN->generatePostamble( SF ) == 2 ) {
                S = qApp->translate( "NetworkSettings", 
                  "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ).
                    arg( (*it) ).
                    arg( CurDevNN->name() );
                return S;
              }
            } // no postamble
          }
        }
      }
    }

    //
    // generate all registered files
    //
    for( QDictIterator<SystemFile> sfit(SFM);
         sfit.current();
         ++sfit ) {
      SystemFile * SF;

      SF = sfit.current();

      // reset all 
      for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
           nnit.current();
           ++nnit ) {
        nnit.current()->setDone(0);
      }

      for( QDictIterator<ANetNodeInstance> nniit(
                  NSResources->netNodeInstances() );
           nniit.current();
           ++nniit ) {
        nniit.current()->setDone(0);
      }

      for( QDictIterator<NetworkSetup> ncit(M);
           ncit.current();
           ++ncit ) {
        ncit.current()->setDone(0);
      }

      Log( ( "Generating system file %s\n", SF->name().latin1() ));

      needToGenerate = 0;

      // are there netnodes that have instances and need 
      // to write data in this system file ?
      for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
           ! needToGenerate && nnit.current();
           ++nnit ) {

        NN = nnit.current();

        if( NN->hasDataForFile( *SF ) ) {
          // netnode can have data

          // are there instances of this node ?
          for( QDictIterator<ANetNodeInstance> nniit(
                      NSResources->netNodeInstances() );
               ! needToGenerate && nniit.current();
               ++nniit ) {
            if( nniit.current()->nodeClass() == NN ) {
              // yes
              Log(("Node %s has data\n",
                  nniit.current()->name() ));
              needToGenerate = 1;
              break;
            }
          }
        }
      }

      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
      if( ! SF->open() ) {
        S = qApp->translate( "NetworkSettings", 
                             "<p>Cannot open system file \"%1\"</p>" ).
            arg( SF->name() );
        return S;
      }

      // 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;
      }

      // find NetworkSetups that want to write to this file
      for( QDictIterator<NetworkSetup> ncit(M);
           ncit.current();
           ++ncit ) {

        NC = ncit.current();

        if( NC->done() ) {
          // already done
          continue;
        }

        if( ! NC->hasDataForFile( *SF ) ) {
          // no data
          continue;
        }

        Log(("Generating %s for NetworkSetup %s\n",
              SF->name().latin1(), NC->name().latin1() ));
        // find highest item that wants to write data to this file
        FirstWithData = NC->firstWithDataForFile( *SF );

        // find device on which this NetworkSetup works
        CurDev = NC->device();
        // class of that node
        CurDevNN = CurDev->netNode()->nodeClass();

        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, 
                                            FirstWithData,
                                            -2 ) == 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 );
          Log(( "Systemfile %s for node instance %s is done\n",
            SF->name().latin1(),
            FirstWithData->name() ));
        }

        NoOfDevs = 0;
        DevCtStart = -1;

        if( SF->knowsDeviceInstances() ) {
          DevCtStart = 0;
          NoOfDevs = CurDevNN->instanceCount();
        }

        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, CurDev->netNode(), i ) == 2 ) {
              S = qApp->translate( "NetworkSettings", 
                "<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 );

          Log(( "Systemfile %s for Nodeclass %s is done\n",
            SF->name().latin1(),
            CurDev->netNode()->nodeClass()->name()
            ));
        }

        // generate profile specific info
        // for all nodeNetworkSetups that work on the same device
        for( QDictIterator<NetworkSetup> ncit2(M);
             ncit2.current();
             ++ncit2 ) {

          if( ncit2.current()->device() != CurDev ) {
            // different device
            continue;
          }

          Log(("NetworkSetup %s of family %s\n", 
                ncit2.current()->name().latin1(), 
                CurDev->name() ));
          // generate 
          NNI = ncit2.current()->firstWithDataForFile( *SF );
          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, 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;
      }

      // end of file
      SF->close();
    }
    return S;
}

QList<NetworkSetup> NetworkSettingsData::collectPossible( 
                    const QString & Interface ) {
    // collect NetworkSetups that can work on top of this interface
    NetworkSetup * NC;
    QList<NetworkSetup> PossibleNetworkSetups;
    Name2NetworkSetup_t & M = NSResources->networkSetups();

    // for all NetworkSetups
    for( QDictIterator<NetworkSetup> it(M);
         it.current();
         ++it ) {
      NC = it.current();
      // check if this profile handles the requested interface
      if( NC->handlesInterface( Interface ) && // if different Intf.
          NC->state() != Disabled && // if enabled
          NC->state() != IsUp  // if already used
        ) {
        Log( ( "Append %s for %s\n", 
              NC->name().latin1(), Interface.latin1() ));
        PossibleNetworkSetups.append( NC );
      }
    }
    return PossibleNetworkSetups;
}


/*
    Called by the system to see if interface can be brought UP

    if allowed, echo Interface-allowed else Interface-disallowed
*/

bool NetworkSettingsData::canStart( const QString & Interface ) {
    // load situation
    NetworkSetup * NC = 0;
    QList<NetworkSetup> PossibleNetworkSetups;

    PossibleNetworkSetups = collectPossible( Interface );

    Log( ( "for %s : Possiblilies %d\n", 
        Interface.latin1(), PossibleNetworkSetups.count() ));
    switch( PossibleNetworkSetups.count() ) {
      case 0 : // no NetworkSetups
        break;
      case 1 : // one NetworkSetup
        NC = PossibleNetworkSetups.first();
        break;
      default : // need to ask user ?
        return 1;
    }

    if( NC ) {
      switch( NC->state() ) {
        case Unchecked :
        case Unknown :
        case Unavailable :
        case Disabled :
          // this profile does not allow interface to be UP
          // -> try others
          break;
        case Off :
          // try to UP the device
          { QString S= NC->setState( Activate );
            if( ! S.isEmpty() ) {
              // could not bring device Online -> try other alters
              Log(( "disallow %ld for %s : %s\n", 
                  NC->number(), Interface.latin1(), S.latin1() ));
              break;
            }
            // interface assigned 
          }
          // FT
        case Available :
        case IsUp : // also called for 'ifdown'
          // device is ready -> done
          Log(( "allow %ld for %s\n", NC->number(), Interface.latin1()));
          printf( "A%d%s\n", NC->number(), Interface.latin1() );
          return 0;
      }
    } 

    // if we come here no alternatives are possible
    Log(( "disallow %s\n", Interface.latin1()));
    printf( "D-%s\n", Interface.latin1() );
    return 0;
}

bool NetworkSettingsData::isModified( void ) {
    if( ForceModified )
      return 1;

    for( QDictIterator<NetworkSetup> it(NSResources->networkSetups());
         it.current();
         ++it ) {
      if( it.current()->isModified() ) {
        return 1;
      }
    }
    return 0;
}

bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) {
    // load situation
    QList<NetworkSetup> PossibleTriggered;

    PossibleTriggered = collectTriggered( Interface );

    Log( ( "for %s : Possiblilies %d\n", 
        Interface.latin1(), PossibleTriggered.count() ));

    return ( PossibleTriggered.count() ) ? 1 : 0;
}

QList<NetworkSetup> NetworkSettingsData::collectTriggered( 
                      const QString & Interface ) {

    // collect NetworkSetups that could be triggered by this interface
    NetworkSetup * NC;
    QList<NetworkSetup> PossibleTriggered;

    // for all NetworkSetups
    Name2NetworkSetup_t & M = NSResources->networkSetups();

    for( QDictIterator<NetworkSetup> it(M);
         it.current();
         ++it ) {
      NC = it.current();
      // check if this profile handles the requested interface
      if( NC->triggeredBy( Interface ) && // if different Intf.
          NC->state() != Disabled && // if enabled
          NC->state() != IsUp  // if already used
        ) {
        Log( ( "Append %s for %s\n", 
            NC->name().latin1(), Interface.latin1() ));
        PossibleTriggered.append( NC );
      }
    }
    return PossibleTriggered;
}

bool NetworkSettingsData::createPath( const QStringList & SL ) {

    QDir D( SL[0] );

    for ( QStringList::ConstIterator it = SL.begin(); 
          it != SL.end(); 
          ++it ) {

      printf( "Create %s\n", (*it).latin1() );
      if( it == SL.begin() )
        continue;

      if( ! D.exists( *it ) ) {
        if( ! D.mkdir( *it ) ) {
      printf( "Failed %s %s\n", D.path().latin1(), (*it).latin1() );
          return 0;
        }
      }

      D.cd( *it );
    }
    return 1;
}