net-telnet-rfc2217 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80efcdecc1ad8f12d8546c6487de4ced9f2042beb7126046fd616cb4f507685c
4
- data.tar.gz: 88afffcd92a3d0764047da96e01f1be3811614247230d4d58e563963d894ad06
3
+ metadata.gz: f0b5b2b5e014b1fc9906ae0be1e7d33fb5d3971cce0b4eda74332e6a1ee24a9e
4
+ data.tar.gz: b56a17ffee69e60c4c8f805fd5fb16a0195a95719ed3b93a4fc5417c1dbb0e2f
5
5
  SHA512:
6
- metadata.gz: 984cfeac7c438e93816979be2ea410d398376e7d1bd0255c85e10e94bd18791c346a30357a3e36d650278ade772aff53b147e5f29485079d320995b3d606ec1d
7
- data.tar.gz: 23c8a0d1ee8b9ac9179973f9ec8defde1402b21022febe9b26c29370eaff7def8f509c5c9848ec2cabc09c5013931eefb5224481a0eb9615f81eb9dcb96dee15
6
+ metadata.gz: 1b4b82e214841d59828c733e9c15a65d2e623ee807f42df97353054564cb6bd7991f6900182ecd35cedebf83876c9388ecdce8574639a86b0e4d237e3e8f0a96
7
+ data.tar.gz: 35da8ce422ca87cfc75ad2c4461582d9ec54f8335f74bb381fe178d12890bae4f5034e7338488187c07cdfb6a900e2eb89f95909c7cdd536a33581062b0c5861
@@ -8,6 +8,10 @@ Net::Telnet.prepend(Net::Telnet::RFC2217::TelnetExtensions)
8
8
  module Net
9
9
  class Telnet
10
10
  class RFC2217
11
+ class WaitReadable < RuntimeError
12
+ include ::IO::WaitReadable
13
+ end
14
+
11
15
  attr_reader :telnet
12
16
 
13
17
  COM_PORT_OPTION = 44.chr
@@ -81,7 +85,9 @@ module Net
81
85
  @modem_params['baud'] = 115200 unless @modem_params.key?('baud')
82
86
  @modem_params['data_bits'] = 8 unless @modem_params.key?('data_bits')
83
87
  @modem_params['stop_bits'] = 1 unless @modem_params.key?('stop_bits')
84
- @modem_params['parity'] = (data_bits == 8 ? NONE : EVEN)
88
+ unless @modem_params.key?('parity')
89
+ @modem_params['parity'] = (data_bits == 8 ? NONE : EVEN)
90
+ end
85
91
  write_modem_params if telnet
86
92
  end
87
93
 
@@ -116,7 +122,7 @@ module Net
116
122
  def readpartial(length, outbuf = '')
117
123
  loop do
118
124
  # 0 is special and means 'read at least one control sequence'
119
- break if length != 0 && @buffer.length != 0
125
+ break if length != 0 || @buffer.length != 0
120
126
 
121
127
  data = sock.sysread([length - @buffer.length, 64 * 1024].max)
122
128
 
@@ -134,7 +140,9 @@ module Net
134
140
  true
135
141
  elsif DONT[0] == control[0] && COM_PORT_OPTION == control[1]
136
142
  raise "Serial port control not supported"
137
- false
143
+ elsif (WILL[0] == control[0] || DONT[0] == control[0]) && OPT_ECHO == control[1]
144
+ # just ignore echo requests
145
+ true
138
146
  else
139
147
  false
140
148
  end
@@ -149,6 +157,32 @@ module Net
149
157
  outbuf
150
158
  end
151
159
 
160
+ def read_nonblock(length, outbuf = '', options = {})
161
+ if outbuf == ({ exception: false })
162
+ options = outbuf
163
+ outbuf = ''
164
+ end
165
+ loop do
166
+ result = wait_readable(0)
167
+ if result == nil
168
+ raise WaitReadable unless options[:exception] == false
169
+ return :wait_readable
170
+ end
171
+ # we have to try to consume control characters first
172
+ readpartial(0)
173
+ # and then only do a real read if we have something
174
+ return readpartial(length, outbuf) unless @buffer.empty?
175
+ # otherwise loop and see if there's more there
176
+ end
177
+ end
178
+
179
+ def wait_readable(timeout = nil)
180
+ return true unless @buffer.empty?
181
+ result = sock.wait_readable(timeout)
182
+ result = self if result == sock
183
+ result
184
+ end
185
+
152
186
  def ungetbyte(b)
153
187
  @buffer.insert(0, b.chr)
154
188
  end
@@ -162,6 +196,10 @@ module Net
162
196
  telnet.write(string)
163
197
  end
164
198
 
199
+ def flush
200
+ sock.flush
201
+ end
202
+
165
203
  def close
166
204
  telnet.close
167
205
  end
@@ -1,78 +1,80 @@
1
1
  module Net
2
2
  class Telnet
3
- module RFC2217::TelnetExtensions
4
- def preprocess(string)
5
- # combine CR+NULL into CR
6
- string = string.gsub(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"]
3
+ class RFC2217
4
+ module TelnetExtensions
5
+ def preprocess(string)
6
+ # combine CR+NULL into CR
7
+ string = string.gsub(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"]
7
8
 
8
- # combine EOL into "\n"
9
- string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
9
+ # combine EOL into "\n"
10
+ string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
10
11
 
11
- # remove NULL
12
- string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
12
+ # remove NULL
13
+ string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
13
14
 
14
- string.gsub(/#{IAC}(
15
- [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
16
- [#{DO}#{DONT}#{WILL}#{WONT}]
17
- [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{44.chr}#{OPT_EXOPL}]|
18
- #{SB}[^#{IAC}]*#{IAC}#{SE}
19
- )/xno) do
20
- if block_given? && IAC != $1
21
- # already handled; don't handle it ourselves
22
- next '' if yield $1
23
- end
15
+ string.gsub(/#{IAC}(
16
+ [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
17
+ [#{DO}#{DONT}#{WILL}#{WONT}]
18
+ [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{44.chr}#{OPT_EXOPL}]|
19
+ #{SB}[^#{IAC}]*#{IAC}#{SE}
20
+ )/xno) do
21
+ if block_given? && IAC != $1
22
+ # already handled; don't handle it ourselves
23
+ next '' if yield $1
24
+ end
24
25
 
25
- if IAC == $1 # handle escaped IAC characters
26
- IAC
27
- elsif AYT == $1 # respond to "IAC AYT" (are you there)
28
- self.write("nobody here but us pigeons" + EOL)
29
- ''
30
- elsif DO[0] == $1[0] # respond to "IAC DO x"
31
- if OPT_BINARY[0] == $1[1]
32
- unless @telnet_option["BINARY"] == true
33
- @telnet_option["BINARY"] = true
34
- self.write(IAC + WILL + OPT_BINARY)
26
+ if IAC == $1 # handle escaped IAC characters
27
+ IAC
28
+ elsif AYT == $1 # respond to "IAC AYT" (are you there)
29
+ self.write("nobody here but us pigeons" + EOL)
30
+ ''
31
+ elsif DO[0] == $1[0] # respond to "IAC DO x"
32
+ if OPT_BINARY[0] == $1[1]
33
+ unless @telnet_option["BINARY"] == true
34
+ @telnet_option["BINARY"] = true
35
+ self.write(IAC + WILL + OPT_BINARY)
36
+ end
37
+ else
38
+ self.write(IAC + WONT + $1[1..1])
35
39
  end
36
- else
40
+ ''
41
+ elsif DONT[0] == $1[0] # respond to "IAC DON'T x" with "IAC WON'T x"
37
42
  self.write(IAC + WONT + $1[1..1])
38
- end
39
- ''
40
- elsif DONT[0] == $1[0] # respond to "IAC DON'T x" with "IAC WON'T x"
41
- self.write(IAC + WONT + $1[1..1])
42
- ''
43
- elsif WILL[0] == $1[0] # respond to "IAC WILL x"
44
- if OPT_BINARY[0] == $1[1]
45
- self.write(IAC + DO + OPT_BINARY)
46
- elsif OPT_ECHO[0] == $1[1]
47
- self.write(IAC + DO + OPT_ECHO)
48
- elsif OPT_SGA[0] == $1[1]
49
- unless @telnet_option["SGA"]
50
- @telnet_option["SGA"] = true
51
- self.write(IAC + DO + OPT_SGA)
43
+ ''
44
+ elsif WILL[0] == $1[0] # respond to "IAC WILL x"
45
+ if OPT_BINARY[0] == $1[1]
46
+ self.write(IAC + DO + OPT_BINARY)
47
+ elsif OPT_ECHO[0] == $1[1]
48
+ self.write(IAC + DO + OPT_ECHO)
49
+ elsif OPT_SGA[0] == $1[1]
50
+ unless @telnet_option["SGA"]
51
+ @telnet_option["SGA"] = true
52
+ self.write(IAC + DO + OPT_SGA)
53
+ end
54
+ else
55
+ self.write(IAC + DONT + $1[1..1])
52
56
  end
53
- else
54
- self.write(IAC + DONT + $1[1..1])
55
- end
56
- ''
57
- elsif WONT[0] == $1[0] # respond to "IAC WON'T x"
58
- if OPT_ECHO[0] == $1[1]
59
- self.write(IAC + DONT + OPT_ECHO)
60
- elsif OPT_SGA[0] == $1[1]
61
- unless @telnet_option["SGA"] == false
62
- @telnet_option["SGA"] = false
63
- self.write(IAC + DONT + OPT_SGA)
57
+ ''
58
+ elsif WONT[0] == $1[0] # respond to "IAC WON'T x"
59
+ if OPT_ECHO[0] == $1[1]
60
+ self.write(IAC + DONT + OPT_ECHO)
61
+ elsif OPT_SGA[0] == $1[1]
62
+ unless @telnet_option["SGA"] == false
63
+ @telnet_option["SGA"] = false
64
+ self.write(IAC + DONT + OPT_SGA)
65
+ end
66
+ else
67
+ self.write(IAC + DONT + $1[1..1])
64
68
  end
69
+ ''
70
+ elsif SB[0] == $1[0] # yield sub option
71
+ ''
65
72
  else
66
- self.write(IAC + DONT + $1[1..1])
73
+ ''
67
74
  end
68
- ''
69
- elsif SB[0] == $1[0] # yield sub option
70
- ''
71
- else
72
- ''
73
75
  end
74
- end
75
- end # preprocess
76
+ end # preprocess
77
+ end
76
78
  end
77
79
  end
78
80
  end
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  class Telnet
3
3
  class RFC2217
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-telnet-rfc2217
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer