Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

sockssocket.c
Go to the documentation of this file.
1 /************************************************
2
3 sockssocket.c -
4
5 created at: Thu Mar 31 12:21:29 JST 1994
6
7 Copyright (C) 1993-2007 Yukihiro Matsumoto
8
9 ************************************************/
10
11 #include "rubysocket.h"
12
13 #ifdef SOCKS
14 /*
15 * call-seq:
16 * SOCKSSocket.new(host, serv) => socket
17 *
18 * Opens a SOCKS connection to +host+ via the SOCKS server +serv+.
19 *
20 */
21 static VALUE
22 socks_init(VALUE sock, VALUE host, VALUE serv)
23 {
24 static int init = 0;
25
26 if (init == 0) {
27 SOCKSinit("ruby");
28 init = 1;
29 }
30
31 return rsock_init_inetsock(sock, host, serv, Qnil, Qnil, INET_SOCKS);
32 }
33
34 #ifdef SOCKS5
35 /*
36 * Closes the SOCKS connection.
37 *
38 */
39 static VALUE
40 socks_s_close(VALUE sock)
41 {
42 rb_io_t *fptr;
43
44 if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
45 rb_raise(rb_eSecurityError, "Insecure: can't close socket");
46 }
47 GetOpenFile(sock, fptr);
48 shutdown(fptr->fd, 2);
49 return rb_io_close(sock);
50 }
51 #endif
52 #endif
53
54 void
55 rsock_init_sockssocket(void)
56 {
57 #ifdef SOCKS
58 /*
59 * Document-class: SOCKSSocket < TCPSocket
60 *
61 * SOCKS is an Internet protocol that routes packets between a client and
62 * a server through a proxy server. SOCKS5, if supported, additionally
63 * provides authentication so only authorized users may access a server.
64 */
65 rb_cSOCKSSocket = rb_define_class("SOCKSSocket", rb_cTCPSocket);
66 rb_define_method(rb_cSOCKSSocket, "initialize", socks_init, 2);
67 #ifdef SOCKS5
68 rb_define_method(rb_cSOCKSSocket, "close", socks_s_close, 0);
69 #endif
70 #endif
71 }
rb_io_t
Definition: io.h:63
OBJ_TAINTED
#define OBJ_TAINTED(x)
INET_SOCKS
#define INET_SOCKS
Definition: rubysocket.h:173
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1780
rb_eSecurityError
VALUE rb_eSecurityError
Definition: error.c:520
GetOpenFile
#define GetOpenFile(obj, fp)
Definition: io.h:120
rb_cTCPSocket
VALUE rb_cTCPSocket
Definition: init.c:15
Qnil
#define Qnil
Definition: tcltklib.c:1896
rsock_init_sockssocket
void rsock_init_sockssocket(void)
Definition: sockssocket.c:55
rb_define_class
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:499
rb_io_t::fd
int fd
Definition: io.h:64
shutdown
#define shutdown(a, b)
Definition: io.c:562
rubysocket.h
rsock_init_inetsock
VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type)
Definition: ipsocket.c:120
rb_safe_level
#define rb_safe_level()
Definition: tcltklib.c:94
rb_io_close
VALUE rb_io_close(VALUE)
Definition: io.c:4221
VALUE
unsigned long VALUE
Definition: ripper.y:104
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344