~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/network/q3http.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef Q3HTTP_H
 
30
#define Q3HTTP_H
 
31
 
 
32
#ifndef QT_H
 
33
#include "QtCore/qobject.h"
 
34
#include "Qt3Support/q3networkprotocol.h"
 
35
#include "QtCore/qmap.h"
 
36
#include "QtCore/qstringlist.h"
 
37
#endif // QT_H
 
38
 
 
39
#ifndef QT_NO_NETWORKPROTOCOL_HTTP
 
40
 
 
41
class Q3Socket;
 
42
class QTimerEvent;
 
43
class QTextStream;
 
44
class QIODevice;
 
45
 
 
46
class Q3HttpPrivate;
 
47
class Q3HttpRequest;
 
48
 
 
49
class Q_COMPAT_EXPORT Q3HttpHeader
 
50
{
 
51
public:
 
52
    Q3HttpHeader();
 
53
    Q3HttpHeader( const Q3HttpHeader& header );
 
54
    Q3HttpHeader( const QString& str );
 
55
    virtual ~Q3HttpHeader();
 
56
 
 
57
    Q3HttpHeader& operator=( const Q3HttpHeader& h );
 
58
 
 
59
    QString value( const QString& key ) const;
 
60
    void setValue( const QString& key, const QString& value );
 
61
    void removeValue( const QString& key );
 
62
 
 
63
    QStringList keys() const;
 
64
    bool hasKey( const QString& key ) const;
 
65
 
 
66
    bool hasContentLength() const;
 
67
    uint contentLength() const;
 
68
    void setContentLength( int len );
 
69
 
 
70
    bool hasContentType() const;
 
71
    QString contentType() const;
 
72
    void setContentType( const QString& type );
 
73
 
 
74
    virtual QString toString() const;
 
75
    bool isValid() const;
 
76
 
 
77
    virtual int majorVersion() const = 0;
 
78
    virtual int minorVersion() const = 0;
 
79
 
 
80
protected:
 
81
    virtual bool parseLine( const QString& line, int number );
 
82
    bool parse( const QString& str );
 
83
    void setValid( bool );
 
84
 
 
85
private:
 
86
    QMap<QString,QString> values;
 
87
    bool valid;
 
88
};
 
89
 
 
90
class Q_COMPAT_EXPORT Q3HttpResponseHeader : public Q3HttpHeader
 
91
{
 
92
private:
 
93
    Q3HttpResponseHeader( int code, const QString& text = QString(), int majorVer = 1, int minorVer = 1 );
 
94
    Q3HttpResponseHeader( const QString& str );
 
95
 
 
96
    void setStatusLine( int code, const QString& text = QString(), int majorVer = 1, int minorVer = 1 );
 
97
 
 
98
public:
 
99
    Q3HttpResponseHeader();
 
100
    Q3HttpResponseHeader( const Q3HttpResponseHeader& header );
 
101
 
 
102
    int statusCode() const;
 
103
    QString reasonPhrase() const;
 
104
 
 
105
    int majorVersion() const;
 
106
    int minorVersion() const;
 
107
 
 
108
    QString toString() const;
 
109
 
 
110
protected:
 
111
    bool parseLine( const QString& line, int number );
 
112
 
 
113
private:
 
114
    int statCode;
 
115
    QString reasonPhr;
 
116
    int majVer;
 
117
    int minVer;
 
118
 
 
119
    friend class Q3Http;
 
120
};
 
121
 
 
122
class Q_COMPAT_EXPORT Q3HttpRequestHeader : public Q3HttpHeader
 
123
{
 
124
public:
 
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 );
 
129
 
 
130
    void setRequest( const QString& method, const QString& path, int majorVer = 1, int minorVer = 1 );
 
131
 
 
132
    QString method() const;
 
133
    QString path() const;
 
134
 
 
135
    int majorVersion() const;
 
136
    int minorVersion() const;
 
137
 
 
138
    QString toString() const;
 
139
 
 
140
protected:
 
141
    bool parseLine( const QString& line, int number );
 
142
 
 
143
private:
 
144
    QString m;
 
145
    QString p;
 
146
    int majVer;
 
147
    int minVer;
 
148
};
 
149
 
 
150
class Q_COMPAT_EXPORT Q3Http : public Q3NetworkProtocol
 
151
{
 
152
    Q_OBJECT
 
153
 
 
154
public:
 
155
    Q3Http();
 
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 );
 
158
    virtual ~Q3Http();
 
159
 
 
160
    int supportedOperations() const;
 
161
 
 
162
    enum State { Unconnected, HostLookup, Connecting, Sending, Reading, Connected, Closing };
 
163
    enum Error {
 
164
        NoError,
 
165
        UnknownError,
 
166
        HostNotFound,
 
167
        ConnectionRefused,
 
168
        UnexpectedClose,
 
169
        InvalidResponseHeader,
 
170
        WrongContentLength,
 
171
        Aborted
 
172
    };
 
173
 
 
174
    int setHost(const QString &hostname, Q_UINT16 port=80 );
 
175
 
 
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 );
 
182
 
 
183
    int closeConnection();
 
184
 
 
185
    Q_ULONG bytesAvailable() const;
 
186
    Q_LONG readBlock( char *data, Q_ULONG maxlen );
 
187
    QByteArray readAll();
 
188
 
 
189
    int currentId() const;
 
190
    QIODevice* currentSourceDevice() const;
 
191
    QIODevice* currentDestinationDevice() const;
 
192
    Q3HttpRequestHeader currentRequest() const;
 
193
    bool hasPendingRequests() const;
 
194
    void clearPendingRequests();
 
195
 
 
196
    State state() const;
 
197
 
 
198
    Error error() const;
 
199
    QString errorString() const;
 
200
 
 
201
public slots:
 
202
    void abort();
 
203
 
 
204
signals:
 
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 );
 
210
 
 
211
    void requestStarted( int );
 
212
    void requestFinished( int, bool );
 
213
    void done( bool );
 
214
 
 
215
protected:
 
216
    void operationGet( Q3NetworkOperation *op );
 
217
    void operationPut( Q3NetworkOperation *op );
 
218
 
 
219
    void timerEvent( QTimerEvent * );
 
220
 
 
221
private slots:
 
222
    void clientReply( const Q3HttpResponseHeader &rep );
 
223
    void clientDone( bool );
 
224
    void clientStateChanged( int );
 
225
 
 
226
    void startNextRequest();
 
227
    void slotReadyRead();
 
228
    void slotConnected();
 
229
    void slotError( int );
 
230
    void slotClosed();
 
231
    void slotBytesWritten( int );
 
232
 
 
233
private:
 
234
    Q3HttpPrivate *d;
 
235
    void *unused; // ### Qt 4.0: remove this (in for binary compatibility)
 
236
    int bytesRead;
 
237
 
 
238
    int addRequest( Q3HttpRequest * );
 
239
    void sendRequest();
 
240
    void finishedWithSuccess();
 
241
    void finishedWithError( const QString& detail, int errorCode );
 
242
 
 
243
    void killIdleTimer();
 
244
 
 
245
    void init();
 
246
    void setState( int );
 
247
    void close();
 
248
 
 
249
    friend class Q3HttpNormalRequest;
 
250
    friend class Q3HttpSetHostRequest;
 
251
    friend class Q3HttpCloseRequest;
 
252
    friend class Q3HttpPGHRequest;
 
253
};
 
254
 
 
255
#endif
 
256
 
 
257
#endif