~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to iris/src/xmpp/cutestuff/httppoll.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * httppoll.h - HTTP polling proxy
 
3
 * Copyright (C) 2003  Justin Karneges
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef CS_HTTPPOLL_H
 
22
#define CS_HTTPPOLL_H
 
23
 
 
24
#include "bytestream.h"
 
25
 
 
26
// CS_NAMESPACE_BEGIN
 
27
 
 
28
class HttpPoll : public ByteStream
 
29
{
 
30
        Q_OBJECT
 
31
public:
 
32
        enum Error { ErrConnectionRefused = ErrCustom, ErrHostNotFound, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth };
 
33
        HttpPoll(QObject *parent=0);
 
34
        ~HttpPoll();
 
35
 
 
36
        void setAuth(const QString &user, const QString &pass="");
 
37
        void connectToUrl(const QString &url);
 
38
        void connectToHost(const QString &proxyHost, int proxyPort, const QString &url);
 
39
 
 
40
        int pollInterval() const;
 
41
        void setPollInterval(int seconds);
 
42
 
 
43
        // from ByteStream
 
44
        bool isOpen() const;
 
45
        void close();
 
46
 
 
47
signals:
 
48
        void connected();
 
49
        void syncStarted();
 
50
        void syncFinished();
 
51
 
 
52
protected:
 
53
        int tryWrite();
 
54
 
 
55
private slots:
 
56
        void http_result();
 
57
        void http_error(int);
 
58
        void do_sync();
 
59
 
 
60
private:
 
61
        class Private;
 
62
        Private *d;
 
63
 
 
64
        void reset(bool clear=false);
 
65
        QByteArray makePacket(const QString &ident, const QString &key, const QString &newkey, const QByteArray &block);
 
66
        void resetKey();
 
67
        const QString & getKey(bool *);
 
68
};
 
69
 
 
70
class HttpProxyPost : public QObject
 
71
{
 
72
        Q_OBJECT
 
73
public:
 
74
        enum Error { ErrConnectionRefused, ErrHostNotFound, ErrSocket, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth };
 
75
        HttpProxyPost(QObject *parent=0);
 
76
        ~HttpProxyPost();
 
77
 
 
78
        void setAuth(const QString &user, const QString &pass="");
 
79
        bool isActive() const;
 
80
        void post(const QString &proxyHost, int proxyPort, const QString &url, const QByteArray &data, bool asProxy=true);
 
81
        void stop();
 
82
        QByteArray body() const;
 
83
        QString getHeader(const QString &) const;
 
84
 
 
85
signals:
 
86
        void result();
 
87
        void error(int);
 
88
 
 
89
private slots:
 
90
        void sock_connected();
 
91
        void sock_connectionClosed();
 
92
        void sock_readyRead();
 
93
        void sock_error(int);
 
94
 
 
95
private:
 
96
        class Private;
 
97
        Private *d;
 
98
 
 
99
        void reset(bool clear=false);
 
100
};
 
101
 
 
102
class HttpProxyGetStream : public QObject
 
103
{
 
104
        Q_OBJECT
 
105
public:
 
106
        enum Error { ErrConnectionRefused, ErrHostNotFound, ErrSocket, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth };
 
107
        HttpProxyGetStream(QObject *parent=0);
 
108
        ~HttpProxyGetStream();
 
109
 
 
110
        void setAuth(const QString &user, const QString &pass="");
 
111
        bool isActive() const;
 
112
        void get(const QString &proxyHost, int proxyPort, const QString &url, bool ssl=false, bool asProxy=false);
 
113
        void stop();
 
114
        QString getHeader(const QString &) const;
 
115
        int length() const; // -1 for unknown
 
116
 
 
117
signals:
 
118
        void handshaken();
 
119
        void dataReady(const QByteArray &buf);
 
120
        void finished();
 
121
        void error(int);
 
122
 
 
123
private slots:
 
124
        void sock_connected();
 
125
        void sock_connectionClosed();
 
126
        void sock_readyRead();
 
127
        void sock_error(int);
 
128
 
 
129
        void tls_readyRead();
 
130
        void tls_readyReadOutgoing();
 
131
        void tls_error();
 
132
 
 
133
private:
 
134
        class Private;
 
135
        Private *d;
 
136
 
 
137
        void reset(bool clear=false);
 
138
        void processData(const QByteArray &block);
 
139
};
 
140
 
 
141
// CS_NAMESPACE_END
 
142
 
 
143
#endif