📄 http.cc
字号:
m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "http" ) != 0 ) { error( ERR_INTERNAL, "kio_http got non http url" ); m_cmd = CMD_NONE; return; } m_cmd = CMD_GET; m_bIgnoreErrors = false; if ( !http_open( usrc, 0L, 0, false ) ) { m_cmd = CMD_NONE; return; } ready(); gettingFile( _url ); totalSize( m_iSize ); int processed_size = 0; time_t t_start = time( 0L ); time_t t_last = t_start; char buffer[ 4096 ]; while( !feof( m_fsocket ) ) { long n = fread( buffer, 1, 2048, m_fsocket ); if ( n == -1 ) { error( ERR_CONNECTION_BROKEN, usrc.host() ); m_cmd = CMD_NONE; return; } if ( n > 0 ) { data( buffer, n ); processed_size += n; time_t t = time( 0L ); if ( t - t_last >= 1 ) { processedSize( processed_size ); speed( processed_size / ( t - t_start ) ); t_last = t; } } } processedSize( m_iSize ); time_t t = time( 0L ); if ( t - t_start >= 1 ) speed( processed_size / ( t - t_start ) ); dataEnd(); http_close(); finished(); m_cmd = CMD_NONE;}void HTTPProtocol::slotCopy( const char *_source, const char *_dest ){ string source = _source; string dest = _dest; K2URL usrc( _source ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, source.c_str() ); m_cmd = CMD_NONE; return; } K2URL udest( _dest ); if ( udest.isMalformed() ) { error( ERR_MALFORMED_URL, dest.c_str() ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "http" ) != 0 ) { error( ERR_INTERNAL, "kio_http got non http protocol as source in copy command" ); m_cmd = CMD_NONE; return; } list<K2URL> lst; if ( !K2URL::split( _dest, lst ) ) { error( ERR_MALFORMED_URL, dest.c_str() ); m_cmd = CMD_NONE; return; } if ( lst.size() > 1 ) { error( ERR_NOT_FILTER_PROTOCOL, "http" ); m_cmd = CMD_NONE; return; } string exec = ProtocolManager::self()->find( lst.back().protocol() ); if ( exec.empty() ) { error( ERR_UNSUPPORTED_PROTOCOL, lst.back().protocol() ); m_cmd = CMD_NONE; return; } // Is the right most protocol a filesystem protocol ? if ( ProtocolManager::self()->outputType( lst.back().protocol() ) != ProtocolManager::T_FILESYSTEM ) { error( ERR_PROTOCOL_IS_NOT_A_FILESYSTEM, lst.back().protocol() ); m_cmd = CMD_NONE; return; } m_cmd = CMD_GET; list<string> files; files.push_back( _source ); Slave slave( exec.c_str() ); if ( slave.pid() == -1 ) { error( ERR_CANNOT_LAUNCH_PROCESS, exec.c_str() ); m_cmd = CMD_NONE; return; } HTTPIOJob job( &slave, this ); int processed_size = 0; /***** * Copy files *****/ time_t t_start = time( 0L ); time_t t_last = t_start; bool overwrite_all = false; bool auto_skip = false; bool resume_all = false; int processed_files = 0; totalDirs( 0 ); totalFiles( files.size() ); m_bIgnoreJobErrors = true; list<string>::iterator fit = files.begin(); for( ; fit != files.end(); fit++ ) { bool overwrite = false; bool skip_copying = false; bool resume = false; unsigned long offset = 0; K2URL u1( fit->c_str() ); if ( u1.isMalformed() ) { error( ERR_MALFORMED_URL, source.c_str() ); m_cmd = CMD_NONE; return; } list<K2URL> l( lst ); string filename = u1.filename(); if ( filename.empty() ) { filename = "index.html"; l.back().addPath( filename.c_str() ); } string d; list<K2URL>::iterator it = l.begin(); for( ; it != l.end(); it++ ) d += it->url(); // Repeat until we got no error do { job.clearError(); m_bIgnoreErrors = true; if ( !http_open( u1, 0L, 0, false, offset ) ) { m_bIgnoreErrors = false; /* if ( !m_bGUI ) { http_close(); releaseError(); m_cmd = CMD_NONE; return; } */ string tmp = "Could not read\n"; tmp += fit->c_str(); list<string>::iterator tmpit = fit; tmpit++; if( tmpit == files.end() ) { open_CriticalDlg( "Error", tmp.c_str(), "Cancel" ); http_close(); clearError(); error( ERR_USER_CANCELED, "" ); m_cmd = CMD_NONE; return; } if ( !open_CriticalDlg( "Error", tmp.c_str(), "Continue", "Cancel" ) ) { http_close(); clearError(); error( ERR_USER_CANCELED, "" ); m_cmd = CMD_NONE; return; } else { clearError(); continue; } } else m_bIgnoreErrors = false; // This is a hack, since total size should be the size of all files together // while we transmit only the size of the current file here. totalSize( m_iSize + offset); canResume( m_bCanResume ); // this will emit sigCanResume( m_bCanResume ) copyingFile( fit->c_str(), d.c_str() ); job.put( d.c_str(), -1, overwrite_all || overwrite, resume_all || resume, m_iSize + offset ); while( !job.isReady() && !job.hasFinished() ) job.dispatch(); // Did we have an error ? if ( job.hasError() ) { int currentError = job.errorId(); debug( "kio_http : ################# COULD NOT PUT %d",currentError); if ( /* m_bGUI && */ currentError == ERR_WRITE_ACCESS_DENIED ) { // Should we skip automatically ? if ( auto_skip ) { job.clearError(); skip_copying = true; continue; } string tmp2 = l.back().url(); SkipDlg_Result r; r = open_SkipDlg( tmp2.c_str(), ( files.size() > 1 ) ); if ( r == S_CANCEL ) { http_close(); error( ERR_USER_CANCELED, "" ); m_cmd = CMD_NONE; return; } else if ( r == S_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); skip_copying = true; continue; } else if ( r == S_AUTO_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); skip_copying = true; continue; } else assert( 0 ); } // Can we prompt the user and ask for a solution ? else if ( /* m_bGUI && */ currentError == ERR_DOES_ALREADY_EXIST || currentError == ERR_DOES_ALREADY_EXIST_FULL ) { // Should we skip automatically ? if ( auto_skip ) { job.clearError(); continue; } RenameDlg_Result r; string n; if ( ProtocolManager::self()->getAutoResume() && m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) { r = R_RESUME_ALL; } else { RenameDlg_Mode m; // ask for resume only if transfer can be resumed and if it is not // already fully downloaded if ( files.size() > 1 ) { if ( m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE | M_RESUME); else m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE); } else { if ( m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE | M_RESUME); else m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE); } string tmp2 = l.back().url(); r = open_RenameDlg( fit->c_str(), tmp2.c_str(), m, n ); } if ( r == R_CANCEL ) { http_close(); error( ERR_USER_CANCELED, "" ); m_cmd = CMD_NONE; return; } else if ( r == R_RENAME ) { K2URL u( n.c_str() ); // The Dialog should have checked this. if ( u.isMalformed() ) assert( 0 ); // Change the destination name of the current file// l = lst;// l.back().addPath( filename.c_str() ); // list<K2URL>::iterator it = l.begin();// for( ; it != l.end(); it++ )// d += it->url(); d = u.path(); // Dont clear error => we will repeat the current command } else if ( r == R_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); } else if ( r == R_AUTO_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); auto_skip = true; } else if ( r == R_OVERWRITE ) { overwrite = true; // Dont clear error => we will repeat the current command } else if ( r == R_OVERWRITE_ALL ) { overwrite_all = true; // Dont clear error => we will repeat the current command } else if ( r == R_RESUME ) { resume = true; offset = getOffset( l.back().url() ); // Dont clear error => we will repeat the current command } else if ( r == R_RESUME_ALL ) { resume_all = true; offset = getOffset( l.back().url() ); // Dont clear error => we will repeat the current command } else assert( 0 ); } // No need to ask the user, so raise an error and finish else { http_close(); error( currentError, job.errorText() ); m_cmd = CMD_NONE; return; } } } while( job.hasError() ); if ( skip_copying ) continue; if ( offset > 0 ) { // set offset processed_size += offset; debug( "kio_http : Offset = %ld", offset ); } /** * Now we can really copy the stuff */ char buffer[ 2048 ]; while( !feof( m_fsocket ) ) { setup_alarm( ProtocolManager::self()->getReadTimeout() ); // start timeout long n = fread( buffer, 1, 2048, m_fsocket ); // !!! slow down loop for local testing// for ( int tmpi = 0; tmpi < 800000; tmpi++ ) ; if ( n == -1 && !sigbreak ) { http_close(); error( ERR_CONNECTION_BROKEN, usrc.host() ); m_cmd = CMD_NONE; return; } if ( n > 0 ) { job.data( buffer, n ); processed_size += n; time_t t = time( 0L ); if ( t - t_last >= 1 ) { processedSize( processed_size ); speed( processed_size / ( t - t_start ) ); t_last = t; } } } job.dataEnd(); http_close(); while( !job.hasFinished() ) job.dispatch(); time_t t = time( 0L ); processedSize( processed_size ); if ( t - t_start >= 1 ) { speed( processed_size / ( t - t_start ) ); t_last = t; } processedFiles( ++processed_files ); } debug( "kio_http : Copied files %s", dest.c_str() ); finished(); m_cmd = CMD_NONE;}void HTTPProtocol::jobError( int _errid, const char *_txt ){ if ( !m_bIgnoreJobErrors ) error( _errid, _txt );}bool HTTPProtocol::error( int _err, const char *_txt ){ if ( m_bIgnoreErrors ) { m_iSavedError = _err; m_strSavedError = _txt; return true; } else return IOProtocol::error( _err, _txt );}/************************************* * * HTTPIOJob * *************************************/HTTPIOJob::HTTPIOJob( Connection *_conn, HTTPProtocol *_HTTP ) : IOJob( _conn ){ m_pHTTP = _HTTP;} void HTTPIOJob::slotError( int _errid, const char *_txt ){ IOJob::slotError( _errid, _txt ); m_pHTTP->jobError( _errid, _txt );}/************************************* * * Utilities * *************************************/void openFileManagerWindow( const char * ){ assert( 0 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -