Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

socks.h

Go to the documentation of this file.
00001 /* 00002 * socks.h 00003 * 00004 * SOCKS protocol 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-2001 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: socks.h,v $ 00027 * Revision 1.7 2002/11/06 22:47:24 robertj 00028 * Fixed header comment (copyright etc) 00029 * 00030 * Revision 1.6 2002/09/16 01:08:59 robertj 00031 * Added #define so can select if #pragma interface/implementation is used on 00032 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00033 * 00034 * Revision 1.5 2002/08/05 05:40:45 robertj 00035 * Fixed missing pragma interface/implementation 00036 * 00037 * Revision 1.4 1999/05/01 03:52:20 robertj 00038 * Fixed various egcs warnings. 00039 * 00040 * Revision 1.3 1999/03/09 08:01:47 robertj 00041 * Changed comments for doc++ support (more to come). 00042 * 00043 * Revision 1.2 1998/12/23 00:33:05 robertj 00044 * UDP support 00045 * 00046 * Revision 1.1 1998/12/22 10:34:17 robertj 00047 * Initial revision 00048 * 00049 */ 00050 00051 #ifndef _SOCKS_H 00052 #define _SOCKS_H 00053 00054 #ifdef P_USE_PRAGMA 00055 #pragma interface 00056 #endif 00057 00058 00059 #include <ptlib/sockets.h> 00060 00061 00067 class PSocksProtocol 00068 { 00069 public: 00070 PSocksProtocol(WORD port); 00071 virtual ~PSocksProtocol() { } 00072 00073 // New functions for class 00074 enum { 00075 DefaultServerPort = 1080 00076 }; 00077 BOOL SetServer( 00078 const PString & hostname, 00079 const char * service = "socks 1080" 00080 ); 00081 BOOL SetServer( 00082 const PString & hostname, 00083 WORD port 00084 ); 00085 00090 void SetAuthentication( 00091 const PString & username, 00092 const PString & password 00093 ); 00094 00095 protected: 00096 BOOL ConnectSocksServer(PTCPSocket & thisSocket); 00097 00098 virtual void SetErrorCodes(PChannel::Errors errCode, int osErr) = 0; 00099 00100 virtual BOOL SendSocksCommand(PTCPSocket & socket, 00101 BYTE command, 00102 const char * hostname, 00103 PIPSocket::Address addr); 00104 virtual BOOL ReceiveSocksResponse(PTCPSocket & socket, 00105 PIPSocket::Address & addr, 00106 WORD & port); 00107 00108 00109 PString serverHost; 00110 WORD serverPort; 00111 PString authenticationUsername; 00112 PString authenticationPassword; 00113 PIPSocket::Address remoteAddress; 00114 WORD remotePort; 00115 PIPSocket::Address localAddress; 00116 WORD localPort; 00117 }; 00118 00119 00122 class PSocksSocket : public PTCPSocket, public PSocksProtocol 00123 { 00124 PCLASSINFO(PSocksSocket, PTCPSocket) 00125 00126 public: 00127 PSocksSocket( 00128 WORD port = 0 00129 ); 00130 00131 // Overrides from class PSocket. 00143 virtual BOOL Connect( 00144 const PString & address // Address of remote machine to connect to. 00145 ); 00146 virtual BOOL Connect( 00147 const Address & addr // Address of remote machine to connect to. 00148 ); 00149 00165 virtual BOOL Listen( 00166 unsigned queueSize = 5, // Number of pending accepts that may be queued. 00167 WORD port = 0, // Port number to use for the connection. 00168 Reusability reuse = AddressIsExclusive // Can/Cant listen more than once. 00169 ); 00170 00190 BOOL Accept(); 00191 virtual BOOL Accept( 00192 PSocket & socket // Listening socket making the connection. 00193 ); 00194 00195 00196 // Overrides from class PIPSocket. 00202 virtual BOOL GetLocalAddress( 00203 Address & addr // Variable to receive hosts IP address 00204 ); 00205 virtual BOOL GetLocalAddress( 00206 Address & addr, // Variable to receive peer hosts IP address 00207 WORD & port // Variable to receive peer hosts port number 00208 ); 00209 00216 virtual BOOL GetPeerAddress( 00217 Address & addr // Variable to receive hosts IP address 00218 ); 00219 virtual BOOL GetPeerAddress( 00220 Address & addr, // Variable to receive peer hosts IP address 00221 WORD & port // Variable to receive peer hosts port number 00222 ); 00223 00224 00225 protected: 00226 virtual void SetErrorCodes(PChannel::Errors errCode, int osErr); 00227 int TransferHandle(PSocksSocket & destination); 00228 00229 private: 00230 virtual BOOL Connect(WORD localPort, const Address & addr); 00231 }; 00232 00233 00236 class PSocks4Socket : public PSocksSocket 00237 { 00238 PCLASSINFO(PSocks4Socket, PSocksSocket) 00239 00240 public: 00241 PSocks4Socket( 00242 WORD port = 0 00243 ); 00244 PSocks4Socket( 00245 const PString & host, 00246 WORD port = 0 00247 ); 00248 00249 // Overrides from class PObject 00262 virtual PObject * Clone() const; 00263 00264 00265 protected: 00266 virtual BOOL SendSocksCommand(PTCPSocket & socket, 00267 BYTE command, 00268 const char * hostname, 00269 PIPSocket::Address addr); 00270 virtual BOOL ReceiveSocksResponse(PTCPSocket & socket, 00271 PIPSocket::Address & addr, 00272 WORD & port); 00273 }; 00274 00275 00278 class PSocks5Socket : public PSocksSocket 00279 { 00280 PCLASSINFO(PSocks5Socket, PSocksSocket) 00281 00282 public: 00283 PSocks5Socket( 00284 WORD port = 0 00285 ); 00286 PSocks5Socket( 00287 const PString & host, 00288 WORD port = 0 00289 ); 00290 00291 // Overrides from class PObject 00304 virtual PObject * Clone() const; 00305 }; 00306 00307 00310 class PSocksUDPSocket : public PUDPSocket, public PSocksProtocol 00311 { 00312 PCLASSINFO(PSocksUDPSocket, PUDPSocket) 00313 00314 public: 00315 PSocksUDPSocket( 00316 WORD port = 0 00317 ); 00318 PSocksUDPSocket( 00319 const PString & host, 00320 WORD port = 0 00321 ); 00322 00323 00324 // Overrides from class PObject 00337 virtual PObject * Clone() const; 00338 00339 00340 // Overrides from class PSocket. 00352 virtual BOOL Connect( 00353 const PString & address // Address of remote machine to connect to. 00354 ); 00355 virtual BOOL Connect( 00356 const Address & addr // Address of remote machine to connect to. 00357 ); 00358 00374 virtual BOOL Listen( 00375 unsigned queueSize = 5, // Number of pending accepts that may be queued. 00376 WORD port = 0, // Port number to use for the connection. 00377 Reusability reuse = AddressIsExclusive // Can/Cant listen more than once. 00378 ); 00379 00380 // Overrides from class PIPSocket. 00386 virtual BOOL GetLocalAddress( 00387 Address & addr // Variable to receive hosts IP address 00388 ); 00389 virtual BOOL GetLocalAddress( 00390 Address & addr, // Variable to receive peer hosts IP address 00391 WORD & port // Variable to receive peer hosts port number 00392 ); 00393 00400 virtual BOOL GetPeerAddress( 00401 Address & addr // Variable to receive hosts IP address 00402 ); 00403 virtual BOOL GetPeerAddress( 00404 Address & addr, // Variable to receive peer hosts IP address 00405 WORD & port // Variable to receive peer hosts port number 00406 ); 00407 00408 00409 // Overrides from class PIPDatagramSocket. 00415 virtual BOOL ReadFrom( 00416 void * buf, // Data to be written as URGENT TCP data. 00417 PINDEX len, // Number of bytes pointed to by <CODE>buf</CODE>. 00418 Address & addr, // Address from which the datagram was received. 00419 WORD & port // Port from which the datagram was received. 00420 ); 00421 00427 virtual BOOL WriteTo( 00428 const void * buf, // Data to be written as URGENT TCP data. 00429 PINDEX len, // Number of bytes pointed to by <CODE>buf</CODE>. 00430 const Address & addr, // Address to which the datagram is sent. 00431 WORD port // Port to which the datagram is sent. 00432 ); 00433 00434 00435 protected: 00436 virtual void SetErrorCodes(PChannel::Errors errCode, int osErr); 00437 00438 PTCPSocket socksControl; 00439 Address serverAddress; 00440 00441 private: 00442 virtual BOOL Connect(WORD localPort, const Address & addr); 00443 }; 00444 00445 00446 #endif // _SOCKS_H 00447 00448 00449 // End of File ///////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7