• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_Socks.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
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   //types of events for Socks auth handlers
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   //the following ports are used by SocksProxy
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 // umm.. the following typedef should take _its own_ type as one of the args
00085 // not possible with C
00086 // Right now just use a generic fn ptr and hide casting in an inline fn.
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   // Changed from @a ip and @a port.
00113   IpEndpoint target_addr; ///< Original target address.
00114   // Changed from @a server_ip, @a server_port.
00115   IpEndpoint server_addr; ///< Origin server address.
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   //socks server selection:
00131   ParentConfigParams *server_params;
00132   HttpRequestData req_data;     //We dont use any http specific fields.
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

Generated by  doxygen 1.7.1