-rw-r--r-- | core/qws/config.in | 13 | ||||
-rw-r--r-- | core/qws/oqwsserver.cpp | 2 | ||||
-rw-r--r-- | core/qws/oqwsserver.h | 2 | ||||
-rw-r--r-- | core/qws/qws.pro | 4 | ||||
-rw-r--r-- | core/qws/transferserver.cpp | 47 | ||||
-rw-r--r-- | core/qws/transferserver.h | 15 |
6 files changed, 37 insertions, 46 deletions
diff --git a/core/qws/config.in b/core/qws/config.in index 3706405..903eaa1 100644 --- a/core/qws/config.in +++ b/core/qws/config.in | |||
@@ -1,16 +1,5 @@ | |||
1 | config QWS | 1 | config QWS |
2 | boolean "Minimal QWS Server" | 2 | boolean "Minimal QWS Server" |
3 | default "n" | 3 | default "n" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && EXPERIMENTAL | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI && EXPERIMENTAL |
5 | 5 | ||
6 | # menu "Advanced QWS Server Config" | ||
7 | # config QWS_QCOP | ||
8 | # bool "QCop bridge and Transfer server (sync)" | ||
9 | # default y | ||
10 | # depends on QWS | ||
11 | # | ||
12 | # config QWS_PACKAGE | ||
13 | # bool "Package Slave (package installs via sync software)" | ||
14 | # default n | ||
15 | # depends on QWS | ||
16 | # endmenu | ||
diff --git a/core/qws/oqwsserver.cpp b/core/qws/oqwsserver.cpp index 907686a..d6b6504 100644 --- a/core/qws/oqwsserver.cpp +++ b/core/qws/oqwsserver.cpp | |||
@@ -1,181 +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 | 27 | ||
28 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) | 28 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) |
29 | #include <qpe/custom.h> | 29 | #include <qpe/custom.h> |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #include <opie/odevice.h> | 32 | #include <opie2/odevice.h> |
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #include <fcntl.h> | 38 | #include <fcntl.h> |
39 | 39 | ||
40 | using namespace Opie; | 40 | using namespace Opie; |
41 | 41 | ||
42 | OQWSServer::OQWSServer( int& argc, char **argv, Type appType ) | 42 | OQWSServer::OQWSServer( int& argc, char **argv, Type appType ) |
43 | : QPEApplication( argc, argv, appType ) | 43 | : QPEApplication( argc, argv, appType ) |
44 | { | 44 | { |
45 | startServers(); | 45 | startServers(); |
46 | } | 46 | } |
47 | 47 | ||
48 | OQWSServer::~OQWSServer() | 48 | OQWSServer::~OQWSServer() |
49 | { | 49 | { |
50 | terminateServers(); | 50 | terminateServers(); |
51 | } | 51 | } |
52 | 52 | ||
53 | bool OQWSServer::eventFilter ( QObject *o, QEvent *e ) | 53 | bool OQWSServer::eventFilter ( QObject *o, QEvent *e ) |
54 | { | 54 | { |
55 | #if 0 | 55 | #if 0 |
56 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { | 56 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { |
57 | QKeyEvent *ke = (QKeyEvent *) e; | 57 | QKeyEvent *ke = (QKeyEvent *) e; |
58 | 58 | ||
59 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); | 59 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); |
60 | 60 | ||
61 | if ( db ) { | 61 | if ( db ) { |
62 | if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) | 62 | if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) |
63 | return true; //checkButtonAction retrune false if events should be routed through | 63 | return true; //checkButtonAction retrune false if events should be routed through |
64 | } | 64 | } |
65 | } | 65 | } |
66 | #endif | 66 | #endif |
67 | return QPEApplication::eventFilter ( o, e ); | 67 | return QPEApplication::eventFilter ( o, e ); |
68 | } | 68 | } |
69 | 69 | ||
70 | #ifdef Q_WS_QWS | 70 | #ifdef Q_WS_QWS |
71 | 71 | ||
72 | bool OQWSServer::qwsEventFilter( QWSEvent *e ) | 72 | bool OQWSServer::qwsEventFilter( QWSEvent *e ) |
73 | { | 73 | { |
74 | #if 0 | 74 | #if 0 |
75 | qpedesktop->checkMemory(); | 75 | qpedesktop->checkMemory(); |
76 | 76 | ||
77 | if ( e->type == QWSEvent::Key ) { | 77 | if ( e->type == QWSEvent::Key ) { |
78 | QWSKeyEvent * ke = (QWSKeyEvent *) e; | 78 | QWSKeyEvent * ke = (QWSKeyEvent *) e; |
79 | ushort keycode = ke-> simpleData. keycode; | 79 | ushort keycode = ke-> simpleData. keycode; |
80 | 80 | ||
81 | if ( !loggedin && keycode != Key_F34 ) | 81 | if ( !loggedin && keycode != Key_F34 ) |
82 | return true; | 82 | return true; |
83 | 83 | ||
84 | bool press = ke-> simpleData. is_press; | 84 | bool press = ke-> simpleData. is_press; |
85 | bool autoRepeat = ke-> simpleData. is_auto_repeat; | 85 | bool autoRepeat = ke-> simpleData. is_auto_repeat; |
86 | 86 | ||
87 | if ( !keyboardGrabbed ( )) { | 87 | if ( !keyboardGrabbed ( )) { |
88 | // 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, |
89 | // when user presses key, unless keyboard has been requested from app. | 89 | // when user presses key, unless keyboard has been requested from app. |
90 | // will not send multiple repeats if user holds key | 90 | // will not send multiple repeats if user holds key |
91 | // i.e. one shot | 91 | // i.e. one shot |
92 | 92 | ||
93 | if ( keycode != 0 && press && !autoRepeat ) { | 93 | if ( keycode != 0 && press && !autoRepeat ) { |
94 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | 94 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { |
95 | if (( *it ). getKeyCode ( ) == keycode ) { | 95 | if (( *it ). getKeyCode ( ) == keycode ) { |
96 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); | 96 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); |
97 | return true; | 97 | return true; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | if ( keycode == HardKey_Suspend ) { | 103 | if ( keycode == HardKey_Suspend ) { |
104 | if ( press ) | 104 | if ( press ) |
105 | emit power ( ); | 105 | emit power ( ); |
106 | return true; | 106 | return true; |
107 | } | 107 | } |
108 | else if ( keycode == HardKey_Backlight ) { | 108 | else if ( keycode == HardKey_Backlight ) { |
109 | if ( press ) | 109 | if ( press ) |
110 | emit backlight ( ); | 110 | emit backlight ( ); |
111 | return true; | 111 | return true; |
112 | } | 112 | } |
113 | else if ( keycode == Key_F32 ) { | 113 | else if ( keycode == Key_F32 ) { |
114 | if ( press ) | 114 | if ( press ) |
115 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 115 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
116 | return true; | 116 | return true; |
117 | } | 117 | } |
118 | 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 |
119 | if ( press ) | 119 | if ( press ) |
120 | emit symbol ( ); | 120 | emit symbol ( ); |
121 | return true; | 121 | return true; |
122 | } | 122 | } |
123 | else if ( keycode == Key_NumLock ) { | 123 | else if ( keycode == Key_NumLock ) { |
124 | if ( press ) | 124 | if ( press ) |
125 | emit numLockStateToggle ( ); | 125 | emit numLockStateToggle ( ); |
126 | } | 126 | } |
127 | else if ( keycode == Key_CapsLock ) { | 127 | else if ( keycode == Key_CapsLock ) { |
128 | if ( press ) | 128 | if ( press ) |
129 | emit capsLockStateToggle(); | 129 | emit capsLockStateToggle(); |
130 | } | 130 | } |
131 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { | 131 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { |
132 | if ( m_keyclick_sound ) | 132 | if ( m_keyclick_sound ) |
133 | ODevice::inst ( )-> keySound ( ); | 133 | ODevice::inst ( )-> keySound ( ); |
134 | } | 134 | } |
135 | } | 135 | } |
136 | else if ( e-> type == QWSEvent::Mouse ) { | 136 | else if ( e-> type == QWSEvent::Mouse ) { |
137 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; | 137 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; |
138 | static bool up = true; | 138 | static bool up = true; |
139 | 139 | ||
140 | if ( me-> simpleData. state & LeftButton ) { | 140 | if ( me-> simpleData. state & LeftButton ) { |
141 | if ( up ) { | 141 | if ( up ) { |
142 | up = false; | 142 | up = false; |
143 | if ( m_screentap_sound ) | 143 | if ( m_screentap_sound ) |
144 | ODevice::inst ( ) -> touchSound ( ); | 144 | ODevice::inst ( ) -> touchSound ( ); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | else { | 147 | else { |
148 | up = true; | 148 | up = true; |
149 | } | 149 | } |
150 | } | 150 | } |
151 | #endif | 151 | #endif |
152 | return QPEApplication::qwsEventFilter ( e ); | 152 | return QPEApplication::qwsEventFilter ( e ); |
153 | } | 153 | } |
154 | 154 | ||
155 | #endif | 155 | #endif |
156 | 156 | ||
157 | void OQWSServer::startServers() | 157 | void OQWSServer::startServers() |
158 | { | 158 | { |
159 | // start qcop bridge server | 159 | // start qcop bridge server |
160 | m_qcopBridge = new QCopBridge( 4243 ); | 160 | m_qcopBridge = new QCopBridge( 4243 ); |
161 | if ( !m_qcopBridge->ok() ) { | 161 | if ( !m_qcopBridge->ok() ) { |
162 | delete m_qcopBridge; | 162 | delete m_qcopBridge; |
163 | m_qcopBridge = 0; | 163 | m_qcopBridge = 0; |
164 | } | 164 | } |
165 | // start transfer server | 165 | // start transfer server |
166 | m_transferServer = new TransferServer( 4242 ); | 166 | m_transferServer = new TransferServer( 4242 ); |
167 | if ( !m_transferServer->ok() ) { | 167 | if ( !m_transferServer->ok() ) { |
168 | delete m_transferServer; | 168 | delete m_transferServer; |
169 | m_transferServer = 0; | 169 | m_transferServer = 0; |
170 | } | 170 | } |
171 | //if ( !transferServer || !qcopBridge ) | 171 | //if ( !transferServer || !qcopBridge ) |
172 | // startTimer( 2000 ); | 172 | // startTimer( 2000 ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void OQWSServer::terminateServers() | 175 | void OQWSServer::terminateServers() |
176 | { | 176 | { |
177 | delete m_transferServer; | 177 | delete m_transferServer; |
178 | delete m_qcopBridge; | 178 | delete m_qcopBridge; |
179 | m_transferServer = 0; | 179 | m_transferServer = 0; |
180 | m_qcopBridge = 0; | 180 | m_qcopBridge = 0; |
181 | } | 181 | } |
diff --git a/core/qws/oqwsserver.h b/core/qws/oqwsserver.h index b95c3fb..c8622d4 100644 --- a/core/qws/oqwsserver.h +++ b/core/qws/oqwsserver.h | |||
@@ -1,57 +1,57 @@ | |||
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 | #ifndef __DESKTOP_H__ | 21 | #ifndef __DESKTOP_H__ |
22 | #define __DESKTOP_H__ | 22 | #define __DESKTOP_H__ |
23 | 23 | ||
24 | 24 | ||
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <opie/odevicebutton.h> | 26 | #include <opie2/odevicebutton.h> |
27 | 27 | ||
28 | #include <qwidget.h> | 28 | #include <qwidget.h> |
29 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
30 | 30 | ||
31 | class QCopBridge; | 31 | class QCopBridge; |
32 | class TransferServer; | 32 | class TransferServer; |
33 | 33 | ||
34 | class OQWSServer : public QPEApplication | 34 | class OQWSServer : public QPEApplication |
35 | { | 35 | { |
36 | Q_OBJECT | 36 | Q_OBJECT |
37 | public: | 37 | public: |
38 | OQWSServer( int& argc, char **argv, Type t ); | 38 | OQWSServer( int& argc, char **argv, Type t ); |
39 | ~OQWSServer(); | 39 | ~OQWSServer(); |
40 | 40 | ||
41 | protected: | 41 | protected: |
42 | virtual bool eventFilter ( QObject *o, QEvent *e ); | 42 | virtual bool eventFilter ( QObject *o, QEvent *e ); |
43 | 43 | ||
44 | #ifdef Q_WS_QWS | 44 | #ifdef Q_WS_QWS |
45 | bool qwsEventFilter( QWSEvent * ); | 45 | bool qwsEventFilter( QWSEvent * ); |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | private: | 48 | private: |
49 | void startServers(); | 49 | void startServers(); |
50 | void terminateServers(); | 50 | void terminateServers(); |
51 | 51 | ||
52 | QCopBridge *m_qcopBridge; | 52 | QCopBridge *m_qcopBridge; |
53 | TransferServer *m_transferServer; | 53 | TransferServer *m_transferServer; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | #endif // __DESKTOP_H__ | 56 | #endif // __DESKTOP_H__ |
57 | 57 | ||
diff --git a/core/qws/qws.pro b/core/qws/qws.pro index 5656a59..50d0b2b 100644 --- a/core/qws/qws.pro +++ b/core/qws/qws.pro | |||
@@ -1,20 +1,20 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | DESTDIR = $(OPIEDIR)/bin | 3 | DESTDIR = $(OPIEDIR)/bin |
4 | 4 | ||
5 | HEADERS = \ | 5 | HEADERS = \ |
6 | transferserver.h \ | 6 | transferserver.h \ |
7 | qcopbridge.h \ | 7 | qcopbridge.h \ |
8 | oqwsserver.h | 8 | oqwsserver.h |
9 | SOURCES = \ | 9 | SOURCES = \ |
10 | main.cpp \ | 10 | main.cpp \ |
11 | transferserver.cpp \ | 11 | transferserver.cpp \ |
12 | qcopbridge.cpp \ | 12 | qcopbridge.cpp \ |
13 | oqwsserver.cpp | 13 | oqwsserver.cpp |
14 | 14 | ||
15 | INCLUDEPATH+= $(OPIEDIR)/include | 15 | INCLUDEPATH+= $(OPIEDIR)/include |
16 | DEPENDPATH+= $(OPIEDIR)/include . | 16 | DEPENDPATH+= $(OPIEDIR)/include . |
17 | TARGET = op-qws | 17 | TARGET = qws |
18 | LIBS += -lqpe -lopie | 18 | LIBS += -lqpe -lopiecore2 -lopieui2 |
19 | 19 | ||
20 | include ( $(OPIEDIR)/include.pro ) | 20 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp index daf63ec..d0fec89 100644 --- a/core/qws/transferserver.cpp +++ b/core/qws/transferserver.cpp | |||
@@ -1,323 +1,324 @@ | |||
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 | 32 | ||
33 | #ifndef _OS_LINUX_ | 33 | #ifndef _OS_LINUX_ |
34 | // 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 |
35 | // anywhere ? Therfore I removed it completely.. | 35 | // anywhere ? Therfore I removed it completely.. |
36 | // I think it should be made permanentyl !? (eilers) | 36 | // I think it should be made permanentyl !? (eilers) |
37 | #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)" |
38 | #if 0 | 38 | #if 0 |
39 | 39 | ||
40 | extern "C" | 40 | extern "C" |
41 | { | 41 | { |
42 | #include <uuid/uuid.h> | 42 | #include <uuid/uuid.h> |
43 | #define UUID_H_INCLUDED | 43 | #define UUID_H_INCLUDED |
44 | } | 44 | } |
45 | 45 | ||
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | #endif // not defined linux | 48 | #endif // not defined linux |
49 | 49 | ||
50 | #if defined(_OS_LINUX_) | 50 | #if defined(_OS_LINUX_) |
51 | #include <shadow.h> | 51 | #include <shadow.h> |
52 | #elif defined(Q_OS_MACX) | 52 | #elif defined(Q_OS_MACX) |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | #include <qtextstream.h> | 56 | #include <qtextstream.h> |
57 | #include <qmessagebox.h> | 57 | #include <qmessagebox.h> |
58 | //#include <qpe/qcopchannel_qws.h> | 58 | //#include <qpe/qcopchannel_qws.h> |
59 | #include <qpe/process.h> | 59 | #include <qpe/process.h> |
60 | #include <qpe/global.h> | 60 | #include <qpe/global.h> |
61 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
62 | #include <qpe/contact.h> | 62 | #include <qpe/contact.h> |
63 | #include <qpe/version.h> | 63 | #include <qpe/version.h> |
64 | #include <qpe/qcopenvelope_qws.h> | 64 | #include <qpe/qcopenvelope_qws.h> |
65 | 65 | ||
66 | #include "transferserver.h" | 66 | #include "transferserver.h" |
67 | #include <opie/oprocess.h> | 67 | #include <opie2/oprocess.h> |
68 | using namespace Opie::Core; | ||
68 | 69 | ||
69 | const int block_size = 51200; | 70 | const int block_size = 51200; |
70 | 71 | ||
71 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | 72 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , |
72 | const char* name ) | 73 | const char* name ) |
73 | : QServerSocket( port, 1, parent, name ) | 74 | : QServerSocket( port, 1, parent, name ) |
74 | { | 75 | { |
75 | if ( !ok() ) | 76 | if ( !ok() ) |
76 | qWarning( "Failed to bind to port %d", port ); | 77 | qWarning( "Failed to bind to port %d", port ); |
77 | } | 78 | } |
78 | 79 | ||
79 | TransferServer::~TransferServer() | 80 | TransferServer::~TransferServer() |
80 | { | 81 | { |
81 | } | 82 | } |
82 | 83 | ||
83 | void TransferServer::newConnection( int socket ) | 84 | void TransferServer::newConnection( int socket ) |
84 | { | 85 | { |
85 | (void) new ServerPI( socket, this ); | 86 | (void) new ServerPI( socket, this ); |
86 | } | 87 | } |
87 | 88 | ||
88 | /* | 89 | /* |
89 | * small class in anonymous namespace | 90 | * small class in anonymous namespace |
90 | * to generate a QUUid for us | 91 | * to generate a QUUid for us |
91 | */ | 92 | */ |
92 | namespace | 93 | namespace |
93 | { | 94 | { |
94 | struct UidGen | 95 | struct UidGen |
95 | { | 96 | { |
96 | QString uuid(); | 97 | QString uuid(); |
97 | }; | 98 | }; |
98 | #if defined(Q_OS_MACX) | 99 | #if defined(Q_OS_MACX) |
99 | QString UidGen::uuid() | 100 | QString UidGen::uuid() |
100 | { | 101 | { |
101 | srandom( random() ); | 102 | srandom( random() ); |
102 | QString numStr = QString::number( random() ); | 103 | QString numStr = QString::number( random() ); |
103 | 104 | ||
104 | return "{" + numStr + "}"; | 105 | return "{" + numStr + "}"; |
105 | } | 106 | } |
106 | #elif defined(_OS_LINUX_) | 107 | #elif defined(_OS_LINUX_) |
107 | /* | 108 | /* |
108 | * linux got a /proc/sys/kernel/random/uuid file | 109 | * linux got a /proc/sys/kernel/random/uuid file |
109 | * it'll generate the uuids for us | 110 | * it'll generate the uuids for us |
110 | */ | 111 | */ |
111 | QString UidGen::uuid() | 112 | QString UidGen::uuid() |
112 | { | 113 | { |
113 | QFile file( "/proc/sys/kernel/random/uuid" ); | 114 | QFile file( "/proc/sys/kernel/random/uuid" ); |
114 | if (!file.open(IO_ReadOnly ) ) | 115 | if (!file.open(IO_ReadOnly ) ) |
115 | return QString::null; | 116 | return QString::null; |
116 | 117 | ||
117 | QTextStream stream(&file); | 118 | QTextStream stream(&file); |
118 | 119 | ||
119 | return "{" + stream.read().stripWhiteSpace() + "}"; | 120 | return "{" + stream.read().stripWhiteSpace() + "}"; |
120 | } | 121 | } |
121 | #else | 122 | #else |
122 | QString UidGen::uuid() | 123 | QString UidGen::uuid() |
123 | { | 124 | { |
124 | uuid_t uuid; | 125 | uuid_t uuid; |
125 | ::uuid_generate( uuid ); | 126 | ::uuid_generate( uuid ); |
126 | return QUUid( uuid ).toString(); | 127 | return QUUid( uuid ).toString(); |
127 | } | 128 | } |
128 | #endif | 129 | #endif |
129 | } | 130 | } |
130 | 131 | ||
131 | QString SyncAuthentication::serverId() | 132 | QString SyncAuthentication::serverId() |
132 | { | 133 | { |
133 | Config cfg("Security"); | 134 | Config cfg("Security"); |
134 | cfg.setGroup("Sync"); | 135 | cfg.setGroup("Sync"); |
135 | QString r = cfg.readEntry("serverid"); | 136 | QString r = cfg.readEntry("serverid"); |
136 | if ( r.isEmpty() ) { | 137 | if ( r.isEmpty() ) { |
137 | UidGen gen; | 138 | UidGen gen; |
138 | r = gen.uuid(); | 139 | r = gen.uuid(); |
139 | cfg.writeEntry("serverid", r ); | 140 | cfg.writeEntry("serverid", r ); |
140 | } | 141 | } |
141 | return r; | 142 | return r; |
142 | } | 143 | } |
143 | 144 | ||
144 | QString SyncAuthentication::ownerName() | 145 | QString SyncAuthentication::ownerName() |
145 | { | 146 | { |
146 | QString vfilename = Global::applicationFileName("addressbook", | 147 | QString vfilename = Global::applicationFileName("addressbook", |
147 | "businesscard.vcf"); | 148 | "businesscard.vcf"); |
148 | if (QFile::exists(vfilename)) { | 149 | if (QFile::exists(vfilename)) { |
149 | Contact c; | 150 | Contact c; |
150 | c = Contact::readVCard( vfilename )[0]; | 151 | c = Contact::readVCard( vfilename )[0]; |
151 | return c.fullName(); | 152 | return c.fullName(); |
152 | } | 153 | } |
153 | 154 | ||
154 | return ""; | 155 | return ""; |
155 | } | 156 | } |
156 | 157 | ||
157 | QString SyncAuthentication::loginName() | 158 | QString SyncAuthentication::loginName() |
158 | { | 159 | { |
159 | struct passwd *pw; | 160 | struct passwd *pw; |
160 | pw = getpwuid( geteuid() ); | 161 | pw = getpwuid( geteuid() ); |
161 | return QString::fromLocal8Bit( pw->pw_name ); | 162 | return QString::fromLocal8Bit( pw->pw_name ); |
162 | } | 163 | } |
163 | 164 | ||
164 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | 165 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) |
165 | { | 166 | { |
166 | Config cfg("Security"); | 167 | Config cfg("Security"); |
167 | cfg.setGroup("Sync"); | 168 | cfg.setGroup("Sync"); |
168 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 169 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
169 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); | 170 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); |
170 | 171 | ||
171 | // QHostAddress allowed; | 172 | // QHostAddress allowed; |
172 | // allowed.setAddress(allowedstr); | 173 | // allowed.setAddress(allowedstr); |
173 | // uint auth_peer = allowed.ip4Addr(); | 174 | // uint auth_peer = allowed.ip4Addr(); |
174 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); | 175 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); |
175 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 176 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
176 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); | 177 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); |
177 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 178 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
178 | } | 179 | } |
179 | 180 | ||
180 | bool SyncAuthentication::checkUser( const QString& user ) | 181 | bool SyncAuthentication::checkUser( const QString& user ) |
181 | { | 182 | { |
182 | if ( user.isEmpty() ) | 183 | if ( user.isEmpty() ) |
183 | return FALSE; | 184 | return FALSE; |
184 | QString euser = loginName(); | 185 | QString euser = loginName(); |
185 | return user == euser; | 186 | return user == euser; |
186 | } | 187 | } |
187 | 188 | ||
188 | bool SyncAuthentication::checkPassword( const QString& password ) | 189 | bool SyncAuthentication::checkPassword( const QString& password ) |
189 | { | 190 | { |
190 | #ifdef ALLOW_UNIX_USER_FTP | 191 | #ifdef ALLOW_UNIX_USER_FTP |
191 | // First, check system password... | 192 | // First, check system password... |
192 | 193 | ||
193 | struct passwd *pw = 0; | 194 | struct passwd *pw = 0; |
194 | struct spwd *spw = 0; | 195 | struct spwd *spw = 0; |
195 | 196 | ||
196 | pw = getpwuid( geteuid() ); | 197 | pw = getpwuid( geteuid() ); |
197 | spw = getspnam( pw->pw_name ); | 198 | spw = getspnam( pw->pw_name ); |
198 | 199 | ||
199 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 200 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
200 | if ( cpwd == "x" && spw ) | 201 | if ( cpwd == "x" && spw ) |
201 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 202 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
202 | 203 | ||
203 | // Note: some systems use more than crypt for passwords. | 204 | // Note: some systems use more than crypt for passwords. |
204 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 205 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
205 | if ( cpwd == cpassword ) | 206 | if ( cpwd == cpassword ) |
206 | return TRUE; | 207 | return TRUE; |
207 | #endif | 208 | #endif |
208 | 209 | ||
209 | static int lastdenial = 0; | 210 | static int lastdenial = 0; |
210 | static int denials = 0; | 211 | static int denials = 0; |
211 | int now = time(0); | 212 | int now = time(0); |
212 | 213 | ||
213 | // Detect old Qtopia Desktop (no password) | 214 | // Detect old Qtopia Desktop (no password) |
214 | if ( password.isEmpty() ) { | 215 | if ( password.isEmpty() ) { |
215 | if ( denials < 1 || now > lastdenial + 600 ) { | 216 | if ( denials < 1 || now > lastdenial + 600 ) { |
216 | QMessageBox::warning( 0, tr("Sync Connection"), | 217 | QMessageBox::warning( 0, tr("Sync Connection"), |
217 | tr("<p>An unauthorized system is requesting access to this device." | 218 | tr("<p>An unauthorized system is requesting access to this device." |
218 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 219 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
219 | "please upgrade."), | 220 | "please upgrade."), |
220 | tr("Deny") ); | 221 | tr("Deny") ); |
221 | denials++; | 222 | denials++; |
222 | lastdenial = now; | 223 | lastdenial = now; |
223 | } | 224 | } |
224 | return FALSE; | 225 | return FALSE; |
225 | } | 226 | } |
226 | 227 | ||
227 | // Second, check sync password... | 228 | // Second, check sync password... |
228 | QString pass = password.left(6); | 229 | QString pass = password.left(6); |
229 | /* old QtopiaDesktops are sending | 230 | /* old QtopiaDesktops are sending |
230 | * rootme newer versions got a Qtopia | 231 | * rootme newer versions got a Qtopia |
231 | * prefixed. Qtopia prefix will suceed | 232 | * prefixed. Qtopia prefix will suceed |
232 | * until the sync software syncs up | 233 | * until the sync software syncs up |
233 | * FIXME | 234 | * FIXME |
234 | */ | 235 | */ |
235 | if ( pass == "rootme" || pass == "Qtopia") { | 236 | if ( pass == "rootme" || pass == "Qtopia") { |
236 | 237 | ||
237 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); | 238 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); |
238 | Config cfg("Security"); | 239 | Config cfg("Security"); |
239 | cfg.setGroup("Sync"); | 240 | cfg.setGroup("Sync"); |
240 | QString pwds = cfg.readEntry("Passwords"); | 241 | QString pwds = cfg.readEntry("Passwords"); |
241 | if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) | 242 | if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) |
242 | return TRUE; | 243 | return TRUE; |
243 | 244 | ||
244 | // Unrecognized system. Be careful... | 245 | // Unrecognized system. Be careful... |
245 | 246 | ||
246 | if ( (denials > 2 && now < lastdenial + 600) | 247 | if ( (denials > 2 && now < lastdenial + 600) |
247 | || QMessageBox::warning(0, tr("Sync Connection"), | 248 | || QMessageBox::warning(0, tr("Sync Connection"), |
248 | tr("<p>An unrecognized system is requesting access to this device." | 249 | tr("<p>An unrecognized system is requesting access to this device." |
249 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 250 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
250 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { | 251 | tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { |
251 | denials++; | 252 | denials++; |
252 | lastdenial = now; | 253 | lastdenial = now; |
253 | return FALSE; | 254 | return FALSE; |
254 | } | 255 | } |
255 | else { | 256 | else { |
256 | denials = 0; | 257 | denials = 0; |
257 | cfg.writeEntry("Passwords", pwds + " " + cpassword); | 258 | cfg.writeEntry("Passwords", pwds + " " + cpassword); |
258 | return TRUE; | 259 | return TRUE; |
259 | } | 260 | } |
260 | } | 261 | } |
261 | 262 | ||
262 | return FALSE; | 263 | return FALSE; |
263 | } | 264 | } |
264 | 265 | ||
265 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | 266 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) |
266 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 267 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
267 | { | 268 | { |
268 | state = Connected; | 269 | state = Connected; |
269 | 270 | ||
270 | setSocket( socket ); | 271 | setSocket( socket ); |
271 | 272 | ||
272 | peerport = peerPort(); | 273 | peerport = peerPort(); |
273 | peeraddress = peerAddress(); | 274 | peeraddress = peerAddress(); |
274 | 275 | ||
275 | #ifndef INSECURE | 276 | #ifndef INSECURE |
276 | 277 | ||
277 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 278 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
278 | state = Forbidden; | 279 | state = Forbidden; |
279 | startTimer( 0 ); | 280 | startTimer( 0 ); |
280 | } | 281 | } |
281 | else | 282 | else |
282 | #endif | 283 | #endif |
283 | { | 284 | { |
284 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 285 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
285 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 286 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
286 | 287 | ||
287 | passiv = FALSE; | 288 | passiv = FALSE; |
288 | for ( int i = 0; i < 4; i++ ) | 289 | for ( int i = 0; i < 4; i++ ) |
289 | wait[i] = FALSE; | 290 | wait[i] = FALSE; |
290 | 291 | ||
291 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); | 292 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); |
292 | state = Wait_USER; | 293 | state = Wait_USER; |
293 | 294 | ||
294 | dtp = new ServerDTP( this ); | 295 | dtp = new ServerDTP( this ); |
295 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 296 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
296 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 297 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
297 | connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); | 298 | connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); |
298 | 299 | ||
299 | 300 | ||
300 | directory = QDir::currentDirPath(); | 301 | directory = QDir::currentDirPath(); |
301 | 302 | ||
302 | static int p = 1024; | 303 | static int p = 1024; |
303 | 304 | ||
304 | while ( !serversocket || !serversocket->ok() ) { | 305 | while ( !serversocket || !serversocket->ok() ) { |
305 | delete serversocket; | 306 | delete serversocket; |
306 | serversocket = new ServerSocket( ++p, this ); | 307 | serversocket = new ServerSocket( ++p, this ); |
307 | } | 308 | } |
308 | connect( serversocket, SIGNAL( newIncomming(int) ), | 309 | connect( serversocket, SIGNAL( newIncomming(int) ), |
309 | SLOT( newConnection(int) ) ); | 310 | SLOT( newConnection(int) ) ); |
310 | } | 311 | } |
311 | } | 312 | } |
312 | 313 | ||
313 | ServerPI::~ServerPI() | 314 | ServerPI::~ServerPI() |
314 | { | 315 | { |
315 | } | 316 | } |
316 | 317 | ||
317 | void ServerPI::connectionClosed() | 318 | void ServerPI::connectionClosed() |
318 | { | 319 | { |
319 | // qDebug( "Debug: Connection closed" ); | 320 | // qDebug( "Debug: Connection closed" ); |
320 | delete this; | 321 | delete this; |
321 | } | 322 | } |
322 | 323 | ||
323 | void ServerPI::send( const QString& msg ) | 324 | void ServerPI::send( const QString& msg ) |
@@ -796,640 +797,640 @@ void ServerPI::dtpCompleted() | |||
796 | QString fn = dtp->fileName(); | 797 | QString fn = dtp->fileName(); |
797 | if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) { | 798 | if ( fn.right(8) == ".desktop" && fn.find("/Documents/") >= 0 ) { |
798 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 799 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
799 | e << fn; | 800 | e << fn; |
800 | } | 801 | } |
801 | } | 802 | } |
802 | waitsocket = 0; | 803 | waitsocket = 0; |
803 | dtp->close(); | 804 | dtp->close(); |
804 | } | 805 | } |
805 | 806 | ||
806 | void ServerPI::dtpFailed() | 807 | void ServerPI::dtpFailed() |
807 | { | 808 | { |
808 | dtp->close(); | 809 | dtp->close(); |
809 | waitsocket = 0; | 810 | waitsocket = 0; |
810 | send( "451 Requested action aborted: local error in processing" ); | 811 | send( "451 Requested action aborted: local error in processing" ); |
811 | } | 812 | } |
812 | 813 | ||
813 | void ServerPI::dtpError( int ) | 814 | void ServerPI::dtpError( int ) |
814 | { | 815 | { |
815 | dtp->close(); | 816 | dtp->close(); |
816 | waitsocket = 0; | 817 | waitsocket = 0; |
817 | send( "451 Requested action aborted: local error in processing" ); | 818 | send( "451 Requested action aborted: local error in processing" ); |
818 | } | 819 | } |
819 | 820 | ||
820 | bool ServerPI::sendList( const QString& arg ) | 821 | bool ServerPI::sendList( const QString& arg ) |
821 | { | 822 | { |
822 | QByteArray listing; | 823 | QByteArray listing; |
823 | QBuffer buffer( listing ); | 824 | QBuffer buffer( listing ); |
824 | 825 | ||
825 | if ( !buffer.open( IO_WriteOnly ) ) | 826 | if ( !buffer.open( IO_WriteOnly ) ) |
826 | return FALSE; | 827 | return FALSE; |
827 | 828 | ||
828 | QTextStream ts( &buffer ); | 829 | QTextStream ts( &buffer ); |
829 | QString fn = arg; | 830 | QString fn = arg; |
830 | 831 | ||
831 | if ( fn.isEmpty() ) | 832 | if ( fn.isEmpty() ) |
832 | fn = directory.path(); | 833 | fn = directory.path(); |
833 | 834 | ||
834 | QFileInfo fi( fn ); | 835 | QFileInfo fi( fn ); |
835 | if ( !fi.exists() ) | 836 | if ( !fi.exists() ) |
836 | return FALSE; | 837 | return FALSE; |
837 | 838 | ||
838 | // return file listing | 839 | // return file listing |
839 | if ( fi.isFile() ) { | 840 | if ( fi.isFile() ) { |
840 | ts << fileListing( &fi ) << endl; | 841 | ts << fileListing( &fi ) << endl; |
841 | } | 842 | } |
842 | 843 | ||
843 | // return directory listing | 844 | // return directory listing |
844 | else if ( fi.isDir() ) { | 845 | else if ( fi.isDir() ) { |
845 | QDir dir( fn ); | 846 | QDir dir( fn ); |
846 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); | 847 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); |
847 | 848 | ||
848 | QFileInfoListIterator it( *list ); | 849 | QFileInfoListIterator it( *list ); |
849 | QFileInfo *info; | 850 | QFileInfo *info; |
850 | 851 | ||
851 | unsigned long total = 0; | 852 | unsigned long total = 0; |
852 | while ( ( info = it.current() ) ) { | 853 | while ( ( info = it.current() ) ) { |
853 | if ( info->fileName() != "." && info->fileName() != ".." ) | 854 | if ( info->fileName() != "." && info->fileName() != ".." ) |
854 | total += info->size(); | 855 | total += info->size(); |
855 | ++it; | 856 | ++it; |
856 | } | 857 | } |
857 | 858 | ||
858 | ts << "total " << QString::number( total / 1024 ) << endl; | 859 | ts << "total " << QString::number( total / 1024 ) << endl; |
859 | 860 | ||
860 | it.toFirst(); | 861 | it.toFirst(); |
861 | while ( ( info = it.current() ) ) { | 862 | while ( ( info = it.current() ) ) { |
862 | if ( info->fileName() == "." || info->fileName() == ".." ) { | 863 | if ( info->fileName() == "." || info->fileName() == ".." ) { |
863 | ++it; | 864 | ++it; |
864 | continue; | 865 | continue; |
865 | } | 866 | } |
866 | ts << fileListing( info ) << endl; | 867 | ts << fileListing( info ) << endl; |
867 | ++it; | 868 | ++it; |
868 | } | 869 | } |
869 | } | 870 | } |
870 | 871 | ||
871 | if ( passiv ) { | 872 | if ( passiv ) { |
872 | waitarray = buffer.buffer(); | 873 | waitarray = buffer.buffer(); |
873 | wait[SendByteArray] = TRUE; | 874 | wait[SendByteArray] = TRUE; |
874 | if ( waitsocket ) | 875 | if ( waitsocket ) |
875 | newConnection( waitsocket ); | 876 | newConnection( waitsocket ); |
876 | } | 877 | } |
877 | else | 878 | else |
878 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); | 879 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); |
879 | return TRUE; | 880 | return TRUE; |
880 | } | 881 | } |
881 | 882 | ||
882 | QString ServerPI::fileListing( QFileInfo *info ) | 883 | QString ServerPI::fileListing( QFileInfo *info ) |
883 | { | 884 | { |
884 | if ( !info ) | 885 | if ( !info ) |
885 | return QString::null; | 886 | return QString::null; |
886 | QString s; | 887 | QString s; |
887 | 888 | ||
888 | // type char | 889 | // type char |
889 | if ( info->isDir() ) | 890 | if ( info->isDir() ) |
890 | s += "d"; | 891 | s += "d"; |
891 | else if ( info->isSymLink() ) | 892 | else if ( info->isSymLink() ) |
892 | s += "l"; | 893 | s += "l"; |
893 | else | 894 | else |
894 | s += "-"; | 895 | s += "-"; |
895 | 896 | ||
896 | // permisson string | 897 | // permisson string |
897 | s += permissionString( info ) + " "; | 898 | s += permissionString( info ) + " "; |
898 | 899 | ||
899 | // number of hardlinks | 900 | // number of hardlinks |
900 | int subdirs = 1; | 901 | int subdirs = 1; |
901 | 902 | ||
902 | if ( info->isDir() ) | 903 | if ( info->isDir() ) |
903 | subdirs = 2; | 904 | subdirs = 2; |
904 | // FIXME : this is to slow | 905 | // FIXME : this is to slow |
905 | //if ( info->isDir() ) | 906 | //if ( info->isDir() ) |
906 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); | 907 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); |
907 | 908 | ||
908 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; | 909 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; |
909 | 910 | ||
910 | // owner | 911 | // owner |
911 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; | 912 | s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; |
912 | 913 | ||
913 | // group | 914 | // group |
914 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; | 915 | s += info->group().leftJustify( 8, ' ', TRUE ) + " "; |
915 | 916 | ||
916 | // file size in bytes | 917 | // file size in bytes |
917 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; | 918 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; |
918 | 919 | ||
919 | // last modified date | 920 | // last modified date |
920 | QDate date = info->lastModified().date(); | 921 | QDate date = info->lastModified().date(); |
921 | QTime time = info->lastModified().time(); | 922 | QTime time = info->lastModified().time(); |
922 | s += date.monthName( date.month() ) + " " | 923 | s += date.monthName( date.month() ) + " " |
923 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " | 924 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " |
924 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" | 925 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" |
925 | + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " "; | 926 | + QString::number( time.minute() ).rightJustify( 2, '0', TRUE ) + " "; |
926 | 927 | ||
927 | // file name | 928 | // file name |
928 | s += info->fileName(); | 929 | s += info->fileName(); |
929 | 930 | ||
930 | return s; | 931 | return s; |
931 | } | 932 | } |
932 | 933 | ||
933 | QString ServerPI::permissionString( QFileInfo *info ) | 934 | QString ServerPI::permissionString( QFileInfo *info ) |
934 | { | 935 | { |
935 | if ( !info ) | 936 | if ( !info ) |
936 | return QString( "---------" ); | 937 | return QString( "---------" ); |
937 | QString s; | 938 | QString s; |
938 | 939 | ||
939 | // user | 940 | // user |
940 | if ( info->permission( QFileInfo::ReadUser ) ) | 941 | if ( info->permission( QFileInfo::ReadUser ) ) |
941 | s += "r"; | 942 | s += "r"; |
942 | else | 943 | else |
943 | s += "-"; | 944 | s += "-"; |
944 | if ( info->permission( QFileInfo::WriteUser ) ) | 945 | if ( info->permission( QFileInfo::WriteUser ) ) |
945 | s += "w"; | 946 | s += "w"; |
946 | else | 947 | else |
947 | s += "-"; | 948 | s += "-"; |
948 | if ( info->permission( QFileInfo::ExeUser ) ) | 949 | if ( info->permission( QFileInfo::ExeUser ) ) |
949 | s += "x"; | 950 | s += "x"; |
950 | else | 951 | else |
951 | s += "-"; | 952 | s += "-"; |
952 | 953 | ||
953 | // group | 954 | // group |
954 | if ( info->permission( QFileInfo::ReadGroup ) ) | 955 | if ( info->permission( QFileInfo::ReadGroup ) ) |
955 | s += "r"; | 956 | s += "r"; |
956 | else | 957 | else |
957 | s += "-"; | 958 | s += "-"; |
958 | if ( info->permission( QFileInfo::WriteGroup ) ) | 959 | if ( info->permission( QFileInfo::WriteGroup ) ) |
959 | s += "w"; | 960 | s += "w"; |
960 | else | 961 | else |
961 | s += "-"; | 962 | s += "-"; |
962 | if ( info->permission( QFileInfo::ExeGroup ) ) | 963 | if ( info->permission( QFileInfo::ExeGroup ) ) |
963 | s += "x"; | 964 | s += "x"; |
964 | else | 965 | else |
965 | s += "-"; | 966 | s += "-"; |
966 | 967 | ||
967 | // exec | 968 | // exec |
968 | if ( info->permission( QFileInfo::ReadOther ) ) | 969 | if ( info->permission( QFileInfo::ReadOther ) ) |
969 | s += "r"; | 970 | s += "r"; |
970 | else | 971 | else |
971 | s += "-"; | 972 | s += "-"; |
972 | if ( info->permission( QFileInfo::WriteOther ) ) | 973 | if ( info->permission( QFileInfo::WriteOther ) ) |
973 | s += "w"; | 974 | s += "w"; |
974 | else | 975 | else |
975 | s += "-"; | 976 | s += "-"; |
976 | if ( info->permission( QFileInfo::ExeOther ) ) | 977 | if ( info->permission( QFileInfo::ExeOther ) ) |
977 | s += "x"; | 978 | s += "x"; |
978 | else | 979 | else |
979 | s += "-"; | 980 | s += "-"; |
980 | 981 | ||
981 | return s; | 982 | return s; |
982 | } | 983 | } |
983 | 984 | ||
984 | void ServerPI::newConnection( int socket ) | 985 | void ServerPI::newConnection( int socket ) |
985 | { | 986 | { |
986 | //qDebug( "New incomming connection" ); | 987 | //qDebug( "New incomming connection" ); |
987 | 988 | ||
988 | if ( !passiv ) | 989 | if ( !passiv ) |
989 | return ; | 990 | return ; |
990 | 991 | ||
991 | if ( wait[SendFile] ) { | 992 | if ( wait[SendFile] ) { |
992 | QStringList targets; | 993 | QStringList targets; |
993 | if ( backupRestoreGzip( waitfile, targets ) ) | 994 | if ( backupRestoreGzip( waitfile, targets ) ) |
994 | dtp->sendGzipFile( waitfile, targets ); | 995 | dtp->sendGzipFile( waitfile, targets ); |
995 | else | 996 | else |
996 | dtp->sendFile( waitfile ); | 997 | dtp->sendFile( waitfile ); |
997 | dtp->setSocket( socket ); | 998 | dtp->setSocket( socket ); |
998 | } | 999 | } |
999 | else if ( wait[RetrieveFile] ) { | 1000 | else if ( wait[RetrieveFile] ) { |
1000 | qDebug("check retrieve file"); | 1001 | qDebug("check retrieve file"); |
1001 | if ( backupRestoreGzip( waitfile ) ) | 1002 | if ( backupRestoreGzip( waitfile ) ) |
1002 | dtp->retrieveGzipFile( waitfile ); | 1003 | dtp->retrieveGzipFile( waitfile ); |
1003 | else | 1004 | else |
1004 | dtp->retrieveFile( waitfile ); | 1005 | dtp->retrieveFile( waitfile ); |
1005 | dtp->setSocket( socket ); | 1006 | dtp->setSocket( socket ); |
1006 | } | 1007 | } |
1007 | else if ( wait[SendByteArray] ) { | 1008 | else if ( wait[SendByteArray] ) { |
1008 | dtp->sendByteArray( waitarray ); | 1009 | dtp->sendByteArray( waitarray ); |
1009 | dtp->setSocket( socket ); | 1010 | dtp->setSocket( socket ); |
1010 | } | 1011 | } |
1011 | else if ( wait[RetrieveByteArray] ) { | 1012 | else if ( wait[RetrieveByteArray] ) { |
1012 | qDebug("retrieve byte array"); | 1013 | qDebug("retrieve byte array"); |
1013 | dtp->retrieveByteArray(); | 1014 | dtp->retrieveByteArray(); |
1014 | dtp->setSocket( socket ); | 1015 | dtp->setSocket( socket ); |
1015 | } | 1016 | } |
1016 | else | 1017 | else |
1017 | waitsocket = socket; | 1018 | waitsocket = socket; |
1018 | 1019 | ||
1019 | for ( int i = 0; i < 4; i++ ) | 1020 | for ( int i = 0; i < 4; i++ ) |
1020 | wait[i] = FALSE; | 1021 | wait[i] = FALSE; |
1021 | } | 1022 | } |
1022 | 1023 | ||
1023 | QString ServerPI::absFilePath( const QString& file ) | 1024 | QString ServerPI::absFilePath( const QString& file ) |
1024 | { | 1025 | { |
1025 | if ( file.isEmpty() ) | 1026 | if ( file.isEmpty() ) |
1026 | return file; | 1027 | return file; |
1027 | 1028 | ||
1028 | QString filepath( file ); | 1029 | QString filepath( file ); |
1029 | if ( file[0] != "/" ) | 1030 | if ( file[0] != "/" ) |
1030 | filepath = directory.path() + "/" + file; | 1031 | filepath = directory.path() + "/" + file; |
1031 | 1032 | ||
1032 | return filepath; | 1033 | return filepath; |
1033 | } | 1034 | } |
1034 | 1035 | ||
1035 | 1036 | ||
1036 | void ServerPI::timerEvent( QTimerEvent * ) | 1037 | void ServerPI::timerEvent( QTimerEvent * ) |
1037 | { | 1038 | { |
1038 | connectionClosed(); | 1039 | connectionClosed(); |
1039 | } | 1040 | } |
1040 | 1041 | ||
1041 | 1042 | ||
1042 | ServerDTP::ServerDTP( QObject *parent, const char* name) | 1043 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
1043 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 1044 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
1044 | retrieveTargzProc( 0 ), gzipProc( 0 ) | 1045 | retrieveTargzProc( 0 ), gzipProc( 0 ) |
1045 | { | 1046 | { |
1046 | 1047 | ||
1047 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1048 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1048 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1049 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1049 | connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); | 1050 | connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); |
1050 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1051 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1051 | 1052 | ||
1052 | gzipProc = new OProcess( this, "gzipProc" ); | 1053 | gzipProc = new Opie::Core::OProcess( this, "gzipProc" ); |
1053 | 1054 | ||
1054 | createTargzProc = new OProcess( QString("tar"), this, "createTargzProc"); | 1055 | createTargzProc = new Opie::Core::OProcess( QString("tar"), this, "createTargzProc"); |
1055 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1056 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1056 | connect( createTargzProc, SIGNAL( processExited(OProcess*) ), SLOT( targzDone() ) ); | 1057 | connect( createTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), SLOT( targzDone() ) ); |
1057 | 1058 | ||
1058 | QStringList args = "tar"; | 1059 | QStringList args = "tar"; |
1059 | args += "-xv"; | 1060 | args += "-xv"; |
1060 | retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" ); | 1061 | retrieveTargzProc = new Opie::Core::OProcess( args, this, "retrieveTargzProc" ); |
1061 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1062 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1062 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess*) ), | 1063 | connect( retrieveTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), |
1063 | SIGNAL( completed() ) ); | 1064 | SIGNAL( completed() ) ); |
1064 | connect( retrieveTargzProc, SIGNAL( processExited(OProcess*) ), | 1065 | connect( retrieveTargzProc, SIGNAL( processExited(Opie::Core::OProcess*) ), |
1065 | SLOT( extractTarDone() ) ); | 1066 | SLOT( extractTarDone() ) ); |
1066 | } | 1067 | } |
1067 | 1068 | ||
1068 | ServerDTP::~ServerDTP() | 1069 | ServerDTP::~ServerDTP() |
1069 | { | 1070 | { |
1070 | buf.close(); | 1071 | buf.close(); |
1071 | file.close(); | 1072 | file.close(); |
1072 | createTargzProc->kill(); | 1073 | createTargzProc->kill(); |
1073 | } | 1074 | } |
1074 | 1075 | ||
1075 | void ServerDTP::extractTarDone() | 1076 | void ServerDTP::extractTarDone() |
1076 | { | 1077 | { |
1077 | qDebug("extract done"); | 1078 | qDebug("extract done"); |
1078 | #ifndef QT_NO_COP | 1079 | #ifndef QT_NO_COP |
1079 | 1080 | ||
1080 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); | 1081 | QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); |
1081 | e << file.name(); | 1082 | e << file.name(); |
1082 | #endif | 1083 | #endif |
1083 | } | 1084 | } |
1084 | 1085 | ||
1085 | void ServerDTP::connected() | 1086 | void ServerDTP::connected() |
1086 | { | 1087 | { |
1087 | // send file mode | 1088 | // send file mode |
1088 | switch ( mode ) { | 1089 | switch ( mode ) { |
1089 | case SendFile : | 1090 | case SendFile : |
1090 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 1091 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
1091 | emit failed(); | 1092 | emit failed(); |
1092 | mode = Idle; | 1093 | mode = Idle; |
1093 | return ; | 1094 | return ; |
1094 | } | 1095 | } |
1095 | 1096 | ||
1096 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 1097 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); |
1097 | 1098 | ||
1098 | bytes_written = 0; | 1099 | bytes_written = 0; |
1099 | if ( file.size() == 0 ) { | 1100 | if ( file.size() == 0 ) { |
1100 | //make sure it doesn't hang on empty files | 1101 | //make sure it doesn't hang on empty files |
1101 | file.close(); | 1102 | file.close(); |
1102 | emit completed(); | 1103 | emit completed(); |
1103 | mode = Idle; | 1104 | mode = Idle; |
1104 | } | 1105 | } |
1105 | else { | 1106 | else { |
1106 | 1107 | ||
1107 | if ( !file.atEnd() ) { | 1108 | if ( !file.atEnd() ) { |
1108 | QCString s; | 1109 | QCString s; |
1109 | s.resize( block_size ); | 1110 | s.resize( block_size ); |
1110 | int bytes = file.readBlock( s.data(), block_size ); | 1111 | int bytes = file.readBlock( s.data(), block_size ); |
1111 | writeBlock( s.data(), bytes ); | 1112 | writeBlock( s.data(), bytes ); |
1112 | } | 1113 | } |
1113 | } | 1114 | } |
1114 | break; | 1115 | break; |
1115 | case SendGzipFile: | 1116 | case SendGzipFile: |
1116 | if ( createTargzProc->isRunning() ) { | 1117 | if ( createTargzProc->isRunning() ) { |
1117 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY | 1118 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY |
1118 | qWarning("Previous tar --gzip process is still running; killing it..."); | 1119 | qWarning("Previous tar --gzip process is still running; killing it..."); |
1119 | createTargzProc->kill(); | 1120 | createTargzProc->kill(); |
1120 | } | 1121 | } |
1121 | 1122 | ||
1122 | bytes_written = 0; | 1123 | bytes_written = 0; |
1123 | qDebug("==>start send tar process"); | 1124 | qDebug("==>start send tar process"); |
1124 | if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) | 1125 | if ( !createTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdout) ) |
1125 | qWarning("Error starting %s or %s", | 1126 | qWarning("Error starting %s or %s", |
1126 | createTargzProc->args()[0].data(), | 1127 | createTargzProc->args()[0].data(), |
1127 | gzipProc->args()[0].data()); | 1128 | gzipProc->args()[0].data()); |
1128 | break; | 1129 | break; |
1129 | case SendBuffer: | 1130 | case SendBuffer: |
1130 | if ( !buf.open( IO_ReadOnly) ) { | 1131 | if ( !buf.open( IO_ReadOnly) ) { |
1131 | emit failed(); | 1132 | emit failed(); |
1132 | mode = Idle; | 1133 | mode = Idle; |
1133 | return ; | 1134 | return ; |
1134 | } | 1135 | } |
1135 | 1136 | ||
1136 | // qDebug( "Debug: Sending byte array" ); | 1137 | // qDebug( "Debug: Sending byte array" ); |
1137 | bytes_written = 0; | 1138 | bytes_written = 0; |
1138 | while ( !buf.atEnd() ) | 1139 | while ( !buf.atEnd() ) |
1139 | putch( buf.getch() ); | 1140 | putch( buf.getch() ); |
1140 | buf.close(); | 1141 | buf.close(); |
1141 | break; | 1142 | break; |
1142 | case RetrieveFile: | 1143 | case RetrieveFile: |
1143 | // retrieve file mode | 1144 | // retrieve file mode |
1144 | if ( file.exists() && !file.remove() ) { | 1145 | if ( file.exists() && !file.remove() ) { |
1145 | emit failed(); | 1146 | emit failed(); |
1146 | mode = Idle; | 1147 | mode = Idle; |
1147 | return ; | 1148 | return ; |
1148 | } | 1149 | } |
1149 | 1150 | ||
1150 | if ( !file.open( IO_WriteOnly) ) { | 1151 | if ( !file.open( IO_WriteOnly) ) { |
1151 | emit failed(); | 1152 | emit failed(); |
1152 | mode = Idle; | 1153 | mode = Idle; |
1153 | return ; | 1154 | return ; |
1154 | } | 1155 | } |
1155 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); | 1156 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); |
1156 | break; | 1157 | break; |
1157 | case RetrieveGzipFile: | 1158 | case RetrieveGzipFile: |
1158 | qDebug("=-> starting tar process to receive .tgz file"); | 1159 | qDebug("=-> starting tar process to receive .tgz file"); |
1159 | break; | 1160 | break; |
1160 | case RetrieveBuffer: | 1161 | case RetrieveBuffer: |
1161 | // retrieve buffer mode | 1162 | // retrieve buffer mode |
1162 | if ( !buf.open( IO_WriteOnly) ) { | 1163 | if ( !buf.open( IO_WriteOnly) ) { |
1163 | emit failed(); | 1164 | emit failed(); |
1164 | mode = Idle; | 1165 | mode = Idle; |
1165 | return ; | 1166 | return ; |
1166 | } | 1167 | } |
1167 | // qDebug( "Debug: Retrieving byte array" ); | 1168 | // qDebug( "Debug: Retrieving byte array" ); |
1168 | break; | 1169 | break; |
1169 | case Idle: | 1170 | case Idle: |
1170 | qDebug("connection established but mode set to Idle; BUG!"); | 1171 | qDebug("connection established but mode set to Idle; BUG!"); |
1171 | break; | 1172 | break; |
1172 | } | 1173 | } |
1173 | } | 1174 | } |
1174 | 1175 | ||
1175 | void ServerDTP::connectionClosed() | 1176 | void ServerDTP::connectionClosed() |
1176 | { | 1177 | { |
1177 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); | 1178 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); |
1178 | 1179 | ||
1179 | // send file mode | 1180 | // send file mode |
1180 | if ( SendFile == mode ) { | 1181 | if ( SendFile == mode ) { |
1181 | if ( bytes_written == file.size() ) | 1182 | if ( bytes_written == file.size() ) |
1182 | emit completed(); | 1183 | emit completed(); |
1183 | else | 1184 | else |
1184 | emit failed(); | 1185 | emit failed(); |
1185 | } | 1186 | } |
1186 | 1187 | ||
1187 | // send buffer mode | 1188 | // send buffer mode |
1188 | else if ( SendBuffer == mode ) { | 1189 | else if ( SendBuffer == mode ) { |
1189 | if ( bytes_written == buf.size() ) | 1190 | if ( bytes_written == buf.size() ) |
1190 | emit completed(); | 1191 | emit completed(); |
1191 | else | 1192 | else |
1192 | emit failed(); | 1193 | emit failed(); |
1193 | } | 1194 | } |
1194 | 1195 | ||
1195 | // retrieve file mode | 1196 | // retrieve file mode |
1196 | else if ( RetrieveFile == mode ) { | 1197 | else if ( RetrieveFile == mode ) { |
1197 | file.close(); | 1198 | file.close(); |
1198 | emit completed(); | 1199 | emit completed(); |
1199 | } | 1200 | } |
1200 | 1201 | ||
1201 | else if ( RetrieveGzipFile == mode ) { | 1202 | else if ( RetrieveGzipFile == mode ) { |
1202 | qDebug("Done writing ungzip file; closing input"); | 1203 | qDebug("Done writing ungzip file; closing input"); |
1203 | gzipProc->flushStdin(); | 1204 | gzipProc->flushStdin(); |
1204 | gzipProc->closeStdin(); | 1205 | gzipProc->closeStdin(); |
1205 | } | 1206 | } |
1206 | 1207 | ||
1207 | // retrieve buffer mode | 1208 | // retrieve buffer mode |
1208 | else if ( RetrieveBuffer == mode ) { | 1209 | else if ( RetrieveBuffer == mode ) { |
1209 | buf.close(); | 1210 | buf.close(); |
1210 | emit completed(); | 1211 | emit completed(); |
1211 | } | 1212 | } |
1212 | 1213 | ||
1213 | mode = Idle; | 1214 | mode = Idle; |
1214 | } | 1215 | } |
1215 | 1216 | ||
1216 | void ServerDTP::bytesWritten( int bytes ) | 1217 | void ServerDTP::bytesWritten( int bytes ) |
1217 | { | 1218 | { |
1218 | bytes_written += bytes; | 1219 | bytes_written += bytes; |
1219 | 1220 | ||
1220 | // send file mode | 1221 | // send file mode |
1221 | if ( SendFile == mode ) { | 1222 | if ( SendFile == mode ) { |
1222 | 1223 | ||
1223 | if ( bytes_written == file.size() ) { | 1224 | if ( bytes_written == file.size() ) { |
1224 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); | 1225 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); |
1225 | file.close(); | 1226 | file.close(); |
1226 | emit completed(); | 1227 | emit completed(); |
1227 | mode = Idle; | 1228 | mode = Idle; |
1228 | } | 1229 | } |
1229 | else if ( !file.atEnd() ) { | 1230 | else if ( !file.atEnd() ) { |
1230 | QCString s; | 1231 | QCString s; |
1231 | s.resize( block_size ); | 1232 | s.resize( block_size ); |
1232 | int bytes = file.readBlock( s.data(), block_size ); | 1233 | int bytes = file.readBlock( s.data(), block_size ); |
1233 | writeBlock( s.data(), bytes ); | 1234 | writeBlock( s.data(), bytes ); |
1234 | } | 1235 | } |
1235 | } | 1236 | } |
1236 | 1237 | ||
1237 | // send buffer mode | 1238 | // send buffer mode |
1238 | if ( SendBuffer == mode ) { | 1239 | if ( SendBuffer == mode ) { |
1239 | 1240 | ||
1240 | if ( bytes_written == buf.size() ) { | 1241 | if ( bytes_written == buf.size() ) { |
1241 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1242 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); |
1242 | emit completed(); | 1243 | emit completed(); |
1243 | mode = Idle; | 1244 | mode = Idle; |
1244 | } | 1245 | } |
1245 | } | 1246 | } |
1246 | } | 1247 | } |
1247 | 1248 | ||
1248 | void ServerDTP::readyRead() | 1249 | void ServerDTP::readyRead() |
1249 | { | 1250 | { |
1250 | // retrieve file mode | 1251 | // retrieve file mode |
1251 | if ( RetrieveFile == mode ) { | 1252 | if ( RetrieveFile == mode ) { |
1252 | QCString s; | 1253 | QCString s; |
1253 | s.resize( bytesAvailable() ); | 1254 | s.resize( bytesAvailable() ); |
1254 | readBlock( s.data(), bytesAvailable() ); | 1255 | readBlock( s.data(), bytesAvailable() ); |
1255 | file.writeBlock( s.data(), s.size() ); | 1256 | file.writeBlock( s.data(), s.size() ); |
1256 | } | 1257 | } |
1257 | else if ( RetrieveGzipFile == mode ) { | 1258 | else if ( RetrieveGzipFile == mode ) { |
1258 | if ( !gzipProc->isRunning() ) | 1259 | if ( !gzipProc->isRunning() ) |
1259 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); | 1260 | gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout )); |
1260 | 1261 | ||
1261 | QByteArray s; | 1262 | QByteArray s; |
1262 | s.resize( bytesAvailable() ); | 1263 | s.resize( bytesAvailable() ); |
1263 | readBlock( s.data(), bytesAvailable() ); | 1264 | readBlock( s.data(), bytesAvailable() ); |
1264 | gzipProc->writeStdin( s.data(), s.size() ); | 1265 | gzipProc->writeStdin( s.data(), s.size() ); |
1265 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1266 | qDebug("wrote %d bytes to ungzip ", s.size() ); |
1266 | } | 1267 | } |
1267 | // retrieve buffer mode | 1268 | // retrieve buffer mode |
1268 | else if ( RetrieveBuffer == mode ) { | 1269 | else if ( RetrieveBuffer == mode ) { |
1269 | QCString s; | 1270 | QCString s; |
1270 | s.resize( bytesAvailable() ); | 1271 | s.resize( bytesAvailable() ); |
1271 | readBlock( s.data(), bytesAvailable() ); | 1272 | readBlock( s.data(), bytesAvailable() ); |
1272 | buf.writeBlock( s.data(), s.size() ); | 1273 | buf.writeBlock( s.data(), s.size() ); |
1273 | } | 1274 | } |
1274 | } | 1275 | } |
1275 | 1276 | ||
1276 | void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) | 1277 | void ServerDTP::writeTargzBlock(Opie::Core::OProcess *, char *buffer, int buflen) |
1277 | { | 1278 | { |
1278 | writeBlock( buffer, buflen ); | 1279 | writeBlock( buffer, buflen ); |
1279 | qDebug("writeTargzBlock %d", buflen); | 1280 | qDebug("writeTargzBlock %d", buflen); |
1280 | if ( !createTargzProc->isRunning() ) { | 1281 | if ( !createTargzProc->isRunning() ) { |
1281 | qDebug("tar and gzip done"); | 1282 | qDebug("tar and gzip done"); |
1282 | emit completed(); | 1283 | emit completed(); |
1283 | mode = Idle; | 1284 | mode = Idle; |
1284 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), | 1285 | disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), |
1285 | this, SLOT( writeTargzBlock(OProcess*,char*,int) ) ); | 1286 | this, SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) ); |
1286 | } | 1287 | } |
1287 | } | 1288 | } |
1288 | 1289 | ||
1289 | void ServerDTP::targzDone() | 1290 | void ServerDTP::targzDone() |
1290 | { | 1291 | { |
1291 | //qDebug("targz done"); | 1292 | //qDebug("targz done"); |
1292 | disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), | 1293 | disconnect( createTargzProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), |
1293 | this, SLOT( gzipTarBlock(OProcess*,char*,int) ) ); | 1294 | this, SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) ); |
1294 | gzipProc->closeStdin(); | 1295 | gzipProc->closeStdin(); |
1295 | } | 1296 | } |
1296 | 1297 | ||
1297 | void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen) | 1298 | void ServerDTP::gzipTarBlock(Opie::Core::OProcess *, char *buffer, int buflen) |
1298 | { | 1299 | { |
1299 | //qDebug("gzipTarBlock"); | 1300 | //qDebug("gzipTarBlock"); |
1300 | if ( !gzipProc->isRunning() ) { | 1301 | if ( !gzipProc->isRunning() ) { |
1301 | //qDebug("auto start gzip proc"); | 1302 | //qDebug("auto start gzip proc"); |
1302 | gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); | 1303 | gzipProc->start(Opie::Core::OProcess::NotifyOnExit, (Opie::Core::OProcess::Communication) ( Opie::Core::OProcess::Stdin | Opie::Core::OProcess::Stdout )); |
1303 | } | 1304 | } |
1304 | gzipProc->writeStdin( buffer, buflen ); | 1305 | gzipProc->writeStdin( buffer, buflen ); |
1305 | } | 1306 | } |
1306 | 1307 | ||
1307 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1308 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1308 | { | 1309 | { |
1309 | file.setName( fn ); | 1310 | file.setName( fn ); |
1310 | mode = SendFile; | 1311 | mode = SendFile; |
1311 | connectToHost( host.toString(), port ); | 1312 | connectToHost( host.toString(), port ); |
1312 | } | 1313 | } |
1313 | 1314 | ||
1314 | void ServerDTP::sendFile( const QString fn ) | 1315 | void ServerDTP::sendFile( const QString fn ) |
1315 | { | 1316 | { |
1316 | file.setName( fn ); | 1317 | file.setName( fn ); |
1317 | mode = SendFile; | 1318 | mode = SendFile; |
1318 | } | 1319 | } |
1319 | 1320 | ||
1320 | void ServerDTP::sendGzipFile( const QString &fn, | 1321 | void ServerDTP::sendGzipFile( const QString &fn, |
1321 | const QStringList &archiveTargets, | 1322 | const QStringList &archiveTargets, |
1322 | const QHostAddress& host, Q_UINT16 port ) | 1323 | const QHostAddress& host, Q_UINT16 port ) |
1323 | { | 1324 | { |
1324 | sendGzipFile( fn, archiveTargets ); | 1325 | sendGzipFile( fn, archiveTargets ); |
1325 | connectToHost( host.toString(), port ); | 1326 | connectToHost( host.toString(), port ); |
1326 | } | 1327 | } |
1327 | 1328 | ||
1328 | void ServerDTP::sendGzipFile( const QString &fn, | 1329 | void ServerDTP::sendGzipFile( const QString &fn, |
1329 | const QStringList &archiveTargets ) | 1330 | const QStringList &archiveTargets ) |
1330 | { | 1331 | { |
1331 | mode = SendGzipFile; | 1332 | mode = SendGzipFile; |
1332 | file.setName( fn ); | 1333 | file.setName( fn ); |
1333 | 1334 | ||
1334 | QStringList args = "tar"; | 1335 | QStringList args = "tar"; |
1335 | args += "-cv"; | 1336 | args += "-cv"; |
1336 | args += archiveTargets; | 1337 | args += archiveTargets; |
1337 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1338 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); |
1338 | createTargzProc->clearArguments( ); | 1339 | createTargzProc->clearArguments( ); |
1339 | *createTargzProc << args; | 1340 | *createTargzProc << args; |
1340 | connect( createTargzProc, | 1341 | connect( createTargzProc, |
1341 | SIGNAL( receivedStdout(OProcess*,char*,int) ), SLOT( gzipTarBlock(OProcess*,char*,int) ) ); | 1342 | SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), SLOT( gzipTarBlock(Opie::Core::OProcess*,char*,int) ) ); |
1342 | 1343 | ||
1343 | gzipProc->clearArguments( ); | 1344 | gzipProc->clearArguments( ); |
1344 | *gzipProc << "gzip"; | 1345 | *gzipProc << "gzip"; |
1345 | connect( gzipProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), | 1346 | connect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), |
1346 | SLOT( writeTargzBlock(OProcess*,char*,int) ) ); | 1347 | SLOT( writeTargzBlock(Opie::Core::OProcess*,char*,int) ) ); |
1347 | } | 1348 | } |
1348 | 1349 | ||
1349 | void ServerDTP::gunzipDone() | 1350 | void ServerDTP::gunzipDone() |
1350 | { | 1351 | { |
1351 | qDebug("gunzipDone"); | 1352 | qDebug("gunzipDone"); |
1352 | disconnect( gzipProc, SIGNAL( processExited() ), | 1353 | disconnect( gzipProc, SIGNAL( processExited() ), |
1353 | this, SLOT( gunzipDone() ) ); | 1354 | this, SLOT( gunzipDone() ) ); |
1354 | retrieveTargzProc->closeStdin(); | 1355 | retrieveTargzProc->closeStdin(); |
1355 | disconnect( gzipProc, SIGNAL( receivedStdout(OProcess*,char*,int) ), | 1356 | disconnect( gzipProc, SIGNAL( receivedStdout(Opie::Core::OProcess*,char*,int) ), |
1356 | this, SLOT( tarExtractBlock(OProcess*,char*,int) ) ); | 1357 | this, SLOT( tarExtractBlock(Opie::Core::OProcess*,char*,int) ) ); |
1357 | } | 1358 | } |
1358 | 1359 | ||
1359 | void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen) | 1360 | void ServerDTP::tarExtractBlock(Opie::Core::OProcess *, char *buffer, int buflen) |
1360 | { | 1361 | { |
1361 | qDebug("tarExtractBlock"); | 1362 | qDebug("tarExtractBlock"); |
1362 | if ( !retrieveTargzProc->isRunning() ) { | 1363 | if ( !retrieveTargzProc->isRunning() ) { |
1363 | qDebug("auto start ungzip proc"); | 1364 | qDebug("auto start ungzip proc"); |
1364 | if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) ) | 1365 | if ( !retrieveTargzProc->start(Opie::Core::OProcess::NotifyOnExit, Opie::Core::OProcess::Stdin) ) |
1365 | qWarning(" failed to start tar -x process"); | 1366 | qWarning(" failed to start tar -x process"); |
1366 | } | 1367 | } |
1367 | retrieveTargzProc->writeStdin( buffer, buflen ); | 1368 | retrieveTargzProc->writeStdin( buffer, buflen ); |
1368 | } | 1369 | } |
1369 | 1370 | ||
1370 | 1371 | ||
1371 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1372 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1372 | { | 1373 | { |
1373 | file.setName( fn ); | 1374 | file.setName( fn ); |
1374 | mode = RetrieveFile; | 1375 | mode = RetrieveFile; |
1375 | connectToHost( host.toString(), port ); | 1376 | connectToHost( host.toString(), port ); |
1376 | } | 1377 | } |
1377 | 1378 | ||
1378 | void ServerDTP::retrieveFile( const QString fn ) | 1379 | void ServerDTP::retrieveFile( const QString fn ) |
1379 | { | 1380 | { |
1380 | file.setName( fn ); | 1381 | file.setName( fn ); |
1381 | mode = RetrieveFile; | 1382 | mode = RetrieveFile; |
1382 | } | 1383 | } |
1383 | 1384 | ||
1384 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1385 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1385 | { | 1386 | { |
1386 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1387 | qDebug("retrieveGzipFile %s", fn.latin1()); |
1387 | file.setName( fn ); | 1388 | file.setName( fn ); |
1388 | mode = RetrieveGzipFile; | 1389 | mode = RetrieveGzipFile; |
1389 | 1390 | ||
1390 | gzipProc->clearArguments(); | 1391 | gzipProc->clearArguments(); |
1391 | *gzipProc << "gunzip"; | 1392 | *gzipProc << "gunzip"; |
1392 | connect( gzipProc, SIGNAL( readyReadStdout() ), | 1393 | connect( gzipProc, SIGNAL( readyReadStdout() ), |
1393 | SLOT( tarExtractBlock() ) ); | 1394 | SLOT( tarExtractBlock() ) ); |
1394 | connect( gzipProc, SIGNAL( processExited() ), | 1395 | connect( gzipProc, SIGNAL( processExited() ), |
1395 | SLOT( gunzipDone() ) ); | 1396 | SLOT( gunzipDone() ) ); |
1396 | } | 1397 | } |
1397 | 1398 | ||
1398 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1399 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |
1399 | { | 1400 | { |
1400 | retrieveGzipFile( fn ); | 1401 | retrieveGzipFile( fn ); |
1401 | connectToHost( host.toString(), port ); | 1402 | connectToHost( host.toString(), port ); |
1402 | } | 1403 | } |
1403 | 1404 | ||
1404 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) | 1405 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) |
1405 | { | 1406 | { |
1406 | buf.setBuffer( array ); | 1407 | buf.setBuffer( array ); |
1407 | mode = SendBuffer; | 1408 | mode = SendBuffer; |
1408 | connectToHost( host.toString(), port ); | 1409 | connectToHost( host.toString(), port ); |
1409 | } | 1410 | } |
1410 | 1411 | ||
1411 | void ServerDTP::sendByteArray( const QByteArray& array ) | 1412 | void ServerDTP::sendByteArray( const QByteArray& array ) |
1412 | { | 1413 | { |
1413 | buf.setBuffer( array ); | 1414 | buf.setBuffer( array ); |
1414 | mode = SendBuffer; | 1415 | mode = SendBuffer; |
1415 | } | 1416 | } |
1416 | 1417 | ||
1417 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) | 1418 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) |
1418 | { | 1419 | { |
1419 | buf.setBuffer( QByteArray() ); | 1420 | buf.setBuffer( QByteArray() ); |
1420 | mode = RetrieveBuffer; | 1421 | mode = RetrieveBuffer; |
1421 | connectToHost( host.toString(), port ); | 1422 | connectToHost( host.toString(), port ); |
1422 | } | 1423 | } |
1423 | 1424 | ||
1424 | void ServerDTP::retrieveByteArray() | 1425 | void ServerDTP::retrieveByteArray() |
1425 | { | 1426 | { |
1426 | buf.setBuffer( QByteArray() ); | 1427 | buf.setBuffer( QByteArray() ); |
1427 | mode = RetrieveBuffer; | 1428 | mode = RetrieveBuffer; |
1428 | } | 1429 | } |
1429 | 1430 | ||
1430 | void ServerDTP::setSocket( int socket ) | 1431 | void ServerDTP::setSocket( int socket ) |
1431 | { | 1432 | { |
1432 | QSocket::setSocket( socket ); | 1433 | QSocket::setSocket( socket ); |
1433 | connected(); | 1434 | connected(); |
1434 | } | 1435 | } |
1435 | 1436 | ||
diff --git a/core/qws/transferserver.h b/core/qws/transferserver.h index 1c5ab4b..82dae40 100644 --- a/core/qws/transferserver.h +++ b/core/qws/transferserver.h | |||
@@ -1,179 +1,180 @@ | |||
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 | #include <qserversocket.h> | 20 | #include <qserversocket.h> |
21 | #include <qsocket.h> | 21 | #include <qsocket.h> |
22 | #include <qdir.h> | 22 | #include <qdir.h> |
23 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qbuffer.h> | 24 | #include <qbuffer.h> |
25 | 25 | ||
26 | class QFileInfo; | 26 | class QFileInfo; |
27 | class OProcess; | 27 | namespace Opie { namespace Core { class OProcess; } } |
28 | |||
28 | class TransferServer : public QServerSocket | 29 | class TransferServer : public QServerSocket |
29 | { | 30 | { |
30 | Q_OBJECT | 31 | Q_OBJECT |
31 | 32 | ||
32 | public: | 33 | public: |
33 | TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); | 34 | TransferServer( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); |
34 | virtual ~TransferServer(); | 35 | virtual ~TransferServer(); |
35 | 36 | ||
36 | void newConnection( int socket ); | 37 | void newConnection( int socket ); |
37 | }; | 38 | }; |
38 | 39 | ||
39 | class SyncAuthentication : QObject | 40 | class SyncAuthentication : QObject |
40 | { | 41 | { |
41 | Q_OBJECT | 42 | Q_OBJECT |
42 | 43 | ||
43 | public: | 44 | public: |
44 | static int isAuthorized(QHostAddress peeraddress); | 45 | static int isAuthorized(QHostAddress peeraddress); |
45 | static bool checkPassword(const QString& pw); | 46 | static bool checkPassword(const QString& pw); |
46 | static bool checkUser(const QString& user); | 47 | static bool checkUser(const QString& user); |
47 | 48 | ||
48 | static QString serverId(); | 49 | static QString serverId(); |
49 | static QString loginName(); | 50 | static QString loginName(); |
50 | static QString ownerName(); | 51 | static QString ownerName(); |
51 | }; | 52 | }; |
52 | 53 | ||
53 | 54 | ||
54 | class ServerDTP : public QSocket | 55 | class ServerDTP : public QSocket |
55 | { | 56 | { |
56 | Q_OBJECT | 57 | Q_OBJECT |
57 | 58 | ||
58 | public: | 59 | public: |
59 | ServerDTP( QObject *parent = 0, const char* name = 0 ); | 60 | ServerDTP( QObject *parent = 0, const char* name = 0 ); |
60 | ~ServerDTP(); | 61 | ~ServerDTP(); |
61 | 62 | ||
62 | enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer, | 63 | enum Mode{ Idle = 0, SendFile, SendGzipFile, SendBuffer, |
63 | RetrieveFile, RetrieveGzipFile, RetrieveBuffer }; | 64 | RetrieveFile, RetrieveGzipFile, RetrieveBuffer }; |
64 | 65 | ||
65 | void sendFile( const QString fn ); | 66 | void sendFile( const QString fn ); |
66 | void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); | 67 | void sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); |
67 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets ); | 68 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets ); |
68 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets, | 69 | void sendGzipFile( const QString &fn, const QStringList &archiveTargets, |
69 | const QHostAddress& host, Q_UINT16 port ); | 70 | const QHostAddress& host, Q_UINT16 port ); |
70 | void sendByteArray( const QByteArray& array ); | 71 | void sendByteArray( const QByteArray& array ); |
71 | void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ); | 72 | void sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ); |
72 | 73 | ||
73 | void retrieveFile( const QString fn ); | 74 | void retrieveFile( const QString fn ); |
74 | void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); | 75 | void retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ); |
75 | void retrieveGzipFile( const QString &fn ); | 76 | void retrieveGzipFile( const QString &fn ); |
76 | void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ); | 77 | void retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ); |
77 | void retrieveByteArray(); | 78 | void retrieveByteArray(); |
78 | void retrieveByteArray( const QHostAddress& host, Q_UINT16 port ); | 79 | void retrieveByteArray( const QHostAddress& host, Q_UINT16 port ); |
79 | 80 | ||
80 | Mode dtpMode() { return mode; } | 81 | Mode dtpMode() { return mode; } |
81 | QByteArray buffer() { return buf.buffer(); } | 82 | QByteArray buffer() { return buf.buffer(); } |
82 | QString fileName() const { return file.name(); } | 83 | QString fileName() const { return file.name(); } |
83 | 84 | ||
84 | void setSocket( int socket ); | 85 | void setSocket( int socket ); |
85 | 86 | ||
86 | signals: | 87 | signals: |
87 | void completed(); | 88 | void completed(); |
88 | void failed(); | 89 | void failed(); |
89 | 90 | ||
90 | private slots: | 91 | private slots: |
91 | void connectionClosed(); | 92 | void connectionClosed(); |
92 | void connected(); | 93 | void connected(); |
93 | void bytesWritten( int bytes ); | 94 | void bytesWritten( int bytes ); |
94 | void readyRead(); | 95 | void readyRead(); |
95 | void writeTargzBlock(OProcess *, char *, int); | 96 | void writeTargzBlock(Opie::Core::OProcess *, char *, int); |
96 | void targzDone(); | 97 | void targzDone(); |
97 | 98 | ||
98 | void gzipTarBlock(OProcess *, char *, int); | 99 | void gzipTarBlock(Opie::Core::OProcess *, char *, int); |
99 | void tarExtractBlock(OProcess *, char *, int); | 100 | void tarExtractBlock(Opie::Core::OProcess *, char *, int); |
100 | void gunzipDone(); | 101 | void gunzipDone(); |
101 | void extractTarDone(); | 102 | void extractTarDone(); |
102 | 103 | ||
103 | private: | 104 | private: |
104 | 105 | ||
105 | unsigned long bytes_written; | 106 | unsigned long bytes_written; |
106 | Mode mode; | 107 | Mode mode; |
107 | QFile file; | 108 | QFile file; |
108 | QBuffer buf; | 109 | QBuffer buf; |
109 | OProcess *createTargzProc; | 110 | Opie::Core::OProcess *createTargzProc; |
110 | OProcess *retrieveTargzProc; | 111 | Opie::Core::OProcess *retrieveTargzProc; |
111 | OProcess *gzipProc; | 112 | Opie::Core::OProcess *gzipProc; |
112 | }; | 113 | }; |
113 | 114 | ||
114 | class ServerSocket : public QServerSocket | 115 | class ServerSocket : public QServerSocket |
115 | { | 116 | { |
116 | Q_OBJECT | 117 | Q_OBJECT |
117 | 118 | ||
118 | public: | 119 | public: |
119 | ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ) | 120 | ServerSocket( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ) |
120 | : QServerSocket( port, 1, parent, name ) {} | 121 | : QServerSocket( port, 1, parent, name ) {} |
121 | 122 | ||
122 | void newConnection( int socket ) { emit newIncomming( socket ); } | 123 | void newConnection( int socket ) { emit newIncomming( socket ); } |
123 | signals: | 124 | signals: |
124 | void newIncomming( int socket ); | 125 | void newIncomming( int socket ); |
125 | }; | 126 | }; |
126 | 127 | ||
127 | class ServerPI : public QSocket | 128 | class ServerPI : public QSocket |
128 | { | 129 | { |
129 | Q_OBJECT | 130 | Q_OBJECT |
130 | 131 | ||
131 | enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; | 132 | enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; |
132 | enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 }; | 133 | enum Transfer { SendFile = 0, RetrieveFile = 1, SendByteArray = 2, RetrieveByteArray = 3 }; |
133 | 134 | ||
134 | public: | 135 | public: |
135 | ServerPI( int socket, QObject *parent = 0, const char* name = 0 ); | 136 | ServerPI( int socket, QObject *parent = 0, const char* name = 0 ); |
136 | virtual ~ServerPI(); | 137 | virtual ~ServerPI(); |
137 | 138 | ||
138 | protected slots: | 139 | protected slots: |
139 | void read(); | 140 | void read(); |
140 | void send( const QString& msg ); | 141 | void send( const QString& msg ); |
141 | void process( const QString& command ); | 142 | void process( const QString& command ); |
142 | void connectionClosed(); | 143 | void connectionClosed(); |
143 | void dtpCompleted(); | 144 | void dtpCompleted(); |
144 | void dtpFailed(); | 145 | void dtpFailed(); |
145 | void dtpError( int ); | 146 | void dtpError( int ); |
146 | void newConnection( int socket ); | 147 | void newConnection( int socket ); |
147 | 148 | ||
148 | protected: | 149 | protected: |
149 | bool checkReadFile( const QString& file ); | 150 | bool checkReadFile( const QString& file ); |
150 | bool checkWriteFile( const QString& file ); | 151 | bool checkWriteFile( const QString& file ); |
151 | bool parsePort( const QString& pw ); | 152 | bool parsePort( const QString& pw ); |
152 | bool backupRestoreGzip( const QString &file, QStringList &targets ); | 153 | bool backupRestoreGzip( const QString &file, QStringList &targets ); |
153 | bool backupRestoreGzip( const QString &file ); | 154 | bool backupRestoreGzip( const QString &file ); |
154 | 155 | ||
155 | bool sendList( const QString& arg ); | 156 | bool sendList( const QString& arg ); |
156 | void sendFile( const QString& file ); | 157 | void sendFile( const QString& file ); |
157 | void retrieveFile( const QString& file ); | 158 | void retrieveFile( const QString& file ); |
158 | 159 | ||
159 | QString permissionString( QFileInfo *info ); | 160 | QString permissionString( QFileInfo *info ); |
160 | QString fileListing( QFileInfo *info ); | 161 | QString fileListing( QFileInfo *info ); |
161 | QString absFilePath( const QString& file ); | 162 | QString absFilePath( const QString& file ); |
162 | 163 | ||
163 | void timerEvent( QTimerEvent *e ); | 164 | void timerEvent( QTimerEvent *e ); |
164 | 165 | ||
165 | private: | 166 | private: |
166 | State state; | 167 | State state; |
167 | Q_UINT16 peerport; | 168 | Q_UINT16 peerport; |
168 | QHostAddress peeraddress; | 169 | QHostAddress peeraddress; |
169 | bool passiv; | 170 | bool passiv; |
170 | bool wait[4]; | 171 | bool wait[4]; |
171 | ServerDTP *dtp; | 172 | ServerDTP *dtp; |
172 | ServerSocket *serversocket; | 173 | ServerSocket *serversocket; |
173 | QString waitfile; | 174 | QString waitfile; |
174 | QDir directory; | 175 | QDir directory; |
175 | QByteArray waitarray; | 176 | QByteArray waitarray; |
176 | QString renameFrom; | 177 | QString renameFrom; |
177 | QString lastCommand; | 178 | QString lastCommand; |
178 | int waitsocket; | 179 | int waitsocket; |
179 | }; | 180 | }; |