1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
33
#include "QtCore/qobject.h"
34
#include "Qt3Support/q3networkprotocol.h"
35
#include "QtCore/qmap.h"
36
#include "QtCore/qstringlist.h"
39
#ifndef QT_NO_NETWORKPROTOCOL_HTTP
49
class Q_COMPAT_EXPORT Q3HttpHeader
53
Q3HttpHeader( const Q3HttpHeader& header );
54
Q3HttpHeader( const QString& str );
55
virtual ~Q3HttpHeader();
57
Q3HttpHeader& operator=( const Q3HttpHeader& h );
59
QString value( const QString& key ) const;
60
void setValue( const QString& key, const QString& value );
61
void removeValue( const QString& key );
63
QStringList keys() const;
64
bool hasKey( const QString& key ) const;
66
bool hasContentLength() const;
67
uint contentLength() const;
68
void setContentLength( int len );
70
bool hasContentType() const;
71
QString contentType() const;
72
void setContentType( const QString& type );
74
virtual QString toString() const;
77
virtual int majorVersion() const = 0;
78
virtual int minorVersion() const = 0;
81
virtual bool parseLine( const QString& line, int number );
82
bool parse( const QString& str );
83
void setValid( bool );
86
QMap<QString,QString> values;
90
class Q_COMPAT_EXPORT Q3HttpResponseHeader : public Q3HttpHeader
93
Q3HttpResponseHeader( int code, const QString& text = QString(), int majorVer = 1, int minorVer = 1 );
94
Q3HttpResponseHeader( const QString& str );
96
void setStatusLine( int code, const QString& text = QString(), int majorVer = 1, int minorVer = 1 );
99
Q3HttpResponseHeader();
100
Q3HttpResponseHeader( const Q3HttpResponseHeader& header );
102
int statusCode() const;
103
QString reasonPhrase() const;
105
int majorVersion() const;
106
int minorVersion() const;
108
QString toString() const;
111
bool parseLine( const QString& line, int number );
122
class Q_COMPAT_EXPORT Q3HttpRequestHeader : public Q3HttpHeader
125
Q3HttpRequestHeader();
126
Q3HttpRequestHeader( const QString& method, const QString& path, int majorVer = 1, int minorVer = 1 );
127
Q3HttpRequestHeader( const Q3HttpRequestHeader& header );
128
Q3HttpRequestHeader( const QString& str );
130
void setRequest( const QString& method, const QString& path, int majorVer = 1, int minorVer = 1 );
132
QString method() const;
133
QString path() const;
135
int majorVersion() const;
136
int minorVersion() const;
138
QString toString() const;
141
bool parseLine( const QString& line, int number );
150
class Q_COMPAT_EXPORT Q3Http : public Q3NetworkProtocol
156
Q3Http( QObject* parent, const char* name = 0 ); // ### Qt 4.0: make parent=0 and get rid of the Q3Http() constructor
157
Q3Http( const QString &hostname, Q_UINT16 port=80, QObject* parent=0, const char* name = 0 );
160
int supportedOperations() const;
162
enum State { Unconnected, HostLookup, Connecting, Sending, Reading, Connected, Closing };
169
InvalidResponseHeader,
174
int setHost(const QString &hostname, Q_UINT16 port=80 );
176
int get( const QString& path, QIODevice* to=0 );
177
int post( const QString& path, QIODevice* data, QIODevice* to=0 );
178
int post( const QString& path, const QByteArray& data, QIODevice* to=0 );
179
int head( const QString& path );
180
int request( const Q3HttpRequestHeader &header, QIODevice *device=0, QIODevice *to=0 );
181
int request( const Q3HttpRequestHeader &header, const QByteArray &data, QIODevice *to=0 );
183
int closeConnection();
185
Q_ULONG bytesAvailable() const;
186
Q_LONG readBlock( char *data, Q_ULONG maxlen );
187
QByteArray readAll();
189
int currentId() const;
190
QIODevice* currentSourceDevice() const;
191
QIODevice* currentDestinationDevice() const;
192
Q3HttpRequestHeader currentRequest() const;
193
bool hasPendingRequests() const;
194
void clearPendingRequests();
199
QString errorString() const;
205
void stateChanged( int );
206
void responseHeaderReceived( const Q3HttpResponseHeader& resp );
207
void readyRead( const Q3HttpResponseHeader& resp );
208
void dataSendProgress( int, int );
209
void dataReadProgress( int, int );
211
void requestStarted( int );
212
void requestFinished( int, bool );
216
void operationGet( Q3NetworkOperation *op );
217
void operationPut( Q3NetworkOperation *op );
219
void timerEvent( QTimerEvent * );
222
void clientReply( const Q3HttpResponseHeader &rep );
223
void clientDone( bool );
224
void clientStateChanged( int );
226
void startNextRequest();
227
void slotReadyRead();
228
void slotConnected();
229
void slotError( int );
231
void slotBytesWritten( int );
235
void *unused; // ### Qt 4.0: remove this (in for binary compatibility)
238
int addRequest( Q3HttpRequest * );
240
void finishedWithSuccess();
241
void finishedWithError( const QString& detail, int errorCode );
243
void killIdleTimer();
246
void setState( int );
249
friend class Q3HttpNormalRequest;
250
friend class Q3HttpSetHostRequest;
251
friend class Q3HttpCloseRequest;
252
friend class Q3HttpPGHRequest;