net-tns 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d83e49611fcd37883b8e3a315b387fd7ff5d45b0
4
- data.tar.gz: 4725b36fb5c5d58179cbe6f136f79e4c94bb4b87
3
+ metadata.gz: ae395e30d483af200c9eda9c522288af1cdad4e1
4
+ data.tar.gz: e4399ebb1818042b98d92b8e18e54de0e0b79d12
5
5
  SHA512:
6
- metadata.gz: 1a0315c84d50fbb96f4e813cf5f67a6f65f37429e05027d56c81dac71e35fed4f1a0af0f192e3c47ee571761e360b19deeec050b514f271182f35727c49622fa
7
- data.tar.gz: 833468e8dda81b69b049672ed6fb131d727ac3436c61e29f9111133615533656cae947cbdc8bde727b1bad32d930c0d3ede228517e31738bd65dfde29c4c8a0e
6
+ metadata.gz: 9bc129315cca6f165f1fdecbb211b436034fdb8606083b7e5d1d1ae80a4bafe87447e1463f1a21042afdb68e8b016b6bb392955f0b7f83165924db4d18840a7c
7
+ data.tar.gz: f17cdca07bcc38a3199b30ded2eb9fe1384c892d43c8ff2d8865e746e1e8ff116763715cfde565ae339e8422670541a498333defaebd627ab86bdc7c9c57987f
@@ -10,7 +10,7 @@ module Net
10
10
  return true
11
11
  rescue Exceptions::ConnectionClosed
12
12
  return false
13
- rescue Exceptions::TnsException
13
+ rescue Exceptions::TNSException
14
14
  return true
15
15
  ensure
16
16
  conn.close_socket() unless conn.nil?
@@ -7,16 +7,17 @@ module Net
7
7
  attr_reader :tns_protocol_version
8
8
 
9
9
  def initialize(opts={})
10
- opts = {
11
- :port => 1521,
12
- }.merge(opts)
13
-
14
10
  @socket = nil
15
- @socket_opts = {}
16
- socket_opts_keys = [:host, :port, :get_socket_callback, :close_socket_callback]
17
- socket_opts_keys.each {|key| @socket_opts[key] = opts.delete(key) if opts.has_key?(key)}
11
+
12
+ @host = opts.delete(:host)
13
+ @port = opts.delete(:port) || 1521
14
+ @new_socket_proc = opts.delete(:new_socket_proc)
18
15
 
19
16
  raise ArgumentError.new("Unrecognized options: #{opts.keys}") unless opts.empty?
17
+
18
+ if @host.nil? == @new_socket_proc.nil?
19
+ raise ArgumentError.new("Invalid socket options. Need :host and :port, OR :new_socket_proc")
20
+ end
20
21
  end
21
22
 
22
23
  # This is a low-level function to directly open a socket for this connection.
@@ -26,19 +27,15 @@ module Net
26
27
  Net::TNS.logger.debug("Connection#open_socket called")
27
28
  close_socket()
28
29
 
29
- if (host = @socket_opts[:host]) && (port = @socket_opts[:port])
30
- if @socket_opts.has_key?(:get_socket_callback) || @socket_opts.has_key?(:close_socket_callback)
31
- raise ArgumentError.new("Cannot specify :host/:port with :get_socket_callback/:close_socket_callback")
32
- end
33
-
30
+ if @host
34
31
  require "socket"
35
- Net::TNS.logger.info("Creating new TCPSocket for #{host}:#{port}")
36
- @socket = TCPSocket.new(host, port)
37
- elsif socket_cb = @socket_opts[:get_socket_callback]
38
- Net::TNS.logger.info("Calling get-socket callback for new socket")
39
- @socket = socket_cb.call()
32
+ Net::TNS.logger.info("Creating new TCPSocket for #{@host}:#{@port}")
33
+ @socket = TCPSocket.new(@host, @port)
34
+ elsif @new_socket_proc
35
+ Net::TNS.logger.info("Calling new-socket proc for new socket")
36
+ @socket = @new_socket_proc.call()
40
37
  else
41
- raise ArgumentError.new("No valid options for socket creation. Need :host and :port, or :get_socket_callback (:close_socket_callback optional)")
38
+ raise ArgumentError.new("Invalid socket options")
42
39
  end
43
40
 
44
41
  return
@@ -50,16 +47,9 @@ module Net
50
47
  def close_socket
51
48
  Net::TNS.logger.debug("Connection#close_socket called")
52
49
  begin
53
- unless @socket.nil?
54
- if close_cb = @socket_opts[:close_socket_callback]
55
- Net::TNS.logger.info("Calling close-socket callback to close socket")
56
- close_cb.call(@socket)
57
- else
58
- unless @socket.closed?
59
- Net::TNS.logger.info("Closing socket")
60
- @socket.close
61
- end
62
- end
50
+ unless @socket.nil? or @socket.closed?
51
+ Net::TNS.logger.info("Closing socket")
52
+ @socket.close
63
53
  end
64
54
  ensure
65
55
  @socket = nil
@@ -140,7 +130,7 @@ module Net
140
130
 
141
131
  def resend_last_tns_packet
142
132
  if @tns_last_sent_packet.nil?
143
- raise Exceptions::TnsException.new( "Resend received without a packet to resend" )
133
+ raise Exceptions::TNSException.new( "Resend received without a packet to resend" )
144
134
  end
145
135
  send_tns_packet( @tns_last_sent_packet )
146
136
  end
@@ -154,7 +144,7 @@ module Net
154
144
  # @return [Net::TNS::Packet]
155
145
  # @raise [Net::TNS::Exceptions::RefuseMessageReceived] If the other side
156
146
  # sent TNS refuse message.
157
- # @raise [Net::TNS::Exceptions::TnsException] If another unexpected
147
+ # @raise [Net::TNS::Exceptions::TNSException] If another unexpected
158
148
  # state or action occurs.
159
149
  def receive_tns_packet( waiting_for_error_message = false )
160
150
  # This is structured as a loop in order to handle messages (e.g. Resends)
@@ -167,7 +157,7 @@ module Net
167
157
 
168
158
  receive_count += 1
169
159
  if ( receive_count >= 3 )
170
- raise Exceptions::TnsException.new( "Maximum receive attempts exceeded - too many Resends received." )
160
+ raise Exceptions::TNSException.new( "Maximum receive attempts exceeded - too many Resends received." )
171
161
  end
172
162
 
173
163
  # Try to receive a TNS packet
@@ -1,22 +1,22 @@
1
1
  module Net::TNS
2
2
  module Exceptions
3
- class TnsException < StandardError
3
+ class TNSException < StandardError
4
4
  end
5
5
 
6
- class ProtocolException < TnsException
6
+ class ProtocolException < TNSException
7
7
  end
8
8
 
9
9
 
10
- class ReceiveTimeoutExceeded < TnsException
10
+ class ReceiveTimeoutExceeded < TNSException
11
11
  end
12
12
 
13
- class ConnectionClosed < TnsException
13
+ class ConnectionClosed < TNSException
14
14
  end
15
15
 
16
- class RefuseMessageReceived < TnsException
16
+ class RefuseMessageReceived < TNSException
17
17
  end
18
18
 
19
- class RedirectMessageReceived < TnsException
19
+ class RedirectMessageReceived < TNSException
20
20
  attr_reader :new_port
21
21
  attr_reader :new_host
22
22
 
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module TNS
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -58,7 +58,11 @@ module Net
58
58
  packet_raw = header_raw + payload_raw
59
59
 
60
60
  unless payload_class = @@tns_packet_classes[ header.packet_type ]
61
- raise Net::TNS::Exceptions::TnsException.new( "Unknown TNS packet type: #{header.packet_type}" )
61
+ raise Net::TNS::Exceptions::TNSException.new( "Unknown TNS packet type: #{header.packet_type}" )
62
+ end
63
+
64
+ unless packet_raw.length == header.packet_length
65
+ raise Net::TNS::Exceptions::ProtocolException
62
66
  end
63
67
 
64
68
  new_packet = payload_class.read( packet_raw )
@@ -6,7 +6,7 @@ module Net
6
6
  class Client
7
7
  def connect(opts={})
8
8
  socket_opts = {}
9
- socket_opts_keys = [:host, :port]
9
+ socket_opts_keys = [:host, :port, :new_socket_proc]
10
10
  socket_opts_keys.each {|key| socket_opts[key] = opts.delete(key) if opts.has_key?(key)}
11
11
 
12
12
  connect_opts = {}
@@ -28,14 +28,14 @@ module Net
28
28
  end
29
29
 
30
30
  def authenticate( username, password )
31
- pre_auth_request = get_pre_auth_request( username )
31
+ begin
32
+ pre_auth_request = get_pre_auth_request( username )
32
33
 
33
- pre_auth_response_raw = @tti_conn.send_and_receive(pre_auth_request)
34
- pre_auth_response = PreAuthenticationResponse.read(pre_auth_response_raw)
34
+ pre_auth_response_raw = @tti_conn.send_and_receive(pre_auth_request)
35
+ pre_auth_response = PreAuthenticationResponse.read(pre_auth_response_raw)
35
36
 
36
- auth_request = get_auth_request(username, password, pre_auth_response)
37
+ auth_request = get_auth_request(username, password, pre_auth_response)
37
38
 
38
- begin
39
39
  @tti_conn.send_and_receive(auth_request)
40
40
  rescue Exceptions::ErrorMessageReceived => error
41
41
  case error.error_code
@@ -79,7 +79,7 @@ module Net
79
79
  while ( true )
80
80
  receive_count += 1
81
81
  if ( receive_count >= 3 )
82
- raise Exceptions::TnsException.new( "Maximum receive attempts exceeded - too many Markers received." )
82
+ raise Exceptions::TNSException.new( "Maximum receive attempts exceeded - too many Markers received." )
83
83
  end
84
84
 
85
85
  Net::TTI.logger.debug("Attempting to receive packet (try ##{receive_count})")
@@ -34,7 +34,7 @@ module Net
34
34
  ttc_code = raw_message[0].unpack("C").first
35
35
 
36
36
  unless message_class = @@ttc_classes[ ttc_code ]
37
- raise Net::TNS::Exceptions::TnsException.new( "Unknown TTC code: #{ttc_code}" )
37
+ raise Net::TNS::Exceptions::TNSException.new( "Unknown TTC code: #{ttc_code}" )
38
38
  end
39
39
 
40
40
  new_message = message_class.new
@@ -47,4 +47,4 @@ module Net
47
47
  end
48
48
 
49
49
  require "pathname"
50
- Dir.glob("#{Pathname.new(__FILE__).dirname}/messages/**/*.rb") { |file| require file }
50
+ Dir.glob("#{Pathname.new(__FILE__).dirname}/messages/*.rb") { |file| require file }
@@ -44,3 +44,6 @@ module Net
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ require "pathname"
49
+ Dir.glob("#{Pathname.new(__FILE__).dirname}/function_calls/*.rb") { |file| require file }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-tns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Woodbury
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-03 00:00:00.000000000 Z
12
+ date: 2014-12-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bindata