00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __P_SOCKS_H__
00025 #define __P_SOCKS_H__
00026 #include "P_EventSystem.h"
00027 #include "I_Socks.h"
00028
00029 #ifdef SOCKS_WITH_TS
00030 #include "ParentSelection.h"
00031 #include <ts/IpMap.h>
00032 #endif
00033
00034 enum
00035 {
00036
00037 SOCKS_AUTH_OPEN,
00038 SOCKS_AUTH_WRITE_COMPLETE,
00039 SOCKS_AUTH_READ_COMPLETE,
00040 SOCKS_AUTH_FILL_WRITE_BUF
00041 };
00042
00043 struct socks_conf_struct
00044 {
00045 int socks_needed;
00046 int server_connect_timeout;
00047 int socks_timeout;
00048 unsigned char default_version;
00049 char *user_name_n_passwd;
00050 int user_name_n_passwd_len;
00051
00052 int per_server_connection_attempts;
00053 int connection_attempts;
00054
00055
00056 int accept_enabled;
00057 int accept_port;
00058 unsigned short http_port;
00059
00060 #ifdef SOCKS_WITH_TS
00061 IpMap ip_map;
00062 #endif
00063
00064 #ifndef SOCKS_WITH_TS
00065 IpEndpoint server_addr;
00066 #endif
00067
00068 socks_conf_struct():socks_needed(0), server_connect_timeout(0), socks_timeout(100), default_version(5),
00069 user_name_n_passwd(NULL), user_name_n_passwd_len(0),
00070 per_server_connection_attempts(1), connection_attempts(0), accept_enabled(0), accept_port(0), http_port(1080)
00071 {
00072 # if !defined(SOCKS_WITH_TS)
00073 memset(&server_addr, 0, sizeof(server_addr));
00074 # endif
00075 }
00076 };
00077
00078 extern struct socks_conf_struct *g_socks_conf_stuff;
00079
00080 void start_SocksProxy(int port);
00081
00082 int loadSocksAuthInfo(int fd, socks_conf_struct * socks_stuff);
00083
00084
00085
00086
00087 typedef int (*SocksAuthHandler) (int event, unsigned char *buf, void (**h_ptr) (void));
00088
00089 TS_INLINE int
00090 invokeSocksAuthHandler(SocksAuthHandler & h, int arg1, unsigned char *arg2)
00091 {
00092 return (h) (arg1, arg2, (void (**)(void)) (&h));
00093 }
00094
00095 void loadSocksConfiguration(socks_conf_struct * socks_conf_stuff);
00096 int socks5BasicAuthHandler(int event, unsigned char *p, void (**)(void));
00097 int socks5PasswdAuthHandler(int event, unsigned char *p, void (**)(void));
00098 int socks5ServerAuthHandler(int event, unsigned char *p, void (**)(void));
00099
00100 class UnixNetVConnection;
00101 typedef UnixNetVConnection SocksNetVC;
00102
00103 struct SocksEntry:public Continuation
00104 {
00105
00106
00107 MIOBuffer *buf;
00108 IOBufferReader *reader;
00109
00110 SocksNetVC *netVConnection;
00111
00112
00113 IpEndpoint target_addr;
00114
00115 IpEndpoint server_addr;
00116
00117 int nattempts;
00118
00119 Action action_;
00120 int lerrno;
00121 Event *timeout;
00122 unsigned char version;
00123
00124 bool write_done;
00125
00126 SocksAuthHandler auth_handler;
00127 unsigned char socks_cmd;
00128
00129 #ifdef SOCKS_WITH_TS
00130
00131 ParentConfigParams *server_params;
00132 HttpRequestData req_data;
00133 ParentResult server_result;
00134 #endif
00135
00136 int startEvent(int event, void *data);
00137 int mainEvent(int event, void *data);
00138 void findServer();
00139 void init(ProxyMutex * m, SocksNetVC * netvc, unsigned char socks_support, unsigned char ver);
00140 void free();
00141
00142 SocksEntry():Continuation(NULL), netVConnection(0),
00143 nattempts(0),
00144 lerrno(0), timeout(0), version(5), write_done(false), auth_handler(NULL), socks_cmd(NORMAL_SOCKS)
00145 {
00146 memset(&target_addr, 0, sizeof(target_addr));
00147 memset(&server_addr, 0, sizeof(server_addr));
00148 }
00149 };
00150
00151 typedef int (SocksEntry::*SocksEntryHandler) (int, void *);
00152
00153 extern ClassAllocator<SocksEntry> socksAllocator;
00154
00155 TS_INLINE void
00156 SocksAddrType::reset()
00157 {
00158 if (type != SOCKS_ATYPE_IPV4 && addr.buf) {
00159 ats_free(addr.buf);
00160 }
00161
00162 addr.buf = 0;
00163 type = SOCKS_ATYPE_NONE;
00164 }
00165
00166 #endif