00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef PUTTY_NETWORK_H
00014 #define PUTTY_NETWORK_H
00015
00016 typedef struct SockAddr_tag *SockAddr;
00017
00018 typedef struct socket_function_table **Socket;
00019 typedef struct plug_function_table **Plug;
00020
00021 struct socket_function_table {
00022 Plug(*plug) (Socket s, Plug p);
00023
00024
00025
00026 void (*close) (Socket s);
00027 int (*write) (Socket s, char *data, int len);
00028 int (*write_oob) (Socket s, char *data, int len);
00029 void (*flush) (Socket s);
00030 void (*set_private_ptr) (Socket s, void *ptr);
00031 void *(*get_private_ptr) (Socket s);
00032 void (*set_frozen) (Socket s, int is_frozen);
00033
00034 char *(*socket_error) (Socket s);
00035 };
00036
00037 struct plug_function_table {
00038 int (*closing)
00039 (Plug p, char *error_msg, int error_code, int calling_back);
00040
00041
00042
00043 int (*receive) (Plug p, int urgent, char *data, int len);
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void (*sent) (Plug p, int bufsize);
00055
00056
00057
00058
00059
00060 int (*accepting)(Plug p, void *sock);
00061
00062
00063
00064 };
00065
00066
00067 Socket new_connection(SockAddr addr, char *hostname,
00068 int port, int privport,
00069 int oobinline, int nodelay, Plug plug);
00070 Socket new_listener(int port, Plug plug, int local_host_only);
00071
00072
00073
00074 void sk_init(void);
00075 void sk_cleanup(void);
00076
00077 SockAddr sk_namelookup(char *host, char **canonicalname);
00078 void sk_getaddr(SockAddr addr, char *buf, int buflen);
00079 int sk_addrtype(SockAddr addr);
00080 void sk_addrcopy(SockAddr addr, char *buf);
00081 void sk_addr_free(SockAddr addr);
00082
00083 Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
00084 int nodelay, Plug p);
00085
00086 Socket sk_newlistener(int port, Plug plug, int local_host_only);
00087
00088 Socket sk_register(void *sock, Plug plug);
00089
00090 #define sk_plug(s,p) (((*s)->plug) (s, p))
00091 #define sk_close(s) (((*s)->close) (s))
00092 #define sk_write(s,buf,len) (((*s)->write) (s, buf, len))
00093 #define sk_write_oob(s,buf,len) (((*s)->write_oob) (s, buf, len))
00094 #define sk_flush(s) (((*s)->flush) (s))
00095
00096 #ifdef DEFINE_PLUG_METHOD_MACROS
00097 #define plug_closing(p,msg,code,callback) (((*p)->closing) (p, msg, code, callback))
00098 #define plug_receive(p,urgent,buf,len) (((*p)->receive) (p, urgent, buf, len))
00099 #define plug_sent(p,bufsize) (((*p)->sent) (p, bufsize))
00100 #define plug_accepting(p, sock) (((*p)->accepting)(p, sock))
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109
00110 #define sk_set_private_ptr(s, ptr) (((*s)->set_private_ptr) (s, ptr))
00111 #define sk_get_private_ptr(s) (((*s)->get_private_ptr) (s))
00112
00113
00114
00115
00116
00117
00118 char *sk_addr_error(SockAddr addr);
00119 #define sk_socket_error(s) (((*s)->socket_error) (s))
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 #define sk_set_frozen(s, is_frozen) (((*s)->set_frozen) (s, is_frozen))
00139
00140
00141
00142
00143
00144 void net_pending_errors(void);
00145
00146
00147
00148
00149
00150
00151
00152
00153 typedef struct certificate *Certificate;
00154 typedef struct our_certificate *Our_Certificate;
00155
00156
00157 typedef struct ssl_client_socket_function_table **SSL_Client_Socket;
00158 typedef struct ssl_client_plug_function_table **SSL_Client_Plug;
00159
00160 struct ssl_client_socket_function_table {
00161 struct socket_function_table base;
00162 void (*renegotiate) (SSL_Client_Socket s);
00163
00164 };
00165
00166 struct ssl_client_plug_function_table {
00167 struct plug_function_table base;
00168 int (*refuse_cert) (SSL_Client_Plug p, Certificate cert[]);
00169
00170
00171
00172 Our_Certificate(*client_cert) (SSL_Client_Plug p);
00173
00174
00175 };
00176
00177 SSL_Client_Socket sk_ssl_client_over(Socket s,
00178 SSL_Client_Plug p);
00179
00180 #define sk_renegotiate(s) (((*s)->renegotiate) (s))
00181
00182 #endif