void Qip::socketReadyRead() { // read from the server QTextStream stream( socket ); QString line; while ( socket->canReadLine() ) { line = stream.readLine(); if ( line.startsWith( "500" ) ) { error( ErrValid, line.mid( 4 ) ); } else if ( line.startsWith( "550" ) ) { error( ErrFileNotExisting, line.mid( 4 ) ); } else if ( line.startsWith( "212+" ) ) { if ( state != List ) { state = List; emit start( operationInProgress() ); } QUrlInfo inf; inf.setName( line.mid( 6 ) + QString( ( line[ 4 ] == 'D' ) ? "/" : "" ) ); inf.setDir( line[ 4 ] == 'D' ); inf.setSymLink( FALSE ); inf.setFile( line[ 4 ] == 'F' ); inf.setWritable( FALSE ); inf.setReadable( TRUE ); emit newChild( inf, operationInProgress() ); } else if ( line.startsWith( "213+" ) ) { state = Data; emit data( line.mid( 4 ).utf8(), operationInProgress() ); } if( line[3] == ' ' && state != Start) { state = Start; operationInProgress()->setState( StDone ); emit finished( operationInProgress() ); } } }
void Qip::error( int code, const QString& msg ) { if ( operationInProgress() ) { operationInProgress()->setState( StFailed ); operationInProgress()->setErrorCode( code ); operationInProgress()->setProtocolDetail( msg ); clearOperationQueue(); emit finished( operationInProgress() ); } state = Start; }
void Nntp::error( int code ) { if ( code == QSocket::ErrHostNotFound || code == QSocket::ErrConnectionRefused ) { // this signal is called if connecting to the server failed if ( operationInProgress() ) { QString msg = tr( "Host not found or couldn't connect to: \n" + url()->host() ); operationInProgress()->setState( StFailed ); operationInProgress()->setProtocolDetail( msg ); operationInProgress()->setErrorCode( (int)ErrHostNotFound ); clearOperationQueue(); emit finished( operationInProgress() ); } } }
void Http::readyRead() { QByteArray s; s.resize( commandSocket->bytesAvailable() ); commandSocket->readBlock( s.data(), commandSocket->bytesAvailable() ); emit data( s, operationInProgress() ); }
void Nntp::parseGroups() { if ( !commandSocket->canReadLine() ) return; // read one line after the other while ( commandSocket->canReadLine() ) { QString s = commandSocket->readLine(); // if the line starts with a dot, all groups or articles have been listed, // so we finished processing the listChildren() command if ( s[ 0 ] == '.' ) { readGroups = FALSE; operationInProgress()->setState( StDone ); emit finished( operationInProgress() ); return; } // if the code of the server response is 215 or 211 // the next line will be the first group or article (depending on what we read). // So let others know that we start reading now... if ( s.left( 3 ) == "215" || s.left( 3 ) == "211" ) { operationInProgress()->setState( StInProgress ); emit start( operationInProgress() ); continue; } // parse the line and create a QUrlInfo object // which describes the child (group or article) bool tab = s.find( '\t' ) != -1; QString group = s.mid( 0, s.find( tab ? '\t' : ' ' ) ); QUrlInfo inf; inf.setName( group ); QString path = url()->path(); inf.setDir( path.isEmpty() || path == "/" ); inf.setSymLink( FALSE ); inf.setFile( !inf.isDir() ); inf.setWritable( FALSE ); inf.setReadable( TRUE ); // let others know about our new child emit newChild( inf, operationInProgress() ); } }
void Http::closed() { if ( url() ) emit connectionStateChanged( ConClosed, tr( "Connection to %1 closed" ).arg( url()->host() ) ); else emit connectionStateChanged( ConClosed, tr( "Connection closed" ) ); connectionReady = FALSE; emit finished( operationInProgress() ); }
void QmvHttp::readyRead() { #ifdef QMVHTTP_DEBUG qDebug("QmvHttp::readyRead"); #endif QByteArray s; s.resize( commandSocket->bytesAvailable() ); commandSocket->readBlock( s.data(), commandSocket->bytesAvailable() ); // still in response header if ( bytes_in == 0 && processGetResponse( &s ) < 0 ) return; emit data( s, operationInProgress() ); bytes_in += s.size(); if ( content_length >= 0 && bytes_in == content_length ) { // reset for next response bytes_in = 0; emit finished( operationInProgress() ); } }
void QmvHttp::closed() { #ifdef QMVHTTP_DEBUG qDebug("QmvHttp::closed"); #endif if ( url() ) emit connectionStateChanged( ConClosed, tr( "Connection to %1 closed" ).arg( url()->host() ) ); else emit connectionStateChanged( ConClosed, tr( "Connection closed" ) ); connectionReady = FALSE; emit finished( operationInProgress() ); }
void Nntp::parseArticle() { if ( !commandSocket->canReadLine() ) return; // read an article one line after the other while ( commandSocket->canReadLine() ) { QString s = commandSocket->readLine(); // if the line starts with a dot, we finished reading something if ( s[ 0 ] == '.' ) { readArticle = FALSE; operationInProgress()->setState( StDone ); emit finished( operationInProgress() ); return; } if ( s.right( 1 ) == "\n" ) s.remove( s.length() - 1, 1 ); // emit the new data of the article which we read emit data( QCString( s.ascii() ), operationInProgress() ); } }
void Q3LocalFs::operationPut( Q3NetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: operationPut" ); #endif op->setState( StInProgress ); QString to = Q3Url( op->arg( 0 ) ).path(); QFile f( to ); if ( !f.open( IO_WriteOnly ) ) { QString msg = tr( "Could not write\n%1" ).arg( to ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrPut ); emit finished( op ); return; } QByteArray ba( op->rawArg( 1 ) ); emit dataTransferProgress( 0, ba.size(), op ); int blockSize = calcBlockSize( ba.size() ); if ( (int)ba.size() < blockSize ) { f.writeBlock( ba.data(), ba.size() ); emit dataTransferProgress( ba.size(), ba.size(), op ); } else { int i = 0; while ( i + blockSize < (int)ba.size() - 1 ) { if ( operationInProgress() != op ) return; f.writeBlock( &ba.data()[ i ], blockSize ); f.flush(); emit dataTransferProgress( i + blockSize, ba.size(), op ); i += blockSize; QPointer<QObject> that = this; qApp->processEvents(); if (!that) return; } if ( i < (int)ba.size() - 1 ) f.writeBlock( &ba.data()[ i ], ba.size() - i ); emit dataTransferProgress( ba.size(), ba.size(), op ); } op->setState( StDone ); f.close(); emit finished( op ); }
void Q3LocalFs::operationGet( Q3NetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: operationGet" ); #endif op->setState( StInProgress ); QString from = Q3Url( op->arg( 0 ) ).path(); QFile f( from ); if ( !f.open( IO_ReadOnly ) ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: could not open %s", from.latin1() ); #endif QString msg = tr( "Could not open\n%1" ).arg( from ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrGet ); emit finished( op ); return; } QByteArray s; emit dataTransferProgress( 0, f.size(), op ); if ( f.size() != 0 ) { int blockSize = calcBlockSize( f.size() ); if ( (int)f.size() < blockSize ) { s.resize( f.size() ); f.readBlock( s.data(), f.size() ); emit data( s, op ); emit dataTransferProgress( f.size(), f.size(), op ); #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: got all %d bytes at once", f.size() ); #endif } else { s.resize( blockSize ); int remaining = f.size(); QPointer<QObject> that = this; while ( that && remaining > 0 ) { if ( operationInProgress() != op ) return; if ( remaining >= blockSize ) { f.readBlock( s.data(), blockSize ); emit data( s, op ); emit dataTransferProgress( f.size() - remaining, f.size(), op ); remaining -= blockSize; } else { s.resize( remaining ); f.readBlock( s.data(), remaining ); emit data( s, op ); emit dataTransferProgress( f.size() - remaining, f.size(), op ); remaining -= remaining; } qApp->processEvents(); } if ( !that ) return; #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: got all %d bytes step by step", f.size() ); #endif emit dataTransferProgress( f.size(), f.size(), op ); } } op->setState( StDone ); f.close(); emit finished( op ); }
void Qip::operationGet( QNetworkOperation * ) { QTextStream os(socket); os << "GET " + url()->path() + "\r\n"; operationInProgress()->setState( StInProgress ); }
void Qip::operationListChildren( QNetworkOperation * ) { QTextStream os(socket); os << "LIST " + url()->path() + "\r\n"; operationInProgress()->setState( StInProgress ); }