author | simon <simon> | 2002-04-30 14:19:15 (UTC) |
---|---|---|
committer | simon <simon> | 2002-04-30 14:19:15 (UTC) |
commit | aa2118f85ef44f5eb22babe5cc53421d7d981a94 (patch) (unidiff) | |
tree | 9bf42c8750d0ad5efb789e5fb3e1b2c43cdea25d | |
parent | 19d341250ca5c5f21ea278ebdc7050c5400e951f (diff) | |
download | opie-aa2118f85ef44f5eb22babe5cc53421d7d981a94.zip opie-aa2118f85ef44f5eb22babe5cc53421d7d981a94.tar.gz opie-aa2118f85ef44f5eb22babe5cc53421d7d981a94.tar.bz2 |
- no default args in method impls
- don't unconditionally define _XOPEN_SOURCE (added comment about this
being wrong)
- fixed parameter shadowing problem in DesktopApplication ctor
-rw-r--r-- | core/launcher/desktop.cpp | 4 | ||||
-rw-r--r-- | core/launcher/qcopbridge.cpp | 10 | ||||
-rw-r--r-- | core/launcher/transferserver.cpp | 10 |
3 files changed, 14 insertions, 10 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index 43006f1..d5c16b3 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -11,258 +11,258 @@ | |||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "desktop.h" | 21 | #include "desktop.h" |
22 | #include "info.h" | 22 | #include "info.h" |
23 | #include "launcher.h" | 23 | #include "launcher.h" |
24 | #include "mrulist.h" | 24 | #include "mrulist.h" |
25 | #include "qcopbridge.h" | 25 | #include "qcopbridge.h" |
26 | #include "shutdownimpl.h" | 26 | #include "shutdownimpl.h" |
27 | #include "startmenu.h" | 27 | #include "startmenu.h" |
28 | #include "taskbar.h" | 28 | #include "taskbar.h" |
29 | #include "transferserver.h" | 29 | #include "transferserver.h" |
30 | #include "irserver.h" | 30 | #include "irserver.h" |
31 | #include "packageslave.h" | 31 | #include "packageslave.h" |
32 | 32 | ||
33 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/password.h> | 35 | #include <qpe/password.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/power.h> | 37 | #include <qpe/power.h> |
38 | #include <qpe/timeconversion.h> | 38 | #include <qpe/timeconversion.h> |
39 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
40 | #include <qpe/global.h> | 40 | #include <qpe/global.h> |
41 | #ifdef QT_QWS_CUSTOM | 41 | #ifdef QT_QWS_CUSTOM |
42 | #include "qpe/custom.h" | 42 | #include "qpe/custom.h" |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include <qgfx_qws.h> | 45 | #include <qgfx_qws.h> |
46 | #include <qmainwindow.h> | 46 | #include <qmainwindow.h> |
47 | #include <qmessagebox.h> | 47 | #include <qmessagebox.h> |
48 | #include <qtimer.h> | 48 | #include <qtimer.h> |
49 | #include <qwindowsystem_qws.h> | 49 | #include <qwindowsystem_qws.h> |
50 | 50 | ||
51 | #include <qvaluelist.h> | 51 | #include <qvaluelist.h> |
52 | 52 | ||
53 | #include <stdlib.h> | 53 | #include <stdlib.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | 55 | ||
56 | class QCopKeyRegister | 56 | class QCopKeyRegister |
57 | { | 57 | { |
58 | public: | 58 | public: |
59 | QCopKeyRegister() : keyCode(0) { } | 59 | QCopKeyRegister() : keyCode(0) { } |
60 | QCopKeyRegister(int k, const QString &c, const QString &m) | 60 | QCopKeyRegister(int k, const QString &c, const QString &m) |
61 | : keyCode(k), channel(c), message(m) { } | 61 | : keyCode(k), channel(c), message(m) { } |
62 | 62 | ||
63 | int getKeyCode() const { return keyCode; } | 63 | int getKeyCode() const { return keyCode; } |
64 | QString getChannel() const { return channel; } | 64 | QString getChannel() const { return channel; } |
65 | QString getMessage() const { return message; } | 65 | QString getMessage() const { return message; } |
66 | 66 | ||
67 | private: | 67 | private: |
68 | int keyCode; | 68 | int keyCode; |
69 | QString channel, message; | 69 | QString channel, message; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | typedef QValueList<QCopKeyRegister> KeyRegisterList; | 72 | typedef QValueList<QCopKeyRegister> KeyRegisterList; |
73 | KeyRegisterList keyRegisterList; | 73 | KeyRegisterList keyRegisterList; |
74 | 74 | ||
75 | static Desktop* qpedesktop = 0; | 75 | static Desktop* qpedesktop = 0; |
76 | static int loggedin=0; | 76 | static int loggedin=0; |
77 | static void login(bool at_poweron) | 77 | static void login(bool at_poweron) |
78 | { | 78 | { |
79 | if ( !loggedin ) { | 79 | if ( !loggedin ) { |
80 | Global::terminateBuiltin("calibrate"); | 80 | Global::terminateBuiltin("calibrate"); |
81 | Password::authenticate(at_poweron); | 81 | Password::authenticate(at_poweron); |
82 | loggedin=1; | 82 | loggedin=1; |
83 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 83 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | bool Desktop::screenLocked() | 87 | bool Desktop::screenLocked() |
88 | { | 88 | { |
89 | return loggedin == 0; | 89 | return loggedin == 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | /* | 92 | /* |
93 | Priority is number of alerts that are needed to pop up | 93 | Priority is number of alerts that are needed to pop up |
94 | alert. | 94 | alert. |
95 | */ | 95 | */ |
96 | class DesktopPowerAlerter : public QMessageBox | 96 | class DesktopPowerAlerter : public QMessageBox |
97 | { | 97 | { |
98 | public: | 98 | public: |
99 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 99 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
100 | : QMessageBox( tr("Battery Status"), "Low Battery", | 100 | : QMessageBox( tr("Battery Status"), "Low Battery", |
101 | QMessageBox::Critical, | 101 | QMessageBox::Critical, |
102 | QMessageBox::Ok | QMessageBox::Default, | 102 | QMessageBox::Ok | QMessageBox::Default, |
103 | QMessageBox::NoButton, QMessageBox::NoButton, | 103 | QMessageBox::NoButton, QMessageBox::NoButton, |
104 | parent, name, FALSE ) | 104 | parent, name, FALSE ) |
105 | { | 105 | { |
106 | currentPriority = INT_MAX; | 106 | currentPriority = INT_MAX; |
107 | alertCount = 0; | 107 | alertCount = 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | void alert( const QString &text, int priority ); | 110 | void alert( const QString &text, int priority ); |
111 | void hideEvent( QHideEvent * ); | 111 | void hideEvent( QHideEvent * ); |
112 | private: | 112 | private: |
113 | int currentPriority; | 113 | int currentPriority; |
114 | int alertCount; | 114 | int alertCount; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 117 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
118 | { | 118 | { |
119 | alertCount++; | 119 | alertCount++; |
120 | if ( alertCount < priority ) | 120 | if ( alertCount < priority ) |
121 | return; | 121 | return; |
122 | if ( priority > currentPriority ) | 122 | if ( priority > currentPriority ) |
123 | return; | 123 | return; |
124 | currentPriority = priority; | 124 | currentPriority = priority; |
125 | setText( text ); | 125 | setText( text ); |
126 | show(); | 126 | show(); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 130 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
131 | { | 131 | { |
132 | QMessageBox::hideEvent( e ); | 132 | QMessageBox::hideEvent( e ); |
133 | alertCount = 0; | 133 | alertCount = 0; |
134 | currentPriority = INT_MAX; | 134 | currentPriority = INT_MAX; |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | 138 | ||
139 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type t ) | 139 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) |
140 | : QPEApplication( argc, argv, t ) | 140 | : QPEApplication( argc, argv, appType ) |
141 | { | 141 | { |
142 | 142 | ||
143 | QTimer *t = new QTimer( this ); | 143 | QTimer *t = new QTimer( this ); |
144 | connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); | 144 | connect( t, SIGNAL(timeout()), this, SLOT(psTimeout()) ); |
145 | t->start( 10000 ); | 145 | t->start( 10000 ); |
146 | ps = new PowerStatus; | 146 | ps = new PowerStatus; |
147 | pa = new DesktopPowerAlerter( 0 ); | 147 | pa = new DesktopPowerAlerter( 0 ); |
148 | 148 | ||
149 | channel = new QCopChannel( "QPE/Desktop", this ); | 149 | channel = new QCopChannel( "QPE/Desktop", this ); |
150 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 150 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
151 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 151 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | DesktopApplication::~DesktopApplication() | 155 | DesktopApplication::~DesktopApplication() |
156 | { | 156 | { |
157 | delete ps; | 157 | delete ps; |
158 | delete pa; | 158 | delete pa; |
159 | } | 159 | } |
160 | 160 | ||
161 | void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) | 161 | void DesktopApplication::receive( const QCString &msg, const QByteArray &data ) |
162 | { | 162 | { |
163 | QDataStream stream( data, IO_ReadOnly ); | 163 | QDataStream stream( data, IO_ReadOnly ); |
164 | if (msg == "keyRegister(int key, QString channel, QString message)") | 164 | if (msg == "keyRegister(int key, QString channel, QString message)") |
165 | { | 165 | { |
166 | int k; | 166 | int k; |
167 | QString c, m; | 167 | QString c, m; |
168 | 168 | ||
169 | stream >> k; | 169 | stream >> k; |
170 | stream >> c; | 170 | stream >> c; |
171 | stream >> m; | 171 | stream >> m; |
172 | 172 | ||
173 | qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m); | 173 | qWarning("KeyRegisterRecieved: %i, %s, %s", k, (const char*)c, (const char *)m); |
174 | keyRegisterList.append(QCopKeyRegister(k,c,m)); | 174 | keyRegisterList.append(QCopKeyRegister(k,c,m)); |
175 | } | 175 | } |
176 | else if (msg == "suspend()"){ | 176 | else if (msg == "suspend()"){ |
177 | emit power(); | 177 | emit power(); |
178 | } | 178 | } |
179 | 179 | ||
180 | } | 180 | } |
181 | 181 | ||
182 | enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; | 182 | enum MemState { Unknown, VeryLow, Low, Normal } memstate=Unknown; |
183 | 183 | ||
184 | #ifdef Q_WS_QWS | 184 | #ifdef Q_WS_QWS |
185 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | 185 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) |
186 | { | 186 | { |
187 | qpedesktop->checkMemory(); | 187 | qpedesktop->checkMemory(); |
188 | 188 | ||
189 | if ( e->type == QWSEvent::Key ) { | 189 | if ( e->type == QWSEvent::Key ) { |
190 | QWSKeyEvent *ke = (QWSKeyEvent *)e; | 190 | QWSKeyEvent *ke = (QWSKeyEvent *)e; |
191 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) | 191 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) |
192 | return TRUE; | 192 | return TRUE; |
193 | bool press = ke->simpleData.is_press; | 193 | bool press = ke->simpleData.is_press; |
194 | 194 | ||
195 | if (!keyRegisterList.isEmpty()) | 195 | if (!keyRegisterList.isEmpty()) |
196 | { | 196 | { |
197 | KeyRegisterList::Iterator it; | 197 | KeyRegisterList::Iterator it; |
198 | for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) | 198 | for( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) |
199 | { | 199 | { |
200 | if ((*it).getKeyCode() == ke->simpleData.keycode) | 200 | if ((*it).getKeyCode() == ke->simpleData.keycode) |
201 | QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); | 201 | QCopEnvelope((*it).getChannel().utf8(), (*it).getMessage().utf8()); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | if ( !keyboardGrabbed() ) { | 205 | if ( !keyboardGrabbed() ) { |
206 | if ( ke->simpleData.keycode == Key_F9 ) { | 206 | if ( ke->simpleData.keycode == Key_F9 ) { |
207 | if ( press ) emit datebook(); | 207 | if ( press ) emit datebook(); |
208 | return TRUE; | 208 | return TRUE; |
209 | } | 209 | } |
210 | if ( ke->simpleData.keycode == Key_F10 ) { | 210 | if ( ke->simpleData.keycode == Key_F10 ) { |
211 | if ( !press && cardSendTimer ) { | 211 | if ( !press && cardSendTimer ) { |
212 | emit contacts(); | 212 | emit contacts(); |
213 | delete cardSendTimer; | 213 | delete cardSendTimer; |
214 | } else if ( press ) { | 214 | } else if ( press ) { |
215 | cardSendTimer = new QTimer(); | 215 | cardSendTimer = new QTimer(); |
216 | cardSendTimer->start( 2000, TRUE ); | 216 | cardSendTimer->start( 2000, TRUE ); |
217 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); | 217 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); |
218 | } | 218 | } |
219 | return TRUE; | 219 | return TRUE; |
220 | } | 220 | } |
221 | /* menu key now opens application menu/toolbar | 221 | /* menu key now opens application menu/toolbar |
222 | if ( ke->simpleData.keycode == Key_F11 ) { | 222 | if ( ke->simpleData.keycode == Key_F11 ) { |
223 | if ( press ) emit menu(); | 223 | if ( press ) emit menu(); |
224 | return TRUE; | 224 | return TRUE; |
225 | } | 225 | } |
226 | */ | 226 | */ |
227 | if ( ke->simpleData.keycode == Key_F12 ) { | 227 | if ( ke->simpleData.keycode == Key_F12 ) { |
228 | while( activePopupWidget() ) | 228 | while( activePopupWidget() ) |
229 | activePopupWidget()->close(); | 229 | activePopupWidget()->close(); |
230 | if ( press ) emit launch(); | 230 | if ( press ) emit launch(); |
231 | return TRUE; | 231 | return TRUE; |
232 | } | 232 | } |
233 | if ( ke->simpleData.keycode == Key_F13 ) { | 233 | if ( ke->simpleData.keycode == Key_F13 ) { |
234 | if ( press ) emit email(); | 234 | if ( press ) emit email(); |
235 | return TRUE; | 235 | return TRUE; |
236 | } | 236 | } |
237 | } | 237 | } |
238 | 238 | ||
239 | if ( ke->simpleData.keycode == Key_F34 ) { | 239 | if ( ke->simpleData.keycode == Key_F34 ) { |
240 | if ( press ) emit power(); | 240 | if ( press ) emit power(); |
241 | return TRUE; | 241 | return TRUE; |
242 | } | 242 | } |
243 | if ( ke->simpleData.keycode == Key_SysReq ) { | 243 | if ( ke->simpleData.keycode == Key_SysReq ) { |
244 | if ( press ) emit power(); | 244 | if ( press ) emit power(); |
245 | return TRUE; | 245 | return TRUE; |
246 | } | 246 | } |
247 | if ( ke->simpleData.keycode == Key_F35 ) { | 247 | if ( ke->simpleData.keycode == Key_F35 ) { |
248 | if ( press ) emit backlight(); | 248 | if ( press ) emit backlight(); |
249 | return TRUE; | 249 | return TRUE; |
250 | } | 250 | } |
251 | if ( ke->simpleData.keycode == Key_F32 ) { | 251 | if ( ke->simpleData.keycode == Key_F32 ) { |
252 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 252 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
253 | return TRUE; | 253 | return TRUE; |
254 | } | 254 | } |
255 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { | 255 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { |
256 | if ( press ) emit symbol(); | 256 | if ( press ) emit symbol(); |
257 | return TRUE; | 257 | return TRUE; |
258 | } | 258 | } |
259 | if ( ke->simpleData.keycode == Key_NumLock ) { | 259 | if ( ke->simpleData.keycode == Key_NumLock ) { |
260 | if ( press ) emit numLockStateToggle(); | 260 | if ( press ) emit numLockStateToggle(); |
261 | } | 261 | } |
262 | if ( ke->simpleData.keycode == Key_CapsLock ) { | 262 | if ( ke->simpleData.keycode == Key_CapsLock ) { |
263 | if ( press ) emit capsLockStateToggle(); | 263 | if ( press ) emit capsLockStateToggle(); |
264 | } | 264 | } |
265 | if ( press ) | 265 | if ( press ) |
266 | qpedesktop->keyClick(); | 266 | qpedesktop->keyClick(); |
267 | } else { | 267 | } else { |
268 | if ( e->type == QWSEvent::Mouse ) { | 268 | if ( e->type == QWSEvent::Mouse ) { |
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp index c8af919..2d084fc 100644 --- a/core/launcher/qcopbridge.cpp +++ b/core/launcher/qcopbridge.cpp | |||
@@ -1,300 +1,304 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "qcopbridge.h" | 21 | #include "qcopbridge.h" |
22 | #include "transferserver.h" | 22 | #include "transferserver.h" |
23 | 23 | ||
24 | #include <qpe/qcopenvelope_qws.h> | 24 | #include <qpe/qcopenvelope_qws.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | 26 | ||
27 | #include <qdir.h> | 27 | #include <qdir.h> |
28 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qtextstream.h> | 29 | #include <qtextstream.h> |
30 | #include <qdatastream.h> | 30 | #include <qdatastream.h> |
31 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qfileinfo.h> | 32 | #include <qfileinfo.h> |
33 | #include <qregexp.h> | 33 | #include <qregexp.h> |
34 | #include <qcopchannel_qws.h> | 34 | #include <qcopchannel_qws.h> |
35 | 35 | ||
36 | // actually this is wrong, _XOPEN_SOURCE should get defined on the commandline | ||
37 | // and it should have a proper value assigned. (Simon) | ||
38 | #if !defined(_XOPEN_SOURCE) | ||
36 | #define _XOPEN_SOURCE | 39 | #define _XOPEN_SOURCE |
40 | #endif | ||
37 | #include <pwd.h> | 41 | #include <pwd.h> |
38 | #include <sys/types.h> | 42 | #include <sys/types.h> |
39 | #include <unistd.h> | 43 | #include <unistd.h> |
40 | 44 | ||
41 | #if defined(_OS_LINUX_) | 45 | #if defined(_OS_LINUX_) |
42 | #include <shadow.h> | 46 | #include <shadow.h> |
43 | #endif | 47 | #endif |
44 | 48 | ||
45 | //#define INSECURE | 49 | //#define INSECURE |
46 | 50 | ||
47 | const int block_size = 51200; | 51 | const int block_size = 51200; |
48 | 52 | ||
49 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent = 0, | 53 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, |
50 | const char* name = 0) | 54 | const char* name ) |
51 | : QServerSocket( port, 1, parent, name ), | 55 | : QServerSocket( port, 1, parent, name ), |
52 | desktopChannel( 0 ), | 56 | desktopChannel( 0 ), |
53 | cardChannel( 0 ) | 57 | cardChannel( 0 ) |
54 | { | 58 | { |
55 | if ( !ok() ) | 59 | if ( !ok() ) |
56 | qWarning( "Failed to bind to port %d", port ); | 60 | qWarning( "Failed to bind to port %d", port ); |
57 | else { | 61 | else { |
58 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); | 62 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); |
59 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 63 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
60 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 64 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); |
61 | cardChannel = new QCopChannel( "QPE/Card", this ); | 65 | cardChannel = new QCopChannel( "QPE/Card", this ); |
62 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 66 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
63 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 67 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); |
64 | } | 68 | } |
65 | sendSync = FALSE; | 69 | sendSync = FALSE; |
66 | } | 70 | } |
67 | 71 | ||
68 | QCopBridge::~QCopBridge() | 72 | QCopBridge::~QCopBridge() |
69 | { | 73 | { |
70 | delete desktopChannel; | 74 | delete desktopChannel; |
71 | } | 75 | } |
72 | 76 | ||
73 | void QCopBridge::newConnection( int socket ) | 77 | void QCopBridge::newConnection( int socket ) |
74 | { | 78 | { |
75 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); | 79 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); |
76 | openConnections.append( pi ); | 80 | openConnections.append( pi ); |
77 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); | 81 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); |
78 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; | 82 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; |
79 | 83 | ||
80 | if ( sendSync ) { | 84 | if ( sendSync ) { |
81 | pi ->startSync(); | 85 | pi ->startSync(); |
82 | sendSync = FALSE; | 86 | sendSync = FALSE; |
83 | } | 87 | } |
84 | } | 88 | } |
85 | 89 | ||
86 | void QCopBridge::connectionClosed( QCopBridgePI *pi ) | 90 | void QCopBridge::connectionClosed( QCopBridgePI *pi ) |
87 | { | 91 | { |
88 | openConnections.remove( pi ); | 92 | openConnections.remove( pi ); |
89 | if ( openConnections.count() == 0 ) { | 93 | if ( openConnections.count() == 0 ) { |
90 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 94 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
91 | } | 95 | } |
92 | } | 96 | } |
93 | 97 | ||
94 | void QCopBridge::closeOpenConnections() | 98 | void QCopBridge::closeOpenConnections() |
95 | { | 99 | { |
96 | QCopBridgePI *pi; | 100 | QCopBridgePI *pi; |
97 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) | 101 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
98 | pi->close(); | 102 | pi->close(); |
99 | } | 103 | } |
100 | 104 | ||
101 | 105 | ||
102 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) | 106 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) |
103 | { | 107 | { |
104 | command.stripWhiteSpace(); | 108 | command.stripWhiteSpace(); |
105 | 109 | ||
106 | int paren = command.find( "(" ); | 110 | int paren = command.find( "(" ); |
107 | if ( paren <= 0 ) { | 111 | if ( paren <= 0 ) { |
108 | qDebug("DesktopMessage: bad qcop syntax"); | 112 | qDebug("DesktopMessage: bad qcop syntax"); |
109 | return; | 113 | return; |
110 | } | 114 | } |
111 | 115 | ||
112 | QString params = command.mid( paren + 1 ); | 116 | QString params = command.mid( paren + 1 ); |
113 | if ( params[params.length()-1] != ')' ) { | 117 | if ( params[params.length()-1] != ')' ) { |
114 | qDebug("DesktopMessage: bad qcop syntax"); | 118 | qDebug("DesktopMessage: bad qcop syntax"); |
115 | return; | 119 | return; |
116 | } | 120 | } |
117 | 121 | ||
118 | params.truncate( params.length()-1 ); | 122 | params.truncate( params.length()-1 ); |
119 | 123 | ||
120 | QStringList paramList = QStringList::split( ",", params ); | 124 | QStringList paramList = QStringList::split( ",", params ); |
121 | QString data; | 125 | QString data; |
122 | if ( paramList.count() ) { | 126 | if ( paramList.count() ) { |
123 | QDataStream stream( args, IO_ReadOnly ); | 127 | QDataStream stream( args, IO_ReadOnly ); |
124 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { | 128 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { |
125 | QString str; | 129 | QString str; |
126 | if ( *it == "QString" ) { | 130 | if ( *it == "QString" ) { |
127 | stream >> str; | 131 | stream >> str; |
128 | } else if ( *it == "QCString" ) { | 132 | } else if ( *it == "QCString" ) { |
129 | QCString cstr; | 133 | QCString cstr; |
130 | stream >> cstr; | 134 | stream >> cstr; |
131 | str = QString::fromLocal8Bit( cstr ); | 135 | str = QString::fromLocal8Bit( cstr ); |
132 | } else if ( *it == "int" ) { | 136 | } else if ( *it == "int" ) { |
133 | int i; | 137 | int i; |
134 | stream >> i; | 138 | stream >> i; |
135 | str = QString::number( i ); | 139 | str = QString::number( i ); |
136 | } else if ( *it == "bool" ) { | 140 | } else if ( *it == "bool" ) { |
137 | int i; | 141 | int i; |
138 | stream >> i; | 142 | stream >> i; |
139 | str = QString::number( i ); | 143 | str = QString::number( i ); |
140 | } else { | 144 | } else { |
141 | qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() ); | 145 | qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() ); |
142 | return; | 146 | return; |
143 | } | 147 | } |
144 | str.replace( QRegExp("&"), "&" ); | 148 | str.replace( QRegExp("&"), "&" ); |
145 | str.replace( QRegExp(" "), "&0x20;" ); | 149 | str.replace( QRegExp(" "), "&0x20;" ); |
146 | str.replace( QRegExp("\n"), "&0x0d;" ); | 150 | str.replace( QRegExp("\n"), "&0x0d;" ); |
147 | str.replace( QRegExp("\r"), "&0x0a;" ); | 151 | str.replace( QRegExp("\r"), "&0x0a;" ); |
148 | data += " " + str; | 152 | data += " " + str; |
149 | } | 153 | } |
150 | } | 154 | } |
151 | QString sendCommand = QString(command.data()) + data; | 155 | QString sendCommand = QString(command.data()) + data; |
152 | // send the command to all open connections | 156 | // send the command to all open connections |
153 | if ( command == "startSync()" ) { | 157 | if ( command == "startSync()" ) { |
154 | // we need to buffer it a bit | 158 | // we need to buffer it a bit |
155 | sendSync = TRUE; | 159 | sendSync = TRUE; |
156 | startTimer( 20000 ); | 160 | startTimer( 20000 ); |
157 | } | 161 | } |
158 | 162 | ||
159 | QCopBridgePI *pi; | 163 | QCopBridgePI *pi; |
160 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { | 164 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { |
161 | pi->sendDesktopMessage( sendCommand ); | 165 | pi->sendDesktopMessage( sendCommand ); |
162 | } | 166 | } |
163 | } | 167 | } |
164 | 168 | ||
165 | void QCopBridge::timerEvent( QTimerEvent * ) | 169 | void QCopBridge::timerEvent( QTimerEvent * ) |
166 | { | 170 | { |
167 | sendSync = FALSE; | 171 | sendSync = FALSE; |
168 | killTimers(); | 172 | killTimers(); |
169 | } | 173 | } |
170 | 174 | ||
171 | 175 | ||
172 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ) | 176 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) |
173 | : QSocket( parent, name ) | 177 | : QSocket( parent, name ) |
174 | { | 178 | { |
175 | setSocket( socket ); | 179 | setSocket( socket ); |
176 | 180 | ||
177 | peerport = peerPort(); | 181 | peerport = peerPort(); |
178 | peeraddress = peerAddress(); | 182 | peeraddress = peerAddress(); |
179 | 183 | ||
180 | #ifndef INSECURE | 184 | #ifndef INSECURE |
181 | if ( !accessAuthorized(peeraddress) ) { | 185 | if ( !accessAuthorized(peeraddress) ) { |
182 | state = Forbidden; | 186 | state = Forbidden; |
183 | startTimer( 0 ); | 187 | startTimer( 0 ); |
184 | } else | 188 | } else |
185 | #endif | 189 | #endif |
186 | { | 190 | { |
187 | state = Connected; | 191 | state = Connected; |
188 | sendSync = FALSE; | 192 | sendSync = FALSE; |
189 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 193 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
190 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 194 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
191 | 195 | ||
192 | send( "220 Qtopia QCop bridge ready!" ); | 196 | send( "220 Qtopia QCop bridge ready!" ); |
193 | state = Wait_USER; | 197 | state = Wait_USER; |
194 | 198 | ||
195 | // idle timer to close connections when not used anymore | 199 | // idle timer to close connections when not used anymore |
196 | startTimer( 60000 ); | 200 | startTimer( 60000 ); |
197 | connected = TRUE; | 201 | connected = TRUE; |
198 | } | 202 | } |
199 | } | 203 | } |
200 | 204 | ||
201 | 205 | ||
202 | QCopBridgePI::~QCopBridgePI() | 206 | QCopBridgePI::~QCopBridgePI() |
203 | { | 207 | { |
204 | 208 | ||
205 | } | 209 | } |
206 | 210 | ||
207 | void QCopBridgePI::connectionClosed() | 211 | void QCopBridgePI::connectionClosed() |
208 | { | 212 | { |
209 | emit connectionClosed( this ); | 213 | emit connectionClosed( this ); |
210 | // qDebug( "Debug: Connection closed" ); | 214 | // qDebug( "Debug: Connection closed" ); |
211 | delete this; | 215 | delete this; |
212 | } | 216 | } |
213 | 217 | ||
214 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) | 218 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) |
215 | { | 219 | { |
216 | QString str = "CALL QPE/Desktop " + msg; | 220 | QString str = "CALL QPE/Desktop " + msg; |
217 | send ( str ); | 221 | send ( str ); |
218 | } | 222 | } |
219 | 223 | ||
220 | 224 | ||
221 | void QCopBridgePI::send( const QString& msg ) | 225 | void QCopBridgePI::send( const QString& msg ) |
222 | { | 226 | { |
223 | QTextStream os( this ); | 227 | QTextStream os( this ); |
224 | os << msg << endl; | 228 | os << msg << endl; |
225 | //qDebug( "sending qcop message: %s", msg.latin1() ); | 229 | //qDebug( "sending qcop message: %s", msg.latin1() ); |
226 | } | 230 | } |
227 | 231 | ||
228 | void QCopBridgePI::read() | 232 | void QCopBridgePI::read() |
229 | { | 233 | { |
230 | while ( canReadLine() ) | 234 | while ( canReadLine() ) |
231 | process( readLine().stripWhiteSpace() ); | 235 | process( readLine().stripWhiteSpace() ); |
232 | } | 236 | } |
233 | 237 | ||
234 | bool QCopBridgePI::checkUser( const QString& user ) | 238 | bool QCopBridgePI::checkUser( const QString& user ) |
235 | { | 239 | { |
236 | if ( user.isEmpty() ) return FALSE; | 240 | if ( user.isEmpty() ) return FALSE; |
237 | 241 | ||
238 | struct passwd *pw; | 242 | struct passwd *pw; |
239 | pw = getpwuid( geteuid() ); | 243 | pw = getpwuid( geteuid() ); |
240 | QString euser = QString::fromLocal8Bit( pw->pw_name ); | 244 | QString euser = QString::fromLocal8Bit( pw->pw_name ); |
241 | return user == euser; | 245 | return user == euser; |
242 | } | 246 | } |
243 | 247 | ||
244 | bool QCopBridgePI::checkPassword( const QString& password ) | 248 | bool QCopBridgePI::checkPassword( const QString& password ) |
245 | { | 249 | { |
246 | // ### HACK for testing on local host | 250 | // ### HACK for testing on local host |
247 | return true; | 251 | return true; |
248 | 252 | ||
249 | /* | 253 | /* |
250 | struct passwd *pw = 0; | 254 | struct passwd *pw = 0; |
251 | struct spwd *spw = 0; | 255 | struct spwd *spw = 0; |
252 | 256 | ||
253 | pw = getpwuid( geteuid() ); | 257 | pw = getpwuid( geteuid() ); |
254 | spw = getspnam( pw->pw_name ); | 258 | spw = getspnam( pw->pw_name ); |
255 | 259 | ||
256 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 260 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
257 | if ( cpwd == "x" && spw ) | 261 | if ( cpwd == "x" && spw ) |
258 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 262 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
259 | 263 | ||
260 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 264 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
261 | return cpwd == cpassword; | 265 | return cpwd == cpassword; |
262 | */ | 266 | */ |
263 | } | 267 | } |
264 | 268 | ||
265 | void QCopBridgePI::process( const QString& message ) | 269 | void QCopBridgePI::process( const QString& message ) |
266 | { | 270 | { |
267 | //qDebug( "Command: %s", message.latin1() ); | 271 | //qDebug( "Command: %s", message.latin1() ); |
268 | 272 | ||
269 | // split message using "," as separator | 273 | // split message using "," as separator |
270 | QStringList msg = QStringList::split( " ", message ); | 274 | QStringList msg = QStringList::split( " ", message ); |
271 | if ( msg.isEmpty() ) return; | 275 | if ( msg.isEmpty() ) return; |
272 | 276 | ||
273 | // command token | 277 | // command token |
274 | QString cmd = msg[0].upper(); | 278 | QString cmd = msg[0].upper(); |
275 | 279 | ||
276 | // argument token | 280 | // argument token |
277 | QString arg; | 281 | QString arg; |
278 | if ( msg.count() >= 2 ) | 282 | if ( msg.count() >= 2 ) |
279 | arg = msg[1]; | 283 | arg = msg[1]; |
280 | 284 | ||
281 | // we always respond to QUIT, regardless of state | 285 | // we always respond to QUIT, regardless of state |
282 | if ( cmd == "QUIT" ) { | 286 | if ( cmd == "QUIT" ) { |
283 | send( "211 Have a nice day!" ); | 287 | send( "211 Have a nice day!" ); |
284 | delete this; | 288 | delete this; |
285 | return; | 289 | return; |
286 | } | 290 | } |
287 | 291 | ||
288 | // connected to client | 292 | // connected to client |
289 | if ( Connected == state ) | 293 | if ( Connected == state ) |
290 | return; | 294 | return; |
291 | 295 | ||
292 | // waiting for user name | 296 | // waiting for user name |
293 | if ( Wait_USER == state ) { | 297 | if ( Wait_USER == state ) { |
294 | 298 | ||
295 | if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) { | 299 | if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) { |
296 | send( "530 Please login with USER and PASS" ); | 300 | send( "530 Please login with USER and PASS" ); |
297 | return; | 301 | return; |
298 | } | 302 | } |
299 | send( "331 User name ok, need password" ); | 303 | send( "331 User name ok, need password" ); |
300 | state = Wait_PASS; | 304 | state = Wait_PASS; |
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index 87a49eb..7294f9c 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -1,212 +1,212 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define _XOPEN_SOURCE | 20 | #define _XOPEN_SOURCE |
21 | #include <pwd.h> | 21 | #include <pwd.h> |
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | 25 | ||
26 | #if defined(_OS_LINUX_) | 26 | #if defined(_OS_LINUX_) |
27 | #include <shadow.h> | 27 | #include <shadow.h> |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qdatastream.h> | 33 | #include <qdatastream.h> |
34 | #include <qmessagebox.h> | 34 | #include <qmessagebox.h> |
35 | #include <qstringlist.h> | 35 | #include <qstringlist.h> |
36 | #include <qfileinfo.h> | 36 | #include <qfileinfo.h> |
37 | #include <qregexp.h> | 37 | #include <qregexp.h> |
38 | //#include <qpe/qcopchannel_qws.h> | 38 | //#include <qpe/qcopchannel_qws.h> |
39 | #include <qpe/qprocess.h> | ||
40 | #include <qpe/process.h> | 39 | #include <qpe/process.h> |
41 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 41 | #include <qpe/qcopenvelope_qws.h> |
43 | 42 | ||
44 | #include "transferserver.h" | 43 | #include "transferserver.h" |
44 | #include "qprocess.h" | ||
45 | 45 | ||
46 | const int block_size = 51200; | 46 | const int block_size = 51200; |
47 | 47 | ||
48 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent = 0, | 48 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, |
49 | const char* name = 0) | 49 | const char* name ) |
50 | : QServerSocket( port, 1, parent, name ) | 50 | : QServerSocket( port, 1, parent, name ) |
51 | { | 51 | { |
52 | if ( !ok() ) | 52 | if ( !ok() ) |
53 | qWarning( "Failed to bind to port %d", port ); | 53 | qWarning( "Failed to bind to port %d", port ); |
54 | } | 54 | } |
55 | 55 | ||
56 | TransferServer::~TransferServer() | 56 | TransferServer::~TransferServer() |
57 | { | 57 | { |
58 | 58 | ||
59 | } | 59 | } |
60 | 60 | ||
61 | void TransferServer::newConnection( int socket ) | 61 | void TransferServer::newConnection( int socket ) |
62 | { | 62 | { |
63 | (void) new ServerPI( socket, this ); | 63 | (void) new ServerPI( socket, this ); |
64 | } | 64 | } |
65 | 65 | ||
66 | bool accessAuthorized(QHostAddress peeraddress) | 66 | bool accessAuthorized(QHostAddress peeraddress) |
67 | { | 67 | { |
68 | Config cfg("Security"); | 68 | Config cfg("Security"); |
69 | cfg.setGroup("Sync"); | 69 | cfg.setGroup("Sync"); |
70 | uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); | 70 | uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); |
71 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); | 71 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); |
72 | bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits))) | 72 | bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits))) |
73 | == auth_peer; | 73 | == auth_peer; |
74 | /* Allows denial-of-service attack. | 74 | /* Allows denial-of-service attack. |
75 | if ( !ok ) { | 75 | if ( !ok ) { |
76 | QMessageBox::warning(0,tr("Security"), | 76 | QMessageBox::warning(0,tr("Security"), |
77 | tr("<p>An attempt to access this device from %1 has been denied.") | 77 | tr("<p>An attempt to access this device from %1 has been denied.") |
78 | .arg(peeraddress.toString())); | 78 | .arg(peeraddress.toString())); |
79 | } | 79 | } |
80 | */ | 80 | */ |
81 | return ok; | 81 | return ok; |
82 | } | 82 | } |
83 | 83 | ||
84 | ServerPI::ServerPI( int socket, QObject *parent = 0, const char* name = 0 ) | 84 | ServerPI::ServerPI( int socket, QObject *parent, const char* name ) |
85 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 85 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
86 | { | 86 | { |
87 | state = Connected; | 87 | state = Connected; |
88 | 88 | ||
89 | setSocket( socket ); | 89 | setSocket( socket ); |
90 | 90 | ||
91 | peerport = peerPort(); | 91 | peerport = peerPort(); |
92 | peeraddress = peerAddress(); | 92 | peeraddress = peerAddress(); |
93 | 93 | ||
94 | #ifndef INSECURE | 94 | #ifndef INSECURE |
95 | if ( !accessAuthorized(peeraddress) ) { | 95 | if ( !accessAuthorized(peeraddress) ) { |
96 | state = Forbidden; | 96 | state = Forbidden; |
97 | startTimer( 0 ); | 97 | startTimer( 0 ); |
98 | } else | 98 | } else |
99 | #endif | 99 | #endif |
100 | { | 100 | { |
101 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 101 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
102 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 102 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
103 | 103 | ||
104 | passiv = FALSE; | 104 | passiv = FALSE; |
105 | for( int i = 0; i < 4; i++ ) | 105 | for( int i = 0; i < 4; i++ ) |
106 | wait[i] = FALSE; | 106 | wait[i] = FALSE; |
107 | 107 | ||
108 | send( "220 Qtopia transfer service ready!" ); | 108 | send( "220 Qtopia transfer service ready!" ); |
109 | state = Wait_USER; | 109 | state = Wait_USER; |
110 | 110 | ||
111 | dtp = new ServerDTP( this ); | 111 | dtp = new ServerDTP( this ); |
112 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 112 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
113 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 113 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
114 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 114 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); |
115 | 115 | ||
116 | 116 | ||
117 | directory = QDir::currentDirPath(); | 117 | directory = QDir::currentDirPath(); |
118 | 118 | ||
119 | static int p = 1024; | 119 | static int p = 1024; |
120 | 120 | ||
121 | while ( !serversocket || !serversocket->ok() ) { | 121 | while ( !serversocket || !serversocket->ok() ) { |
122 | delete serversocket; | 122 | delete serversocket; |
123 | serversocket = new ServerSocket( ++p, this ); | 123 | serversocket = new ServerSocket( ++p, this ); |
124 | } | 124 | } |
125 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 125 | connect( serversocket, SIGNAL( newIncomming( int ) ), |
126 | SLOT( newConnection( int ) ) ); | 126 | SLOT( newConnection( int ) ) ); |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | ServerPI::~ServerPI() | 130 | ServerPI::~ServerPI() |
131 | { | 131 | { |
132 | 132 | ||
133 | } | 133 | } |
134 | 134 | ||
135 | void ServerPI::connectionClosed() | 135 | void ServerPI::connectionClosed() |
136 | { | 136 | { |
137 | // qDebug( "Debug: Connection closed" ); | 137 | // qDebug( "Debug: Connection closed" ); |
138 | delete this; | 138 | delete this; |
139 | } | 139 | } |
140 | 140 | ||
141 | void ServerPI::send( const QString& msg ) | 141 | void ServerPI::send( const QString& msg ) |
142 | { | 142 | { |
143 | QTextStream os( this ); | 143 | QTextStream os( this ); |
144 | os << msg << endl; | 144 | os << msg << endl; |
145 | //qDebug( "Reply: %s", msg.latin1() ); | 145 | //qDebug( "Reply: %s", msg.latin1() ); |
146 | } | 146 | } |
147 | 147 | ||
148 | void ServerPI::read() | 148 | void ServerPI::read() |
149 | { | 149 | { |
150 | while ( canReadLine() ) | 150 | while ( canReadLine() ) |
151 | process( readLine().stripWhiteSpace() ); | 151 | process( readLine().stripWhiteSpace() ); |
152 | } | 152 | } |
153 | 153 | ||
154 | bool ServerPI::checkUser( const QString& user ) | 154 | bool ServerPI::checkUser( const QString& user ) |
155 | { | 155 | { |
156 | if ( user.isEmpty() ) return FALSE; | 156 | if ( user.isEmpty() ) return FALSE; |
157 | 157 | ||
158 | struct passwd *pw; | 158 | struct passwd *pw; |
159 | pw = getpwuid( geteuid() ); | 159 | pw = getpwuid( geteuid() ); |
160 | QString euser = QString::fromLocal8Bit( pw->pw_name ); | 160 | QString euser = QString::fromLocal8Bit( pw->pw_name ); |
161 | return user == euser; | 161 | return user == euser; |
162 | } | 162 | } |
163 | 163 | ||
164 | bool ServerPI::checkPassword( const QString& /* password */ ) | 164 | bool ServerPI::checkPassword( const QString& /* password */ ) |
165 | { | 165 | { |
166 | // ### HACK for testing on local host | 166 | // ### HACK for testing on local host |
167 | return true; | 167 | return true; |
168 | 168 | ||
169 | /* | 169 | /* |
170 | struct passwd *pw = 0; | 170 | struct passwd *pw = 0; |
171 | struct spwd *spw = 0; | 171 | struct spwd *spw = 0; |
172 | 172 | ||
173 | pw = getpwuid( geteuid() ); | 173 | pw = getpwuid( geteuid() ); |
174 | spw = getspnam( pw->pw_name ); | 174 | spw = getspnam( pw->pw_name ); |
175 | 175 | ||
176 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 176 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
177 | if ( cpwd == "x" && spw ) | 177 | if ( cpwd == "x" && spw ) |
178 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 178 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
179 | 179 | ||
180 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 180 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
181 | return cpwd == cpassword; | 181 | return cpwd == cpassword; |
182 | */ | 182 | */ |
183 | } | 183 | } |
184 | 184 | ||
185 | bool ServerPI::checkReadFile( const QString& file ) | 185 | bool ServerPI::checkReadFile( const QString& file ) |
186 | { | 186 | { |
187 | QString filename; | 187 | QString filename; |
188 | 188 | ||
189 | if ( file[0] != "/" ) | 189 | if ( file[0] != "/" ) |
190 | filename = directory.path() + "/" + file; | 190 | filename = directory.path() + "/" + file; |
191 | else | 191 | else |
192 | filename = file; | 192 | filename = file; |
193 | 193 | ||
194 | QFileInfo fi( filename ); | 194 | QFileInfo fi( filename ); |
195 | return ( fi.exists() && fi.isReadable() ); | 195 | return ( fi.exists() && fi.isReadable() ); |
196 | } | 196 | } |
197 | 197 | ||
198 | bool ServerPI::checkWriteFile( const QString& file ) | 198 | bool ServerPI::checkWriteFile( const QString& file ) |
199 | { | 199 | { |
200 | QString filename; | 200 | QString filename; |
201 | 201 | ||
202 | if ( file[0] != "/" ) | 202 | if ( file[0] != "/" ) |
203 | filename = directory.path() + "/" + file; | 203 | filename = directory.path() + "/" + file; |
204 | else | 204 | else |
205 | filename = file; | 205 | filename = file; |
206 | 206 | ||
207 | QFileInfo fi( filename ); | 207 | QFileInfo fi( filename ); |
208 | 208 | ||
209 | if ( fi.exists() ) | 209 | if ( fi.exists() ) |
210 | if ( !QFile( filename ).remove() ) | 210 | if ( !QFile( filename ).remove() ) |
211 | return FALSE; | 211 | return FALSE; |
212 | return TRUE; | 212 | return TRUE; |
@@ -727,257 +727,257 @@ QString ServerPI::fileListing( QFileInfo *info ) | |||
727 | else | 727 | else |
728 | s += "-"; | 728 | s += "-"; |
729 | 729 | ||
730 | // permisson string | 730 | // permisson string |
731 | s += permissionString( info ) + " "; | 731 | s += permissionString( info ) + " "; |
732 | 732 | ||
733 | // number of hardlinks | 733 | // number of hardlinks |
734 | int subdirs = 1; | 734 | int subdirs = 1; |
735 | 735 | ||
736 | if ( info->isDir() ) | 736 | if ( info->isDir() ) |
737 | subdirs = 2; | 737 | subdirs = 2; |
738 | // FIXME : this is to slow | 738 | // FIXME : this is to slow |
739 | //if ( info->isDir() ) | 739 | //if ( info->isDir() ) |
740 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); | 740 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); |
741 | 741 | ||
742 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; | 742 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; |
743 | 743 | ||
744 | // owner | 744 | // owner |
745 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; | 745 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; |
746 | 746 | ||
747 | // group | 747 | // group |
748 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; | 748 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; |
749 | 749 | ||
750 | // file size in bytes | 750 | // file size in bytes |
751 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; | 751 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; |
752 | 752 | ||
753 | // last modified date | 753 | // last modified date |
754 | QDate date = info->lastModified().date(); | 754 | QDate date = info->lastModified().date(); |
755 | QTime time = info->lastModified().time(); | 755 | QTime time = info->lastModified().time(); |
756 | s += date.monthName( date.month() ) + " " | 756 | s += date.monthName( date.month() ) + " " |
757 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " | 757 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " |
758 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" | 758 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" |
759 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; | 759 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; |
760 | 760 | ||
761 | // file name | 761 | // file name |
762 | s += info->fileName(); | 762 | s += info->fileName(); |
763 | 763 | ||
764 | return s; | 764 | return s; |
765 | } | 765 | } |
766 | 766 | ||
767 | QString ServerPI::permissionString( QFileInfo *info ) | 767 | QString ServerPI::permissionString( QFileInfo *info ) |
768 | { | 768 | { |
769 | if ( !info ) return QString( "---------" ); | 769 | if ( !info ) return QString( "---------" ); |
770 | QString s; | 770 | QString s; |
771 | 771 | ||
772 | // user | 772 | // user |
773 | if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; | 773 | if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; |
774 | else s += "-"; | 774 | else s += "-"; |
775 | if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; | 775 | if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; |
776 | else s += "-"; | 776 | else s += "-"; |
777 | if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; | 777 | if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; |
778 | else s += "-"; | 778 | else s += "-"; |
779 | 779 | ||
780 | // group | 780 | // group |
781 | if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; | 781 | if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; |
782 | else s += "-"; | 782 | else s += "-"; |
783 | if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; | 783 | if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; |
784 | else s += "-"; | 784 | else s += "-"; |
785 | if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; | 785 | if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; |
786 | else s += "-"; | 786 | else s += "-"; |
787 | 787 | ||
788 | // exec | 788 | // exec |
789 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; | 789 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; |
790 | else s += "-"; | 790 | else s += "-"; |
791 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; | 791 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; |
792 | else s += "-"; | 792 | else s += "-"; |
793 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; | 793 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; |
794 | else s += "-"; | 794 | else s += "-"; |
795 | 795 | ||
796 | return s; | 796 | return s; |
797 | } | 797 | } |
798 | 798 | ||
799 | void ServerPI::newConnection( int socket ) | 799 | void ServerPI::newConnection( int socket ) |
800 | { | 800 | { |
801 | //qDebug( "New incomming connection" ); | 801 | //qDebug( "New incomming connection" ); |
802 | 802 | ||
803 | if ( !passiv ) return; | 803 | if ( !passiv ) return; |
804 | 804 | ||
805 | if ( wait[SendFile] ) { | 805 | if ( wait[SendFile] ) { |
806 | QStringList targets; | 806 | QStringList targets; |
807 | if ( backupRestoreGzip( waitfile, targets ) ) | 807 | if ( backupRestoreGzip( waitfile, targets ) ) |
808 | dtp->sendGzipFile( waitfile, targets ); | 808 | dtp->sendGzipFile( waitfile, targets ); |
809 | else | 809 | else |
810 | dtp->sendFile( waitfile ); | 810 | dtp->sendFile( waitfile ); |
811 | dtp->setSocket( socket ); | 811 | dtp->setSocket( socket ); |
812 | } | 812 | } |
813 | else if ( wait[RetrieveFile] ) { | 813 | else if ( wait[RetrieveFile] ) { |
814 | qDebug("check retrieve file"); | 814 | qDebug("check retrieve file"); |
815 | if ( backupRestoreGzip( waitfile ) ) | 815 | if ( backupRestoreGzip( waitfile ) ) |
816 | dtp->retrieveGzipFile( waitfile ); | 816 | dtp->retrieveGzipFile( waitfile ); |
817 | else | 817 | else |
818 | dtp->retrieveFile( waitfile ); | 818 | dtp->retrieveFile( waitfile ); |
819 | dtp->setSocket( socket ); | 819 | dtp->setSocket( socket ); |
820 | } | 820 | } |
821 | else if ( wait[SendByteArray] ) { | 821 | else if ( wait[SendByteArray] ) { |
822 | dtp->sendByteArray( waitarray ); | 822 | dtp->sendByteArray( waitarray ); |
823 | dtp->setSocket( socket ); | 823 | dtp->setSocket( socket ); |
824 | } | 824 | } |
825 | else if ( wait[RetrieveByteArray] ) { | 825 | else if ( wait[RetrieveByteArray] ) { |
826 | qDebug("retrieve byte array"); | 826 | qDebug("retrieve byte array"); |
827 | dtp->retrieveByteArray(); | 827 | dtp->retrieveByteArray(); |
828 | dtp->setSocket( socket ); | 828 | dtp->setSocket( socket ); |
829 | } | 829 | } |
830 | else | 830 | else |
831 | waitsocket = socket; | 831 | waitsocket = socket; |
832 | 832 | ||
833 | for( int i = 0; i < 4; i++ ) | 833 | for( int i = 0; i < 4; i++ ) |
834 | wait[i] = FALSE; | 834 | wait[i] = FALSE; |
835 | } | 835 | } |
836 | 836 | ||
837 | QString ServerPI::absFilePath( const QString& file ) | 837 | QString ServerPI::absFilePath( const QString& file ) |
838 | { | 838 | { |
839 | if ( file.isEmpty() ) return file; | 839 | if ( file.isEmpty() ) return file; |
840 | 840 | ||
841 | QString filepath( file ); | 841 | QString filepath( file ); |
842 | if ( file[0] != "/" ) | 842 | if ( file[0] != "/" ) |
843 | filepath = directory.path() + "/" + file; | 843 | filepath = directory.path() + "/" + file; |
844 | 844 | ||
845 | return filepath; | 845 | return filepath; |
846 | } | 846 | } |
847 | 847 | ||
848 | 848 | ||
849 | void ServerPI::timerEvent( QTimerEvent * ) | 849 | void ServerPI::timerEvent( QTimerEvent * ) |
850 | { | 850 | { |
851 | connectionClosed(); | 851 | connectionClosed(); |
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0) | 855 | ServerDTP::ServerDTP( QObject *parent, const char* name ) |
856 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 856 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
857 | retrieveTargzProc( 0 ), gzipProc( 0 ) | 857 | retrieveTargzProc( 0 ), gzipProc( 0 ) |
858 | { | 858 | { |
859 | 859 | ||
860 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 860 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
861 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 861 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
862 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); | 862 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); |
863 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 863 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
864 | 864 | ||
865 | gzipProc = new QProcess( this, "gzipProc" ); | 865 | gzipProc = new QProcess( this, "gzipProc" ); |
866 | gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); | 866 | gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout ); |
867 | 867 | ||
868 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); | 868 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); |
869 | createTargzProc->setCommunication( QProcess::Stdout ); | 869 | createTargzProc->setCommunication( QProcess::Stdout ); |
870 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 870 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
871 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); | 871 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); |
872 | 872 | ||
873 | QStringList args = "tar"; | 873 | QStringList args = "tar"; |
874 | args += "-xv"; | 874 | args += "-xv"; |
875 | retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); | 875 | retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); |
876 | retrieveTargzProc->setCommunication( QProcess::Stdin ); | 876 | retrieveTargzProc->setCommunication( QProcess::Stdin ); |
877 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 877 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
878 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 878 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
879 | SIGNAL( completed() ) ); | 879 | SIGNAL( completed() ) ); |
880 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 880 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
881 | SLOT( extractTarDone() ) ); | 881 | SLOT( extractTarDone() ) ); |
882 | } | 882 | } |
883 | 883 | ||
884 | ServerDTP::~ServerDTP() | 884 | ServerDTP::~ServerDTP() |
885 | { | 885 | { |
886 | buf.close(); | 886 | buf.close(); |
887 | file.close(); | 887 | file.close(); |
888 | createTargzProc->kill(); | 888 | createTargzProc->kill(); |
889 | } | 889 | } |
890 | 890 | ||
891 | void ServerDTP::extractTarDone() | 891 | void ServerDTP::extractTarDone() |
892 | { | 892 | { |
893 | qDebug("extract done"); | 893 | qDebug("extract done"); |
894 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); | 894 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); |
895 | e << file.name(); | 895 | e << file.name(); |
896 | } | 896 | } |
897 | 897 | ||
898 | void ServerDTP::connected() | 898 | void ServerDTP::connected() |
899 | { | 899 | { |
900 | // send file mode | 900 | // send file mode |
901 | switch ( mode ) { | 901 | switch ( mode ) { |
902 | case SendFile : | 902 | case SendFile : |
903 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 903 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
904 | emit failed(); | 904 | emit failed(); |
905 | mode = Idle; | 905 | mode = Idle; |
906 | return; | 906 | return; |
907 | } | 907 | } |
908 | 908 | ||
909 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 909 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); |
910 | 910 | ||
911 | bytes_written = 0; | 911 | bytes_written = 0; |
912 | if ( file.size() == 0 ) { | 912 | if ( file.size() == 0 ) { |
913 | //make sure it doesn't hang on empty files | 913 | //make sure it doesn't hang on empty files |
914 | file.close(); | 914 | file.close(); |
915 | emit completed(); | 915 | emit completed(); |
916 | mode = Idle; | 916 | mode = Idle; |
917 | } else { | 917 | } else { |
918 | 918 | ||
919 | if( !file.atEnd() ) { | 919 | if( !file.atEnd() ) { |
920 | QCString s; | 920 | QCString s; |
921 | s.resize( block_size ); | 921 | s.resize( block_size ); |
922 | int bytes = file.readBlock( s.data(), block_size ); | 922 | int bytes = file.readBlock( s.data(), block_size ); |
923 | writeBlock( s.data(), bytes ); | 923 | writeBlock( s.data(), bytes ); |
924 | } | 924 | } |
925 | } | 925 | } |
926 | break; | 926 | break; |
927 | case SendGzipFile: | 927 | case SendGzipFile: |
928 | if ( createTargzProc->isRunning() ) { | 928 | if ( createTargzProc->isRunning() ) { |
929 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY | 929 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY |
930 | qWarning("Previous tar --gzip process is still running; killing it..."); | 930 | qWarning("Previous tar --gzip process is still running; killing it..."); |
931 | createTargzProc->kill(); | 931 | createTargzProc->kill(); |
932 | } | 932 | } |
933 | 933 | ||
934 | bytes_written = 0; | 934 | bytes_written = 0; |
935 | qDebug("==>start send tar process"); | 935 | qDebug("==>start send tar process"); |
936 | if ( !createTargzProc->start() ) | 936 | if ( !createTargzProc->start() ) |
937 | qWarning("Error starting %s or %s", | 937 | qWarning("Error starting %s or %s", |
938 | createTargzProc->arguments().join(" ").latin1(), | 938 | createTargzProc->arguments().join(" ").latin1(), |
939 | gzipProc->arguments().join(" ").latin1() ); | 939 | gzipProc->arguments().join(" ").latin1() ); |
940 | break; | 940 | break; |
941 | case SendBuffer: | 941 | case SendBuffer: |
942 | if ( !buf.open( IO_ReadOnly) ) { | 942 | if ( !buf.open( IO_ReadOnly) ) { |
943 | emit failed(); | 943 | emit failed(); |
944 | mode = Idle; | 944 | mode = Idle; |
945 | return; | 945 | return; |
946 | } | 946 | } |
947 | 947 | ||
948 | // qDebug( "Debug: Sending byte array" ); | 948 | // qDebug( "Debug: Sending byte array" ); |
949 | bytes_written = 0; | 949 | bytes_written = 0; |
950 | while( !buf.atEnd() ) | 950 | while( !buf.atEnd() ) |
951 | putch( buf.getch() ); | 951 | putch( buf.getch() ); |
952 | buf.close(); | 952 | buf.close(); |
953 | break; | 953 | break; |
954 | case RetrieveFile: | 954 | case RetrieveFile: |
955 | // retrieve file mode | 955 | // retrieve file mode |
956 | if ( file.exists() && !file.remove() ) { | 956 | if ( file.exists() && !file.remove() ) { |
957 | emit failed(); | 957 | emit failed(); |
958 | mode = Idle; | 958 | mode = Idle; |
959 | return; | 959 | return; |
960 | } | 960 | } |
961 | 961 | ||
962 | if ( !file.open( IO_WriteOnly) ) { | 962 | if ( !file.open( IO_WriteOnly) ) { |
963 | emit failed(); | 963 | emit failed(); |
964 | mode = Idle; | 964 | mode = Idle; |
965 | return; | 965 | return; |
966 | } | 966 | } |
967 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); | 967 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); |
968 | break; | 968 | break; |
969 | case RetrieveGzipFile: | 969 | case RetrieveGzipFile: |
970 | qDebug("=-> starting tar process to receive .tgz file"); | 970 | qDebug("=-> starting tar process to receive .tgz file"); |
971 | break; | 971 | break; |
972 | case RetrieveBuffer: | 972 | case RetrieveBuffer: |
973 | // retrieve buffer mode | 973 | // retrieve buffer mode |
974 | if ( !buf.open( IO_WriteOnly) ) { | 974 | if ( !buf.open( IO_WriteOnly) ) { |
975 | emit failed(); | 975 | emit failed(); |
976 | mode = Idle; | 976 | mode = Idle; |
977 | return; | 977 | return; |
978 | } | 978 | } |
979 | // qDebug( "Debug: Retrieving byte array" ); | 979 | // qDebug( "Debug: Retrieving byte array" ); |
980 | break; | 980 | break; |
981 | case Idle: | 981 | case Idle: |
982 | qDebug("connection established but mode set to Idle; BUG!"); | 982 | qDebug("connection established but mode set to Idle; BUG!"); |
983 | break; | 983 | break; |