00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "rubysocket.h"
00012
00013 #ifdef SOCKS
00014
00015
00016
00017
00018
00019
00020
00021 static VALUE
00022 socks_init(VALUE sock, VALUE host, VALUE serv)
00023 {
00024 static int init = 0;
00025
00026 if (init == 0) {
00027 SOCKSinit("ruby");
00028 init = 1;
00029 }
00030
00031 return rsock_init_inetsock(sock, host, serv, Qnil, Qnil, INET_SOCKS);
00032 }
00033
00034 #ifdef SOCKS5
00035
00036
00037
00038
00039 static VALUE
00040 socks_s_close(VALUE sock)
00041 {
00042 rb_io_t *fptr;
00043
00044 if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
00045 rb_raise(rb_eSecurityError, "Insecure: can't close socket");
00046 }
00047 GetOpenFile(sock, fptr);
00048 shutdown(fptr->fd, 2);
00049 return rb_io_close(sock);
00050 }
00051 #endif
00052 #endif
00053
00054 void
00055 rsock_init_sockssocket(void)
00056 {
00057 #ifdef SOCKS
00058
00059
00060
00061
00062
00063
00064
00065 rb_cSOCKSSocket = rb_define_class("SOCKSSocket", rb_cTCPSocket);
00066 rb_define_method(rb_cSOCKSSocket, "initialize", socks_init, 2);
00067 #ifdef SOCKS5
00068 rb_define_method(rb_cSOCKSSocket, "close", socks_s_close, 0);
00069 #endif
00070 #endif
00071 }
00072