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