summaryrefslogtreecommitdiff
authorzecke <zecke>2002-09-06 21:35:13 (UTC)
committer zecke <zecke>2002-09-06 21:35:13 (UTC)
commite95e14f056ce6be658a4fd0d4737168431e92d88 (patch) (unidiff)
tree732f0a69b2063dc6c54444486223fd99879da72c
parent5536f65e60b3c662d2da3636e617faaad02522db (diff)
downloadopie-e95e14f056ce6be658a4fd0d4737168431e92d88.zip
opie-e95e14f056ce6be658a4fd0d4737168431e92d88.tar.gz
opie-e95e14f056ce6be658a4fd0d4737168431e92d88.tar.bz2
Remove the libuuid dependency for Linux targets...
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcher.pro2
-rw-r--r--core/launcher/opie-taskbar.control2
-rw-r--r--core/launcher/transferserver.cpp59
3 files changed, 49 insertions, 14 deletions
diff --git a/core/launcher/launcher.pro b/core/launcher/launcher.pro
index bae5c51..5b32bc3 100644
--- a/core/launcher/launcher.pro
+++ b/core/launcher/launcher.pro
@@ -70,49 +70,49 @@ SOURCES = background.cpp \
70 ../../rsync/checksum.c \ 70 ../../rsync/checksum.c \
71 ../../rsync/command.c \ 71 ../../rsync/command.c \
72 ../../rsync/delta.c \ 72 ../../rsync/delta.c \
73 ../../rsync/emit.c \ 73 ../../rsync/emit.c \
74 ../../rsync/hex.c \ 74 ../../rsync/hex.c \
75 ../../rsync/job.c \ 75 ../../rsync/job.c \
76 ../../rsync/mdfour.c \ 76 ../../rsync/mdfour.c \
77 ../../rsync/mksum.c \ 77 ../../rsync/mksum.c \
78 ../../rsync/msg.c \ 78 ../../rsync/msg.c \
79 ../../rsync/netint.c \ 79 ../../rsync/netint.c \
80 ../../rsync/patch.c \ 80 ../../rsync/patch.c \
81 ../../rsync/prototab.c \ 81 ../../rsync/prototab.c \
82 ../../rsync/readsums.c \ 82 ../../rsync/readsums.c \
83 ../../rsync/scoop.c \ 83 ../../rsync/scoop.c \
84 ../../rsync/search.c \ 84 ../../rsync/search.c \
85 ../../rsync/stats.c \ 85 ../../rsync/stats.c \
86 ../../rsync/stream.c \ 86 ../../rsync/stream.c \
87 ../../rsync/sumset.c \ 87 ../../rsync/sumset.c \
88 ../../rsync/trace.c \ 88 ../../rsync/trace.c \
89 ../../rsync/tube.c \ 89 ../../rsync/tube.c \
90 ../../rsync/util.c \ 90 ../../rsync/util.c \
91 ../../rsync/version.c \ 91 ../../rsync/version.c \
92 ../../rsync/whole.c \ 92 ../../rsync/whole.c \
93 ../../rsync/qrsync.cpp 93 ../../rsync/qrsync.cpp
94 INTERFACES= syncdialog.ui 94 INTERFACES= syncdialog.ui
95INCLUDEPATH += ../../include 95INCLUDEPATH += ../../include
96 DEPENDPATH+= ../../include . 96 DEPENDPATH+= ../../include .
97INCLUDEPATH += ../../core/apps/calibrate 97INCLUDEPATH += ../../core/apps/calibrate
98 DEPENDPATH+= ../../core/apps/calibrate 98 DEPENDPATH+= ../../core/apps/calibrate
99INCLUDEPATH += ../../rsync 99INCLUDEPATH += ../../rsync
100 DEPENDPATH+= ../../rsync 100 DEPENDPATH+= ../../rsync
101 TARGET = qpe 101 TARGET = qpe
102 LIBS += -lqpe -lcrypt -lopie -luuid 102 LIBS += -lqpe -lcrypt -lopie
103 103
104TRANSLATIONS = ../../i18n/de/qpe.ts \ 104TRANSLATIONS = ../../i18n/de/qpe.ts \
105 ../../i18n/en/qpe.ts \ 105 ../../i18n/en/qpe.ts \
106 ../../i18n/es/qpe.ts \ 106 ../../i18n/es/qpe.ts \
107 ../../i18n/fr/qpe.ts \ 107 ../../i18n/fr/qpe.ts \
108 ../../i18n/hu/qpe.ts \ 108 ../../i18n/hu/qpe.ts \
109 ../../i18n/ja/qpe.ts \ 109 ../../i18n/ja/qpe.ts \
110 ../../i18n/ko/qpe.ts \ 110 ../../i18n/ko/qpe.ts \
111 ../../i18n/no/qpe.ts \ 111 ../../i18n/no/qpe.ts \
112 ../../i18n/pl/qpe.ts \ 112 ../../i18n/pl/qpe.ts \
113 ../../i18n/pt/qpe.ts \ 113 ../../i18n/pt/qpe.ts \
114 ../../i18n/pt_BR/qpe.ts \ 114 ../../i18n/pt_BR/qpe.ts \
115 ../../i18n/sl/qpe.ts \ 115 ../../i18n/sl/qpe.ts \
116 ../../i18n/zh_CN/qpe.ts \ 116 ../../i18n/zh_CN/qpe.ts \
117 ../../i18n/it/qpe.ts \ 117 ../../i18n/it/qpe.ts \
118 ../../i18n/zh_TW/qpe.ts 118 ../../i18n/zh_TW/qpe.ts
diff --git a/core/launcher/opie-taskbar.control b/core/launcher/opie-taskbar.control
index ce73d8b..e9338fb 100644
--- a/core/launcher/opie-taskbar.control
+++ b/core/launcher/opie-taskbar.control
@@ -1,9 +1,9 @@
1Files: bin/qpe apps/Settings/Calibrate.desktop pics/launcher 1Files: bin/qpe apps/Settings/Calibrate.desktop pics/launcher
2Priority: required 2Priority: required
3Section: opie/system 3Section: opie/system
4Maintainer: Project Opie <opie@handhelds.org> 4Maintainer: Project Opie <opie@handhelds.org>
5Architecture: arm 5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION.1 6Version: $QPE_VERSION-$SUB_VERSION.1
7Depends: qt-embedded (>=$QTE_VERSION), libuuid1 7Depends: qt-embedded (>=$QTE_VERSION)
8Description: Launcher for Opie 8Description: Launcher for Opie
9 The "finder" or "explorer", or whatever you want to call it. 9 The "finder" or "explorer", or whatever you want to call it.
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 9d18b7b..a20df2f 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,263 +1,298 @@
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#include <shadow.h> 26#include <shadow.h>
27 27
28#ifndef _OS_LINUX_
29
28extern "C" { 30extern "C" {
29#include <uuid/uuid.h> 31#include <uuid/uuid.h>
30#define UUID_H_INCLUDED 32#define UUID_H_INCLUDED
31} 33}
32 34
35#endif // not defined linux
36
33#if defined(_OS_LINUX_) 37#if defined(_OS_LINUX_)
34#include <shadow.h> 38#include <shadow.h>
35#endif 39#endif
36 40
37#include <qdir.h> 41#include <qdir.h>
38#include <qfile.h> 42#include <qfile.h>
39#include <qtextstream.h> 43#include <qtextstream.h>
40#include <qdatastream.h> 44#include <qdatastream.h>
41#include <qmessagebox.h> 45#include <qmessagebox.h>
42#include <qstringlist.h> 46#include <qstringlist.h>
43#include <qfileinfo.h> 47#include <qfileinfo.h>
44#include <qregexp.h> 48#include <qregexp.h>
45//#include <qpe/qcopchannel_qws.h> 49//#include <qpe/qcopchannel_qws.h>
46#include <qpe/process.h> 50#include <qpe/process.h>
47#include <qpe/global.h> 51#include <qpe/global.h>
48#include <qpe/config.h> 52#include <qpe/config.h>
49#include <qpe/contact.h> 53#include <qpe/contact.h>
50#include <qpe/quuid.h> 54#include <qpe/quuid.h>
51#include <qpe/version.h> 55#include <qpe/version.h>
52#ifdef QWS 56#ifdef QWS
53#include <qpe/qcopenvelope_qws.h> 57#include <qpe/qcopenvelope_qws.h>
54#endif 58#endif
55 59
56#include "transferserver.h" 60#include "transferserver.h"
57#include "qprocess.h" 61#include "qprocess.h"
58 62
59const int block_size = 51200; 63const int block_size = 51200;
60 64
61TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 65TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
62 const char* name ) 66 const char* name )
63 : QServerSocket( port, 1, parent, name ) 67 : QServerSocket( port, 1, parent, name )
64{ 68{
65 if ( !ok() ) 69 if ( !ok() )
66 qWarning( "Failed to bind to port %d", port ); 70 qWarning( "Failed to bind to port %d", port );
67} 71}
68 72
69TransferServer::~TransferServer() 73TransferServer::~TransferServer()
70{ 74{
71 75
72} 76}
73 77
74void TransferServer::newConnection( int socket ) 78void TransferServer::newConnection( int socket )
75{ 79{
76 (void) new ServerPI( socket, this ); 80 (void) new ServerPI( socket, this );
77} 81}
78 82
83/*
84 * small class in anonymous namespace
85 * to generate a QUUid for us
86 */
87namespace {
88 struct UidGen {
89 QString uuid();
90 };
91#if defined(_OS_LINUX_)
92 /*
93 * linux got a /proc/sys/kernel/random/uuid file
94 * it'll generate the uuids for us
95 */
96 QString UidGen::uuid() {
97 QFile file( "/proc/sys/kernel/random/uuid" );
98 if (!file.open(IO_ReadOnly ) )
99 return QString::null;
100
101 QTextStream stream(&file);
102
103 return "{" + stream.read().stripWhiteSpace() + "}";
104 }
105#else
106 QString UidGen::uuid() {
107 uuid_t uuid;
108 uuid_generate( uuid );
109 return QUUid( uuid ).toString();
110 }
111#endif
112}
113
79QString SyncAuthentication::serverId() 114QString SyncAuthentication::serverId()
80{ 115{
81 Config cfg("Security"); 116 Config cfg("Security");
82 cfg.setGroup("Sync"); 117 cfg.setGroup("Sync");
83 QString r=cfg.readEntry("serverid"); 118 QString r=cfg.readEntry("serverid");
84 if ( r.isEmpty() ) { 119 if ( r.isEmpty() ) {
85 uuid_t uuid; 120 UidGen gen;
86 uuid_generate( uuid ); 121 r = gen.uuid();
87 cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); 122 cfg.writeEntry("serverid", r );
88 } 123 }
89 return r; 124 return r;
90} 125}
91 126
92QString SyncAuthentication::ownerName() 127QString SyncAuthentication::ownerName()
93{ 128{
94 QString vfilename = Global::applicationFileName("addressbook", 129 QString vfilename = Global::applicationFileName("addressbook",
95 "businesscard.vcf"); 130 "businesscard.vcf");
96 if (QFile::exists(vfilename)) { 131 if (QFile::exists(vfilename)) {
97 Contact c; 132 Contact c;
98 c = Contact::readVCard( vfilename )[0]; 133 c = Contact::readVCard( vfilename )[0];
99 return c.fullName(); 134 return c.fullName();
100 } 135 }
101 136
102 return ""; 137 return "";
103} 138}
104 139
105QString SyncAuthentication::loginName() 140QString SyncAuthentication::loginName()
106{ 141{
107 struct passwd *pw; 142 struct passwd *pw;
108 pw = getpwuid( geteuid() ); 143 pw = getpwuid( geteuid() );
109 return QString::fromLocal8Bit( pw->pw_name ); 144 return QString::fromLocal8Bit( pw->pw_name );
110} 145}
111 146
112int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 147int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
113{ 148{
114 Config cfg("Security"); 149 Config cfg("Security");
115 cfg.setGroup("Sync"); 150 cfg.setGroup("Sync");
116// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 151// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
117 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 152 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
118 153
119// QHostAddress allowed; 154// QHostAddress allowed;
120// allowed.setAddress(allowedstr); 155// allowed.setAddress(allowedstr);
121// uint auth_peer = allowed.ip4Addr(); 156// uint auth_peer = allowed.ip4Addr();
122 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
123 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 158 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
124 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); 159 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
125 return (peeraddress.ip4Addr() & mask) == auth_peer; 160 return (peeraddress.ip4Addr() & mask) == auth_peer;
126} 161}
127 162
128bool SyncAuthentication::checkUser( const QString& user ) 163bool SyncAuthentication::checkUser( const QString& user )
129{ 164{
130 if ( user.isEmpty() ) return FALSE; 165 if ( user.isEmpty() ) return FALSE;
131 QString euser = loginName(); 166 QString euser = loginName();
132 return user == euser; 167 return user == euser;
133} 168}
134 169
135bool SyncAuthentication::checkPassword( const QString& password ) 170bool SyncAuthentication::checkPassword( const QString& password )
136{ 171{
137#ifdef ALLOW_UNIX_USER_FTP 172#ifdef ALLOW_UNIX_USER_FTP
138 // First, check system password... 173 // First, check system password...
139 174
140 struct passwd *pw = 0; 175 struct passwd *pw = 0;
141 struct spwd *spw = 0; 176 struct spwd *spw = 0;
142 177
143 pw = getpwuid( geteuid() ); 178 pw = getpwuid( geteuid() );
144 spw = getspnam( pw->pw_name ); 179 spw = getspnam( pw->pw_name );
145 180
146 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 181 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
147 if ( cpwd == "x" && spw ) 182 if ( cpwd == "x" && spw )
148 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 183 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
149 184
150 // Note: some systems use more than crypt for passwords. 185 // Note: some systems use more than crypt for passwords.
151 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 186 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
152 if ( cpwd == cpassword ) 187 if ( cpwd == cpassword )
153 return TRUE; 188 return TRUE;
154#endif 189#endif
155 190
156 static int lastdenial=0; 191 static int lastdenial=0;
157 static int denials=0; 192 static int denials=0;
158 int now = time(0); 193 int now = time(0);
159 194
160 // Detect old Qtopia Desktop (no password) 195 // Detect old Qtopia Desktop (no password)
161 if ( password.isEmpty() ) { 196 if ( password.isEmpty() ) {
162 if ( denials < 1 || now > lastdenial+600 ) { 197 if ( denials < 1 || now > lastdenial+600 ) {
163 QMessageBox::warning( 0,tr("Sync Connection"), 198 QMessageBox::warning( 0,tr("Sync Connection"),
164 tr("<p>An unauthorized system is requesting access to this device." 199 tr("<p>An unauthorized system is requesting access to this device."
165 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 200 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
166 "please upgrade."), 201 "please upgrade."),
167 tr("Deny") ); 202 tr("Deny") );
168 denials++; 203 denials++;
169 lastdenial=now; 204 lastdenial=now;
170 } 205 }
171 return FALSE; 206 return FALSE;
172 } 207 }
173 208
174 // Second, check sync password... 209 // Second, check sync password...
175 QString pass = password.left(6); 210 QString pass = password.left(6);
176 /* old QtopiaDesktops are sending 211 /* old QtopiaDesktops are sending
177 * rootme newer versions got a Qtopia 212 * rootme newer versions got a Qtopia
178 * prefixed. Qtopia prefix will suceed 213 * prefixed. Qtopia prefix will suceed
179 * until the sync software syncs up 214 * until the sync software syncs up
180 * FIXME 215 * FIXME
181 */ 216 */
182 if ( pass == "rootme" || pass == "Qtopia") { 217 if ( pass == "rootme" || pass == "Qtopia") {
183 218
184 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 219 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
185 Config cfg("Security"); 220 Config cfg("Security");
186 cfg.setGroup("Sync"); 221 cfg.setGroup("Sync");
187 QString pwds = cfg.readEntry("Passwords"); 222 QString pwds = cfg.readEntry("Passwords");
188 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) 223 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
189 return TRUE; 224 return TRUE;
190 225
191 // Unrecognized system. Be careful... 226 // Unrecognized system. Be careful...
192 227
193 if ( (denials > 2 && now < lastdenial+600) 228 if ( (denials > 2 && now < lastdenial+600)
194 || QMessageBox::warning(0,tr("Sync Connection"), 229 || QMessageBox::warning(0,tr("Sync Connection"),
195 tr("<p>An unrecognized system is requesting access to this device." 230 tr("<p>An unrecognized system is requesting access to this device."
196 "<p>If you have just initiated a Sync for the first time, this is normal."), 231 "<p>If you have just initiated a Sync for the first time, this is normal."),
197 tr("Allow"),tr("Deny"))==1 ) 232 tr("Allow"),tr("Deny"))==1 )
198 { 233 {
199 denials++; 234 denials++;
200 lastdenial=now; 235 lastdenial=now;
201 return FALSE; 236 return FALSE;
202 } else { 237 } else {
203 denials=0; 238 denials=0;
204 cfg.writeEntry("Passwords",pwds+" "+cpassword); 239 cfg.writeEntry("Passwords",pwds+" "+cpassword);
205 return TRUE; 240 return TRUE;
206 } 241 }
207 } 242 }
208 243
209 return FALSE; 244 return FALSE;
210} 245}
211 246
212ServerPI::ServerPI( int socket, QObject *parent , const char* name ) 247ServerPI::ServerPI( int socket, QObject *parent , const char* name )
213 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 248 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 )
214{ 249{
215 state = Connected; 250 state = Connected;
216 251
217 setSocket( socket ); 252 setSocket( socket );
218 253
219 peerport = peerPort(); 254 peerport = peerPort();
220 peeraddress = peerAddress(); 255 peeraddress = peerAddress();
221 256
222#ifndef INSECURE 257#ifndef INSECURE
223 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 258 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
224 state = Forbidden; 259 state = Forbidden;
225 startTimer( 0 ); 260 startTimer( 0 );
226 } else 261 } else
227#endif 262#endif
228 { 263 {
229 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 264 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
230 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 265 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
231 266
232 passiv = FALSE; 267 passiv = FALSE;
233 for( int i = 0; i < 4; i++ ) 268 for( int i = 0; i < 4; i++ )
234 wait[i] = FALSE; 269 wait[i] = FALSE;
235 270
236 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 271 send( "220 Qtopia " QPE_VERSION " FTP Server" );
237 state = Wait_USER; 272 state = Wait_USER;
238 273
239 dtp = new ServerDTP( this ); 274 dtp = new ServerDTP( this );
240 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 275 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
241 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 276 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
242 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 277 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
243 278
244 279
245 directory = QDir::currentDirPath(); 280 directory = QDir::currentDirPath();
246 281
247 static int p = 1024; 282 static int p = 1024;
248 283
249 while ( !serversocket || !serversocket->ok() ) { 284 while ( !serversocket || !serversocket->ok() ) {
250 delete serversocket; 285 delete serversocket;
251 serversocket = new ServerSocket( ++p, this ); 286 serversocket = new ServerSocket( ++p, this );
252 } 287 }
253 connect( serversocket, SIGNAL( newIncomming( int ) ), 288 connect( serversocket, SIGNAL( newIncomming( int ) ),
254 SLOT( newConnection( int ) ) ); 289 SLOT( newConnection( int ) ) );
255 } 290 }
256} 291}
257 292
258ServerPI::~ServerPI() 293ServerPI::~ServerPI()
259{ 294{
260 295
261} 296}
262 297
263void ServerPI::connectionClosed() 298void ServerPI::connectionClosed()
@@ -598,65 +633,65 @@ void ServerPI::process( const QString& message )
598 if ( sendList( absFilePath( args ) ) ) 633 if ( sendList( absFilePath( args ) ) )
599 send( "150 File status okay" ); 634 send( "150 File status okay" );
600 else 635 else
601 send( "500 Syntax error, command unrecognized" ); 636 send( "500 Syntax error, command unrecognized" );
602 } 637 }
603 638
604 // size (SIZE) 639 // size (SIZE)
605 else if ( cmd == "SIZE" ) { 640 else if ( cmd == "SIZE" ) {
606 QString filePath = absFilePath( args ); 641 QString filePath = absFilePath( args );
607 QFileInfo fi( filePath ); 642 QFileInfo fi( filePath );
608 bool gzipfile = backupRestoreGzip( filePath ); 643 bool gzipfile = backupRestoreGzip( filePath );
609 if ( !fi.exists() && !gzipfile ) 644 if ( !fi.exists() && !gzipfile )
610 send( "500 Syntax error, command unrecognized" ); 645 send( "500 Syntax error, command unrecognized" );
611 else { 646 else {
612 if ( !gzipfile ) 647 if ( !gzipfile )
613 send( "213 " + QString::number( fi.size() ) ); 648 send( "213 " + QString::number( fi.size() ) );
614 else { 649 else {
615 Process duproc( QString("du") ); 650 Process duproc( QString("du") );
616 duproc.addArgument("-s"); 651 duproc.addArgument("-s");
617 QString in, out; 652 QString in, out;
618 if ( !duproc.exec(in, out) ) { 653 if ( !duproc.exec(in, out) ) {
619 qDebug("du process failed; just sending back 1K"); 654 qDebug("du process failed; just sending back 1K");
620 send( "213 1024"); 655 send( "213 1024");
621 } 656 }
622 else { 657 else {
623 QString size = out.left( out.find("\t") ); 658 QString size = out.left( out.find("\t") );
624 int guess = size.toInt()/5; 659 int guess = size.toInt()/5;
625 if ( filePath.contains("doc") ) 660 if ( filePath.contains("doc") )
626 guess *= 1000; 661 guess *= 1000;
627 qDebug("sending back gzip guess of %d", guess); 662 qDebug("sending back gzip guess of %d", guess);
628 send( "213 " + QString::number(guess) ); 663 send( "213 " + QString::number(guess) );
629 } 664 }
630 } 665 }
631 } 666 }
632 } 667 }
633 // name list (NLST) 668 // name list (NLST)
634 else if ( cmd == "NLST" ) { 669 else if ( cmd == "NLST" ) {
635 send( "502 Command not implemented" ); 670 send( "502 Command not implemented" );
636 } 671 }
637 672
638 // site parameters (SITE) 673 // site parameters (SITE)
639 else if ( cmd == "SITE" ) { 674 else if ( cmd == "SITE" ) {
640 send( "502 Command not implemented" ); 675 send( "502 Command not implemented" );
641 } 676 }
642 677
643 // system (SYST) 678 // system (SYST)
644 else if ( cmd == "SYST" ) { 679 else if ( cmd == "SYST" ) {
645 send( "215 UNIX Type: L8" ); 680 send( "215 UNIX Type: L8" );
646 } 681 }
647 682
648 // status (STAT) 683 // status (STAT)
649 else if ( cmd == "STAT" ) { 684 else if ( cmd == "STAT" ) {
650 send( "502 Command not implemented" ); 685 send( "502 Command not implemented" );
651 } 686 }
652 687
653 // help (HELP ) 688 // help (HELP )
654 else if ( cmd == "HELP" ) { 689 else if ( cmd == "HELP" ) {
655 send( "502 Command not implemented" ); 690 send( "502 Command not implemented" );
656 } 691 }
657 692
658 // noop (NOOP) 693 // noop (NOOP)
659 else if ( cmd == "NOOP" ) { 694 else if ( cmd == "NOOP" ) {
660 send( "200 Command okay" ); 695 send( "200 Command okay" );
661 } 696 }
662 697
@@ -1148,65 +1183,65 @@ void ServerDTP::bytesWritten( int bytes )
1148 } 1183 }
1149 else if( !file.atEnd() ) { 1184 else if( !file.atEnd() ) {
1150 QCString s; 1185 QCString s;
1151 s.resize( block_size ); 1186 s.resize( block_size );
1152 int bytes = file.readBlock( s.data(), block_size ); 1187 int bytes = file.readBlock( s.data(), block_size );
1153 writeBlock( s.data(), bytes ); 1188 writeBlock( s.data(), bytes );
1154 } 1189 }
1155 } 1190 }
1156 1191
1157 // send buffer mode 1192 // send buffer mode
1158 if ( SendBuffer == mode ) { 1193 if ( SendBuffer == mode ) {
1159 1194
1160 if ( bytes_written == buf.size() ) { 1195 if ( bytes_written == buf.size() ) {
1161 // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); 1196 // qDebug( "Debug: Sending complete: %d bytes", buf.size() );
1162 emit completed(); 1197 emit completed();
1163 mode = Idle; 1198 mode = Idle;
1164 } 1199 }
1165 } 1200 }
1166} 1201}
1167 1202
1168void ServerDTP::readyRead() 1203void ServerDTP::readyRead()
1169{ 1204{
1170 // retrieve file mode 1205 // retrieve file mode
1171 if ( RetrieveFile == mode ) { 1206 if ( RetrieveFile == mode ) {
1172 QCString s; 1207 QCString s;
1173 s.resize( bytesAvailable() ); 1208 s.resize( bytesAvailable() );
1174 readBlock( s.data(), bytesAvailable() ); 1209 readBlock( s.data(), bytesAvailable() );
1175 file.writeBlock( s.data(), s.size() ); 1210 file.writeBlock( s.data(), s.size() );
1176 } 1211 }
1177 else if ( RetrieveGzipFile == mode ) { 1212 else if ( RetrieveGzipFile == mode ) {
1178 if ( !gzipProc->isRunning() ) 1213 if ( !gzipProc->isRunning() )
1179 gzipProc->start(); 1214 gzipProc->start();
1180 1215
1181 QByteArray s; 1216 QByteArray s;
1182 s.resize( bytesAvailable() ); 1217 s.resize( bytesAvailable() );
1183 readBlock( s.data(), bytesAvailable() ); 1218 readBlock( s.data(), bytesAvailable() );
1184 gzipProc->writeToStdin( s ); 1219 gzipProc->writeToStdin( s );
1185 qDebug("wrote %d bytes to ungzip ", s.size() ); 1220 qDebug("wrote %d bytes to ungzip ", s.size() );
1186 } 1221 }
1187 // retrieve buffer mode 1222 // retrieve buffer mode
1188 else if ( RetrieveBuffer == mode ) { 1223 else if ( RetrieveBuffer == mode ) {
1189 QCString s; 1224 QCString s;
1190 s.resize( bytesAvailable() ); 1225 s.resize( bytesAvailable() );
1191 readBlock( s.data(), bytesAvailable() ); 1226 readBlock( s.data(), bytesAvailable() );
1192 buf.writeBlock( s.data(), s.size() ); 1227 buf.writeBlock( s.data(), s.size() );
1193 } 1228 }
1194} 1229}
1195 1230
1196void ServerDTP::writeTargzBlock() 1231void ServerDTP::writeTargzBlock()
1197{ 1232{
1198 QByteArray block = gzipProc->readStdout(); 1233 QByteArray block = gzipProc->readStdout();
1199 writeBlock( block.data(), block.size() ); 1234 writeBlock( block.data(), block.size() );
1200 qDebug("writeTargzBlock %d", block.size()); 1235 qDebug("writeTargzBlock %d", block.size());
1201 if ( !createTargzProc->isRunning() ) { 1236 if ( !createTargzProc->isRunning() ) {
1202 qDebug("tar and gzip done"); 1237 qDebug("tar and gzip done");
1203 emit completed(); 1238 emit completed();
1204 mode = Idle; 1239 mode = Idle;
1205 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1240 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1206 this, SLOT( writeTargzBlock() ) ); 1241 this, SLOT( writeTargzBlock() ) );
1207 } 1242 }
1208} 1243}
1209 1244
1210void ServerDTP::targzDone() 1245void ServerDTP::targzDone()
1211{ 1246{
1212 //qDebug("targz done"); 1247 //qDebug("targz done");
@@ -1231,111 +1266,111 @@ void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 p
1231 mode = SendFile; 1266 mode = SendFile;
1232 connectToHost( host.toString(), port ); 1267 connectToHost( host.toString(), port );
1233} 1268}
1234 1269
1235void ServerDTP::sendFile( const QString fn ) 1270void ServerDTP::sendFile( const QString fn )
1236{ 1271{
1237 file.setName( fn ); 1272 file.setName( fn );
1238 mode = SendFile; 1273 mode = SendFile;
1239} 1274}
1240 1275
1241void ServerDTP::sendGzipFile( const QString &fn, 1276void ServerDTP::sendGzipFile( const QString &fn,
1242 const QStringList &archiveTargets, 1277 const QStringList &archiveTargets,
1243 const QHostAddress& host, Q_UINT16 port ) 1278 const QHostAddress& host, Q_UINT16 port )
1244{ 1279{
1245 sendGzipFile( fn, archiveTargets ); 1280 sendGzipFile( fn, archiveTargets );
1246 connectToHost( host.toString(), port ); 1281 connectToHost( host.toString(), port );
1247} 1282}
1248 1283
1249void ServerDTP::sendGzipFile( const QString &fn, 1284void ServerDTP::sendGzipFile( const QString &fn,
1250 const QStringList &archiveTargets ) 1285 const QStringList &archiveTargets )
1251{ 1286{
1252 mode = SendGzipFile; 1287 mode = SendGzipFile;
1253 file.setName( fn ); 1288 file.setName( fn );
1254 1289
1255 QStringList args = "tar"; 1290 QStringList args = "tar";
1256 args += "-cv"; 1291 args += "-cv";
1257 args += archiveTargets; 1292 args += archiveTargets;
1258 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1293 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1259 createTargzProc->setArguments( args ); 1294 createTargzProc->setArguments( args );
1260 connect( createTargzProc, 1295 connect( createTargzProc,
1261 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); 1296 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) );
1262 1297
1263 gzipProc->setArguments( "gzip" ); 1298 gzipProc->setArguments( "gzip" );
1264 connect( gzipProc, SIGNAL( readyReadStdout() ), 1299 connect( gzipProc, SIGNAL( readyReadStdout() ),
1265 SLOT( writeTargzBlock() ) ); 1300 SLOT( writeTargzBlock() ) );
1266} 1301}
1267 1302
1268void ServerDTP::gunzipDone() 1303void ServerDTP::gunzipDone()
1269{ 1304{
1270 qDebug("gunzipDone"); 1305 qDebug("gunzipDone");
1271 disconnect( gzipProc, SIGNAL( processExited() ), 1306 disconnect( gzipProc, SIGNAL( processExited() ),
1272 this, SLOT( gunzipDone() ) ); 1307 this, SLOT( gunzipDone() ) );
1273 retrieveTargzProc->closeStdin(); 1308 retrieveTargzProc->closeStdin();
1274 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1309 disconnect( gzipProc, SIGNAL( readyReadStdout() ),
1275 this, SLOT( tarExtractBlock() ) ); 1310 this, SLOT( tarExtractBlock() ) );
1276} 1311}
1277 1312
1278void ServerDTP::tarExtractBlock() 1313void ServerDTP::tarExtractBlock()
1279{ 1314{
1280 qDebug("ungzipTarBlock"); 1315 qDebug("ungzipTarBlock");
1281 if ( !retrieveTargzProc->isRunning() ) { 1316 if ( !retrieveTargzProc->isRunning() ) {
1282 qDebug("auto start ungzip proc"); 1317 qDebug("auto start ungzip proc");
1283 if ( !retrieveTargzProc->start() ) 1318 if ( !retrieveTargzProc->start() )
1284 qWarning(" failed to start tar -x process"); 1319 qWarning(" failed to start tar -x process");
1285 } 1320 }
1286 retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); 1321 retrieveTargzProc->writeToStdin( gzipProc->readStdout() );
1287} 1322}
1288 1323
1289 1324
1290void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) 1325void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1291{ 1326{
1292 file.setName( fn ); 1327 file.setName( fn );
1293 mode = RetrieveFile; 1328 mode = RetrieveFile;
1294 connectToHost( host.toString(), port ); 1329 connectToHost( host.toString(), port );
1295} 1330}
1296 1331
1297void ServerDTP::retrieveFile( const QString fn ) 1332void ServerDTP::retrieveFile( const QString fn )
1298{ 1333{
1299 file.setName( fn ); 1334 file.setName( fn );
1300 mode = RetrieveFile; 1335 mode = RetrieveFile;
1301} 1336}
1302 1337
1303void ServerDTP::retrieveGzipFile( const QString &fn ) 1338void ServerDTP::retrieveGzipFile( const QString &fn )
1304{ 1339{
1305 qDebug("retrieveGzipFile %s", fn.latin1()); 1340 qDebug("retrieveGzipFile %s", fn.latin1());
1306 file.setName( fn ); 1341 file.setName( fn );
1307 mode = RetrieveGzipFile; 1342 mode = RetrieveGzipFile;
1308 1343
1309 gzipProc->setArguments( "gunzip" ); 1344 gzipProc->setArguments( "gunzip" );
1310 connect( gzipProc, SIGNAL( readyReadStdout() ), 1345 connect( gzipProc, SIGNAL( readyReadStdout() ),
1311 SLOT( tarExtractBlock() ) ); 1346 SLOT( tarExtractBlock() ) );
1312 connect( gzipProc, SIGNAL( processExited() ), 1347 connect( gzipProc, SIGNAL( processExited() ),
1313 SLOT( gunzipDone() ) ); 1348 SLOT( gunzipDone() ) );
1314} 1349}
1315 1350
1316void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) 1351void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port )
1317{ 1352{
1318 retrieveGzipFile( fn ); 1353 retrieveGzipFile( fn );
1319 connectToHost( host.toString(), port ); 1354 connectToHost( host.toString(), port );
1320} 1355}
1321 1356
1322void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) 1357void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port )
1323{ 1358{
1324 buf.setBuffer( array ); 1359 buf.setBuffer( array );
1325 mode = SendBuffer; 1360 mode = SendBuffer;
1326 connectToHost( host.toString(), port ); 1361 connectToHost( host.toString(), port );
1327} 1362}
1328 1363
1329void ServerDTP::sendByteArray( const QByteArray& array ) 1364void ServerDTP::sendByteArray( const QByteArray& array )
1330{ 1365{
1331 buf.setBuffer( array ); 1366 buf.setBuffer( array );
1332 mode = SendBuffer; 1367 mode = SendBuffer;
1333} 1368}
1334 1369
1335void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) 1370void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port )
1336{ 1371{
1337 buf.setBuffer( QByteArray() ); 1372 buf.setBuffer( QByteArray() );
1338 mode = RetrieveBuffer; 1373 mode = RetrieveBuffer;
1339 connectToHost( host.toString(), port ); 1374 connectToHost( host.toString(), port );
1340} 1375}
1341 1376