author | chicken <chicken> | 2004-03-01 17:44:52 (UTC) |
---|---|---|
committer | chicken <chicken> | 2004-03-01 17:44:52 (UTC) |
commit | 5b640d3f070b0b2de361421abf93949410546e19 (patch) (unidiff) | |
tree | 98d6ebb158e780a299cca27cbb7c7105a8dedef3 | |
parent | bdac663be648746b868757a6fc9e6c443e6f51b1 (diff) | |
download | opie-5b640d3f070b0b2de361421abf93949410546e19.zip opie-5b640d3f070b0b2de361421abf93949410546e19.tar.gz opie-5b640d3f070b0b2de361421abf93949410546e19.tar.bz2 |
fix includes
-rw-r--r-- | core/qws/main.cpp | 2 | ||||
-rw-r--r-- | core/qws/oqwsserver.cpp | 15 | ||||
-rw-r--r-- | core/qws/qcopbridge.cpp | 6 | ||||
-rw-r--r-- | core/qws/transferserver.cpp | 8 |
4 files changed, 0 insertions, 31 deletions
diff --git a/core/qws/main.cpp b/core/qws/main.cpp index bfed283..1c3c621 100644 --- a/core/qws/main.cpp +++ b/core/qws/main.cpp | |||
@@ -1,71 +1,69 @@ | |||
1 | #include <qwindowsystem_qws.h> | ||
2 | #include <qapplication.h> | ||
3 | 1 | ||
4 | #include "oqwsserver.h" | 2 | #include "oqwsserver.h" |
5 | 3 | ||
6 | #include <sys/types.h> | 4 | #include <sys/types.h> |
7 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
8 | #include <fcntl.h> | 6 | #include <fcntl.h> |
9 | #include <unistd.h> | 7 | #include <unistd.h> |
10 | 8 | ||
11 | #include <syslog.h> | 9 | #include <syslog.h> |
12 | #include <stdio.h> | 10 | #include <stdio.h> |
13 | 11 | ||
14 | #define APPNAME "op-qws" | 12 | #define APPNAME "op-qws" |
15 | 13 | ||
16 | void toSyslog(QtMsgType type, const char *msg) | 14 | void toSyslog(QtMsgType type, const char *msg) |
17 | { | 15 | { |
18 | int level = LOG_INFO; | 16 | int level = LOG_INFO; |
19 | switch (type) { | 17 | switch (type) { |
20 | case QtDebugMsg: | 18 | case QtDebugMsg: |
21 | level = LOG_DEBUG; | 19 | level = LOG_DEBUG; |
22 | break; | 20 | break; |
23 | case QtWarningMsg: | 21 | case QtWarningMsg: |
24 | level = LOG_WARNING; | 22 | level = LOG_WARNING; |
25 | break; | 23 | break; |
26 | case QtFatalMsg: | 24 | case QtFatalMsg: |
27 | level = LOG_ERR; | 25 | level = LOG_ERR; |
28 | break; | 26 | break; |
29 | } | 27 | } |
30 | syslog (LOG_DAEMON | level, msg); | 28 | syslog (LOG_DAEMON | level, msg); |
31 | } | 29 | } |
32 | 30 | ||
33 | int daemon_init(void) | 31 | int daemon_init(void) |
34 | { | 32 | { |
35 | pid_t pid; | 33 | pid_t pid; |
36 | 34 | ||
37 | if ((pid = fork()) < 0) | 35 | if ((pid = fork()) < 0) |
38 | return(-1); | 36 | return(-1); |
39 | else if (pid != 0) | 37 | else if (pid != 0) |
40 | exit(0); | 38 | exit(0); |
41 | 39 | ||
42 | setsid(); | 40 | setsid(); |
43 | 41 | ||
44 | chdir("/"); | 42 | chdir("/"); |
45 | 43 | ||
46 | umask(0); | 44 | umask(0); |
47 | 45 | ||
48 | fclose(stdout); | 46 | fclose(stdout); |
49 | fclose(stderr); | 47 | fclose(stderr); |
50 | fclose(stdin); | 48 | fclose(stdin); |
51 | 49 | ||
52 | return(0); | 50 | return(0); |
53 | } | 51 | } |
54 | 52 | ||
55 | int main( int argc, char ** argv ) | 53 | int main( int argc, char ** argv ) |
56 | { | 54 | { |
57 | while (argc > 1) { | 55 | while (argc > 1) { |
58 | if (strcmp(argv[--argc], "-d") == 0) { | 56 | if (strcmp(argv[--argc], "-d") == 0) { |
59 | // daemonize | 57 | // daemonize |
60 | openlog(APPNAME, 0, LOG_DAEMON); | 58 | openlog(APPNAME, 0, LOG_DAEMON); |
61 | qInstallMsgHandler(toSyslog); | 59 | qInstallMsgHandler(toSyslog); |
62 | if (daemon_init() != 0) { | 60 | if (daemon_init() != 0) { |
63 | fprintf(stderr, "%s: Error: Unable to daemonize\n", APPNAME); | 61 | fprintf(stderr, "%s: Error: Unable to daemonize\n", APPNAME); |
64 | return 1; | 62 | return 1; |
65 | } | 63 | } |
66 | } | 64 | } |
67 | } | 65 | } |
68 | 66 | ||
69 | OQWSServer a(argc, argv, QApplication::GuiServer); | 67 | OQWSServer a(argc, argv, QApplication::GuiServer); |
70 | return a.exec(); | 68 | return a.exec(); |
71 | } | 69 | } |
diff --git a/core/qws/oqwsserver.cpp b/core/qws/oqwsserver.cpp index 1c61d19..907686a 100644 --- a/core/qws/oqwsserver.cpp +++ b/core/qws/oqwsserver.cpp | |||
@@ -1,196 +1,181 @@ | |||
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 <syslog.h> | 21 | #include <syslog.h> |
22 | 22 | ||
23 | #include "oqwsserver.h" | 23 | #include "oqwsserver.h" |
24 | #include "qcopbridge.h" | 24 | #include "qcopbridge.h" |
25 | #include "transferserver.h" | 25 | #include "transferserver.h" |
26 | 26 | ||
27 | #include <qpe/applnk.h> | ||
28 | #include <qpe/mimetype.h> | ||
29 | #include <qpe/password.h> | ||
30 | #include <qpe/config.h> | ||
31 | #include <qpe/power.h> | ||
32 | #include <qpe/timeconversion.h> | ||
33 | #include <qpe/qcopenvelope_qws.h> | ||
34 | #include <qpe/network.h> | ||
35 | #include <qpe/global.h> | ||
36 | 27 | ||
37 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) | 28 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) |
38 | #include <qpe/custom.h> | 29 | #include <qpe/custom.h> |
39 | #endif | 30 | #endif |
40 | 31 | ||
41 | #include <opie/odevice.h> | 32 | #include <opie/odevice.h> |
42 | 33 | ||
43 | #include <qgfx_qws.h> | ||
44 | #include <qmainwindow.h> | ||
45 | #include <qmessagebox.h> | ||
46 | #include <qtimer.h> | ||
47 | #include <qwindowsystem_qws.h> | ||
48 | 34 | ||
49 | #include <qvaluelist.h> | ||
50 | 35 | ||
51 | #include <stdlib.h> | 36 | #include <stdlib.h> |
52 | #include <unistd.h> | 37 | #include <unistd.h> |
53 | #include <fcntl.h> | 38 | #include <fcntl.h> |
54 | 39 | ||
55 | using namespace Opie; | 40 | using namespace Opie; |
56 | 41 | ||
57 | OQWSServer::OQWSServer( int& argc, char **argv, Type appType ) | 42 | OQWSServer::OQWSServer( int& argc, char **argv, Type appType ) |
58 | : QPEApplication( argc, argv, appType ) | 43 | : QPEApplication( argc, argv, appType ) |
59 | { | 44 | { |
60 | startServers(); | 45 | startServers(); |
61 | } | 46 | } |
62 | 47 | ||
63 | OQWSServer::~OQWSServer() | 48 | OQWSServer::~OQWSServer() |
64 | { | 49 | { |
65 | terminateServers(); | 50 | terminateServers(); |
66 | } | 51 | } |
67 | 52 | ||
68 | bool OQWSServer::eventFilter ( QObject *o, QEvent *e ) | 53 | bool OQWSServer::eventFilter ( QObject *o, QEvent *e ) |
69 | { | 54 | { |
70 | #if 0 | 55 | #if 0 |
71 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { | 56 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { |
72 | QKeyEvent *ke = (QKeyEvent *) e; | 57 | QKeyEvent *ke = (QKeyEvent *) e; |
73 | 58 | ||
74 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); | 59 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); |
75 | 60 | ||
76 | if ( db ) { | 61 | if ( db ) { |
77 | if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) | 62 | if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) |
78 | return true; //checkButtonAction retrune false if events should be routed through | 63 | return true; //checkButtonAction retrune false if events should be routed through |
79 | } | 64 | } |
80 | } | 65 | } |
81 | #endif | 66 | #endif |
82 | return QPEApplication::eventFilter ( o, e ); | 67 | return QPEApplication::eventFilter ( o, e ); |
83 | } | 68 | } |
84 | 69 | ||
85 | #ifdef Q_WS_QWS | 70 | #ifdef Q_WS_QWS |
86 | 71 | ||
87 | bool OQWSServer::qwsEventFilter( QWSEvent *e ) | 72 | bool OQWSServer::qwsEventFilter( QWSEvent *e ) |
88 | { | 73 | { |
89 | #if 0 | 74 | #if 0 |
90 | qpedesktop->checkMemory(); | 75 | qpedesktop->checkMemory(); |
91 | 76 | ||
92 | if ( e->type == QWSEvent::Key ) { | 77 | if ( e->type == QWSEvent::Key ) { |
93 | QWSKeyEvent * ke = (QWSKeyEvent *) e; | 78 | QWSKeyEvent * ke = (QWSKeyEvent *) e; |
94 | ushort keycode = ke-> simpleData. keycode; | 79 | ushort keycode = ke-> simpleData. keycode; |
95 | 80 | ||
96 | if ( !loggedin && keycode != Key_F34 ) | 81 | if ( !loggedin && keycode != Key_F34 ) |
97 | return true; | 82 | return true; |
98 | 83 | ||
99 | bool press = ke-> simpleData. is_press; | 84 | bool press = ke-> simpleData. is_press; |
100 | bool autoRepeat = ke-> simpleData. is_auto_repeat; | 85 | bool autoRepeat = ke-> simpleData. is_auto_repeat; |
101 | 86 | ||
102 | if ( !keyboardGrabbed ( )) { | 87 | if ( !keyboardGrabbed ( )) { |
103 | // app that registers key/message to be sent back to the app, when it doesn't have focus, | 88 | // app that registers key/message to be sent back to the app, when it doesn't have focus, |
104 | // when user presses key, unless keyboard has been requested from app. | 89 | // when user presses key, unless keyboard has been requested from app. |
105 | // will not send multiple repeats if user holds key | 90 | // will not send multiple repeats if user holds key |
106 | // i.e. one shot | 91 | // i.e. one shot |
107 | 92 | ||
108 | if ( keycode != 0 && press && !autoRepeat ) { | 93 | if ( keycode != 0 && press && !autoRepeat ) { |
109 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | 94 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { |
110 | if (( *it ). getKeyCode ( ) == keycode ) { | 95 | if (( *it ). getKeyCode ( ) == keycode ) { |
111 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); | 96 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); |
112 | return true; | 97 | return true; |
113 | } | 98 | } |
114 | } | 99 | } |
115 | } | 100 | } |
116 | } | 101 | } |
117 | 102 | ||
118 | if ( keycode == HardKey_Suspend ) { | 103 | if ( keycode == HardKey_Suspend ) { |
119 | if ( press ) | 104 | if ( press ) |
120 | emit power ( ); | 105 | emit power ( ); |
121 | return true; | 106 | return true; |
122 | } | 107 | } |
123 | else if ( keycode == HardKey_Backlight ) { | 108 | else if ( keycode == HardKey_Backlight ) { |
124 | if ( press ) | 109 | if ( press ) |
125 | emit backlight ( ); | 110 | emit backlight ( ); |
126 | return true; | 111 | return true; |
127 | } | 112 | } |
128 | else if ( keycode == Key_F32 ) { | 113 | else if ( keycode == Key_F32 ) { |
129 | if ( press ) | 114 | if ( press ) |
130 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 115 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
131 | return true; | 116 | return true; |
132 | } | 117 | } |
133 | else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM | 118 | else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM |
134 | if ( press ) | 119 | if ( press ) |
135 | emit symbol ( ); | 120 | emit symbol ( ); |
136 | return true; | 121 | return true; |
137 | } | 122 | } |
138 | else if ( keycode == Key_NumLock ) { | 123 | else if ( keycode == Key_NumLock ) { |
139 | if ( press ) | 124 | if ( press ) |
140 | emit numLockStateToggle ( ); | 125 | emit numLockStateToggle ( ); |
141 | } | 126 | } |
142 | else if ( keycode == Key_CapsLock ) { | 127 | else if ( keycode == Key_CapsLock ) { |
143 | if ( press ) | 128 | if ( press ) |
144 | emit capsLockStateToggle(); | 129 | emit capsLockStateToggle(); |
145 | } | 130 | } |
146 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { | 131 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { |
147 | if ( m_keyclick_sound ) | 132 | if ( m_keyclick_sound ) |
148 | ODevice::inst ( )-> keySound ( ); | 133 | ODevice::inst ( )-> keySound ( ); |
149 | } | 134 | } |
150 | } | 135 | } |
151 | else if ( e-> type == QWSEvent::Mouse ) { | 136 | else if ( e-> type == QWSEvent::Mouse ) { |
152 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; | 137 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; |
153 | static bool up = true; | 138 | static bool up = true; |
154 | 139 | ||
155 | if ( me-> simpleData. state & LeftButton ) { | 140 | if ( me-> simpleData. state & LeftButton ) { |
156 | if ( up ) { | 141 | if ( up ) { |
157 | up = false; | 142 | up = false; |
158 | if ( m_screentap_sound ) | 143 | if ( m_screentap_sound ) |
159 | ODevice::inst ( ) -> touchSound ( ); | 144 | ODevice::inst ( ) -> touchSound ( ); |
160 | } | 145 | } |
161 | } | 146 | } |
162 | else { | 147 | else { |
163 | up = true; | 148 | up = true; |
164 | } | 149 | } |
165 | } | 150 | } |
166 | #endif | 151 | #endif |
167 | return QPEApplication::qwsEventFilter ( e ); | 152 | return QPEApplication::qwsEventFilter ( e ); |
168 | } | 153 | } |
169 | 154 | ||
170 | #endif | 155 | #endif |
171 | 156 | ||
172 | void OQWSServer::startServers() | 157 | void OQWSServer::startServers() |
173 | { | 158 | { |
174 | // start qcop bridge server | 159 | // start qcop bridge server |
175 | m_qcopBridge = new QCopBridge( 4243 ); | 160 | m_qcopBridge = new QCopBridge( 4243 ); |
176 | if ( !m_qcopBridge->ok() ) { | 161 | if ( !m_qcopBridge->ok() ) { |
177 | delete m_qcopBridge; | 162 | delete m_qcopBridge; |
178 | m_qcopBridge = 0; | 163 | m_qcopBridge = 0; |
179 | } | 164 | } |
180 | // start transfer server | 165 | // start transfer server |
181 | m_transferServer = new TransferServer( 4242 ); | 166 | m_transferServer = new TransferServer( 4242 ); |
182 | if ( !m_transferServer->ok() ) { | 167 | if ( !m_transferServer->ok() ) { |
183 | delete m_transferServer; | 168 | delete m_transferServer; |
184 | m_transferServer = 0; | 169 | m_transferServer = 0; |
185 | } | 170 | } |
186 | //if ( !transferServer || !qcopBridge ) | 171 | //if ( !transferServer || !qcopBridge ) |
187 | // startTimer( 2000 ); | 172 | // startTimer( 2000 ); |
188 | } | 173 | } |
189 | 174 | ||
190 | void OQWSServer::terminateServers() | 175 | void OQWSServer::terminateServers() |
191 | { | 176 | { |
192 | delete m_transferServer; | 177 | delete m_transferServer; |
193 | delete m_qcopBridge; | 178 | delete m_qcopBridge; |
194 | m_transferServer = 0; | 179 | m_transferServer = 0; |
195 | m_qcopBridge = 0; | 180 | m_qcopBridge = 0; |
196 | } | 181 | } |
diff --git a/core/qws/qcopbridge.cpp b/core/qws/qcopbridge.cpp index 6177a7c..c0c52e8 100644 --- a/core/qws/qcopbridge.cpp +++ b/core/qws/qcopbridge.cpp | |||
@@ -1,422 +1,416 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the 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 | #include <qpe/version.h> | 26 | #include <qpe/version.h> |
27 | 27 | ||
28 | #include <qdir.h> | ||
29 | #include <qfile.h> | ||
30 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
31 | #include <qdatastream.h> | ||
32 | #include <qstringlist.h> | ||
33 | #include <qfileinfo.h> | ||
34 | #include <qregexp.h> | ||
35 | #ifdef QWS | 29 | #ifdef QWS |
36 | #include <qcopchannel_qws.h> | 30 | #include <qcopchannel_qws.h> |
37 | #endif | 31 | #endif |
38 | 32 | ||
39 | #define _XOPEN_SOURCE | 33 | #define _XOPEN_SOURCE |
40 | #include <pwd.h> | 34 | #include <pwd.h> |
41 | #include <sys/types.h> | 35 | #include <sys/types.h> |
42 | #include <unistd.h> | 36 | #include <unistd.h> |
43 | 37 | ||
44 | #if defined(_OS_LINUX_) | 38 | #if defined(_OS_LINUX_) |
45 | #include <shadow.h> | 39 | #include <shadow.h> |
46 | #endif | 40 | #endif |
47 | 41 | ||
48 | //#define INSECURE | 42 | //#define INSECURE |
49 | 43 | ||
50 | const int block_size = 51200; | 44 | const int block_size = 51200; |
51 | 45 | ||
52 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , | 46 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , |
53 | const char* name ) | 47 | const char* name ) |
54 | : QServerSocket( port, 1, parent, name ), | 48 | : QServerSocket( port, 1, parent, name ), |
55 | desktopChannel( 0 ), | 49 | desktopChannel( 0 ), |
56 | cardChannel( 0 ) | 50 | cardChannel( 0 ) |
57 | { | 51 | { |
58 | if ( !ok() ) | 52 | if ( !ok() ) |
59 | qWarning( "Failed to bind to port %d", port ); | 53 | qWarning( "Failed to bind to port %d", port ); |
60 | else { | 54 | else { |
61 | #ifndef QT_NO_COP | 55 | #ifndef QT_NO_COP |
62 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); | 56 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); |
63 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 57 | connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
64 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 58 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); |
65 | cardChannel = new QCopChannel( "QPE/Card", this ); | 59 | cardChannel = new QCopChannel( "QPE/Card", this ); |
66 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 60 | connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
67 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); | 61 | this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); |
68 | #endif | 62 | #endif |
69 | } | 63 | } |
70 | sendSync = FALSE; | 64 | sendSync = FALSE; |
71 | } | 65 | } |
72 | 66 | ||
73 | QCopBridge::~QCopBridge() | 67 | QCopBridge::~QCopBridge() |
74 | { | 68 | { |
75 | #ifndef QT_NO_COP | 69 | #ifndef QT_NO_COP |
76 | delete desktopChannel; | 70 | delete desktopChannel; |
77 | #endif | 71 | #endif |
78 | } | 72 | } |
79 | 73 | ||
80 | void QCopBridge::newConnection( int socket ) | 74 | void QCopBridge::newConnection( int socket ) |
81 | { | 75 | { |
82 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); | 76 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); |
83 | openConnections.append( pi ); | 77 | openConnections.append( pi ); |
84 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); | 78 | connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); |
85 | #ifndef QT_NO_COP | 79 | #ifndef QT_NO_COP |
86 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; | 80 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; |
87 | #endif | 81 | #endif |
88 | 82 | ||
89 | if ( sendSync ) { | 83 | if ( sendSync ) { |
90 | pi ->startSync(); | 84 | pi ->startSync(); |
91 | sendSync = FALSE; | 85 | sendSync = FALSE; |
92 | } | 86 | } |
93 | } | 87 | } |
94 | 88 | ||
95 | void QCopBridge::connectionClosed( QCopBridgePI *pi ) | 89 | void QCopBridge::connectionClosed( QCopBridgePI *pi ) |
96 | { | 90 | { |
97 | openConnections.remove( pi ); | 91 | openConnections.remove( pi ); |
98 | if ( openConnections.count() == 0 ) { | 92 | if ( openConnections.count() == 0 ) { |
99 | #ifndef QT_NO_COP | 93 | #ifndef QT_NO_COP |
100 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 94 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
101 | #endif | 95 | #endif |
102 | } | 96 | } |
103 | } | 97 | } |
104 | 98 | ||
105 | void QCopBridge::closeOpenConnections() | 99 | void QCopBridge::closeOpenConnections() |
106 | { | 100 | { |
107 | QCopBridgePI *pi; | 101 | QCopBridgePI *pi; |
108 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) | 102 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
109 | pi->close(); | 103 | pi->close(); |
110 | } | 104 | } |
111 | 105 | ||
112 | 106 | ||
113 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) | 107 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) |
114 | { | 108 | { |
115 | command.stripWhiteSpace(); | 109 | command.stripWhiteSpace(); |
116 | 110 | ||
117 | int paren = command.find( "(" ); | 111 | int paren = command.find( "(" ); |
118 | if ( paren <= 0 ) { | 112 | if ( paren <= 0 ) { |
119 | qDebug("DesktopMessage: bad qcop syntax"); | 113 | qDebug("DesktopMessage: bad qcop syntax"); |
120 | return; | 114 | return; |
121 | } | 115 | } |
122 | 116 | ||
123 | QString params = command.mid( paren + 1 ); | 117 | QString params = command.mid( paren + 1 ); |
124 | if ( params[params.length()-1] != ')' ) { | 118 | if ( params[params.length()-1] != ')' ) { |
125 | qDebug("DesktopMessage: bad qcop syntax"); | 119 | qDebug("DesktopMessage: bad qcop syntax"); |
126 | return; | 120 | return; |
127 | } | 121 | } |
128 | 122 | ||
129 | params.truncate( params.length()-1 ); | 123 | params.truncate( params.length()-1 ); |
130 | 124 | ||
131 | QStringList paramList = QStringList::split( ",", params ); | 125 | QStringList paramList = QStringList::split( ",", params ); |
132 | QString data; | 126 | QString data; |
133 | if ( paramList.count() ) { | 127 | if ( paramList.count() ) { |
134 | QDataStream stream( args, IO_ReadOnly ); | 128 | QDataStream stream( args, IO_ReadOnly ); |
135 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { | 129 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { |
136 | QString str; | 130 | QString str; |
137 | if ( *it == "QString" ) { | 131 | if ( *it == "QString" ) { |
138 | stream >> str; | 132 | stream >> str; |
139 | } else if ( *it == "QCString" ) { | 133 | } else if ( *it == "QCString" ) { |
140 | QCString cstr; | 134 | QCString cstr; |
141 | stream >> cstr; | 135 | stream >> cstr; |
142 | str = QString::fromLocal8Bit( cstr ); | 136 | str = QString::fromLocal8Bit( cstr ); |
143 | } else if ( *it == "int" ) { | 137 | } else if ( *it == "int" ) { |
144 | int i; | 138 | int i; |
145 | stream >> i; | 139 | stream >> i; |
146 | str = QString::number( i ); | 140 | str = QString::number( i ); |
147 | } else if ( *it == "bool" ) { | 141 | } else if ( *it == "bool" ) { |
148 | int i; | 142 | int i; |
149 | stream >> i; | 143 | stream >> i; |
150 | str = QString::number( i ); | 144 | str = QString::number( i ); |
151 | } else { | 145 | } else { |
152 | qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); | 146 | qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); |
153 | return; | 147 | return; |
154 | } | 148 | } |
155 | QString estr; | 149 | QString estr; |
156 | for (int i=0; i<(int)str.length(); i++) { | 150 | for (int i=0; i<(int)str.length(); i++) { |
157 | QChar ch = str[i]; | 151 | QChar ch = str[i]; |
158 | if ( ch.row() ) | 152 | if ( ch.row() ) |
159 | goto quick; | 153 | goto quick; |
160 | switch (ch.cell()) { | 154 | switch (ch.cell()) { |
161 | case '&': | 155 | case '&': |
162 | estr.append( "&" ); | 156 | estr.append( "&" ); |
163 | break; | 157 | break; |
164 | case ' ': | 158 | case ' ': |
165 | estr.append( "&0x20;" ); | 159 | estr.append( "&0x20;" ); |
166 | break; | 160 | break; |
167 | case '\n': | 161 | case '\n': |
168 | estr.append( "&0x0d;" ); | 162 | estr.append( "&0x0d;" ); |
169 | break; | 163 | break; |
170 | case '\r': | 164 | case '\r': |
171 | estr.append( "&0x0a;" ); | 165 | estr.append( "&0x0a;" ); |
172 | break; | 166 | break; |
173 | default: quick: | 167 | default: quick: |
174 | estr.append(ch); | 168 | estr.append(ch); |
175 | } | 169 | } |
176 | } | 170 | } |
177 | data += " " + estr; | 171 | data += " " + estr; |
178 | } | 172 | } |
179 | } | 173 | } |
180 | QString sendCommand = QString(command.data()) + data; | 174 | QString sendCommand = QString(command.data()) + data; |
181 | // send the command to all open connections | 175 | // send the command to all open connections |
182 | if ( command == "startSync()" ) { | 176 | if ( command == "startSync()" ) { |
183 | // we need to buffer it a bit | 177 | // we need to buffer it a bit |
184 | sendSync = TRUE; | 178 | sendSync = TRUE; |
185 | startTimer( 20000 ); | 179 | startTimer( 20000 ); |
186 | } | 180 | } |
187 | 181 | ||
188 | QCopBridgePI *pi; | 182 | QCopBridgePI *pi; |
189 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { | 183 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { |
190 | pi->sendDesktopMessage( sendCommand ); | 184 | pi->sendDesktopMessage( sendCommand ); |
191 | } | 185 | } |
192 | } | 186 | } |
193 | 187 | ||
194 | void QCopBridge::timerEvent( QTimerEvent * ) | 188 | void QCopBridge::timerEvent( QTimerEvent * ) |
195 | { | 189 | { |
196 | sendSync = FALSE; | 190 | sendSync = FALSE; |
197 | killTimers(); | 191 | killTimers(); |
198 | } | 192 | } |
199 | 193 | ||
200 | 194 | ||
201 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) | 195 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) |
202 | : QSocket( parent, name ) | 196 | : QSocket( parent, name ) |
203 | { | 197 | { |
204 | setSocket( socket ); | 198 | setSocket( socket ); |
205 | 199 | ||
206 | peerport = peerPort(); | 200 | peerport = peerPort(); |
207 | peeraddress = peerAddress(); | 201 | peeraddress = peerAddress(); |
208 | 202 | ||
209 | #ifndef INSECURE | 203 | #ifndef INSECURE |
210 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 204 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
211 | state = Forbidden; | 205 | state = Forbidden; |
212 | startTimer( 0 ); | 206 | startTimer( 0 ); |
213 | } else | 207 | } else |
214 | #endif | 208 | #endif |
215 | { | 209 | { |
216 | state = Connected; | 210 | state = Connected; |
217 | sendSync = FALSE; | 211 | sendSync = FALSE; |
218 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 212 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
219 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 213 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
220 | 214 | ||
221 | QString intro="220 Qtopia "; | 215 | QString intro="220 Qtopia "; |
222 | intro += QPE_VERSION; intro += ";"; | 216 | intro += QPE_VERSION; intro += ";"; |
223 | intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; | 217 | intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; |
224 | intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; | 218 | intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; |
225 | intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; | 219 | intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; |
226 | send( intro ); | 220 | send( intro ); |
227 | state = Wait_USER; | 221 | state = Wait_USER; |
228 | 222 | ||
229 | // idle timer to close connections when not used anymore | 223 | // idle timer to close connections when not used anymore |
230 | startTimer( 60000 ); | 224 | startTimer( 60000 ); |
231 | connected = TRUE; | 225 | connected = TRUE; |
232 | } | 226 | } |
233 | } | 227 | } |
234 | 228 | ||
235 | 229 | ||
236 | QCopBridgePI::~QCopBridgePI() | 230 | QCopBridgePI::~QCopBridgePI() |
237 | { | 231 | { |
238 | 232 | ||
239 | } | 233 | } |
240 | 234 | ||
241 | void QCopBridgePI::connectionClosed() | 235 | void QCopBridgePI::connectionClosed() |
242 | { | 236 | { |
243 | emit connectionClosed( this ); | 237 | emit connectionClosed( this ); |
244 | // qDebug( "Debug: Connection closed" ); | 238 | // qDebug( "Debug: Connection closed" ); |
245 | delete this; | 239 | delete this; |
246 | } | 240 | } |
247 | 241 | ||
248 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) | 242 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) |
249 | { | 243 | { |
250 | QString str = "CALL QPE/Desktop " + msg; | 244 | QString str = "CALL QPE/Desktop " + msg; |
251 | send ( str ); | 245 | send ( str ); |
252 | } | 246 | } |
253 | 247 | ||
254 | 248 | ||
255 | void QCopBridgePI::send( const QString& msg ) | 249 | void QCopBridgePI::send( const QString& msg ) |
256 | { | 250 | { |
257 | QTextStream os( this ); | 251 | QTextStream os( this ); |
258 | os << msg << endl; | 252 | os << msg << endl; |
259 | //qDebug( "sending qcop message: %s", msg.latin1() ); | 253 | //qDebug( "sending qcop message: %s", msg.latin1() ); |
260 | } | 254 | } |
261 | 255 | ||
262 | void QCopBridgePI::read() | 256 | void QCopBridgePI::read() |
263 | { | 257 | { |
264 | while ( canReadLine() ) | 258 | while ( canReadLine() ) |
265 | process( readLine().stripWhiteSpace() ); | 259 | process( readLine().stripWhiteSpace() ); |
266 | } | 260 | } |
267 | 261 | ||
268 | void QCopBridgePI::process( const QString& message ) | 262 | void QCopBridgePI::process( const QString& message ) |
269 | { | 263 | { |
270 | //qDebug( "Command: %s", message.latin1() ); | 264 | //qDebug( "Command: %s", message.latin1() ); |
271 | 265 | ||
272 | // split message using "," as separator | 266 | // split message using "," as separator |
273 | QStringList msg = QStringList::split( " ", message ); | 267 | QStringList msg = QStringList::split( " ", message ); |
274 | if ( msg.isEmpty() ) return; | 268 | if ( msg.isEmpty() ) return; |
275 | 269 | ||
276 | // command token | 270 | // command token |
277 | QString cmd = msg[0].upper(); | 271 | QString cmd = msg[0].upper(); |
278 | 272 | ||
279 | // argument token | 273 | // argument token |
280 | QString arg; | 274 | QString arg; |
281 | if ( msg.count() >= 2 ) | 275 | if ( msg.count() >= 2 ) |
282 | arg = msg[1]; | 276 | arg = msg[1]; |
283 | 277 | ||
284 | // we always respond to QUIT, regardless of state | 278 | // we always respond to QUIT, regardless of state |
285 | if ( cmd == "QUIT" ) { | 279 | if ( cmd == "QUIT" ) { |
286 | send( "211 Have a nice day!" ); | 280 | send( "211 Have a nice day!" ); |
287 | delete this; | 281 | delete this; |
288 | return; | 282 | return; |
289 | } | 283 | } |
290 | 284 | ||
291 | // connected to client | 285 | // connected to client |
292 | if ( Connected == state ) | 286 | if ( Connected == state ) |
293 | return; | 287 | return; |
294 | 288 | ||
295 | // waiting for user name | 289 | // waiting for user name |
296 | if ( Wait_USER == state ) { | 290 | if ( Wait_USER == state ) { |
297 | 291 | ||
298 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 292 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
299 | send( "530 Please login with USER and PASS" ); | 293 | send( "530 Please login with USER and PASS" ); |
300 | return; | 294 | return; |
301 | } | 295 | } |
302 | send( "331 User name ok, need password" ); | 296 | send( "331 User name ok, need password" ); |
303 | state = Wait_PASS; | 297 | state = Wait_PASS; |
304 | return; | 298 | return; |
305 | } | 299 | } |
306 | 300 | ||
307 | // waiting for password | 301 | // waiting for password |
308 | if ( Wait_PASS == state ) { | 302 | if ( Wait_PASS == state ) { |
309 | 303 | ||
310 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 304 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
311 | send( "530 Please login with USER and PASS" ); | 305 | send( "530 Please login with USER and PASS" ); |
312 | return; | 306 | return; |
313 | } | 307 | } |
314 | send( "230 User logged in, proceed" ); | 308 | send( "230 User logged in, proceed" ); |
315 | state = Ready; | 309 | state = Ready; |
316 | if ( sendSync ) { | 310 | if ( sendSync ) { |
317 | sendDesktopMessage( "startSync()" ); | 311 | sendDesktopMessage( "startSync()" ); |
318 | sendSync = FALSE; | 312 | sendSync = FALSE; |
319 | } | 313 | } |
320 | return; | 314 | return; |
321 | } | 315 | } |
322 | 316 | ||
323 | // noop (NOOP) | 317 | // noop (NOOP) |
324 | else if ( cmd == "NOOP" ) { | 318 | else if ( cmd == "NOOP" ) { |
325 | connected = TRUE; | 319 | connected = TRUE; |
326 | send( "200 Command okay" ); | 320 | send( "200 Command okay" ); |
327 | } | 321 | } |
328 | 322 | ||
329 | // call (CALL) | 323 | // call (CALL) |
330 | else if ( cmd == "CALL" ) { | 324 | else if ( cmd == "CALL" ) { |
331 | 325 | ||
332 | // example: call QPE/System execute(QString) addressbook | 326 | // example: call QPE/System execute(QString) addressbook |
333 | 327 | ||
334 | if ( msg.count() < 3 ) { | 328 | if ( msg.count() < 3 ) { |
335 | send( "500 Syntax error, command unrecognized" ); | 329 | send( "500 Syntax error, command unrecognized" ); |
336 | } | 330 | } |
337 | else { | 331 | else { |
338 | 332 | ||
339 | QString channel = msg[1]; | 333 | QString channel = msg[1]; |
340 | QString command = msg[2]; | 334 | QString command = msg[2]; |
341 | 335 | ||
342 | command.stripWhiteSpace(); | 336 | command.stripWhiteSpace(); |
343 | 337 | ||
344 | int paren = command.find( "(" ); | 338 | int paren = command.find( "(" ); |
345 | if ( paren <= 0 ) { | 339 | if ( paren <= 0 ) { |
346 | send( "500 Syntax error, command unrecognized" ); | 340 | send( "500 Syntax error, command unrecognized" ); |
347 | return; | 341 | return; |
348 | } | 342 | } |
349 | 343 | ||
350 | QString params = command.mid( paren + 1 ); | 344 | QString params = command.mid( paren + 1 ); |
351 | if ( params[params.length()-1] != ')' ) { | 345 | if ( params[params.length()-1] != ')' ) { |
352 | send( "500 Syntax error, command unrecognized" ); | 346 | send( "500 Syntax error, command unrecognized" ); |
353 | return; | 347 | return; |
354 | } | 348 | } |
355 | 349 | ||
356 | params.truncate( params.length()-1 ); | 350 | params.truncate( params.length()-1 ); |
357 | QByteArray buffer; | 351 | QByteArray buffer; |
358 | QDataStream ds( buffer, IO_WriteOnly ); | 352 | QDataStream ds( buffer, IO_WriteOnly ); |
359 | 353 | ||
360 | int msgId = 3; | 354 | int msgId = 3; |
361 | 355 | ||
362 | QStringList paramList = QStringList::split( ",", params ); | 356 | QStringList paramList = QStringList::split( ",", params ); |
363 | if ( paramList.count() > msg.count() - 3 ) { | 357 | if ( paramList.count() > msg.count() - 3 ) { |
364 | send( "500 Syntax error, command unrecognized" ); | 358 | send( "500 Syntax error, command unrecognized" ); |
365 | return; | 359 | return; |
366 | } | 360 | } |
367 | 361 | ||
368 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { | 362 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { |
369 | 363 | ||
370 | QString arg = msg[msgId]; | 364 | QString arg = msg[msgId]; |
371 | arg.replace( QRegExp("&0x20;"), " " ); | 365 | arg.replace( QRegExp("&0x20;"), " " ); |
372 | arg.replace( QRegExp("&"), "&" ); | 366 | arg.replace( QRegExp("&"), "&" ); |
373 | arg.replace( QRegExp("&0x0d;"), "\n" ); | 367 | arg.replace( QRegExp("&0x0d;"), "\n" ); |
374 | arg.replace( QRegExp("&0x0a;"), "\r" ); | 368 | arg.replace( QRegExp("&0x0a;"), "\r" ); |
375 | if ( *it == "QString" ) | 369 | if ( *it == "QString" ) |
376 | ds << arg; | 370 | ds << arg; |
377 | else if ( *it == "QCString" ) | 371 | else if ( *it == "QCString" ) |
378 | ds << arg.local8Bit(); | 372 | ds << arg.local8Bit(); |
379 | else if ( *it == "int" ) | 373 | else if ( *it == "int" ) |
380 | ds << arg.toInt(); | 374 | ds << arg.toInt(); |
381 | else if ( *it == "bool" ) | 375 | else if ( *it == "bool" ) |
382 | ds << arg.toInt(); | 376 | ds << arg.toInt(); |
383 | else { | 377 | else { |
384 | send( "500 Syntax error, command unrecognized" ); | 378 | send( "500 Syntax error, command unrecognized" ); |
385 | return; | 379 | return; |
386 | } | 380 | } |
387 | msgId++; | 381 | msgId++; |
388 | } | 382 | } |
389 | 383 | ||
390 | #ifndef QT_NO_COP | 384 | #ifndef QT_NO_COP |
391 | if ( !QCopChannel::isRegistered( channel.latin1() ) ) { | 385 | if ( !QCopChannel::isRegistered( channel.latin1() ) ) { |
392 | // send message back about it | 386 | // send message back about it |
393 | QString answer = "599 ChannelNotRegistered " + channel; | 387 | QString answer = "599 ChannelNotRegistered " + channel; |
394 | send( answer ); | 388 | send( answer ); |
395 | return; | 389 | return; |
396 | } | 390 | } |
397 | #endif | 391 | #endif |
398 | 392 | ||
399 | #ifndef QT_NO_COP | 393 | #ifndef QT_NO_COP |
400 | if ( paramList.count() ) | 394 | if ( paramList.count() ) |
401 | QCopChannel::send( channel.latin1(), command.latin1(), buffer ); | 395 | QCopChannel::send( channel.latin1(), command.latin1(), buffer ); |
402 | else | 396 | else |
403 | QCopChannel::send( channel.latin1(), command.latin1() ); | 397 | QCopChannel::send( channel.latin1(), command.latin1() ); |
404 | 398 | ||
405 | send( "200 Command okay" ); | 399 | send( "200 Command okay" ); |
406 | #endif | 400 | #endif |
407 | } | 401 | } |
408 | } | 402 | } |
409 | // not implemented | 403 | // not implemented |
410 | else | 404 | else |
411 | send( "502 Command not implemented" ); | 405 | send( "502 Command not implemented" ); |
412 | } | 406 | } |
413 | 407 | ||
414 | 408 | ||
415 | 409 | ||
416 | void QCopBridgePI::timerEvent( QTimerEvent * ) | 410 | void QCopBridgePI::timerEvent( QTimerEvent * ) |
417 | { | 411 | { |
418 | if ( connected ) | 412 | if ( connected ) |
419 | connected = FALSE; | 413 | connected = FALSE; |
420 | else | 414 | else |
421 | connectionClosed(); | 415 | connectionClosed(); |
422 | } | 416 | } |
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp index 239c824..30bf438 100644 --- a/core/qws/transferserver.cpp +++ b/core/qws/transferserver.cpp | |||
@@ -1,1443 +1,1435 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the 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 | #include <time.h> | 25 | #include <time.h> |
26 | 26 | ||
27 | #ifndef Q_OS_MACX | 27 | #ifndef Q_OS_MACX |
28 | #include <shadow.h> | 28 | #include <shadow.h> |
29 | #endif /* Q_OS_MACX */ | 29 | #endif /* Q_OS_MACX */ |
30 | 30 | ||
31 | /* we need the _OS_LINUX stuff first ! */ | 31 | /* we need the _OS_LINUX stuff first ! */ |
32 | #include <qglobal.h> | ||
33 | 32 | ||
34 | #ifndef _OS_LINUX_ | 33 | #ifndef _OS_LINUX_ |
35 | // Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found | 34 | // Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found |
36 | // anywhere ? Therfore I removed it completely.. | 35 | // anywhere ? Therfore I removed it completely.. |
37 | // I think it should be made permanentyl !? (eilers) | 36 | // I think it should be made permanentyl !? (eilers) |
38 | #warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)" | 37 | #warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)" |
39 | #if 0 | 38 | #if 0 |
40 | 39 | ||
41 | extern "C" | 40 | extern "C" |
42 | { | 41 | { |
43 | #include <uuid/uuid.h> | 42 | #include <uuid/uuid.h> |
44 | #define UUID_H_INCLUDED | 43 | #define UUID_H_INCLUDED |
45 | } | 44 | } |
46 | 45 | ||
47 | #endif | 46 | #endif |
48 | 47 | ||
49 | #endif // not defined linux | 48 | #endif // not defined linux |
50 | 49 | ||
51 | #if defined(_OS_LINUX_) | 50 | #if defined(_OS_LINUX_) |
52 | #include <shadow.h> | 51 | #include <shadow.h> |
53 | #elif defined(Q_OS_MACX) | 52 | #elif defined(Q_OS_MACX) |
54 | #include <stdlib.h> | 53 | #include <stdlib.h> |
55 | #endif | 54 | #endif |
56 | 55 | ||
57 | #include <qdir.h> | ||
58 | #include <qfile.h> | ||
59 | #include <qtextstream.h> | 56 | #include <qtextstream.h> |
60 | #include <qdatastream.h> | ||
61 | #include <qmessagebox.h> | 57 | #include <qmessagebox.h> |
62 | #include <qstringlist.h> | ||
63 | #include <qfileinfo.h> | ||
64 | #include <qregexp.h> | ||
65 | //#include <qpe/qcopchannel_qws.h> | 58 | //#include <qpe/qcopchannel_qws.h> |
66 | #include <qpe/process.h> | 59 | #include <qpe/process.h> |
67 | #include <qpe/global.h> | 60 | #include <qpe/global.h> |
68 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
69 | #include <qpe/contact.h> | 62 | #include <qpe/contact.h> |
70 | #include <qpe/quuid.h> | ||
71 | #include <qpe/version.h> | 63 | #include <qpe/version.h> |
72 | #include <qpe/qcopenvelope_qws.h> | 64 | #include <qpe/qcopenvelope_qws.h> |
73 | 65 | ||
74 | #include "transferserver.h" | 66 | #include "transferserver.h" |
75 | #include <opie/oprocess.h> | 67 | #include <opie/oprocess.h> |
76 | 68 | ||
77 | const int block_size = 51200; | 69 | const int block_size = 51200; |
78 | 70 | ||
79 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | 71 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , |
80 | const char* name ) | 72 | const char* name ) |
81 | : QServerSocket( port, 1, parent, name ) | 73 | : QServerSocket( port, 1, parent, name ) |
82 | { | 74 | { |
83 | if ( !ok() ) | 75 | if ( !ok() ) |
84 | qWarning( "Failed to bind to port %d", port ); | 76 | qWarning( "Failed to bind to port %d", port ); |
85 | } | 77 | } |
86 | 78 | ||
87 | TransferServer::~TransferServer() | 79 | TransferServer::~TransferServer() |
88 | { | 80 | { |
89 | } | 81 | } |
90 | 82 | ||
91 | void TransferServer::newConnection( int socket ) | 83 | void TransferServer::newConnection( int socket ) |
92 | { | 84 | { |
93 | (void) new ServerPI( socket, this ); | 85 | (void) new ServerPI( socket, this ); |
94 | } | 86 | } |
95 | 87 | ||
96 | /* | 88 | /* |
97 | * small class in anonymous namespace | 89 | * small class in anonymous namespace |
98 | * to generate a QUUid for us | 90 | * to generate a QUUid for us |
99 | */ | 91 | */ |
100 | namespace | 92 | namespace |
101 | { | 93 | { |
102 | struct UidGen | 94 | struct UidGen |
103 | { | 95 | { |
104 | QString uuid(); | 96 | QString uuid(); |
105 | }; | 97 | }; |
106 | #if defined(Q_OS_MACX) | 98 | #if defined(Q_OS_MACX) |
107 | QString UidGen::uuid() | 99 | QString UidGen::uuid() |
108 | { | 100 | { |
109 | srandom( random() ); | 101 | srandom( random() ); |
110 | QString numStr = QString::number( random() ); | 102 | QString numStr = QString::number( random() ); |
111 | 103 | ||
112 | return "{" + numStr + "}"; | 104 | return "{" + numStr + "}"; |
113 | } | 105 | } |
114 | #elif defined(_OS_LINUX_) | 106 | #elif defined(_OS_LINUX_) |
115 | /* | 107 | /* |
116 | * linux got a /proc/sys/kernel/random/uuid file | 108 | * linux got a /proc/sys/kernel/random/uuid file |
117 | * it'll generate the uuids for us | 109 | * it'll generate the uuids for us |
118 | */ | 110 | */ |
119 | QString UidGen::uuid() | 111 | QString UidGen::uuid() |
120 | { | 112 | { |
121 | QFile file( "/proc/sys/kernel/random/uuid" ); | 113 | QFile file( "/proc/sys/kernel/random/uuid" ); |
122 | if (!file.open(IO_ReadOnly ) ) | 114 | if (!file.open(IO_ReadOnly ) ) |
123 | return QString::null; | 115 | return QString::null; |
124 | 116 | ||
125 | QTextStream stream(&file); | 117 | QTextStream stream(&file); |
126 | 118 | ||
127 | return "{" + stream.read().stripWhiteSpace() + "}"; | 119 | return "{" + stream.read().stripWhiteSpace() + "}"; |
128 | } | 120 | } |
129 | #else | 121 | #else |
130 | QString UidGen::uuid() | 122 | QString UidGen::uuid() |
131 | { | 123 | { |
132 | uuid_t uuid; | 124 | uuid_t uuid; |
133 | ::uuid_generate( uuid ); | 125 | ::uuid_generate( uuid ); |
134 | return QUUid( uuid ).toString(); | 126 | return QUUid( uuid ).toString(); |
135 | } | 127 | } |
136 | #endif | 128 | #endif |
137 | } | 129 | } |
138 | 130 | ||
139 | QString SyncAuthentication::serverId() | 131 | QString SyncAuthentication::serverId() |
140 | { | 132 | { |
141 | Config cfg("Security"); | 133 | Config cfg("Security"); |
142 | cfg.setGroup("Sync"); | 134 | cfg.setGroup("Sync"); |
143 | QString r = cfg.readEntry("serverid"); | 135 | QString r = cfg.readEntry("serverid"); |
144 | if ( r.isEmpty() ) { | 136 | if ( r.isEmpty() ) { |
145 | UidGen gen; | 137 | UidGen gen; |
146 | r = gen.uuid(); | 138 | r = gen.uuid(); |
147 | cfg.writeEntry("serverid", r ); | 139 | cfg.writeEntry("serverid", r ); |
148 | } | 140 | } |
149 | return r; | 141 | return r; |
150 | } | 142 | } |
151 | 143 | ||
152 | QString SyncAuthentication::ownerName() | 144 | QString SyncAuthentication::ownerName() |
153 | { | 145 | { |
154 | QString vfilename = Global::applicationFileName("addressbook", | 146 | QString vfilename = Global::applicationFileName("addressbook", |
155 | "businesscard.vcf"); | 147 | "businesscard.vcf"); |
156 | if (QFile::exists(vfilename)) { | 148 | if (QFile::exists(vfilename)) { |
157 | Contact c; | 149 | Contact c; |
158 | c = Contact::readVCard( vfilename )[0]; | 150 | c = Contact::readVCard( vfilename )[0]; |
159 | return c.fullName(); | 151 | return c.fullName(); |
160 | } | 152 | } |
161 | 153 | ||
162 | return ""; | 154 | return ""; |
163 | } | 155 | } |
164 | 156 | ||
165 | QString SyncAuthentication::loginName() | 157 | QString SyncAuthentication::loginName() |
166 | { | 158 | { |
167 | struct passwd *pw; | 159 | struct passwd *pw; |
168 | pw = getpwuid( geteuid() ); | 160 | pw = getpwuid( geteuid() ); |
169 | return QString::fromLocal8Bit( pw->pw_name ); | 161 | return QString::fromLocal8Bit( pw->pw_name ); |
170 | } | 162 | } |
171 | 163 | ||
172 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | 164 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) |
173 | { | 165 | { |
174 | Config cfg("Security"); | 166 | Config cfg("Security"); |
175 | cfg.setGroup("Sync"); | 167 | cfg.setGroup("Sync"); |
176 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 168 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
177 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); | 169 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); |
178 | 170 | ||
179 | // QHostAddress allowed; | 171 | // QHostAddress allowed; |
180 | // allowed.setAddress(allowedstr); | 172 | // allowed.setAddress(allowedstr); |
181 | // uint auth_peer = allowed.ip4Addr(); | 173 | // uint auth_peer = allowed.ip4Addr(); |
182 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); | 174 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); |
183 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 175 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
184 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); | 176 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); |
185 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 177 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
186 | } | 178 | } |
187 | 179 | ||
188 | bool SyncAuthentication::checkUser( const QString& user ) | 180 | bool SyncAuthentication::checkUser( const QString& user ) |
189 | { | 181 | { |
190 | if ( user.isEmpty() ) | 182 | if ( user.isEmpty() ) |
191 | return FALSE; | 183 | return FALSE; |
192 | QString euser = loginName(); | 184 | QString euser = loginName(); |
193 | return user == euser; | 185 | return user == euser; |
194 | } | 186 | } |
195 | 187 | ||
196 | bool SyncAuthentication::checkPassword( const QString& password ) | 188 | bool SyncAuthentication::checkPassword( const QString& password ) |
197 | { | 189 | { |
198 | #ifdef ALLOW_UNIX_USER_FTP | 190 | #ifdef ALLOW_UNIX_USER_FTP |
199 | // First, check system password... | 191 | // First, check system password... |
200 | 192 | ||
201 | struct passwd *pw = 0; | 193 | struct passwd *pw = 0; |
202 | struct spwd *spw = 0; | 194 | struct spwd *spw = 0; |
203 | 195 | ||
204 | pw = getpwuid( geteuid() ); | 196 | pw = getpwuid( geteuid() ); |
205 | spw = getspnam( pw->pw_name ); | 197 | spw = getspnam( pw->pw_name ); |
206 | 198 | ||
207 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 199 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
208 | if ( cpwd == "x" && spw ) | 200 | if ( cpwd == "x" && spw ) |
209 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 201 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
210 | 202 | ||
211 | // Note: some systems use more than crypt for passwords. | 203 | // Note: some systems use more than crypt for passwords. |
212 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 204 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
213 | if ( cpwd == cpassword ) | 205 | if ( cpwd == cpassword ) |
214 | return TRUE; | 206 | return TRUE; |
215 | #endif | 207 | #endif |
216 | 208 | ||
217 | static int lastdenial = 0; | 209 | static int lastdenial = 0; |
218 | static int denials = 0; | 210 | static int denials = 0; |
219 | int now = time(0); | 211 | int now = time(0); |
220 | 212 | ||
221 | // Detect old Qtopia Desktop (no password) | 213 | // Detect old Qtopia Desktop (no password) |
222 | if ( password.isEmpty() ) { | 214 | if ( password.isEmpty() ) { |
223 | if ( denials < 1 || now > lastdenial + 600 ) { | 215 | if ( denials < 1 || now > lastdenial + 600 ) { |
224 | QMessageBox::warning( 0, tr("Sync Connection"), | 216 | QMessageBox::warning( 0, tr("Sync Connection"), |
225 | tr("<p>An unauthorized system is requesting access to this device." | 217 | tr("<p>An unauthorized system is requesting access to this device." |
226 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 218 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
227 | "please upgrade."), | 219 | "please upgrade."), |
228 | tr("Deny") ); | 220 | tr("Deny") ); |
229 | denials++; | 221 | denials++; |
230 | lastdenial = now; | 222 | lastdenial = now; |
231 | } | 223 | } |
232 | return FALSE; | 224 | return FALSE; |
233 | } | 225 | } |
234 | 226 | ||
235 | // Second, check sync password... | 227 | // Second, check sync password... |
236 | QString pass = password.left(6); | 228 | QString pass = password.left(6); |
237 | /* old QtopiaDesktops are sending | 229 | /* old QtopiaDesktops are sending |
238 | * rootme newer versions got a Qtopia | 230 | * rootme newer versions got a Qtopia |
239 | * prefixed. Qtopia prefix will suceed | 231 | * prefixed. Qtopia prefix will suceed |
240 | * until the sync software syncs up | 232 | * until the sync software syncs up |
241 | * FIXME | 233 | * FIXME |
242 | */ | 234 | */ |
243 | if ( pass == "rootme" || pass == "Qtopia") { | 235 | if ( pass == "rootme" || pass == "Qtopia") { |
244 | 236 | ||
245 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); | 237 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); |
246 | Config cfg("Security"); | 238 | Config cfg("Security"); |
247 | cfg.setGroup("Sync"); | 239 | cfg.setGroup("Sync"); |
248 | QString pwds = cfg.readEntry("Passwords"); | 240 | QString pwds = cfg.readEntry("Passwords"); |
249 | if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) | 241 | if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) |
250 | return TRUE; | 242 | return TRUE; |
251 | 243 | ||
252 | // Unrecognized system. Be careful... | 244 | // Unrecognized system. Be careful... |
253 | 245 | ||
254 | if ( (denials > 2 && now < lastdenial + 600) | 246 | if ( (denials > 2 && now < lastdenial + 600) |
255 | || QMessageBox::warning(0, tr("Sync Connection"), | 247 | || QMessageBox::warning(0, tr("Sync Connection"), |
256 | tr("<p>An unrecognized system is requesting access to this device." | 248 | tr("<p>An unrecognized system is requesting access to this device." |
257 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 249 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
258 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { | 250 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { |
259 | denials++; | 251 | denials++; |
260 | lastdenial = now; | 252 | lastdenial = now; |
261 | return FALSE; | 253 | return FALSE; |
262 | } | 254 | } |
263 | else { | 255 | else { |
264 | denials = 0; | 256 | denials = 0; |
265 | cfg.writeEntry("Passwords", pwds + " " + cpassword); | 257 | cfg.writeEntry("Passwords", pwds + " " + cpassword); |
266 | return TRUE; | 258 | return TRUE; |
267 | } | 259 | } |
268 | } | 260 | } |
269 | 261 | ||
270 | return FALSE; | 262 | return FALSE; |
271 | } | 263 | } |
272 | 264 | ||
273 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | 265 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) |
274 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 266 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
275 | { | 267 | { |
276 | state = Connected; | 268 | state = Connected; |
277 | 269 | ||
278 | setSocket( socket ); | 270 | setSocket( socket ); |
279 | 271 | ||
280 | peerport = peerPort(); | 272 | peerport = peerPort(); |
281 | peeraddress = peerAddress(); | 273 | peeraddress = peerAddress(); |
282 | 274 | ||
283 | #ifndef INSECURE | 275 | #ifndef INSECURE |
284 | 276 | ||
285 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 277 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
286 | state = Forbidden; | 278 | state = Forbidden; |
287 | startTimer( 0 ); | 279 | startTimer( 0 ); |
288 | } | 280 | } |
289 | else | 281 | else |
290 | #endif | 282 | #endif |
291 | { | 283 | { |
292 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 284 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
293 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 285 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
294 | 286 | ||
295 | passiv = FALSE; | 287 | passiv = FALSE; |
296 | for ( int i = 0; i < 4; i++ ) | 288 | for ( int i = 0; i < 4; i++ ) |
297 | wait[i] = FALSE; | 289 | wait[i] = FALSE; |
298 | 290 | ||
299 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); | 291 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); |
300 | state = Wait_USER; | 292 | state = Wait_USER; |
301 | 293 | ||
302 | dtp = new ServerDTP( this ); | 294 | dtp = new ServerDTP( this ); |
303 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 295 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
304 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 296 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
305 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 297 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); |
306 | 298 | ||
307 | 299 | ||
308 | directory = QDir::currentDirPath(); | 300 | directory = QDir::currentDirPath(); |
309 | 301 | ||
310 | static int p = 1024; | 302 | static int p = 1024; |
311 | 303 | ||
312 | while ( !serversocket || !serversocket->ok() ) { | 304 | while ( !serversocket || !serversocket->ok() ) { |
313 | delete serversocket; | 305 | delete serversocket; |
314 | serversocket = new ServerSocket( ++p, this ); | 306 | serversocket = new ServerSocket( ++p, this ); |
315 | } | 307 | } |
316 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 308 | connect( serversocket, SIGNAL( newIncomming( int ) ), |
317 | SLOT( newConnection( int ) ) ); | 309 | SLOT( newConnection( int ) ) ); |
318 | } | 310 | } |
319 | } | 311 | } |
320 | 312 | ||
321 | ServerPI::~ServerPI() | 313 | ServerPI::~ServerPI() |
322 | { | 314 | { |
323 | } | 315 | } |
324 | 316 | ||
325 | void ServerPI::connectionClosed() | 317 | void ServerPI::connectionClosed() |
326 | { | 318 | { |
327 | // qDebug( "Debug: Connection closed" ); | 319 | // qDebug( "Debug: Connection closed" ); |
328 | delete this; | 320 | delete this; |
329 | } | 321 | } |
330 | 322 | ||
331 | void ServerPI::send( const QString& msg ) | 323 | void ServerPI::send( const QString& msg ) |
332 | { | 324 | { |
333 | QTextStream os( this ); | 325 | QTextStream os( this ); |
334 | os << msg << endl; | 326 | os << msg << endl; |
335 | //qDebug( "Reply: %s", msg.latin1() ); | 327 | //qDebug( "Reply: %s", msg.latin1() ); |
336 | } | 328 | } |
337 | 329 | ||
338 | void ServerPI::read() | 330 | void ServerPI::read() |
339 | { | 331 | { |
340 | while ( canReadLine() ) | 332 | while ( canReadLine() ) |
341 | process( readLine().stripWhiteSpace() ); | 333 | process( readLine().stripWhiteSpace() ); |
342 | } | 334 | } |
343 | 335 | ||
344 | bool ServerPI::checkReadFile( const QString& file ) | 336 | bool ServerPI::checkReadFile( const QString& file ) |
345 | { | 337 | { |
346 | QString filename; | 338 | QString filename; |
347 | 339 | ||
348 | if ( file[0] != "/" ) | 340 | if ( file[0] != "/" ) |
349 | filename = directory.path() + "/" + file; | 341 | filename = directory.path() + "/" + file; |
350 | else | 342 | else |
351 | filename = file; | 343 | filename = file; |
352 | 344 | ||
353 | QFileInfo fi( filename ); | 345 | QFileInfo fi( filename ); |
354 | return ( fi.exists() && fi.isReadable() ); | 346 | return ( fi.exists() && fi.isReadable() ); |
355 | } | 347 | } |
356 | 348 | ||
357 | bool ServerPI::checkWriteFile( const QString& file ) | 349 | bool ServerPI::checkWriteFile( const QString& file ) |
358 | { | 350 | { |
359 | QString filename; | 351 | QString filename; |
360 | 352 | ||
361 | if ( file[0] != "/" ) | 353 | if ( file[0] != "/" ) |
362 | filename = directory.path() + "/" + file; | 354 | filename = directory.path() + "/" + file; |
363 | else | 355 | else |
364 | filename = file; | 356 | filename = file; |
365 | 357 | ||
366 | QFileInfo fi( filename ); | 358 | QFileInfo fi( filename ); |
367 | 359 | ||
368 | if ( fi.exists() ) | 360 | if ( fi.exists() ) |
369 | if ( !QFile( filename ).remove() ) | 361 | if ( !QFile( filename ).remove() ) |
370 | return FALSE; | 362 | return FALSE; |
371 | return TRUE; | 363 | return TRUE; |
372 | } | 364 | } |
373 | 365 | ||
374 | void ServerPI::process( const QString& message ) | 366 | void ServerPI::process( const QString& message ) |
375 | { | 367 | { |
376 | //qDebug( "Command: %s", message.latin1() ); | 368 | //qDebug( "Command: %s", message.latin1() ); |
377 | 369 | ||
378 | // split message using "," as separator | 370 | // split message using "," as separator |
379 | QStringList msg = QStringList::split( " ", message ); | 371 | QStringList msg = QStringList::split( " ", message ); |
380 | if ( msg.isEmpty() ) | 372 | if ( msg.isEmpty() ) |
381 | return ; | 373 | return ; |
382 | 374 | ||
383 | // command token | 375 | // command token |
384 | QString cmd = msg[0].upper(); | 376 | QString cmd = msg[0].upper(); |
385 | 377 | ||
386 | // argument token | 378 | // argument token |
387 | QString arg; | 379 | QString arg; |
388 | if ( msg.count() >= 2 ) | 380 | if ( msg.count() >= 2 ) |
389 | arg = msg[1]; | 381 | arg = msg[1]; |
390 | 382 | ||
391 | // full argument string | 383 | // full argument string |
392 | QString args; | 384 | QString args; |
393 | if ( msg.count() >= 2 ) { | 385 | if ( msg.count() >= 2 ) { |
394 | QStringList copy( msg ); | 386 | QStringList copy( msg ); |
395 | // FIXME: for Qt3 | 387 | // FIXME: for Qt3 |
396 | // copy.pop_front() | 388 | // copy.pop_front() |
397 | copy.remove( copy.begin() ); | 389 | copy.remove( copy.begin() ); |
398 | args = copy.join( " " ); | 390 | args = copy.join( " " ); |
399 | } | 391 | } |
400 | 392 | ||
401 | //qDebug( "args: %s", args.latin1() ); | 393 | //qDebug( "args: %s", args.latin1() ); |
402 | 394 | ||
403 | // we always respond to QUIT, regardless of state | 395 | // we always respond to QUIT, regardless of state |
404 | if ( cmd == "QUIT" ) { | 396 | if ( cmd == "QUIT" ) { |
405 | send( "211 Good bye!" ); | 397 | send( "211 Good bye!" ); |
406 | delete this; | 398 | delete this; |
407 | return ; | 399 | return ; |
408 | } | 400 | } |
409 | 401 | ||
410 | // connected to client | 402 | // connected to client |
411 | if ( Connected == state ) | 403 | if ( Connected == state ) |
412 | return ; | 404 | return ; |
413 | 405 | ||
414 | // waiting for user name | 406 | // waiting for user name |
415 | if ( Wait_USER == state ) { | 407 | if ( Wait_USER == state ) { |
416 | 408 | ||
417 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 409 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
418 | send( "530 Please login with USER and PASS" ); | 410 | send( "530 Please login with USER and PASS" ); |
419 | return ; | 411 | return ; |
420 | } | 412 | } |
421 | send( "331 User name ok, need password" ); | 413 | send( "331 User name ok, need password" ); |
422 | state = Wait_PASS; | 414 | state = Wait_PASS; |
423 | return ; | 415 | return ; |
424 | } | 416 | } |
425 | 417 | ||
426 | // waiting for password | 418 | // waiting for password |
427 | if ( Wait_PASS == state ) { | 419 | if ( Wait_PASS == state ) { |
428 | 420 | ||
429 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 421 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
430 | send( "530 Please login with USER and PASS" ); | 422 | send( "530 Please login with USER and PASS" ); |
431 | return ; | 423 | return ; |
432 | } | 424 | } |
433 | send( "230 User logged in, proceed" ); | 425 | send( "230 User logged in, proceed" ); |
434 | state = Ready; | 426 | state = Ready; |
435 | return ; | 427 | return ; |
436 | } | 428 | } |
437 | 429 | ||
438 | // ACCESS CONTROL COMMANDS | 430 | // ACCESS CONTROL COMMANDS |
439 | 431 | ||
440 | 432 | ||
441 | // account (ACCT) | 433 | // account (ACCT) |
442 | if ( cmd == "ACCT" ) { | 434 | if ( cmd == "ACCT" ) { |
443 | // even wu-ftp does not support it | 435 | // even wu-ftp does not support it |
444 | send( "502 Command not implemented" ); | 436 | send( "502 Command not implemented" ); |
445 | } | 437 | } |
446 | 438 | ||
447 | // change working directory (CWD) | 439 | // change working directory (CWD) |
448 | else if ( cmd == "CWD" ) { | 440 | else if ( cmd == "CWD" ) { |
449 | 441 | ||
450 | if ( !args.isEmpty() ) { | 442 | if ( !args.isEmpty() ) { |
451 | if ( directory.cd( args, TRUE ) ) | 443 | if ( directory.cd( args, TRUE ) ) |
452 | send( "250 Requested file action okay, completed" ); | 444 | send( "250 Requested file action okay, completed" ); |
453 | else | 445 | else |
454 | send( "550 Requested action not taken" ); | 446 | send( "550 Requested action not taken" ); |
455 | } | 447 | } |
456 | else | 448 | else |
457 | send( "500 Syntax error, command unrecognized" ); | 449 | send( "500 Syntax error, command unrecognized" ); |
458 | } | 450 | } |
459 | 451 | ||
460 | // change to parent directory (CDUP) | 452 | // change to parent directory (CDUP) |
461 | else if ( cmd == "CDUP" ) { | 453 | else if ( cmd == "CDUP" ) { |
462 | if ( directory.cdUp() ) | 454 | if ( directory.cdUp() ) |
463 | send( "250 Requested file action okay, completed" ); | 455 | send( "250 Requested file action okay, completed" ); |
464 | else | 456 | else |
465 | send( "550 Requested action not taken" ); | 457 | send( "550 Requested action not taken" ); |
466 | } | 458 | } |
467 | 459 | ||
468 | // structure mount (SMNT) | 460 | // structure mount (SMNT) |
469 | else if ( cmd == "SMNT" ) { | 461 | else if ( cmd == "SMNT" ) { |
470 | // even wu-ftp does not support it | 462 | // even wu-ftp does not support it |
471 | send( "502 Command not implemented" ); | 463 | send( "502 Command not implemented" ); |
472 | } | 464 | } |
473 | 465 | ||
474 | // reinitialize (REIN) | 466 | // reinitialize (REIN) |
475 | else if ( cmd == "REIN" ) { | 467 | else if ( cmd == "REIN" ) { |
476 | // even wu-ftp does not support it | 468 | // even wu-ftp does not support it |
477 | send( "502 Command not implemented" ); | 469 | send( "502 Command not implemented" ); |
478 | } | 470 | } |
479 | 471 | ||
480 | 472 | ||
481 | // TRANSFER PARAMETER COMMANDS | 473 | // TRANSFER PARAMETER COMMANDS |
482 | 474 | ||
483 | 475 | ||
484 | // data port (PORT) | 476 | // data port (PORT) |
485 | else if ( cmd == "PORT" ) { | 477 | else if ( cmd == "PORT" ) { |
486 | if ( parsePort( arg ) ) | 478 | if ( parsePort( arg ) ) |
487 | send( "200 Command okay" ); | 479 | send( "200 Command okay" ); |
488 | else | 480 | else |
489 | send( "500 Syntax error, command unrecognized" ); | 481 | send( "500 Syntax error, command unrecognized" ); |
490 | } | 482 | } |
491 | 483 | ||
492 | // passive (PASV) | 484 | // passive (PASV) |
493 | else if ( cmd == "PASV" ) { | 485 | else if ( cmd == "PASV" ) { |
494 | passiv = TRUE; | 486 | passiv = TRUE; |
495 | send( "227 Entering Passive Mode (" | 487 | send( "227 Entering Passive Mode (" |
496 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," | 488 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," |
497 | + QString::number( ( serversocket->port() ) >> 8 ) + "," | 489 | + QString::number( ( serversocket->port() ) >> 8 ) + "," |
498 | + QString::number( ( serversocket->port() ) & 0xFF ) + ")" ); | 490 | + QString::number( ( serversocket->port() ) & 0xFF ) + ")" ); |
499 | } | 491 | } |
500 | 492 | ||
501 | // representation type (TYPE) | 493 | // representation type (TYPE) |
502 | else if ( cmd == "TYPE" ) { | 494 | else if ( cmd == "TYPE" ) { |
503 | if ( arg.upper() == "A" || arg.upper() == "I" ) | 495 | if ( arg.upper() == "A" || arg.upper() == "I" ) |
504 | send( "200 Command okay" ); | 496 | send( "200 Command okay" ); |
505 | else | 497 | else |
506 | send( "504 Command not implemented for that parameter" ); | 498 | send( "504 Command not implemented for that parameter" ); |
507 | } | 499 | } |
508 | 500 | ||
509 | // file structure (STRU) | 501 | // file structure (STRU) |
510 | else if ( cmd == "STRU" ) { | 502 | else if ( cmd == "STRU" ) { |
511 | if ( arg.upper() == "F" ) | 503 | if ( arg.upper() == "F" ) |
512 | send( "200 Command okay" ); | 504 | send( "200 Command okay" ); |
513 | else | 505 | else |
514 | send( "504 Command not implemented for that parameter" ); | 506 | send( "504 Command not implemented for that parameter" ); |
515 | } | 507 | } |
516 | 508 | ||
517 | // transfer mode (MODE) | 509 | // transfer mode (MODE) |
518 | else if ( cmd == "MODE" ) { | 510 | else if ( cmd == "MODE" ) { |
519 | if ( arg.upper() == "S" ) | 511 | if ( arg.upper() == "S" ) |
520 | send( "200 Command okay" ); | 512 | send( "200 Command okay" ); |
521 | else | 513 | else |
522 | send( "504 Command not implemented for that parameter" ); | 514 | send( "504 Command not implemented for that parameter" ); |
523 | } | 515 | } |
524 | 516 | ||
525 | 517 | ||
526 | // FTP SERVICE COMMANDS | 518 | // FTP SERVICE COMMANDS |
527 | 519 | ||
528 | 520 | ||
529 | // retrieve (RETR) | 521 | // retrieve (RETR) |
530 | else if ( cmd == "RETR" ) | 522 | else if ( cmd == "RETR" ) |
531 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) | 523 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) |
532 | || backupRestoreGzip( absFilePath( args ) ) ) { | 524 | || backupRestoreGzip( absFilePath( args ) ) ) { |
533 | send( "150 File status okay" ); | 525 | send( "150 File status okay" ); |
534 | sendFile( absFilePath( args ) ); | 526 | sendFile( absFilePath( args ) ); |
535 | } | 527 | } |
536 | else { | 528 | else { |
537 | qDebug("550 Requested action not taken"); | 529 | qDebug("550 Requested action not taken"); |
538 | send( "550 Requested action not taken" ); | 530 | send( "550 Requested action not taken" ); |
539 | } | 531 | } |
540 | 532 | ||
541 | // store (STOR) | 533 | // store (STOR) |
542 | else if ( cmd == "STOR" ) | 534 | else if ( cmd == "STOR" ) |
543 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { | 535 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { |
544 | send( "150 File status okay" ); | 536 | send( "150 File status okay" ); |
545 | retrieveFile( absFilePath( args ) ); | 537 | retrieveFile( absFilePath( args ) ); |
546 | } | 538 | } |
547 | else | 539 | else |
548 | send( "550 Requested action not taken" ); | 540 | send( "550 Requested action not taken" ); |
549 | 541 | ||
550 | // store unique (STOU) | 542 | // store unique (STOU) |
551 | else if ( cmd == "STOU" ) { | 543 | else if ( cmd == "STOU" ) { |
552 | send( "502 Command not implemented" ); | 544 | send( "502 Command not implemented" ); |
553 | } | 545 | } |
554 | 546 | ||
555 | // append (APPE) | 547 | // append (APPE) |
556 | else if ( cmd == "APPE" ) { | 548 | else if ( cmd == "APPE" ) { |
557 | send( "502 Command not implemented" ); | 549 | send( "502 Command not implemented" ); |
558 | } | 550 | } |
559 | 551 | ||
560 | // allocate (ALLO) | 552 | // allocate (ALLO) |
561 | else if ( cmd == "ALLO" ) { | 553 | else if ( cmd == "ALLO" ) { |
562 | send( "200 Command okay" ); | 554 | send( "200 Command okay" ); |
563 | } | 555 | } |
564 | 556 | ||
565 | // restart (REST) | 557 | // restart (REST) |
566 | else if ( cmd == "REST" ) { | 558 | else if ( cmd == "REST" ) { |
567 | send( "502 Command not implemented" ); | 559 | send( "502 Command not implemented" ); |
568 | } | 560 | } |
569 | 561 | ||
570 | // rename from (RNFR) | 562 | // rename from (RNFR) |
571 | else if ( cmd == "RNFR" ) { | 563 | else if ( cmd == "RNFR" ) { |
572 | renameFrom = QString::null; | 564 | renameFrom = QString::null; |
573 | if ( args.isEmpty() ) | 565 | if ( args.isEmpty() ) |
574 | send( "500 Syntax error, command unrecognized" ); | 566 | send( "500 Syntax error, command unrecognized" ); |
575 | else { | 567 | else { |
576 | QFile file( absFilePath( args ) ); | 568 | QFile file( absFilePath( args ) ); |
577 | if ( file.exists() ) { | 569 | if ( file.exists() ) { |
578 | send( "350 File exists, ready for destination name" ); | 570 | send( "350 File exists, ready for destination name" ); |
579 | renameFrom = absFilePath( args ); | 571 | renameFrom = absFilePath( args ); |
580 | } | 572 | } |
581 | else | 573 | else |
582 | send( "550 Requested action not taken" ); | 574 | send( "550 Requested action not taken" ); |
583 | } | 575 | } |
584 | } | 576 | } |
585 | 577 | ||
586 | // rename to (RNTO) | 578 | // rename to (RNTO) |
587 | else if ( cmd == "RNTO" ) { | 579 | else if ( cmd == "RNTO" ) { |
588 | if ( lastCommand != "RNFR" ) | 580 | if ( lastCommand != "RNFR" ) |
589 | send( "503 Bad sequence of commands" ); | 581 | send( "503 Bad sequence of commands" ); |
590 | else if ( args.isEmpty() ) | 582 | else if ( args.isEmpty() ) |
591 | send( "500 Syntax error, command unrecognized" ); | 583 | send( "500 Syntax error, command unrecognized" ); |
592 | else { | 584 | else { |
593 | QDir dir( absFilePath( args ) ); | 585 | QDir dir( absFilePath( args ) ); |
594 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) | 586 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) |
595 | send( "250 Requested file action okay, completed." ); | 587 | send( "250 Requested file action okay, completed." ); |
596 | else | 588 | else |
597 | send( "550 Requested action not taken" ); | 589 | send( "550 Requested action not taken" ); |
598 | } | 590 | } |
599 | } | 591 | } |
600 | 592 | ||
601 | // abort (ABOR) | 593 | // abort (ABOR) |
602 | else if ( cmd.contains( "ABOR" ) ) { | 594 | else if ( cmd.contains( "ABOR" ) ) { |
603 | dtp->close(); | 595 | dtp->close(); |
604 | if ( dtp->dtpMode() != ServerDTP::Idle ) | 596 | if ( dtp->dtpMode() != ServerDTP::Idle ) |
605 | send( "426 Connection closed; transfer aborted" ); | 597 | send( "426 Connection closed; transfer aborted" ); |
606 | else | 598 | else |
607 | send( "226 Closing data connection" ); | 599 | send( "226 Closing data connection" ); |
608 | } | 600 | } |
609 | 601 | ||
610 | // delete (DELE) | 602 | // delete (DELE) |
611 | else if ( cmd == "DELE" ) { | 603 | else if ( cmd == "DELE" ) { |
612 | if ( args.isEmpty() ) | 604 | if ( args.isEmpty() ) |
613 | send( "500 Syntax error, command unrecognized" ); | 605 | send( "500 Syntax error, command unrecognized" ); |
614 | else { | 606 | else { |
615 | QFile file( absFilePath( args ) ) ; | 607 | QFile file( absFilePath( args ) ) ; |
616 | if ( file.remove() ) { | 608 | if ( file.remove() ) { |
617 | send( "250 Requested file action okay, completed" ); | 609 | send( "250 Requested file action okay, completed" ); |
618 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 610 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
619 | e << file.name(); | 611 | e << file.name(); |
620 | } | 612 | } |
621 | else { | 613 | else { |
622 | send( "550 Requested action not taken" ); | 614 | send( "550 Requested action not taken" ); |
623 | } | 615 | } |
624 | } | 616 | } |
625 | } | 617 | } |
626 | 618 | ||
627 | // remove directory (RMD) | 619 | // remove directory (RMD) |
628 | else if ( cmd == "RMD" ) { | 620 | else if ( cmd == "RMD" ) { |
629 | if ( args.isEmpty() ) | 621 | if ( args.isEmpty() ) |
630 | send( "500 Syntax error, command unrecognized" ); | 622 | send( "500 Syntax error, command unrecognized" ); |
631 | else { | 623 | else { |
632 | QDir dir; | 624 | QDir dir; |
633 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) | 625 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) |
634 | send( "250 Requested file action okay, completed" ); | 626 | send( "250 Requested file action okay, completed" ); |
635 | else | 627 | else |
636 | send( "550 Requested action not taken" ); | 628 | send( "550 Requested action not taken" ); |
637 | } | 629 | } |
638 | } | 630 | } |
639 | 631 | ||
640 | // make directory (MKD) | 632 | // make directory (MKD) |
641 | else if ( cmd == "MKD" ) { | 633 | else if ( cmd == "MKD" ) { |
642 | if ( args.isEmpty() ) { | 634 | if ( args.isEmpty() ) { |
643 | qDebug(" Error: no arg"); | 635 | qDebug(" Error: no arg"); |
644 | send( "500 Syntax error, command unrecognized" ); | 636 | send( "500 Syntax error, command unrecognized" ); |
645 | } | 637 | } |
646 | else { | 638 | else { |
647 | QDir dir; | 639 | QDir dir; |
648 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) | 640 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) |
649 | send( "250 Requested file action okay, completed." ); | 641 | send( "250 Requested file action okay, completed." ); |
650 | else | 642 | else |
651 | send( "550 Requested action not taken" ); | 643 | send( "550 Requested action not taken" ); |
652 | } | 644 | } |
653 | } | 645 | } |
654 | 646 | ||
655 | // print working directory (PWD) | 647 | // print working directory (PWD) |
656 | else if ( cmd == "PWD" ) { | 648 | else if ( cmd == "PWD" ) { |
657 | send( "257 \"" + directory.path() + "\"" ); | 649 | send( "257 \"" + directory.path() + "\"" ); |
658 | } | 650 | } |
659 | 651 | ||
660 | // list (LIST) | 652 | // list (LIST) |
661 | else if ( cmd == "LIST" ) { | 653 | else if ( cmd == "LIST" ) { |
662 | if ( sendList( absFilePath( args ) ) ) | 654 | if ( sendList( absFilePath( args ) ) ) |
663 | send( "150 File status okay" ); | 655 | send( "150 File status okay" ); |
664 | else | 656 | else |
665 | send( "500 Syntax error, command unrecognized" ); | 657 | send( "500 Syntax error, command unrecognized" ); |
666 | } | 658 | } |
667 | 659 | ||
668 | // size (SIZE) | 660 | // size (SIZE) |
669 | else if ( cmd == "SIZE" ) { | 661 | else if ( cmd == "SIZE" ) { |
670 | QString filePath = absFilePath( args ); | 662 | QString filePath = absFilePath( args ); |
671 | QFileInfo fi( filePath ); | 663 | QFileInfo fi( filePath ); |
672 | bool gzipfile = backupRestoreGzip( filePath ); | 664 | bool gzipfile = backupRestoreGzip( filePath ); |
673 | if ( !fi.exists() && !gzipfile ) | 665 | if ( !fi.exists() && !gzipfile ) |
674 | send( "500 Syntax error, command unrecognized" ); | 666 | send( "500 Syntax error, command unrecognized" ); |
675 | else { | 667 | else { |
676 | if ( !gzipfile ) | 668 | if ( !gzipfile ) |
677 | send( "213 " + QString::number( fi.size() ) ); | 669 | send( "213 " + QString::number( fi.size() ) ); |
678 | else { | 670 | else { |
679 | Process duproc( QString("du") ); | 671 | Process duproc( QString("du") ); |
680 | duproc.addArgument("-s"); | 672 | duproc.addArgument("-s"); |
681 | QString in, out; | 673 | QString in, out; |
682 | if ( !duproc.exec(in, out) ) { | 674 | if ( !duproc.exec(in, out) ) { |
683 | qDebug("du process failed; just sending back 1K"); | 675 | qDebug("du process failed; just sending back 1K"); |
684 | send( "213 1024"); | 676 | send( "213 1024"); |
685 | } | 677 | } |
686 | else { | 678 | else { |
687 | QString size = out.left( out.find("\t") ); | 679 | QString size = out.left( out.find("\t") ); |
688 | int guess = size.toInt() / 5; | 680 | int guess = size.toInt() / 5; |
689 | if ( filePath.contains("doc") ) | 681 | if ( filePath.contains("doc") ) |
690 | guess *= 1000; | 682 | guess *= 1000; |
691 | qDebug("sending back gzip guess of %d", guess); | 683 | qDebug("sending back gzip guess of %d", guess); |
692 | send( "213 " + QString::number(guess) ); | 684 | send( "213 " + QString::number(guess) ); |
693 | } | 685 | } |
694 | } | 686 | } |
695 | } | 687 | } |
696 | } | 688 | } |
697 | // name list (NLST) | 689 | // name list (NLST) |
698 | else if ( cmd == "NLST" ) { | 690 | else if ( cmd == "NLST" ) { |
699 | send( "502 Command not implemented" ); | 691 | send( "502 Command not implemented" ); |
700 | } | 692 | } |
701 | 693 | ||
702 | // site parameters (SITE) | 694 | // site parameters (SITE) |
703 | else if ( cmd == "SITE" ) { | 695 | else if ( cmd == "SITE" ) { |
704 | send( "502 Command not implemented" ); | 696 | send( "502 Command not implemented" ); |
705 | } | 697 | } |
706 | 698 | ||
707 | // system (SYST) | 699 | // system (SYST) |
708 | else if ( cmd == "SYST" ) { | 700 | else if ( cmd == "SYST" ) { |
709 | send( "215 UNIX Type: L8" ); | 701 | send( "215 UNIX Type: L8" ); |
710 | } | 702 | } |
711 | 703 | ||
712 | // status (STAT) | 704 | // status (STAT) |
713 | else if ( cmd == "STAT" ) { | 705 | else if ( cmd == "STAT" ) { |
714 | send( "502 Command not implemented" ); | 706 | send( "502 Command not implemented" ); |
715 | } | 707 | } |
716 | 708 | ||
717 | // help (HELP ) | 709 | // help (HELP ) |
718 | else if ( cmd == "HELP" ) { | 710 | else if ( cmd == "HELP" ) { |
719 | send( "502 Command not implemented" ); | 711 | send( "502 Command not implemented" ); |
720 | } | 712 | } |
721 | 713 | ||
722 | // noop (NOOP) | 714 | // noop (NOOP) |
723 | else if ( cmd == "NOOP" ) { | 715 | else if ( cmd == "NOOP" ) { |
724 | send( "200 Command okay" ); | 716 | send( "200 Command okay" ); |
725 | } | 717 | } |
726 | 718 | ||
727 | // not implemented | 719 | // not implemented |
728 | else | 720 | else |
729 | send( "502 Command not implemented" ); | 721 | send( "502 Command not implemented" ); |
730 | 722 | ||
731 | lastCommand = cmd; | 723 | lastCommand = cmd; |
732 | } | 724 | } |
733 | 725 | ||
734 | bool ServerPI::backupRestoreGzip( const QString &file ) | 726 | bool ServerPI::backupRestoreGzip( const QString &file ) |
735 | { | 727 | { |
736 | return (file.find( "backup" ) != -1 && | 728 | return (file.find( "backup" ) != -1 && |
737 | file.findRev( ".tgz" ) == (int)file.length() - 4 ); | 729 | file.findRev( ".tgz" ) == (int)file.length() - 4 ); |
738 | } | 730 | } |
739 | 731 | ||
740 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | 732 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) |
741 | { | 733 | { |
742 | if ( file.find( "backup" ) != -1 && | 734 | if ( file.find( "backup" ) != -1 && |
743 | file.findRev( ".tgz" ) == (int)file.length() - 4 ) { | 735 | file.findRev( ".tgz" ) == (int)file.length() - 4 ) { |
744 | QFileInfo info( file ); | 736 | QFileInfo info( file ); |
745 | targets = info.dirPath( TRUE ); | 737 | targets = info.dirPath( TRUE ); |
746 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), | 738 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), |
747 | targets.join(" ").latin1() ); | 739 | targets.join(" ").latin1() ); |
748 | return true; | 740 | return true; |
749 | } | 741 | } |
750 | return false; | 742 | return false; |
751 | } | 743 | } |
752 | 744 | ||
753 | void ServerPI::sendFile( const QString& file ) | 745 | void ServerPI::sendFile( const QString& file ) |
754 | { | 746 | { |
755 | if ( passiv ) { | 747 | if ( passiv ) { |
756 | wait[SendFile] = TRUE; | 748 | wait[SendFile] = TRUE; |
757 | waitfile = file; | 749 | waitfile = file; |
758 | if ( waitsocket ) | 750 | if ( waitsocket ) |
759 | newConnection( waitsocket ); | 751 | newConnection( waitsocket ); |
760 | } | 752 | } |
761 | else { | 753 | else { |
762 | QStringList targets; | 754 | QStringList targets; |
763 | if ( backupRestoreGzip( file, targets ) ) | 755 | if ( backupRestoreGzip( file, targets ) ) |
764 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); | 756 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); |
765 | else | 757 | else |
766 | dtp->sendFile( file, peeraddress, peerport ); | 758 | dtp->sendFile( file, peeraddress, peerport ); |
767 | } | 759 | } |
768 | } | 760 | } |
769 | 761 | ||
770 | void ServerPI::retrieveFile( const QString& file ) | 762 | void ServerPI::retrieveFile( const QString& file ) |
771 | { | 763 | { |
772 | if ( passiv ) { | 764 | if ( passiv ) { |
773 | wait[RetrieveFile] = TRUE; | 765 | wait[RetrieveFile] = TRUE; |
774 | waitfile = file; | 766 | waitfile = file; |
775 | if ( waitsocket ) | 767 | if ( waitsocket ) |
776 | newConnection( waitsocket ); | 768 | newConnection( waitsocket ); |
777 | } | 769 | } |
778 | else { | 770 | else { |
779 | QStringList targets; | 771 | QStringList targets; |
780 | if ( backupRestoreGzip( file, targets ) ) | 772 | if ( backupRestoreGzip( file, targets ) ) |
781 | dtp->retrieveGzipFile( file, peeraddress, peerport ); | 773 | dtp->retrieveGzipFile( file, peeraddress, peerport ); |
782 | else | 774 | else |
783 | dtp->retrieveFile( file, peeraddress, peerport ); | 775 | dtp->retrieveFile( file, peeraddress, peerport ); |
784 | } | 776 | } |
785 | } | 777 | } |
786 | 778 | ||
787 | bool ServerPI::parsePort( const QString& pp ) | 779 | bool ServerPI::parsePort( const QString& pp ) |
788 | { | 780 | { |
789 | QStringList p = QStringList::split( ",", pp ); | 781 | QStringList p = QStringList::split( ",", pp ); |
790 | if ( p.count() != 6 ) | 782 | if ( p.count() != 6 ) |
791 | return FALSE; | 783 | return FALSE; |
792 | 784 | ||
793 | // h1,h2,h3,h4,p1,p2 | 785 | // h1,h2,h3,h4,p1,p2 |
794 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + | 786 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + |
795 | ( p[2].toInt() << 8 ) + p[3].toInt() ); | 787 | ( p[2].toInt() << 8 ) + p[3].toInt() ); |
796 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); | 788 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); |
797 | return TRUE; | 789 | return TRUE; |
798 | } | 790 | } |
799 | 791 | ||
800 | void ServerPI::dtpCompleted() | 792 | void ServerPI::dtpCompleted() |
801 | { | 793 | { |
802 | send( "226 Closing data connection, file transfer successful" ); | 794 | send( "226 Closing data connection, file transfer successful" ); |
803 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { | 795 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { |
804 | QString fn = dtp->fileName(); | 796 | QString fn = dtp->fileName(); |
805 | if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) { | 797 | if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) { |
806 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 798 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
807 | e << fn; | 799 | e << fn; |
808 | } | 800 | } |
809 | } | 801 | } |
810 | waitsocket = 0; | 802 | waitsocket = 0; |
811 | dtp->close(); | 803 | dtp->close(); |
812 | } | 804 | } |
813 | 805 | ||
814 | void ServerPI::dtpFailed() | 806 | void ServerPI::dtpFailed() |
815 | { | 807 | { |
816 | dtp->close(); | 808 | dtp->close(); |
817 | waitsocket = 0; | 809 | waitsocket = 0; |
818 | send( "451 Requested action aborted: local error in processing" ); | 810 | send( "451 Requested action aborted: local error in processing" ); |
819 | } | 811 | } |
820 | 812 | ||
821 | void ServerPI::dtpError( int ) | 813 | void ServerPI::dtpError( int ) |
822 | { | 814 | { |
823 | dtp->close(); | 815 | dtp->close(); |
824 | waitsocket = 0; | 816 | waitsocket = 0; |
825 | send( "451 Requested action aborted: local error in processing" ); | 817 | send( "451 Requested action aborted: local error in processing" ); |
826 | } | 818 | } |
827 | 819 | ||
828 | bool ServerPI::sendList( const QString& arg ) | 820 | bool ServerPI::sendList( const QString& arg ) |
829 | { | 821 | { |
830 | QByteArray listing; | 822 | QByteArray listing; |
831 | QBuffer buffer( listing ); | 823 | QBuffer buffer( listing ); |
832 | 824 | ||
833 | if ( !buffer.open( IO_WriteOnly ) ) | 825 | if ( !buffer.open( IO_WriteOnly ) ) |
834 | return FALSE; | 826 | return FALSE; |
835 | 827 | ||
836 | QTextStream ts( &buffer ); | 828 | QTextStream ts( &buffer ); |
837 | QString fn = arg; | 829 | QString fn = arg; |
838 | 830 | ||
839 | if ( fn.isEmpty() ) | 831 | if ( fn.isEmpty() ) |
840 | fn = directory.path(); | 832 | fn = directory.path(); |
841 | 833 | ||
842 | QFileInfo fi( fn ); | 834 | QFileInfo fi( fn ); |
843 | if ( !fi.exists() ) | 835 | if ( !fi.exists() ) |
844 | return FALSE; | 836 | return FALSE; |
845 | 837 | ||
846 | // return file listing | 838 | // return file listing |
847 | if ( fi.isFile() ) { | 839 | if ( fi.isFile() ) { |
848 | ts << fileListing( &fi ) << endl; | 840 | ts << fileListing( &fi ) << endl; |
849 | } | 841 | } |
850 | 842 | ||
851 | // return directory listing | 843 | // return directory listing |
852 | else if ( fi.isDir() ) { | 844 | else if ( fi.isDir() ) { |
853 | QDir dir( fn ); | 845 | QDir dir( fn ); |
854 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); | 846 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); |
855 | 847 | ||
856 | QFileInfoListIterator it( *list ); | 848 | QFileInfoListIterator it( *list ); |
857 | QFileInfo *info; | 849 | QFileInfo *info; |
858 | 850 | ||
859 | unsigned long total = 0; | 851 | unsigned long total = 0; |
860 | while ( ( info = it.current() ) ) { | 852 | while ( ( info = it.current() ) ) { |
861 | if ( info->fileName() != "." && info->fileName() != ".." ) | 853 | if ( info->fileName() != "." && info->fileName() != ".." ) |
862 | total += info->size(); | 854 | total += info->size(); |
863 | ++it; | 855 | ++it; |
864 | } | 856 | } |
865 | 857 | ||
866 | ts << "total " << QString::number( total / 1024 ) << endl; | 858 | ts << "total " << QString::number( total / 1024 ) << endl; |
867 | 859 | ||
868 | it.toFirst(); | 860 | it.toFirst(); |
869 | while ( ( info = it.current() ) ) { | 861 | while ( ( info = it.current() ) ) { |
870 | if ( info->fileName() == "." || info->fileName() == ".." ) { | 862 | if ( info->fileName() == "." || info->fileName() == ".." ) { |
871 | ++it; | 863 | ++it; |
872 | continue; | 864 | continue; |
873 | } | 865 | } |
874 | ts << fileListing( info ) << endl; | 866 | ts << fileListing( info ) << endl; |
875 | ++it; | 867 | ++it; |
876 | } | 868 | } |
877 | } | 869 | } |
878 | 870 | ||
879 | if ( passiv ) { | 871 | if ( passiv ) { |
880 | waitarray = buffer.buffer(); | 872 | waitarray = buffer.buffer(); |
881 | wait[SendByteArray] = TRUE; | 873 | wait[SendByteArray] = TRUE; |
882 | if ( waitsocket ) | 874 | if ( waitsocket ) |
883 | newConnection( waitsocket ); | 875 | newConnection( waitsocket ); |
884 | } | 876 | } |
885 | else | 877 | else |
886 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); | 878 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); |
887 | return TRUE; | 879 | return TRUE; |
888 | } | 880 | } |
889 | 881 | ||
890 | QString ServerPI::fileListing( QFileInfo *info ) | 882 | QString ServerPI::fileListing( QFileInfo *info ) |
891 | { | 883 | { |
892 | if ( !info ) | 884 | if ( !info ) |
893 | return QString::null; | 885 | return QString::null; |
894 | QString s; | 886 | QString s; |
895 | 887 | ||
896 | // type char | 888 | // type char |
897 | if ( info->isDir() ) | 889 | if ( info->isDir() ) |
898 | s += "d"; | 890 | s += "d"; |
899 | else if ( info->isSymLink() ) | 891 | else if ( info->isSymLink() ) |
900 | s += "l"; | 892 | s += "l"; |
901 | else | 893 | else |
902 | s += "-"; | 894 | s += "-"; |
903 | 895 | ||
904 | // permisson string | 896 | // permisson string |
905 | s += permissionString( info ) + " "; | 897 | s += permissionString( info ) + " "; |
906 | 898 | ||
907 | // number of hardlinks | 899 | // number of hardlinks |
908 | int subdirs = 1; | 900 | int subdirs = 1; |
909 | 901 | ||
910 | if ( info->isDir() ) | 902 | if ( info->isDir() ) |
911 | subdirs = 2; | 903 | subdirs = 2; |
912 | // FIXME : this is to slow | 904 | // FIXME : this is to slow |
913 | //if ( info->isDir() ) | 905 | //if ( info->isDir() ) |
914 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); | 906 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); |
915 | 907 | ||
916 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; | 908 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; |
917 | 909 | ||
918 | // owner | 910 | // owner |
919 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; | 911 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; |
920 | 912 | ||
921 | // group | 913 | // group |
922 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; | 914 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; |
923 | 915 | ||
924 | // file size in bytes | 916 | // file size in bytes |
925 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; | 917 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; |
926 | 918 | ||
927 | // last modified date | 919 | // last modified date |
928 | QDate date = info->lastModified().date(); | 920 | QDate date = info->lastModified().date(); |
929 | QTime time = info->lastModified().time(); | 921 | QTime time = info->lastModified().time(); |
930 | s += date.monthName( date.month() ) + " " | 922 | s += date.monthName( date.month() ) + " " |
931 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " | 923 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " |
932 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" | 924 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" |
933 | + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " "; | 925 | + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " "; |
934 | 926 | ||
935 | // file name | 927 | // file name |
936 | s += info->fileName(); | 928 | s += info->fileName(); |
937 | 929 | ||
938 | return s; | 930 | return s; |
939 | } | 931 | } |
940 | 932 | ||
941 | QString ServerPI::permissionString( QFileInfo *info ) | 933 | QString ServerPI::permissionString( QFileInfo *info ) |
942 | { | 934 | { |
943 | if ( !info ) | 935 | if ( !info ) |
944 | return QString( "---------" ); | 936 | return QString( "---------" ); |
945 | QString s; | 937 | QString s; |
946 | 938 | ||
947 | // user | 939 | // user |
948 | if ( info->permission( QFileInfo::ReadUser ) ) | 940 | if ( info->permission( QFileInfo::ReadUser ) ) |
949 | s += "r"; | 941 | s += "r"; |
950 | else | 942 | else |
951 | s += "-"; | 943 | s += "-"; |
952 | if ( info->permission( QFileInfo::WriteUser ) ) | 944 | if ( info->permission( QFileInfo::WriteUser ) ) |
953 | s += "w"; | 945 | s += "w"; |
954 | else | 946 | else |
955 | s += "-"; | 947 | s += "-"; |
956 | if ( info->permission( QFileInfo::ExeUser ) ) | 948 | if ( info->permission( QFileInfo::ExeUser ) ) |
957 | s += "x"; | 949 | s += "x"; |
958 | else | 950 | else |
959 | s += "-"; | 951 | s += "-"; |
960 | 952 | ||
961 | // group | 953 | // group |
962 | if ( info->permission( QFileInfo::ReadGroup ) ) | 954 | if ( info->permission( QFileInfo::ReadGroup ) ) |
963 | s += "r"; | 955 | s += "r"; |
964 | else | 956 | else |
965 | s += "-"; | 957 | s += "-"; |
966 | if ( info->permission( QFileInfo::WriteGroup ) ) | 958 | if ( info->permission( QFileInfo::WriteGroup ) ) |
967 | s += "w"; | 959 | s += "w"; |
968 | else | 960 | else |
969 | s += "-"; | 961 | s += "-"; |
970 | if ( info->permission( QFileInfo::ExeGroup ) ) | 962 | if ( info->permission( QFileInfo::ExeGroup ) ) |
971 | s += "x"; | 963 | s += "x"; |
972 | else | 964 | else |
973 | s += "-"; | 965 | s += "-"; |
974 | 966 | ||
975 | // exec | 967 | // exec |
976 | if ( info->permission( QFileInfo::ReadOther ) ) | 968 | if ( info->permission( QFileInfo::ReadOther ) ) |
977 | s += "r"; | 969 | s += "r"; |
978 | else | 970 | else |
979 | s += "-"; | 971 | s += "-"; |
980 | if ( info->permission( QFileInfo::WriteOther ) ) | 972 | if ( info->permission( QFileInfo::WriteOther ) ) |
981 | s += "w"; | 973 | s += "w"; |
982 | else | 974 | else |
983 | s += "-"; | 975 | s += "-"; |
984 | if ( info->permission( QFileInfo::ExeOther ) ) | 976 | if ( info->permission( QFileInfo::ExeOther ) ) |
985 | s += "x"; | 977 | s += "x"; |
986 | else | 978 | else |
987 | s += "-"; | 979 | s += "-"; |
988 | 980 | ||
989 | return s; | 981 | return s; |
990 | } | 982 | } |
991 | 983 | ||
992 | void ServerPI::newConnection( int socket ) | 984 | void ServerPI::newConnection( int socket ) |
993 | { | 985 | { |
994 | //qDebug( "New incomming connection" ); | 986 | //qDebug( "New incomming connection" ); |
995 | 987 | ||
996 | if ( !passiv ) | 988 | if ( !passiv ) |
997 | return ; | 989 | return ; |
998 | 990 | ||
999 | if ( wait[SendFile] ) { | 991 | if ( wait[SendFile] ) { |
1000 | QStringList targets; | 992 | QStringList targets; |
1001 | if ( backupRestoreGzip( waitfile, targets ) ) | 993 | if ( backupRestoreGzip( waitfile, targets ) ) |
1002 | dtp->sendGzipFile( waitfile, targets ); | 994 | dtp->sendGzipFile( waitfile, targets ); |
1003 | else | 995 | else |
1004 | dtp->sendFile( waitfile ); | 996 | dtp->sendFile( waitfile ); |
1005 | dtp->setSocket( socket ); | 997 | dtp->setSocket( socket ); |
1006 | } | 998 | } |
1007 | else if ( wait[RetrieveFile] ) { | 999 | else if ( wait[RetrieveFile] ) { |
1008 | qDebug("check retrieve file"); | 1000 | qDebug("check retrieve file"); |
1009 | if ( backupRestoreGzip( waitfile ) ) | 1001 | if ( backupRestoreGzip( waitfile ) ) |
1010 | dtp->retrieveGzipFile( waitfile ); | 1002 | dtp->retrieveGzipFile( waitfile ); |
1011 | else | 1003 | else |
1012 | dtp->retrieveFile( waitfile ); | 1004 | dtp->retrieveFile( waitfile ); |
1013 | dtp->setSocket( socket ); | 1005 | dtp->setSocket( socket ); |
1014 | } | 1006 | } |
1015 | else if ( wait[SendByteArray] ) { | 1007 | else if ( wait[SendByteArray] ) { |
1016 | dtp->sendByteArray( waitarray ); | 1008 | dtp->sendByteArray( waitarray ); |
1017 | dtp->setSocket( socket ); | 1009 | dtp->setSocket( socket ); |
1018 | } | 1010 | } |
1019 | else if ( wait[RetrieveByteArray] ) { | 1011 | else if ( wait[RetrieveByteArray] ) { |
1020 | qDebug("retrieve byte array"); | 1012 | qDebug("retrieve byte array"); |
1021 | dtp->retrieveByteArray(); | 1013 | dtp->retrieveByteArray(); |
1022 | dtp->setSocket( socket ); | 1014 | dtp->setSocket( socket ); |
1023 | } | 1015 | } |
1024 | else | 1016 | else |
1025 | waitsocket = socket; | 1017 | waitsocket = socket; |
1026 | 1018 | ||
1027 | for ( int i = 0; i < 4; i++ ) | 1019 | for ( int i = 0; i < 4; i++ ) |
1028 | wait[i] = FALSE; | 1020 | wait[i] = FALSE; |
1029 | } | 1021 | } |
1030 | 1022 | ||
1031 | QString ServerPI::absFilePath( const QString& file ) | 1023 | QString ServerPI::absFilePath( const QString& file ) |
1032 | { | 1024 | { |
1033 | if ( file.isEmpty() ) | 1025 | if ( file.isEmpty() ) |
1034 | return file; | 1026 | return file; |
1035 | 1027 | ||
1036 | QString filepath( file ); | 1028 | QString filepath( file ); |
1037 | if ( file[0] != "/" ) | 1029 | if ( file[0] != "/" ) |
1038 | filepath = directory.path() + "/" + file; | 1030 | filepath = directory.path() + "/" + file; |
1039 | 1031 | ||
1040 | return filepath; | 1032 | return filepath; |
1041 | } | 1033 | } |
1042 | 1034 | ||
1043 | 1035 | ||
1044 | void ServerPI::timerEvent( QTimerEvent * ) | 1036 | void ServerPI::timerEvent( QTimerEvent * ) |
1045 | { | 1037 | { |
1046 | connectionClosed(); | 1038 | connectionClosed(); |
1047 | } | 1039 | } |
1048 | 1040 | ||
1049 | 1041 | ||
1050 | ServerDTP::ServerDTP( QObject *parent, const char* name) | 1042 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
1051 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 1043 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
1052 | retrieveTargzProc( 0 ), gzipProc( 0 ) | 1044 | retrieveTargzProc( 0 ), gzipProc( 0 ) |
1053 | { | 1045 | { |
1054 | 1046 | ||
1055 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1047 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1056 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1048 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1057 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); | 1049 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); |
1058 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1050 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1059 | 1051 | ||
1060 | gzipProc = new OProcess( this, "gzipProc" ); | 1052 | gzipProc = new OProcess( this, "gzipProc" ); |
1061 | 1053 | ||
1062 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); | 1054 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); |
1063 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1055 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1064 | connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); | 1056 | connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); |
1065 | 1057 | ||
1066 | QStringList args = "tar"; | 1058 | QStringList args = "tar"; |
1067 | args += "-xv"; | 1059 | args += "-xv"; |
1068 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); | 1060 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); |
1069 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1061 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1070 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), | 1062 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), |
1071 | SIGNAL( completed() ) ); | 1063 | SIGNAL( completed() ) ); |
1072 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), | 1064 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), |
1073 | SLOT( extractTarDone() ) ); | 1065 | SLOT( extractTarDone() ) ); |
1074 | } | 1066 | } |
1075 | 1067 | ||
1076 | ServerDTP::~ServerDTP() | 1068 | ServerDTP::~ServerDTP() |
1077 | { | 1069 | { |
1078 | buf.close(); | 1070 | buf.close(); |
1079 | file.close(); | 1071 | file.close(); |
1080 | createTargzProc->kill(); | 1072 | createTargzProc->kill(); |
1081 | } | 1073 | } |
1082 | 1074 | ||
1083 | void ServerDTP::extractTarDone() | 1075 | void ServerDTP::extractTarDone() |
1084 | { | 1076 | { |
1085 | qDebug("extract done"); | 1077 | qDebug("extract done"); |
1086 | #ifndef QT_NO_COP | 1078 | #ifndef QT_NO_COP |
1087 | 1079 | ||
1088 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); | 1080 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); |
1089 | e << file.name(); | 1081 | e << file.name(); |
1090 | #endif | 1082 | #endif |
1091 | } | 1083 | } |
1092 | 1084 | ||
1093 | void ServerDTP::connected() | 1085 | void ServerDTP::connected() |
1094 | { | 1086 | { |
1095 | // send file mode | 1087 | // send file mode |
1096 | switch ( mode ) { | 1088 | switch ( mode ) { |
1097 | case SendFile : | 1089 | case SendFile : |
1098 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 1090 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
1099 | emit failed(); | 1091 | emit failed(); |
1100 | mode = Idle; | 1092 | mode = Idle; |
1101 | return ; | 1093 | return ; |
1102 | } | 1094 | } |
1103 | 1095 | ||
1104 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 1096 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); |
1105 | 1097 | ||
1106 | bytes_written = 0; | 1098 | bytes_written = 0; |
1107 | if ( file.size() == 0 ) { | 1099 | if ( file.size() == 0 ) { |
1108 | //make sure it doesn't hang on empty files | 1100 | //make sure it doesn't hang on empty files |
1109 | file.close(); | 1101 | file.close(); |
1110 | emit completed(); | 1102 | emit completed(); |
1111 | mode = Idle; | 1103 | mode = Idle; |
1112 | } | 1104 | } |
1113 | else { | 1105 | else { |
1114 | 1106 | ||
1115 | if ( !file.atEnd() ) { | 1107 | if ( !file.atEnd() ) { |
1116 | QCString s; | 1108 | QCString s; |
1117 | s.resize( block_size ); | 1109 | s.resize( block_size ); |
1118 | int bytes = file.readBlock( s.data(), block_size ); | 1110 | int bytes = file.readBlock( s.data(), block_size ); |
1119 | writeBlock( s.data(), bytes ); | 1111 | writeBlock( s.data(), bytes ); |
1120 | } | 1112 | } |
1121 | } | 1113 | } |
1122 | break; | 1114 | break; |
1123 | case SendGzipFile: | 1115 | case SendGzipFile: |
1124 | if ( createTargzProc->isRunning() ) { | 1116 | if ( createTargzProc->isRunning() ) { |
1125 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY | 1117 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY |
1126 | qWarning("Previous tar --gzip process is still running; killing it..."); | 1118 | qWarning("Previous tar --gzip process is still running; killing it..."); |
1127 | createTargzProc->kill(); | 1119 | createTargzProc->kill(); |
1128 | } | 1120 | } |
1129 | 1121 | ||
1130 | bytes_written = 0; | 1122 | bytes_written = 0; |
1131 | qDebug("==>start send tar process"); | 1123 | qDebug("==>start send tar process"); |
1132 | if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) | 1124 | if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) |
1133 | qWarning("Error starting %s or %s", | 1125 | qWarning("Error starting %s or %s", |
1134 | createTargzProc->args()[0].data(), | 1126 | createTargzProc->args()[0].data(), |
1135 | gzipProc->args()[0].data()); | 1127 | gzipProc->args()[0].data()); |
1136 | break; | 1128 | break; |
1137 | case SendBuffer: | 1129 | case SendBuffer: |
1138 | if ( !buf.open( IO_ReadOnly) ) { | 1130 | if ( !buf.open( IO_ReadOnly) ) { |
1139 | emit failed(); | 1131 | emit failed(); |
1140 | mode = Idle; | 1132 | mode = Idle; |
1141 | return ; | 1133 | return ; |
1142 | } | 1134 | } |
1143 | 1135 | ||
1144 | // qDebug( "Debug: Sending byte array" ); | 1136 | // qDebug( "Debug: Sending byte array" ); |
1145 | bytes_written = 0; | 1137 | bytes_written = 0; |
1146 | while ( !buf.atEnd() ) | 1138 | while ( !buf.atEnd() ) |
1147 | putch( buf.getch() ); | 1139 | putch( buf.getch() ); |
1148 | buf.close(); | 1140 | buf.close(); |
1149 | break; | 1141 | break; |
1150 | case RetrieveFile: | 1142 | case RetrieveFile: |
1151 | // retrieve file mode | 1143 | // retrieve file mode |
1152 | if ( file.exists() && !file.remove() ) { | 1144 | if ( file.exists() && !file.remove() ) { |
1153 | emit failed(); | 1145 | emit failed(); |
1154 | mode = Idle; | 1146 | mode = Idle; |
1155 | return ; | 1147 | return ; |
1156 | } | 1148 | } |
1157 | 1149 | ||
1158 | if ( !file.open( IO_WriteOnly) ) { | 1150 | if ( !file.open( IO_WriteOnly) ) { |
1159 | emit failed(); | 1151 | emit failed(); |
1160 | mode = Idle; | 1152 | mode = Idle; |
1161 | return ; | 1153 | return ; |
1162 | } | 1154 | } |
1163 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); | 1155 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); |
1164 | break; | 1156 | break; |
1165 | case RetrieveGzipFile: | 1157 | case RetrieveGzipFile: |
1166 | qDebug("=-> starting tar process to receive .tgz file"); | 1158 | qDebug("=-> starting tar process to receive .tgz file"); |
1167 | break; | 1159 | break; |
1168 | case RetrieveBuffer: | 1160 | case RetrieveBuffer: |
1169 | // retrieve buffer mode | 1161 | // retrieve buffer mode |
1170 | if ( !buf.open( IO_WriteOnly) ) { | 1162 | if ( !buf.open( IO_WriteOnly) ) { |
1171 | emit failed(); | 1163 | emit failed(); |
1172 | mode = Idle; | 1164 | mode = Idle; |
1173 | return ; | 1165 | return ; |
1174 | } | 1166 | } |
1175 | // qDebug( "Debug: Retrieving byte array" ); | 1167 | // qDebug( "Debug: Retrieving byte array" ); |
1176 | break; | 1168 | break; |
1177 | case Idle: | 1169 | case Idle: |
1178 | qDebug("connection established but mode set to Idle; BUG!"); | 1170 | qDebug("connection established but mode set to Idle; BUG!"); |
1179 | break; | 1171 | break; |
1180 | } | 1172 | } |
1181 | } | 1173 | } |
1182 | 1174 | ||
1183 | void ServerDTP::connectionClosed() | 1175 | void ServerDTP::connectionClosed() |
1184 | { | 1176 | { |
1185 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); | 1177 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); |
1186 | 1178 | ||
1187 | // send file mode | 1179 | // send file mode |
1188 | if ( SendFile == mode ) { | 1180 | if ( SendFile == mode ) { |
1189 | if ( bytes_written == file.size() ) | 1181 | if ( bytes_written == file.size() ) |
1190 | emit completed(); | 1182 | emit completed(); |
1191 | else | 1183 | else |
1192 | emit failed(); | 1184 | emit failed(); |
1193 | } | 1185 | } |
1194 | 1186 | ||
1195 | // send buffer mode | 1187 | // send buffer mode |
1196 | else if ( SendBuffer == mode ) { | 1188 | else if ( SendBuffer == mode ) { |
1197 | if ( bytes_written == buf.size() ) | 1189 | if ( bytes_written == buf.size() ) |
1198 | emit completed(); | 1190 | emit completed(); |
1199 | else | 1191 | else |
1200 | emit failed(); | 1192 | emit failed(); |
1201 | } | 1193 | } |
1202 | 1194 | ||
1203 | // retrieve file mode | 1195 | // retrieve file mode |
1204 | else if ( RetrieveFile == mode ) { | 1196 | else if ( RetrieveFile == mode ) { |
1205 | file.close(); | 1197 | file.close(); |
1206 | emit completed(); | 1198 | emit completed(); |
1207 | } | 1199 | } |
1208 | 1200 | ||
1209 | else if ( RetrieveGzipFile == mode ) { | 1201 | else if ( RetrieveGzipFile == mode ) { |
1210 | qDebug("Done writing ungzip file; closing input"); | 1202 | qDebug("Done writing ungzip file; closing input"); |
1211 | gzipProc->flushStdin(); | 1203 | gzipProc->flushStdin(); |
1212 | gzipProc->closeStdin(); | 1204 | gzipProc->closeStdin(); |
1213 | } | 1205 | } |
1214 | 1206 | ||
1215 | // retrieve buffer mode | 1207 | // retrieve buffer mode |
1216 | else if ( RetrieveBuffer == mode ) { | 1208 | else if ( RetrieveBuffer == mode ) { |
1217 | buf.close(); | 1209 | buf.close(); |
1218 | emit completed(); | 1210 | emit completed(); |
1219 | } | 1211 | } |
1220 | 1212 | ||
1221 | mode = Idle; | 1213 | mode = Idle; |
1222 | } | 1214 | } |
1223 | 1215 | ||
1224 | void ServerDTP::bytesWritten( int bytes ) | 1216 | void ServerDTP::bytesWritten( int bytes ) |
1225 | { | 1217 | { |
1226 | bytes_written += bytes; | 1218 | bytes_written += bytes; |
1227 | 1219 | ||
1228 | // send file mode | 1220 | // send file mode |
1229 | if ( SendFile == mode ) { | 1221 | if ( SendFile == mode ) { |
1230 | 1222 | ||
1231 | if ( bytes_written == file.size() ) { | 1223 | if ( bytes_written == file.size() ) { |
1232 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); | 1224 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); |
1233 | file.close(); | 1225 | file.close(); |
1234 | emit completed(); | 1226 | emit completed(); |
1235 | mode = Idle; | 1227 | mode = Idle; |
1236 | } | 1228 | } |
1237 | else if ( !file.atEnd() ) { | 1229 | else if ( !file.atEnd() ) { |
1238 | QCString s; | 1230 | QCString s; |
1239 | s.resize( block_size ); | 1231 | s.resize( block_size ); |
1240 | int bytes = file.readBlock( s.data(), block_size ); | 1232 | int bytes = file.readBlock( s.data(), block_size ); |
1241 | writeBlock( s.data(), bytes ); | 1233 | writeBlock( s.data(), bytes ); |
1242 | } | 1234 | } |
1243 | } | 1235 | } |
1244 | 1236 | ||
1245 | // send buffer mode | 1237 | // send buffer mode |
1246 | if ( SendBuffer == mode ) { | 1238 | if ( SendBuffer == mode ) { |
1247 | 1239 | ||
1248 | if ( bytes_written == buf.size() ) { | 1240 | if ( bytes_written == buf.size() ) { |
1249 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1241 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); |
1250 | emit completed(); | 1242 | emit completed(); |
1251 | mode = Idle; | 1243 | mode = Idle; |
1252 | } | 1244 | } |
1253 | } | 1245 | } |
1254 | } | 1246 | } |
1255 | 1247 | ||
1256 | void ServerDTP::readyRead() | 1248 | void ServerDTP::readyRead() |
1257 | { | 1249 | { |
1258 | // retrieve file mode | 1250 | // retrieve file mode |
1259 | if ( RetrieveFile == mode ) { | 1251 | if ( RetrieveFile == mode ) { |
1260 | QCString s; | 1252 | QCString s; |
1261 | s.resize( bytesAvailable() ); | 1253 | s.resize( bytesAvailable() ); |
1262 | readBlock( s.data(), bytesAvailable() ); | 1254 | readBlock( s.data(), bytesAvailable() ); |
1263 | file.writeBlock( s.data(), s.size() ); | 1255 | file.writeBlock( s.data(), s.size() ); |
1264 | } | 1256 | } |
1265 | else if ( RetrieveGzipFile == mode ) { | 1257 | else if ( RetrieveGzipFile == mode ) { |
1266 | if ( !gzipProc->isRunning() ) | 1258 | if ( !gzipProc->isRunning() ) |
1267 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); | 1259 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1268 | 1260 | ||
1269 | QByteArray s; | 1261 | QByteArray s; |
1270 | s.resize( bytesAvailable() ); | 1262 | s.resize( bytesAvailable() ); |
1271 | readBlock( s.data(), bytesAvailable() ); | 1263 | readBlock( s.data(), bytesAvailable() ); |
1272 | gzipProc->writeStdin( s.data(), s.size() ); | 1264 | gzipProc->writeStdin( s.data(), s.size() ); |
1273 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1265 | qDebug("wrote %d bytes to ungzip ", s.size() ); |
1274 | } | 1266 | } |
1275 | // retrieve buffer mode | 1267 | // retrieve buffer mode |
1276 | else if ( RetrieveBuffer == mode ) { | 1268 | else if ( RetrieveBuffer == mode ) { |
1277 | QCString s; | 1269 | QCString s; |
1278 | s.resize( bytesAvailable() ); | 1270 | s.resize( bytesAvailable() ); |
1279 | readBlock( s.data(), bytesAvailable() ); | 1271 | readBlock( s.data(), bytesAvailable() ); |
1280 | buf.writeBlock( s.data(), s.size() ); | 1272 | buf.writeBlock( s.data(), s.size() ); |
1281 | } | 1273 | } |
1282 | } | 1274 | } |
1283 | 1275 | ||
1284 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) | 1276 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) |
1285 | { | 1277 | { |
1286 | writeBlock( buffer, buflen ); | 1278 | writeBlock( buffer, buflen ); |
1287 | qDebug("writeTargzBlock %d", buflen); | 1279 | qDebug("writeTargzBlock %d", buflen); |
1288 | if ( !createTargzProc->isRunning() ) { | 1280 | if ( !createTargzProc->isRunning() ) { |
1289 | qDebug("tar and gzip done"); | 1281 | qDebug("tar and gzip done"); |
1290 | emit completed(); | 1282 | emit completed(); |
1291 | mode = Idle; | 1283 | mode = Idle; |
1292 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ), | 1284 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ), |
1293 | this, SLOT( writeTargzBlock(OProcess *, char *, int) ) ); | 1285 | this, SLOT( writeTargzBlock(OProcess *, char *, int) ) ); |
1294 | } | 1286 | } |
1295 | } | 1287 | } |
1296 | 1288 | ||
1297 | void ServerDTP::targzDone() | 1289 | void ServerDTP::targzDone() |
1298 | { | 1290 | { |
1299 | //qDebug("targz done"); | 1291 | //qDebug("targz done"); |
1300 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | 1292 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1301 | this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); | 1293 | this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); |
1302 | gzipProc->closeStdin(); | 1294 | gzipProc->closeStdin(); |
1303 | } | 1295 | } |
1304 | 1296 | ||
1305 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) | 1297 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) |
1306 | { | 1298 | { |
1307 | //qDebug("gzipTarBlock"); | 1299 | //qDebug("gzipTarBlock"); |
1308 | if ( !gzipProc->isRunning() ) { | 1300 | if ( !gzipProc->isRunning() ) { |
1309 | //qDebug("auto start gzip proc"); | 1301 | //qDebug("auto start gzip proc"); |
1310 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); | 1302 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); |
1311 | } | 1303 | } |
1312 | gzipProc->writeStdin( buffer, buflen ); | 1304 | gzipProc->writeStdin( buffer, buflen ); |
1313 | } | 1305 | } |
1314 | 1306 | ||
1315 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1307 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1316 | { | 1308 | { |
1317 | file.setName( fn ); | 1309 | file.setName( fn ); |
1318 | mode = SendFile; | 1310 | mode = SendFile; |
1319 | connectToHost( host.toString(), port ); | 1311 | connectToHost( host.toString(), port ); |
1320 | } | 1312 | } |
1321 | 1313 | ||
1322 | void ServerDTP::sendFile( const QString fn ) | 1314 | void ServerDTP::sendFile( const QString fn ) |
1323 | { | 1315 | { |
1324 | file.setName( fn ); | 1316 | file.setName( fn ); |
1325 | mode = SendFile; | 1317 | mode = SendFile; |
1326 | } | 1318 | } |
1327 | 1319 | ||
1328 | void ServerDTP::sendGzipFile( const QString &fn, | 1320 | void ServerDTP::sendGzipFile( const QString &fn, |
1329 | const QStringList &archiveTargets, | 1321 | const QStringList &archiveTargets, |
1330 | const QHostAddress& host, Q_UINT16 port ) | 1322 | const QHostAddress& host, Q_UINT16 port ) |
1331 | { | 1323 | { |
1332 | sendGzipFile( fn, archiveTargets ); | 1324 | sendGzipFile( fn, archiveTargets ); |
1333 | connectToHost( host.toString(), port ); | 1325 | connectToHost( host.toString(), port ); |
1334 | } | 1326 | } |
1335 | 1327 | ||
1336 | void ServerDTP::sendGzipFile( const QString &fn, | 1328 | void ServerDTP::sendGzipFile( const QString &fn, |
1337 | const QStringList &archiveTargets ) | 1329 | const QStringList &archiveTargets ) |
1338 | { | 1330 | { |
1339 | mode = SendGzipFile; | 1331 | mode = SendGzipFile; |
1340 | file.setName( fn ); | 1332 | file.setName( fn ); |
1341 | 1333 | ||
1342 | QStringList args = "tar"; | 1334 | QStringList args = "tar"; |
1343 | args += "-cv"; | 1335 | args += "-cv"; |
1344 | args += archiveTargets; | 1336 | args += archiveTargets; |
1345 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1337 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); |
1346 | createTargzProc->clearArguments( ); | 1338 | createTargzProc->clearArguments( ); |
1347 | *createTargzProc << args; | 1339 | *createTargzProc << args; |
1348 | connect( createTargzProc, | 1340 | connect( createTargzProc, |
1349 | SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); | 1341 | SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); |
1350 | 1342 | ||
1351 | gzipProc->clearArguments( ); | 1343 | gzipProc->clearArguments( ); |
1352 | *gzipProc << "gzip"; | 1344 | *gzipProc << "gzip"; |
1353 | connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | 1345 | connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1354 | SLOT( writeTargzBlock(OProcess *, char *, int) ) ); | 1346 | SLOT( writeTargzBlock(OProcess *, char *, int) ) ); |
1355 | } | 1347 | } |
1356 | 1348 | ||
1357 | void ServerDTP::gunzipDone() | 1349 | void ServerDTP::gunzipDone() |
1358 | { | 1350 | { |
1359 | qDebug("gunzipDone"); | 1351 | qDebug("gunzipDone"); |
1360 | disconnect( gzipProc, SIGNAL( processExited() ), | 1352 | disconnect( gzipProc, SIGNAL( processExited() ), |
1361 | this, SLOT( gunzipDone() ) ); | 1353 | this, SLOT( gunzipDone() ) ); |
1362 | retrieveTargzProc->closeStdin(); | 1354 | retrieveTargzProc->closeStdin(); |
1363 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), | 1355 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), |
1364 | this, SLOT( tarExtractBlock(OProcess *, char *, int) ) ); | 1356 | this, SLOT( tarExtractBlock(OProcess *, char *, int) ) ); |
1365 | } | 1357 | } |
1366 | 1358 | ||
1367 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) | 1359 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) |
1368 | { | 1360 | { |
1369 | qDebug("tarExtractBlock"); | 1361 | qDebug("tarExtractBlock"); |
1370 | if ( !retrieveTargzProc->isRunning() ) { | 1362 | if ( !retrieveTargzProc->isRunning() ) { |
1371 | qDebug("auto start ungzip proc"); | 1363 | qDebug("auto start ungzip proc"); |
1372 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) | 1364 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) |
1373 | qWarning(" failed to start tar -x process"); | 1365 | qWarning(" failed to start tar -x process"); |
1374 | } | 1366 | } |
1375 | retrieveTargzProc->writeStdin( buffer, buflen ); | 1367 | retrieveTargzProc->writeStdin( buffer, buflen ); |
1376 | } | 1368 | } |
1377 | 1369 | ||
1378 | 1370 | ||
1379 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1371 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1380 | { | 1372 | { |
1381 | file.setName( fn ); | 1373 | file.setName( fn ); |
1382 | mode = RetrieveFile; | 1374 | mode = RetrieveFile; |
1383 | connectToHost( host.toString(), port ); | 1375 | connectToHost( host.toString(), port ); |
1384 | } | 1376 | } |
1385 | 1377 | ||
1386 | void ServerDTP::retrieveFile( const QString fn ) | 1378 | void ServerDTP::retrieveFile( const QString fn ) |
1387 | { | 1379 | { |
1388 | file.setName( fn ); | 1380 | file.setName( fn ); |
1389 | mode = RetrieveFile; | 1381 | mode = RetrieveFile; |
1390 | } | 1382 | } |
1391 | 1383 | ||
1392 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1384 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1393 | { | 1385 | { |
1394 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1386 | qDebug("retrieveGzipFile %s", fn.latin1()); |
1395 | file.setName( fn ); | 1387 | file.setName( fn ); |
1396 | mode = RetrieveGzipFile; | 1388 | mode = RetrieveGzipFile; |
1397 | 1389 | ||
1398 | gzipProc->clearArguments(); | 1390 | gzipProc->clearArguments(); |
1399 | *gzipProc << "gunzip"; | 1391 | *gzipProc << "gunzip"; |
1400 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1392 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1401 | SLOT( tarExtractBlock() ) ); | 1393 | SLOT( tarExtractBlock() ) ); |
1402 | connect( gzipProc, SIGNAL( processExited() ), | 1394 | connect( gzipProc, SIGNAL( processExited() ), |
1403 | SLOT( gunzipDone() ) ); | 1395 | SLOT( gunzipDone() ) ); |
1404 | } | 1396 | } |
1405 | 1397 | ||
1406 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1398 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |
1407 | { | 1399 | { |
1408 | retrieveGzipFile( fn ); | 1400 | retrieveGzipFile( fn ); |
1409 | connectToHost( host.toString(), port ); | 1401 | connectToHost( host.toString(), port ); |
1410 | } | 1402 | } |
1411 | 1403 | ||
1412 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) | 1404 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) |
1413 | { | 1405 | { |
1414 | buf.setBuffer( array ); | 1406 | buf.setBuffer( array ); |
1415 | mode = SendBuffer; | 1407 | mode = SendBuffer; |
1416 | connectToHost( host.toString(), port ); | 1408 | connectToHost( host.toString(), port ); |
1417 | } | 1409 | } |
1418 | 1410 | ||
1419 | void ServerDTP::sendByteArray( const QByteArray& array ) | 1411 | void ServerDTP::sendByteArray( const QByteArray& array ) |
1420 | { | 1412 | { |
1421 | buf.setBuffer( array ); | 1413 | buf.setBuffer( array ); |
1422 | mode = SendBuffer; | 1414 | mode = SendBuffer; |
1423 | } | 1415 | } |
1424 | 1416 | ||
1425 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) | 1417 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) |
1426 | { | 1418 | { |
1427 | buf.setBuffer( QByteArray() ); | 1419 | buf.setBuffer( QByteArray() ); |
1428 | mode = RetrieveBuffer; | 1420 | mode = RetrieveBuffer; |
1429 | connectToHost( host.toString(), port ); | 1421 | connectToHost( host.toString(), port ); |
1430 | } | 1422 | } |
1431 | 1423 | ||
1432 | void ServerDTP::retrieveByteArray() | 1424 | void ServerDTP::retrieveByteArray() |
1433 | { | 1425 | { |
1434 | buf.setBuffer( QByteArray() ); | 1426 | buf.setBuffer( QByteArray() ); |
1435 | mode = RetrieveBuffer; | 1427 | mode = RetrieveBuffer; |
1436 | } | 1428 | } |
1437 | 1429 | ||
1438 | void ServerDTP::setSocket( int socket ) | 1430 | void ServerDTP::setSocket( int socket ) |
1439 | { | 1431 | { |
1440 | QSocket::setSocket( socket ); | 1432 | QSocket::setSocket( socket ); |
1441 | connected(); | 1433 | connected(); |
1442 | } | 1434 | } |
1443 | 1435 | ||