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 | |
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
69 files changed, 1308 insertions, 1190 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp index d8420b9..398dcdc 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp @@ -40,11 +40,3 @@ void ABluetoothBNEP::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } - -bool ABluetoothBNEP::hasDataFor( const QString & ) { - return 0; -} - -bool ABluetoothBNEP::generateDataForCommonFile( SystemFile & , long ){ - return 0; -} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h index bb3e7e7..1bf0f48 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h @@ -14,22 +14,18 @@ public : ABluetoothBNEP( BluetoothBNEPNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new BluetoothBNEPRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new BluetoothBNEPRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S ); - virtual bool generateDataForCommonFile( SystemFile & SF, long ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp index cff2639..7ec8288 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp @@ -28,11 +28,3 @@ void ABluetoothRFCOMM::commit( void ) { if( GUI->commit( Data ) ) setModified( 1 ); } - -bool ABluetoothRFCOMM::hasDataFor( const QString & ) { - return 0; -} - -bool ABluetoothRFCOMM::generateDataForCommonFile( SystemFile & , long ){ - return 0; -} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h index 97bd29c..820fc17 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h @@ -14,22 +14,18 @@ public : ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new BluetoothRFCOMMRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new BluetoothRFCOMMRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S ); - virtual bool generateDataForCommonFile( SystemFile & SF, long ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h index aff1f59..65fd686 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h @@ -12,6 +12,9 @@ public : virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ) + { return QString( "/dev/rfcomm..." ); } + protected : void detectState( NodeCollection * ) diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp index b59b4f0..443a627 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp @@ -46,29 +46,6 @@ const char * BluetoothBNEPNetNode::provides( void ) { return "device"; } -bool BluetoothBNEPNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool BluetoothBNEPNetNode::hasDataFor( const QString & S ) { - return S == "interfaces"; -} - -bool BluetoothBNEPNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr) { - QString NIC = genNic( DevNr ); - - if( S.name() == "interfaces" ) { - // generate mapping stanza for this interface - S << "# check if " << NIC << " can be brought UP" << endl; - S << "mapping " << NIC << endl; - S << " script networksettings2-request" << endl << endl; - } - return 0; -} - QString BluetoothBNEPNetNode::genNic( long nr ) { QString S; return S.sprintf( "bnep%ld", nr ); @@ -124,21 +101,6 @@ const char * BluetoothRFCOMMNetNode::provides( void ) { return "line"; } -bool BluetoothRFCOMMNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool BluetoothRFCOMMNetNode::hasDataFor( const QString & ) { - return 0; -} - -bool BluetoothRFCOMMNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void BluetoothRFCOMMNetNode::setSpecificAttribute( QString &, QString & ) { } diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h index 2e5e1d2..4d6a3c1 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h @@ -7,31 +7,23 @@ class ABluetoothBNEP; class BluetoothBNEPNetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - BluetoothBNEPNetNode(); - virtual ~BluetoothBNEPNetNode(); + BluetoothBNEPNetNode(); + virtual ~BluetoothBNEPNetNode(); - virtual const QString pixmapName() - { return "Devices/bluetooth"; } + virtual QString genNic( long ); + virtual long instanceCount( void ) + { return InstanceCount; } + virtual const QString pixmapName() + { return "Devices/bluetooth"; } - virtual const QString nodeDescription() ; - - virtual ANetNodeInstance * createInstance( void ); - - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); - virtual bool generateDeviceDataForCommonFile( - SystemFile & , long DevNr ); - - virtual long instanceCount( void ) - { return InstanceCount; } - virtual QString genNic( long ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char * provides( void ); + virtual const char ** needs( void ); private: @@ -45,27 +37,20 @@ private: class BluetoothRFCOMMNetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - BluetoothRFCOMMNetNode(); - virtual ~BluetoothRFCOMMNetNode(); - - virtual const QString pixmapName() - { return "Devices/bluetooth"; } - - virtual const QString nodeDescription() ; - - virtual ANetNodeInstance * createInstance( void ); + BluetoothRFCOMMNetNode(); + virtual ~BluetoothRFCOMMNetNode(); - virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const QString pixmapName() + { return "Devices/bluetooth"; } - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); - virtual bool generateDeviceDataForCommonFile( - SystemFile & , long ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp index b8c690b..38568df 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.cpp +++ b/noncore/settings/networksettings2/cable/cable_NN.cpp @@ -36,17 +36,6 @@ const char * CableNetNode::provides( void ) { return "line"; } -bool CableNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool CableNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void CableNetNode::setSpecificAttribute( QString & , QString & ) { } diff --git a/noncore/settings/networksettings2/cable/cable_NN.h b/noncore/settings/networksettings2/cable/cable_NN.h index c48037a..5cc2b2d 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.h +++ b/noncore/settings/networksettings2/cable/cable_NN.h @@ -7,28 +7,20 @@ class ACable; class CableNetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - CableNetNode(); - virtual ~CableNetNode(); + CableNetNode(); + virtual ~CableNetNode(); - virtual const QString pixmapName() - { return "Devices/cable"; } + virtual const QString pixmapName() + { return "Devices/cable"; } - virtual const QString nodeDescription() ; - - virtual ANetNodeInstance * createInstance( void ); - - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: diff --git a/noncore/settings/networksettings2/cable/cable_NNI.cpp b/noncore/settings/networksettings2/cable/cable_NNI.cpp index ca21135..4bd9421 100644 --- a/noncore/settings/networksettings2/cable/cable_NNI.cpp +++ b/noncore/settings/networksettings2/cable/cable_NNI.cpp @@ -49,6 +49,29 @@ void ACable::saveSpecificAttribute( QTextStream & TS ) { ((Data.SoftwareControl) ? "yes" : "no") << endl; } +short ACable::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + short rvl, rvd; + + rvl = 1; + if( ID == "peers" ) { + TS << Data.Device + << endl; + TS << Data.Speed + << endl; + TS << "lock " + << Data.LockFile + << endl; + rvl = 0; + } + + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; +} + QWidget * ACable::edit( QWidget * parent ) { GUI = new CableEdit( parent ); GUI->showData( Data ); @@ -64,10 +87,3 @@ void ACable::commit( void ) { setModified( 1 ); } } - -bool ACable::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/cable/cable_NNI.h b/noncore/settings/networksettings2/cable/cable_NNI.h index bf3e292..d06cbbe 100644 --- a/noncore/settings/networksettings2/cable/cable_NNI.h +++ b/noncore/settings/networksettings2/cable/cable_NNI.h @@ -14,24 +14,22 @@ public : ACable( CableNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new CableRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new CableRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); - + short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/cable/cablerun.cpp b/noncore/settings/networksettings2/cable/cablerun.cpp index 5e99237..85660f6 100644 --- a/noncore/settings/networksettings2/cable/cablerun.cpp +++ b/noncore/settings/networksettings2/cable/cablerun.cpp @@ -4,7 +4,7 @@ void CableRun::detectState( NodeCollection * NC ) { - int fd = open( D->Device.latin1(), O_RDWR ); + int fd = open( Data->Device.latin1(), O_RDWR ); if( fd < 0 ) { NC->setCurrentState( Unavailable ); @@ -24,3 +24,7 @@ bool CableRun::setState( NodeCollection * NC, Action_t A, bool ) { bool CableRun::canSetState( State_t , Action_t ) { return 1; } + +QString CableRun::deviceFile( void ) { + return Data->Device; +} diff --git a/noncore/settings/networksettings2/cable/cablerun.h b/noncore/settings/networksettings2/cable/cablerun.h index c5b59d5..20608f6 100644 --- a/noncore/settings/networksettings2/cable/cablerun.h +++ b/noncore/settings/networksettings2/cable/cablerun.h @@ -6,12 +6,14 @@ class CableRun : public AsLine { public : CableRun( ANetNodeInstance * NNI, - CableData & Data ) : AsLine( NNI ) - { D = &Data; } + CableData_t & D ) : AsLine( NNI ) + { Data = &D; } virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ); + protected : void detectState( NodeCollection * NC ); @@ -20,5 +22,5 @@ protected : private : - CableData_t * D; + CableData_t * Data; }; diff --git a/noncore/settings/networksettings2/irda/irda_NN.cpp b/noncore/settings/networksettings2/irda/irda_NN.cpp index 49bc06e..9483e22 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.cpp +++ b/noncore/settings/networksettings2/irda/irda_NN.cpp @@ -36,17 +36,6 @@ const char * IRDANetNode::provides( void ) { return "line"; } -bool IRDANetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool IRDANetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void IRDANetNode::setSpecificAttribute( QString & , QString & ) { } diff --git a/noncore/settings/networksettings2/irda/irda_NN.h b/noncore/settings/networksettings2/irda/irda_NN.h index fa6408d..900bbc6 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.h +++ b/noncore/settings/networksettings2/irda/irda_NN.h @@ -7,28 +7,20 @@ class AIRDA; class IRDANetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - IRDANetNode(); - virtual ~IRDANetNode(); + IRDANetNode(); + virtual ~IRDANetNode(); - virtual const QString pixmapName() - { return "Devices/irda"; } + virtual const QString pixmapName() + { return "Devices/irda"; } - virtual const QString nodeDescription() ; - - virtual ANetNodeInstance * createInstance( void ); - - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: diff --git a/noncore/settings/networksettings2/irda/irda_NNI.cpp b/noncore/settings/networksettings2/irda/irda_NNI.cpp index f00a1d5..9cf443b 100644 --- a/noncore/settings/networksettings2/irda/irda_NNI.cpp +++ b/noncore/settings/networksettings2/irda/irda_NNI.cpp @@ -29,9 +29,3 @@ void AIRDA::commit( void ) { setModified( 1 ); } -bool AIRDA::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/irda/irda_NNI.h b/noncore/settings/networksettings2/irda/irda_NNI.h index 210d87d..e21b68f 100644 --- a/noncore/settings/networksettings2/irda/irda_NNI.h +++ b/noncore/settings/networksettings2/irda/irda_NNI.h @@ -14,24 +14,18 @@ public : AIRDA( IRDANetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new IRDARun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new IRDARun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/irda/irdarun.h b/noncore/settings/networksettings2/irda/irdarun.h index 4c903cc..4258aff 100644 --- a/noncore/settings/networksettings2/irda/irdarun.h +++ b/noncore/settings/networksettings2/irda/irdarun.h @@ -12,6 +12,9 @@ public : virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ) + { return QString( "/dev/irda" ); } + protected : void detectState( NodeCollection * ) diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp index 05cd06d..20ae7f6 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp @@ -38,29 +38,6 @@ const char * LanCardNetNode::provides( void ) { return "device"; } -bool LanCardNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool LanCardNetNode::hasDataFor( const QString & S ) { - return S == "interfaces"; -} - -bool LanCardNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr ) { - QString NIC = genNic( DevNr ); - - if( S.name() == "interfaces" ) { - // generate mapping stanza for this interface - S << "# check if " << NIC << " can be brought UP" << endl; - S << "mapping " << NIC << endl; - S << " script networksettings2-request" << endl << endl; - } - return 0; -} - QString LanCardNetNode::genNic( long nr ) { QString S; return S.sprintf( "eth%ld", nr ); diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h index d58823c..6882af7 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.h +++ b/noncore/settings/networksettings2/lancard/lancard_NN.h @@ -18,23 +18,16 @@ public: virtual const QString pixmapName() { return "Devices/card"; } - virtual const QString nodeDescription() ; + virtual QString genNic( long ); + virtual long instanceCount( void ) + { return InstanceCount; } + virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); - virtual const char ** needs( void ); virtual const char * provides( void ); - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - - virtual long instanceCount( void ) - { return InstanceCount; } - - virtual QString genNic( long ); - virtual QStringList & addressesOfNIC( void ) + QStringList & addressesOfNIC( void ) { return NICMACAddresses; } private: diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp index 99c033e..9fb05b9 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp @@ -43,9 +43,3 @@ void ALanCard::commit( void ) { setModified( 1 ); } -bool ALanCard::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.h b/noncore/settings/networksettings2/lancard/lancard_NNI.h index 4e91523..8e55a19 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NNI.h +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.h @@ -14,23 +14,18 @@ public : ALanCard( LanCardNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new LanCardRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new LanCardRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & S, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 6c969fc..b32b323 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp @@ -1,5 +1,6 @@ #include "nsdata.h" #include "activateprofile.h" +#include "activatevpn.h" #include "networksettings.h" #include <qpe/qpeapplication.h> @@ -21,6 +22,8 @@ OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) #define ACT_REGEN 2 // used by interfaces to request user prompt #define ACT_PROMPT 3 +// used by interfaces to trigger VPN +#define ACT_VPN 4 int main( int argc, char * argv[] ) { int rv = 0; @@ -44,6 +47,9 @@ int main( int argc, char * argv[] ) { } else if( strcmp( argv[i], "--prompt" ) == 0 ) { Action = ACT_PROMPT; rmv = 1; + } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { + Action = ACT_VPN; + rmv = 1; } if( rmv ) { memmove( argv+i, argv+i+rmv, @@ -78,10 +84,8 @@ int main( int argc, char * argv[] ) { switch( Action ) { case ACT_REQUEST : { NetworkSettingsData NS; - Log(("ACT_REQUEST\n")); if( NS.canStart( argv[1] ) ) { QString S; - Log(("NEED FOR PROMPT\n" )); S.sprintf( QPEApplication::qpeDir()+ "/bin/networksettings2" ); char * MyArgv[4]; @@ -97,14 +101,12 @@ int main( int argc, char * argv[] ) { break; case ACT_REGEN : { NetworkSettingsData NS; - Log(("REGEN\n" )); // regen returns 0 if OK rv = (NS.regenerate()) ? 1 : 0; } break; case ACT_PROMPT : { ActivateProfile AP(argv[1]); - Log(("PROMPT\n" )); if( AP.exec() == QDialog::Accepted ) { printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); } else { @@ -112,9 +114,13 @@ int main( int argc, char * argv[] ) { } } break; + case ACT_VPN : + { ActivateVPN AVPN; + AVPN.exec(); + } + break; case ACT_GUI : { QWidget * W = new NetworkSettings(0); - Log(("GUI\n" )); TheApp->setMainWidget( W ); W->show(); #ifdef _WS_QWS_ diff --git a/noncore/settings/networksettings2/modem/modem_NN.cpp b/noncore/settings/networksettings2/modem/modem_NN.cpp index 18aa480..ee61b10 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.cpp +++ b/noncore/settings/networksettings2/modem/modem_NN.cpp @@ -37,17 +37,6 @@ const char * ModemNetNode::provides( void ) { return "line"; } -bool ModemNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool ModemNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void ModemNetNode::setSpecificAttribute( QString & , QString & ) { } diff --git a/noncore/settings/networksettings2/modem/modem_NN.h b/noncore/settings/networksettings2/modem/modem_NN.h index 2f496dd..a76525f 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.h +++ b/noncore/settings/networksettings2/modem/modem_NN.h @@ -18,18 +18,10 @@ public: { return "Devices/modem"; } virtual const QString nodeDescription() ; - virtual ANetNodeInstance * createInstance( void ); - virtual const char ** needs( void ); virtual const char * provides( void ); - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/modem/modem_NNI.cpp b/noncore/settings/networksettings2/modem/modem_NNI.cpp index 6c76b56..91df22b 100644 --- a/noncore/settings/networksettings2/modem/modem_NNI.cpp +++ b/noncore/settings/networksettings2/modem/modem_NNI.cpp @@ -29,9 +29,3 @@ void AModem::commit( void ) { setModified( 1 ); } -bool AModem::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/modem/modem_NNI.h b/noncore/settings/networksettings2/modem/modem_NNI.h index a623704..ca7c279 100644 --- a/noncore/settings/networksettings2/modem/modem_NNI.h +++ b/noncore/settings/networksettings2/modem/modem_NNI.h @@ -14,24 +14,18 @@ public : AModem( ModemNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new ModemRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new ModemRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/modem/modemrun.h b/noncore/settings/networksettings2/modem/modemrun.h index 336462e..491a677 100644 --- a/noncore/settings/networksettings2/modem/modemrun.h +++ b/noncore/settings/networksettings2/modem/modemrun.h @@ -12,6 +12,9 @@ public : virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ) + { return QString("/dev/modem"); } + protected : void detectState( NodeCollection * ) diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index b4313c4..1feffdb 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp @@ -1,3 +1,4 @@ +#include <asdevice.h> #include "network_NN.h" #include "network_NNI.h" @@ -30,23 +31,42 @@ ANetNodeInstance * NetworkNetNode::createInstance( void ) { return new ANetwork( this ); } -const char ** NetworkNetNode::needs( void ) { - return NetworkNeeds; +bool NetworkNetNode::hasDataForFile( const QString & S ) { + return S == "interfaces"; } -const char * NetworkNetNode::provides( void ) { - return "connection"; +short NetworkNetNode::generateFile( const QString & ID, + const QString & , + QTextStream & TS, + ANetNodeInstance * NNI, + long DevNr ) { + + QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); + + if( ID == "interfaces" ) { + Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() )); + // generate mapping stanza for this interface + TS << "# check if " + << NIC + << " can be brought UP" + << endl; + TS << "mapping " + << NIC + << endl; + TS << " script networksettings2-request" + << endl + << endl; + return 0; + } + return 1; } -bool NetworkNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; +const char ** NetworkNetNode::needs( void ) { + return NetworkNeeds; } -bool NetworkNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; +const char * NetworkNetNode::provides( void ) { + return "connection"; } void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { diff --git a/noncore/settings/networksettings2/network/network_NN.h b/noncore/settings/networksettings2/network/network_NN.h index 6548c32..745d1a7 100644 --- a/noncore/settings/networksettings2/network/network_NN.h +++ b/noncore/settings/networksettings2/network/network_NN.h @@ -7,28 +7,27 @@ class ANetwork; class NetworkNetNode : public ANetNode{ - Q_OBJECT + Q_OBJECT public: - NetworkNetNode(); - virtual ~NetworkNetNode(); + NetworkNetNode(); + virtual ~NetworkNetNode(); - virtual const QString pixmapName() - { return "Devices/tcpip"; } + virtual bool hasDataForFile( const QString & S ); - virtual const QString nodeDescription() ; + virtual short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + ANetNodeInstance * NNI, + long DevNr ); + virtual const QString pixmapName() + { return "Devices/tcpip"; } - virtual ANetNodeInstance * createInstance( void ); - - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 3e368a2..324c6e2 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp @@ -99,57 +99,71 @@ void ANetwork::commit( void ) { setModified( 1 ); } -bool ANetwork::hasDataFor( const QString & S ) { +bool ANetwork::hasDataForFile( const QString & S ) { return S == "interfaces"; } -bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { +short ANetwork::generateFile( const QString & ID, + const QString & Path, + QTextStream &TS, + long DevNr + ) { + + short rvl, rvd ; QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); - if( S.name() == "interfaces" ) { + rvl = 1; + if( ID == "interfaces" ) { + Log(("Generate Network for %s\n", ID.latin1() )); // we can safely call from here since device item is deeper if( Data.UseDHCP ) { - S << "iface " - << NIC - << "-c" - << connection()->number() - << "-allowed inet dhcp" - << endl; - S << " up echo \"" - << NIC - << "\" > /tmp/profile-" - << connection()->number() - << ".up" - << endl; + TS << "iface " + << NIC + << "-c" + << connection()->number() + << "-allowed inet dhcp" + << endl; + TS << " up echo \"" + << NIC + << "\" > /tmp/profile-" + << connection()->number() + << ".up" + << endl; if( Data.SendHostname ) { - S << " hostname " - << Data.Hostname - << endl; + TS << " hostname " + << Data.Hostname + << endl; } - S << " down rm -f /tmp/profile-" - << connection()->number() - << ".up" - << endl; + TS << " down rm -f /tmp/profile-" + << connection()->number() + << ".up" + << endl; } else { - S << "iface " - << NIC << "-c" - << connection()->number() - << "-allowed inet static" - << endl; - S << " up echo \"" - << NIC - << "\" > /tmp/profile-" - << connection()->number() - << ".up" - << endl; - S << " down rm -f /tmp/profile-" - << connection()->number() - << ".up" - << endl; - S << " address " << Data.IPAddress << endl; - S << " broadcast " << Data.Broadcast << endl; - S << " netmask " << Data.NetMask << endl; + TS << "iface " + << NIC << "-c" + << connection()->number() + << "-allowed inet static" + << endl; + TS << " up echo \"" + << NIC + << "\" > /tmp/profile-" + << connection()->number() + << ".up" + << endl; + TS << " down rm -f /tmp/profile-" + << connection()->number() + << ".up" + << endl; + TS << " address " + << Data.IPAddress + << endl; + TS << " broadcast " + << Data.Broadcast + << endl; + TS << " netmask " + << Data.NetMask + << endl; // derive network address = IPAddress & netmask { QString NW; @@ -161,29 +175,45 @@ bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { arg( ipal[1].toShort() & nmal[1].toShort() ). arg( ipal[2].toShort() & nmal[2].toShort() ). arg( ipal[3].toShort() & nmal[3].toShort() ); - S << " network " << NW << endl; + TS << " network " + << NW + << endl; } } for ( QStringList::Iterator it = Data.PreUp_SL.begin(); it != Data.PreUp_SL.end(); ++it ) { - S << " pre-up " << (*it) << endl; + TS << " pre-up " + << (*it) + << endl; } for ( QStringList::Iterator it = Data.PostUp_SL.begin(); it != Data.PostUp_SL.end(); ++it ) { - S << " up " << (*it) << endl; + TS << " up " + << (*it) + << endl; } for ( QStringList::Iterator it = Data.PreDown_SL.begin(); it != Data.PreDown_SL.end(); ++it ) { - S << " down " << (*it) << endl; + TS << " down " + << (*it) + << endl; } for ( QStringList::Iterator it = Data.PostDown_SL.begin(); it != Data.PostDown_SL.end(); ++it ) { - S << " post-down " << (*it) << endl; + TS << " post-down " + << (*it) + << endl; } + rvl = 0; } - return 0; + + // embed other info in it + rvd = connection()->getToplevel()->generateFileEmbedded( ID, Path, TS, DevNr ); + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/network/network_NNI.h b/noncore/settings/networksettings2/network/network_NNI.h index 0058793..5e42503 100644 --- a/noncore/settings/networksettings2/network/network_NNI.h +++ b/noncore/settings/networksettings2/network/network_NNI.h @@ -15,22 +15,23 @@ public : ANetwork( NetworkNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new NetworkRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new NetworkRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual bool hasDataForFile( const QString & S ); + virtual short generateFile( const QString & ID, + const QString & Path, + QTextStream &TS, + long DevNr ); protected : diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index 6ee4106..ce0eabc 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,5 +1,6 @@ #include <stdio.h> #include <unistd.h> +#include <errno.h> #include <qpe/qpeapplication.h> #include <qlistbox.h> @@ -12,6 +13,7 @@ #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> +#include <qevent.h> #include <asdevice.h> #include "networksettings.h" @@ -41,6 +43,13 @@ NetworkSettings::NetworkSettings( QWidget *parent, // populate main Listbox Profiles_LB->clear(); + QPEApplication::setStylusOperation( + Profiles_LB->viewport(), QPEApplication::RightOnHold ); + + connect( Profiles_LB, + SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), + this, SLOT(SLOT_EditNode(QListBoxItem*)) ); + { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections @@ -78,22 +87,18 @@ NetworkSettings::NetworkSettings( QWidget *parent, NetworkSettings::~NetworkSettings() { QString S; - S = NSD.generateSettings(); - if( ! S.isEmpty() ) { - QMessageBox::warning( - 0, - tr( "In System Config" ), - S - ); - } + if( isModified() ) { + S = NSD.saveSettings(); + if( ! S.isEmpty() ) { + // problem saving + QMessageBox::warning( + 0, + tr( "Saving setup" ), S ); + } - S = NSD.saveSettings(); - if( ! S.isEmpty() ) { - // problem saving - QMessageBox::warning( - 0, - tr( "Saving setup" ), S ); + SLOT_GenerateConfig(); } + } void NetworkSettings::SLOT_CmdMessage( const QString & S ) { @@ -145,9 +150,6 @@ void NetworkSettings::SLOT_RefreshStates( void ) { */ } -void NetworkSettings::SLOT_NoLongerBusy( void ) { - NSResources->busy( FALSE ); -} void NetworkSettings::SLOT_AddNode( void ) { SLOT_EditNode( 0 ); } @@ -166,12 +168,13 @@ void NetworkSettings::SLOT_DeleteNode( void ) { NSResources->removeConnection( LBI->text() ); delete LBI; setModified( 1 ); - NSD.forceGeneration(1); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; + + printf( "------------------ Edit NOde\n" ); EditConnection EC( this ); if( LBI ) { @@ -186,8 +189,7 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); - NSResources->busy( TRUE ); - QTimer::singleShot( 1000, this, SLOT( SLOT_NoLongerBusy() )); + // we need to retry while( 1 ) { if( EC.exec() == QDialog::Accepted ) { @@ -319,15 +321,7 @@ void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { } void NetworkSettings::SLOT_GenerateConfig( void ) { - QString S = NSD.generateSettings( TRUE ); - - if( ! S.isEmpty() ) { - QMessageBox::warning( - 0, - tr( "Generating system configuration" ), - S - ); - } + NSD.regenerate(); } void NetworkSettings::SLOT_Enable( void ) { diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h index 8ffde06..8ec5d08 100644 --- a/noncore/settings/networksettings2/networksettings.h +++ b/noncore/settings/networksettings2/networksettings.h @@ -6,6 +6,7 @@ class ANetNode; class ANetNodeInstance; class QTimer; class QListBoxItem; +class QEvent; class NetworkSettings : public NetworkSettingsGUI { @@ -28,7 +29,6 @@ public : public slots : - void SLOT_NoLongerBusy( void ); void SLOT_AddNode( void ); void SLOT_DeleteNode( void ); void SLOT_ShowNode( QListBoxItem * ); @@ -50,5 +50,4 @@ private : void updateProfileState( QListBoxItem * it ); QTimer * UpdateTimer; NetworkSettingsData NSD; - }; diff --git a/noncore/settings/networksettings2/networksettings.pro b/noncore/settings/networksettings2/networksettings.pro index ff147b1..f04289b 100644 --- a/noncore/settings/networksettings2/networksettings.pro +++ b/noncore/settings/networksettings2/networksettings.pro @@ -3,17 +3,20 @@ CONFIG = qt warn_on debug #CONFIG = qt warn_on release HEADERS = networksettings.h \ activateprofile.h \ + activatevpn.h \ editconnection.h SOURCES = main.cpp \ networksettings.cpp \ nsdata.cpp \ activateprofile.cpp \ + activatevpn.cpp \ editconnection.cpp INCLUDEPATH += $(OPIEDIR)/include networksettings2/ DEPENDPATH += $(OPIEDIR)/include networksettings2/ LIBS += -lqpe -L$(OPIEDIR)/plugins/networksettings2 -lnetworksettings2 -lopiecore2 INTERFACES = networksettingsGUI.ui \ editconnectionGUI.ui \ + activatevpnGUI.ui \ activateprofileGUI.ui TARGET = $(OPIEDIR)/bin/networksettings2 diff --git a/noncore/settings/networksettings2/networksettings2/Utils.h b/noncore/settings/networksettings2/networksettings2/Utils.h index 63ef51c..739476e 100644 --- a/noncore/settings/networksettings2/networksettings2/Utils.h +++ b/noncore/settings/networksettings2/networksettings2/Utils.h @@ -4,5 +4,6 @@ #define Log(x) VLog x extern void VLog( char * Format, ... ); extern void LogClose( void ); +extern QString removeSpaces( const QString & X ); #endif diff --git a/noncore/settings/networksettings2/networksettings2/asline.h b/noncore/settings/networksettings2/networksettings2/asline.h index 6bd93ec..ee4de38 100644 --- a/noncore/settings/networksettings2/networksettings2/asline.h +++ b/noncore/settings/networksettings2/networksettings2/asline.h @@ -13,6 +13,8 @@ public : RuntimeInfo( NNI ) { } + virtual QString deviceFile( void ) = 0; + }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 8c80e0b..4a2440a 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -144,7 +144,7 @@ NodeCollection::NodeCollection( QTextStream & TS ) : if( A == "name" ) { Name = N; } else if( A == "number" ) { - Log(( "read number %s\n", N.latin1() )); + Log(( "Profile number %s\n", N.latin1() )); setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); @@ -295,8 +295,27 @@ void NodeCollection::reassign( void ) { } bool NodeCollection::triggersVPN() { - return getToplevel()->runtime()->asFullSetup()->triggersVPN(); + return getToplevel()->runtime()->asFullSetup()->triggersVPN(); } + +bool NodeCollection::hasDataForFile( const QString & S ) { + return ( firstWithDataForFile( S ) != 0 ); +} + +ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) { + for( QListIterator<ANetNodeInstance> it(*this); + it.current(); + ++it ) { + if( it.current()->hasDataForFile( S ) ) { + Log(( "Node %s has data for %s\n", + it.current()->nodeClass()->name(), + S.latin1() )); + return it.current(); + } + } + return 0; +} + // // // RUNTIMEINFO diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index ca35c27..d3d7b34 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -5,6 +5,7 @@ #include <qlist.h> #include <qdict.h> #include <qpixmap.h> +#include <qstringlist.h> #include <qobject.h> #include <time.h> @@ -32,106 +33,146 @@ extern QString quote( QString X ); #include "systemfile.h" typedef enum State { - // if we have not yet detected the state of the device - Unchecked = 0, - // if we cannot determine the state - Unknown = 1, - // if connection cannot be established e.g. because - // the hardware is not available - Unavailable = 2, - // if the connection cannot be establishec but NOT - // because it is physically impossible but because - // it has been disabled for FUNCTIONAL reasons - Disabled = 3, - // if connection is available to is currently down - // i.e. the corresponding hardware is not activated - Off = 4, - // if connection is available to be used (i.e. the - // devices if fully ready to be used - Available = 5, - // if connection is being used - IsUp = 6 + // if we have not yet detected the state of the device + Unchecked = 0, + // if we cannot determine the state + Unknown = 1, + // if connection cannot be established e.g. because + // the hardware is not available + Unavailable = 2, + // if the connection cannot be establishec but NOT + // because it is physically impossible but because + // it has been disabled for FUNCTIONAL reasons + Disabled = 3, + // if connection is available to is currently down + // i.e. the corresponding hardware is not activated + Off = 4, + // if connection is available to be used (i.e. the + // devices if fully ready to be used + Available = 5, + // if connection is being used + IsUp = 6 } State_t; typedef enum Action { - // to make the device unavailable functionally - Disable = 0, - // to make the device available functionally - Enable = 1, - // bring the hardware up - Activate = 2, - // bring the hardware down - Deactivate = 3, - // bring the connection up - Up = 4, - // bring the connection down - Down = 5 + // to make the device unavailable functionally + Disable = 0, + // to make the device available functionally + Enable = 1, + // bring the hardware up + Activate = 2, + // bring the hardware down + Deactivate = 3, + // bring the connection up + Up = 4, + // bring the connection down + Down = 5 } Action_t; class ANetNode : public QObject{ public: - typedef QArray<ANetNode *> NetNodeList; - - ANetNode( const char * Name ) : QObject( 0, Name ) {} - virtual ~ANetNode(){}; - - // pixmap needed for this NetNode - virtual const QString pixmapName() = 0; - - // description for this NetNode - virtual const QString nodeDescription() = 0; - - // create a blank instance of a net node - virtual ANetNodeInstance * createInstance( void ) = 0; - - // return feature this NetNode provides - virtual const char * provides( void ) = 0; - virtual const char ** needs( void ) = 0; - - // generate files specific for this node (if any) - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; - // return TRUE if this node has data to be inserted in systemfile - // with name S - virtual bool hasDataFor( const QString & S ) = 0; - // generate data specific for the device for the system file S - // called only IF data was needed - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ) = 0; - - // does this Node provide a Connection - bool isToplevel( void ) - { return strcmp( provides(), "fullsetup") == 0 ; } - - // generate NIC name based on instance nr - // only relevant if node instances are devices - virtual QString genNic( long ) - { return QString(""); } - - // max number of instances for this node type - // only relevant if node instances are devices - virtual long instanceCount( void ) - { return 1; } - - // set the value of an attribute - void setAttribute( QString & Attr, QString & Value ) ; - void saveAttributes( QTextStream & TS ) ; - - // compiled references to 'needed' NetNodes -> needs list - void setAlternatives( NetNodeList * Alt ) - { Alternatives = Alt; } - NetNodeList & alternatives( void ) - { return *Alternatives; } + typedef QArray<ANetNode *> NetNodeList; + + ANetNode( const char * Name ) : QObject( 0, Name ) {} + virtual ~ANetNode(){}; + + // + // + // standard methods with sensible default + // + // + + inline int done( void ) + { return Done; } + inline void setDone( int D ) + { Done = D; } + + // does this Node provide a Connection + inline bool isToplevel( void ) + { return strcmp( provides(), "fullsetup") == 0 ; } + + // set the value of an attribute + void setAttribute( QString & Attr, QString & Value ) ; + void saveAttributes( QTextStream & TS ) ; + + // compiled references to 'needed' NetNodes -> needs list + inline void setAlternatives( NetNodeList * Alt ) + { Alternatives = Alt; } + inline NetNodeList & alternatives( void ) + { return *Alternatives; } + + // + // + // Virtual methods with sensible default + // + // + + // do instances of this noce class have data for this file + virtual bool hasDataForFile( const QString & ) + { return 0; } + + // generate instance independent stuff + // 0 : data output, 1 no data, 2 error + virtual short generateFile( const QString & , + const QString & , + QTextStream & , + long ) + { return 1; } + + // generate instance dependent but profile common stuff + // 0 : data output, 1 no data, 2 error + virtual short generateFile( const QString & , + const QString & , + QTextStream & , + ANetNodeInstance * , + long ) + { return 1; } + + + // generate NIC name based on instance nr + // only relevant if node instances are devices + virtual QString genNic( long ) + { return QString(""); } + + // max number of instances for this node type + // only relevant if node instances are devices + virtual long instanceCount( void ) + { return 1; } + + // return list of files that are specific for this node class + virtual QStringList * properFiles( void ) + { return 0; } + + // + // + // pure virtual methods with sensible default + // + // + + // pixmap needed for this NetNode + virtual const QString pixmapName() = 0; + + // description for this NetNode + virtual const QString nodeDescription() = 0; + + // create a blank instance of a net node + virtual ANetNodeInstance * createInstance( void ) = 0; + + // return feature this NetNode provides + virtual const char * provides( void ) = 0; + virtual const char ** needs( void ) = 0; protected : - NetNodeList * Alternatives; + NetNodeList * Alternatives; private : - virtual void setSpecificAttribute( QString & , QString & ) = 0; - virtual void saveSpecificAttribute( QTextStream & ) = 0; + virtual void setSpecificAttribute( QString & , QString & ) = 0; + virtual void saveSpecificAttribute( QTextStream & ) = 0; + int Done; }; @@ -139,91 +180,138 @@ class ANetNodeInstance : public QObject { public: - ANetNodeInstance( ANetNode * NN ) : QObject() - { IsModified=0; NodeType = NN; IsNew = TRUE; } - virtual ~ANetNodeInstance( void ) { } - - virtual RuntimeInfo * runtime( void ) = 0; - - void setConnection( NodeCollection * NC ) - { Connection = NC; } - NodeCollection * connection( void ) - { return Connection; } - - // create edit widget under parent - virtual QWidget * edit( QWidget * parent ) = 0; - // is given data acceptable - virtual QString acceptable( void ) = 0; - - // return data was modified - void setModified( bool M ) - { IsModified = M; } - bool isModified( void ) - { return IsModified; } - - // get data from GUI and store in node - virtual void commit( void ) = 0; - - // get next node - ANetNodeInstance * nextNode(); - // return NetNode this is an instance of - ANetNode * nodeClass( void ) - { return NodeType; } - - // intialize am instance of a net node - void initialize( void ); - - // set the value of an attribute - void setAttribute( QString & Attr, QString & Value ) ; - void saveAttributes( QTextStream & TS ) ; + ANetNodeInstance( ANetNode * NN ) : QObject() + { IsModified=0; NodeType = NN; IsNew = TRUE; } + virtual ~ANetNodeInstance( void ) { } + + inline int done( void ) + { return Done; } + inline void setDone( int D ) + { Done = D; } + + // return data was modified + inline void setModified( bool M ) + { IsModified = M; } + inline bool isModified( void ) + { return IsModified; } + + // get next node + ANetNodeInstance * nextNode(); + // return NetNode this is an instance of + ANetNode * nodeClass( void ) + { return NodeType; } + + // intialize am instance of a net node + void initialize( void ); + + // set the value of an attribute + void setAttribute( QString & Attr, QString & Value ) ; + void saveAttributes( QTextStream & TS ) ; + + // return true if node isntance is NEW and not loaded + inline void setNew( bool IsN ) + { IsNew = IsN; } + inline bool isNew( void ) + { return IsNew; } + + // return description for this instance + inline QString & description( void ) + { return Description; } + inline void setDescription( const QString & S ) + { Description = S; } + + // pixmap for this instance -> from NetNode + inline const QString pixmapName( void ) + { return NodeType->pixmapName(); } + + inline const char * provides( void ) + { return NodeType->provides(); } + + inline const char ** needs( void ) + { return NodeType->needs(); } + + inline void setConnection( NodeCollection * NC ) + { Connection = NC; } + inline NodeCollection * connection( void ) + { return Connection; } + + // + // + // Virtual methods with sensible defaults + // + // + + + + // open proper file identified by S + virtual QFile * openFile( const QString & ) + { return 0; } + + // check if this node (or sub nodes) have data for this file + virtual bool hasDataForFile( const QString & S ) + { return nodeClass()->hasDataForFile( S ); } + + // generate code specific for this node but embedded + // in the section of the parent + // this is called within the code of the parent + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) + { ANetNodeInstance * NNI = nextNode(); + return (NNI) ? NNI->generateFileEmbedded( ID, Path, TS, DevNr ) : 1; + } - // return true if node isntance is NEW and not loaded - void setNew( bool IsN ) - { IsNew = IsN; } - bool isNew( void ) - { return IsNew; } + // generate code specific for this node + // (or find the first node that does) + virtual short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) + { ANetNodeInstance * NNI = nextNode(); + return (NNI) ? NNI->generateFile( ID, Path, TS, DevNr ) : 1; + } - // return description for this instance - QString & description( void ) - { return Description; } - void setDescription( const QString & S ) - { Description = S; } + // return true if this node instance is triggered by this trigger + // could be delegated to deeper instances + virtual bool triggeredBy( const QString & ) + { return 0; } - // pixmap for this instance -> from NetNode - const QString pixmapName( void ) - { return NodeType->pixmapName(); } + // + // + // Pure virtual functions + // + // - const char * provides( void ) - { return NodeType->provides(); } + // return runtime information for this node + virtual RuntimeInfo * runtime( void ) = 0; - const char ** needs( void ) - { return NodeType->needs(); } + // create edit widget under parent + virtual QWidget * edit( QWidget * parent ) = 0; - // returns node specific data -> only useful for 'buddy' - virtual void * data( void ) = 0; + // is given data acceptable + virtual QString acceptable( void ) = 0; - // return TRUE if this node has data to be inserted in systemfile - // with name S - virtual bool hasDataFor( const QString & S ) = 0; + // get data from GUI and store in node + virtual void commit( void ) = 0; - // generate data specific for a profile and for the system file S - // called only IF data was needed - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ) = 0; + // returns node specific data -> only useful for 'buddy' + virtual void * data( void ) = 0; protected : - virtual void setSpecificAttribute( QString & , QString & ) = 0; - virtual void saveSpecificAttribute( QTextStream & ) = 0; + virtual void setSpecificAttribute( QString & , QString & ) = 0; + virtual void saveSpecificAttribute( QTextStream & ) = 0; - ANetNode * NodeType; - // connection to which this node belongs to - NodeCollection * Connection; - QString Description; - bool IsModified; - bool IsNew; + ANetNode * NodeType; + // connection to which this node belongs to + NodeCollection * Connection; + QString Description; + bool IsModified; + bool IsNew; + int Done; - static long InstanceCounter; + static long InstanceCounter; }; class RuntimeInfo : public QObject { @@ -282,34 +370,39 @@ public : NodeCollection( QTextStream & TS ); ~NodeCollection( void ); - int number( void ) + inline int done( void ) + { return Done; } + inline void setDone( int D ) + { Done = D; } + + inline int number( void ) { return Number; } - void setNumber( int i ) + inline void setNumber( int i ) { Number = i; } - bool isNew( void ) + inline bool isNew( void ) { return IsNew; } - void setNew( bool N ) + inline void setNew( bool N ) { IsNew = N ; } - bool isModified( void ) + inline bool isModified( void ) { return IsModified; } - void setModified( bool N ) + inline void setModified( bool N ) { IsModified = N ; } - bool handlesInterface( const QString & S ) { + inline bool handlesInterface( const QString & S ) { return getToplevel()->runtime()->handlesInterface( S ); } - InterfaceInfo * assignedInterface( void ) { + inline InterfaceInfo * assignedInterface( void ) { return getToplevel()->runtime()->assignedInterface(); } - AsDevice * device() { + inline AsDevice * device() { return getToplevel()->runtime()->device(); } bool triggersVPN(); - State_t state( bool Update = 0 ) + inline State_t state( bool Update = 0 ) { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState, Unchecked )); if( CurrentState == Unchecked || Update ) { @@ -325,15 +418,15 @@ public : // get the ixmap for this device QPixmap devicePixmap( void ); QPixmap statePixmap( State_t S ); - QPixmap statePixmap( bool Update = 0 ) + inline QPixmap statePixmap( bool Update = 0 ) { return statePixmap( state(Update) ); } QString stateName( State_t ); - QString stateName( bool Update = 0 ) + inline QString stateName( bool Update = 0 ) { return stateName( state(Update) ); } - bool setState( Action_t A, bool Force =0 ) + inline bool setState( Action_t A, bool Force =0 ) { return getToplevel()->runtime()->setState( this, A, Force ); } - bool canSetState( Action_t A ) + inline bool canSetState( Action_t A ) { return getToplevel()->runtime()->canSetState( CurrentState, A ); } void save( QTextStream & TS ); @@ -348,19 +441,35 @@ public : ANetNodeInstance * findNext( ANetNodeInstance * NNI ); ANetNodeInstance * findByName( const QString & S ); - const QString & name() + inline const QString & name() { return Name; } const QString & description( void ); - void setName( const QString & N) + inline void setName( const QString & N) { Name = N; } - State_t currentState( void ) + inline State_t currentState( void ) { return CurrentState; } - void setCurrentState( State_t S ) + inline void setCurrentState( State_t S ) { CurrentState = S; } + // return TRUE if this node can have data to be inserted in + // file identified by S + bool hasDataForFile( const QString & S ); + ANetNodeInstance * firstWithDataForFile( const QString & S ); + + // generate items for this file -> toplevel call + short generateFile( const QString & FID, // identification of file + const QString & FName, // effective filename of file + QTextStream & TS, // stream to file + long DN // device number + ) + { return getToplevel()->generateFile( FID, FName, TS, DN ); } + + bool triggeredBy( const QString & Trigger ) + { return getToplevel()->triggeredBy( Trigger ); } + private : int compareItems ( QCollection::Item item1, @@ -378,6 +487,7 @@ private : // index in listbox int Index; bool IsModified; + int Done; }; diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 71e84cd..7ece817 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -77,7 +77,7 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), tr( "<p>Fully configured connection profile</p>" ) ); // define system files - addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); + addSystemFile( "interfaces", "/tmp/interfaces", 1 ); // get access to the system TheSystem = new System(); @@ -88,7 +88,16 @@ TheNSResources::~TheNSResources( void ) { delete TheSystem; } -void TheNSResources::busy( bool B ) { +void TheNSResources::addSystemFile( const QString & ID, + const QString & P, + bool KDI ) { + if( ! SystemFiles.find( ID ) ) { + // new system file + SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); + } // else existed +} + +void TheNSResources::busy( bool ) { /* if( B ) { ShowWait->show(); diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 55d2f29..16355ba 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -66,8 +66,9 @@ public : Name2SystemFile_t & systemFiles( void ) { return SystemFiles; } - void addSystemFile( SystemFile * SF ) - { SystemFiles.insert( SF->name(), SF ); } + void addSystemFile( const QString & ID, + const QString & P, + bool KDI ); ANetNodeInstance * createNodeInstance( const QString & S ) { ANetNodeInstance * NNI = 0; diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index a579396..271e73d 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -390,8 +390,11 @@ void VLog( char * Format, ... ) { va_start(l, Format ); if( logf == (FILE *)0 ) { - // logf = fopen( "/tmp/ns2log", "a" ); - logf = stderr; + if( getenv("NS2STDERR") ) { + logf = stderr; + } else { + logf = fopen( "/tmp/ns2log", "a" ); + } if( ! logf ) { fprintf( stderr, "Cannot open logfile /tmp/ns2log %d\n", errno ); @@ -411,7 +414,16 @@ void VLog( char * Format, ... ) { void LogClose( void ) { if( (long)logf > 1 ) { fprintf( logf, "____ CLOSE LOGFILE ____\n"); - fclose( logf ); + if( logf != stderr ) { + fclose( logf ); + } logf = 0; } } + +QString removeSpaces( const QString & X ) { + QStringList SL; + + SL = QStringList::split( " ", X ); + return SL.join( "_" ); +} diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index b3fc1a5..2b40834 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -11,7 +11,9 @@ #define TEMPLATEDIR "networktemplates/" QString TemplDir; -SystemFile::SystemFile( const QString & N, const QString & P ){ +SystemFile::SystemFile( const QString & N, + const QString & P, + bool KDI ){ Name = N; Path = P; F = 0; @@ -57,6 +59,8 @@ SystemFile::SystemFile( const QString & N, const QString & P ){ FI.setFile( S ); hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); } + + KnowsDeviceInstances = KDI; } SystemFile::~SystemFile( void ) { @@ -96,29 +100,29 @@ bool SystemFile::preSection( void ) { if( hasPreSection ) { QFile Fl( TemplDir + Name + "/presection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); } - return 0; + return 1; } bool SystemFile::postSection( void ) { if( hasPostSection ) { QFile Fl( TemplDir + Name + "/postsection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); } - return 0; + return 1; } bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { if( hasPreNodeSection ) { QFile Fl( TemplDir + Name + "/prenodesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); @@ -129,14 +133,14 @@ bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { S = TX.readLine(); } } - return 0; + return 1; } bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { if( hasPostNodeSection ) { QFile Fl( TemplDir + Name + "/postnodesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); @@ -147,14 +151,14 @@ bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { S = TX.readLine(); } } - return 0; + return 1; } bool SystemFile::preDeviceSection( ANetNode * NN ) { if( hasPreDeviceSection ) { QFile Fl( TemplDir + Name + "/predevicesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); @@ -164,14 +168,14 @@ bool SystemFile::preDeviceSection( ANetNode * NN ) { S = TX.readLine(); } } - return 0; + return 1; } bool SystemFile::postDeviceSection( ANetNode * NN ) { if( hasPostDeviceSection ) { QFile Fl( TemplDir + Name + "/postdevicesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); @@ -181,5 +185,5 @@ bool SystemFile::postDeviceSection( ANetNode * NN ) { S = TX.readLine(); } } - return 0; + return 1; } diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.h b/noncore/settings/networksettings2/networksettings2/systemfile.h index f57dab0..ceed605 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.h +++ b/noncore/settings/networksettings2/networksettings2/systemfile.h @@ -11,11 +11,17 @@ class SystemFile : public QTextStream { public : - SystemFile( const QString & Name, const QString & Path ); + SystemFile( const QString & Name, + const QString & Path, + bool KnowsDevicesInstances ); ~SystemFile( void ); - const QString & name( void ) + const QString & name( void ) const { return Name; } + const QString & path( void ) const + { return Path; } + bool knowsDeviceInstances( void ) const + { return KnowsDeviceInstances; } bool open( void ); bool close( void ); @@ -38,6 +44,7 @@ private : bool hasPostNodeSection; bool hasPreDeviceSection; bool hasPostDeviceSection; + bool KnowsDeviceInstances; }; #endif 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 ) { Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings - Force = 0; IsModified = 0; loadSettings(); } @@ -218,166 +217,288 @@ QString NetworkSettingsData::saveSettings( void ) { 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; + Name2SystemFile_t & SFM = NSResources->systemFiles(); + Name2Connection_t & M = NSResources->connections(); + NodeCollection * NC; + ANetNodeInstance * NNI; + ANetNodeInstance * FirstWithData; + SystemFile * SF; + AsDevice * CurDev; + ANetNode * NN, * CurDevNN = 0; + long NoOfDevs; + long DevCtStart; + bool needToGenerate; // regenerate system files Log( ( "Generating settings from %s\n", CfgFile.latin1() )); - { Name2SystemFile_t & SFM = NSResources->systemFiles(); - Name2Connection_t & M = NSResources->connections(); - NodeCollection * NC; - ANetNodeInstance * NNI; - SystemFile * SF; - AsDevice * CurDev; - ANetNode * CurDevNN; - bool needToRegenerate = ForceIt; - - // - // 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; + // + // generate files proper to each netnodeinstance + // + { Name2Instance_t & NNIs = NSResources->netNodeInstances(); + + for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); + NNIIt.current(); + ++NNIIt ) { + // for all nodes find those that are modified + NNI = NNIIt.current(); + + { // 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; } } - if( needToRegenerate ) - break; } - if( needToRegenerate ) - break; } } + } - // - // generate files proper to each netnodeinstance - // - { Name2Instance_t & NNIs = NSResources->netNodeInstances(); - - for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); - NNIIt.current(); - ++NNIIt - ){ - // for all nodes find those that are modified - NNI = NNIIt.current(); - - if( ForceIt || NNI->isModified() ) { - if( NNI->nodeClass()->generateProperFilesFor( NNI ) ) { - // problem generating - S = qApp->translate( "NetworkSettings", - "<p>Cannot generate files proper to \"%1\"</p>" ). - arg(NNI->nodeClass()->name()) ; - return S; + // + // generate all system files + // + for( QDictIterator<SystemFile> sfit(SFM); + sfit.current(); + ++sfit ) { + SF = sfit.current(); + + // reset all + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + nnit.current(); + ++nnit ) { + nnit.current()->NetNode->setDone(0); + } + + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + nniit.current(); + ++nniit ) { + nniit.current()->setDone(0); + } + + for( QDictIterator<NodeCollection> ncit(M); + ncit.current(); + ++ncit ) { + ncit.current()->setDone(0); + } + + 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 ) { + + NN = nnit.current()->NetNode; + + if( NN->hasDataForFile( SF->name() ) ) { + // 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; } } } } - // - // generate all system files - // - for( QDictIterator<SystemFile> sfit(SFM); - sfit.current(); - ++sfit ) { - SF = sfit.current(); + 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; + } - Log( ( "Generating %s\n", SF->name().latin1() )); - SF->open(); + // ok generate this system file + SF->open(); - do { // so we can break; + // 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; + } - // global presection for this system file - if( SF->preSection() ) { + // 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 preSection for file \"%1\"</p>" ). + "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } - // find all netnodes and figure out if - // for that node there are instances - for( QDictIterator<NetNode_t> nnit( - NSResources->netNodes() ); - nnit.current(); - ++nnit ) { - - CurDevNN = nnit.current()->NetNode; - - // are there instances for this netnode ? - NNI = 0; - for( QDictIterator<ANetNodeInstance> nniit( - NSResources->netNodeInstances() ); - nniit.current(); - ++nniit ) { - if( nniit.current()->nodeClass() == CurDevNN ) { - NNI = nniit.current(); - break; - } + 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(); + } + + 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 section \"Device\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; } + } + CurDev->netNode()->nodeClass()->setDone( 1 ); + } - if( ! NNI ) - // no instances -> next netnode type - continue; + // generate profile specific info + // for all nodeconnections that work on the same device + for( QDictIterator<NodeCollection> ncit2(M); + ncit2.current(); + ++ncit2 ) { - // 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() ) - return S; - } - } else { - S = generateSystemFileNode( *SF, 0, NNI, -1 ); - if( ! S.isEmpty() ) + 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->postSection() ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in postSection for file \"%1\"</p>" ). - arg( SF->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; + } } - } while( 0 ); - SF->close(); + 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(); } - Force = 0; return S; } @@ -463,111 +584,10 @@ bool NetworkSettingsData::canStart( const char * Interface ) { */ 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; -} diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index 57eb722..507185e 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h @@ -13,7 +13,7 @@ public : void loadSettings( void ); QString saveSettings( void ); - QString generateSettings( bool Force = FALSE ); + QString generateSettings( void ); bool isModified( void ) { return IsModified; } @@ -25,18 +25,9 @@ public : bool canStart( const char * Interface ); bool regenerate( void ); - void forceGeneration( bool m ) - { Force = m; } - private : - QString NetworkSettingsData::generateSystemFileNode( - SystemFile & SF, - AsDevice * CurDev, - ANetNodeInstance * DevNNI, - long DevInstNr ); bool IsModified; - bool Force; // collect strings in config file nobody wants QStringList LeftOvers; diff --git a/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui b/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui index 826843a..0c5f4c8 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui +++ b/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui @@ -11,7 +11,7 @@ <rect> <x>0</x> <y>0</y> - <width>249</width> + <width>245</width> <height>209</height> </rect> </property> @@ -57,11 +57,11 @@ <vbox> <property stdset="1"> <name>margin</name> - <number>0</number> + <number>3</number> </property> <property stdset="1"> <name>spacing</name> - <number>0</number> + <number>2</number> </property> <widget> <class>QRadioButton</class> @@ -191,15 +191,54 @@ </hbox> </widget> <widget> - <class>QRadioButton</class> + <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>PapChap_RB</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Pap/Chap/EAP</string> + <cstring>Layout3</cstring> </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>Pap_RB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Pap</string> + </property> + </widget> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>Chap_RB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Chap</string> + </property> + </widget> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>EAP_RB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>EAP</string> + </property> + </widget> + </hbox> </widget> <widget> <class>QLayoutWidget</class> @@ -275,9 +314,9 @@ </property> <property stdset="1"> <name>spacing</name> - <number>1</number> + <number>2</number> </property> - <widget row="2" column="0" > + <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> @@ -288,7 +327,7 @@ <string>Server</string> </property> </widget> - <widget row="3" column="0" > + <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> @@ -299,54 +338,25 @@ <string>Secret</string> </property> </widget> - <widget row="0" column="1" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>PAP</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>CHAP</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>EAP</string> - </property> - </item> - <property stdset="1"> - <name>name</name> - <cstring>AuthMethod_CB</cstring> - </property> - </widget> - <widget row="1" column="0" > - <class>QLabel</class> + <widget row="1" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel1</cstring> + <cstring>Server_LE</cstring> </property> <property stdset="1"> <name>text</name> - <string>Client</string> + <string>*</string> </property> </widget> - <widget row="0" column="0" > - <class>QLabel</class> + <widget row="2" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel1_4</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Method</string> + <cstring>Secret_LE</cstring> </property> </widget> - <widget row="1" column="1" rowspan="1" colspan="2" > + <widget row="0" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> @@ -357,45 +367,17 @@ <string>*</string> </property> </widget> - <widget row="2" column="1" rowspan="1" colspan="2" > - <class>QLineEdit</class> + <widget row="0" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>Server_LE</cstring> + <cstring>TextLabel1</cstring> </property> <property stdset="1"> <name>text</name> - <string>*</string> - </property> - </widget> - <widget row="3" column="1" rowspan="1" colspan="2" > - <class>QLineEdit</class> - <property stdset="1"> - <name>name</name> - <cstring>Secret_LE</cstring> + <string>Client</string> </property> </widget> - <spacer row="0" column="2" > - <property> - <name>name</name> - <cstring>Spacer7</cstring> - </property> - <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> </grid> </widget> </hbox> @@ -417,7 +399,7 @@ </widget> <connections> <connection> - <sender>PapChap_RB</sender> + <sender>Pap_RB</sender> <signal>toggled(bool)</signal> <receiver>GroupBox3</receiver> <slot>setEnabled(bool)</slot> @@ -428,5 +410,17 @@ <receiver>GroupBox1</receiver> <slot>setEnabled(bool)</slot> </connection> + <connection> + <sender>Chap_RB</sender> + <signal>toggled(bool)</signal> + <receiver>GroupBox3</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>EAP_RB</sender> + <signal>toggled(bool)</signal> + <receiver>GroupBox3</receiver> + <slot>setEnabled(bool)</slot> + </connection> </connections> </UI> diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp index f305cc4..450d560 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp @@ -9,6 +9,13 @@ PPPAuthEdit::PPPAuthEdit( QWidget * Parent ) : PPPAuthGUI( Parent ){ } +bool PPPAuthEdit::PAP_Checked( void ) { + return ( Pap_RB->isChecked() || + Chap_RB->isChecked() || + EAP_RB->isChecked() + ); +} + QString PPPAuthEdit::acceptable( void ) { if( Login_RB->isChecked() ) { if( LoginSend_LE->text().isEmpty() ) @@ -19,7 +26,7 @@ QString PPPAuthEdit::acceptable( void ) { return tr("Password send missing"); if( PasswordExpect_LE->text().isEmpty() ) return tr("Password expect missing"); - } else if( PapChap_RB->isChecked() ) { + } else if( PAP_Checked() ) { if( Client_LE->text().isEmpty() ) return tr("Pap/Chap/EAP client id missing"); if( Server_LE->text().isEmpty() ) @@ -34,14 +41,13 @@ bool PPPAuthEdit::commit( PPPData_t & D ) { bool SM = 0; if( ( D.Auth.Mode == 0 && ! Login_RB->isChecked() ) || - ( D.Auth.Mode == 1 && ! PapChap_RB->isChecked() ) || + ( D.Auth.Mode == 1 && ! PAP_Checked() ) || ( D.Auth.Mode == 2 && ! Terminal_RB->isChecked() ) ) { // mode modifed SM = 1; D.Auth.Mode = ( Login_RB->isChecked() ) ? 0 : - ( ( PapChap_RB->isChecked() ) ? - 1 : 2 ); + ( PAP_Checked() ) ? 1 : 2; } if( Login_RB->isChecked() ) { @@ -49,11 +55,17 @@ bool PPPAuthEdit::commit( PPPData_t & D ) { TXTM( D.Auth.Login.Send, LoginSend_LE, SM ); TXTM( D.Auth.Password.Expect, PasswordExpect_LE, SM ); TXTM( D.Auth.Password.Send, PasswordSend_LE, SM ); - } else if( PapChap_RB->isChecked() ) { + } else if( PAP_Checked() ) { TXTM( D.Auth.Client, Client_LE, SM ); TXTM( D.Auth.Server, Server_LE, SM ); TXTM( D.Auth.Secret, Secret_LE, SM ); - CIM( D.Auth.PCEMode, AuthMethod_CB, SM ); + if( Pap_RB->isChecked() ) { + D.Auth.PCEMode = 0; + } else if( Chap_RB->isChecked() ) { + D.Auth.PCEMode = 1; + } else if( EAP_RB->isChecked() ) { + D.Auth.PCEMode = 2; + } } return SM; } @@ -62,13 +74,23 @@ void PPPAuthEdit::showData( PPPData_t & D ) { switch( D.Auth.Mode ) { case 0 : - Login_RB->isChecked(); + Login_RB->setChecked( TRUE ); break; case 1 : - PapChap_RB->isChecked(); + switch( D.Auth.PCEMode ) { + case 0 : + Pap_RB->setChecked( TRUE ); + break; + case 1 : + Chap_RB->setChecked( TRUE ); + break; + case 2 : + EAP_RB->setChecked( TRUE ); + break; + } break; case 2 : - Terminal_RB->isChecked(); + Terminal_RB->setChecked( TRUE ); break; } @@ -80,6 +102,4 @@ void PPPAuthEdit::showData( PPPData_t & D ) { Client_LE->setText( D.Auth.Client ); Server_LE->setText( D.Auth.Server ); Secret_LE->setText( D.Auth.Secret ); - - AuthMethod_CB->setCurrentItem( D.Auth.PCEMode ); } diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.h b/noncore/settings/networksettings2/ppp/PPPAuthedit.h index cbd540e..2392569 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.h +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.h @@ -9,6 +9,8 @@ public : QString acceptable( void ); bool commit( PPPData_t & Data ); void showData( PPPData_t & Data ); + bool PAP_Checked( void ); + private : diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index b7edf87..ff4465c 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp @@ -1,6 +1,10 @@ +#include <qfile.h> +#include <qtextstream.h> #include "ppp_NN.h" #include "ppp_NNI.h" +QStringList * PPPNetNode::ProperFiles = 0; + static const char * PPPNeeds[] = { "line", "modem", @@ -11,6 +15,17 @@ static const char * PPPNeeds[] = * Constructor, find all of the possible interfaces */ PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { + + // proper files : will leak + ProperFiles =new QStringList; + *ProperFiles << "peers"; + *ProperFiles << "chatscript"; + + // system files + NSResources->addSystemFile( + "pap-secrets", "/tmp/pap-secrets", 0 ); + NSResources->addSystemFile( + "chap-secrets", "/tmp/chap-secrets", 0 ); } /** @@ -39,15 +54,17 @@ const char * PPPNetNode::provides( void ) { return "connection"; } -bool PPPNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; +QStringList * PPPNetNode::properFiles( void ) { + return ProperFiles; + } -bool PPPNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; +// need to generate : +// /etc/ppp/pap-secrets +// /etc/ppp/pap-secrets +bool PPPNetNode::hasDataForFile( const QString & S ) { + return S == "pap-secrets" || + S == "chap-secrets" ; } QString PPPNetNode::genNic( long NicNr ) { diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.h b/noncore/settings/networksettings2/ppp/ppp_NN.h index b1483c4..249be5a 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.h +++ b/noncore/settings/networksettings2/ppp/ppp_NN.h @@ -7,35 +7,32 @@ class APPP; class PPPNetNode : public ANetNode{ - Q_OBJECT + Q_OBJECT public: - PPPNetNode(); - virtual ~PPPNetNode(); + PPPNetNode(); + virtual ~PPPNetNode(); - virtual const QString pixmapName() - { return "Devices/ppp"; } + virtual const QString pixmapName() + { return "Devices/ppp"; } - virtual const QString nodeDescription() ; + virtual bool hasDataForFile( const QString & S ); - virtual ANetNodeInstance * createInstance( void ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - - virtual QString genNic( long NicNr ); + virtual QString genNic( long NicNr ); + virtual QStringList * properFiles( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); + + static QStringList * ProperFiles; }; extern "C" diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp index d0fd31c..ba639de 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp @@ -1,3 +1,5 @@ +#include <qfile.h> +#include <qfileinfo.h> #include "PPPedit.h" #include "ppp_NNI.h" #include "ppp_NN.h" @@ -113,9 +115,107 @@ void APPP::commit( void ) { } } -bool APPP::generateDataForCommonFile( - SystemFile & , - long) { - return 1; +QFile * APPP::openFile( const QString & ID ) { + QFile * F = 0; + QString S; + + if( ID == "peers" ) { + S = removeSpaces( QString("/tmp/") + connection()->name() ); + + F = new QFile( S ); + + if( ! F->open( IO_WriteOnly ) ) { + Log(("Cannot open file %s\n", S.latin1() )); + return 0; + } + } else if ( ID == "chatscripts" ) { + S = removeSpaces( QString("/tmp/") + connection()->name() + ".chat" ); + F = new QFile( S ); + + if( ! F->open( IO_WriteOnly ) ) { + Log(("Cannot open file %s\n", S.latin1() )); + return 0; + } + } + if( F ) { + Log(("Generate proper file %s = %s\n", + ID.latin1(), F->name().latin1())); + } + return F; } +short APPP::generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + short rvl, rvd; + + rvl = 1; + rvd = 1; + + if( ID == "pap-secrets" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { + TS << "# secrets for " + << connection()->name().latin1() + << endl; + TS << Data.Auth.Client + << " " + << Data.Auth.Server + << " " + << Data.Auth.Secret + << endl; + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + } else if( ID == "chap-secrets" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { + // used for both EAP and Chap + TS << "# secrets for " + << connection()->name().latin1() + << endl; + TS << Data.Auth.Client + << " " + << Data.Auth.Server + << " " + << Data.Auth.Secret + << endl; + + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + } else if ( ID == "peers" ) { + QFileInfo FI(Path); + Log(("Generate PPP for %s\n", ID.latin1() )); + + TS << "connect \"/usr/sbin/chat -v -f /etc/ppp/" + << FI.baseName() + << ".chat\"" + << endl; + + if( Data.IP.GWIsDefault ) { + TS << "defaultroute" + << endl; + } + + TS << "linkname " + << removeSpaces( ID.latin1() ) + << endl; + + // insert other data here + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } else if ( ID == "chatscripts" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; +} diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.h b/noncore/settings/networksettings2/ppp/ppp_NNI.h index 989c2f0..0bf8fa9 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.h +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.h @@ -7,6 +7,7 @@ class PPPNetNode; class PPPEdit; +class QTextStream; class APPP : public ANetNodeInstance { @@ -14,24 +15,26 @@ public : APPP( PPPNetNode * PNN ); - QWidget * edit( QWidget * parent ); - QString acceptable( void ); - void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) + { if( RT == 0 ) { RT = new PPPRun( this, Data ); + } return RT->runtimeInfo(); } + QWidget * edit( QWidget * parent ); + QString acceptable( void ); + void commit( void ); + virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } + virtual QFile * openFile( const QString & ID ); + short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/profile/profile_NN.cpp b/noncore/settings/networksettings2/profile/profile_NN.cpp index 59c34a3..945b48d 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.cpp +++ b/noncore/settings/networksettings2/profile/profile_NN.cpp @@ -9,7 +9,7 @@ static const char * ProfileNeeds[] = /** * Constructor, find all of the possible interfaces */ -ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular profile")) { +ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular connection profile")) { } /** @@ -38,17 +38,6 @@ const char * ProfileNetNode::provides( void ) { return "fullsetup"; } -bool ProfileNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool ProfileNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void ProfileNetNode::setSpecificAttribute( QString & , QString & ) { } diff --git a/noncore/settings/networksettings2/profile/profile_NN.h b/noncore/settings/networksettings2/profile/profile_NN.h index e602bd7..1f1ee2c 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.h +++ b/noncore/settings/networksettings2/profile/profile_NN.h @@ -18,18 +18,10 @@ public: { return "Devices/commprofile"; } virtual const QString nodeDescription() ; - virtual ANetNodeInstance * createInstance( void ); - virtual const char ** needs( void ); virtual const char * provides( void ); - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr); - private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/profile/profile_NNI.cpp b/noncore/settings/networksettings2/profile/profile_NNI.cpp index cb52b2a..f0f0b97 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.cpp +++ b/noncore/settings/networksettings2/profile/profile_NNI.cpp @@ -50,9 +50,28 @@ void AProfile::commit( void ) { setModified( 1 ); } -bool AProfile::generateDataForCommonFile( - SystemFile & , - long) { - return 1; +short AProfile::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + + short rvl, rvd; + + rvl = 1; + + if( ID == "interfaces" ) { + Log(("Generate Profile for %s\n", ID.latin1() )); + if( Data.TriggerVPN ) { + // this profile triggers VPN -> insert trigger + TS << " up networksettings2 --triggervpn" + << endl; + rvl = 0; + } + } + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; } + + diff --git a/noncore/settings/networksettings2/profile/profile_NNI.h b/noncore/settings/networksettings2/profile/profile_NNI.h index 2c2db7f..957f4af 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.h +++ b/noncore/settings/networksettings2/profile/profile_NNI.h @@ -14,26 +14,25 @@ public : AProfile( ProfileNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new ProfileRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - const QString & description( void ) - { return Data.Description; } - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new ProfileRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr); + const QString & description( void ) + { return Data.Description; } protected : diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index c10a09c..14c479a 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -37,29 +37,6 @@ const char * USBNetNode::provides( void ) { return "device"; } -bool USBNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool USBNetNode::hasDataFor( const QString & S ) { - return (S== "interfaces"); -} - -bool USBNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr ) { - QString NIC = genNic( DevNr ); - - if( S.name() == "interfaces" ) { - // generate mapping stanza for this interface - S << "# check if " << NIC << " can be brought UP" << endl; - S << "mapping " << NIC << endl; - S << " script networksettings2-request" << endl << endl; - } - return 0; -} - QString USBNetNode::genNic( long ) { return QString( "usbf" ); } diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h index fea89f0..73da15a 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -18,17 +18,10 @@ public: { return "Devices/usb"; } virtual const QString nodeDescription() ; - virtual ANetNodeInstance * createInstance( void ); - virtual const char ** needs( void ); virtual const char * provides( void ); - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S); - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - virtual QString genNic( long nr ); private: diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp index e90204c..50c6e8d 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -32,21 +32,30 @@ void AUSB::commit( void ) { } } -bool AUSB::hasDataFor( const QString & S ) { - return (S== "interfaces"); -} - -bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) { +short AUSB::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); + short rvl, rvd; + + rvl = 1; - if( S.name() == "interfaces" ) { + if( ID == "interfaces" ) { + Log(("Generate USB for %s\n", ID.latin1() )); // generate mapping stanza for this interface - S << " pre-up " - << QPEApplication::qpeDir() - << "bin/setmacaddress.sh " - << NIC - << " || true" - << endl; + TS << " pre-up " + << QPEApplication::qpeDir() + << "bin/setmacaddress.sh " + << NIC + << " || true" + << endl; + rvl = 0; } - return 0; + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; + } diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index d2ee217..fcdfd91 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -14,22 +14,22 @@ public : AUSB( USBNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new USBRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new USBRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); protected : diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.cpp b/noncore/settings/networksettings2/vpn/vpn_NN.cpp index 6c7b308..9d3b6e7 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NN.cpp @@ -2,8 +2,7 @@ #include "vpn_NNI.h" static const char * VPNNeeds[] = - { "connection", - 0 + { 0 }; /** @@ -38,17 +37,6 @@ const char * VPNNetNode::provides( void ) { return "connection"; } -bool VPNNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool VPNNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void VPNNetNode::setSpecificAttribute( QString & , QString & ) { } diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.h b/noncore/settings/networksettings2/vpn/vpn_NN.h index 5b6632e..3c7b5e0 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.h +++ b/noncore/settings/networksettings2/vpn/vpn_NN.h @@ -18,18 +18,10 @@ public: { return "Devices/vpn"; } virtual const QString nodeDescription() ; - virtual ANetNodeInstance * createInstance( void ); - virtual const char ** needs( void ); virtual const char * provides( void ); - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/vpn/vpn_NNI.cpp b/noncore/settings/networksettings2/vpn/vpn_NNI.cpp index ee999e8..6c20aeb 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NNI.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NNI.cpp @@ -28,9 +28,3 @@ void AVPN::commit( void ) { setModified( 1 ); } -bool AVPN::generateDataForCommonFile( - SystemFile & , - long) { - return 1; -} - diff --git a/noncore/settings/networksettings2/vpn/vpn_NNI.h b/noncore/settings/networksettings2/vpn/vpn_NNI.h index c3eb016..aee5891 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NNI.h +++ b/noncore/settings/networksettings2/vpn/vpn_NNI.h @@ -14,23 +14,19 @@ public : AVPN( VPNNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new VPNRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new VPNRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.cpp b/noncore/settings/networksettings2/wlan/wlan_NN.cpp index ce8a734..e4c3f60 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NN.cpp @@ -38,29 +38,6 @@ const char * WLanNetNode::provides( void ) { return "device"; } -bool WLanNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool WLanNetNode::hasDataFor( const QString & S ) { - return S == "interfaces"; -} - -bool WLanNetNode::generateDeviceDataForCommonFile( - SystemFile & S, - long DevNr ) { - QString NIC = genNic( DevNr ); - - if( S.name() == "interfaces" ) { - // generate mapping stanza for this interface - S << "# check if " << NIC << " can be brought UP" << endl; - S << "mapping " << NIC << endl; - S << " script networksettings2-request" << endl << endl; - } - return 0; -} - QString WLanNetNode::genNic( long nr ) { QString S; return S.sprintf( "wlan%ld", nr ); diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.h b/noncore/settings/networksettings2/wlan/wlan_NN.h index b5ff3fd..c13c05c 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.h +++ b/noncore/settings/networksettings2/wlan/wlan_NN.h @@ -18,21 +18,12 @@ public: { return "Devices/wlan"; } virtual const QString nodeDescription() ; - virtual ANetNodeInstance * createInstance( void ); - virtual const char ** needs( void ); virtual const char * provides( void ); - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - - virtual bool hasDataFor( const QString & S ); - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - virtual long instanceCount( void ) { return InstanceCount; } - virtual QString genNic( long ); private: diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp index 61969f2..0e4fc4c 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp @@ -79,62 +79,73 @@ void AWLan::commit( void ) { setModified( 1 ); } -bool AWLan::generateDataForCommonFile( - SystemFile & S, - long ) { +short AWLan::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { - S << " wireless_essid \"" - << Data.ESSID - << "\"" - << endl; + short rvl, rvd; - if( ! Data.NodeName.isEmpty() ) { - if( Data.NodeName == tr("<UseHostName>") ) { - char Buf[100]; - if( gethostname(Buf, sizeof(Buf) ) == 0 ) { - Buf[99] = '\0'; // just to make sure - S << " wireless_nick " - << Buf - << endl; + rvl = 1; + + if( ID == "interfaces" ) { + Log(("Generate WLanNNI for %s\n", ID.latin1() )); + TS << " wireless_essid \"" + << Data.ESSID + << "\"" + << endl; + + if( ! Data.NodeName.isEmpty() ) { + if( Data.NodeName == tr("<UseHostName>") ) { + char Buf[100]; + if( gethostname(Buf, sizeof(Buf) ) == 0 ) { + Buf[99] = '\0'; // just to make sure + TS << " wireless_nick " + << Buf + << endl; + } + } else { + TS << " wireless_nick \"" + << Data.NodeName + << "\"" + << endl; } - } else { - S << " wireless_nick \"" - << Data.NodeName - << "\"" - << endl; } - } - char * M; - switch ( Data.Mode ) { - case 0 : - M = "Auto"; - break; - case 1 : - M = "Managed"; - break; - case 2 : - M = "Ad-Hoc"; - break; - } + char * M = "Auto"; + switch ( Data.Mode ) { + case 0 : + break; + case 1 : + M = "Managed"; + break; + case 2 : + M = "Ad-Hoc"; + break; + } - S << " wireless_mode " - << M - << endl; - if( Data.Encrypted ) { - for( int i = 0; i < 4; i ++ ) { - if( ! Data.Key[i].isEmpty() ) { - S << " wireless_key" - << i - << " " - << Data.Key[i] - << endl; + TS << " wireless_mode " + << M + << endl; + if( Data.Encrypted ) { + for( int i = 0; i < 4; i ++ ) { + if( ! Data.Key[i].isEmpty() ) { + TS << " wireless_key" + << i + << " " + << Data.Key[i] + << endl; + } } + TS << " wireless_keymode " + << ((Data.AcceptNonEncrypted) ? "open" : "restricted") + << endl; } - S << " wireless_keymode " - << ((Data.AcceptNonEncrypted) ? "open" : "restricted") - << endl; + rvl = 0; } - return 0; + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr); + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.h b/noncore/settings/networksettings2/wlan/wlan_NNI.h index 2211c47..a9be65f 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.h +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.h @@ -14,23 +14,23 @@ public : AWLan( WLanNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new WLanRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new WLanRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 1; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); + protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); |