• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIOSlave

http.h

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org>
00003    Copyright (C) 2000,2001 Waldo Bastian <bastian@kde.org>
00004    Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
00005    Copyright (C) 2001,2002 Hamish Rodda <rodda@kde.org>
00006    Copyright (C) 2007      Daniel Nicoletti <mirttex@users.sourceforge.net>
00007 
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License as published by the Free Software Foundation; either
00012    version 2 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Library General Public License for more details.
00018 
00019    You should have received a copy of the GNU Library General Public License
00020    along with this library; see the file COPYING.LIB.  If not, write to
00021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022    Boston, MA 02110-1301, USA.
00023 */
00024 
00025 #ifndef HTTP_H_
00026 #define HTTP_H_
00027 
00028 
00029 #include <sys/types.h>
00030 #include <netinet/in.h>
00031 #include <arpa/inet.h>
00032 #include <string.h>
00033 #include <stdio.h>
00034 #include <zlib.h>
00035 #include <time.h>
00036 
00037 #include <QtCore/QByteRef>
00038 #include <QtCore/QList>
00039 #include <QtCore/QStringList>
00040 
00041 #include <kurl.h>
00042 #include "kio/tcpslavebase.h"
00043 #include "kio/http.h"
00044 
00045 class QDomNodeList;
00046 
00047 namespace KIO {
00048     class AuthInfo;
00049 }
00050 
00051 class HTTPProtocol : public QObject, public KIO::TCPSlaveBase
00052 {
00053   Q_OBJECT
00054 public:
00055   HTTPProtocol( const QByteArray &protocol, const QByteArray &pool,
00056                 const QByteArray &app );
00057   virtual ~HTTPProtocol();
00058 
00060   enum HTTP_REV    {HTTP_None, HTTP_Unknown, HTTP_10, HTTP_11, SHOUTCAST};
00061 
00063   enum HTTP_AUTH   {AUTH_None, AUTH_Basic, AUTH_NTLM, AUTH_Digest, AUTH_Negotiate};
00064 
00066   // Removed to interfaces/kio/http.h
00067   //enum HTTP_METHOD {HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_HEAD, HTTP_DELETE,
00068   //                  HTTP_OPTIONS, DAV_PROPFIND, DAV_PROPPATCH, DAV_MKCOL,
00069   //                  DAV_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK, DAV_SEARCH };
00070 
00072   struct HTTPState
00073   {
00074     HTTPState ()
00075     {
00076       port = 0;
00077       doProxy = false;
00078     }
00079 
00080     QString hostname;
00081     QString encoded_hostname;
00082     short unsigned int port;
00083     QString user;
00084     QString passwd;
00085     bool doProxy;
00086     KUrl proxyUrl;
00087   };
00088 
00090   struct DAVRequest
00091   {
00092     DAVRequest ()
00093     {
00094       overwrite = false;
00095       depth = 0;
00096     }
00097 
00098     QString desturl;
00099     bool overwrite;
00100     int depth;
00101   };
00102 
00104   struct HTTPRequest
00105   {
00106     HTTPRequest ()
00107     {
00108       port = 0;
00109       method = KIO::HTTP_UNKNOWN;
00110       offset = 0;
00111       endoffset = 0;
00112       doProxy = false;
00113       allowCompressedPage = false;
00114       disablePassDlg = false;
00115       bNoAuth = false;
00116       bUseCache = false;
00117       bCachedRead = false;
00118       bCachedWrite = false;
00119       fcache = 0;
00120       bMustRevalidate = false;
00121       cacheExpireDateOffset = 0;
00122       bErrorPage = false;
00123       bUseCookiejar = false;
00124       expireDate = 0;
00125       creationDate = 0;
00126       bytesCached=0;
00127     }
00128 
00129     QString hostname;
00130     QString encoded_hostname;
00131     short unsigned int port;
00132     QString user;
00133     QString passwd;
00134     QString path;
00135     QString query;
00136     KIO::HTTP_METHOD method;
00137     KIO::CacheControl cache;
00138     KIO::filesize_t offset;
00139     KIO::filesize_t endoffset;
00140     KUrl url;
00141     QString window;                 // Window Id this request is related to.
00142     QString referrer;
00143     QString charsets;
00144     QString languages;
00145     QString userAgent;
00146     QString id;
00147     DAVRequest davData;
00148     bool doProxy;
00149     KUrl proxyUrl;
00150     bool allowCompressedPage;
00151     bool disablePassDlg;
00152     bool bNoAuth; // Do not authenticate
00153 
00154     // Indicates whether an error-page or error-msg should is preferred.
00155     bool bErrorPage;
00156 
00157     // Cookie flags
00158     bool bUseCookiejar;
00159 
00160     // Cache related
00161     bool bUseCache; // Whether the cache is active
00162     bool bCachedRead; // Whether the file is to be read from m_fcache.
00163     bool bCachedWrite; // Whether the file is to be written to m_fcache.
00164     bool bMustRevalidate; // Cache entry is expired.
00165     QString cef; // Cache Entry File belonging to this URL.
00166     gzFile fcache; // File stream of a cache entry
00167     QString etag; // ETag header.
00168     QString lastModified; // Last modified.
00169     long cacheExpireDateOffset; // Position in the cache entry where the
00170                                   // 16 byte expire date is stored.
00171     long bytesCached;
00172     time_t expireDate; // Date when the cache entry will expire
00173     time_t creationDate; // Date when the cache entry was created
00174     QString strCharset;
00175 
00176     // Cookie flags
00177     enum { CookiesAuto, CookiesManual, CookiesNone } cookieMode;
00178   };
00179 
00180   struct DigestAuthInfo
00181   {
00182     QByteArray nc;
00183     QByteArray qop;
00184     QByteArray realm;
00185     QByteArray nonce;
00186     QByteArray method;
00187     QByteArray cnonce;
00188     QByteArray username;
00189     QByteArray password;
00190     KUrl::List digestURI;
00191     QByteArray algorithm;
00192     QByteArray entityBody;
00193   };
00194 
00195 //---------------------- Re-implemented methods ----------------
00196   virtual void setHost(const QString& host, quint16 port, const QString& user,
00197                        const QString& pass);
00198 
00199   virtual void slave_status();
00200 
00201   virtual void get( const KUrl& url );
00202   virtual void put( const KUrl& url, int _mode, KIO::JobFlags flags );
00203 
00204 //----------------- Re-implemented methods for WebDAV -----------
00205   virtual void listDir( const KUrl& url );
00206   virtual void mkdir( const KUrl& url, int _permissions );
00207 
00208   virtual void rename( const KUrl& src, const KUrl& dest, KIO::JobFlags flags );
00209   virtual void copy( const KUrl& src, const KUrl& dest, int _permissions, KIO::JobFlags flags );
00210   virtual void del( const KUrl& url, bool _isfile );
00211 
00212   // ask the host whether it supports WebDAV & cache this info
00213   bool davHostOk();
00214 
00215   // send generic DAV request
00216   void davGeneric( const KUrl& url, KIO::HTTP_METHOD method );
00217 
00218   // Send requests to lock and unlock resources
00219   void davLock( const KUrl& url, const QString& scope,
00220                 const QString& type, const QString& owner );
00221   void davUnlock( const KUrl& url );
00222 
00223   // Calls httpClose() and finished()
00224   void davFinished();
00225 
00226   // Handle error conditions
00227   QString davError( int code = -1, const QString &url = QString() );
00228 //---------------------------- End WebDAV -----------------------
00229 
00239   virtual void special( const QByteArray &data );
00240 
00241   virtual void mimetype( const KUrl& url);
00242 
00243   virtual void stat( const KUrl& url );
00244 
00245   virtual void reparseConfiguration();
00246 
00247   virtual void closeConnection(); // Forced close of connection
00248 
00249   void post( const KUrl& url );
00250   void multiGet(const QByteArray &data);
00251   bool checkRequestUrl( const KUrl& );
00252   void cacheUpdate( const KUrl &url, bool nocache, time_t expireDate);
00253 
00254   void httpError(); // Generate error message based on response code
00255 
00256   bool isOffline(const KUrl &url); // Check network status
00257 
00258 protected Q_SLOTS:
00259   void slotData(const QByteArray &);
00260   void error( int _errid, const QString &_text );
00261 
00262 protected:
00263   int readChunked();    // Read a chunk
00264   int readLimited();    // Read maximum m_iSize bytes.
00265   int readUnlimited();  // Read as much as possible.
00266 
00273   ssize_t write(const void *buf, size_t nbytes);
00274 
00280   ssize_t read (void *b, size_t nbytes);
00281 
00282   char *gets (char *str, int size);
00283 
00284   void setRewindMarker();
00285   void rewind();
00286 
00292   void addEncoding(const QString &, QStringList &);
00293 
00294   void configAuth( char *, bool );
00295 
00296   bool sendQuery();
00297   void httpClose(bool keepAlive);  // Close transfer
00298 
00299   bool httpOpenConnection();   // Open connection
00300   void httpCloseConnection();  // Close connection
00301   bool httpShouldCloseConnection();  // Check whether to keep the connection.
00302 
00303   void forwardHttpResponseHeader();
00304 
00305   bool readResponseHeader();
00306   bool readHeaderFromCache();
00307   void parseContentDisposition(const QString &disposition);
00308 
00309   bool sendBody();
00310 
00311   // where dataInternal == true, the content is to be made available
00312   // to an internal function.
00313   bool readBody( bool dataInternal = false );
00314 
00318   void davSetRequest( const QByteArray& requestXML );
00319   void davStatList( const KUrl& url, bool stat = true );
00320   void davParsePropstats( const QDomNodeList& propstats, KIO::UDSEntry& entry );
00321   void davParseActiveLocks( const QDomNodeList& activeLocks,
00322                             uint& lockCount );
00323 
00327   long parseDateTime( const QString& input, const QString& type );
00328 
00332   int codeFromResponse( const QString& response );
00333 
00338   QString davProcessLocks();
00339 
00343   void addCookies( const QString &url, const QByteArray &cookieHeader);
00344 
00348   QString findCookies( const QString &url);
00349 
00361   gzFile checkCacheEntry(bool readWrite = false);
00362 
00368   void createCacheEntry(const QString &mimetype, time_t expireDate);
00369 
00375   void writeCacheEntry( const char *buffer, int nbytes);
00376 
00380   void closeCacheEntry();
00381 
00385   void updateExpireDate(time_t expireDate, bool updateCreationDate=false);
00386 
00390   void cleanCache();
00391 
00397   // where dataInternal == true, the content is to be made available
00398   // to an internal function.
00399   void proceedUntilResponseContent( bool dataInternal = false );
00400 
00404   bool proceedUntilResponseHeader();
00405 
00409   void resetSessionSettings();
00410 
00414   void resetResponseSettings();
00415 
00422   void resetConnectionSettings();
00423 
00428   QString proxyAuthenticationHeader();
00429 
00433   bool getAuthorization();
00434 
00438   void saveAuthorization();
00439 
00443   QString createBasicAuth( bool isForProxy = false );
00444 
00448   QString createDigestAuth( bool isForProxy = false );
00449 
00453   QString createNTLMAuth( bool isForProxy = false );
00454 
00458   QString createNegotiateAuth();
00459 
00463   QByteArray gssError( int major_status, int minor_status );
00464 
00468   void calculateResponse( DigestAuthInfo &info, QByteArray &Response );
00469 
00473   bool retryPrompt();
00474 
00478   void promptInfo( KIO::AuthInfo& info );
00479 
00480 protected:
00481   HTTPState m_state;
00482   HTTPRequest m_request;
00483   QList<HTTPRequest*> m_requestQueue;
00484   quint16 m_defaultPort;
00485 
00486   // Processing related
00487   KIO::filesize_t m_iSize; // Expected size of message
00488   KIO::filesize_t m_iBytesLeft; // # of bytes left to receive in this message.
00489   KIO::filesize_t m_iContentLeft; // # of content bytes left
00490   QByteArray m_bufReceive; // Receive buffer
00491   char m_lineBuf[1024];
00492   char m_rewindBuf[8192];
00493   size_t m_rewindCount;
00494   size_t m_lineCount;
00495   size_t m_lineCountUnget;
00496   char *m_linePtr;
00497   char *m_lineBufUnget;
00498   char *m_linePtrUnget;
00499   bool m_dataInternal; // Data is for internal consumption
00500   bool m_bChunked; // Chunked transfer encoding
00501 
00502   bool m_bBusy; // Busy handling request queue.
00503   bool m_bEOF;
00504   bool m_bEOD;
00505 
00506   // First request on a connection
00507   bool m_bFirstRequest;
00508 
00509 //--- Settings related to a single response only
00510   bool m_bRedirect; // Indicates current request is a redirection
00511   QStringList m_responseHeaders; // All headers
00512 
00513 
00514   // Language/Encoding related
00515   QStringList m_qTransferEncodings;
00516   QStringList m_qContentEncodings;
00517   QString m_sContentMD5;
00518   QString m_strMimeType;
00519 
00520 
00521 //--- WebDAV
00522   // Data structure to hold data which will be passed to an internal func.
00523   QByteArray m_bufWebDavData;
00524   QStringList m_davCapabilities;
00525 
00526   bool m_davHostOk;
00527   bool m_davHostUnsupported;
00528 //----------
00529 
00530   // Mimetype determination
00531   bool m_cpMimeBuffer;
00532   QByteArray m_mimeTypeBuffer;
00533 
00534 
00535   // Holds the POST data so it won't get lost on if we
00536   // happend to get a 401/407 response when submitting,
00537   // a form.
00538   QByteArray m_bufPOST;
00539 
00540   // Cache related
00541   int m_maxCacheAge; // Maximum age of a cache entry.
00542   long m_maxCacheSize; // Maximum cache size in Kb.
00543   QString m_strCacheDir; // Location of the cache.
00544 
00545 
00546 
00547 //--- Proxy related members
00548   bool m_bUseProxy;
00549   bool m_bNeedTunnel; // Whether we need to make a SSL tunnel
00550   bool m_bIsTunneled; // Whether we have an active SSL tunnel
00551   bool m_bProxyAuthValid;
00552   int m_iProxyPort;
00553   KUrl m_proxyURL;
00554   QString m_strProxyRealm;
00555 
00556   // Operation mode
00557   QByteArray m_protocol;
00558 
00559   // Authentication
00560   QString m_strRealm;
00561   QString m_strAuthorization;
00562   QString m_strProxyAuthorization;
00563   HTTP_AUTH Authentication;
00564   HTTP_AUTH ProxyAuthentication;
00565   short unsigned int m_iProxyAuthCount;
00566   short unsigned int m_iWWWAuthCount;
00567   bool m_bUnauthorized;
00568 
00569   // Persistent proxy connections
00570   bool m_bPersistentProxyConnection;
00571 
00572 
00573   // Indicates whether there was some connection error.
00574   bool m_bError;
00575 
00576   // Persistent connections
00577   bool m_bKeepAlive;
00578   int m_keepAliveTimeout; // Timeout in seconds.
00579 
00580   // Previous and current response codes
00581   unsigned int m_responseCode;
00582   unsigned int m_prevResponseCode;
00583 
00584   // Values that determine the remote connection timeouts.
00585   int m_remoteRespTimeout;
00586 };
00587 #endif

KIOSlave

Skip menu "KIOSlave"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal