1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/* This file is part of the KDE libraries
Copyright (C) 2001 George Staikos <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _KSOCKS_H_
#define _KSOCKS_H_
#include <tqstringlist.h>
#include <sys/types.h>
#include <sys/time.h>
#include <kstaticdeleter.h>
#include <tdelibs_export.h>
#ifdef Q_OS_UNIX
class KSocksTable;
class KSocksPrivate;
class KLibrary;
class KConfigBase;
struct sockaddr;
typedef unsigned ksocklen_t;
/**
* This class provides you with an interface to a
* <a href="http://www.socks.nec.com/">SOCKS</a> Proxy server. A SOCKS server
* is able to provide full internet access behind a firewall.
* KSocks is a singleton; there can only be one instance at any
* given time. To obtain a reference to that instance, use
* self().
*
* @short Access to a SOCKS Proxy.
*/
class TDECORE_EXPORT KSocks {
friend class KStaticDeleter<KSocks>;
public:
/**
* Return an instance of class KSocks *.
* You cannot delete this object. It is a singleton class.
* @return the KSock instance
*/
static KSocks *self();
/**
* Checks whether KSocks has been started (ie someone called self())
* @return true if activated
*/
static bool activated();
/**
* Disable the use of SOCKS immediately
*/
void disableSocks();
/**
* Enable the use of SOCKS immediately if hasSocks() is true.
*/
void enableSocks();
/**
* Checks whether SOCKS is currently being used.
* @return true if SOCKS is currently being used.
*/
bool usingSocks();
/**
* Checks whether SOCKS is available for use.
* @return true if SOCKS is available for use.
*/
bool hasSocks();
/**
* Returns whether asynchronous connects work with the
* selected SOCKS impementation
*/
bool hasWorkingAsyncConnect();
/*
** REIMPLEMENTATIONS OF LIBC SOCKET FUNCTIONS
**/
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int connect (int sockfd, const sockaddr *serv_addr,
ksocklen_t addrlen);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
signed long int read (int fd, void *buf, unsigned long int count);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
signed long int write (int fd, const void *buf, unsigned long int count);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int recvfrom (int s, void *buf, unsigned long int len, int flags,
sockaddr *from, ksocklen_t *fromlen);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int sendto (int s, const void *msg, unsigned long int len, int flags,
const sockaddr *to, ksocklen_t tolen);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int recv (int s, void *buf, unsigned long int len, int flags);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int send (int s, const void *msg, unsigned long int len, int flags);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int getsockname (int s, sockaddr *name, ksocklen_t *namelen);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int getpeername (int s, sockaddr *name, ksocklen_t *namelen);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int accept (int s, sockaddr *addr, ksocklen_t *addrlen);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int select (int n, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int listen (int s, int backlog);
/**
* This is the re-implementation of libc's function of the same
* name. Read the appropriate man page.
*/
int bind (int sockfd, sockaddr *my_addr,
ksocklen_t addrlen);
int bind (int sockfd, const sockaddr *my_addr,
ksocklen_t addrlen);
/**
* If you're using this, you're probably doing something wrong.
* Please don't use it.
* @internal
*/
void die();
/**
* Set this before the first call to KSocks::self() and it will fail
* to initialize SOCKS.
*/
static void disable();
/**
* Set this before the first call to KSocks::self() and it will use
* @p config to read its configuration from.
*/
static void setConfig(KConfigBase *config);
private:
KSocks(KConfigBase *config);
~KSocks();
void stopSocks();
static KSocks *_me;
static bool _disabled;
TQStringList _libNames;
TQStringList _libPaths;
bool _useSocks, _hasSocks;
KLibrary* _socksLib;
KSocksTable *_st;
KSocksPrivate *d;
};
#endif //Q_OS_UNIX
#endif //_KSOCKS_H_
|