~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * socks.h - SOCKS5 TCP proxy client/server
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_SOCKS_H
22
 
#define CS_SOCKS_H
23
 
 
24
 
#include "bytestream.h"
25
 
 
26
 
// CS_NAMESPACE_BEGIN
27
 
 
28
 
class QHostAddress;
29
 
class SocksClient;
30
 
class SocksServer;
31
 
 
32
 
class SocksUDP : public QObject
33
 
{
34
 
        Q_OBJECT
35
 
public:
36
 
        ~SocksUDP();
37
 
 
38
 
        void change(const QString &host, int port);
39
 
        void write(const QByteArray &data);
40
 
 
41
 
signals:
42
 
        void packetReady(const QByteArray &data);
43
 
 
44
 
private slots:
45
 
        void sd_activated();
46
 
 
47
 
private:
48
 
        class Private;
49
 
        Private *d;
50
 
 
51
 
        friend class SocksClient;
52
 
        SocksUDP(SocksClient *sc, const QString &host, int port, const QHostAddress &routeAddr, int routePort);
53
 
};
54
 
 
55
 
class SocksClient : public ByteStream
56
 
{
57
 
        Q_OBJECT
58
 
public:
59
 
        enum Error { ErrConnectionRefused = ErrCustom, ErrHostNotFound, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth };
60
 
        enum Method { AuthNone=0x0001, AuthUsername=0x0002 };
61
 
        enum Request { ReqConnect, ReqUDPAssociate };
62
 
        SocksClient(QObject *parent=0);
63
 
        SocksClient(int, QObject *parent=0);
64
 
        ~SocksClient();
65
 
 
66
 
        bool isIncoming() const;
67
 
 
68
 
        // outgoing
69
 
        void setAuth(const QString &user, const QString &pass="");
70
 
        void connectToHost(const QString &proxyHost, int proxyPort, const QString &host, int port, bool udpMode=false);
71
 
 
72
 
        // incoming
73
 
        void chooseMethod(int);
74
 
        void authGrant(bool);
75
 
        void requestDeny();
76
 
        void grantConnect();
77
 
        void grantUDPAssociate(const QString &relayHost, int relayPort);
78
 
 
79
 
        // from ByteStream
80
 
        bool isOpen() const;
81
 
        void close();
82
 
        void write(const QByteArray &);
83
 
        QByteArray read(int bytes=0);
84
 
        int bytesAvailable() const;
85
 
        int bytesToWrite() const;
86
 
 
87
 
        // remote address
88
 
        QHostAddress peerAddress() const;
89
 
        quint16 peerPort() const;
90
 
 
91
 
        // udp
92
 
        QString udpAddress() const;
93
 
        quint16 udpPort() const;
94
 
        SocksUDP *createUDP(const QString &host, int port, const QHostAddress &routeAddr, int routePort);
95
 
 
96
 
signals:
97
 
        // outgoing
98
 
        void connected();
99
 
 
100
 
        // incoming
101
 
        void incomingMethods(int);
102
 
        void incomingAuth(const QString &user, const QString &pass);
103
 
        void incomingConnectRequest(const QString &host, int port);
104
 
        void incomingUDPAssociateRequest();
105
 
 
106
 
private slots:
107
 
        void sock_connected();
108
 
        void sock_connectionClosed();
109
 
        void sock_delayedCloseFinished();
110
 
        void sock_readyRead();
111
 
        void sock_bytesWritten(int);
112
 
        void sock_error(int);
113
 
        void serve();
114
 
 
115
 
private:
116
 
        class Private;
117
 
        Private *d;
118
 
 
119
 
        void init();
120
 
        void reset(bool clear=false);
121
 
        void do_request();
122
 
        void processOutgoing(const QByteArray &);
123
 
        void processIncoming(const QByteArray &);
124
 
        void continueIncoming();
125
 
        void writeData(const QByteArray &a);
126
 
};
127
 
 
128
 
class SocksServer : public QObject
129
 
{
130
 
        Q_OBJECT
131
 
public:
132
 
        SocksServer(QObject *parent=0);
133
 
        ~SocksServer();
134
 
 
135
 
        bool isActive() const;
136
 
        bool listen(quint16 port, bool udp=false);
137
 
        void stop();
138
 
        int port() const;
139
 
        QHostAddress address() const;
140
 
        SocksClient *takeIncoming();
141
 
 
142
 
        void writeUDP(const QHostAddress &addr, int port, const QByteArray &data);
143
 
 
144
 
signals:
145
 
        void incomingReady();
146
 
        void incomingUDP(const QString &host, int port, const QHostAddress &addr, int sourcePort, const QByteArray &data);
147
 
 
148
 
private slots:
149
 
        void connectionReady(int);
150
 
        void connectionError();
151
 
        void sd_activated();
152
 
 
153
 
private:
154
 
        class Private;
155
 
        Private *d;
156
 
};
157
 
 
158
 
// CS_NAMESPACE_END
159
 
 
160
 
#endif