~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to cutestuff/network/socks.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

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 SocksServer;
 
30
 
 
31
class SocksClient : public ByteStream
 
32
{
 
33
        Q_OBJECT
 
34
public:
 
35
        enum Error { ErrConnectionRefused = ErrCustom, ErrHostNotFound, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth };
 
36
        enum Method { AuthNone=0x0001, AuthUsername=0x0002 };
 
37
        SocksClient(QObject *parent=0);
 
38
        SocksClient(int, QObject *parent=0);
 
39
        ~SocksClient();
 
40
 
 
41
        bool isIncoming() const;
 
42
 
 
43
        // outgoing
 
44
        void setAuth(const QString &user, const QString &pass="");
 
45
        void connectToHost(const QString &proxyHost, int proxyPort, const QString &host, int port);
 
46
 
 
47
        // incoming
 
48
        void chooseMethod(int);
 
49
        void authGrant(bool);
 
50
        void requestGrant(bool);
 
51
 
 
52
        // from ByteStream
 
53
        bool isOpen() const;
 
54
        void close();
 
55
        void write(const QByteArray &);
 
56
        QByteArray read(int bytes=0);
 
57
        int bytesAvailable() const;
 
58
        int bytesToWrite() const;
 
59
 
 
60
        QHostAddress peerAddress() const;
 
61
        Q_UINT16 peerPort() const;
 
62
 
 
63
signals:
 
64
        // outgoing
 
65
        void connected();
 
66
 
 
67
        // incoming
 
68
        void incomingMethods(int);
 
69
        void incomingAuth(const QString &user, const QString &pass);
 
70
        void incomingRequest(const QString &host, int port);
 
71
 
 
72
private slots:
 
73
        void sock_connected();
 
74
        void sock_connectionClosed();
 
75
        void sock_delayedCloseFinished();
 
76
        void sock_readyRead();
 
77
        void sock_bytesWritten(int);
 
78
        void sock_error(int);
 
79
        void serve();
 
80
 
 
81
private:
 
82
        class Private;
 
83
        Private *d;
 
84
 
 
85
        void init();
 
86
        void reset(bool clear=false);
 
87
        void do_request();
 
88
        void processOutgoing(const QByteArray &);
 
89
        void processIncoming(const QByteArray &);
 
90
        void continueIncoming();
 
91
        void writeData(const QByteArray &a);
 
92
};
 
93
 
 
94
class SocksServer : public QObject
 
95
{
 
96
        Q_OBJECT
 
97
public:
 
98
        SocksServer(QObject *parent=0);
 
99
        ~SocksServer();
 
100
 
 
101
        bool isActive() const;
 
102
        bool listen(Q_UINT16 port);
 
103
        void stop();
 
104
        int port() const;
 
105
        QHostAddress address() const;
 
106
        SocksClient *takeIncoming();
 
107
 
 
108
signals:
 
109
        void incomingReady();
 
110
 
 
111
private slots:
 
112
        void connectionReady(int);
 
113
        void connectionError();
 
114
 
 
115
private:
 
116
        class Private;
 
117
        Private *d;
 
118
};
 
119
 
 
120
// CS_NAMESPACE_END
 
121
 
 
122
#endif