rtunnel 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Manifest.txt +1 -0
  2. data/lib/cmds.rb +166 -0
  3. data/lib/core.rb +2 -2
  4. metadata +2 -1
data/Manifest.txt CHANGED
@@ -10,3 +10,4 @@ lib/rtunnel_server_cmd.rb
10
10
  lib/client.rb
11
11
  lib/core.rb
12
12
  lib/server.rb
13
+ lib/cmds.rb
data/lib/cmds.rb ADDED
@@ -0,0 +1,166 @@
1
+ module RTunnel
2
+ class Command
3
+
4
+ def to_s
5
+ CLASSES_TO_CODES[self.class].dup
6
+ end
7
+
8
+ class << self
9
+ def parse(data)
10
+ klass = class_from_code(data[0..0])
11
+
12
+ new_data = data[1..-1]
13
+ cmd = klass.parse(new_data)
14
+
15
+ data.replace(new_data)
16
+
17
+ cmd
18
+ end
19
+
20
+ def match(data)
21
+ return false if ! (klass = class_from_code(data[0..0]))
22
+
23
+ klass.match(data[1..-1])
24
+ end
25
+
26
+ private
27
+
28
+ def class_from_code(code)
29
+ CODES_TO_CLASSES[code]
30
+ end
31
+ end
32
+ end
33
+
34
+ class ConnectionCommand < Command
35
+ attr_reader :conn_id
36
+
37
+ def initialize(conn_id)
38
+ @conn_id = conn_id
39
+ end
40
+
41
+ def to_s
42
+ super + "#{conn_id}|"
43
+ end
44
+
45
+ class << self
46
+ RE = %r{^([^|]+)\|}
47
+
48
+ def parse(data)
49
+ data =~ RE
50
+ conn_id = $1
51
+
52
+ cmd = self.new(conn_id)
53
+
54
+ data.sub! RE, ''
55
+
56
+ cmd
57
+ end
58
+
59
+ def match(data)
60
+ !! (data =~ RE)
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ class CreateConnectionCommand < ConnectionCommand
67
+ end
68
+
69
+ class CloseConnectionCommand < ConnectionCommand
70
+ end
71
+
72
+ class SendDataCommand < Command
73
+ attr_reader :conn_id
74
+ attr_reader :data
75
+
76
+ def initialize(conn_id, data)
77
+ @conn_id = conn_id
78
+ @data = data
79
+ end
80
+
81
+ def to_s
82
+ super + "#{conn_id}|#{data.size}|#{data}"
83
+ end
84
+
85
+ class << self
86
+ RE = %r{^([^|]+)\|([^|]+)\|}
87
+
88
+ def parse(data)
89
+ data =~ RE
90
+
91
+ conn_id = $1
92
+ data_size = $2.to_i
93
+
94
+ new_data = data.sub(RE, '')
95
+ cmd_data = new_data[0,data_size]
96
+
97
+ cmd = SendDataCommand.new(conn_id, cmd_data)
98
+
99
+ data.replace(new_data[data_size..-1])
100
+
101
+ cmd
102
+ end
103
+
104
+ def match(data)
105
+ return false if ! (data =~ RE)
106
+
107
+ data_size = $2.to_i
108
+
109
+ data.sub(RE, '').size >= data_size
110
+ end
111
+ end
112
+ end
113
+
114
+ class RemoteListenCommand < Command
115
+ attr_reader :address
116
+
117
+ def initialize(address)
118
+ @address = address
119
+ end
120
+
121
+ def to_s
122
+ super + "#{address}|"
123
+ end
124
+
125
+ class << self
126
+ RE = %r{^([^|]+)\|}
127
+
128
+ def parse(data)
129
+ data =~ RE
130
+ address = $1
131
+
132
+ cmd = self.new(address)
133
+
134
+ data.sub! RE, ''
135
+
136
+ cmd
137
+ end
138
+
139
+ def match(data)
140
+ !! (data =~ RE)
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+ class PingCommand < Command
147
+ def self.parse(data)
148
+ PingCommand.new
149
+ end
150
+
151
+ def self.match(data)
152
+ true
153
+ end
154
+ end
155
+
156
+ class Command
157
+ CODES_TO_CLASSES = {
158
+ "C" => CreateConnectionCommand,
159
+ "X" => CloseConnectionCommand,
160
+ "D" => SendDataCommand,
161
+ "P" => PingCommand,
162
+ "L" => RemoteListenCommand,
163
+ }
164
+ CLASSES_TO_CODES = CODES_TO_CLASSES.invert
165
+ end
166
+ end
data/lib/core.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RTunnel
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
 
4
4
  DEFAULT_CONTROL_PORT = 19050
5
5
  PING_TIMEOUT = 10
@@ -50,4 +50,4 @@ class UUID
50
50
  def self.t
51
51
  timestamp_create.hexdigest
52
52
  end
53
- end
53
+ end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rtunnel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
6
+ version: 0.3.1
7
7
  date: 2007-11-27 00:00:00 +07:00
8
8
  summary: The author was too lazy to write a summary
9
9
  require_paths:
@@ -41,6 +41,7 @@ files:
41
41
  - lib/client.rb
42
42
  - lib/core.rb
43
43
  - lib/server.rb
44
+ - lib/cmds.rb
44
45
  test_files: []
45
46
 
46
47
  rdoc_options: