• 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 QAuthenticator;
00046 class QDomNodeList;
00047 class QNetworkProxy;
00048 
00049 namespace KIO {
00050     class AuthInfo;
00051 }
00052 
00053 class HTTPProtocol : public QObject, public KIO::TCPSlaveBase
00054 {
00055   Q_OBJECT
00056 public:
00057   HTTPProtocol( const QByteArray &protocol, const QByteArray &pool,
00058                 const QByteArray &app );
00059   virtual ~HTTPProtocol();
00060 
00062   enum HTTP_REV    {HTTP_None, HTTP_Unknown, HTTP_10, HTTP_11, SHOUTCAST};
00063 
00065   enum HTTP_AUTH   {AUTH_None, AUTH_Basic, AUTH_NTLM, AUTH_Digest, AUTH_Negotiate};
00066 
00068   // Removed to interfaces/kio/http.h
00069   //enum HTTP_METHOD {HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_HEAD, HTTP_DELETE,
00070   //                  HTTP_OPTIONS, DAV_PROPFIND, DAV_PROPPATCH, DAV_MKCOL,
00071   //                  DAV_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK, DAV_SEARCH };
00072 
00074   struct HTTPState
00075   {
00076     HTTPState ()
00077     {
00078       port = 0;
00079       doProxy = false;
00080     }
00081 
00082     QString hostname;
00083     QString encoded_hostname;
00084     short unsigned int port;
00085     QString user;
00086     QString passwd;
00087     bool doProxy;
00088     KUrl proxyUrl;
00089   };
00090 
00092   struct DAVRequest
00093   {
00094     DAVRequest ()
00095     {
00096       overwrite = false;
00097       depth = 0;
00098     }
00099 
00100     QString desturl;
00101     bool overwrite;
00102     int depth;
00103   };
00104 
00106   struct HTTPRequest
00107   {
00108     HTTPRequest ()
00109     {
00110       port = 0;
00111       method = KIO::HTTP_UNKNOWN;
00112       offset = 0;
00113       endoffset = 0;
00114       doProxy = false;
00115       allowCompressedPage = false;
00116       disablePassDlg = false;
00117       bNoAuth = false;
00118       bUseCache = false;
00119       bCachedRead = false;
00120       bCachedWrite = false;
00121       fcache = 0;
00122       bMustRevalidate = false;
00123       cacheExpireDateOffset = 0;
00124       bErrorPage = false;
00125       bUseCookiejar = false;
00126       expireDate = 0;
00127       creationDate = 0;
00128       bytesCached=0;
00129     }
00130 
00131     QString hostname;
00132     QString encoded_hostname;
00133     short unsigned int port;
00134     QString user;
00135     QString passwd;
00136     QString path;
00137     QString query;
00138     KIO::HTTP_METHOD method;
00139     KIO::CacheControl cache;
00140     KIO::filesize_t offset;
00141     KIO::filesize_t endoffset;
00142     KUrl url;
00143     QString window;                 // Window Id this request is related to.
00144     QString referrer;
00145     QString charsets;
00146     QString languages;
00147     QString userAgent;
00148     QString id;
00149     DAVRequest davData;
00150     bool doProxy;
00151     KUrl proxyUrl;
00152     bool allowCompressedPage;
00153     bool disablePassDlg;
00154     bool bNoAuth; // Do not authenticate
00155 
00156     // Indicates whether an error-page or error-msg should is preferred.
00157     bool bErrorPage;
00158 
00159     // Cookie flags
00160     bool bUseCookiejar;
00161 
00162     // Cache related
00163     bool bUseCache; // Whether the cache is active
00164     bool bCachedRead; // Whether the file is to be read from m_fcache.
00165     bool bCachedWrite; // Whether the file is to be written to m_fcache.
00166     bool bMustRevalidate; // Cache entry is expired.
00167     QString cef; // Cache Entry File belonging to this URL.
00168     gzFile fcache; // File stream of a cache entry
00169     QString etag; // ETag header.
00170     QString lastModified; // Last modified.
00171     long cacheExpireDateOffset; // Position in the cache entry where the
00172                                   // 16 byte expire date is stored.
00173     long bytesCached;
00174     time_t expireDate; // Date when the cache entry will expire
00175     time_t creationDate; // Date when the cache entry was created
00176     QString strCharset;
00177 
00178     // Cookie flags
00179     enum { CookiesAuto, CookiesManual, CookiesNone } cookieMode;
00180   };
00181 
00182   struct DigestAuthInfo
00183   {
00184     QByteArray nc;
00185     QByteArray qop;
00186     QByteArray realm;
00187     QByteArray nonce;
00188     QByteArray method;
00189     QByteArray cnonce;
00190     QByteArray username;
00191     QByteArray password;
00192     KUrl::List digestURI;
00193     QByteArray algorithm;
00194     QByteArray entityBody;
00195   };
00196 
00197 //---------------------- Re-implemented methods ----------------
00198   virtual void setHost(const QString& host, quint16 port, const QString& user,
00199                        const QString& pass);
00200 
00201   virtual void slave_status();
00202 
00203   virtual void get( const KUrl& url );
00204   virtual void put( const KUrl& url, int _mode, KIO::JobFlags flags );
00205 
00206 //----------------- Re-implemented methods for WebDAV -----------
00207   virtual void listDir( const KUrl& url );
00208   virtual void mkdir( const KUrl& url, int _permissions );
00209 
00210   virtual void rename( const KUrl& src, const KUrl& dest, KIO::JobFlags flags );
00211   virtual void copy( const KUrl& src, const KUrl& dest, int _permissions, KIO::JobFlags flags );
00212   virtual void del( const KUrl& url, bool _isfile );
00213 
00214   // ask the host whether it supports WebDAV & cache this info
00215   bool davHostOk();
00216 
00217   // send generic DAV request
00218   void davGeneric( const KUrl& url, KIO::HTTP_METHOD method );
00219 
00220   // Send requests to lock and unlock resources
00221   void davLock( const KUrl& url, const QString& scope,
00222                 const QString& type, const QString& owner );
00223   void davUnlock( const KUrl& url );
00224 
00225   // Calls httpClose() and finished()
00226   void davFinished();
00227 
00228   // Handle error conditions
00229   QString davError( int code = -1, const QString &url = QString() );
00230 //---------------------------- End WebDAV -----------------------
00231 
00241   virtual void special( const QByteArray &data );
00242 
00243   virtual void mimetype( const KUrl& url);
00244 
00245   virtual void stat( const KUrl& url );
00246 
00247   virtual void reparseConfiguration();
00248 
00249   virtual void closeConnection(); // Forced close of connection
00250 
00251   void post( const KUrl& url );
00252   void multiGet(const QByteArray &data);
00253   bool checkRequestUrl( const KUrl& );
00254   void cacheUpdate( const KUrl &url, bool nocache, time_t expireDate);
00255 
00256   void httpError(); // Generate error message based on response code
00257 
00258   bool isOffline(const KUrl &url); // Check network status
00259 
00260 protected Q_SLOTS:
00261   void slotData(const QByteArray &);
00262   void error(int errid, const QString &text);
00263   void proxyAuthenticationForSocket(const QNetworkProxy &, QAuthenticator *);
00264   void saveProxyAuthenticationForSocket();
00265 
00266 protected:
00267   int readChunked();    // Read a chunk
00268   int readLimited();    // Read maximum m_iSize bytes.
00269   int readUnlimited();  // Read as much as possible.
00270 
00277   ssize_t write(const void *buf, size_t nbytes);
00278 
00284   ssize_t read (void *b, size_t nbytes);
00285 
00286   char *gets (char *str, int size);
00287 
00288   void setRewindMarker();
00289   void rewind();
00290 
00296   void addEncoding(const QString &, QStringList &);
00297 
00298   void configAuth( char *, bool );
00299 
00300   bool sendQuery();
00301   void httpClose(bool keepAlive);  // Close transfer
00302 
00303   bool httpOpenConnection();   // Open connection
00304   void httpCloseConnection();  // Close connection
00305   bool httpShouldCloseConnection();  // Check whether to keep the connection.
00306 
00307   void forwardHttpResponseHeader();
00308 
00309   bool readResponseHeader();
00310   bool readHeaderFromCache();
00311   void parseContentDisposition(const QString &disposition);
00312 
00313   bool sendBody();
00314 
00315   // where dataInternal == true, the content is to be made available
00316   // to an internal function.
00317   bool readBody( bool dataInternal = false );
00318 
00322   void davSetRequest( const QByteArray& requestXML );
00323   void davStatList( const KUrl& url, bool stat = true );
00324   void davParsePropstats( const QDomNodeList& propstats, KIO::UDSEntry& entry );
00325   void davParseActiveLocks( const QDomNodeList& activeLocks,
00326                             uint& lockCount );
00327 
00331   long parseDateTime( const QString& input, const QString& type );
00332 
00336   int codeFromResponse( const QString& response );
00337 
00342   QString davProcessLocks();
00343 
00347   void addCookies( const QString &url, const QByteArray &cookieHeader);
00348 
00352   QString findCookies( const QString &url);
00353 
00365   gzFile checkCacheEntry(bool readWrite = false);
00366 
00372   void createCacheEntry(const QString &mimetype, time_t expireDate);
00373 
00379   void writeCacheEntry( const char *buffer, int nbytes);
00380 
00384   void closeCacheEntry();
00385 
00389   void updateExpireDate(time_t expireDate, bool updateCreationDate=false);
00390 
00394   void cleanCache();
00395 
00401   // where dataInternal == true, the content is to be made available
00402   // to an internal function.
00403   void proceedUntilResponseContent( bool dataInternal = false );
00404 
00408   bool proceedUntilResponseHeader();
00409 
00413   void resetSessionSettings();
00414 
00418   void resetResponseSettings();
00419 
00426   void resetConnectionSettings();
00427 
00432   QString proxyAuthenticationHeader();
00433 
00437   bool getAuthorization();
00438 
00442   void saveAuthorization(bool isForProxy);
00443 
00447   QString createBasicAuth( bool isForProxy = false );
00448 
00452   QString createDigestAuth( bool isForProxy = false );
00453 
00457   QString createNTLMAuth( bool isForProxy = false );
00458 
00462   QString createNegotiateAuth();
00463 
00467   QByteArray gssError( int major_status, int minor_status );
00468 
00472   void calculateResponse( DigestAuthInfo &info, QByteArray &Response );
00473 
00477   bool retryPrompt();
00478 
00482   void promptInfo( KIO::AuthInfo& info );
00483 
00484 protected:
00485   HTTPState m_state;
00486   HTTPRequest m_request;
00487   QList<HTTPRequest*> m_requestQueue;
00488   quint16 m_defaultPort;
00489 
00490   // Processing related
00491   KIO::filesize_t m_iSize; // Expected size of message
00492   KIO::filesize_t m_iBytesLeft; // # of bytes left to receive in this message.
00493   KIO::filesize_t m_iContentLeft; // # of content bytes left
00494   QByteArray m_bufReceive; // Receive buffer
00495   char m_lineBuf[1024];
00496   char m_rewindBuf[8192];
00497   size_t m_rewindCount;
00498   size_t m_lineCount;
00499   size_t m_lineCountUnget;
00500   char *m_linePtr;
00501   char *m_lineBufUnget;
00502   char *m_linePtrUnget;
00503   bool m_dataInternal; // Data is for internal consumption
00504   bool m_bChunked; // Chunked transfer encoding
00505 
00506   bool m_bBusy; // Busy handling request queue.
00507   bool m_bEOF;
00508   bool m_bEOD;
00509 
00510   // First request on a connection
00511   bool m_bFirstRequest;
00512 
00513 //--- Settings related to a single response only
00514   bool m_bRedirect; // Indicates current request is a redirection
00515   QStringList m_responseHeaders; // All headers
00516 
00517 
00518   // Language/Encoding related
00519   QStringList m_qTransferEncodings;
00520   QStringList m_qContentEncodings;
00521   QString m_sContentMD5;
00522   QString m_strMimeType;
00523 
00524 
00525 //--- WebDAV
00526   // Data structure to hold data which will be passed to an internal func.
00527   QByteArray m_bufWebDavData;
00528   QStringList m_davCapabilities;
00529 
00530   bool m_davHostOk;
00531   bool m_davHostUnsupported;
00532 //----------
00533 
00534   // Mimetype determination
00535   bool m_cpMimeBuffer;
00536   QByteArray m_mimeTypeBuffer;
00537 
00538 
00539   // Holds the POST data so it won't get lost on if we
00540   // happend to get a 401/407 response when submitting,
00541   // a form.
00542   QByteArray m_bufPOST;
00543 
00544   // Cache related
00545   int m_maxCacheAge; // Maximum age of a cache entry.
00546   long m_maxCacheSize; // Maximum cache size in Kb.
00547   QString m_strCacheDir; // Location of the cache.
00548 
00549 
00550 
00551 //--- Proxy related members
00552   bool m_bUseProxy;
00553   bool m_bNeedTunnel; // Whether we need to make a SSL tunnel
00554   bool m_bIsTunneled; // Whether we have an active SSL tunnel
00555   bool m_bProxyAuthValid;
00556   int m_iProxyPort;
00557   KUrl m_proxyURL;
00558   QString m_strProxyRealm;
00559 
00560   // Operation mode
00561   QByteArray m_protocol;
00562 
00563   // Authentication
00564   QString m_strRealm;
00565   QString m_strAuthorization;
00566   QString m_strProxyAuthorization;
00567   HTTP_AUTH Authentication;
00568   HTTP_AUTH ProxyAuthentication;
00569   short unsigned int m_iProxyAuthCount;
00570   short unsigned int m_iWWWAuthCount;
00571   bool m_bUnauthorized;
00572 
00573   // Persistent proxy connections
00574   bool m_bPersistentProxyConnection;
00575 
00576 
00577   // Indicates whether there was some connection error.
00578   bool m_bError;
00579 
00580   // Persistent connections
00581   bool m_bKeepAlive;
00582   int m_keepAliveTimeout; // Timeout in seconds.
00583 
00584   // Previous and current response codes
00585   unsigned int m_responseCode;
00586   unsigned int m_prevResponseCode;
00587 
00588   // Values that determine the remote connection timeouts.
00589   int m_remoteRespTimeout;
00590 };
00591 #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.6
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