socksify 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/socksify.rb CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  require 'socket'
19
19
  require 'resolv'
20
- require 'socksify_debug'
20
+ require 'socksify/debug'
21
21
 
22
22
  class SOCKSError < RuntimeError
23
23
  def initialize(msg)
@@ -118,13 +118,33 @@ class TCPSocket
118
118
  @@socks_ignores = ignores
119
119
  end
120
120
 
121
+ class SOCKSConnectionPeerAddress
122
+ attr_reader :socks_server, :socks_port, :peer_host
123
+ def initialize(socks_server, socks_port, peer_host)
124
+ @socks_server, @socks_port, @peer_host = socks_server, socks_port, peer_host
125
+ end
126
+
127
+ def to_s
128
+ "#{@peer_host} (via #{@socks_server}:#{@socks_port}"
129
+ end
130
+ alias_method :to_str, :to_s
131
+ end
132
+
121
133
  alias :initialize_tcp :initialize
122
134
 
123
135
  # See http://tools.ietf.org/html/rfc1928
124
136
  def initialize(host=nil, port=0, local_host="0.0.0.0", local_port=0)
125
- socks_server = self.class.socks_server
126
- socks_port = self.class.socks_port
127
- socks_ignores = self.class.socks_ignores
137
+ if host.is_a?(SOCKSConnectionPeerAddress)
138
+ socks_peer = host
139
+ socks_server = socks_peer.socks_server
140
+ socks_port = socks_peer.socks_port
141
+ socks_ignores = []
142
+ host = socks_peer.peer_host
143
+ else
144
+ socks_server = self.class.socks_server
145
+ socks_port = self.class.socks_port
146
+ socks_ignores = self.class.socks_ignores
147
+ end
128
148
 
129
149
  if socks_server and socks_port and not socks_ignores.include?(host)
130
150
  Socksify::debug_notice "Connecting to SOCKS server #{socks_server}:#{socks_port}"
File without changes
@@ -0,0 +1,55 @@
1
+ =begin
2
+ Copyright (C) 2007 Stephan Maka <stephan@spaceboyz.net>
3
+ Copyright (C) 2011 Musy Bite <musybite@gmail.com>
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
19
+ require 'socksify'
20
+ require 'net/http'
21
+
22
+ module Net
23
+ class HTTP
24
+ def self.SOCKSProxy(p_host, p_port)
25
+ delta = SOCKSProxyDelta
26
+ proxyclass = Class.new(self)
27
+ proxyclass.send(:include, delta)
28
+ proxyclass.module_eval {
29
+ include delta::InstanceMethods
30
+ extend delta::ClassMethods
31
+ @socks_server = p_host
32
+ @socks_port = p_port
33
+ }
34
+ proxyclass
35
+ end
36
+
37
+ module SOCKSProxyDelta
38
+ module ClassMethods
39
+ def socks_server
40
+ @socks_server
41
+ end
42
+
43
+ def socks_port
44
+ @socks_port
45
+ end
46
+ end
47
+
48
+ module InstanceMethods
49
+ def conn_address
50
+ TCPSocket::SOCKSConnectionPeerAddress.new(self.class.socks_server, self.class.socks_port, address())
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,23 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socksify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 1.2.0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stephan Maka
14
14
  - Andrey Kouznetsov
15
15
  - Christopher Thorpe
16
+ - Musy Bite
16
17
  autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2010-12-14 00:00:00 +01:00
21
+ date: 2011-02-22 00:00:00 +01:00
21
22
  default_executable:
22
23
  dependencies: []
23
24
 
@@ -33,9 +34,10 @@ extra_rdoc_files:
33
34
  - COPYING
34
35
  files:
35
36
  - COPYING
36
- - lib/socksify_debug.rb
37
37
  - lib/socksify.rb.orig
38
38
  - lib/socksify.rb
39
+ - lib/socksify/debug.rb
40
+ - lib/socksify/http.rb
39
41
  - bin/socksify_ruby
40
42
  - doc/index.css
41
43
  - doc/index.html