author | wimpie <wimpie> | 2005-01-11 15:35:46 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-11 15:35:46 (UTC) |
commit | 4c4cdd76caea5a8be4a971892375c7c6b4f4a8b9 (patch) (unidiff) | |
tree | 0e8adcc616a1d20b637aad3de568dcb45af05f71 | |
parent | 32e8aa951218c0bd6118ee04bb22ef83b3b7ec2e (diff) | |
download | opie-4c4cdd76caea5a8be4a971892375c7c6b4f4a8b9.zip opie-4c4cdd76caea5a8be4a971892375c7c6b4f4a8b9.tar.gz opie-4c4cdd76caea5a8be4a971892375c7c6b4f4a8b9.tar.bz2 |
vpn should now work IF only the vpn plugin would do something.
shortened logical interface names (busybox only supports 10 characters
and then ONLY if you recompile it with mappings enabled)
Other small fixes
14 files changed, 174 insertions, 54 deletions
diff --git a/noncore/settings/networksettings2/activateprofileGUI.ui b/noncore/settings/networksettings2/activateprofileGUI.ui index 12ab051..861ce96 100644 --- a/noncore/settings/networksettings2/activateprofileGUI.ui +++ b/noncore/settings/networksettings2/activateprofileGUI.ui | |||
@@ -1,85 +1,110 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>ActivateProfileGUI</class> | 2 | <class>ActivateProfileGUI</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QDialog</class> | 4 | <class>QDialog</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>ActivateProfileGUI</cstring> | 7 | <cstring>ActivateProfileGUI</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>231</width> | 14 | <width>219</width> |
15 | <height>121</height> | 15 | <height>121</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>Activate Network</string> | 20 | <string>Activate Network</string> |
21 | </property> | 21 | </property> |
22 | <property> | 22 | <property> |
23 | <name>layoutMargin</name> | 23 | <name>layoutMargin</name> |
24 | </property> | 24 | </property> |
25 | <property> | 25 | <property> |
26 | <name>layoutSpacing</name> | 26 | <name>layoutSpacing</name> |
27 | </property> | 27 | </property> |
28 | <vbox> | 28 | <vbox> |
29 | <property stdset="1"> | 29 | <property stdset="1"> |
30 | <name>margin</name> | 30 | <name>margin</name> |
31 | <number>2</number> | 31 | <number>2</number> |
32 | </property> | 32 | </property> |
33 | <property stdset="1"> | 33 | <property stdset="1"> |
34 | <name>spacing</name> | 34 | <name>spacing</name> |
35 | <number>2</number> | 35 | <number>2</number> |
36 | </property> | 36 | </property> |
37 | <widget> | 37 | <widget> |
38 | <class>QLayoutWidget</class> | 38 | <class>QLayoutWidget</class> |
39 | <property stdset="1"> | 39 | <property stdset="1"> |
40 | <name>name</name> | 40 | <name>name</name> |
41 | <cstring>Layout2</cstring> | 41 | <cstring>Layout2</cstring> |
42 | </property> | 42 | </property> |
43 | <property> | ||
44 | <name>layoutSpacing</name> | ||
45 | </property> | ||
43 | <hbox> | 46 | <hbox> |
44 | <property stdset="1"> | 47 | <property stdset="1"> |
45 | <name>margin</name> | 48 | <name>margin</name> |
46 | <number>0</number> | 49 | <number>0</number> |
47 | </property> | 50 | </property> |
48 | <property stdset="1"> | 51 | <property stdset="1"> |
49 | <name>spacing</name> | 52 | <name>spacing</name> |
50 | <number>6</number> | 53 | <number>0</number> |
51 | </property> | 54 | </property> |
52 | <widget> | 55 | <widget> |
53 | <class>QLabel</class> | 56 | <class>QLabel</class> |
54 | <property stdset="1"> | 57 | <property stdset="1"> |
55 | <name>name</name> | 58 | <name>name</name> |
56 | <cstring>TextLabel1</cstring> | 59 | <cstring>TextLabel1</cstring> |
57 | </property> | 60 | </property> |
58 | <property stdset="1"> | 61 | <property stdset="1"> |
62 | <name>sizePolicy</name> | ||
63 | <sizepolicy> | ||
64 | <hsizetype>0</hsizetype> | ||
65 | <vsizetype>1</vsizetype> | ||
66 | </sizepolicy> | ||
67 | </property> | ||
68 | <property stdset="1"> | ||
59 | <name>text</name> | 69 | <name>text</name> |
60 | <string>Select profile to activate for </string> | 70 | <string>Select profile to activate for </string> |
61 | </property> | 71 | </property> |
62 | </widget> | 72 | </widget> |
63 | <widget> | 73 | <widget> |
64 | <class>QLabel</class> | 74 | <class>QLabel</class> |
65 | <property stdset="1"> | 75 | <property stdset="1"> |
66 | <name>name</name> | 76 | <name>name</name> |
67 | <cstring>DeviceName_LBL</cstring> | 77 | <cstring>DeviceName_LBL</cstring> |
68 | </property> | 78 | </property> |
69 | <property stdset="1"> | 79 | <property stdset="1"> |
80 | <name>sizePolicy</name> | ||
81 | <sizepolicy> | ||
82 | <hsizetype>7</hsizetype> | ||
83 | <vsizetype>1</vsizetype> | ||
84 | </sizepolicy> | ||
85 | </property> | ||
86 | <property stdset="1"> | ||
70 | <name>text</name> | 87 | <name>text</name> |
71 | <string>TextLabel2</string> | 88 | <string>TextLabel2</string> |
72 | </property> | 89 | </property> |
73 | </widget> | 90 | </widget> |
74 | </hbox> | 91 | </hbox> |
75 | </widget> | 92 | </widget> |
76 | <widget> | 93 | <widget> |
77 | <class>QListBox</class> | 94 | <class>QListBox</class> |
78 | <property stdset="1"> | 95 | <property stdset="1"> |
79 | <name>name</name> | 96 | <name>name</name> |
80 | <cstring>Profiles_LB</cstring> | 97 | <cstring>Profiles_LB</cstring> |
81 | </property> | 98 | </property> |
82 | </widget> | 99 | </widget> |
83 | </vbox> | 100 | </vbox> |
84 | </widget> | 101 | </widget> |
102 | <connections> | ||
103 | <connection> | ||
104 | <sender>Profiles_LB</sender> | ||
105 | <signal>doubleClicked(QListBoxItem*)</signal> | ||
106 | <receiver>ActivateProfileGUI</receiver> | ||
107 | <slot>accept()</slot> | ||
108 | </connection> | ||
109 | </connections> | ||
85 | </UI> | 110 | </UI> |
diff --git a/noncore/settings/networksettings2/activatevpn.cpp b/noncore/settings/networksettings2/activatevpn.cpp index b75e623..768a031 100644 --- a/noncore/settings/networksettings2/activatevpn.cpp +++ b/noncore/settings/networksettings2/activatevpn.cpp | |||
@@ -1,47 +1,48 @@ | |||
1 | #include <qlistview.h> | 1 | #include <qlistview.h> |
2 | #include <qheader.h> | 2 | #include <qheader.h> |
3 | #include <resources.h> | 3 | #include <resources.h> |
4 | #include "activatevpn.h" | 4 | #include "activatevpn.h" |
5 | 5 | ||
6 | class MyCheckListItem : public QCheckListItem { | 6 | class MyCheckListItem : public QCheckListItem { |
7 | 7 | ||
8 | public : | 8 | public : |
9 | 9 | ||
10 | MyCheckListItem( NodeCollection * N, QListView * V ); | 10 | MyCheckListItem( NodeCollection * N, QListView * V ); |
11 | 11 | ||
12 | NodeCollection * NC; | 12 | NodeCollection * NC; |
13 | 13 | ||
14 | }; | 14 | }; |
15 | 15 | ||
16 | MyCheckListItem::MyCheckListItem( NodeCollection * N, QListView * V ): | 16 | MyCheckListItem::MyCheckListItem( NodeCollection * N, QListView * V ): |
17 | QCheckListItem( V, N->name() ) { | 17 | QCheckListItem( V, N->name() ) { |
18 | NC = N; | 18 | NC = N; |
19 | } | 19 | } |
20 | 20 | ||
21 | ActivateVPN::ActivateVPN( void ) : | 21 | ActivateVPN::ActivateVPN( const QString & I ) : |
22 | ActivateVPNGUI( 0, 0, TRUE ), NSD() { | 22 | ActivateVPNGUI( 0, 0, TRUE ), NSD() { |
23 | 23 | ||
24 | QCheckListItem * CI; | 24 | QCheckListItem * CI; |
25 | VPN_LV->clear(); | 25 | VPN_LV->clear(); |
26 | VPN_LV->header()->hide(); | 26 | VPN_LV->header()->hide(); |
27 | 27 | ||
28 | // find all connections that want to be triggered by this interface | ||
28 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | 29 | for( QDictIterator<NodeCollection> it(NSResources->connections()); |
29 | it.current(); | 30 | it.current(); |
30 | ++it ) { | 31 | ++it ) { |
31 | if( it.current()->triggeredBy( "vpn" ) ) { | 32 | if( it.current()->triggeredBy( I ) ) { |
32 | CI = new MyCheckListItem( it.current(), VPN_LV ); | 33 | CI = new MyCheckListItem( it.current(), VPN_LV ); |
33 | } | 34 | } |
34 | } | 35 | } |
35 | } | 36 | } |
36 | 37 | ||
37 | ActivateVPN::~ActivateVPN( void ) { | 38 | ActivateVPN::~ActivateVPN( void ) { |
38 | } | 39 | } |
39 | 40 | ||
40 | void ActivateVPN::SLOT_ChangedVPNSetting( QListViewItem * I ) { | 41 | void ActivateVPN::SLOT_ChangedVPNSetting( QListViewItem * I ) { |
41 | 42 | ||
42 | MyCheckListItem * MI = (MyCheckListItem *)I; | 43 | MyCheckListItem * MI = (MyCheckListItem *)I; |
43 | 44 | ||
44 | printf( "%s : %d\n", | 45 | printf( "%s : %d\n", |
45 | MI->text(0).latin1(), | 46 | MI->text(0).latin1(), |
46 | MI->isOn() ); | 47 | MI->isOn() ); |
47 | } | 48 | } |
diff --git a/noncore/settings/networksettings2/activatevpn.h b/noncore/settings/networksettings2/activatevpn.h index 5794757..49a940b 100644 --- a/noncore/settings/networksettings2/activatevpn.h +++ b/noncore/settings/networksettings2/activatevpn.h | |||
@@ -1,20 +1,20 @@ | |||
1 | #include "activatevpnGUI.h" | 1 | #include "activatevpnGUI.h" |
2 | #include "nsdata.h" | 2 | #include "nsdata.h" |
3 | 3 | ||
4 | class ActivateVPN : public ActivateVPNGUI { | 4 | class ActivateVPN : public ActivateVPNGUI { |
5 | 5 | ||
6 | Q_OBJECT | 6 | Q_OBJECT |
7 | 7 | ||
8 | public : | 8 | public : |
9 | 9 | ||
10 | ActivateVPN( void ); | 10 | ActivateVPN( const QString & Interface ); |
11 | ~ActivateVPN( void ); | 11 | ~ActivateVPN( void ); |
12 | 12 | ||
13 | public slots : | 13 | public slots : |
14 | 14 | ||
15 | void SLOT_ChangedVPNSetting( QListViewItem * ); | 15 | void SLOT_ChangedVPNSetting( QListViewItem * ); |
16 | 16 | ||
17 | private : | 17 | private : |
18 | 18 | ||
19 | NetworkSettingsData NSD; | 19 | NetworkSettingsData NSD; |
20 | }; | 20 | }; |
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 973b4b7..2243826 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp | |||
@@ -1,163 +1,179 @@ | |||
1 | #include "nsdata.h" | 1 | #include "nsdata.h" |
2 | #include "activateprofile.h" | 2 | #include "activateprofile.h" |
3 | #include "activatevpn.h" | 3 | #include "activatevpn.h" |
4 | #include "networksettings.h" | 4 | #include "networksettings.h" |
5 | 5 | ||
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | #include <qpe/qpeapplication.h> | 7 | #include <qpe/qpeapplication.h> |
8 | 8 | ||
9 | #include <opie2/oapplicationfactory.h> | 9 | #include <opie2/oapplicationfactory.h> |
10 | using namespace Opie::Core; | 10 | using namespace Opie::Core; |
11 | 11 | ||
12 | #ifdef GONE | 12 | #ifdef GONE |
13 | 13 | ||
14 | OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) | 14 | OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) |
15 | 15 | ||
16 | #else | 16 | #else |
17 | 17 | ||
18 | // just standard GUI | 18 | // just standard GUI |
19 | #define ACT_GUI 0 | 19 | #define ACT_GUI 0 |
20 | // used by interfaces to request for allow of up/down | 20 | // used by interfaces to request for allow of up/down |
21 | #define ACT_REQUEST 1 | 21 | #define ACT_REQUEST 1 |
22 | // regenerate config files | 22 | // regenerate config files |
23 | #define ACT_REGEN 2 | 23 | #define ACT_REGEN 2 |
24 | // used by interfaces to request user prompt | 24 | // used by interfaces to request user prompt |
25 | #define ACT_PROMPT 3 | 25 | #define ACT_PROMPT 3 |
26 | // used by interfaces to trigger VPN | 26 | // used by interfaces to trigger VPN prompting |
27 | #define ACT_VPN 4 | 27 | #define ACT_TRIGGERVPN 4 |
28 | // activate opietooth | 28 | // activate opietooth |
29 | #define ACT_OT 5 | 29 | #define ACT_OT 5 |
30 | // prompt for VPN networks | ||
31 | #define ACT_PROMPTVPN 6 | ||
30 | 32 | ||
31 | // include Opietooth GUI | 33 | // include Opietooth GUI |
32 | #include <opietooth2/Opietooth.h> | 34 | #include <opietooth2/Opietooth.h> |
33 | using namespace Opietooth2; | 35 | using namespace Opietooth2; |
34 | 36 | ||
35 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
36 | #include <qlayout.h> | 38 | #include <qlayout.h> |
37 | #include <qframe.h> | 39 | #include <qframe.h> |
38 | #include <qlabel.h> | 40 | #include <qlabel.h> |
39 | 41 | ||
40 | int main( int argc, char * argv[] ) { | 42 | int main( int argc, char * argv[] ) { |
41 | int rv = 0; | 43 | int rv = 0; |
42 | int Action = ACT_GUI; | 44 | int Action = ACT_GUI; |
43 | // could be overruled by -qws | 45 | // could be overruled by -qws |
44 | QApplication::Type GuiType = QApplication::GuiClient; | 46 | QApplication::Type GuiType = QApplication::GuiClient; |
45 | 47 | ||
46 | QPEApplication * TheApp; | 48 | QPEApplication * TheApp; |
47 | 49 | ||
48 | for ( int i = 1; i < argc; i ++ ) { | 50 | for ( int i = 1; i < argc; i ++ ) { |
49 | int rmv; | 51 | int rmv; |
50 | rmv = 0; | 52 | rmv = 0; |
51 | if( strcmp( argv[i], "--regen" ) == 0 ) { | 53 | if( strcmp( argv[i], "--regen" ) == 0 ) { |
52 | Action = ACT_REGEN; | 54 | Action = ACT_REGEN; |
53 | GuiType = QApplication::Tty; | 55 | GuiType = QApplication::Tty; |
54 | rmv = 1; | 56 | rmv = 1; |
55 | } else if( strcmp( argv[i], "--prompt" ) == 0 ) { | 57 | } else if( strcmp( argv[i], "--prompt" ) == 0 ) { |
56 | Action = ACT_PROMPT; | 58 | Action = ACT_PROMPT; |
57 | rmv = 1; | 59 | rmv = 1; |
58 | } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { | 60 | } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { |
59 | Action = ACT_VPN; | 61 | GuiType = QApplication::Tty; |
62 | Action = ACT_TRIGGERVPN; | ||
63 | rmv = 1; | ||
64 | } else if( strcmp( argv[i], "--promptvpn" ) == 0 ) { | ||
65 | Action = ACT_PROMPTVPN; | ||
60 | rmv = 1; | 66 | rmv = 1; |
61 | } else if( strcmp( argv[i], "--opietooth" ) == 0 ) { | 67 | } else if( strcmp( argv[i], "--opietooth" ) == 0 ) { |
62 | Action = ACT_OT; | 68 | Action = ACT_OT; |
63 | rmv = 1; | 69 | rmv = 1; |
64 | } | 70 | } |
65 | if( rmv ) { | 71 | if( rmv ) { |
66 | memmove( argv+i, argv+i+rmv, | 72 | memmove( argv+i, argv+i+rmv, |
67 | sizeof( char * ) * (argc-i-rmv) ); | 73 | sizeof( char * ) * (argc-i-rmv) ); |
68 | i --; | 74 | i --; |
69 | argc -= rmv; | 75 | argc -= rmv; |
70 | } | 76 | } |
71 | } | 77 | } |
72 | 78 | ||
73 | if( strstr( argv[0], "-request" ) ) { | 79 | if( strstr( argv[0], "-request" ) ) { |
74 | // called from system to request something | 80 | // called from system to request something |
75 | GuiType = QApplication::Tty; | 81 | GuiType = QApplication::Tty; |
76 | Action = ACT_REQUEST; | 82 | Action = ACT_REQUEST; |
77 | Log(("Request : %s\n", argv[1] )); | 83 | Log(("Request : %s\n", argv[1] )); |
78 | } else if( strstr( argv[0], "-opietooth" ) ) { | 84 | } else if( strstr( argv[0], "-opietooth" ) ) { |
79 | Action = ACT_OT; | 85 | Action = ACT_OT; |
80 | } | 86 | } |
81 | 87 | ||
82 | // Start Qt | 88 | // Start Qt |
83 | // because QPEApplication does not handle GuiType well | 89 | // because QPEApplication does not handle GuiType well |
84 | if( GuiType == QApplication::Tty ) { | 90 | if( GuiType == QApplication::Tty ) { |
85 | // this cast is NOT correct but we do not use | 91 | // this cast is NOT correct but we do not use |
86 | // TheApp anymore ... | 92 | // TheApp anymore ... |
87 | TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); | 93 | TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); |
88 | } else { | 94 | } else { |
89 | TheApp = new QPEApplication( argc, argv, GuiType ); | 95 | TheApp = new QPEApplication( argc, argv, GuiType ); |
90 | } | 96 | } |
91 | 97 | ||
92 | // init qt with app widget | 98 | // init qt with app widget |
93 | 99 | ||
94 | switch( Action ) { | 100 | switch( Action ) { |
95 | case ACT_REQUEST : | 101 | case ACT_REQUEST : |
96 | { NetworkSettingsData NS; | 102 | { NetworkSettingsData NS; |
97 | if( NS.canStart( argv[1] ) ) { | 103 | if( NS.canStart( argv[1] ) ) { |
104 | QStringList SL; | ||
105 | SL << QPEApplication::qpeDir() + "bin/networksettings2" | ||
106 | << "--prompt" | ||
107 | << argv[1]; | ||
108 | // exec synchronous -> blocks | ||
109 | NSResources->system().execAsUser( SL, 1 ); | ||
110 | } | ||
111 | } | ||
112 | break; | ||
113 | case ACT_TRIGGERVPN : | ||
114 | { NetworkSettingsData NS; | ||
115 | if( NS.couldBeTriggered( argv[1] ) ) { | ||
116 | // there are VPNS that can be triggered | ||
98 | QStringList S; | 117 | QStringList S; |
99 | S << QPEApplication::qpeDir() + "/bin/networksettings2"; | 118 | S << QPEApplication::qpeDir() + "bin/networksettings2"; |
100 | S << "networksettings2"; | 119 | S << "--promptvpn"; |
101 | S << "--prompt"; | ||
102 | S << argv[1]; | 120 | S << argv[1]; |
103 | NSResources->system().execAsUser( S ); | 121 | NSResources->system().execAsUser( S ); |
104 | Log(("FAILED %s-cNN-allowed\n", argv[1] )); | ||
105 | // if we come here , failed | ||
106 | printf( "%s-cNN-disallowed", argv[1] ); | ||
107 | } | 122 | } |
108 | } | 123 | } |
109 | break; | 124 | break; |
110 | case ACT_REGEN : | 125 | case ACT_REGEN : |
111 | { NetworkSettingsData NS; | 126 | { NetworkSettingsData NS; |
112 | QString S= NS.generateSettings(); | 127 | QString S= NS.generateSettings(); |
113 | // regen returns 0 if OK | 128 | // regen returns 0 if OK |
114 | rv = ( S.isEmpty() ) ? 0 : 1; | 129 | rv = ( S.isEmpty() ) ? 0 : 1; |
115 | } | 130 | } |
116 | break; | 131 | break; |
117 | case ACT_PROMPT : | 132 | case ACT_PROMPT : |
118 | { ActivateProfile AP(argv[1]); | 133 | { ActivateProfile AP(argv[1]); |
119 | if( AP.exec() == QDialog::Accepted ) { | 134 | if( AP.exec() == QDialog::Accepted ) { |
120 | Log(("%s-c%ld-allowed\n", | 135 | Log(("allow profile %ld for %s\n", |
121 | argv[1], AP.selectedProfile() )); | 136 | AP.selectedProfile(), argv[1] )); |
122 | printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); | 137 | printf( "A%ld%s\n", AP.selectedProfile(), argv[1] ); |
123 | } else { | 138 | } else { |
124 | Log(("%s-c%NN-disallowed\n", argv[1] )); | 139 | Log(("disallow %s\n", argv[1] )); |
125 | printf( "%s-cNN-disallowed", argv[1] ); | 140 | printf( "D-%s\n", argv[1] ); |
126 | } | 141 | } |
127 | } | 142 | } |
128 | break; | 143 | break; |
129 | case ACT_VPN : | 144 | case ACT_PROMPTVPN : |
130 | { ActivateVPN AVPN; | 145 | { ActivateVPN AVPN( argv[1] ); |
146 | Log(("Trigger vpns on interface %s\n", argv[1] )); | ||
131 | AVPN.exec(); | 147 | AVPN.exec(); |
132 | } | 148 | } |
133 | break; | 149 | break; |
134 | case ACT_GUI : | 150 | case ACT_GUI : |
135 | case ACT_OT : | 151 | case ACT_OT : |
136 | { QWidget * W; | 152 | { QWidget * W; |
137 | 153 | ||
138 | if( Action == ACT_OT ) { | 154 | if( Action == ACT_OT ) { |
139 | W = new OTMain( 0 ); | 155 | W = new OTMain( 0 ); |
140 | } else { | 156 | } else { |
141 | W = new NetworkSettings(0); | 157 | W = new NetworkSettings(0); |
142 | } | 158 | } |
143 | TheApp->setMainWidget( W ); | 159 | TheApp->setMainWidget( W ); |
144 | 160 | ||
145 | W->show(); | 161 | W->show(); |
146 | W->showMaximized(); | 162 | W->showMaximized(); |
147 | rv = TheApp->exec(); | 163 | rv = TheApp->exec(); |
148 | 164 | ||
149 | delete W; | 165 | delete W; |
150 | } | 166 | } |
151 | break; | 167 | break; |
152 | } | 168 | } |
153 | 169 | ||
154 | LogClose(); | 170 | LogClose(); |
155 | 171 | ||
156 | return rv; | 172 | return rv; |
157 | } | 173 | } |
158 | 174 | ||
159 | #endif | 175 | #endif |
160 | 176 | ||
161 | 177 | ||
162 | // main.cpp | 178 | // main.cpp |
163 | 179 | ||
diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 78e6545..34dac54 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp | |||
@@ -1,217 +1,218 @@ | |||
1 | #include <system.h> | 1 | #include <system.h> |
2 | #include <netnode.h> | 2 | #include <netnode.h> |
3 | #include "networkedit.h" | 3 | #include "networkedit.h" |
4 | #include "network_NNI.h" | 4 | #include "network_NNI.h" |
5 | #include "network_NN.h" | 5 | #include "network_NN.h" |
6 | 6 | ||
7 | ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) { | 7 | ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) { |
8 | Data.UseDHCP = 1; | 8 | Data.UseDHCP = 1; |
9 | Data.IPAddress = ""; | 9 | Data.IPAddress = ""; |
10 | Data.NetMask = ""; | 10 | Data.NetMask = ""; |
11 | Data.Broadcast = ""; | 11 | Data.Broadcast = ""; |
12 | Data.Gateway = ""; | 12 | Data.Gateway = ""; |
13 | Data.DNS1 = ""; | 13 | Data.DNS1 = ""; |
14 | Data.DNS2 = ""; | 14 | Data.DNS2 = ""; |
15 | Data.SendHostname = 0; | 15 | Data.SendHostname = 0; |
16 | Data.Hostname = ""; | 16 | Data.Hostname = ""; |
17 | Data.PreUp_SL.clear(); | 17 | Data.PreUp_SL.clear(); |
18 | Data.PreDown_SL.clear(); | 18 | Data.PreDown_SL.clear(); |
19 | Data.PostUp_SL.clear(); | 19 | Data.PostUp_SL.clear(); |
20 | Data.PostDown_SL.clear(); | 20 | Data.PostDown_SL.clear(); |
21 | GUI = 0; | 21 | GUI = 0; |
22 | RT = 0; | 22 | RT = 0; |
23 | } | 23 | } |
24 | 24 | ||
25 | void ANetwork::setSpecificAttribute( QString & A, QString & V ) { | 25 | void ANetwork::setSpecificAttribute( QString & A, QString & V ) { |
26 | if( A == "usedhcp" ) { | 26 | if( A == "usedhcp" ) { |
27 | Data.UseDHCP = (V == "yes"); | 27 | Data.UseDHCP = (V == "yes"); |
28 | } else if( A == "sendhostname" ) { | 28 | } else if( A == "sendhostname" ) { |
29 | Data.SendHostname = (V=="yes"); | 29 | Data.SendHostname = (V=="yes"); |
30 | } else if( A == "hostname" ) { | 30 | } else if( A == "hostname" ) { |
31 | Data.Hostname = V; | 31 | Data.Hostname = V; |
32 | } else if( A == "ipaddress" ) { | 32 | } else if( A == "ipaddress" ) { |
33 | Data.IPAddress = V; | 33 | Data.IPAddress = V; |
34 | } else if( A == "netmask" ) { | 34 | } else if( A == "netmask" ) { |
35 | Data.NetMask = V; | 35 | Data.NetMask = V; |
36 | } else if( A == "broadcast" ) { | 36 | } else if( A == "broadcast" ) { |
37 | Data.Broadcast = V; | 37 | Data.Broadcast = V; |
38 | } else if( A == "gateway" ) { | 38 | } else if( A == "gateway" ) { |
39 | Data.Gateway = V; | 39 | Data.Gateway = V; |
40 | } else if( A == "dns1" ) { | 40 | } else if( A == "dns1" ) { |
41 | Data.DNS1 = V; | 41 | Data.DNS1 = V; |
42 | } else if( A == "dns2" ) { | 42 | } else if( A == "dns2" ) { |
43 | Data.DNS2 = V; | 43 | Data.DNS2 = V; |
44 | } else if( A == "preup" ) { | 44 | } else if( A == "preup" ) { |
45 | Data.PreUp_SL.append( V ); | 45 | Data.PreUp_SL.append( V ); |
46 | } else if( A == "predown" ) { | 46 | } else if( A == "predown" ) { |
47 | Data.PreDown_SL.append( V ); | 47 | Data.PreDown_SL.append( V ); |
48 | } else if( A == "postup" ) { | 48 | } else if( A == "postup" ) { |
49 | Data.PostUp_SL.append( V ); | 49 | Data.PostUp_SL.append( V ); |
50 | } else if( A == "postdown" ) { | 50 | } else if( A == "postdown" ) { |
51 | Data.PostDown_SL.append( V ); | 51 | Data.PostDown_SL.append( V ); |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | void ANetwork::saveSpecificAttribute( QTextStream & TS ) { | 55 | void ANetwork::saveSpecificAttribute( QTextStream & TS ) { |
56 | TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl; | 56 | TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl; |
57 | TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl; | 57 | TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl; |
58 | TS << "hostname=" << Data.Hostname << endl; | 58 | TS << "hostname=" << Data.Hostname << endl; |
59 | TS << "ipaddress=" << Data.IPAddress << endl; | 59 | TS << "ipaddress=" << Data.IPAddress << endl; |
60 | TS << "netmask=" << Data.NetMask << endl; | 60 | TS << "netmask=" << Data.NetMask << endl; |
61 | TS << "broadcast=" << Data.Broadcast << endl; | 61 | TS << "broadcast=" << Data.Broadcast << endl; |
62 | TS << "gateway=" << Data.Gateway << endl; | 62 | TS << "gateway=" << Data.Gateway << endl; |
63 | TS << "dns1=" << Data.DNS1 << endl; | 63 | TS << "dns1=" << Data.DNS1 << endl; |
64 | TS << "dns2=" << Data.DNS2 << endl; | 64 | TS << "dns2=" << Data.DNS2 << endl; |
65 | for ( QStringList::Iterator it = Data.PreUp_SL.begin(); | 65 | for ( QStringList::Iterator it = Data.PreUp_SL.begin(); |
66 | it != Data.PreUp_SL.end(); | 66 | it != Data.PreUp_SL.end(); |
67 | ++it ) { | 67 | ++it ) { |
68 | TS << "preup=" << quote(*it) << endl; | 68 | TS << "preup=" << quote(*it) << endl; |
69 | } | 69 | } |
70 | for ( QStringList::Iterator it = Data.PreDown_SL.begin(); | 70 | for ( QStringList::Iterator it = Data.PreDown_SL.begin(); |
71 | it != Data.PreDown_SL.end(); | 71 | it != Data.PreDown_SL.end(); |
72 | ++it ) { | 72 | ++it ) { |
73 | TS << "predown=" << quote(*it) << endl; | 73 | TS << "predown=" << quote(*it) << endl; |
74 | } | 74 | } |
75 | for ( QStringList::Iterator it = Data.PostUp_SL.begin(); | 75 | for ( QStringList::Iterator it = Data.PostUp_SL.begin(); |
76 | it != Data.PostUp_SL.end(); | 76 | it != Data.PostUp_SL.end(); |
77 | ++it ) { | 77 | ++it ) { |
78 | TS << "postup=" << quote(*it) << endl; | 78 | TS << "postup=" << quote(*it) << endl; |
79 | } | 79 | } |
80 | for ( QStringList::Iterator it = Data.PostDown_SL.begin(); | 80 | for ( QStringList::Iterator it = Data.PostDown_SL.begin(); |
81 | it != Data.PostDown_SL.end(); | 81 | it != Data.PostDown_SL.end(); |
82 | ++it ) { | 82 | ++it ) { |
83 | TS << "postdown=" << quote(*it) << endl; | 83 | TS << "postdown=" << quote(*it) << endl; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | QWidget * ANetwork::edit( QWidget * parent ) { | 87 | QWidget * ANetwork::edit( QWidget * parent ) { |
88 | GUI = new NetworkEdit( parent ); | 88 | GUI = new NetworkEdit( parent ); |
89 | GUI->showData( Data ); | 89 | GUI->showData( Data ); |
90 | return GUI; | 90 | return GUI; |
91 | } | 91 | } |
92 | 92 | ||
93 | QString ANetwork::acceptable( void ) { | 93 | QString ANetwork::acceptable( void ) { |
94 | return ( GUI ) ? GUI->acceptable( ) : QString(); | 94 | return ( GUI ) ? GUI->acceptable( ) : QString(); |
95 | } | 95 | } |
96 | 96 | ||
97 | void ANetwork::commit( void ) { | 97 | void ANetwork::commit( void ) { |
98 | if( GUI && GUI->commit( Data ) ) | 98 | if( GUI && GUI->commit( Data ) ) |
99 | setModified( 1 ); | 99 | setModified( 1 ); |
100 | } | 100 | } |
101 | 101 | ||
102 | bool ANetwork::hasDataForFile( SystemFile & S ) { | 102 | bool ANetwork::hasDataForFile( SystemFile & S ) { |
103 | return S.name() == "interfaces"; | 103 | return S.name() == "interfaces"; |
104 | } | 104 | } |
105 | 105 | ||
106 | short ANetwork::generateFile( SystemFile &SF, | 106 | short ANetwork::generateFile( SystemFile &SF, |
107 | long DevNr | 107 | long DevNr |
108 | ) { | 108 | ) { |
109 | 109 | ||
110 | short rvl, rvd ; | 110 | short rvl, rvd ; |
111 | QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); | 111 | QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); |
112 | 112 | ||
113 | rvl = 1; | 113 | rvl = 1; |
114 | if( SF.name() == "interfaces" ) { | 114 | if( SF.name() == "interfaces" ) { |
115 | Log(("Generate Network for %s\n", SF.name().latin1() )); | 115 | Log(("Generate Network for %s\n", SF.name().latin1() )); |
116 | // we can safely call from here since device item is deeper | 116 | // we can safely call from here since device item is deeper |
117 | if( Data.UseDHCP ) { | 117 | if( Data.UseDHCP ) { |
118 | SF << "iface " | 118 | SF << "iface " |
119 | << NIC | 119 | << "A" |
120 | << "-c" | ||
121 | << connection()->number() | 120 | << connection()->number() |
122 | << "-allowed inet dhcp" | 121 | << NIC |
122 | << " inet dhcp" | ||
123 | << endl; | 123 | << endl; |
124 | SF << " up echo \"" | 124 | SF << " up echo \"" |
125 | << NIC | 125 | << NIC |
126 | << "\" > /tmp/profile-" | 126 | << "\" > /tmp/profile-" |
127 | << connection()->number() | 127 | << connection()->number() |
128 | << ".up" | 128 | << ".up" |
129 | << endl; | 129 | << endl; |
130 | if( Data.SendHostname ) { | 130 | if( Data.SendHostname ) { |
131 | SF << " hostname " | 131 | SF << " hostname " |
132 | << Data.Hostname | 132 | << Data.Hostname |
133 | << endl; | 133 | << endl; |
134 | } | 134 | } |
135 | 135 | ||
136 | SF << " down rm -f /tmp/profile-" | 136 | SF << " down rm -f /tmp/profile-" |
137 | << connection()->number() | 137 | << connection()->number() |
138 | << ".up" | 138 | << ".up" |
139 | << endl; | 139 | << endl; |
140 | } else { | 140 | } else { |
141 | SF << "iface " | 141 | SF << "iface " |
142 | << NIC << "-c" | 142 | << "A" |
143 | << connection()->number() | 143 | << connection()->number() |
144 | << "-allowed inet static" | 144 | << NIC |
145 | << " inet static" | ||
145 | << endl; | 146 | << endl; |
146 | SF << " up echo \"" | 147 | SF << " up echo \"" |
147 | << NIC | 148 | << NIC |
148 | << "\" > /tmp/profile-" | 149 | << "\" > /tmp/profile-" |
149 | << connection()->number() | 150 | << connection()->number() |
150 | << ".up" | 151 | << ".up" |
151 | << endl; | 152 | << endl; |
152 | SF << " down rm -f /tmp/profile-" | 153 | SF << " down rm -f /tmp/profile-" |
153 | << connection()->number() | 154 | << connection()->number() |
154 | << ".up" | 155 | << ".up" |
155 | << endl; | 156 | << endl; |
156 | SF << " address " | 157 | SF << " address " |
157 | << Data.IPAddress | 158 | << Data.IPAddress |
158 | << endl; | 159 | << endl; |
159 | SF << " broadcast " | 160 | SF << " broadcast " |
160 | << Data.Broadcast | 161 | << Data.Broadcast |
161 | << endl; | 162 | << endl; |
162 | SF << " netmask " | 163 | SF << " netmask " |
163 | << Data.NetMask | 164 | << Data.NetMask |
164 | << endl; | 165 | << endl; |
165 | 166 | ||
166 | // derive network address = IPAddress & netmask | 167 | // derive network address = IPAddress & netmask |
167 | { QString NW; | 168 | { QString NW; |
168 | QStringList ipal = QStringList::split( '.', Data.IPAddress ); | 169 | QStringList ipal = QStringList::split( '.', Data.IPAddress ); |
169 | QStringList nmal = QStringList::split( '.', Data.NetMask ); | 170 | QStringList nmal = QStringList::split( '.', Data.NetMask ); |
170 | 171 | ||
171 | NW = QString( "%1.%2.%3.%4" ). | 172 | NW = QString( "%1.%2.%3.%4" ). |
172 | arg( ipal[0].toShort() & nmal[0].toShort() ). | 173 | arg( ipal[0].toShort() & nmal[0].toShort() ). |
173 | arg( ipal[1].toShort() & nmal[1].toShort() ). | 174 | arg( ipal[1].toShort() & nmal[1].toShort() ). |
174 | arg( ipal[2].toShort() & nmal[2].toShort() ). | 175 | arg( ipal[2].toShort() & nmal[2].toShort() ). |
175 | arg( ipal[3].toShort() & nmal[3].toShort() ); | 176 | arg( ipal[3].toShort() & nmal[3].toShort() ); |
176 | SF << " network " | 177 | SF << " network " |
177 | << NW | 178 | << NW |
178 | << endl; | 179 | << endl; |
179 | } | 180 | } |
180 | } | 181 | } |
181 | for ( QStringList::Iterator it = Data.PreUp_SL.begin(); | 182 | for ( QStringList::Iterator it = Data.PreUp_SL.begin(); |
182 | it != Data.PreUp_SL.end(); | 183 | it != Data.PreUp_SL.end(); |
183 | ++it ) { | 184 | ++it ) { |
184 | SF << " pre-up " | 185 | SF << " pre-up " |
185 | << (*it) | 186 | << (*it) |
186 | << endl; | 187 | << endl; |
187 | } | 188 | } |
188 | for ( QStringList::Iterator it = Data.PostUp_SL.begin(); | 189 | for ( QStringList::Iterator it = Data.PostUp_SL.begin(); |
189 | it != Data.PostUp_SL.end(); | 190 | it != Data.PostUp_SL.end(); |
190 | ++it ) { | 191 | ++it ) { |
191 | SF << " up " | 192 | SF << " up " |
192 | << (*it) | 193 | << (*it) |
193 | << endl; | 194 | << endl; |
194 | } | 195 | } |
195 | for ( QStringList::Iterator it = Data.PreDown_SL.begin(); | 196 | for ( QStringList::Iterator it = Data.PreDown_SL.begin(); |
196 | it != Data.PreDown_SL.end(); | 197 | it != Data.PreDown_SL.end(); |
197 | ++it ) { | 198 | ++it ) { |
198 | SF << " down " | 199 | SF << " down " |
199 | << (*it) | 200 | << (*it) |
200 | << endl; | 201 | << endl; |
201 | } | 202 | } |
202 | for ( QStringList::Iterator it = Data.PostDown_SL.begin(); | 203 | for ( QStringList::Iterator it = Data.PostDown_SL.begin(); |
203 | it != Data.PostDown_SL.end(); | 204 | it != Data.PostDown_SL.end(); |
204 | ++it ) { | 205 | ++it ) { |
205 | SF << " post-down " | 206 | SF << " post-down " |
206 | << (*it) | 207 | << (*it) |
207 | << endl; | 208 | << endl; |
208 | } | 209 | } |
209 | rvl = 0; | 210 | rvl = 0; |
210 | } | 211 | } |
211 | 212 | ||
212 | // embed other info in it | 213 | // embed other info in it |
213 | rvd = connection()->getToplevel()->generateFileEmbedded( SF, DevNr ); | 214 | rvd = connection()->getToplevel()->generateFileEmbedded( SF, DevNr ); |
214 | 215 | ||
215 | return (rvd == 2 || rvl == 2 ) ? 2 : | 216 | return (rvd == 2 || rvl == 2 ) ? 2 : |
216 | (rvd == 0 || rvl == 0 ) ? 0 : 1; | 217 | (rvd == 0 || rvl == 0 ) ? 0 : 1; |
217 | } | 218 | } |
diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index 2c93d9d..74467ad 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp | |||
@@ -1,50 +1,51 @@ | |||
1 | #include <system.h> | 1 | #include <system.h> |
2 | #include <netnode.h> | 2 | #include <netnode.h> |
3 | #include <resources.h> | 3 | #include <resources.h> |
4 | #include "networkrun.h" | 4 | #include "networkrun.h" |
5 | 5 | ||
6 | State_t NetworkRun::detectState( void ) { | 6 | State_t NetworkRun::detectState( void ) { |
7 | InterfaceInfo * II = nodeCollection()->assignedInterface(); | 7 | InterfaceInfo * II = nodeCollection()->assignedInterface(); |
8 | 8 | ||
9 | Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 )); | 9 | Log(( "Interface %p %p : %d\n", II, nodeCollection(), (II) ? II->IsUp : 0 )); |
10 | if( II && II->IsUp ) { | 10 | if( II && II->IsUp ) { |
11 | // device has assigned interface | 11 | // device has assigned interface |
12 | return IsUp; | 12 | return IsUp; |
13 | } | 13 | } |
14 | 14 | ||
15 | // had no interface or interface is no longer up -> release | 15 | // had no interface or interface is no longer up -> release |
16 | nodeCollection()->assignInterface( 0 ); | 16 | nodeCollection()->assignInterface( 0 ); |
17 | 17 | ||
18 | return Unknown; | 18 | return Unknown; |
19 | } | 19 | } |
20 | 20 | ||
21 | QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { | 21 | QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { |
22 | // we handle UP and DOWN | 22 | // we handle UP and DOWN |
23 | InterfaceInfo * II = NC->assignedInterface(); | 23 | InterfaceInfo * II = NC->assignedInterface(); |
24 | 24 | ||
25 | if( ! II ) { | 25 | if( ! II ) { |
26 | Log(( "no interface assigned." )); | 26 | Log(( "no interface assigned." )); |
27 | return QString(); | 27 | return QString(); |
28 | } | 28 | } |
29 | 29 | ||
30 | QStringList SL; | 30 | QStringList SL; |
31 | 31 | ||
32 | if( A == Up ) { | 32 | if( A == Up ) { |
33 | // we can bring UP if lower level is available | 33 | // we can bring UP if lower level is available |
34 | SL << "ifup"; | 34 | SL << "ifup"; |
35 | } else if( A == Down ) { | 35 | } else if( A == Down ) { |
36 | SL << "ifdown"; | 36 | SL << "ifdown"; |
37 | } else { | 37 | } else { |
38 | return QString(); | 38 | return QString(); |
39 | } | 39 | } |
40 | 40 | ||
41 | SL << QString().sprintf( "%s=%s-c%d-allowed", | 41 | SL << QString().sprintf( "%s=A%ld%s", |
42 | II->Name.latin1(), II->Name.latin1(), | 42 | II->Name.latin1(), |
43 | nodeCollection()->number() ); | 43 | nodeCollection()->number(), |
44 | II->Name.latin1() ); | ||
44 | 45 | ||
45 | if( ! NSResources->system().runAsRoot( SL ) ) { | 46 | if( ! NSResources->system().runAsRoot( SL ) ) { |
46 | return QString("Cannot call %1").arg(SL.join(" ")); | 47 | return QString("Cannot call %1").arg(SL.join(" ")); |
47 | } | 48 | } |
48 | 49 | ||
49 | return QString(); | 50 | return QString(); |
50 | } | 51 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 3479abb..b81dcaa 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp | |||
@@ -1,479 +1,481 @@ | |||
1 | #include <unistd.h> | 1 | #include <unistd.h> |
2 | #include <errno.h> | 2 | #include <errno.h> |
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <pwd.h> | 4 | #include <pwd.h> |
5 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | 8 | ||
9 | #include <qpe/qlibrary.h> | 9 | #include <qpe/qlibrary.h> |
10 | #include <qpe/qpeapplication.h> | 10 | #include <qpe/qpeapplication.h> |
11 | 11 | ||
12 | #include <opie2/odebug.h> | 12 | #include <opie2/odebug.h> |
13 | #include <opie2/opluginloader.h> | 13 | #include <opie2/opluginloader.h> |
14 | 14 | ||
15 | #include <qtopia/resource.h> | 15 | #include <qtopia/resource.h> |
16 | 16 | ||
17 | #include "netnode.h" | 17 | #include "netnode.h" |
18 | #include "resources.h" | 18 | #include "resources.h" |
19 | #include "netnodeinterface.h" | 19 | #include "netnodeinterface.h" |
20 | 20 | ||
21 | #define PLUGINDIR "plugins/networksettings2" | 21 | #define PLUGINDIR "plugins/networksettings2" |
22 | #define ICONDIR "/pics/networksettings2/" | 22 | #define ICONDIR "/pics/networksettings2/" |
23 | 23 | ||
24 | // single resources instance | 24 | // single resources instance |
25 | TheNSResources * _NSResources = 0; | 25 | TheNSResources * _NSResources = 0; |
26 | 26 | ||
27 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | 27 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), |
28 | ConnectionsMap(), DanglingConnectionsMap() { | 28 | ConnectionsMap(), DanglingConnectionsMap() { |
29 | 29 | ||
30 | _NSResources = this; | 30 | _NSResources = this; |
31 | 31 | ||
32 | detectCurrentUser(); | 32 | detectCurrentUser(); |
33 | 33 | ||
34 | // load available netnodes | 34 | // load available netnodes |
35 | 35 | ||
36 | Plugins = 0; | 36 | Plugins = 0; |
37 | findAvailableNetNodes(); | 37 | findAvailableNetNodes(); |
38 | 38 | ||
39 | // compile provides and needs lists | 39 | // compile provides and needs lists |
40 | { const char ** NeedsRun; | 40 | { const char ** NeedsRun; |
41 | QDictIterator<ANetNode> OuterIt( AllNodeTypes ); | 41 | QDictIterator<ANetNode> OuterIt( AllNodeTypes ); |
42 | bool Done; | 42 | bool Done; |
43 | 43 | ||
44 | for ( ; OuterIt.current(); ++OuterIt ) { | 44 | for ( ; OuterIt.current(); ++OuterIt ) { |
45 | // find needs list | 45 | // find needs list |
46 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; | 46 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; |
47 | ANetNode::NetNodeList & NNL = *(NNLP); | 47 | ANetNode::NetNodeList & NNL = *(NNLP); |
48 | 48 | ||
49 | // must iterate this way to avoid duplication pointers | 49 | // must iterate this way to avoid duplication pointers |
50 | for ( QDictIterator<ANetNode> InnerIt( AllNodeTypes ); | 50 | for ( QDictIterator<ANetNode> InnerIt( AllNodeTypes ); |
51 | InnerIt.current(); ++InnerIt ) { | 51 | InnerIt.current(); ++InnerIt ) { |
52 | 52 | ||
53 | if( InnerIt.current() == OuterIt.current() ) | 53 | if( InnerIt.current() == OuterIt.current() ) |
54 | // avoid recursive | 54 | // avoid recursive |
55 | continue; | 55 | continue; |
56 | 56 | ||
57 | const char ** Provides = InnerIt.current()->provides(); | 57 | const char ** Provides = InnerIt.current()->provides(); |
58 | NeedsRun = OuterIt.current()->needs(); | 58 | NeedsRun = OuterIt.current()->needs(); |
59 | 59 | ||
60 | for( ; *NeedsRun; NeedsRun ++ ) { | 60 | for( ; *NeedsRun; NeedsRun ++ ) { |
61 | const char ** PRun; | 61 | const char ** PRun; |
62 | PRun = Provides; | 62 | PRun = Provides; |
63 | for( ; *PRun; PRun ++ ) { | 63 | for( ; *PRun; PRun ++ ) { |
64 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { | 64 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { |
65 | // inner provides what outer needs | 65 | // inner provides what outer needs |
66 | NNL.resize( NNL.size() + 1 ); | 66 | NNL.resize( NNL.size() + 1 ); |
67 | NNL[NNL.size()-1] = InnerIt.current(); | 67 | NNL[NNL.size()-1] = InnerIt.current(); |
68 | Done = 1; // break from 2 loops | 68 | Done = 1; // break from 2 loops |
69 | break; | 69 | break; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | } | 72 | } |
73 | } | 73 | } |
74 | OuterIt.current()->setAlternatives( NNLP ); | 74 | OuterIt.current()->setAlternatives( NNLP ); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | // define built in Node types to Description map | 78 | // define built in Node types to Description map |
79 | addNodeType( "device", tr( "Network Device" ), | 79 | addNodeType( "device", tr( "Network Device" ), |
80 | tr( "<p>Devices that can handle IP packets</p>" ) ); | 80 | tr( "<p>Devices that can handle IP packets</p>" ) ); |
81 | addNodeType( "line", tr( "Character device" ), | 81 | addNodeType( "line", tr( "Character device" ), |
82 | tr( "<p>Devices that can handle single bytes</p>" ) ); | 82 | tr( "<p>Devices that can handle single bytes</p>" ) ); |
83 | addNodeType( "connection", tr( "IP Connection" ), | 83 | addNodeType( "connection", tr( "IP Connection" ), |
84 | tr( "<p>Nodes that provide working IP connections</p>" ) ); | 84 | tr( "<p>Nodes that provide working IP connections</p>" ) ); |
85 | addNodeType( "fullsetup", tr( "Connection Profile" ), | 85 | addNodeType( "fullsetup", tr( "Connection Profile" ), |
86 | tr( "<p>Fully configured connection profile</p>" ) ); | 86 | tr( "<p>Fully configured connection profile</p>" ) ); |
87 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), | 87 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), |
88 | tr( "<p>Connection to a GPRS capable device</p>" ) ); | 88 | tr( "<p>Connection to a GPRS capable device</p>" ) ); |
89 | 89 | ||
90 | // get access to the system | 90 | // get access to the system |
91 | TheSystem = new System(); | 91 | TheSystem = new System(); |
92 | 92 | ||
93 | } | 93 | } |
94 | 94 | ||
95 | TheNSResources::~TheNSResources( void ) { | 95 | TheNSResources::~TheNSResources( void ) { |
96 | 96 | ||
97 | if( Plugins ) { | 97 | if( Plugins ) { |
98 | delete Plugins; | 98 | delete Plugins; |
99 | delete PluginManager; | 99 | delete PluginManager; |
100 | } | 100 | } |
101 | delete TheSystem; | 101 | delete TheSystem; |
102 | 102 | ||
103 | } | 103 | } |
104 | 104 | ||
105 | void TheNSResources::addNodeType( const QString & ID, | 105 | void TheNSResources::addNodeType( const QString & ID, |
106 | const QString & Name, | 106 | const QString & Name, |
107 | const QString & Descr ) { | 107 | const QString & Descr ) { |
108 | if( NodeTypeNameMap[ID].isEmpty() ) { | 108 | if( NodeTypeNameMap[ID].isEmpty() ) { |
109 | NodeTypeNameMap.insert( ID, Name ); | 109 | NodeTypeNameMap.insert( ID, Name ); |
110 | NodeTypeDescriptionMap.insert( ID, Descr ); | 110 | NodeTypeDescriptionMap.insert( ID, Descr ); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | void TheNSResources::addSystemFile( const QString & ID, | 114 | void TheNSResources::addSystemFile( const QString & ID, |
115 | const QString & P, | 115 | const QString & P, |
116 | bool KDI ) { | 116 | bool KDI ) { |
117 | if( ! SystemFiles.find( ID ) ) { | 117 | if( ! SystemFiles.find( ID ) ) { |
118 | // new system file | 118 | // new system file |
119 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); | 119 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); |
120 | } // else existed | 120 | } // else existed |
121 | } | 121 | } |
122 | 122 | ||
123 | void TheNSResources::busy( bool ) { | 123 | void TheNSResources::busy( bool ) { |
124 | /* | 124 | /* |
125 | if( B ) { | 125 | if( B ) { |
126 | ShowWait->show(); | 126 | ShowWait->show(); |
127 | qApp->process | 127 | qApp->process |
128 | } else { | 128 | } else { |
129 | ShowWait->hide(); | 129 | ShowWait->hide(); |
130 | } | 130 | } |
131 | */ | 131 | */ |
132 | } | 132 | } |
133 | 133 | ||
134 | void TheNSResources::findAvailableNetNodes( void ){ | 134 | void TheNSResources::findAvailableNetNodes( void ){ |
135 | 135 | ||
136 | Plugins = new OPluginLoader( "networksettings2" ); | 136 | Plugins = new OPluginLoader( "networksettings2" ); |
137 | Plugins->setAutoDelete( true ); | 137 | Plugins->setAutoDelete( true ); |
138 | 138 | ||
139 | PluginManager = new OPluginManager( Plugins ); | 139 | PluginManager = new OPluginManager( Plugins ); |
140 | PluginManager->load(); | 140 | PluginManager->load(); |
141 | 141 | ||
142 | if( Plugins->isInSafeMode() ) { | 142 | if( Plugins->isInSafeMode() ) { |
143 | QMessageBox::information( | 143 | QMessageBox::information( |
144 | 0, | 144 | 0, |
145 | tr( "Today Error"), | 145 | tr( "Today Error"), |
146 | tr( "<qt>The plugin '%1' caused Today to crash." | 146 | tr( "<qt>The plugin '%1' caused Today to crash." |
147 | " It could be that the plugin is not properly" | 147 | " It could be that the plugin is not properly" |
148 | " installed.<br>Today tries to continue loading" | 148 | " installed.<br>Today tries to continue loading" |
149 | " plugins.</qt>" ) | 149 | " plugins.</qt>" ) |
150 | .arg( PluginManager->crashedPlugin().name())); | 150 | .arg( PluginManager->crashedPlugin().name())); |
151 | } | 151 | } |
152 | 152 | ||
153 | // Get All Plugins | 153 | // Get All Plugins |
154 | OPluginLoader::List allplugins = Plugins->filtered(); | 154 | OPluginLoader::List allplugins = Plugins->filtered(); |
155 | QString lang = ::getenv("LANG"); | 155 | QString lang = ::getenv("LANG"); |
156 | 156 | ||
157 | for( OPluginLoader::List::Iterator it = allplugins.begin(); | 157 | for( OPluginLoader::List::Iterator it = allplugins.begin(); |
158 | it != allplugins.end(); | 158 | it != allplugins.end(); |
159 | ++it ) { | 159 | ++it ) { |
160 | 160 | ||
161 | // check if this plugin supports the proper interface | 161 | // check if this plugin supports the proper interface |
162 | NetNodeInterface * interface = | 162 | NetNodeInterface * interface = |
163 | Plugins->load<NetNodeInterface>( *it, IID_NetworkSettings2 ); | 163 | Plugins->load<NetNodeInterface>( *it, IID_NetworkSettings2 ); |
164 | 164 | ||
165 | if( ! interface ) { | 165 | if( ! interface ) { |
166 | Log(( "Plugin %s from %s does not support proper interface\n", | 166 | Log(( "Plugin %s from %s does not support proper interface\n", |
167 | (*it).name().latin1(), (*it).path().latin1() )); | 167 | (*it).name().latin1(), (*it).path().latin1() )); |
168 | continue; | 168 | continue; |
169 | } | 169 | } |
170 | 170 | ||
171 | // add the nodes in this plugin to the dictionary | 171 | // add the nodes in this plugin to the dictionary |
172 | { QList<ANetNode> PNN; | 172 | { QList<ANetNode> PNN; |
173 | 173 | ||
174 | interface->create_plugin( PNN ); | 174 | interface->create_plugin( PNN ); |
175 | 175 | ||
176 | if( PNN.isEmpty() ) { | 176 | if( PNN.isEmpty() ) { |
177 | Log(( "Plugin %s from %s does offer any nodes\n", | 177 | Log(( "Plugin %s from %s does offer any nodes\n", |
178 | (*it).name().latin1(), (*it).path().latin1() )); | 178 | (*it).name().latin1(), (*it).path().latin1() )); |
179 | delete interface; | 179 | delete interface; |
180 | continue; | 180 | continue; |
181 | } | 181 | } |
182 | 182 | ||
183 | // merge this node with global node | 183 | // merge this node with global node |
184 | for( QListIterator<ANetNode> it(PNN); | 184 | for( QListIterator<ANetNode> it(PNN); |
185 | it.current(); | 185 | it.current(); |
186 | ++it ) { | 186 | ++it ) { |
187 | AllNodeTypes.insert( it.current()->name(), it.current() ); | 187 | AllNodeTypes.insert( it.current()->name(), it.current() ); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | // load the translation | 191 | // load the translation |
192 | QTranslator *trans = new QTranslator(qApp); | 192 | QTranslator *trans = new QTranslator(qApp); |
193 | QString fn = QPEApplication::qpeDir()+ | 193 | QString fn = QPEApplication::qpeDir()+ |
194 | "/i18n/"+lang+"/"+ (*it).name() + ".qm"; | 194 | "/i18n/"+lang+"/"+ (*it).name() + ".qm"; |
195 | 195 | ||
196 | if( trans->load( fn ) ) | 196 | if( trans->load( fn ) ) |
197 | qApp->installTranslator( trans ); | 197 | qApp->installTranslator( trans ); |
198 | else | 198 | else |
199 | delete trans; | 199 | delete trans; |
200 | } | 200 | } |
201 | 201 | ||
202 | } | 202 | } |
203 | 203 | ||
204 | // used to find unique connection number | 204 | // used to find unique connection number |
205 | int TheNSResources::assignConnectionNumber( void ) { | 205 | int TheNSResources::assignConnectionNumber( void ) { |
206 | bool found = 1; | 206 | bool found = 1; |
207 | for( int trial = 0; ; trial ++ ) { | 207 | for( int trial = 0; ; trial ++ ) { |
208 | found = 1; | 208 | found = 1; |
209 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | 209 | for( QDictIterator<NodeCollection> it(ConnectionsMap); |
210 | it.current(); | 210 | it.current(); |
211 | ++it ) { | 211 | ++it ) { |
212 | if( it.current()->number() == trial ) { | 212 | if( it.current()->number() == trial ) { |
213 | found = 0; | 213 | found = 0; |
214 | break; | 214 | break; |
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
218 | if( found ) { | 218 | if( found ) { |
219 | Log(("Assign profile number %d\n", trial )); | 219 | Log(("Assign profile number %d\n", trial )); |
220 | return trial; | 220 | return trial; |
221 | } | 221 | } |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | QPixmap TheNSResources::getPixmap( const QString & QS ) { | 225 | QPixmap TheNSResources::getPixmap( const QString & QS ) { |
226 | QPixmap P; | 226 | QPixmap P; |
227 | QString S("networksettings2/"); | 227 | QString S("networksettings2/"); |
228 | S += QS; | 228 | S += QS; |
229 | P = Resource::loadPixmap( S ); | 229 | P = Resource::loadPixmap( S ); |
230 | if( P.isNull() ) { | 230 | if( P.isNull() ) { |
231 | Log(( "Cannot load %s\n", S.latin1() )); | 231 | Log(( "Cannot load %s\n", S.latin1() )); |
232 | } | 232 | } |
233 | return ( P.isNull() ) ? QPixmap() : P; | 233 | return ( P.isNull() ) ? QPixmap() : P; |
234 | } | 234 | } |
235 | 235 | ||
236 | QString TheNSResources::tr( const char * s ) { | 236 | QString TheNSResources::tr( const char * s ) { |
237 | return qApp->translate( "resource", s ); | 237 | return qApp->translate( "resource", s ); |
238 | } | 238 | } |
239 | 239 | ||
240 | const QString & TheNSResources::netNode2Name( const char * s ) { | 240 | const QString & TheNSResources::netNode2Name( const char * s ) { |
241 | return NodeTypeNameMap[s]; | 241 | return NodeTypeNameMap[s]; |
242 | } | 242 | } |
243 | 243 | ||
244 | const QString & TheNSResources::netNode2Description( const char * s ) { | 244 | const QString & TheNSResources::netNode2Description( const char * s ) { |
245 | return NodeTypeDescriptionMap[s]; | 245 | return NodeTypeDescriptionMap[s]; |
246 | } | 246 | } |
247 | 247 | ||
248 | void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) { | 248 | void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) { |
249 | ANetNodeInstance * NNI; | 249 | ANetNodeInstance * NNI; |
250 | Log(( "Add Connection %s, Dangling %d\n", | ||
251 | NC->name().latin1(), Dangling )); | ||
250 | if( Dangling ) { | 252 | if( Dangling ) { |
251 | DanglingConnectionsMap.insert( NC->name(), NC ); | 253 | DanglingConnectionsMap.insert( NC->name(), NC ); |
252 | } else { | 254 | } else { |
253 | ConnectionsMap.insert( NC->name(), NC ); | 255 | ConnectionsMap.insert( NC->name(), NC ); |
254 | } | 256 | } |
255 | 257 | ||
256 | // add (new) nodes to NodeList | 258 | // add (new) nodes to NodeList |
257 | for( QListIterator<ANetNodeInstance> it(*NC); | 259 | for( QListIterator<ANetNodeInstance> it(*NC); |
258 | it.current(); | 260 | it.current(); |
259 | ++it ) { | 261 | ++it ) { |
260 | NNI = it.current(); | 262 | NNI = it.current(); |
261 | if( findNodeInstance( NNI->name() ) == 0 ) { | 263 | if( findNodeInstance( NNI->name() ) == 0 ) { |
262 | // new item | 264 | // new item |
263 | addNodeInstance( NNI ); | 265 | addNodeInstance( NNI ); |
264 | } | 266 | } |
265 | } | 267 | } |
266 | } | 268 | } |
267 | 269 | ||
268 | void TheNSResources::removeConnection( const QString & N ) { | 270 | void TheNSResources::removeConnection( const QString & N ) { |
269 | NodeCollection * NC = findConnection( N ); | 271 | NodeCollection * NC = findConnection( N ); |
270 | if( ! NC ) | 272 | if( ! NC ) |
271 | return; | 273 | return; |
272 | 274 | ||
273 | // delete netnodes in this connection | 275 | // delete netnodes in this connection |
274 | ANetNodeInstance * NNI; | 276 | ANetNodeInstance * NNI; |
275 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { | 277 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { |
276 | removeNodeInstance( NNI->name() ); | 278 | removeNodeInstance( NNI->name() ); |
277 | } | 279 | } |
278 | if( ConnectionsMap.find( N ) ) { | 280 | if( ConnectionsMap.find( N ) ) { |
279 | ConnectionsMap.remove( N ); | 281 | ConnectionsMap.remove( N ); |
280 | } else { | 282 | } else { |
281 | DanglingConnectionsMap.remove( N ); | 283 | DanglingConnectionsMap.remove( N ); |
282 | } | 284 | } |
283 | 285 | ||
284 | } | 286 | } |
285 | 287 | ||
286 | // dangling connections are filtered out | 288 | // dangling connections are filtered out |
287 | NodeCollection * TheNSResources::findConnection( const QString & S ) { | 289 | NodeCollection * TheNSResources::findConnection( const QString & S ) { |
288 | return ConnectionsMap[ S ]; | 290 | return ConnectionsMap[ S ]; |
289 | } | 291 | } |
290 | 292 | ||
291 | NodeCollection * TheNSResources::getConnection( int nr ) { | 293 | NodeCollection * TheNSResources::getConnection( int nr ) { |
292 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | 294 | for( QDictIterator<NodeCollection> it(ConnectionsMap); |
293 | it.current(); | 295 | it.current(); |
294 | ++it ) { | 296 | ++it ) { |
295 | if( it.current()->number() == nr ) { | 297 | if( it.current()->number() == nr ) { |
296 | return it.current(); | 298 | return it.current(); |
297 | } | 299 | } |
298 | } | 300 | } |
299 | return 0; | 301 | return 0; |
300 | } | 302 | } |
301 | /* | 303 | /* |
302 | void TheNSResources::renumberConnections( void ) { | 304 | void TheNSResources::renumberConnections( void ) { |
303 | Name2Connection_t & M = NSResources->connections(); | 305 | Name2Connection_t & M = NSResources->connections(); |
304 | NodeCollection * NC; | 306 | NodeCollection * NC; |
305 | 307 | ||
306 | // for all connections | 308 | // for all connections |
307 | NodeCollection::resetMaxNr(); | 309 | NodeCollection::resetMaxNr(); |
308 | for( QDictIterator<NodeCollection> it(M); | 310 | for( QDictIterator<NodeCollection> it(M); |
309 | it.current(); | 311 | it.current(); |
310 | ++it ) { | 312 | ++it ) { |
311 | NC = it.current(); | 313 | NC = it.current(); |
312 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 314 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
313 | NC->setModified( 1 ); | 315 | NC->setModified( 1 ); |
314 | } | 316 | } |
315 | } | 317 | } |
316 | */ | 318 | */ |
317 | 319 | ||
318 | typedef struct EnvVars { | 320 | typedef struct EnvVars { |
319 | char * Name; | 321 | char * Name; |
320 | int Len; | 322 | int Len; |
321 | } EnvVar_t; | 323 | } EnvVar_t; |
322 | 324 | ||
323 | #define AnEV(x) x, sizeof(x)-1 | 325 | #define AnEV(x) x, sizeof(x)-1 |
324 | 326 | ||
325 | static EnvVar_t EV[] = { | 327 | static EnvVar_t EV[] = { |
326 | AnEV( "HOME" ), | 328 | AnEV( "HOME" ), |
327 | AnEV( "LOGNAME" ), | 329 | AnEV( "LOGNAME" ), |
328 | AnEV( "USER" ), | 330 | AnEV( "USER" ), |
329 | AnEV( "LD_LIBRARY_PATH" ), | 331 | AnEV( "LD_LIBRARY_PATH" ), |
330 | AnEV( "PATH" ), | 332 | AnEV( "PATH" ), |
331 | AnEV( "QTDIR" ), | 333 | AnEV( "QTDIR" ), |
332 | AnEV( "OPIEDIR" ), | 334 | AnEV( "OPIEDIR" ), |
333 | AnEV( "SHELL" ), | 335 | AnEV( "SHELL" ), |
334 | { NULL, 0 } | 336 | { NULL, 0 } |
335 | }; | 337 | }; |
336 | 338 | ||
337 | void TheNSResources::detectCurrentUser( void ) { | 339 | void TheNSResources::detectCurrentUser( void ) { |
338 | // find current running qpe | 340 | // find current running qpe |
339 | QString QPEEnvFile = ""; | 341 | QString QPEEnvFile = ""; |
340 | 342 | ||
341 | CurrentUser.UserName = ""; | 343 | CurrentUser.UserName = ""; |
342 | CurrentUser.HomeDir = ""; | 344 | CurrentUser.HomeDir = ""; |
343 | 345 | ||
344 | if( getenv( "OPIEDIR" ) == 0 ) { | 346 | if( getenv( "OPIEDIR" ) == 0 ) { |
345 | // nothing known | 347 | // nothing known |
346 | { // open proc dir and find all dirs in it | 348 | { // open proc dir and find all dirs in it |
347 | QRegExp R("[0-9]+"); | 349 | QRegExp R("[0-9]+"); |
348 | QDir ProcDir( "/proc" ); | 350 | QDir ProcDir( "/proc" ); |
349 | QFileInfo FI; | 351 | QFileInfo FI; |
350 | QStringList EL = ProcDir.entryList( QDir::Dirs ); | 352 | QStringList EL = ProcDir.entryList( QDir::Dirs ); |
351 | 353 | ||
352 | // print it out | 354 | // print it out |
353 | for ( QStringList::Iterator it = EL.begin(); | 355 | for ( QStringList::Iterator it = EL.begin(); |
354 | it != EL.end(); | 356 | it != EL.end(); |
355 | ++it ) { | 357 | ++it ) { |
356 | if( R.match( (*it) ) >= 0 ) { | 358 | if( R.match( (*it) ) >= 0 ) { |
357 | QString S = ProcDir.path()+"/"+ (*it); | 359 | QString S = ProcDir.path()+"/"+ (*it); |
358 | S.append( "/exe" ); | 360 | S.append( "/exe" ); |
359 | FI.setFile( S ); | 361 | FI.setFile( S ); |
360 | // get the link | 362 | // get the link |
361 | S = FI.readLink(); | 363 | S = FI.readLink(); |
362 | if( S.right( 8 ) == "/bin/qpe" ) { | 364 | if( S.right( 8 ) == "/bin/qpe" ) { |
363 | // found running qpe | 365 | // found running qpe |
364 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); | 366 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); |
365 | break; | 367 | break; |
366 | } | 368 | } |
367 | } | 369 | } |
368 | } | 370 | } |
369 | } | 371 | } |
370 | 372 | ||
371 | if( QPEEnvFile.isEmpty() ) { | 373 | if( QPEEnvFile.isEmpty() ) { |
372 | // could not find qpe | 374 | // could not find qpe |
373 | Log(("Could not find qpe\n" )); | 375 | Log(("Could not find qpe\n" )); |
374 | return; | 376 | return; |
375 | } | 377 | } |
376 | 378 | ||
377 | // FI now contains path ProcDir to the cmd dir | 379 | // FI now contains path ProcDir to the cmd dir |
378 | { char * Buf = 0; | 380 | { char * Buf = 0; |
379 | char TB[1024]; | 381 | char TB[1024]; |
380 | long BufSize = 0; | 382 | long BufSize = 0; |
381 | int fd; | 383 | int fd; |
382 | int rd; | 384 | int rd; |
383 | 385 | ||
384 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); | 386 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); |
385 | if( fd < 0 ) { | 387 | if( fd < 0 ) { |
386 | Log(("Could not open %s : %d\n", | 388 | Log(("Could not open %s : %d\n", |
387 | QPEEnvFile.latin1(), errno )); | 389 | QPEEnvFile.latin1(), errno )); |
388 | return; | 390 | return; |
389 | } | 391 | } |
390 | 392 | ||
391 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { | 393 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { |
392 | Buf = (char *)realloc( Buf, BufSize+rd ); | 394 | Buf = (char *)realloc( Buf, BufSize+rd ); |
393 | memcpy( Buf+BufSize, TB, rd ); | 395 | memcpy( Buf+BufSize, TB, rd ); |
394 | BufSize += rd; | 396 | BufSize += rd; |
395 | } | 397 | } |
396 | 398 | ||
397 | char * Data = Buf; | 399 | char * Data = Buf; |
398 | char * DataEnd = Data+BufSize-1; | 400 | char * DataEnd = Data+BufSize-1; |
399 | 401 | ||
400 | // get env items out of list | 402 | // get env items out of list |
401 | while( Data < DataEnd ) { | 403 | while( Data < DataEnd ) { |
402 | 404 | ||
403 | EnvVar_t * Run = EV; | 405 | EnvVar_t * Run = EV; |
404 | while( Run->Name ) { | 406 | while( Run->Name ) { |
405 | if( strncmp( Data, Run->Name, Run->Len ) == 0 && | 407 | if( strncmp( Data, Run->Name, Run->Len ) == 0 && |
406 | Data[Run->Len] == '=' | 408 | Data[Run->Len] == '=' |
407 | ) { | 409 | ) { |
408 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | 410 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); |
409 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | 411 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = |
410 | strdup( Data ); | 412 | strdup( Data ); |
411 | 413 | ||
412 | if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { | 414 | if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { |
413 | // put OPIEDIR in env | 415 | // put OPIEDIR in env |
414 | putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); | 416 | putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); |
415 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { | 417 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { |
416 | CurrentUser.HomeDir = Data+5; | 418 | CurrentUser.HomeDir = Data+5; |
417 | } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { | 419 | } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { |
418 | CurrentUser.UserName = Data+8; | 420 | CurrentUser.UserName = Data+8; |
419 | } | 421 | } |
420 | break; | 422 | break; |
421 | } | 423 | } |
422 | Run ++; | 424 | Run ++; |
423 | } | 425 | } |
424 | 426 | ||
425 | Data += strlen( Data )+1; | 427 | Data += strlen( Data )+1; |
426 | } | 428 | } |
427 | 429 | ||
428 | free( Buf ); | 430 | free( Buf ); |
429 | 431 | ||
430 | if( ! CurrentUser.UserName.isEmpty() ) { | 432 | if( ! CurrentUser.UserName.isEmpty() ) { |
431 | // find user info | 433 | // find user info |
432 | struct passwd pwd; | 434 | struct passwd pwd; |
433 | struct passwd * pwdres; | 435 | struct passwd * pwdres; |
434 | 436 | ||
435 | if( getpwnam_r( CurrentUser.UserName.latin1(), | 437 | if( getpwnam_r( CurrentUser.UserName.latin1(), |
436 | &pwd, TB, sizeof(TB), &pwdres ) || | 438 | &pwd, TB, sizeof(TB), &pwdres ) || |
437 | pwdres == 0 ) { | 439 | pwdres == 0 ) { |
438 | Log(("Could not determine user %s : %d\n", | 440 | Log(("Could not determine user %s : %d\n", |
439 | CurrentUser.UserName.latin1(), errno )); | 441 | CurrentUser.UserName.latin1(), errno )); |
440 | return; | 442 | return; |
441 | } | 443 | } |
442 | CurrentUser.Uid = pwd.pw_uid; | 444 | CurrentUser.Uid = pwd.pw_uid; |
443 | CurrentUser.Gid = pwd.pw_gid; | 445 | CurrentUser.Gid = pwd.pw_gid; |
444 | } else{ | 446 | } else{ |
445 | CurrentUser.Uid = | 447 | CurrentUser.Uid = |
446 | CurrentUser.Gid = -1; | 448 | CurrentUser.Gid = -1; |
447 | } | 449 | } |
448 | } | 450 | } |
449 | 451 | ||
450 | } else { | 452 | } else { |
451 | char * X; | 453 | char * X; |
452 | QString S; | 454 | QString S; |
453 | 455 | ||
454 | EnvVar_t * Run = EV; | 456 | EnvVar_t * Run = EV; |
455 | while( Run->Name ) { | 457 | while( Run->Name ) { |
456 | 458 | ||
457 | if( ( X = getenv( Run->Name ) ) ) { | 459 | if( ( X = getenv( Run->Name ) ) ) { |
458 | Log(( "Env : %s = %s\n", Run->Name, X )); | 460 | Log(( "Env : %s = %s\n", Run->Name, X )); |
459 | 461 | ||
460 | S.sprintf( "%s=%s", Run->Name, X ); | 462 | S.sprintf( "%s=%s", Run->Name, X ); |
461 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | 463 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); |
462 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | 464 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = |
463 | strdup( S.latin1() ); | 465 | strdup( S.latin1() ); |
464 | 466 | ||
465 | if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { | 467 | if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { |
466 | CurrentUser.UserName = X; | 468 | CurrentUser.UserName = X; |
467 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { | 469 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { |
468 | CurrentUser.HomeDir = X; | 470 | CurrentUser.HomeDir = X; |
469 | } // regulare env var | 471 | } // regulare env var |
470 | } else { | 472 | } else { |
471 | Log(("Could not determine %s\n", Run->Name )); | 473 | Log(("Could not determine %s\n", Run->Name )); |
472 | } | 474 | } |
473 | Run ++; | 475 | Run ++; |
474 | } | 476 | } |
475 | 477 | ||
476 | CurrentUser.Uid = getuid(); | 478 | CurrentUser.Uid = getuid(); |
477 | CurrentUser.Gid = getgid(); | 479 | CurrentUser.Gid = getgid(); |
478 | } | 480 | } |
479 | } | 481 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index b27cda1..51c4250 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h | |||
@@ -1,153 +1,153 @@ | |||
1 | #ifndef __RESOURCES__H | 1 | #ifndef __RESOURCES__H |
2 | #define __RESOURCES__H | 2 | #define __RESOURCES__H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qdict.h> | 5 | #include <qdict.h> |
6 | #include <qmap.h> | 6 | #include <qmap.h> |
7 | #include <qlist.h> | 7 | #include <qlist.h> |
8 | #include "netnode.h" | 8 | #include "netnode.h" |
9 | #include "systemfile.h" | 9 | #include "systemfile.h" |
10 | #include "system.h" | 10 | #include "system.h" |
11 | 11 | ||
12 | class QLibrary; | 12 | class QLibrary; |
13 | class QPixmap; | 13 | class QPixmap; |
14 | class ANetNode; | 14 | class ANetNode; |
15 | class ANetNodeInstance; | 15 | class ANetNodeInstance; |
16 | 16 | ||
17 | namespace Opie { | 17 | namespace Opie { |
18 | namespace Core { | 18 | namespace Core { |
19 | class OPluginLoader; | 19 | class OPluginLoader; |
20 | class OPluginManager; | 20 | class OPluginManager; |
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
24 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); | 24 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); |
25 | 25 | ||
26 | class CurrentQPEUser { | 26 | class CurrentQPEUser { |
27 | 27 | ||
28 | public : | 28 | public : |
29 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} | 29 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} |
30 | 30 | ||
31 | inline bool known( void ) | 31 | inline bool known( void ) |
32 | { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } | 32 | { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } |
33 | 33 | ||
34 | QString UserName; | 34 | QString UserName; |
35 | QString HomeDir; | 35 | QString HomeDir; |
36 | int Uid; | 36 | int Uid; |
37 | int Gid; | 37 | int Gid; |
38 | QArray<char *> EnvList; | 38 | QArray<char *> EnvList; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | typedef QDict<ANetNode> Name2NetNode_t; | 41 | typedef QDict<ANetNode> Name2NetNode_t; |
42 | typedef QDict<ANetNodeInstance > Name2Instance_t; | 42 | typedef QDict<ANetNodeInstance > Name2Instance_t; |
43 | typedef QDict<NodeCollection> Name2Connection_t; | 43 | typedef QDict<NodeCollection> Name2Connection_t; |
44 | typedef QDict<SystemFile> Name2SystemFile_t; | 44 | typedef QDict<SystemFile> Name2SystemFile_t; |
45 | 45 | ||
46 | class TheNSResources { | 46 | class TheNSResources { |
47 | 47 | ||
48 | public : | 48 | public : |
49 | 49 | ||
50 | TheNSResources( void ); | 50 | TheNSResources( void ); |
51 | ~TheNSResources( ); | 51 | ~TheNSResources( ); |
52 | 52 | ||
53 | // give busy feedback | 53 | // give busy feedback |
54 | void busy( bool B ); | 54 | void busy( bool B ); |
55 | 55 | ||
56 | System & system() | 56 | System & system() |
57 | { return *TheSystem; } | 57 | { return *TheSystem; } |
58 | 58 | ||
59 | int assignConnectionNumber(void); | 59 | int assignConnectionNumber(void); |
60 | QPixmap getPixmap( const QString & Name ); | 60 | QPixmap getPixmap( const QString & Name ); |
61 | 61 | ||
62 | Name2NetNode_t & netNodes( void ) | 62 | Name2NetNode_t & netNodes( void ) |
63 | { return AllNodeTypes; } | 63 | { return AllNodeTypes; } |
64 | bool netNodeExists( const QString & X ) | 64 | bool netNodeExists( const QString & X ) |
65 | { return AllNodeTypes.find(X)!=0; } | 65 | { return AllNodeTypes.find(X)!=0; } |
66 | ANetNode * findNetNode( const QString & N ) | 66 | ANetNode * findNetNode( const QString & N ) |
67 | { return AllNodeTypes.find(N); | 67 | { return AllNodeTypes.find(N); |
68 | } | 68 | } |
69 | // define new plugin (=node) | 69 | // define new plugin (=node) |
70 | void addNodeType( const QString & ID, | 70 | void addNodeType( const QString & ID, |
71 | const QString & LongName, | 71 | const QString & LongName, |
72 | const QString & Description ); | 72 | const QString & Description ); |
73 | 73 | ||
74 | Name2SystemFile_t & systemFiles( void ) | 74 | Name2SystemFile_t & systemFiles( void ) |
75 | { return SystemFiles; } | 75 | { return SystemFiles; } |
76 | void addSystemFile( const QString & ID, | 76 | void addSystemFile( const QString & ID, |
77 | const QString & P, | 77 | const QString & P, |
78 | bool KDI ); | 78 | bool KDI ); |
79 | 79 | ||
80 | ANetNodeInstance * createNodeInstance( const QString & S ) | 80 | ANetNodeInstance * createNodeInstance( const QString & S ) |
81 | { ANetNode * NN = findNetNode( S ); | 81 | { ANetNode * NN = findNetNode( S ); |
82 | 82 | ||
83 | Log(( "Find node type %s : %p\n", S.latin1(), NN )); | 83 | Log(( "Find node type %s : %p\n", S.latin1(), NN )); |
84 | 84 | ||
85 | if( NN == 0 ) | 85 | if( NN == 0 ) |
86 | // type of this instance not found | 86 | // type of this instance not found |
87 | return 0; | 87 | return 0; |
88 | 88 | ||
89 | ANetNodeInstance * NNI = NN->createInstance(); | 89 | ANetNodeInstance * NNI = NN->createInstance(); |
90 | NNI->initialize(); | 90 | NNI->initialize(); |
91 | return NNI; | 91 | return NNI; |
92 | } | 92 | } |
93 | 93 | ||
94 | Name2Instance_t & netNodeInstances( void ) | 94 | Name2Instance_t & netNodeInstances( void ) |
95 | { return AllNodes; } | 95 | { return AllNodes; } |
96 | void addNodeInstance( ANetNodeInstance * I ) | 96 | void addNodeInstance( ANetNodeInstance * I ) |
97 | { AllNodes.insert( I->name(), I ); } | 97 | { AllNodes.insert( I->name(), I ); } |
98 | void removeNodeInstance( const QString & N ) | 98 | void removeNodeInstance( const QString & N ) |
99 | { AllNodes.remove( N );} | 99 | { AllNodes.remove( N );} |
100 | ANetNodeInstance * findNodeInstance( const QString & S ) | 100 | ANetNodeInstance * findNodeInstance( const QString & S ) |
101 | { return AllNodes[S]; } | 101 | { return AllNodes[S]; } |
102 | 102 | ||
103 | const QString & netNode2Name( const char * Type ); | 103 | const QString & netNode2Name( const char * Type ); |
104 | const QString & netNode2Description( const char * Type ); | 104 | const QString & netNode2Description( const char * Type ); |
105 | 105 | ||
106 | void addConnection( NodeCollection * NC, bool Dangling ); | 106 | void addConnection( NodeCollection * NC, bool Dangling ); |
107 | void removeConnection( const QString & N ); | 107 | void removeConnection( const QString & N ); |
108 | NodeCollection * findConnection( const QString & N ); | 108 | NodeCollection * findConnection( const QString & N ); |
109 | NodeCollection * getConnection( int nr ); | 109 | NodeCollection * getConnection( int nr ); |
110 | Name2Connection_t & connections( void ) | 110 | Name2Connection_t & connections( void ) |
111 | { return ConnectionsMap; } | 111 | { return ConnectionsMap; } |
112 | Name2Connection_t & danglingConnections( void ) | 112 | Name2Connection_t & danglingConnections( void ) |
113 | { return ConnectionsMap; } | 113 | { return DanglingConnectionsMap; } |
114 | 114 | ||
115 | inline bool userKnown( void ) | 115 | inline bool userKnown( void ) |
116 | { return CurrentUser.known(); } | 116 | { return CurrentUser.known(); } |
117 | CurrentQPEUser & currentUser( void ) | 117 | CurrentQPEUser & currentUser( void ) |
118 | { return CurrentUser; } | 118 | { return CurrentUser; } |
119 | 119 | ||
120 | private : | 120 | private : |
121 | 121 | ||
122 | void detectCurrentUser( void ); | 122 | void detectCurrentUser( void ); |
123 | QString tr( const char * path ); | 123 | QString tr( const char * path ); |
124 | 124 | ||
125 | void findAvailableNetNodes( void ); | 125 | void findAvailableNetNodes( void ); |
126 | 126 | ||
127 | QMap< QString, QString> NodeTypeNameMap; | 127 | QMap< QString, QString> NodeTypeNameMap; |
128 | QMap< QString, QString> NodeTypeDescriptionMap; | 128 | QMap< QString, QString> NodeTypeDescriptionMap; |
129 | // list of connections that are valid | 129 | // list of connections that are valid |
130 | Name2Connection_t ConnectionsMap; | 130 | Name2Connection_t ConnectionsMap; |
131 | // list of connection configurations that are not valid | 131 | // list of connection configurations that are not valid |
132 | // e.g. because plugins are missing | 132 | // e.g. because plugins are missing |
133 | Name2Connection_t DanglingConnectionsMap; | 133 | Name2Connection_t DanglingConnectionsMap; |
134 | System * TheSystem; | 134 | System * TheSystem; |
135 | Name2SystemFile_t SystemFiles; | 135 | Name2SystemFile_t SystemFiles; |
136 | 136 | ||
137 | // all node type classes | 137 | // all node type classes |
138 | Name2NetNode_t AllNodeTypes; | 138 | Name2NetNode_t AllNodeTypes; |
139 | 139 | ||
140 | // all nodes | 140 | // all nodes |
141 | Name2Instance_t AllNodes; | 141 | Name2Instance_t AllNodes; |
142 | 142 | ||
143 | CurrentQPEUser CurrentUser; | 143 | CurrentQPEUser CurrentUser; |
144 | 144 | ||
145 | Opie::Core::OPluginLoader * Plugins; | 145 | Opie::Core::OPluginLoader * Plugins; |
146 | Opie::Core::OPluginManager * PluginManager; | 146 | Opie::Core::OPluginManager * PluginManager; |
147 | 147 | ||
148 | }; | 148 | }; |
149 | 149 | ||
150 | extern TheNSResources * _NSResources; | 150 | extern TheNSResources * _NSResources; |
151 | #define NSResources _NSResources | 151 | #define NSResources _NSResources |
152 | 152 | ||
153 | #endif | 153 | #endif |
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index f027d35..a290f08 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp | |||
@@ -1,587 +1,603 @@ | |||
1 | #include <sys/types.h> | 1 | #include <sys/types.h> |
2 | #include <sys/wait.h> | 2 | #include <sys/wait.h> |
3 | 3 | ||
4 | #include <net/if.h> | 4 | #include <net/if.h> |
5 | #include <net/if_arp.h> | 5 | #include <net/if_arp.h> |
6 | #include <netinet/in.h> | 6 | #include <netinet/in.h> |
7 | #include <arpa/inet.h> | 7 | #include <arpa/inet.h> |
8 | #include <sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
9 | #include <sys/socket.h> | 9 | #include <sys/socket.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <fcntl.h> | 12 | #include <fcntl.h> |
13 | #include <errno.h> | 13 | #include <errno.h> |
14 | #include <unistd.h> | 14 | #include <unistd.h> |
15 | 15 | ||
16 | #include <opie2/oprocess.h> | 16 | #include <opie2/oprocess.h> |
17 | 17 | ||
18 | #include <qdir.h> | 18 | #include <qdir.h> |
19 | #include <qregexp.h> | 19 | #include <qregexp.h> |
20 | #include <qstringlist.h> | 20 | #include <qstringlist.h> |
21 | #include <qfile.h> | 21 | #include <qfile.h> |
22 | #include <qtextstream.h> | 22 | #include <qtextstream.h> |
23 | #include <qapplication.h> | 23 | #include <qapplication.h> |
24 | 24 | ||
25 | #include "resources.h" | 25 | #include "resources.h" |
26 | #include "system.h" | 26 | #include "system.h" |
27 | 27 | ||
28 | #define PROCNETDEV "/proc/net/dev" | 28 | #define PROCNETDEV "/proc/net/dev" |
29 | 29 | ||
30 | #ifndef ARPHRD_IEEE80211 | 30 | #ifndef ARPHRD_IEEE80211 |
31 | #define ARPHRD_IEEE80211 801 | 31 | #define ARPHRD_IEEE80211 801 |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | static char Dig2Hex[] = { | 34 | static char Dig2Hex[] = { |
35 | '0', '1', '2', '3', | 35 | '0', '1', '2', '3', |
36 | '4', '5', '6', '7', | 36 | '4', '5', '6', '7', |
37 | '8', '9', 'A', 'B', | 37 | '8', '9', 'A', 'B', |
38 | 'C', 'D', 'E', 'F' | 38 | 'C', 'D', 'E', 'F' |
39 | }; | 39 | }; |
40 | 40 | ||
41 | // get HIGH nibble of byte | 41 | // get HIGH nibble of byte |
42 | #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] | 42 | #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] |
43 | // get LOW nibble of byte | 43 | // get LOW nibble of byte |
44 | #define LN(x) Dig2Hex[((x)&0x0f)] | 44 | #define LN(x) Dig2Hex[((x)&0x0f)] |
45 | 45 | ||
46 | System::System( void ) : QObject(), ProbedInterfaces() { | 46 | System::System( void ) : QObject(), ProbedInterfaces() { |
47 | ProcDevNet = 0; | 47 | ProcDevNet = 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | System::~System( void ) { | 50 | System::~System( void ) { |
51 | if( ProcDevNet ) | 51 | if( ProcDevNet ) |
52 | delete ProcDevNet; | 52 | delete ProcDevNet; |
53 | } | 53 | } |
54 | 54 | ||
55 | QDict<InterfaceInfo> & System::interfaces( void ) { | 55 | QDict<InterfaceInfo> & System::interfaces( void ) { |
56 | if( ProbedInterfaces.count() == 0 ) { | 56 | if( ProbedInterfaces.count() == 0 ) { |
57 | probeInterfaces(); | 57 | probeInterfaces(); |
58 | } | 58 | } |
59 | return ProbedInterfaces; | 59 | return ProbedInterfaces; |
60 | } | 60 | } |
61 | 61 | ||
62 | int System::runAsRoot( QStringList & S, MyProcess * Prc ) { | 62 | int System::runAsRoot( QStringList & S, MyProcess * Prc ) { |
63 | char * usr = getenv("USER"); | 63 | char * usr = getenv("USER"); |
64 | 64 | ||
65 | if( S.count() == 0 ) { | 65 | if( S.count() == 0 ) { |
66 | // loophole to start shell | 66 | // close loophole to start shell |
67 | return 8888; | 67 | return 8888; |
68 | } | 68 | } |
69 | if( usr == 0 || strcmp( usr, "root" ) ) { | 69 | if( usr == 0 || strcmp( usr, "root" ) ) { |
70 | // unknown or non-root user -> use SUDO | 70 | // unknown or non-root user -> use SUDO |
71 | S.prepend( "sudo" ); | 71 | S.prepend( "sudo" ); |
72 | } | 72 | } |
73 | 73 | ||
74 | if( getenv( "NS2TESTMODE" ) ) { | 74 | if( getenv( "NS2TESTMODE" ) ) { |
75 | odebug << "TESTMODE !!! execute " | 75 | odebug << "TESTMODE !!! execute " |
76 | << S.join( " ") | 76 | << S.join( " ") |
77 | << oendl; | 77 | << oendl; |
78 | } else { | 78 | } else { |
79 | MyProcess * P; | 79 | MyProcess * P; |
80 | 80 | ||
81 | if( Prc ) { | 81 | if( Prc ) { |
82 | P = Prc; | 82 | P = Prc; |
83 | } else { | 83 | } else { |
84 | P = new MyProcess(); | 84 | P = new MyProcess(); |
85 | emit processEvent( tr("Command : ") + S.join( " " ) ); | 85 | emit processEvent( tr("Command : ") + S.join( " " ) ); |
86 | 86 | ||
87 | connect( P, | 87 | connect( P, |
88 | SIGNAL( stdoutLine( const QString & ) ), | 88 | SIGNAL( stdoutLine( const QString & ) ), |
89 | this, | 89 | this, |
90 | SIGNAL( stdoutLine( const QString & ) ) ); | 90 | SIGNAL( stdoutLine( const QString & ) ) ); |
91 | 91 | ||
92 | connect( P, | 92 | connect( P, |
93 | SIGNAL( stderrLine( const QString & ) ), | 93 | SIGNAL( stderrLine( const QString & ) ), |
94 | this, | 94 | this, |
95 | SIGNAL( stderrLine( const QString & ) ) ); | 95 | SIGNAL( stderrLine( const QString & ) ) ); |
96 | 96 | ||
97 | connect( P, | 97 | connect( P, |
98 | SIGNAL(processExited(MyProcess*) ), | 98 | SIGNAL(processExited(MyProcess*) ), |
99 | this, SLOT | 99 | this, SLOT |
100 | (SLOT_ProcessExited(MyProcess*) ) ); | 100 | (SLOT_ProcessExited(MyProcess*) ) ); |
101 | } | 101 | } |
102 | 102 | ||
103 | P->process() << S; | 103 | P->process() << S; |
104 | 104 | ||
105 | Log(("Executing %s\n", S.join( " " ).latin1() )); | 105 | Log(("Executing %s\n", S.join( " " ).latin1() )); |
106 | 106 | ||
107 | if( ! P->process().start( OProcess::DontCare, | 107 | if( ! P->process().start( OProcess::DontCare, |
108 | OProcess::AllOutput ) ) { | 108 | OProcess::AllOutput ) ) { |
109 | odebug << "Error starting " << S << oendl; | 109 | odebug << "Error starting " << S << oendl; |
110 | if( ! Prc ) | 110 | if( ! Prc ) |
111 | delete P; | 111 | delete P; |
112 | // error starting app | 112 | // error starting app |
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | odebug << "Started " << S << oendl; | 115 | odebug << "Started " << S << oendl; |
116 | } | 116 | } |
117 | 117 | ||
118 | // all is fine | 118 | // all is fine |
119 | return 1; | 119 | return 1; |
120 | } | 120 | } |
121 | 121 | ||
122 | int System::execAsUser( QStringList & SL ) { | 122 | int System::execAsUser( QStringList & SL, bool Synchronous ) { |
123 | MyProcess * P = new MyProcess(); | 123 | MyProcess * P = new MyProcess(); |
124 | CurrentQPEUser CU = NSResources->currentUser(); | 124 | CurrentQPEUser CU = NSResources->currentUser(); |
125 | char * usr = getenv("USER"); | 125 | char * usr = getenv("USER"); |
126 | 126 | ||
127 | if( strcmp( usr, "root" ) == 0 ) { | 127 | if( usr == 0 || |
128 | strcmp( usr, "root" ) == 0 ) { | ||
128 | // find user running qpe | 129 | // find user running qpe |
129 | if( CU.UserName.isEmpty() ) { | 130 | if( CU.UserName.isEmpty() ) { |
130 | // if we come here, the exec was not successfull | 131 | // if we come here, the exec was not successfull |
131 | Log(("User not known \n" )); | 132 | Log(("User not known \n" )); |
132 | return 0; | 133 | return 0; |
133 | } | 134 | } |
134 | } | 135 | } |
135 | 136 | ||
136 | // now we are ready to exec the requested command | 137 | // now we are ready to exec the requested command |
137 | setuid( CU.Uid ); | 138 | setuid( CU.Uid ); |
138 | setgid( CU.Gid ); | 139 | setgid( CU.Gid ); |
139 | 140 | ||
140 | for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { | 141 | for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { |
141 | QString X; | 142 | QString X; |
142 | QStringList SL; | 143 | QStringList SL; |
143 | X = CU.EnvList[i]; | 144 | X = CU.EnvList[i]; |
144 | SL = QStringList::split( "=", X ); | 145 | SL = QStringList::split( "=", X ); |
145 | P->process().setEnvironment( SL[0], SL[1] ); | 146 | P->process().setEnvironment( SL[0], SL[1] ); |
146 | } | 147 | } |
147 | 148 | ||
148 | P->process() << SL; | 149 | P->process() << SL; |
149 | 150 | ||
150 | emit processEvent( tr("Command : ") + SL.join( " " ) ); | 151 | emit processEvent( tr("Command : ") + SL.join( " " ) ); |
151 | 152 | ||
152 | Log(("Executing as user %s : %s\n", | 153 | Log(("Executing as user %s : %s\n", |
153 | CU.UserName.latin1(), | 154 | CU.UserName.latin1(), |
154 | SL.join( " " ).latin1() )); | 155 | SL.join( " " ).latin1() )); |
155 | 156 | ||
156 | int rv = ( P->process().start( OProcess::DontCare, | 157 | P->setEchoMode( Synchronous ); |
157 | OProcess::NoCommunication ) ); | 158 | |
159 | bool rv = P->process().start( | ||
160 | (Synchronous) ? OProcess::Block : | ||
161 | OProcess::DontCare, | ||
162 | (Synchronous) ? OProcess::AllOutput : | ||
163 | OProcess::NoCommunication ); | ||
158 | delete P; | 164 | delete P; |
159 | 165 | ||
160 | if( rv ) { | 166 | if( ! rv ) { |
161 | // if we come here, the exec was not successfull | 167 | // if we come here, the exec was not successfull |
162 | Log(("Could not exec : %d\n", errno )); | 168 | Log(("Could not exec : %d\n", errno )); |
163 | } | 169 | } |
164 | 170 | ||
165 | return ! rv; | 171 | return rv; |
166 | } | 172 | } |
167 | 173 | ||
168 | void System::SLOT_ProcessExited( MyProcess * P ) { | 174 | void System::SLOT_ProcessExited( MyProcess * P ) { |
169 | QString R; | 175 | QString R; |
170 | 176 | ||
171 | for( QValueListConstIterator<QCString> it = P->process().args().begin(); | 177 | for( QValueListConstIterator<QCString> it = P->process().args().begin(); |
172 | it != P->process().args().end(); | 178 | it != P->process().args().end(); |
173 | ++it ) { | 179 | ++it ) { |
174 | R += (*it); | 180 | R += (*it); |
175 | R += " "; | 181 | R += " "; |
176 | } | 182 | } |
177 | 183 | ||
178 | R += "Returned with " + QString().setNum( P->process().exitStatus() ); | 184 | R += "Returned with " + QString().setNum( P->process().exitStatus() ); |
179 | emit processEvent( R ); | 185 | emit processEvent( R ); |
180 | delete P; | 186 | delete P; |
181 | } | 187 | } |
182 | 188 | ||
183 | void System::refreshStatistics( InterfaceInfo & I ) { | 189 | void System::refreshStatistics( InterfaceInfo & I ) { |
184 | if( ! ProcDevNet ) { | 190 | if( ! ProcDevNet ) { |
185 | return; | 191 | return; |
186 | } | 192 | } |
187 | // cannot seek on dev | 193 | // cannot seek on dev |
188 | ProcDevNet->close(); | 194 | ProcDevNet->close(); |
189 | ProcDevNet->open( IO_ReadOnly ); | 195 | ProcDevNet->open( IO_ReadOnly ); |
190 | 196 | ||
191 | QString line; | 197 | QString line; |
192 | QTextStream procTs(ProcDevNet); | 198 | QTextStream procTs(ProcDevNet); |
193 | QStringList SL; | 199 | QStringList SL; |
194 | int loc = -1; | 200 | int loc = -1; |
195 | int version; | 201 | int version; |
196 | 202 | ||
197 | procTs.readLine(); | 203 | procTs.readLine(); |
198 | line = procTs.readLine(); | 204 | line = procTs.readLine(); |
199 | // get version | 205 | // get version |
200 | if( line.find("compressed") ) | 206 | if( line.find("compressed") ) |
201 | version = 3; | 207 | version = 3; |
202 | else if( line.find( "bytes" ) ) | 208 | else if( line.find( "bytes" ) ) |
203 | version = 2; | 209 | version = 2; |
204 | else | 210 | else |
205 | version = 1; | 211 | version = 1; |
206 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { | 212 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { |
207 | if( (loc = line.find(":") ) == -1) { | 213 | if( (loc = line.find(":") ) == -1) { |
208 | continue; | 214 | continue; |
209 | } | 215 | } |
210 | 216 | ||
211 | if( I.Name != line.left(loc) ) | 217 | if( I.Name != line.left(loc) ) |
212 | continue; | 218 | continue; |
213 | 219 | ||
214 | // tokenize | 220 | // tokenize |
215 | SL = QStringList::split( ' ', line, FALSE ); | 221 | SL = QStringList::split( ' ', line, FALSE ); |
216 | 222 | ||
217 | // update data | 223 | // update data |
218 | switch( version ) { | 224 | switch( version ) { |
219 | case 1 : | 225 | case 1 : |
220 | I.RcvBytes = SL[1]; | 226 | I.RcvBytes = SL[1]; |
221 | I.RcvErrors = SL[3]; | 227 | I.RcvErrors = SL[3]; |
222 | I.RcvDropped = SL[4]; | 228 | I.RcvDropped = SL[4]; |
223 | I.SndBytes = SL[6]; | 229 | I.SndBytes = SL[6]; |
224 | I.SndErrors = SL[8]; | 230 | I.SndErrors = SL[8]; |
225 | I.SndDropped = SL[9]; | 231 | I.SndDropped = SL[9]; |
226 | I.Collisions = SL[11]; | 232 | I.Collisions = SL[11]; |
227 | break; | 233 | break; |
228 | case 2 : | 234 | case 2 : |
229 | I.RcvBytes = SL[1]; | 235 | I.RcvBytes = SL[1]; |
230 | I.RcvErrors = SL[3]; | 236 | I.RcvErrors = SL[3]; |
231 | I.RcvDropped = SL[4]; | 237 | I.RcvDropped = SL[4]; |
232 | I.SndBytes = SL[7]; | 238 | I.SndBytes = SL[7]; |
233 | I.SndErrors = SL[9]; | 239 | I.SndErrors = SL[9]; |
234 | I.SndDropped = SL[10]; | 240 | I.SndDropped = SL[10]; |
235 | I.Collisions = SL[12]; | 241 | I.Collisions = SL[12]; |
236 | break; | 242 | break; |
237 | case 3 : | 243 | case 3 : |
238 | I.RcvBytes = SL[1]; | 244 | I.RcvBytes = SL[1]; |
239 | I.RcvErrors = SL[3]; | 245 | I.RcvErrors = SL[3]; |
240 | I.RcvDropped = SL[4]; | 246 | I.RcvDropped = SL[4]; |
241 | I.SndBytes = SL[9]; | 247 | I.SndBytes = SL[9]; |
242 | I.SndErrors = SL[11]; | 248 | I.SndErrors = SL[11]; |
243 | I.SndDropped = SL[12]; | 249 | I.SndDropped = SL[12]; |
244 | I.Collisions = SL[14]; | 250 | I.Collisions = SL[14]; |
245 | break; | 251 | break; |
246 | } | 252 | } |
247 | break; | 253 | break; |
248 | } | 254 | } |
249 | } | 255 | } |
250 | 256 | ||
251 | // | 257 | // |
252 | // THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT | 258 | // THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT |
253 | // FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT | 259 | // FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT |
254 | // | 260 | // |
255 | 261 | ||
256 | void System::probeInterfaces( void ) { | 262 | void System::probeInterfaces( void ) { |
257 | 263 | ||
258 | // probe interfaces | 264 | // probe interfaces |
259 | int sockfd; | 265 | int sockfd; |
260 | // get list of all interfaces | 266 | // get list of all interfaces |
261 | struct ifreq ifrs; | 267 | struct ifreq ifrs; |
262 | InterfaceInfo * IFI; | 268 | InterfaceInfo * IFI; |
263 | 269 | ||
264 | // flag all as 'down' | 270 | // flag all as 'down' |
265 | for( QDictIterator<InterfaceInfo> it( ProbedInterfaces ); | 271 | for( QDictIterator<InterfaceInfo> it( ProbedInterfaces ); |
266 | it.current(); | 272 | it.current(); |
267 | ++it ) { | 273 | ++it ) { |
268 | it.current()->IsUp = 0; | 274 | it.current()->IsUp = 0; |
269 | } | 275 | } |
270 | 276 | ||
271 | sockfd = socket(PF_INET, SOCK_DGRAM, 0); | 277 | sockfd = socket(PF_INET, SOCK_DGRAM, 0); |
272 | if(sockfd == -1) { | 278 | if(sockfd == -1) { |
273 | odebug << "Cannot open INET socket " | 279 | odebug << "Cannot open INET socket " |
274 | << errno | 280 | << errno |
275 | << " " | 281 | << " " |
276 | << strerror( errno ) | 282 | << strerror( errno ) |
277 | << oendl; | 283 | << oendl; |
278 | return; | 284 | return; |
279 | } | 285 | } |
280 | 286 | ||
281 | // read interfaces from /proc/dev/net | 287 | // read interfaces from /proc/dev/net |
282 | // SIOCGIFCONF does not return ALL interfaces ???!? | 288 | // SIOCGIFCONF does not return ALL interfaces ???!? |
283 | ProcDevNet = new QFile(PROCNETDEV); | 289 | ProcDevNet = new QFile(PROCNETDEV); |
284 | if( ! ProcDevNet->open(IO_ReadOnly) ) { | 290 | if( ! ProcDevNet->open(IO_ReadOnly) ) { |
285 | odebug << "Cannot open " | 291 | odebug << "Cannot open " |
286 | << PROCNETDEV | 292 | << PROCNETDEV |
287 | << " " | 293 | << " " |
288 | << errno | 294 | << errno |
289 | << " " | 295 | << " " |
290 | << strerror( errno ) | 296 | << strerror( errno ) |
291 | << oendl; | 297 | << oendl; |
292 | delete ProcDevNet; | 298 | delete ProcDevNet; |
293 | ProcDevNet =0; | 299 | ProcDevNet =0; |
294 | ::close( sockfd ); | 300 | ::close( sockfd ); |
295 | return; | 301 | return; |
296 | } | 302 | } |
297 | 303 | ||
298 | QString line; | 304 | QString line; |
299 | QString NicName; | 305 | QString NicName; |
300 | QTextStream procTs(ProcDevNet); | 306 | QTextStream procTs(ProcDevNet); |
301 | int loc = -1; | 307 | int loc = -1; |
302 | 308 | ||
303 | procTs.readLine(); // eat a line | 309 | procTs.readLine(); // eat a line |
304 | procTs.readLine(); // eat a line | 310 | procTs.readLine(); // eat a line |
305 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { | 311 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { |
306 | if((loc = line.find(":")) == -1) { | 312 | if((loc = line.find(":")) == -1) { |
307 | continue; | 313 | continue; |
308 | } | 314 | } |
309 | 315 | ||
310 | NicName = line.left(loc); | 316 | NicName = line.left(loc); |
311 | 317 | ||
312 | // set name for ioctl | 318 | // set name for ioctl |
313 | strcpy( ifrs.ifr_name, NicName.latin1() ); | 319 | strcpy( ifrs.ifr_name, NicName.latin1() ); |
314 | 320 | ||
315 | if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) { | 321 | if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) { |
316 | // new nic | 322 | // new nic |
317 | Log(("New NIC found : %s\n", NicName.latin1())); | 323 | Log(("New NIC found : %s\n", NicName.latin1())); |
318 | IFI = new InterfaceInfo; | 324 | IFI = new InterfaceInfo; |
319 | IFI->Name = line.left(loc); | 325 | IFI->Name = line.left(loc); |
320 | IFI->Collection = 0; | 326 | IFI->Collection = 0; |
321 | ProbedInterfaces.insert( IFI->Name, IFI ); | 327 | ProbedInterfaces.insert( IFI->Name, IFI ); |
322 | 328 | ||
323 | // get dynamic info | 329 | // get dynamic info |
324 | if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { | 330 | if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { |
325 | IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT); | 331 | IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT); |
326 | } else { | 332 | } else { |
327 | IFI->IsPointToPoint = 0; | 333 | IFI->IsPointToPoint = 0; |
328 | } | 334 | } |
329 | 335 | ||
330 | // settings that never change | 336 | // settings that never change |
331 | IFI->DstAddress = ""; | 337 | IFI->DstAddress = ""; |
332 | 338 | ||
333 | if( IFI->IsPointToPoint ) { | 339 | if( IFI->IsPointToPoint ) { |
334 | if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) { | 340 | if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) { |
335 | IFI->DstAddress = | 341 | IFI->DstAddress = |
336 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr); | 342 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr); |
337 | } | 343 | } |
338 | } | 344 | } |
339 | 345 | ||
340 | IFI->CardType = 999999; | 346 | IFI->CardType = 999999; |
341 | IFI->MACAddress = ""; | 347 | IFI->MACAddress = ""; |
342 | 348 | ||
343 | if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { | 349 | if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { |
344 | Log(("Family for NIC %s : %d\n", IFI->Name.latin1(), | 350 | Log(("Family for NIC %s : %d\n", IFI->Name.latin1(), |
345 | ifrs.ifr_hwaddr.sa_family )); | 351 | ifrs.ifr_hwaddr.sa_family )); |
346 | 352 | ||
347 | IFI->CardType = ifrs.ifr_hwaddr.sa_family; | 353 | IFI->CardType = ifrs.ifr_hwaddr.sa_family; |
348 | switch( ifrs.ifr_hwaddr.sa_family ) { | 354 | switch( ifrs.ifr_hwaddr.sa_family ) { |
349 | case ARPHRD_ETHER : // regular MAC address | 355 | case ARPHRD_ETHER : // regular MAC address |
350 | // valid address -> convert to regular ::: format | 356 | // valid address -> convert to regular ::: format |
351 | // length = 6 bytes = 12 DIGITS -> 6 : | 357 | // length = 6 bytes = 12 DIGITS -> 6 : |
352 | IFI->MACAddress.sprintf( | 358 | IFI->MACAddress.sprintf( |
353 | "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", | 359 | "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", |
354 | HN( ifrs.ifr_hwaddr.sa_data[0] ), | 360 | HN( ifrs.ifr_hwaddr.sa_data[0] ), |
355 | LN( ifrs.ifr_hwaddr.sa_data[0] ), | 361 | LN( ifrs.ifr_hwaddr.sa_data[0] ), |
356 | HN( ifrs.ifr_hwaddr.sa_data[1] ), | 362 | HN( ifrs.ifr_hwaddr.sa_data[1] ), |
357 | LN( ifrs.ifr_hwaddr.sa_data[1] ), | 363 | LN( ifrs.ifr_hwaddr.sa_data[1] ), |
358 | HN( ifrs.ifr_hwaddr.sa_data[2] ), | 364 | HN( ifrs.ifr_hwaddr.sa_data[2] ), |
359 | LN( ifrs.ifr_hwaddr.sa_data[2] ), | 365 | LN( ifrs.ifr_hwaddr.sa_data[2] ), |
360 | HN( ifrs.ifr_hwaddr.sa_data[3] ), | 366 | HN( ifrs.ifr_hwaddr.sa_data[3] ), |
361 | LN( ifrs.ifr_hwaddr.sa_data[3] ), | 367 | LN( ifrs.ifr_hwaddr.sa_data[3] ), |
362 | HN( ifrs.ifr_hwaddr.sa_data[4] ), | 368 | HN( ifrs.ifr_hwaddr.sa_data[4] ), |
363 | LN( ifrs.ifr_hwaddr.sa_data[4] ), | 369 | LN( ifrs.ifr_hwaddr.sa_data[4] ), |
364 | HN( ifrs.ifr_hwaddr.sa_data[5] ), | 370 | HN( ifrs.ifr_hwaddr.sa_data[5] ), |
365 | LN( ifrs.ifr_hwaddr.sa_data[5] ) | 371 | LN( ifrs.ifr_hwaddr.sa_data[5] ) |
366 | ); | 372 | ); |
367 | break; | 373 | break; |
368 | #ifdef ARPHRD_IEEE1394 | 374 | #ifdef ARPHRD_IEEE1394 |
369 | case ARPHRD_IEEE1394 : // Firewire Eth address | 375 | case ARPHRD_IEEE1394 : // Firewire Eth address |
370 | IFI->MACAddress.sprintf( | 376 | IFI->MACAddress.sprintf( |
371 | "%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00", | 377 | "%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00", |
372 | HN( ifrs.ifr_hwaddr.sa_data[0] ), | 378 | HN( ifrs.ifr_hwaddr.sa_data[0] ), |
373 | LN( ifrs.ifr_hwaddr.sa_data[0] ), | 379 | LN( ifrs.ifr_hwaddr.sa_data[0] ), |
374 | HN( ifrs.ifr_hwaddr.sa_data[1] ), | 380 | HN( ifrs.ifr_hwaddr.sa_data[1] ), |
375 | LN( ifrs.ifr_hwaddr.sa_data[1] ), | 381 | LN( ifrs.ifr_hwaddr.sa_data[1] ), |
376 | HN( ifrs.ifr_hwaddr.sa_data[2] ), | 382 | HN( ifrs.ifr_hwaddr.sa_data[2] ), |
377 | LN( ifrs.ifr_hwaddr.sa_data[2] ), | 383 | LN( ifrs.ifr_hwaddr.sa_data[2] ), |
378 | HN( ifrs.ifr_hwaddr.sa_data[3] ), | 384 | HN( ifrs.ifr_hwaddr.sa_data[3] ), |
379 | LN( ifrs.ifr_hwaddr.sa_data[3] ), | 385 | LN( ifrs.ifr_hwaddr.sa_data[3] ), |
380 | HN( ifrs.ifr_hwaddr.sa_data[4] ), | 386 | HN( ifrs.ifr_hwaddr.sa_data[4] ), |
381 | LN( ifrs.ifr_hwaddr.sa_data[4] ), | 387 | LN( ifrs.ifr_hwaddr.sa_data[4] ), |
382 | HN( ifrs.ifr_hwaddr.sa_data[5] ), | 388 | HN( ifrs.ifr_hwaddr.sa_data[5] ), |
383 | LN( ifrs.ifr_hwaddr.sa_data[5] ), | 389 | LN( ifrs.ifr_hwaddr.sa_data[5] ), |
384 | HN( ifrs.ifr_hwaddr.sa_data[6] ), | 390 | HN( ifrs.ifr_hwaddr.sa_data[6] ), |
385 | LN( ifrs.ifr_hwaddr.sa_data[6] ), | 391 | LN( ifrs.ifr_hwaddr.sa_data[6] ), |
386 | HN( ifrs.ifr_hwaddr.sa_data[7] ), | 392 | HN( ifrs.ifr_hwaddr.sa_data[7] ), |
387 | LN( ifrs.ifr_hwaddr.sa_data[7] ), | 393 | LN( ifrs.ifr_hwaddr.sa_data[7] ), |
388 | HN( ifrs.ifr_hwaddr.sa_data[8] ), | 394 | HN( ifrs.ifr_hwaddr.sa_data[8] ), |
389 | LN( ifrs.ifr_hwaddr.sa_data[8] ), | 395 | LN( ifrs.ifr_hwaddr.sa_data[8] ), |
390 | HN( ifrs.ifr_hwaddr.sa_data[9] ), | 396 | HN( ifrs.ifr_hwaddr.sa_data[9] ), |
391 | LN( ifrs.ifr_hwaddr.sa_data[9] ), | 397 | LN( ifrs.ifr_hwaddr.sa_data[9] ), |
392 | HN( ifrs.ifr_hwaddr.sa_data[10] ), | 398 | HN( ifrs.ifr_hwaddr.sa_data[10] ), |
393 | LN( ifrs.ifr_hwaddr.sa_data[10] ), | 399 | LN( ifrs.ifr_hwaddr.sa_data[10] ), |
394 | HN( ifrs.ifr_hwaddr.sa_data[11] ), | 400 | HN( ifrs.ifr_hwaddr.sa_data[11] ), |
395 | LN( ifrs.ifr_hwaddr.sa_data[11] ), | 401 | LN( ifrs.ifr_hwaddr.sa_data[11] ), |
396 | HN( ifrs.ifr_hwaddr.sa_data[12] ), | 402 | HN( ifrs.ifr_hwaddr.sa_data[12] ), |
397 | LN( ifrs.ifr_hwaddr.sa_data[12] ), | 403 | LN( ifrs.ifr_hwaddr.sa_data[12] ), |
398 | HN( ifrs.ifr_hwaddr.sa_data[13] ), | 404 | HN( ifrs.ifr_hwaddr.sa_data[13] ), |
399 | LN( ifrs.ifr_hwaddr.sa_data[13] ) | 405 | LN( ifrs.ifr_hwaddr.sa_data[13] ) |
400 | ); | 406 | ); |
401 | break; | 407 | break; |
402 | #endif | 408 | #endif |
403 | case ARPHRD_PPP : // PPP | 409 | case ARPHRD_PPP : // PPP |
404 | break; | 410 | break; |
405 | case ARPHRD_IEEE80211 : // WLAN | 411 | case ARPHRD_IEEE80211 : // WLAN |
406 | break; | 412 | break; |
407 | case ARPHRD_IRDA : // IRDA | 413 | case ARPHRD_IRDA : // IRDA |
408 | break; | 414 | break; |
409 | } | 415 | } |
410 | } | 416 | } |
411 | } else // else already probed before -> just update | 417 | } else // else already probed before -> just update |
412 | Log(("Redetected NIC %s\n", NicName.latin1())); | 418 | Log(("Redetected NIC %s\n", NicName.latin1())); |
413 | 419 | ||
414 | // get dynamic info | 420 | // get dynamic info |
415 | if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { | 421 | if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { |
416 | IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP); | 422 | IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP); |
417 | IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST); | 423 | IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST); |
418 | } else { | 424 | } else { |
419 | IFI->IsUp = 0; | 425 | IFI->IsUp = 0; |
420 | IFI->HasMulticast = 0; | 426 | IFI->HasMulticast = 0; |
421 | } | 427 | } |
422 | 428 | ||
423 | if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) { | 429 | if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) { |
424 | IFI->Address = | 430 | IFI->Address = |
425 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr); | 431 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr); |
426 | } else { | 432 | } else { |
427 | IFI->Address = ""; | 433 | IFI->Address = ""; |
428 | IFI->IsUp = 0; | 434 | IFI->IsUp = 0; |
429 | } | 435 | } |
430 | if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) { | 436 | if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) { |
431 | IFI->BCastAddress = | 437 | IFI->BCastAddress = |
432 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr); | 438 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr); |
433 | } else { | 439 | } else { |
434 | IFI->BCastAddress = ""; | 440 | IFI->BCastAddress = ""; |
435 | } | 441 | } |
436 | if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) { | 442 | if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) { |
437 | IFI->Netmask = | 443 | IFI->Netmask = |
438 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); | 444 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); |
439 | } else { | 445 | } else { |
440 | IFI->Netmask = ""; | 446 | IFI->Netmask = ""; |
441 | } | 447 | } |
442 | Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp )); | 448 | Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp )); |
443 | } | 449 | } |
444 | 450 | ||
445 | ::close( sockfd ); | 451 | ::close( sockfd ); |
446 | } | 452 | } |
447 | 453 | ||
448 | InterfaceInfo * System::findInterface( const QString & N ) { | 454 | InterfaceInfo * System::findInterface( const QString & N ) { |
449 | InterfaceInfo * Run; | 455 | InterfaceInfo * Run; |
450 | // has PAN connection UP interface ? | 456 | // has PAN connection UP interface ? |
451 | for( QDictIterator<InterfaceInfo> It(ProbedInterfaces); | 457 | for( QDictIterator<InterfaceInfo> It(ProbedInterfaces); |
452 | It.current(); | 458 | It.current(); |
453 | ++It ) { | 459 | ++It ) { |
454 | Run = It.current(); | 460 | Run = It.current(); |
455 | if( N == Run->Name ) { | 461 | if( N == Run->Name ) { |
456 | // this PAN connection is up | 462 | // this PAN connection is up |
457 | return Run; | 463 | return Run; |
458 | } | 464 | } |
459 | } | 465 | } |
460 | return 0; | 466 | return 0; |
461 | } | 467 | } |
462 | 468 | ||
463 | #include <stdarg.h> | 469 | #include <stdarg.h> |
464 | static FILE * logf = 0; | 470 | static FILE * logf = 0; |
465 | 471 | ||
466 | void VLog( char * Format, ... ) { | 472 | void VLog( char * Format, ... ) { |
467 | va_list l; | 473 | va_list l; |
468 | 474 | ||
469 | va_start(l, Format ); | 475 | va_start(l, Format ); |
470 | 476 | ||
471 | if( logf == (FILE *)0 ) { | 477 | if( logf == (FILE *)0 ) { |
472 | QString S = getenv("NS2LOG"); | 478 | QString S = getenv("NS2LOG"); |
473 | if( S == "stderr" ) { | 479 | if( S == "stderr" ) { |
474 | logf = stderr; | 480 | logf = stderr; |
475 | } else if( S.isEmpty() ) { | 481 | } else if( S.isEmpty() ) { |
476 | logf = fopen( "/tmp/ns2log", "a" ); | 482 | logf = fopen( "/tmp/ns2log", "a" ); |
477 | } else { | 483 | } else { |
478 | logf = fopen( S, "a" ); | 484 | logf = fopen( S, "a" ); |
479 | } | 485 | } |
480 | 486 | ||
481 | if( ! logf ) { | 487 | if( ! logf ) { |
482 | fprintf( stderr, "Cannot open logfile %s : %d\n", | 488 | fprintf( stderr, "Cannot open logfile %s : %d\n", |
483 | S.latin1(), errno ); | 489 | S.latin1(), errno ); |
484 | logf = (FILE *)1; | 490 | logf = (FILE *)1; |
485 | } else { | 491 | } else { |
486 | fprintf( logf, "____ OPEN LOGFILE ____\n"); | 492 | fprintf( logf, "____ OPEN LOGFILE ____\n"); |
487 | } | 493 | } |
488 | } | 494 | } |
489 | 495 | ||
490 | if( (unsigned long)logf > 1 ) { | 496 | if( (unsigned long)logf > 1 ) { |
491 | vfprintf( logf, Format, l ); | 497 | vfprintf( logf, Format, l ); |
492 | } | 498 | } |
493 | va_end( l ); | 499 | va_end( l ); |
494 | fflush( logf ); | 500 | fflush( logf ); |
495 | 501 | ||
496 | } | 502 | } |
497 | 503 | ||
498 | void LogClose( void ) { | 504 | void LogClose( void ) { |
499 | if( (long)logf > 1 ) { | 505 | if( (long)logf > 1 ) { |
500 | fprintf( logf, "____ CLOSE LOGFILE ____\n"); | 506 | fprintf( logf, "____ CLOSE LOGFILE ____\n"); |
501 | if( logf != stderr ) { | 507 | if( logf != stderr ) { |
502 | fclose( logf ); | 508 | fclose( logf ); |
503 | } | 509 | } |
504 | logf = 0; | 510 | logf = 0; |
505 | } | 511 | } |
506 | } | 512 | } |
507 | 513 | ||
508 | QString removeSpaces( const QString & X ) { | 514 | QString removeSpaces( const QString & X ) { |
509 | QString Y; | 515 | QString Y; |
510 | Y = X.simplifyWhiteSpace(); | 516 | Y = X.simplifyWhiteSpace(); |
511 | Y.replace( QRegExp(" "), "_" ); | 517 | Y.replace( QRegExp(" "), "_" ); |
512 | odebug << X << " **" << Y << "**" << oendl; | 518 | odebug << X << " **" << Y << "**" << oendl; |
513 | return Y; | 519 | return Y; |
514 | } | 520 | } |
515 | 521 | ||
516 | // | 522 | // |
517 | // | 523 | // |
518 | // | 524 | // |
519 | // | 525 | // |
520 | // | 526 | // |
521 | 527 | ||
522 | MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() { | 528 | MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() { |
523 | P = new OProcess(); | 529 | P = new OProcess(); |
524 | connect( P, | 530 | connect( P, |
525 | SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 531 | SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
526 | this, | 532 | this, |
527 | SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) ); | 533 | SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) ); |
528 | 534 | ||
529 | connect( P, | 535 | connect( P, |
530 | SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 536 | SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
531 | this, | 537 | this, |
532 | SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) ); | 538 | SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) ); |
533 | connect( P, | 539 | connect( P, |
534 | SIGNAL( processExited(Opie::Core::OProcess*) ), | 540 | SIGNAL( processExited(Opie::Core::OProcess*) ), |
535 | this, | 541 | this, |
536 | SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) ); | 542 | SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) ); |
537 | } | 543 | } |
538 | 544 | ||
539 | MyProcess::~MyProcess() { | 545 | MyProcess::~MyProcess() { |
540 | delete P; | 546 | delete P; |
541 | } | 547 | } |
542 | 548 | ||
543 | void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) { | 549 | void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) { |
550 | if( EchoMode ) { | ||
551 | write( 1, Buf, len ); | ||
552 | return; | ||
553 | } | ||
554 | |||
544 | char * LB = (char *)alloca( len + 1 ); | 555 | char * LB = (char *)alloca( len + 1 ); |
545 | memcpy( LB, Buf, len ); | 556 | memcpy( LB, Buf, len ); |
546 | LB[len] = '\0'; | 557 | LB[len] = '\0'; |
547 | 558 | ||
548 | // now input is zero terminated | 559 | // now input is zero terminated |
549 | StdoutBuffer += LB; | 560 | StdoutBuffer += LB; |
550 | 561 | ||
551 | odebug << "Received " << len << " bytes on stdout" << oendl; | 562 | odebug << "Received " << len << " bytes on stdout" << oendl; |
552 | // see if we have some lines (allow empty lines) | 563 | // see if we have some lines (allow empty lines) |
553 | QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE ); | 564 | QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE ); |
554 | 565 | ||
555 | for( unsigned int i = 0; i < SL.count()-1; i ++ ) { | 566 | for( unsigned int i = 0; i < SL.count()-1; i ++ ) { |
556 | Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) ); | 567 | Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) ); |
557 | emit stdoutLine( SL[i] ); | 568 | emit stdoutLine( SL[i] ); |
558 | } | 569 | } |
559 | 570 | ||
560 | // last line is rest | 571 | // last line is rest |
561 | StdoutBuffer = SL[ SL.count()-1 ]; | 572 | StdoutBuffer = SL[ SL.count()-1 ]; |
562 | } | 573 | } |
563 | 574 | ||
564 | void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) { | 575 | void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) { |
576 | if( EchoMode ) { | ||
577 | write( 2, Buf, len ); | ||
578 | return; | ||
579 | } | ||
580 | |||
565 | char * LB = (char *)alloca( len + 1 ); | 581 | char * LB = (char *)alloca( len + 1 ); |
566 | memcpy( LB, Buf, len ); | 582 | memcpy( LB, Buf, len ); |
567 | LB[len] = '\0'; | 583 | LB[len] = '\0'; |
568 | 584 | ||
569 | // now input is zero terminated | 585 | // now input is zero terminated |
570 | StderrBuffer += LB; | 586 | StderrBuffer += LB; |
571 | 587 | ||
572 | odebug << "Received " << len << " bytes on stderr" << oendl; | 588 | odebug << "Received " << len << " bytes on stderr" << oendl; |
573 | // see if we have some lines (allow empty lines) | 589 | // see if we have some lines (allow empty lines) |
574 | QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE ); | 590 | QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE ); |
575 | 591 | ||
576 | for( unsigned int i = 0; i < SL.count()-1; i ++ ) { | 592 | for( unsigned int i = 0; i < SL.count()-1; i ++ ) { |
577 | Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) ); | 593 | Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) ); |
578 | emit stderrLine( SL[i] ); | 594 | emit stderrLine( SL[i] ); |
579 | } | 595 | } |
580 | 596 | ||
581 | // last line is rest | 597 | // last line is rest |
582 | StderrBuffer = SL[ SL.count()-1 ]; | 598 | StderrBuffer = SL[ SL.count()-1 ]; |
583 | } | 599 | } |
584 | 600 | ||
585 | void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) { | 601 | void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) { |
586 | emit processExited( this ); | 602 | emit processExited( this ); |
587 | } | 603 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h index f7a7274..ebee0d5 100644 --- a/noncore/settings/networksettings2/networksettings2/system.h +++ b/noncore/settings/networksettings2/networksettings2/system.h | |||
@@ -1,134 +1,140 @@ | |||
1 | #ifndef __SYSTEM__H | 1 | #ifndef __SYSTEM__H |
2 | #define __SYSTEM__H | 2 | #define __SYSTEM__H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | 5 | ||
6 | #include <opie2/oprocess.h> | 6 | #include <opie2/oprocess.h> |
7 | 7 | ||
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | // for hardware types | 10 | // for hardware types |
11 | #include <net/if_arp.h> | 11 | #include <net/if_arp.h> |
12 | #include <qdict.h> | 12 | #include <qdict.h> |
13 | #include <qobject.h> | 13 | #include <qobject.h> |
14 | #include <stdio.h> | 14 | #include <stdio.h> |
15 | 15 | ||
16 | class NodeCollection; | 16 | class NodeCollection; |
17 | class ANetNodeInstance; | 17 | class ANetNodeInstance; |
18 | class QFile; | 18 | class QFile; |
19 | 19 | ||
20 | class MyProcess : public QObject { | 20 | class MyProcess : public QObject { |
21 | 21 | ||
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | 23 | ||
24 | public : | 24 | public : |
25 | 25 | ||
26 | MyProcess(); | 26 | MyProcess(); |
27 | ~MyProcess(); | 27 | ~MyProcess(); |
28 | 28 | ||
29 | inline OProcess & process() | 29 | inline OProcess & process() |
30 | { return *P; } | 30 | { return *P; } |
31 | 31 | ||
32 | inline void setEchoMode( bool M ) { | ||
33 | EchoMode = M; | ||
34 | } | ||
35 | |||
32 | public slots : | 36 | public slots : |
33 | 37 | ||
34 | void SLOT_Stdout( Opie::Core::OProcess * P, char *, int ); | 38 | void SLOT_Stdout( Opie::Core::OProcess * P, char *, int ); |
35 | void SLOT_Stderr( Opie::Core::OProcess * P, char *, int ); | 39 | void SLOT_Stderr( Opie::Core::OProcess * P, char *, int ); |
36 | void SLOT_ProcessExited( Opie::Core::OProcess * P); | 40 | void SLOT_ProcessExited( Opie::Core::OProcess * P); |
37 | 41 | ||
38 | signals : | 42 | signals : |
39 | 43 | ||
40 | void stdoutLine( const QString & ); | 44 | void stdoutLine( const QString & ); |
41 | void stderrLine( const QString & ); | 45 | void stderrLine( const QString & ); |
42 | void processExited( MyProcess * ); | 46 | void processExited( MyProcess * ); |
43 | 47 | ||
44 | private : | 48 | private : |
45 | 49 | ||
46 | QString StdoutBuffer; | 50 | QString StdoutBuffer; |
47 | QString StderrBuffer; | 51 | QString StderrBuffer; |
48 | OProcess * P; | 52 | OProcess * P; |
53 | // output all output to my output | ||
54 | bool EchoMode; | ||
49 | }; | 55 | }; |
50 | 56 | ||
51 | class InterfaceInfo { | 57 | class InterfaceInfo { |
52 | 58 | ||
53 | public : | 59 | public : |
54 | 60 | ||
55 | InterfaceInfo() : | 61 | InterfaceInfo() : |
56 | Name(), | 62 | Name(), |
57 | MACAddress(), | 63 | MACAddress(), |
58 | BCastAddress(), | 64 | BCastAddress(), |
59 | Netmask(), | 65 | Netmask(), |
60 | DstAddress() { | 66 | DstAddress() { |
61 | } | 67 | } |
62 | 68 | ||
63 | NodeCollection * assignedConnection() | 69 | NodeCollection * assignedConnection() |
64 | { return Collection; } | 70 | { return Collection; } |
65 | 71 | ||
66 | void assignConnection( NodeCollection * NNI ) | 72 | void assignConnection( NodeCollection * NNI ) |
67 | { Collection = NNI; } | 73 | { Collection = NNI; } |
68 | 74 | ||
69 | NodeCollection * Collection; // connection taking care of me | 75 | NodeCollection * Collection; // connection taking care of me |
70 | QString Name; // name of interface | 76 | QString Name; // name of interface |
71 | int CardType; // type of card | 77 | int CardType; // type of card |
72 | QString MACAddress; // MAC address | 78 | QString MACAddress; // MAC address |
73 | QString Address; // IP Address | 79 | QString Address; // IP Address |
74 | QString BCastAddress; // Broadcast Address | 80 | QString BCastAddress; // Broadcast Address |
75 | QString Netmask; // Netmask | 81 | QString Netmask; // Netmask |
76 | QString DstAddress; // Peer address (if P-t-P) | 82 | QString DstAddress; // Peer address (if P-t-P) |
77 | bool IsUp; // interface is UP | 83 | bool IsUp; // interface is UP |
78 | bool HasMulticast; // Supports Multicast | 84 | bool HasMulticast; // Supports Multicast |
79 | bool IsPointToPoint; // IsPointToPoint card | 85 | bool IsPointToPoint; // IsPointToPoint card |
80 | 86 | ||
81 | QString RcvBytes; | 87 | QString RcvBytes; |
82 | QString SndBytes; | 88 | QString SndBytes; |
83 | QString RcvErrors; | 89 | QString RcvErrors; |
84 | QString SndErrors; | 90 | QString SndErrors; |
85 | QString RcvDropped; | 91 | QString RcvDropped; |
86 | QString SndDropped; | 92 | QString SndDropped; |
87 | QString Collisions; | 93 | QString Collisions; |
88 | }; | 94 | }; |
89 | 95 | ||
90 | class System : public QObject { | 96 | class System : public QObject { |
91 | 97 | ||
92 | Q_OBJECT | 98 | Q_OBJECT |
93 | 99 | ||
94 | public : | 100 | public : |
95 | 101 | ||
96 | System( void ); | 102 | System( void ); |
97 | ~System( void ); | 103 | ~System( void ); |
98 | 104 | ||
99 | QDict<InterfaceInfo> & interfaces( void ); | 105 | QDict<InterfaceInfo> & interfaces( void ); |
100 | InterfaceInfo * interface( const QString& N ) | 106 | InterfaceInfo * interface( const QString& N ) |
101 | { return interfaces()[N]; } | 107 | { return interfaces()[N]; } |
102 | 108 | ||
103 | // exec command as root | 109 | // exec command as root |
104 | int runAsRoot( QStringList & S, MyProcess * Prc = 0 ); | 110 | int runAsRoot( QStringList & S, MyProcess * Prc = 0 ); |
105 | 111 | ||
106 | // exec command as user | 112 | // exec command as user |
107 | int execAsUser( QStringList & Cmd ); | 113 | int execAsUser( QStringList & Cmd, bool Synchronous = 0 ); |
108 | 114 | ||
109 | // refresh stats for this interface | 115 | // refresh stats for this interface |
110 | void refreshStatistics( InterfaceInfo & ); | 116 | void refreshStatistics( InterfaceInfo & ); |
111 | 117 | ||
112 | // reloads interfaces | 118 | // reloads interfaces |
113 | void probeInterfaces( void ); | 119 | void probeInterfaces( void ); |
114 | 120 | ||
115 | InterfaceInfo * findInterface( const QString & DevName ); | 121 | InterfaceInfo * findInterface( const QString & DevName ); |
116 | 122 | ||
117 | private slots : | 123 | private slots : |
118 | 124 | ||
119 | void SLOT_ProcessExited( MyProcess * ); | 125 | void SLOT_ProcessExited( MyProcess * ); |
120 | 126 | ||
121 | signals : | 127 | signals : |
122 | 128 | ||
123 | void stdoutLine( const QString & ); | 129 | void stdoutLine( const QString & ); |
124 | void stderrLine( const QString & ); | 130 | void stderrLine( const QString & ); |
125 | void processEvent( const QString & ); | 131 | void processEvent( const QString & ); |
126 | 132 | ||
127 | private : | 133 | private : |
128 | 134 | ||
129 | QDict<InterfaceInfo> ProbedInterfaces; | 135 | QDict<InterfaceInfo> ProbedInterfaces; |
130 | FILE * OutputOfCmd; | 136 | FILE * OutputOfCmd; |
131 | QFile * ProcDevNet; | 137 | QFile * ProcDevNet; |
132 | }; | 138 | }; |
133 | 139 | ||
134 | #endif | 140 | #endif |
diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index 1b1988e..0314765 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp | |||
@@ -1,235 +1,234 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | #include <qfileinfo.h> | 3 | #include <qfileinfo.h> |
4 | #include <qmessagebox.h> | 4 | #include <qmessagebox.h> |
5 | #include <qfile.h> | 5 | #include <qfile.h> |
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | 7 | ||
8 | #include "resources.h" | 8 | #include "resources.h" |
9 | #include "systemfile.h" | 9 | #include "systemfile.h" |
10 | 10 | ||
11 | #define TEMPLATEDIR "NS2templates/" | 11 | #define TEMPLATEDIR "NS2templates/" |
12 | QString TemplDir; | 12 | QString TemplDir; |
13 | 13 | ||
14 | SystemFile::SystemFile( const QString & N, | 14 | SystemFile::SystemFile( const QString & N, |
15 | const QString & P, | 15 | const QString & P, |
16 | bool KDI ){ | 16 | bool KDI ){ |
17 | Name = N; | 17 | Name = N; |
18 | Path = P; | 18 | Path = P; |
19 | InAppend = 0; | 19 | InAppend = 0; |
20 | F = 0; | 20 | F = 0; |
21 | // get template info | 21 | // get template info |
22 | { QString S; | 22 | { QString S; |
23 | QFileInfo FI; | 23 | QFileInfo FI; |
24 | 24 | ||
25 | // find location of templates | 25 | // find location of templates |
26 | TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; | 26 | TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; |
27 | FI.setFile( TemplDir ); | 27 | FI.setFile( TemplDir ); |
28 | if( ! FI.isDir() ) { | 28 | if( ! FI.isDir() ) { |
29 | // try current dir | 29 | // try current dir |
30 | TemplDir = "./" TEMPLATEDIR; | 30 | TemplDir = "./" TEMPLATEDIR; |
31 | FI.setFile( TemplDir ); | 31 | FI.setFile( TemplDir ); |
32 | if( ! FI.isDir() ) { | 32 | if( ! FI.isDir() ) { |
33 | hasPreSection = | 33 | hasPreSection = |
34 | hasPostSection = | 34 | hasPostSection = |
35 | hasPreNodeSection = | 35 | hasPreNodeSection = |
36 | hasPostNodeSection = | 36 | hasPostNodeSection = |
37 | hasPreDeviceSection = | 37 | hasPreDeviceSection = |
38 | hasPostDeviceSection = 0; | 38 | hasPostDeviceSection = 0; |
39 | return; | 39 | return; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | // have found location | 43 | // have found location |
44 | S = TemplDir + Name + "/presection"; | 44 | S = TemplDir + Name + "/presection"; |
45 | FI.setFile( S ); | 45 | FI.setFile( S ); |
46 | hasPreSection = ( FI.exists() && FI.isReadable() ); | 46 | hasPreSection = ( FI.exists() && FI.isReadable() ); |
47 | S = TemplDir + Name + "/postsection"; | 47 | S = TemplDir + Name + "/postsection"; |
48 | FI.setFile( S ); | 48 | FI.setFile( S ); |
49 | hasPostSection = ( FI.exists() && FI.isReadable() ); | 49 | hasPostSection = ( FI.exists() && FI.isReadable() ); |
50 | S = TemplDir + Name + "/prenodesection"; | 50 | S = TemplDir + Name + "/prenodesection"; |
51 | FI.setFile( S ); | 51 | FI.setFile( S ); |
52 | hasPreNodeSection = ( FI.exists() && FI.isReadable() ); | 52 | hasPreNodeSection = ( FI.exists() && FI.isReadable() ); |
53 | S = TemplDir + Name + "/postnodesection"; | 53 | S = TemplDir + Name + "/postnodesection"; |
54 | FI.setFile( S ); | 54 | FI.setFile( S ); |
55 | hasPostNodeSection = ( FI.exists() && FI.isReadable() ); | 55 | hasPostNodeSection = ( FI.exists() && FI.isReadable() ); |
56 | S = TemplDir + Name + "/predevicesection"; | 56 | S = TemplDir + Name + "/predevicesection"; |
57 | FI.setFile( S ); | 57 | FI.setFile( S ); |
58 | hasPreDeviceSection = ( FI.exists() && FI.isReadable() ); | 58 | hasPreDeviceSection = ( FI.exists() && FI.isReadable() ); |
59 | S = TemplDir + Name + "/postdevicesection"; | 59 | S = TemplDir + Name + "/postdevicesection"; |
60 | FI.setFile( S ); | 60 | FI.setFile( S ); |
61 | hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); | 61 | hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); |
62 | } | 62 | } |
63 | 63 | ||
64 | KnowsDeviceInstances = KDI; | 64 | KnowsDeviceInstances = KDI; |
65 | } | 65 | } |
66 | 66 | ||
67 | SystemFile::SystemFile( const QString & N, bool KDI ){ | 67 | SystemFile::SystemFile( const QString & N, bool KDI ){ |
68 | Name = N; | 68 | Name = N; |
69 | Path = ""; | 69 | Path = ""; |
70 | InAppend = 0; | 70 | InAppend = 0; |
71 | F =0; | 71 | F =0; |
72 | KnowsDeviceInstances = KDI; | 72 | KnowsDeviceInstances = KDI; |
73 | hasPreSection = | 73 | hasPreSection = |
74 | hasPostSection = | 74 | hasPostSection = |
75 | hasPreNodeSection = | 75 | hasPreNodeSection = |
76 | hasPostNodeSection = | 76 | hasPostNodeSection = |
77 | hasPreDeviceSection = | 77 | hasPreDeviceSection = |
78 | hasPostDeviceSection = 0; | 78 | hasPostDeviceSection = 0; |
79 | } | 79 | } |
80 | 80 | ||
81 | SystemFile::~SystemFile( void ) { | 81 | SystemFile::~SystemFile( void ) { |
82 | close(); | 82 | close(); |
83 | } | 83 | } |
84 | 84 | ||
85 | bool SystemFile::open( void ) { | 85 | bool SystemFile::open( void ) { |
86 | QString Prefix = getenv( "NS2OUTPUTTO" ); | 86 | QString Prefix = getenv( "NS2OUTPUTTO" ); |
87 | 87 | ||
88 | if( Prefix != "stderr" /* && Name != "interfaces" */ ) { | 88 | if( Prefix != "stderr" /* && Name != "interfaces" */ ) { |
89 | // generate files where the need to be | 89 | // generate files where the need to be |
90 | if( F ) { | 90 | if( F ) { |
91 | F->close(); | 91 | F->close(); |
92 | delete F; | 92 | delete F; |
93 | } | 93 | } |
94 | 94 | ||
95 | F = new QFile( Prefix + Path + ((InAppend)?"":"bup") ); | 95 | F = new QFile( Prefix + Path + ((InAppend)?"":"bup") ); |
96 | Log(( "Open systemfile %s\n", F->name().latin1() )); | 96 | Log(( "Open systemfile %s\n", F->name().latin1() )); |
97 | if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) { | 97 | if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) { |
98 | return 0; | 98 | return 0; |
99 | } | 99 | } |
100 | } else { | 100 | } else { |
101 | if( ! F ) { | 101 | if( ! F ) { |
102 | odebug << "!!!!!!!!!!!!!!!!!! " << oendl; | 102 | odebug << "!!!!!!!!!!!!!!!!!! " << oendl; |
103 | odebug << "!!!! TESTMODE !!!!" << oendl; | 103 | odebug << "!!!! TESTMODE !!!!" << oendl; |
104 | odebug << "!!!!!!!!!!!!!!!!!! " << oendl; | 104 | odebug << "!!!!!!!!!!!!!!!!!! " << oendl; |
105 | odebug << "!!!!" << oendl; | 105 | odebug << "!!!!" << oendl; |
106 | odebug << "!!!! GENERATE " << Path << oendl; | 106 | odebug << "!!!! GENERATE " << Path << oendl; |
107 | if( InAppend ) { | 107 | if( InAppend ) { |
108 | odebug << "!!!! In APPEND mode" << oendl; | 108 | odebug << "!!!! In APPEND mode" << oendl; |
109 | } | 109 | } |
110 | odebug << "!!!!" << oendl; | 110 | odebug << "!!!!" << oendl; |
111 | odebug << "!!!!!!!!!!!!!!!!!!" << oendl; | 111 | odebug << "!!!!!!!!!!!!!!!!!!" << oendl; |
112 | 112 | ||
113 | F = new QFile(); | 113 | F = new QFile(); |
114 | F->open( IO_WriteOnly, stderr ); | 114 | F->open( IO_WriteOnly, stderr ); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | setDevice( F ); | 117 | setDevice( F ); |
118 | return 1; | 118 | return 1; |
119 | } | 119 | } |
120 | 120 | ||
121 | bool SystemFile::close( void ) { | 121 | bool SystemFile::close( void ) { |
122 | if( ! F || ! F->isOpen() ) { | 122 | if( ! F || ! F->isOpen() ) { |
123 | return 1 ; | 123 | return 1 ; |
124 | } | 124 | } |
125 | 125 | ||
126 | QString Prefix = getenv( "NS2OUTPUTTO" ); | 126 | QString Prefix = getenv( "NS2OUTPUTTO" ); |
127 | 127 | ||
128 | if( Prefix == "stderr" ) { | 128 | if( Prefix == "stderr" ) { |
129 | return 1; | 129 | return 1; |
130 | } | 130 | } |
131 | 131 | ||
132 | QString OldP = Prefix + Path + "bup"; | 132 | QString OldP = Prefix + Path + "bup"; |
133 | 133 | ||
134 | F->close(); | 134 | F->close(); |
135 | delete F; | 135 | delete F; |
136 | F = 0; | 136 | F = 0; |
137 | 137 | ||
138 | if( ! InAppend ) { | 138 | if( ! InAppend ) { |
139 | odebug << "Rename " << OldP << " to " << Path << oendl; | ||
140 | return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); | 139 | return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); |
141 | } | 140 | } |
142 | return 1; | 141 | return 1; |
143 | } | 142 | } |
144 | 143 | ||
145 | bool SystemFile::preSection( void ) { | 144 | bool SystemFile::preSection( void ) { |
146 | if( hasPreSection ) { | 145 | if( hasPreSection ) { |
147 | QFile Fl( TemplDir + Name + "/presection" ); | 146 | QFile Fl( TemplDir + Name + "/presection" ); |
148 | if( ! Fl.open( IO_ReadOnly ) ) | 147 | if( ! Fl.open( IO_ReadOnly ) ) |
149 | return 0; // error | 148 | return 0; // error |
150 | // copy file to this file | 149 | // copy file to this file |
151 | F->writeBlock( Fl.readAll() ); | 150 | F->writeBlock( Fl.readAll() ); |
152 | } | 151 | } |
153 | return 1; | 152 | return 1; |
154 | } | 153 | } |
155 | 154 | ||
156 | bool SystemFile::postSection( void ) { | 155 | bool SystemFile::postSection( void ) { |
157 | if( hasPostSection ) { | 156 | if( hasPostSection ) { |
158 | QFile Fl( TemplDir + Name + "/postsection" ); | 157 | QFile Fl( TemplDir + Name + "/postsection" ); |
159 | if( ! Fl.open( IO_ReadOnly ) ) | 158 | if( ! Fl.open( IO_ReadOnly ) ) |
160 | return 0; // error | 159 | return 0; // error |
161 | // copy file to this file | 160 | // copy file to this file |
162 | F->writeBlock( Fl.readAll() ); | 161 | F->writeBlock( Fl.readAll() ); |
163 | } | 162 | } |
164 | return 1; | 163 | return 1; |
165 | } | 164 | } |
166 | 165 | ||
167 | bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { | 166 | bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { |
168 | if( hasPreNodeSection ) { | 167 | if( hasPreNodeSection ) { |
169 | QFile Fl( TemplDir + Name + "/prenodesection" ); | 168 | QFile Fl( TemplDir + Name + "/prenodesection" ); |
170 | if( ! Fl.open( IO_ReadOnly ) ) | 169 | if( ! Fl.open( IO_ReadOnly ) ) |
171 | return 0; // error | 170 | return 0; // error |
172 | QTextStream TX( &Fl ); | 171 | QTextStream TX( &Fl ); |
173 | QString Out; | 172 | QString Out; |
174 | QString S = TX.readLine(); | 173 | QString S = TX.readLine(); |
175 | while( ! TX.eof() ) { | 174 | while( ! TX.eof() ) { |
176 | Out = S. | 175 | Out = S. |
177 | arg(NNI->nodeClass()->name()); | 176 | arg(NNI->nodeClass()->name()); |
178 | (*this) << Out << endl; | 177 | (*this) << Out << endl; |
179 | S = TX.readLine(); | 178 | S = TX.readLine(); |
180 | } | 179 | } |
181 | } | 180 | } |
182 | return 1; | 181 | return 1; |
183 | } | 182 | } |
184 | 183 | ||
185 | bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { | 184 | bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { |
186 | if( hasPostNodeSection ) { | 185 | if( hasPostNodeSection ) { |
187 | QFile Fl( TemplDir + Name + "/postnodesection" ); | 186 | QFile Fl( TemplDir + Name + "/postnodesection" ); |
188 | if( ! Fl.open( IO_ReadOnly ) ) | 187 | if( ! Fl.open( IO_ReadOnly ) ) |
189 | return 0; // error | 188 | return 0; // error |
190 | QTextStream TX( &Fl ); | 189 | QTextStream TX( &Fl ); |
191 | QString Out; | 190 | QString Out; |
192 | QString S = TX.readLine(); | 191 | QString S = TX.readLine(); |
193 | while( ! TX.eof() ) { | 192 | while( ! TX.eof() ) { |
194 | Out = S. | 193 | Out = S. |
195 | arg(NNI->name()); | 194 | arg(NNI->name()); |
196 | (*this) << Out << endl; | 195 | (*this) << Out << endl; |
197 | S = TX.readLine(); | 196 | S = TX.readLine(); |
198 | } | 197 | } |
199 | } | 198 | } |
200 | return 1; | 199 | return 1; |
201 | } | 200 | } |
202 | 201 | ||
203 | bool SystemFile::preDeviceSection( ANetNode * NN ) { | 202 | bool SystemFile::preDeviceSection( ANetNode * NN ) { |
204 | if( hasPreDeviceSection ) { | 203 | if( hasPreDeviceSection ) { |
205 | QFile Fl( TemplDir + Name + "/predevicesection" ); | 204 | QFile Fl( TemplDir + Name + "/predevicesection" ); |
206 | if( ! Fl.open( IO_ReadOnly ) ) | 205 | if( ! Fl.open( IO_ReadOnly ) ) |
207 | return 0; // error | 206 | return 0; // error |
208 | QTextStream TX( &Fl ); | 207 | QTextStream TX( &Fl ); |
209 | QString Out; | 208 | QString Out; |
210 | QString S = TX.readLine(); | 209 | QString S = TX.readLine(); |
211 | while( ! TX.eof() ) { | 210 | while( ! TX.eof() ) { |
212 | Out = S.arg(NN->name()); | 211 | Out = S.arg(NN->name()); |
213 | (*this) << Out << endl; | 212 | (*this) << Out << endl; |
214 | S = TX.readLine(); | 213 | S = TX.readLine(); |
215 | } | 214 | } |
216 | } | 215 | } |
217 | return 1; | 216 | return 1; |
218 | } | 217 | } |
219 | 218 | ||
220 | bool SystemFile::postDeviceSection( ANetNode * NN ) { | 219 | bool SystemFile::postDeviceSection( ANetNode * NN ) { |
221 | if( hasPostDeviceSection ) { | 220 | if( hasPostDeviceSection ) { |
222 | QFile Fl( TemplDir + Name + "/postdevicesection" ); | 221 | QFile Fl( TemplDir + Name + "/postdevicesection" ); |
223 | if( ! Fl.open( IO_ReadOnly ) ) | 222 | if( ! Fl.open( IO_ReadOnly ) ) |
224 | return 0; // error | 223 | return 0; // error |
225 | QTextStream TX( &Fl ); | 224 | QTextStream TX( &Fl ); |
226 | QString Out; | 225 | QString Out; |
227 | QString S = TX.readLine(); | 226 | QString S = TX.readLine(); |
228 | while( ! TX.eof() ) { | 227 | while( ! TX.eof() ) { |
229 | Out = S.arg(NN->name()); | 228 | Out = S.arg(NN->name()); |
230 | (*this) << Out << endl; | 229 | (*this) << Out << endl; |
231 | S = TX.readLine(); | 230 | S = TX.readLine(); |
232 | } | 231 | } |
233 | } | 232 | } |
234 | return 1; | 233 | return 1; |
235 | } | 234 | } |
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index d76353a..39031ed 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -1,743 +1,787 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <opie2/odebug.h> | 2 | #include <opie2/odebug.h> |
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qfileinfo.h> | 7 | #include <qfileinfo.h> |
8 | 8 | ||
9 | #include "nsdata.h" | 9 | #include "nsdata.h" |
10 | #include <netnode.h> | 10 | #include <netnode.h> |
11 | #include <resources.h> | 11 | #include <resources.h> |
12 | 12 | ||
13 | static QString CfgFile; | 13 | static QString CfgFile; |
14 | 14 | ||
15 | NetworkSettingsData::NetworkSettingsData( void ) { | 15 | NetworkSettingsData::NetworkSettingsData( void ) { |
16 | // init global resources structure | 16 | // init global resources structure |
17 | new TheNSResources(); | 17 | new TheNSResources(); |
18 | 18 | ||
19 | if( ! NSResources->userKnown() ) { | 19 | if( ! NSResources->userKnown() ) { |
20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", | 20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", |
21 | NSResources->currentUser().HomeDir.latin1(), | 21 | NSResources->currentUser().HomeDir.latin1(), |
22 | NSResources->currentUser().UserName.latin1() )); | 22 | NSResources->currentUser().UserName.latin1() )); |
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | 25 | ||
26 | CfgFile.sprintf( "%s/Settings/NS2.conf", | 26 | CfgFile.sprintf( "%s/Settings/NS2.conf", |
27 | NSResources->currentUser().HomeDir.latin1() ); | 27 | NSResources->currentUser().HomeDir.latin1() ); |
28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); | 28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); |
29 | 29 | ||
30 | // load settings | 30 | // load settings |
31 | loadSettings(); | 31 | loadSettings(); |
32 | 32 | ||
33 | // assign interfaces by scanning /tmp/profile-%s.Up files | 33 | // assign interfaces by scanning /tmp/profile-%s.Up files |
34 | { QDir D( "/tmp" ); | 34 | { QDir D( "/tmp" ); |
35 | QFile * F = new QFile; | 35 | QFile * F = new QFile; |
36 | int profilenr; | 36 | int profilenr; |
37 | QString interfacename; | 37 | QString interfacename; |
38 | QTextStream TS ( F ); | 38 | QTextStream TS ( F ); |
39 | 39 | ||
40 | QStringList SL = D.entryList( "profile-*.up"); | 40 | QStringList SL = D.entryList( "profile-*.up"); |
41 | 41 | ||
42 | Log(( "System reports %d interfaces. Found %d up\n", | 42 | Log(( "System reports %d interfaces. Found %d up\n", |
43 | NSResources->system().interfaces().count(), | 43 | NSResources->system().interfaces().count(), |
44 | SL.count() )); | 44 | SL.count() )); |
45 | 45 | ||
46 | for ( QStringList::Iterator it = SL.begin(); | 46 | for ( QStringList::Iterator it = SL.begin(); |
47 | it != SL.end(); | 47 | it != SL.end(); |
48 | ++it ) { | 48 | ++it ) { |
49 | profilenr = atol( (*it).mid( 8 ).latin1() ); | 49 | profilenr = atol( (*it).mid( 8 ).latin1() ); |
50 | // read the interface store int 'up' | 50 | // read the interface store int 'up' |
51 | F->setName( D.path() + "/" + (*it) ); | 51 | F->setName( D.path() + "/" + (*it) ); |
52 | if( F->open( IO_ReadOnly ) ) { | 52 | if( F->open( IO_ReadOnly ) ) { |
53 | NodeCollection * NC; | 53 | NodeCollection * NC; |
54 | interfacename = TS.readLine(); | 54 | interfacename = TS.readLine(); |
55 | F->close(); | 55 | F->close(); |
56 | 56 | ||
57 | Log(( "Assign interface %s to Profile nr %d\n", | 57 | Log(( "Assign interface %s to Profile nr %d\n", |
58 | interfacename.latin1(), profilenr )); | 58 | interfacename.latin1(), profilenr )); |
59 | 59 | ||
60 | NC = NSResources->getConnection( profilenr ); | 60 | NC = NSResources->getConnection( profilenr ); |
61 | if( NC ) { | 61 | if( NC ) { |
62 | NC->assignInterface( | 62 | NC->assignInterface( |
63 | NSResources->system().findInterface( interfacename ) ); | 63 | NSResources->system().findInterface( interfacename ) ); |
64 | Log(( "Assign interface %p\n", | ||
65 | NC->assignedInterface() )); | ||
64 | } else { | 66 | } else { |
65 | Log(( "Profile nr %d no longer defined\n", | 67 | Log(( "Profile nr %d no longer defined\n", |
66 | profilenr )); | 68 | profilenr )); |
67 | } | 69 | } |
68 | } | 70 | } |
69 | } | 71 | } |
70 | } | 72 | } |
71 | } | 73 | } |
72 | 74 | ||
73 | // saving is done by caller | 75 | // saving is done by caller |
74 | NetworkSettingsData::~NetworkSettingsData( void ) { | 76 | NetworkSettingsData::~NetworkSettingsData( void ) { |
75 | delete NSResources; | 77 | delete NSResources; |
76 | } | 78 | } |
77 | 79 | ||
78 | void NetworkSettingsData::loadSettings( void ) { | 80 | void NetworkSettingsData::loadSettings( void ) { |
79 | QString Line, S; | 81 | QString Line, S; |
80 | QString Attr, Value; | 82 | QString Attr, Value; |
81 | long idx; | 83 | long idx; |
82 | 84 | ||
83 | QFile F( CfgFile ); | 85 | QFile F( CfgFile ); |
84 | QTextStream TS( &F ); | 86 | QTextStream TS( &F ); |
85 | 87 | ||
86 | ForceModified = 0; | 88 | ForceModified = 0; |
87 | 89 | ||
88 | do { | 90 | do { |
89 | 91 | ||
90 | if( ! F.open(IO_ReadOnly) ) | 92 | if( ! F.open(IO_ReadOnly) ) |
91 | break; | 93 | break; |
92 | 94 | ||
93 | /* load the file -> | 95 | /* load the file -> |
94 | 96 | ||
95 | FORMAT : | 97 | FORMAT : |
96 | 98 | ||
97 | [NETNODETYPE] | 99 | [NETNODETYPE] |
98 | Entries ... | 100 | Entries ... |
99 | <EMPTYLINE> | 101 | <EMPTYLINE> |
100 | [connection] | 102 | [connection] |
101 | Name=Name | 103 | Name=Name |
102 | Node=Name | 104 | Node=Name |
103 | <EMPTYLINE> | 105 | <EMPTYLINE> |
104 | */ | 106 | */ |
105 | while( ! TS.atEnd() ) { | 107 | while( ! TS.atEnd() ) { |
106 | S = Line = TS.readLine(); | 108 | S = Line = TS.readLine(); |
107 | 109 | ||
108 | if ( S.isEmpty() || S[0] != '[' ) | 110 | if ( S.isEmpty() || S[0] != '[' ) |
109 | continue; | 111 | continue; |
110 | 112 | ||
111 | S = S.mid( 1, S.length()-2 ); | 113 | S = S.mid( 1, S.length()-2 ); |
112 | 114 | ||
113 | if( ! NSResources ) { | 115 | if( ! NSResources ) { |
114 | continue; | 116 | continue; |
115 | } | 117 | } |
116 | 118 | ||
117 | if( S == "connection" ) { | 119 | if( S == "connection" ) { |
118 | // load connections -> collections of nodes | 120 | // load connections -> collections of nodes |
119 | bool Dangling; | 121 | bool Dangling; |
120 | NodeCollection * NC = new NodeCollection( TS, Dangling ); | 122 | NodeCollection * NC = new NodeCollection( TS, Dangling ); |
121 | NSResources->addConnection( NC, Dangling ); | 123 | NSResources->addConnection( NC, Dangling ); |
122 | } else { | 124 | } else { |
123 | ANetNode * NN = 0; | 125 | ANetNode * NN = 0; |
124 | ANetNodeInstance* NNI = 0; | 126 | ANetNodeInstance* NNI = 0; |
125 | if( S.startsWith( "nodetype " ) ) { | 127 | if( S.startsWith( "nodetype " ) ) { |
126 | S = S.mid( 9, S.length()-9 ); | 128 | S = S.mid( 9, S.length()-9 ); |
127 | S = deQuote(S); | 129 | S = deQuote(S); |
128 | // try to find netnode | 130 | // try to find netnode |
129 | NN = NSResources->findNetNode( S ); | 131 | NN = NSResources->findNetNode( S ); |
130 | } else { | 132 | } else { |
131 | // try to find instance | 133 | // try to find instance |
132 | NNI = NSResources->createNodeInstance( S ); | 134 | NNI = NSResources->createNodeInstance( S ); |
133 | } | 135 | } |
134 | 136 | ||
135 | if( NN == 0 && NNI == 0 ) { | 137 | if( NN == 0 && NNI == 0 ) { |
136 | LeftOvers.append( Line ); | 138 | LeftOvers.append( Line ); |
137 | do { | 139 | do { |
138 | Line = TS.readLine(); | 140 | Line = TS.readLine(); |
139 | // store even delimiter | 141 | // store even delimiter |
140 | LeftOvers.append( Line ); | 142 | LeftOvers.append( Line ); |
141 | } while ( ! Line.isEmpty() ); | 143 | } while ( ! Line.isEmpty() ); |
142 | 144 | ||
143 | //next section | 145 | //next section |
144 | continue; | 146 | continue; |
145 | } | 147 | } |
146 | 148 | ||
147 | // read entries of this section | 149 | // read entries of this section |
148 | do { | 150 | do { |
149 | S = Line = TS.readLine(); | 151 | S = Line = TS.readLine(); |
150 | 152 | ||
151 | if( S.isEmpty() ) { | 153 | if( S.isEmpty() ) { |
152 | // empty line | 154 | // empty line |
153 | break; | 155 | break; |
154 | } | 156 | } |
155 | idx = S.find( '=' ); | 157 | idx = S.find( '=' ); |
156 | if( idx > 0 ) { | 158 | if( idx > 0 ) { |
157 | Attr = S.left( idx ); | 159 | Attr = S.left( idx ); |
158 | Value = S.mid( idx+1, S.length() ); | 160 | Value = S.mid( idx+1, S.length() ); |
159 | } else { | 161 | } else { |
160 | Value=""; | 162 | Value=""; |
161 | Attr = S; | 163 | Attr = S; |
162 | } | 164 | } |
163 | 165 | ||
164 | Value.stripWhiteSpace(); | 166 | Value.stripWhiteSpace(); |
165 | Attr.stripWhiteSpace(); | 167 | Attr.stripWhiteSpace(); |
166 | Attr.lower(); | 168 | Attr.lower(); |
167 | // dequote Attr | 169 | // dequote Attr |
168 | Value = deQuote(Value); | 170 | Value = deQuote(Value); |
169 | 171 | ||
170 | if( NN ) { | 172 | if( NN ) { |
171 | // set the attribute | 173 | // set the attribute |
172 | NN->setAttribute( Attr, Value ); | 174 | NN->setAttribute( Attr, Value ); |
173 | } else { | 175 | } else { |
174 | // set the attribute | 176 | // set the attribute |
175 | NNI->setAttribute( Attr, Value ); | 177 | NNI->setAttribute( Attr, Value ); |
176 | } | 178 | } |
177 | } while( 1 ); | 179 | } while( 1 ); |
178 | 180 | ||
179 | if( NNI ) { | 181 | if( NNI ) { |
180 | // loading from file -> exists | 182 | // loading from file -> exists |
181 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); | 183 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); |
182 | NNI->setNew( FALSE ); | 184 | NNI->setNew( FALSE ); |
183 | NSResources->addNodeInstance( NNI ); | 185 | NSResources->addNodeInstance( NNI ); |
184 | } | 186 | } |
185 | 187 | ||
186 | if( NN ) { | 188 | if( NN ) { |
187 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | 189 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); |
188 | } | 190 | } |
189 | } | 191 | } |
190 | } | 192 | } |
191 | 193 | ||
192 | } while( 0 ); | 194 | } while( 0 ); |
193 | 195 | ||
194 | } | 196 | } |
195 | 197 | ||
196 | QString NetworkSettingsData::saveSettings( void ) { | 198 | QString NetworkSettingsData::saveSettings( void ) { |
197 | QString ErrS = ""; | 199 | QString ErrS = ""; |
198 | 200 | ||
199 | if( ! isModified() ) | 201 | if( ! isModified() ) |
200 | return ErrS; | 202 | return ErrS; |
201 | 203 | ||
202 | QString S; | 204 | QString S; |
203 | QFile F( CfgFile + ".bup" ); | 205 | QFile F( CfgFile + ".bup" ); |
204 | 206 | ||
205 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); | 207 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); |
206 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | 208 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { |
207 | ErrS = qApp->translate( "NetworkSettings", | 209 | ErrS = qApp->translate( "NetworkSettings", |
208 | "<p>Could not save setup to \"%1\" !</p>" ). | 210 | "<p>Could not save setup to \"%1\" !</p>" ). |
209 | arg(CfgFile); | 211 | arg(CfgFile); |
210 | // problem | 212 | // problem |
211 | return ErrS; | 213 | return ErrS; |
212 | } | 214 | } |
213 | 215 | ||
214 | QTextStream TS( &F ); | 216 | QTextStream TS( &F ); |
215 | 217 | ||
216 | // save global configs | 218 | // save global configs |
217 | for( QDictIterator<ANetNode> it( NSResources->netNodes() ); | 219 | for( QDictIterator<ANetNode> it( NSResources->netNodes() ); |
218 | it.current(); | 220 | it.current(); |
219 | ++it ) { | 221 | ++it ) { |
220 | TS << "[nodetype " | 222 | TS << "[nodetype " |
221 | << quote( QString( it.current()->name() ) ) | 223 | << quote( QString( it.current()->name() ) ) |
222 | << "]" | 224 | << "]" |
223 | << endl; | 225 | << endl; |
224 | 226 | ||
225 | it.current()->saveAttributes( TS ); | 227 | it.current()->saveAttributes( TS ); |
226 | TS << endl; | 228 | TS << endl; |
227 | } | 229 | } |
228 | 230 | ||
229 | // save leftovers | 231 | // save leftovers |
230 | for ( QStringList::Iterator it = LeftOvers.begin(); | 232 | for ( QStringList::Iterator it = LeftOvers.begin(); |
231 | it != LeftOvers.end(); ++it ) { | 233 | it != LeftOvers.end(); ++it ) { |
232 | TS << (*it) << endl; | 234 | TS << (*it) << endl; |
233 | } | 235 | } |
234 | 236 | ||
235 | // save all netnode instances | 237 | // save all netnode instances |
236 | { ANetNodeInstance * NNI; | 238 | { ANetNodeInstance * NNI; |
237 | for( QDictIterator<ANetNodeInstance> nit( | 239 | for( QDictIterator<ANetNodeInstance> nit( |
238 | NSResources->netNodeInstances()); | 240 | NSResources->netNodeInstances()); |
239 | nit.current(); | 241 | nit.current(); |
240 | ++nit ) { | 242 | ++nit ) { |
241 | // header | 243 | // header |
242 | NNI = nit.current(); | 244 | NNI = nit.current(); |
243 | TS << '[' | 245 | TS << '[' |
244 | << QString(NNI->nodeClass()->name()) | 246 | << QString(NNI->nodeClass()->name()) |
245 | << ']' | 247 | << ']' |
246 | << endl; | 248 | << endl; |
247 | NNI->saveAttributes( TS ); | 249 | NNI->saveAttributes( TS ); |
248 | TS << endl; | 250 | TS << endl; |
249 | } | 251 | } |
250 | } | 252 | } |
251 | 253 | ||
252 | // good connections | 254 | // good connections |
253 | { Name2Connection_t & M = NSResources->connections(); | 255 | { Name2Connection_t & M = NSResources->connections(); |
254 | 256 | ||
255 | // for all connections | 257 | // for all connections |
256 | for( QDictIterator<NodeCollection> it(M); | 258 | for( QDictIterator<NodeCollection> it(M); |
257 | it.current(); | 259 | it.current(); |
258 | ++it ) { | 260 | ++it ) { |
259 | TS << "[connection]" << endl; | 261 | TS << "[connection]" << endl; |
260 | it.current()->save(TS); | 262 | it.current()->save(TS); |
261 | } | 263 | } |
262 | } | 264 | } |
263 | 265 | ||
264 | // save dangling connections | 266 | // save dangling connections |
265 | { Name2Connection_t & M = NSResources->danglingConnections(); | 267 | { Name2Connection_t & M = NSResources->danglingConnections(); |
266 | 268 | ||
267 | // for all connections | 269 | // for all connections |
268 | for( QDictIterator<NodeCollection> it(M); | 270 | for( QDictIterator<NodeCollection> it(M); |
269 | it.current(); | 271 | it.current(); |
270 | ++it ) { | 272 | ++it ) { |
271 | TS << "[connection]" << endl; | 273 | TS << "[connection]" << endl; |
272 | it.current()->save(TS); | 274 | it.current()->save(TS); |
273 | } | 275 | } |
274 | } | 276 | } |
275 | 277 | ||
276 | QDir D("."); | 278 | QDir D("."); |
277 | D.rename( CfgFile + ".bup", CfgFile ); | 279 | D.rename( CfgFile + ".bup", CfgFile ); |
278 | 280 | ||
279 | // | 281 | // |
280 | // proper files AND system files regenerated | 282 | // proper files AND system files regenerated |
281 | // | 283 | // |
282 | 284 | ||
283 | 285 | ||
284 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | 286 | for( QDictIterator<NodeCollection> it(NSResources->connections()); |
285 | it.current(); | 287 | it.current(); |
286 | ++it ) { | 288 | ++it ) { |
287 | it.current()->setModified( 0 ); | 289 | it.current()->setModified( 0 ); |
288 | } | 290 | } |
289 | 291 | ||
290 | return ErrS; | 292 | return ErrS; |
291 | } | 293 | } |
292 | 294 | ||
293 | QString NetworkSettingsData::generateSettings( void ) { | 295 | QString NetworkSettingsData::generateSettings( void ) { |
294 | QString S = ""; | 296 | QString S = ""; |
295 | Name2SystemFile_t & SFM = NSResources->systemFiles(); | 297 | Name2SystemFile_t & SFM = NSResources->systemFiles(); |
296 | Name2Connection_t & M = NSResources->connections(); | 298 | Name2Connection_t & M = NSResources->connections(); |
297 | NodeCollection * NC; | 299 | NodeCollection * NC; |
298 | ANetNodeInstance * NNI; | 300 | ANetNodeInstance * NNI; |
299 | ANetNodeInstance * FirstWithData; | 301 | ANetNodeInstance * FirstWithData; |
300 | RuntimeInfo * CurDev; | 302 | RuntimeInfo * CurDev; |
301 | ANetNode * NN, * CurDevNN = 0; | 303 | ANetNode * NN, * CurDevNN = 0; |
302 | long NoOfDevs; | 304 | long NoOfDevs; |
303 | long DevCtStart; | 305 | long DevCtStart; |
304 | bool needToGenerate; | 306 | bool needToGenerate; |
305 | 307 | ||
306 | // regenerate system files | 308 | // regenerate system files |
307 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 309 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
308 | 310 | ||
309 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); | 311 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
310 | nnit.current(); | 312 | nnit.current(); |
311 | ++nnit ) { | 313 | ++nnit ) { |
312 | bool FirstItem = 1; | 314 | bool FirstItem = 1; |
313 | bool Generated = 0; | 315 | bool Generated = 0; |
314 | 316 | ||
315 | CurDevNN = nnit.current(); | 317 | CurDevNN = nnit.current(); |
316 | 318 | ||
317 | { QStringList SL; | 319 | { QStringList SL; |
318 | SL = CurDevNN->properFiles(); | 320 | SL = CurDevNN->properFiles(); |
319 | 321 | ||
320 | for ( QStringList::Iterator it = SL.begin(); | 322 | for ( QStringList::Iterator it = SL.begin(); |
321 | it != SL.end(); | 323 | it != SL.end(); |
322 | ++it ) { | 324 | ++it ) { |
323 | 325 | ||
324 | Generated = 0; | 326 | Generated = 0; |
325 | FirstItem = 1; | 327 | FirstItem = 1; |
326 | // iterate over NNI's of this class | 328 | // iterate over NNI's of this class |
327 | for( QDictIterator<ANetNodeInstance> nniit( | 329 | for( QDictIterator<ANetNodeInstance> nniit( |
328 | NSResources->netNodeInstances() ); | 330 | NSResources->netNodeInstances() ); |
329 | nniit.current(); | 331 | nniit.current(); |
330 | ++nniit ) { | 332 | ++nniit ) { |
331 | if( nniit.current()->nodeClass() != CurDevNN ) | 333 | if( nniit.current()->nodeClass() != CurDevNN ) |
332 | // different class | 334 | // different class |
333 | continue; | 335 | continue; |
334 | 336 | ||
335 | // open proper file | 337 | // open proper file |
336 | { SystemFile SF( (*it) ); | 338 | { SystemFile SF( (*it) ); |
337 | 339 | ||
338 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { | 340 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { |
339 | // cannot open | 341 | // cannot open |
340 | S = qApp->translate( "NetworkSettings", | 342 | S = qApp->translate( "NetworkSettings", |
341 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 343 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
342 | arg( (*it) ).arg( CurDevNN->name() ); | 344 | arg( (*it) ).arg( CurDevNN->name() ); |
343 | return S; | 345 | return S; |
344 | } | 346 | } |
345 | 347 | ||
346 | if( ! SF.open() ) { | 348 | if( ! SF.open() ) { |
347 | S = qApp->translate( "NetworkSettings", | 349 | S = qApp->translate( "NetworkSettings", |
348 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 350 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
349 | arg( (*it) ).arg( CurDevNN->name() ); | 351 | arg( (*it) ).arg( CurDevNN->name() ); |
350 | return S; | 352 | return S; |
351 | } | 353 | } |
352 | 354 | ||
353 | // preamble on first | 355 | // preamble on first |
354 | if( FirstItem ) { | 356 | if( FirstItem ) { |
355 | if( CurDevNN->generatePreamble( SF ) == 2 ) { | 357 | if( CurDevNN->generatePreamble( SF ) == 2 ) { |
356 | S = qApp->translate( "NetworkSettings", | 358 | S = qApp->translate( "NetworkSettings", |
357 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). | 359 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
358 | arg( (*it) ). | 360 | arg( (*it) ). |
359 | arg( CurDevNN->name() ); | 361 | arg( CurDevNN->name() ); |
360 | return S; | 362 | return S; |
361 | } | 363 | } |
362 | } | 364 | } |
363 | FirstItem = 0; | 365 | FirstItem = 0; |
364 | Generated = 1; | 366 | Generated = 1; |
365 | 367 | ||
366 | // item specific | 368 | // item specific |
367 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { | 369 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { |
368 | S = qApp->translate( "NetworkSettings", | 370 | S = qApp->translate( "NetworkSettings", |
369 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). | 371 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). |
370 | arg( nniit.current()->name() ). | 372 | arg( nniit.current()->name() ). |
371 | arg( (*it) ). | 373 | arg( (*it) ). |
372 | arg( CurDevNN->name() ); | 374 | arg( CurDevNN->name() ); |
373 | return S; | 375 | return S; |
374 | } | 376 | } |
375 | } | 377 | } |
376 | } | 378 | } |
377 | 379 | ||
378 | if( Generated ) { | 380 | if( Generated ) { |
379 | SystemFile SF( (*it) ); | 381 | SystemFile SF( (*it) ); |
380 | 382 | ||
381 | if( CurDevNN->openFile( SF, 0 ) && | 383 | if( CurDevNN->openFile( SF, 0 ) && |
382 | ! SF.path().isEmpty() | 384 | ! SF.path().isEmpty() |
383 | ) { | 385 | ) { |
384 | 386 | ||
385 | if( ! SF.open() ) { | 387 | if( ! SF.open() ) { |
386 | S = qApp->translate( "NetworkSettings", | 388 | S = qApp->translate( "NetworkSettings", |
387 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 389 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
388 | arg( (*it) ).arg( CurDevNN->name() ); | 390 | arg( (*it) ).arg( CurDevNN->name() ); |
389 | return S; | 391 | return S; |
390 | } | 392 | } |
391 | 393 | ||
392 | if( CurDevNN->generatePostamble( SF ) == 2 ) { | 394 | if( CurDevNN->generatePostamble( SF ) == 2 ) { |
393 | S = qApp->translate( "NetworkSettings", | 395 | S = qApp->translate( "NetworkSettings", |
394 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). | 396 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
395 | arg( (*it) ). | 397 | arg( (*it) ). |
396 | arg( CurDevNN->name() ); | 398 | arg( CurDevNN->name() ); |
397 | return S; | 399 | return S; |
398 | } | 400 | } |
399 | } // no postamble | 401 | } // no postamble |
400 | } | 402 | } |
401 | } | 403 | } |
402 | } | 404 | } |
403 | } | 405 | } |
404 | 406 | ||
405 | // | 407 | // |
406 | // generate all registered files | 408 | // generate all registered files |
407 | // | 409 | // |
408 | for( QDictIterator<SystemFile> sfit(SFM); | 410 | for( QDictIterator<SystemFile> sfit(SFM); |
409 | sfit.current(); | 411 | sfit.current(); |
410 | ++sfit ) { | 412 | ++sfit ) { |
411 | SystemFile * SF; | 413 | SystemFile * SF; |
412 | 414 | ||
413 | SF = sfit.current(); | 415 | SF = sfit.current(); |
414 | 416 | ||
415 | // reset all | 417 | // reset all |
416 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); | 418 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
417 | nnit.current(); | 419 | nnit.current(); |
418 | ++nnit ) { | 420 | ++nnit ) { |
419 | nnit.current()->setDone(0); | 421 | nnit.current()->setDone(0); |
420 | } | 422 | } |
421 | 423 | ||
422 | for( QDictIterator<ANetNodeInstance> nniit( | 424 | for( QDictIterator<ANetNodeInstance> nniit( |
423 | NSResources->netNodeInstances() ); | 425 | NSResources->netNodeInstances() ); |
424 | nniit.current(); | 426 | nniit.current(); |
425 | ++nniit ) { | 427 | ++nniit ) { |
426 | nniit.current()->setDone(0); | 428 | nniit.current()->setDone(0); |
427 | } | 429 | } |
428 | 430 | ||
429 | for( QDictIterator<NodeCollection> ncit(M); | 431 | for( QDictIterator<NodeCollection> ncit(M); |
430 | ncit.current(); | 432 | ncit.current(); |
431 | ++ncit ) { | 433 | ++ncit ) { |
432 | ncit.current()->setDone(0); | 434 | ncit.current()->setDone(0); |
433 | } | 435 | } |
434 | 436 | ||
435 | Log( ( "Generating system file %s\n", SF->name().latin1() )); | 437 | Log( ( "Generating system file %s\n", SF->name().latin1() )); |
436 | 438 | ||
437 | needToGenerate = 0; | 439 | needToGenerate = 0; |
438 | 440 | ||
439 | // are there netnodes that have instances and need | 441 | // are there netnodes that have instances and need |
440 | // to write data in this system file ? | 442 | // to write data in this system file ? |
441 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); | 443 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
442 | ! needToGenerate && nnit.current(); | 444 | ! needToGenerate && nnit.current(); |
443 | ++nnit ) { | 445 | ++nnit ) { |
444 | 446 | ||
445 | NN = nnit.current(); | 447 | NN = nnit.current(); |
446 | 448 | ||
447 | if( NN->hasDataForFile( *SF ) ) { | 449 | if( NN->hasDataForFile( *SF ) ) { |
448 | // netnode can have data | 450 | // netnode can have data |
449 | 451 | ||
450 | // are there instances of this node ? | 452 | // are there instances of this node ? |
451 | for( QDictIterator<ANetNodeInstance> nniit( | 453 | for( QDictIterator<ANetNodeInstance> nniit( |
452 | NSResources->netNodeInstances() ); | 454 | NSResources->netNodeInstances() ); |
453 | ! needToGenerate && nniit.current(); | 455 | ! needToGenerate && nniit.current(); |
454 | ++nniit ) { | 456 | ++nniit ) { |
455 | if( nniit.current()->nodeClass() == NN ) { | 457 | if( nniit.current()->nodeClass() == NN ) { |
456 | // yes | 458 | // yes |
457 | Log(("Node %s has data\n", | 459 | Log(("Node %s has data\n", |
458 | nniit.current()->name() )); | 460 | nniit.current()->name() )); |
459 | needToGenerate = 1; | 461 | needToGenerate = 1; |
460 | break; | 462 | break; |
461 | } | 463 | } |
462 | } | 464 | } |
463 | } | 465 | } |
464 | } | 466 | } |
465 | 467 | ||
466 | if( ! needToGenerate ) { | 468 | if( ! needToGenerate ) { |
467 | // no instances found that might need to write data | 469 | // no instances found that might need to write data |
468 | // in this systemfile | 470 | // in this systemfile |
469 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); | 471 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); |
470 | continue; | 472 | continue; |
471 | } | 473 | } |
472 | 474 | ||
473 | // ok generate this system file | 475 | // ok generate this system file |
474 | if( ! SF->open() ) { | 476 | if( ! SF->open() ) { |
475 | S = qApp->translate( "NetworkSettings", | 477 | S = qApp->translate( "NetworkSettings", |
476 | "<p>Cannot open system file \"%1\"</p>" ). | 478 | "<p>Cannot open system file \"%1\"</p>" ). |
477 | arg( SF->name() ); | 479 | arg( SF->name() ); |
478 | return S; | 480 | return S; |
479 | } | 481 | } |
480 | 482 | ||
481 | // global presection for this system file | 483 | // global presection for this system file |
482 | if( ! SF->preSection() ) { | 484 | if( ! SF->preSection() ) { |
483 | S = qApp->translate( "NetworkSettings", | 485 | S = qApp->translate( "NetworkSettings", |
484 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). | 486 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). |
485 | arg( SF->name() ); | 487 | arg( SF->name() ); |
486 | return S; | 488 | return S; |
487 | } | 489 | } |
488 | 490 | ||
489 | // find connections that want to write to this file | 491 | // find connections that want to write to this file |
490 | for( QDictIterator<NodeCollection> ncit(M); | 492 | for( QDictIterator<NodeCollection> ncit(M); |
491 | ncit.current(); | 493 | ncit.current(); |
492 | ++ncit ) { | 494 | ++ncit ) { |
493 | 495 | ||
494 | NC = ncit.current(); | 496 | NC = ncit.current(); |
495 | 497 | ||
496 | if( NC->done() ) { | 498 | if( NC->done() ) { |
497 | // already done | 499 | // already done |
498 | continue; | 500 | continue; |
499 | } | 501 | } |
500 | 502 | ||
501 | if( ! NC->hasDataForFile( *SF ) ) { | 503 | if( ! NC->hasDataForFile( *SF ) ) { |
502 | // no data | 504 | // no data |
503 | continue; | 505 | continue; |
504 | } | 506 | } |
505 | 507 | ||
506 | Log(("Generating %s for connection %s\n", | 508 | Log(("Generating %s for connection %s\n", |
507 | SF->name().latin1(), NC->name().latin1() )); | 509 | SF->name().latin1(), NC->name().latin1() )); |
508 | // find highest item that wants to write data to this file | 510 | // find highest item that wants to write data to this file |
509 | FirstWithData = NC->firstWithDataForFile( *SF ); | 511 | FirstWithData = NC->firstWithDataForFile( *SF ); |
510 | 512 | ||
511 | // find device on which this connection works | 513 | // find device on which this connection works |
512 | CurDev = NC->device(); | 514 | CurDev = NC->device(); |
513 | // class of that node | 515 | // class of that node |
514 | CurDevNN = CurDev->netNode()->nodeClass(); | 516 | CurDevNN = CurDev->netNode()->nodeClass(); |
515 | 517 | ||
516 | if( ! FirstWithData->nodeClass()->done() ) { | 518 | if( ! FirstWithData->nodeClass()->done() ) { |
517 | // generate fixed part | 519 | // generate fixed part |
518 | if( ! SF->preDeviceSection( CurDevNN ) ) { | 520 | if( ! SF->preDeviceSection( CurDevNN ) ) { |
519 | S = qApp->translate( "NetworkSettings", | 521 | S = qApp->translate( "NetworkSettings", |
520 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). | 522 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). |
521 | arg( SF->name() ); | 523 | arg( SF->name() ); |
522 | return S; | 524 | return S; |
523 | } | 525 | } |
524 | 526 | ||
525 | if( FirstWithData->nodeClass()->generateFile( | 527 | if( FirstWithData->nodeClass()->generateFile( |
526 | *SF, | 528 | *SF, |
527 | FirstWithData, | 529 | FirstWithData, |
528 | -2 ) == 2 ) { | 530 | -2 ) == 2 ) { |
529 | S = qApp->translate( "NetworkSettings", | 531 | S = qApp->translate( "NetworkSettings", |
530 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). | 532 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). |
531 | arg( SF->name() ). | 533 | arg( SF->name() ). |
532 | arg( CurDevNN->name() ); | 534 | arg( CurDevNN->name() ); |
533 | return S; | 535 | return S; |
534 | } | 536 | } |
535 | FirstWithData->nodeClass()->setDone( 1 ); | 537 | FirstWithData->nodeClass()->setDone( 1 ); |
536 | Log(( "Systemfile %s for node instance %s is done\n", | 538 | Log(( "Systemfile %s for node instance %s is done\n", |
537 | SF->name().latin1(), | 539 | SF->name().latin1(), |
538 | FirstWithData->name() )); | 540 | FirstWithData->name() )); |
539 | } | 541 | } |
540 | 542 | ||
541 | NoOfDevs = 0; | 543 | NoOfDevs = 0; |
542 | DevCtStart = -1; | 544 | DevCtStart = -1; |
543 | 545 | ||
544 | if( SF->knowsDeviceInstances() ) { | 546 | if( SF->knowsDeviceInstances() ) { |
545 | DevCtStart = 0; | 547 | DevCtStart = 0; |
546 | NoOfDevs = CurDevNN->instanceCount(); | 548 | NoOfDevs = CurDevNN->instanceCount(); |
547 | } | 549 | } |
548 | 550 | ||
549 | if( ! CurDev->netNode()->nodeClass()->done() ) { | 551 | if( ! CurDev->netNode()->nodeClass()->done() ) { |
550 | // first time this device is handled | 552 | // first time this device is handled |
551 | // generate common device specific part | 553 | // generate common device specific part |
552 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 554 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
553 | 555 | ||
554 | if( FirstWithData->nodeClass()->generateFile( | 556 | if( FirstWithData->nodeClass()->generateFile( |
555 | *SF, CurDev->netNode(), i ) == 2 ) { | 557 | *SF, CurDev->netNode(), i ) == 2 ) { |
556 | S = qApp->translate( "NetworkSettings", | 558 | S = qApp->translate( "NetworkSettings", |
557 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). | 559 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). |
558 | arg( SF->name() ). | 560 | arg( SF->name() ). |
559 | arg( CurDevNN->name() ); | 561 | arg( CurDevNN->name() ); |
560 | return S; | 562 | return S; |
561 | } | 563 | } |
562 | } | 564 | } |
563 | CurDev->netNode()->nodeClass()->setDone( 1 ); | 565 | CurDev->netNode()->nodeClass()->setDone( 1 ); |
564 | 566 | ||
565 | Log(( "Systemfile %s for Nodeclass %s is done\n", | 567 | Log(( "Systemfile %s for Nodeclass %s is done\n", |
566 | SF->name().latin1(), | 568 | SF->name().latin1(), |
567 | CurDev->netNode()->nodeClass()->name() | 569 | CurDev->netNode()->nodeClass()->name() |
568 | )); | 570 | )); |
569 | } | 571 | } |
570 | 572 | ||
571 | // generate profile specific info | 573 | // generate profile specific info |
572 | // for all nodeconnections that work on the same device | 574 | // for all nodeconnections that work on the same device |
573 | for( QDictIterator<NodeCollection> ncit2(M); | 575 | for( QDictIterator<NodeCollection> ncit2(M); |
574 | ncit2.current(); | 576 | ncit2.current(); |
575 | ++ncit2 ) { | 577 | ++ncit2 ) { |
576 | 578 | ||
577 | if( ncit2.current()->device() != CurDev ) { | 579 | if( ncit2.current()->device() != CurDev ) { |
578 | // different device | 580 | // different device |
579 | continue; | 581 | continue; |
580 | } | 582 | } |
581 | 583 | ||
582 | Log(("Connection %s of family %s\n", | 584 | Log(("Connection %s of family %s\n", |
583 | ncit2.current()->name().latin1(), | 585 | ncit2.current()->name().latin1(), |
584 | CurDev->name() )); | 586 | CurDev->name() )); |
585 | // generate | 587 | // generate |
586 | NNI = ncit2.current()->firstWithDataForFile( *SF ); | 588 | NNI = ncit2.current()->firstWithDataForFile( *SF ); |
587 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 589 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
588 | if( ! SF->preNodeSection( NNI, i ) ) { | 590 | if( ! SF->preNodeSection( NNI, i ) ) { |
589 | S = qApp->translate( "NetworkSettings", | 591 | S = qApp->translate( "NetworkSettings", |
590 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 592 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
591 | arg( SF->name() ). | 593 | arg( SF->name() ). |
592 | arg( CurDevNN->name() ); | 594 | arg( CurDevNN->name() ); |
593 | return S; | 595 | return S; |
594 | } | 596 | } |
595 | 597 | ||
596 | switch( NNI->generateFile( *SF, i ) ) { | 598 | switch( NNI->generateFile( *SF, i ) ) { |
597 | case 0 : | 599 | case 0 : |
598 | (*SF) << endl; | 600 | (*SF) << endl; |
599 | break; | 601 | break; |
600 | case 1 : | 602 | case 1 : |
601 | break; | 603 | break; |
602 | case 2 : | 604 | case 2 : |
603 | S = qApp->translate( "NetworkSettings", | 605 | S = qApp->translate( "NetworkSettings", |
604 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). | 606 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). |
605 | arg( SF->name() ). | 607 | arg( SF->name() ). |
606 | arg( CurDevNN->name() ); | 608 | arg( CurDevNN->name() ); |
607 | return S; | 609 | return S; |
608 | } | 610 | } |
609 | 611 | ||
610 | if( ! SF->postNodeSection( NNI, i ) ) { | 612 | if( ! SF->postNodeSection( NNI, i ) ) { |
611 | S = qApp->translate( "NetworkSettings", | 613 | S = qApp->translate( "NetworkSettings", |
612 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 614 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
613 | arg( SF->name() ). | 615 | arg( SF->name() ). |
614 | arg( CurDevNN->name() ); | 616 | arg( CurDevNN->name() ); |
615 | return S; | 617 | return S; |
616 | } | 618 | } |
617 | } | 619 | } |
618 | 620 | ||
619 | ncit2.current()->setDone( 1 ); | 621 | ncit2.current()->setDone( 1 ); |
620 | 622 | ||
621 | } | 623 | } |
622 | } | 624 | } |
623 | 625 | ||
624 | if( ! SF->postDeviceSection( CurDevNN ) ) { | 626 | if( ! SF->postDeviceSection( CurDevNN ) ) { |
625 | S = qApp->translate( "NetworkSettings", | 627 | S = qApp->translate( "NetworkSettings", |
626 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). | 628 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). |
627 | arg( SF->name() ). | 629 | arg( SF->name() ). |
628 | arg( CurDevNN->name() ); | 630 | arg( CurDevNN->name() ); |
629 | return S; | 631 | return S; |
630 | } | 632 | } |
631 | 633 | ||
632 | 634 | ||
633 | if( ! SF->postSection() ) { | 635 | if( ! SF->postSection() ) { |
634 | S = qApp->translate( "NetworkSettings", | 636 | S = qApp->translate( "NetworkSettings", |
635 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). | 637 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). |
636 | arg( SF->name() ); | 638 | arg( SF->name() ); |
637 | return S; | 639 | return S; |
638 | } | 640 | } |
639 | 641 | ||
640 | // end of file | 642 | // end of file |
641 | SF->close(); | 643 | SF->close(); |
642 | } | 644 | } |
643 | return S; | 645 | return S; |
644 | } | 646 | } |
645 | 647 | ||
646 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { | 648 | QList<NodeCollection> NetworkSettingsData::collectPossible( |
649 | const QString & Interface ) { | ||
647 | // collect connections that can work on top of this interface | 650 | // collect connections that can work on top of this interface |
648 | NodeCollection * NC; | 651 | NodeCollection * NC; |
649 | QList<NodeCollection> PossibleConnections; | 652 | QList<NodeCollection> PossibleConnections; |
650 | Name2Connection_t & M = NSResources->connections(); | 653 | Name2Connection_t & M = NSResources->connections(); |
651 | 654 | ||
652 | // for all connections | 655 | // for all connections |
653 | for( QDictIterator<NodeCollection> it(M); | 656 | for( QDictIterator<NodeCollection> it(M); |
654 | it.current(); | 657 | it.current(); |
655 | ++it ) { | 658 | ++it ) { |
656 | NC = it.current(); | 659 | NC = it.current(); |
657 | // check if this profile handles the requested interface | 660 | // check if this profile handles the requested interface |
658 | if( NC->handlesInterface( Interface ) && // if different Intf. | 661 | if( NC->handlesInterface( Interface ) && // if different Intf. |
659 | NC->state() != Disabled && // if not enabled | 662 | NC->state() != Disabled && // if enabled |
660 | NC->state() != IsUp // if already used | 663 | NC->state() != IsUp // if already used |
661 | ) { | 664 | ) { |
662 | Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); | 665 | Log( ( "Append %s for %s\n", |
666 | NC->name().latin1(), Interface.latin1() )); | ||
663 | PossibleConnections.append( NC ); | 667 | PossibleConnections.append( NC ); |
664 | } | 668 | } |
665 | } | 669 | } |
666 | return PossibleConnections; | 670 | return PossibleConnections; |
667 | } | 671 | } |
668 | 672 | ||
669 | 673 | ||
670 | /* | 674 | /* |
671 | Called by the system to see if interface can be brought UP | 675 | Called by the system to see if interface can be brought UP |
672 | 676 | ||
673 | if allowed, echo Interface-allowed else Interface-disallowed | 677 | if allowed, echo Interface-allowed else Interface-disallowed |
674 | */ | 678 | */ |
675 | 679 | ||
676 | bool NetworkSettingsData::canStart( const char * Interface ) { | 680 | bool NetworkSettingsData::canStart( const QString & Interface ) { |
677 | // load situation | 681 | // load situation |
678 | NodeCollection * NC = 0; | 682 | NodeCollection * NC = 0; |
679 | QList<NodeCollection> PossibleConnections; | 683 | QList<NodeCollection> PossibleConnections; |
680 | 684 | ||
681 | PossibleConnections = collectPossible( Interface ); | 685 | PossibleConnections = collectPossible( Interface ); |
682 | 686 | ||
683 | Log( ( "for %s : Possiblilies %d\n", | 687 | Log( ( "for %s : Possiblilies %d\n", |
684 | Interface, PossibleConnections.count() )); | 688 | Interface.latin1(), PossibleConnections.count() )); |
685 | switch( PossibleConnections.count() ) { | 689 | switch( PossibleConnections.count() ) { |
686 | case 0 : // no connections | 690 | case 0 : // no connections |
687 | break; | 691 | break; |
688 | case 1 : // one connection | 692 | case 1 : // one connection |
689 | NC = PossibleConnections.first(); | 693 | NC = PossibleConnections.first(); |
690 | break; | 694 | break; |
691 | default : // need to ask user ? | 695 | default : // need to ask user ? |
692 | return 1; | 696 | return 1; |
693 | } | 697 | } |
694 | 698 | ||
695 | if( NC ) { | 699 | if( NC ) { |
696 | switch( NC->state() ) { | 700 | switch( NC->state() ) { |
697 | case Unchecked : | 701 | case Unchecked : |
698 | case Unknown : | 702 | case Unknown : |
699 | case Unavailable : | 703 | case Unavailable : |
700 | case Disabled : | 704 | case Disabled : |
701 | // this profile does not allow interface to be UP | 705 | // this profile does not allow interface to be UP |
702 | // -> try others | 706 | // -> try others |
703 | break; | 707 | break; |
704 | case Off : | 708 | case Off : |
705 | // try to UP the device | 709 | // try to UP the device |
706 | { QString S= NC->setState( Activate ); | 710 | { QString S= NC->setState( Activate ); |
707 | if( ! S.isEmpty() ) { | 711 | if( ! S.isEmpty() ) { |
708 | // could not bring device Online -> try other alters | 712 | // could not bring device Online -> try other alters |
709 | Log(( "%s-c%d-disallowed : %s\n", | 713 | Log(( "disallow %ld for %s : %s\n", |
710 | Interface, NC->number(), S.latin1() )); | 714 | NC->number(), Interface.latin1(), S.latin1() )); |
711 | break; | 715 | break; |
712 | } | 716 | } |
713 | // interface assigned | 717 | // interface assigned |
714 | } | 718 | } |
715 | // FT | 719 | // FT |
716 | case Available : | 720 | case Available : |
717 | case IsUp : // also called for 'ifdown' | 721 | case IsUp : // also called for 'ifdown' |
718 | // device is ready -> done | 722 | // device is ready -> done |
719 | Log(( "%s-c%d-allowed\n", Interface, NC->number() )); | 723 | Log(( "allow %ld for %s\n", NC->number(), Interface.latin1())); |
720 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); | 724 | printf( "A%ld%s\n", NC->number(), Interface.latin1() ); |
721 | return 0; | 725 | return 0; |
722 | } | 726 | } |
723 | } | 727 | } |
724 | 728 | ||
725 | // if we come here no alternatives are possible | 729 | // if we come here no alternatives are possible |
726 | Log(( "%s-cnn-disallowed\n", Interface )); | 730 | Log(( "disallow %s\n", Interface.latin1())); |
727 | printf( "%s-cnn-disallowed\n", Interface ); | 731 | printf( "D-%s\n", Interface.latin1() ); |
728 | return 0; | 732 | return 0; |
729 | } | 733 | } |
730 | 734 | ||
731 | bool NetworkSettingsData::isModified( void ) { | 735 | bool NetworkSettingsData::isModified( void ) { |
732 | if( ForceModified ) | 736 | if( ForceModified ) |
733 | return 1; | 737 | return 1; |
734 | 738 | ||
735 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | 739 | for( QDictIterator<NodeCollection> it(NSResources->connections()); |
736 | it.current(); | 740 | it.current(); |
737 | ++it ) { | 741 | ++it ) { |
738 | if( it.current()->isModified() ) { | 742 | if( it.current()->isModified() ) { |
739 | return 1; | 743 | return 1; |
740 | } | 744 | } |
741 | } | 745 | } |
742 | return 0; | 746 | return 0; |
743 | } | 747 | } |
748 | |||
749 | bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) { | ||
750 | // load situation | ||
751 | QList<NodeCollection> PossibleTriggered; | ||
752 | |||
753 | PossibleTriggered = collectTriggered( Interface ); | ||
754 | |||
755 | Log( ( "for %s : Possiblilies %d\n", | ||
756 | Interface.latin1(), PossibleTriggered.count() )); | ||
757 | |||
758 | return ( PossibleTriggered.count() ) ? 1 : 0; | ||
759 | } | ||
760 | |||
761 | QList<NodeCollection> NetworkSettingsData::collectTriggered( | ||
762 | const QString & Interface ) { | ||
763 | |||
764 | // collect connections that could be triggered by this interface | ||
765 | NodeCollection * NC; | ||
766 | QList<NodeCollection> PossibleTriggered; | ||
767 | |||
768 | // for all connections | ||
769 | Name2Connection_t & M = NSResources->connections(); | ||
770 | |||
771 | for( QDictIterator<NodeCollection> it(M); | ||
772 | it.current(); | ||
773 | ++it ) { | ||
774 | NC = it.current(); | ||
775 | // check if this profile handles the requested interface | ||
776 | if( NC->triggeredBy( Interface ) && // if different Intf. | ||
777 | NC->state() != Disabled && // if enabled | ||
778 | NC->state() != IsUp // if already used | ||
779 | ) { | ||
780 | Log( ( "Append %s for %s\n", | ||
781 | NC->name().latin1(), Interface.latin1() )); | ||
782 | PossibleTriggered.append( NC ); | ||
783 | } | ||
784 | } | ||
785 | return PossibleTriggered; | ||
786 | } | ||
787 | |||
diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index a0ae7d1..5791c1e 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h | |||
@@ -1,34 +1,38 @@ | |||
1 | #ifndef __NSDATA_H | 1 | #ifndef __NSDATA_H |
2 | #define __NSDATA_H | 2 | #define __NSDATA_H |
3 | 3 | ||
4 | #include <netnode.h> | 4 | #include <netnode.h> |
5 | 5 | ||
6 | class NetworkSettingsData { | 6 | class NetworkSettingsData { |
7 | 7 | ||
8 | public : | 8 | public : |
9 | 9 | ||
10 | NetworkSettingsData( void ); | 10 | NetworkSettingsData( void ); |
11 | ~NetworkSettingsData( void ); | 11 | ~NetworkSettingsData( void ); |
12 | 12 | ||
13 | void loadSettings( void ); | 13 | void loadSettings( void ); |
14 | QString saveSettings( void ); | 14 | QString saveSettings( void ); |
15 | 15 | ||
16 | QString generateSettings( void ); | 16 | QString generateSettings( void ); |
17 | 17 | ||
18 | bool isModified( void ); | 18 | bool isModified( void ); |
19 | inline void setModified( bool M ) | 19 | inline void setModified( bool M ) |
20 | { ForceModified = M; } | 20 | { ForceModified = M; } |
21 | 21 | ||
22 | QList<NodeCollection> collectPossible( const char * Interface ); | 22 | QList<NodeCollection> collectPossible( const QString & Interface ); |
23 | // return TRUE if we need gui to decide | 23 | // return TRUE if we need gui to decide |
24 | bool canStart( const char * Interface ); | 24 | bool canStart( const QString & Interface ); |
25 | // return TRUE if there are vpns that could be triggered | ||
26 | // by this interface | ||
27 | bool couldBeTriggered( const QString & Interface ); | ||
25 | 28 | ||
26 | private : | 29 | private : |
27 | 30 | ||
31 | QList<NodeCollection> collectTriggered( const QString &Interface ); | ||
28 | bool ForceModified; | 32 | bool ForceModified; |
29 | 33 | ||
30 | // collect strings in config file nobody wants | 34 | // collect strings in config file nobody wants |
31 | QStringList LeftOvers; | 35 | QStringList LeftOvers; |
32 | }; | 36 | }; |
33 | 37 | ||
34 | #endif | 38 | #endif |
diff --git a/noncore/settings/networksettings2/profile/profile_NNI.cpp b/noncore/settings/networksettings2/profile/profile_NNI.cpp index a1e1254..fc2d809 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.cpp +++ b/noncore/settings/networksettings2/profile/profile_NNI.cpp | |||
@@ -1,76 +1,81 @@ | |||
1 | #include <qpe/qpeapplication.h> | ||
1 | #include <opie2/odebug.h> | 2 | #include <opie2/odebug.h> |
2 | #include "profileedit.h" | 3 | #include "profileedit.h" |
3 | #include "profile_NNI.h" | 4 | #include "profile_NNI.h" |
4 | #include "profile_NN.h" | 5 | #include "profile_NN.h" |
5 | 6 | ||
6 | AProfile::AProfile( ProfileNetNode * PNN ) : ANetNodeInstance( PNN ) { | 7 | AProfile::AProfile( ProfileNetNode * PNN ) : ANetNodeInstance( PNN ) { |
7 | Data.Automatic = 1; | 8 | Data.Automatic = 1; |
8 | Data.Confirm = 0; | 9 | Data.Confirm = 0; |
9 | Data.Description = ""; | 10 | Data.Description = ""; |
10 | Data.Disabled = 0; | 11 | Data.Disabled = 0; |
11 | Data.TriggerVPN = 0; | 12 | Data.TriggerVPN = 0; |
12 | GUI = 0; | 13 | GUI = 0; |
13 | RT = 0; | 14 | RT = 0; |
14 | } | 15 | } |
15 | 16 | ||
16 | void AProfile::setSpecificAttribute( QString & Attr, QString & Value ) { | 17 | void AProfile::setSpecificAttribute( QString & Attr, QString & Value ) { |
17 | 18 | ||
18 | if ( Attr == "automatic" ) { | 19 | if ( Attr == "automatic" ) { |
19 | Data.Automatic = (Value=="yes"); | 20 | Data.Automatic = (Value=="yes"); |
20 | } else if ( Attr == "preconfirm" ) { | 21 | } else if ( Attr == "preconfirm" ) { |
21 | Data.Confirm = (Value=="yes"); | 22 | Data.Confirm = (Value=="yes"); |
22 | } else if ( Attr == "disabled" ) { | 23 | } else if ( Attr == "disabled" ) { |
23 | Data.Disabled = (Value=="yes"); | 24 | Data.Disabled = (Value=="yes"); |
24 | } else if ( Attr == "triggervpn" ) { | 25 | } else if ( Attr == "triggervpn" ) { |
25 | Data.TriggerVPN = (Value=="yes"); | 26 | Data.TriggerVPN = (Value=="yes"); |
26 | } else if ( Attr == "description" ) { | 27 | } else if ( Attr == "description" ) { |
27 | Data.Description = Value; | 28 | Data.Description = Value; |
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
31 | void AProfile::saveSpecificAttribute( QTextStream & TS ) { | 32 | void AProfile::saveSpecificAttribute( QTextStream & TS ) { |
32 | TS << "automatic=" << ((Data.Automatic) ? "yes" : "no") << endl; | 33 | TS << "automatic=" << ((Data.Automatic) ? "yes" : "no") << endl; |
33 | TS << "preconfirm=" << ((Data.Confirm) ? "yes" : "no") << endl; | 34 | TS << "preconfirm=" << ((Data.Confirm) ? "yes" : "no") << endl; |
34 | TS << "disabled=" << ((Data.Disabled) ? "yes" : "no") << endl; | 35 | TS << "disabled=" << ((Data.Disabled) ? "yes" : "no") << endl; |
35 | TS << "triggervpn=" << ((Data.TriggerVPN) ? "yes" : "no") << endl; | 36 | TS << "triggervpn=" << ((Data.TriggerVPN) ? "yes" : "no") << endl; |
36 | TS << "description=" << Data.Description << endl; | 37 | TS << "description=" << Data.Description << endl; |
37 | } | 38 | } |
38 | 39 | ||
39 | QWidget * AProfile::edit( QWidget * parent ) { | 40 | QWidget * AProfile::edit( QWidget * parent ) { |
40 | GUI = new ProfileEdit( parent, this ); | 41 | GUI = new ProfileEdit( parent, this ); |
41 | GUI->showData( Data ); | 42 | GUI->showData( Data ); |
42 | return GUI; | 43 | return GUI; |
43 | } | 44 | } |
44 | 45 | ||
45 | QString AProfile::acceptable( void ) { | 46 | QString AProfile::acceptable( void ) { |
46 | return ( GUI ) ? GUI->acceptable( ) : QString(); | 47 | return ( GUI ) ? GUI->acceptable( ) : QString(); |
47 | } | 48 | } |
48 | 49 | ||
49 | void AProfile::commit( void ) { | 50 | void AProfile::commit( void ) { |
50 | if( GUI && GUI->commit( Data ) ) | 51 | if( GUI && GUI->commit( Data ) ) |
51 | setModified( 1 ); | 52 | setModified( 1 ); |
52 | } | 53 | } |
53 | 54 | ||
54 | short AProfile::generateFileEmbedded( SystemFile & SF, | 55 | short AProfile::generateFileEmbedded( SystemFile & SF, |
55 | long DevNr ) { | 56 | long DevNr ) { |
56 | 57 | ||
57 | short rvl, rvd; | 58 | short rvl, rvd; |
58 | 59 | ||
59 | rvl = 1; | 60 | rvl = 1; |
60 | 61 | ||
61 | if( SF.name() == "interfaces" ) { | 62 | if( SF.name() == "interfaces" ) { |
62 | Log(("Generate Profile for %s\n", SF.name().latin1() )); | 63 | Log(("Generate Profile for %s\n", SF.name().latin1() )); |
63 | if( Data.TriggerVPN ) { | 64 | if( Data.TriggerVPN ) { |
64 | // this profile triggers VPN -> insert trigger | 65 | // this profile triggers VPN -> insert trigger |
65 | SF << " up networksettings2 --triggervpn" | 66 | SF << " up " |
67 | << QPEApplication::qpeDir() | ||
68 | << "bin/networksettings2 --triggervpn " | ||
69 | << runtime()->device()->netNode()->nodeClass()->genNic( DevNr ) | ||
70 | << " || true" | ||
66 | << endl; | 71 | << endl; |
67 | rvl = 0; | 72 | rvl = 0; |
68 | } | 73 | } |
69 | } | 74 | } |
70 | rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr ); | 75 | rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr ); |
71 | return (rvd == 2 || rvl == 2 ) ? 2 : | 76 | return (rvd == 2 || rvl == 2 ) ? 2 : |
72 | (rvd == 0 || rvl == 0 ) ? 0 : 1; | 77 | (rvd == 0 || rvl == 0 ) ? 0 : 1; |
73 | } | 78 | } |
74 | 79 | ||
75 | 80 | ||
76 | 81 | ||