~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/dlnaexport/extra/hupnp/src/http/hhttp_asynchandler_p.h

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2010, 2011 Tuomo Penttinen, all rights reserved.
 
3
 *
 
4
 *  Author: Tuomo Penttinen <tp@herqq.org>
 
5
 *
 
6
 *  This file is part of Herqq UPnP (HUPnP) library.
 
7
 *
 
8
 *  Herqq UPnP is free software: you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU Lesser General Public License as published by
 
10
 *  the Free Software Foundation, either version 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  Herqq UPnP is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
 *  GNU Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public License
 
19
 *  along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#ifndef HTTP_ASYNCHANDLER_P_H_
 
23
#define HTTP_ASYNCHANDLER_P_H_
 
24
 
 
25
//
 
26
// !! Warning !!
 
27
//
 
28
// This file is not part of public API and it should
 
29
// never be included in client code. The contents of this file may
 
30
// change or the file may be removed without of notice.
 
31
//
 
32
 
 
33
#include <HUpnpCore/HUpnp>
 
34
 
 
35
#include "hhttp_p.h"
 
36
#include "hhttp_header_p.h"
 
37
#include "hhttp_messaginginfo_p.h"
 
38
 
 
39
#include <QtCore/QHash>
 
40
#include <QtCore/QObject>
 
41
#include <QtCore/QByteArray>
 
42
#include <QtNetwork/QAbstractSocket>
 
43
 
 
44
class QtSoapMessage;
 
45
 
 
46
namespace Herqq
 
47
{
 
48
 
 
49
namespace Upnp
 
50
{
 
51
 
 
52
class HHttpAsyncHandler;
 
53
 
 
54
//
 
55
//
 
56
//
 
57
class HHttpAsyncOperation :
 
58
    public QObject
 
59
{
 
60
Q_OBJECT
 
61
H_DISABLE_COPY(HHttpAsyncOperation)
 
62
friend class HHttpAsyncHandler;
 
63
 
 
64
public:
 
65
 
 
66
    enum OpType
 
67
    {
 
68
        MsgIO,
 
69
        SendOnly,
 
70
        ReceiveRequest,
 
71
        ReceiveResponse
 
72
    };
 
73
 
 
74
private:
 
75
 
 
76
    enum InternalState
 
77
    {
 
78
        Internal_Failed,
 
79
        Internal_NotStarted,
 
80
        Internal_WritingBlob,
 
81
        Internal_WritingChunkedSizeLine,
 
82
        Internal_WritingChunk,
 
83
        Internal_ReadingHeader,
 
84
        Internal_ReadingData,
 
85
        Internal_ReadingChunkSizeLine,
 
86
        Internal_ReadingChunk,
 
87
        Internal_FinishedSuccessfully
 
88
    };
 
89
 
 
90
    HMessagingInfo* m_mi;
 
91
 
 
92
    QByteArray m_dataToSend;
 
93
    // the data which will be sent to the target socket
 
94
 
 
95
    qint64 m_dataSend;
 
96
    // used only with chunked encoding when a chunk cannot be sent in full and
 
97
    // the operation needs to be continued later
 
98
 
 
99
    qint64 m_dataSent;
 
100
    // the amount of data that has been successfully sent
 
101
 
 
102
    InternalState m_state;
 
103
    // the current state of this "state machine"
 
104
 
 
105
    HHttpHeader* m_headerRead;
 
106
    // the http reader read from the target socket
 
107
    // (request / response, depends of the setup)
 
108
 
 
109
    QByteArray m_dataRead;
 
110
    // the response data that is currently read from the target socket
 
111
 
 
112
    qint64 m_dataToRead;
 
113
    // the amount of data that should be available (once the operation is
 
114
    // successfully completed)
 
115
 
 
116
    unsigned int m_id;
 
117
    // id for the operation
 
118
 
 
119
    const QByteArray m_loggingIdentifier;
 
120
 
 
121
    OpType m_opType;
 
122
    // what the operation is supposed to do
 
123
 
 
124
private:
 
125
 
 
126
    void sendChunked();
 
127
 
 
128
    void readBlob();
 
129
    bool readChunkedSizeLine();
 
130
    bool readChunk();
 
131
 
 
132
    // the return value of these two methods indicate if it is okay to continue
 
133
    // the operation. when returned false, the operation has signaled completion
 
134
    // and thus must be aborted immediately.
 
135
    bool readHeader();
 
136
    bool readData();
 
137
 
 
138
    bool run();
 
139
    void done_(InternalState state, bool emitSignal = true);
 
140
 
 
141
private Q_SLOTS:
 
142
 
 
143
    void bytesWritten(qint64);
 
144
    void readyRead();
 
145
    void error(QAbstractSocket::SocketError);
 
146
 
 
147
public:
 
148
 
 
149
    enum State
 
150
    {
 
151
        Failed,
 
152
        NotStarted,
 
153
        Writing,
 
154
        Reading,
 
155
        Succeeded
 
156
    };
 
157
 
 
158
    HHttpAsyncOperation(
 
159
        const QByteArray& loggingIdentifier, unsigned int id, HMessagingInfo* mi,
 
160
        bool waitingRequest, QObject* parent);
 
161
 
 
162
    HHttpAsyncOperation(
 
163
        const QByteArray& loggingIdentifier, unsigned int id, HMessagingInfo* mi,
 
164
        const QByteArray& data, bool sendOnly, QObject* parent);
 
165
 
 
166
    virtual ~HHttpAsyncOperation();
 
167
 
 
168
    State state() const;
 
169
 
 
170
    inline unsigned int id() const { return m_id; }
 
171
 
 
172
    // the data of the response
 
173
    inline QByteArray dataRead() const { return m_dataRead; }
 
174
 
 
175
    // the header of the response
 
176
    inline const HHttpHeader* headerRead() const { return m_headerRead; }
 
177
 
 
178
    inline HMessagingInfo* messagingInfo() const { return m_mi; }
 
179
 
 
180
    inline HMessagingInfo* takeMessagingInfo()
 
181
    {
 
182
        HMessagingInfo* retVal = m_mi; m_mi = 0;
 
183
        return retVal;
 
184
    }
 
185
 
 
186
    inline OpType opType() const { return m_opType; }
 
187
 
 
188
Q_SIGNALS:
 
189
 
 
190
    void done(unsigned int);
 
191
};
 
192
 
 
193
//
 
194
// Performs async messaging utilizing the event loop.
 
195
// This class is not thread-safe.
 
196
//
 
197
class H_UPNP_CORE_EXPORT HHttpAsyncHandler :
 
198
    public QObject
 
199
{
 
200
Q_OBJECT
 
201
H_DISABLE_COPY(HHttpAsyncHandler)
 
202
friend class HHttpAsyncOperation;
 
203
 
 
204
private:
 
205
 
 
206
    const QByteArray m_loggingIdentifier;
 
207
 
 
208
    QHash<unsigned int, HHttpAsyncOperation*> m_operations;
 
209
 
 
210
    unsigned int m_lastIdUsed;
 
211
 
 
212
private Q_SLOTS:
 
213
 
 
214
    void done(unsigned int);
 
215
 
 
216
Q_SIGNALS:
 
217
 
 
218
    // user is expected to delete the transferred object
 
219
    void msgIoComplete(HHttpAsyncOperation*);
 
220
 
 
221
public:
 
222
 
 
223
    HHttpAsyncHandler(const QByteArray& loggingIdentifier, QObject* parent);
 
224
    virtual ~HHttpAsyncHandler();
 
225
 
 
226
    //
 
227
    // \param mi
 
228
    // \param data contains an entire HTTP message, including headers.
 
229
    //
 
230
    // \return an object that contains state data for the operation.
 
231
    // once the operation is done, user is expected to delete the object, but
 
232
    // NOT any sooner!
 
233
    HHttpAsyncOperation* msgIo(HMessagingInfo* mi, const QByteArray& data);
 
234
 
 
235
    //
 
236
    // Helper overload
 
237
    //
 
238
    HHttpAsyncOperation* msgIo(
 
239
        HMessagingInfo*, HHttpRequestHeader&, const QtSoapMessage&);
 
240
 
 
241
    //
 
242
    //
 
243
    //
 
244
    HHttpAsyncOperation* send(HMessagingInfo*, const QByteArray& data);
 
245
 
 
246
    //
 
247
    // waitingRequest == expecting to receive HHttpRequestHeader, otherwise
 
248
    // expecting to receive HHttpResponseHeader
 
249
    //
 
250
    HHttpAsyncOperation* receive(HMessagingInfo*, bool waitingRequest);
 
251
};
 
252
 
 
253
}
 
254
}
 
255
 
 
256
#endif /* HTTP_ASYNCHANDLER_P_H_ */