Eneboo - Documentación para desarrolladores
src/qt/include/qhttp.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qhttp.h   3.3.8   edited Jan 11 14:46 $
00003 **
00004 ** Definition of QHttp and related classes.
00005 **
00006 ** Created : 970521
00007 **
00008 ** Copyright (C) 1997-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the network module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00022 ** file in accordance with the Qt Commercial License Agreement provided
00023 ** with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QHTTP_H
00039 #define QHTTP_H
00040 
00041 #ifndef QT_H
00042 #include "qobject.h"
00043 #include "qnetworkprotocol.h"
00044 #include "qstringlist.h"
00045 #endif // QT_H
00046 
00047 #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
00048 #define QM_EXPORT_HTTP
00049 #define QM_TEMPLATE_EXTERN_HTTP
00050 #else
00051 #define QM_EXPORT_HTTP Q_EXPORT
00052 #define QM_TEMPLATE_EXTERN_HTTP Q_TEMPLATE_EXTERN
00053 #endif
00054 
00055 #ifndef QT_NO_NETWORKPROTOCOL_HTTP
00056 
00057 class QSocket;
00058 class QTimerEvent;
00059 class QTextStream;
00060 class QIODevice;
00061 
00062 class QHttpPrivate;
00063 class QHttpRequest;
00064 
00065 class QM_EXPORT_HTTP QHttpHeader
00066 {
00067 public:
00068     QHttpHeader();
00069     QHttpHeader( const QHttpHeader& header );
00070     QHttpHeader( const QString& str );
00071     virtual ~QHttpHeader();
00072 
00073     QHttpHeader& operator=( const QHttpHeader& h );
00074 
00075     QString value( const QString& key ) const;
00076     void setValue( const QString& key, const QString& value );
00077     void removeValue( const QString& key );
00078 
00079     QStringList keys() const;
00080     bool hasKey( const QString& key ) const;
00081 
00082     bool hasContentLength() const;
00083     uint contentLength() const;
00084     void setContentLength( int len );
00085 
00086     bool hasContentType() const;
00087     QString contentType() const;
00088     void setContentType( const QString& type );
00089 
00090     virtual QString toString() const;
00091     bool isValid() const;
00092 
00093     virtual int majorVersion() const = 0;
00094     virtual int minorVersion() const = 0;
00095 
00096 protected:
00097     virtual bool parseLine( const QString& line, int number );
00098     bool parse( const QString& str );
00099     void setValid( bool );
00100 
00101 private:
00102     QMap<QString,QString> values;
00103     bool valid;
00104 };
00105 
00106 class QM_EXPORT_HTTP QHttpResponseHeader : public QHttpHeader
00107 {
00108 private:
00109     QHttpResponseHeader( int code, const QString& text = QString::null, int majorVer = 1, int minorVer = 1 );
00110     QHttpResponseHeader( const QString& str );
00111 
00112     void setStatusLine( int code, const QString& text = QString::null, int majorVer = 1, int minorVer = 1 );
00113 
00114 public:
00115     QHttpResponseHeader();
00116     QHttpResponseHeader( const QHttpResponseHeader& header );
00117 
00118     int statusCode() const;
00119     QString reasonPhrase() const;
00120 
00121     int majorVersion() const;
00122     int minorVersion() const;
00123 
00124     QString toString() const;
00125 
00126 protected:
00127     bool parseLine( const QString& line, int number );
00128 
00129 private:
00130     int statCode;
00131     QString reasonPhr;
00132     int majVer;
00133     int minVer;
00134 
00135     friend class QHttp;
00136 };
00137 
00138 class QM_EXPORT_HTTP QHttpRequestHeader : public QHttpHeader
00139 {
00140 public:
00141     QHttpRequestHeader();
00142     QHttpRequestHeader( const QString& method, const QString& path, int majorVer = 1, int minorVer = 1 );
00143     QHttpRequestHeader( const QHttpRequestHeader& header );
00144     QHttpRequestHeader( const QString& str );
00145 
00146     void setRequest( const QString& method, const QString& path, int majorVer = 1, int minorVer = 1 );
00147 
00148     QString method() const;
00149     QString path() const;
00150 
00151     int majorVersion() const;
00152     int minorVersion() const;
00153 
00154     QString toString() const;
00155 
00156 protected:
00157     bool parseLine( const QString& line, int number );
00158 
00159 private:
00160     QString m;
00161     QString p;
00162     int majVer;
00163     int minVer;
00164 };
00165 
00166 class QM_EXPORT_HTTP QHttp : public QNetworkProtocol
00167 {
00168     Q_OBJECT
00169 
00170 public:
00171     QHttp();
00172     QHttp( QObject* parent, const char* name = 0 ); // ### Qt 4.0: make parent=0 and get rid of the QHttp() constructor
00173     QHttp( const QString &hostname, Q_UINT16 port=80, QObject* parent=0, const char* name = 0 );
00174     virtual ~QHttp();
00175 
00176     int supportedOperations() const;
00177 
00178     enum State { Unconnected, HostLookup, Connecting, Sending, Reading, Connected, Closing };
00179     enum Error {
00180         NoError,
00181         UnknownError,
00182         HostNotFound,
00183         ConnectionRefused,
00184         UnexpectedClose,
00185         InvalidResponseHeader,
00186         WrongContentLength,
00187         Aborted
00188     };
00189 
00190     int setHost(const QString &hostname, Q_UINT16 port=80 );
00191 
00192     int get( const QString& path, QIODevice* to=0 );
00193     int post( const QString& path, QIODevice* data, QIODevice* to=0  );
00194     int post( const QString& path, const QByteArray& data, QIODevice* to=0 );
00195     int head( const QString& path );
00196     int request( const QHttpRequestHeader &header, QIODevice *device=0, QIODevice *to=0 );
00197     int request( const QHttpRequestHeader &header, const QByteArray &data, QIODevice *to=0 );
00198 
00199     int closeConnection();
00200 
00201     Q_ULONG bytesAvailable() const;
00202     Q_LONG readBlock( char *data, Q_ULONG maxlen );
00203     QByteArray readAll();
00204 
00205     int currentId() const;
00206     QIODevice* currentSourceDevice() const;
00207     QIODevice* currentDestinationDevice() const;
00208     QHttpRequestHeader currentRequest() const;
00209     bool hasPendingRequests() const;
00210     void clearPendingRequests();
00211 
00212     State state() const;
00213 
00214     Error error() const;
00215     QString errorString() const;
00216 
00217 public slots:
00218     void abort();
00219 
00220 signals:
00221     void stateChanged( int );
00222     void responseHeaderReceived( const QHttpResponseHeader& resp );
00223     void readyRead( const QHttpResponseHeader& resp );
00224     void dataSendProgress( int, int );
00225     void dataReadProgress( int, int );
00226 
00227     void requestStarted( int );
00228     void requestFinished( int, bool );
00229     void done( bool );
00230 
00231 protected:
00232     void operationGet( QNetworkOperation *op );
00233     void operationPut( QNetworkOperation *op );
00234 
00235     void timerEvent( QTimerEvent * );
00236 
00237 private slots:
00238     void clientReply( const QHttpResponseHeader &rep );
00239     void clientDone( bool );
00240     void clientStateChanged( int );
00241 
00242     void startNextRequest();
00243     void slotReadyRead();
00244     void slotConnected();
00245     void slotError( int );
00246     void slotClosed();
00247     void slotBytesWritten( int );
00248 
00249 private:
00250     QHttpPrivate *d;
00251     void *unused; // ### Qt 4.0: remove this (in for binary compatibility)
00252     int bytesRead;
00253 
00254     int addRequest( QHttpRequest * );
00255     void sendRequest();
00256     void finishedWithSuccess();
00257     void finishedWithError( const QString& detail, int errorCode );
00258 
00259     void killIdleTimer();
00260 
00261     void init();
00262     void setState( int );
00263     void close();
00264 
00265     friend class QHttpNormalRequest;
00266     friend class QHttpSetHostRequest;
00267     friend class QHttpCloseRequest;
00268     friend class QHttpPGHRequest;
00269 };
00270 
00271 #define Q_DEFINED_QHTTP
00272 #include "qwinexport.h"
00273 #endif
00274 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'