Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index b998e95..a5e20b2 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -52,68 +52,68 @@ | |||
52 | #ifdef Q_WS_QWS | 52 | #ifdef Q_WS_QWS |
53 | #include <qtopia/qcopenvelope_qws.h> | 53 | #include <qtopia/qcopenvelope_qws.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | 56 | ||
57 | #include "transferserver.h" | 57 | #include "transferserver.h" |
58 | #include <qtopia/qprocess.h> | 58 | #include <qtopia/qprocess.h> |
59 | 59 | ||
60 | const int block_size = 51200; | 60 | const int block_size = 51200; |
61 | 61 | ||
62 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, | 62 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, |
63 | const char* name) | 63 | const char* name) |
64 | : QServerSocket( port, 1, parent, name ) | 64 | : QServerSocket( port, 1, parent, name ) |
65 | { | 65 | { |
66 | connections.setAutoDelete( TRUE ); | 66 | connections.setAutoDelete( TRUE ); |
67 | if ( !ok() ) | 67 | if ( !ok() ) |
68 | qWarning( "Failed to bind to port %d", port ); | 68 | qWarning( "Failed to bind to port %d", port ); |
69 | } | 69 | } |
70 | 70 | ||
71 | void TransferServer::authorizeConnections() | 71 | void TransferServer::authorizeConnections() |
72 | { | 72 | { |
73 | QListIterator<ServerPI> it(connections); | 73 | QListIterator<ServerPI> it(connections); |
74 | while ( it.current() ) { | 74 | while ( it.current() ) { |
75 | if ( !it.current()->verifyAuthorised() ) { | 75 | if ( !it.current()->verifyAuthorised() ) { |
76 | disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); | 76 | disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); |
77 | connections.removeRef( it.current() ); | 77 | connections.removeRef( it.current() ); |
78 | } else | 78 | } else |
79 | ++it; | 79 | ++it; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | void TransferServer::closed(ServerPI *item) | 83 | void TransferServer::closed(ServerPI *item) |
84 | { | 84 | { |
85 | connections.removeRef(item); | 85 | connections.removeRef(item); |
86 | } | 86 | } |
87 | 87 | ||
88 | TransferServer::~TransferServer() | 88 | TransferServer::~TransferServer() |
89 | { | 89 | { |
90 | } | 90 | } |
91 | 91 | ||
92 | void TransferServer::newConnection( int socket ) | 92 | void TransferServer::newConnection( int socket ) |
93 | { | 93 | { |
94 | ServerPI *ptr = new ServerPI( socket, this ); | 94 | ServerPI *ptr = new ServerPI( socket, this ); |
95 | connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); | 95 | connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); |
96 | connections.append( ptr ); | 96 | connections.append( ptr ); |
97 | } | 97 | } |
98 | 98 | ||
99 | QString SyncAuthentication::serverId() | 99 | QString SyncAuthentication::serverId() |
100 | { | 100 | { |
101 | Config cfg("Security"); | 101 | Config cfg("Security"); |
102 | cfg.setGroup("Sync"); | 102 | cfg.setGroup("Sync"); |
103 | QString r = cfg.readEntry("serverid"); | 103 | QString r = cfg.readEntry("serverid"); |
104 | 104 | ||
105 | if ( r.isEmpty() ) { | 105 | if ( r.isEmpty() ) { |
106 | r = OGlobal::generateUuid(); | 106 | r = OGlobal::generateUuid(); |
107 | cfg.writeEntry("serverid", r ); | 107 | cfg.writeEntry("serverid", r ); |
108 | } | 108 | } |
109 | return r; | 109 | return r; |
110 | } | 110 | } |
111 | 111 | ||
112 | QString SyncAuthentication::ownerName() | 112 | QString SyncAuthentication::ownerName() |
113 | { | 113 | { |
114 | QString vfilename = Global::applicationFileName("addressbook", | 114 | QString vfilename = Global::applicationFileName("addressbook", |
115 | "businesscard.vcf"); | 115 | "businesscard.vcf"); |
116 | if (QFile::exists(vfilename)) { | 116 | if (QFile::exists(vfilename)) { |
117 | Contact c; | 117 | Contact c; |
118 | c = Contact::readVCard( vfilename )[0]; | 118 | c = Contact::readVCard( vfilename )[0]; |
119 | return c.fullName(); | 119 | return c.fullName(); |
@@ -312,61 +312,61 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) | |||
312 | 312 | ||
313 | peerport = peerPort(); | 313 | peerport = peerPort(); |
314 | peeraddress = peerAddress(); | 314 | peeraddress = peerAddress(); |
315 | 315 | ||
316 | #ifndef INSECURE | 316 | #ifndef INSECURE |
317 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 317 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
318 | state = Forbidden; | 318 | state = Forbidden; |
319 | startTimer( 0 ); | 319 | startTimer( 0 ); |
320 | } else | 320 | } else |
321 | #endif | 321 | #endif |
322 | { | 322 | { |
323 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 323 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
324 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 324 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
325 | 325 | ||
326 | passiv = FALSE; | 326 | passiv = FALSE; |
327 | for( int i = 0; i < 4; i++ ) | 327 | for( int i = 0; i < 4; i++ ) |
328 | wait[i] = FALSE; | 328 | wait[i] = FALSE; |
329 | 329 | ||
330 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr | 330 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr |
331 | state = Wait_USER; | 331 | state = Wait_USER; |
332 | 332 | ||
333 | dtp = new ServerDTP( this ); | 333 | dtp = new ServerDTP( this ); |
334 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 334 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
335 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 335 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
336 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 336 | connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); |
337 | 337 | ||
338 | 338 | ||
339 | directory = QDir::currentDirPath(); | 339 | directory = QDir::currentDirPath(); |
340 | 340 | ||
341 | static int p = 1024; | 341 | static int p = 1024; |
342 | 342 | ||
343 | while ( !serversocket || !serversocket->ok() ) { | 343 | while ( !serversocket || !serversocket->ok() ) { |
344 | delete serversocket; | 344 | delete serversocket; |
345 | serversocket = new ServerSocket( ++p, this ); | 345 | serversocket = new ServerSocket( ++p, this ); |
346 | } | 346 | } |
347 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 347 | connect( serversocket, SIGNAL( newIncomming(int) ), |
348 | SLOT( newConnection( int ) ) ); | 348 | SLOT( newConnection(int) ) ); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | ServerPI::~ServerPI() | 352 | ServerPI::~ServerPI() |
353 | { | 353 | { |
354 | close(); | 354 | close(); |
355 | 355 | ||
356 | if ( dtp ) | 356 | if ( dtp ) |
357 | dtp->close(); | 357 | dtp->close(); |
358 | delete dtp; | 358 | delete dtp; |
359 | delete serversocket; | 359 | delete serversocket; |
360 | } | 360 | } |
361 | 361 | ||
362 | bool ServerPI::verifyAuthorised() | 362 | bool ServerPI::verifyAuthorised() |
363 | { | 363 | { |
364 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { | 364 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { |
365 | state = Forbidden; | 365 | state = Forbidden; |
366 | return FALSE; | 366 | return FALSE; |
367 | } | 367 | } |
368 | return TRUE; | 368 | return TRUE; |
369 | } | 369 | } |
370 | 370 | ||
371 | void ServerPI::connectionClosed() | 371 | void ServerPI::connectionClosed() |
372 | { | 372 | { |
@@ -1065,49 +1065,49 @@ QString ServerPI::absFilePath( const QString& file ) | |||
1065 | { | 1065 | { |
1066 | if ( file.isEmpty() ) return file; | 1066 | if ( file.isEmpty() ) return file; |
1067 | 1067 | ||
1068 | QString filepath( file ); | 1068 | QString filepath( file ); |
1069 | if ( file[0] != "/" ) | 1069 | if ( file[0] != "/" ) |
1070 | filepath = directory.path() + "/" + file; | 1070 | filepath = directory.path() + "/" + file; |
1071 | 1071 | ||
1072 | return filepath; | 1072 | return filepath; |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | 1075 | ||
1076 | void ServerPI::timerEvent( QTimerEvent * ) | 1076 | void ServerPI::timerEvent( QTimerEvent * ) |
1077 | { | 1077 | { |
1078 | connectionClosed(); | 1078 | connectionClosed(); |
1079 | } | 1079 | } |
1080 | 1080 | ||
1081 | 1081 | ||
1082 | ServerDTP::ServerDTP( QObject *parent, const char* name) | 1082 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
1083 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 1083 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
1084 | retrieveTargzProc( 0 ) | 1084 | retrieveTargzProc( 0 ) |
1085 | { | 1085 | { |
1086 | 1086 | ||
1087 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1087 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1088 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1088 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1089 | connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); | 1089 | connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); |
1090 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1090 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1091 | 1091 | ||
1092 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr | 1092 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr |
1093 | createTargzProc->setCommunication( QProcess::Stdout ); | 1093 | createTargzProc->setCommunication( QProcess::Stdout ); |
1094 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1094 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1095 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); | 1095 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); |
1096 | 1096 | ||
1097 | retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); | 1097 | retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); |
1098 | retrieveTargzProc->setCommunication( QProcess::Stdin ); | 1098 | retrieveTargzProc->setCommunication( QProcess::Stdin ); |
1099 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1099 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1100 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1100 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1101 | SIGNAL( completed() ) ); | 1101 | SIGNAL( completed() ) ); |
1102 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1102 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1103 | SLOT( extractTarDone() ) ); | 1103 | SLOT( extractTarDone() ) ); |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | ServerDTP::~ServerDTP() | 1106 | ServerDTP::~ServerDTP() |
1107 | { | 1107 | { |
1108 | buf.close(); | 1108 | buf.close(); |
1109 | if ( RetrieveFile == mode && file.isOpen() ) { | 1109 | if ( RetrieveFile == mode && file.isOpen() ) { |
1110 | // We're being shutdown before the client closed. | 1110 | // We're being shutdown before the client closed. |
1111 | file.close(); | 1111 | file.close(); |
1112 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { | 1112 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { |
1113 | qDebug( "STOR incomplete" ); | 1113 | qDebug( "STOR incomplete" ); |