1
#ifndef _KviHttpRequest_h_
2
#define _KviHttpRequest_h_
3
//=============================================================================
5
// File : KviHttpRequest.h
6
// Creation date : Sat Aug 17 13:43:31 2002 GMT by Szymon Stefanek
8
// This file is part of the KVIrc irc client distribution
9
// Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
11
// This program is FREE software. You can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your opinion) any later version.
16
// This program is distributed in the HOPE that it will be USEFUL,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
// See the GNU General Public License for more details.
21
// You should have received a copy of the GNU General Public License
22
// along with this program. If not, write to the Free Software Foundation,
23
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
//=============================================================================
27
#include "kvi_settings.h"
28
#include "kvi_inttypes.h"
30
#include "KviHeapObject.h"
31
#include "KviCString.h"
33
#include "KviPointerHashTable.h"
36
#include <QAbstractSocket>
43
// This class implements a HTTP protocol client.
44
// It's able to send GET, POST and HEAD requests,
45
// download stuff to a file or to a qt SLOT().
48
// FIXME: Document and hide internals.
50
class KviHttpRequestPrivate;
52
class KVILIB_API KviHttpRequest : public QObject, public KviHeapObject
59
HeadersOnly, // Download headers only (HEAD request)
60
WholeFile, // Emit the data as whole file (binaryData() is emitted)
61
Blocks, // Emit the data as blocks (binaryData() is emitted)
62
Lines, // Emit the data as ASCII text lines (the client must take care of decoding the data)
63
StoreToFile // Store the data to a file
66
enum ExistingFileAction
68
Overwrite, // Overwrite existing file
69
RenameIncoming, // Automatically rename the incoming file
70
RenameExisting, // Automatically rename the existing file
71
Resume // Attempt to resume the file (get partial content)
78
virtual ~KviHttpRequest();
84
ProcessingType m_eProcessingType;
85
ExistingFileAction m_eExistingFileAction;
86
void * m_pPrivateData;
87
unsigned int m_uMaxContentLength;
88
unsigned int m_uContentOffset;
91
QString m_szLastError;
92
unsigned int m_uTotalSize;
93
unsigned int m_uReceivedSize;
95
bool m_bHeaderProcessed;
96
bool m_bChunkedTransferEncoding;
98
unsigned int m_uRemainingChunkSize;
99
bool m_bIgnoreRemainingData; // used in chunked transfer after the last chunk has been seen
100
unsigned int m_uConnectionTimeout; // in seconds, 60 secs by default
104
KviHttpRequestPrivate * m_p;
108
void setConnectionTimeout(unsigned int uConnectionTimeout)
110
m_uConnectionTimeout = uConnectionTimeout;
111
if(m_uConnectionTimeout < 5)
112
m_uConnectionTimeout = 5; // keep it sane
115
const KviUrl & url(){ return m_url; };
116
ProcessingType processingType(){ return m_eProcessingType; };
117
ExistingFileAction existingFileAction(){ return m_eExistingFileAction; };
118
const QString &fileName(){ return m_szFileName; };
119
void * privateData(){ return m_pPrivateData; };
120
unsigned int maxContentLength(){ return m_uMaxContentLength; };
121
unsigned int contentOffset(){ return m_uContentOffset; };
122
unsigned int totalSize(){ return m_uTotalSize; };
123
unsigned int receivedSize(){ return m_uReceivedSize; };
127
void setPostData(const QString &szPostData){ m_szPostData = szPostData; };
128
void setUrl(const KviUrl &u){ m_url = u; };
129
void setProcessingType(ProcessingType t){ m_eProcessingType = t; };
130
void setExistingFileAction(ExistingFileAction a){ m_eExistingFileAction = a; };
131
void setFileName(const QString &szFileName){ m_szFileName = szFileName; };
132
void setPrivateData(void * ptr){ m_pPrivateData = ptr; };
133
void setMaxContentLength(int uMaxContentLength){ m_uMaxContentLength = uMaxContentLength; }; //0 means unlimited
134
// this will work regardless of ExistingFileAction : even if the file doesn't exist
135
void setContentOffset(int uContentOffset){ m_uContentOffset = uContentOffset; };
139
// this is a shortcut for reset()+setUrl()+setProcessingType()+setFileName()+start()
140
bool get(const KviUrl &u,ProcessingType p = WholeFile,const QString &szFileName = QString());
142
const QString & lastError(){ return m_szLastError; };
146
void resolvingHost(const QString &hostname);
147
void contactingHost(const QString &ipandport);
148
void connectionEstabilished();
149
void receivedResponse(const QString &response);
151
void terminated(bool bSuccess);
153
void status(const QString &message);
154
void data(const KviCString &data);
155
void binaryData(const KviDataBuffer &data);
156
void header(KviPointerHashTable<const char *,KviCString> * hdr);
157
void requestSent(const QStringList &request);
163
void processData(KviDataBuffer * data);
164
bool processHeader(KviCString &szHeader);
166
void emitLines(KviDataBuffer * pDataBuffer);
170
void resetInternalStatus();
173
void slotSocketReadDataReady();
174
void slotSocketDisconnected();
175
void slotSocketConnected();
176
void slotSocketError(QAbstractSocket::SocketError socketError);
177
void slotConnectionTimedOut();
178
void slotSocketHostResolved();
182
#endif //_KviHttpRequest_h_