[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kio_virtualfile/kioslave/http
From:       Allan Sandfeld Jensen <kde () carewolf ! com>
Date:       2006-07-30 20:07:11
Message-ID: 1154290031.721816.29032.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 567987 by carewolf:

Beginning of random-access HTTP


 M  +94 -6     http.cc  
 M  +3 -0      http.h  
 M  +1 -0      http.protocol  


--- branches/work/kio_virtualfile/kioslave/http/http.cc #567986:567987
@@ -61,6 +61,7 @@
 #include <kstringhandler.h>
 #include <kremoteencoding.h>
 
+#include "kio/connection.h"
 #include "kio/ioslave_defaults.h"
 #include "kio/http_slave_defaults.h"
 
@@ -1244,6 +1245,89 @@
     httpError();
 }
 
+void HTTPProtocol::open( const KUrl& url, int access )
+{
+    kDebug(7103) << "(" << m_pid << ") HTTPProtocol::open " << url.url() << endl;
+
+    if ( !checkRequestURL( url ) )
+        return;
+
+    m_request.method = HTTP_HEAD;
+    m_request.path = url.path();
+    m_request.query = url.query();
+
+    // ### use cache
+    m_request.bUseCache = false;
+
+    m_request.passwd = url.pass();
+    m_request.user = url.user();
+    m_request.doProxy = m_bUseProxy;
+
+    retrieveHeader( false );
+
+    KIO::filesize_t pos = 0;
+//     emit mimeType( m_strMimeType );
+    emit totalSize( m_iSize );
+    emit position( pos );
+    emit opened();
+
+    // Command-loop:
+    int cmd = CMD_NONE;
+    while (true) {
+        kDebug( 7103 ) << "HTTP::open -- loop" << endl;
+        QByteArray args;
+        int stat = appconn->read(&cmd, args);
+        if ( stat == -1 )
+        {   // error
+            kDebug( 7103 ) << "HTTP::open -- connection error" << endl;
+            break;
+        }
+        QDataStream stream( args );
+        switch( cmd ) {
+        case CMD_READ: {
+            kDebug( 7103 ) << "HTTP::open -- read" << endl;
+            int bytes;
+            stream >> bytes;
+            m_request.method = HTTP_GET;
+            m_request.offset = pos;
+            m_request.length = bytes;
+            retrieveContent( true );
+            pos += bytes;
+            emit data( m_bufWebDavData );
+            m_bufWebDavData.clear();
+            continue;
+        }
+        case CMD_WRITE: {
+            kDebug( 7103 ) << "HTTP::open -- write" << endl;
+            continue;
+        }
+        case CMD_SEEK: {
+            kDebug( 7103 ) << "HTTP::open -- seek" << endl;
+            int offset;
+            stream >> offset;
+            pos = offset;
+            // if partial gets works at all seek is automatically succesfull
+            emit position( offset );
+            continue;
+        }
+        case CMD_NONE:
+            kDebug( 7103 ) << "HTTP::open -- none " << endl;
+            continue;
+        case CMD_CLOSE:
+            kDebug( 7103 ) << "HTTP::open -- close " << endl;
+            break;
+        default:
+            kDebug( 7103 ) << "HTTP::open -- invalid command: " << cmd << endl;
+            break;
+        }
+        break;
+    }
+
+    httpClose(false); // Always close connection.
+    finished();
+}
+
+
 void HTTPProtocol::copy( const KUrl& src, const KUrl& dest, int, bool overwrite )
 {
   kDebug(7113) << "(" << m_pid << ") HTTPProtocol::copy " << src.prettyUrl()
@@ -2330,10 +2414,13 @@
         header += "\r\n";
     }
 
-    if ( m_request.offset > 0 )
+    if ( m_request.offset > 0 || m_request.length > 0)
     {
-      header += QString("Range: bytes=%1-\r\n").arg(KIO::number(m_request.offset));
-      kDebug(7103) << "kio_http : Range = " << KIO::number(m_request.offset) << \
endl; +      if (m_request.length == 0)
+        header += QString("Range: \
bytes=%1-\r\n").arg(KIO::number(m_request.offset)); +      else
+        header += QString("Range: \
bytes=%1-%2\r\n").arg(KIO::number(m_request.offset)).arg(KIO::number(m_request.offset+m_request.length-1));
 +      kDebug(7103) << "Range = " << KIO::number(m_request.offset) << ":" << \
KIO::number(m_request.length) << endl;  }
 
     if ( m_request.cache == CC_Reload )
@@ -2619,7 +2706,7 @@
      setMetaData("expire-date", tmp);
      tmp.setNum(m_request.creationDate);
      setMetaData("cache-creation-date", tmp);
-     mimeType(m_strMimeType);
+//      mimeType(m_strMimeType);
      forwardHttpResponseHeader();
      return true;
   }
@@ -2830,6 +2917,7 @@
       else if (m_responseCode == 416) // Range not supported
       {
         m_request.offset = 0;
+        m_request.length = 0;
         httpCloseConnection();
         return false; // Try again.
       }
@@ -3703,8 +3791,8 @@
   if (locationStr.isEmpty() && (!m_strMimeType.isEmpty() ||
       m_request.method == HTTP_HEAD))
   {
-    kDebug(7113) << "(" << m_pid << ") Emitting mimetype " << m_strMimeType << endl;
-    mimeType( m_strMimeType );
+    kDebug(7103) << "(" << m_pid << ") Emitting mimetype " << m_strMimeType << endl;
+//     mimeType( m_strMimeType );
   }
 
   forwardHttpResponseHeader();
--- branches/work/kio_virtualfile/kioslave/http/http.h #567986:567987
@@ -105,6 +105,7 @@
       port = 0;
       method = KIO::HTTP_UNKNOWN;
       offset = 0;
+      length = 0;
       doProxy = false;
       allowCompressedPage = false;
       disablePassDlg = false;
@@ -131,6 +132,7 @@
     KIO::HTTP_METHOD method;
     KIO::CacheControl cache;
     KIO::filesize_t offset;
+    KIO::filesize_t length;
     bool doProxy;
     KUrl url;
     QString window;                 // Window Id this request is related to.
@@ -192,6 +194,7 @@
   virtual void get( const KUrl& url );
   virtual void put( const KUrl& url, int _mode, bool overwrite,
                     bool _resume );
+  virtual void open( const KUrl& url, int access );
 
 //----------------- Re-implemented methods for WebDAV -----------
   virtual void listDir( const KUrl& url );
--- branches/work/kio_virtualfile/kioslave/http/http.protocol #567986:567987
@@ -4,6 +4,7 @@
 input=none
 output=filesystem
 reading=true
+opening=true
 defaultMimetype=application/octet-stream
 determineMimetypeFromExtension=false
 Icon=www


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic