~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvilib/net/KviHttpRequest.h

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _KviHttpRequest_h_
 
2
#define _KviHttpRequest_h_
 
3
//=============================================================================
 
4
//
 
5
//   File : KviHttpRequest.h
 
6
//   Creation date : Sat Aug 17 13:43:31 2002 GMT by Szymon Stefanek
 
7
//
 
8
//   This file is part of the KVIrc irc client distribution
 
9
//   Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
 
10
//
 
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.
 
15
//
 
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.
 
20
//
 
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.
 
24
//
 
25
//=============================================================================
 
26
 
 
27
#include "kvi_settings.h"
 
28
#include "kvi_inttypes.h"
 
29
 
 
30
#include "KviHeapObject.h"
 
31
#include "KviCString.h"
 
32
#include "KviUrl.h"
 
33
#include "KviPointerHashTable.h"
 
34
 
 
35
#include <QObject>
 
36
#include <QAbstractSocket>
 
37
 
 
38
class KviDnsResolver;
 
39
class KviDataBuffer;
 
40
 
 
41
 
 
42
//
 
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().
 
46
//
 
47
 
 
48
// FIXME: Document and hide internals.
 
49
 
 
50
class KviHttpRequestPrivate;
 
51
 
 
52
class KVILIB_API KviHttpRequest : public QObject, public KviHeapObject
 
53
{
 
54
        Q_OBJECT
 
55
public:
 
56
 
 
57
        enum ProcessingType
 
58
        {
 
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
 
64
        };
 
65
 
 
66
        enum ExistingFileAction
 
67
        {
 
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)
 
72
        };
 
73
 
 
74
public:
 
75
 
 
76
        KviHttpRequest();
 
77
 
 
78
        virtual ~KviHttpRequest();
 
79
 
 
80
protected:
 
81
        // data
 
82
        KviUrl                 m_url;
 
83
        QString                m_szFileName;
 
84
        ProcessingType         m_eProcessingType;
 
85
        ExistingFileAction     m_eExistingFileAction;
 
86
        void                 * m_pPrivateData;
 
87
        unsigned int           m_uMaxContentLength;
 
88
        unsigned int           m_uContentOffset;
 
89
        QString                m_szPostData;
 
90
        // status
 
91
        QString                m_szLastError;
 
92
        unsigned int           m_uTotalSize;
 
93
        unsigned int           m_uReceivedSize;
 
94
        // internal status
 
95
        bool                   m_bHeaderProcessed;
 
96
        bool                   m_bChunkedTransferEncoding;
 
97
        bool                   m_bGzip;
 
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
 
101
 
 
102
private:
 
103
 
 
104
        KviHttpRequestPrivate * m_p;
 
105
 
 
106
public:
 
107
 
 
108
        void setConnectionTimeout(unsigned int uConnectionTimeout)
 
109
        {
 
110
                m_uConnectionTimeout = uConnectionTimeout;
 
111
                if(m_uConnectionTimeout < 5)
 
112
                        m_uConnectionTimeout = 5; // keep it sane
 
113
        }
 
114
 
 
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; };
 
124
 
 
125
        void reset();
 
126
 
 
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; };
 
136
 
 
137
        bool start();
 
138
 
 
139
        // this is a shortcut for reset()+setUrl()+setProcessingType()+setFileName()+start()
 
140
        bool get(const KviUrl &u,ProcessingType p = WholeFile,const QString &szFileName = QString());
 
141
 
 
142
        const QString & lastError(){ return m_szLastError; };
 
143
 
 
144
        void abort();
 
145
signals:
 
146
        void resolvingHost(const QString &hostname);
 
147
        void contactingHost(const QString &ipandport);
 
148
        void connectionEstabilished();
 
149
        void receivedResponse(const QString &response);
 
150
 
 
151
        void terminated(bool bSuccess);
 
152
 
 
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);
 
158
 
 
159
private:
 
160
        void closeSocket();
 
161
        bool doConnect();
 
162
 
 
163
        void processData(KviDataBuffer * data);
 
164
        bool processHeader(KviCString &szHeader);
 
165
        bool openFile();
 
166
        void emitLines(KviDataBuffer * pDataBuffer);
 
167
 
 
168
        void resetStatus();
 
169
        void resetData();
 
170
        void resetInternalStatus();
 
171
 
 
172
private slots:
 
173
        void slotSocketReadDataReady();
 
174
        void slotSocketDisconnected();
 
175
        void slotSocketConnected();
 
176
        void slotSocketError(QAbstractSocket::SocketError socketError);
 
177
        void slotConnectionTimedOut();
 
178
        void slotSocketHostResolved();
 
179
};
 
180
 
 
181
 
 
182
#endif //_KviHttpRequest_h_