stomp 1.2.4 → 1.2.5

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.
Files changed (56) hide show
  1. data/CHANGELOG.rdoc +11 -0
  2. data/README.rdoc +38 -26
  3. data/Rakefile +3 -0
  4. data/bin/catstomp +34 -34
  5. data/bin/stompcat +36 -36
  6. data/examples/client11_ex1.rb +64 -55
  7. data/examples/client11_putget1.rb +47 -35
  8. data/examples/conn11_ex1.rb +59 -51
  9. data/examples/conn11_ex2.rb +59 -50
  10. data/examples/conn11_hb1.rb +35 -26
  11. data/examples/consumer.rb +25 -12
  12. data/examples/get11conn_ex1.rb +97 -89
  13. data/examples/get11conn_ex2.rb +55 -47
  14. data/examples/logexamp.rb +66 -52
  15. data/examples/logexamp_ssl.rb +66 -52
  16. data/examples/publisher.rb +21 -10
  17. data/examples/put11conn_ex1.rb +35 -24
  18. data/examples/putget11_rh1.rb +66 -56
  19. data/examples/slogger.rb +65 -52
  20. data/examples/ssl_uc1.rb +24 -13
  21. data/examples/ssl_uc1_ciphers.rb +28 -15
  22. data/examples/ssl_uc2.rb +26 -16
  23. data/examples/ssl_uc2_ciphers.rb +31 -18
  24. data/examples/ssl_uc3.rb +25 -14
  25. data/examples/ssl_uc3_ciphers.rb +31 -18
  26. data/examples/ssl_uc4.rb +26 -15
  27. data/examples/ssl_uc4_ciphers.rb +32 -19
  28. data/examples/ssl_ucx_default_ciphers.rb +25 -12
  29. data/examples/stomp11_common.rb +16 -15
  30. data/examples/topic_consumer.rb +23 -10
  31. data/examples/topic_publisher.rb +22 -8
  32. data/lib/client/utils.rb +116 -0
  33. data/lib/connection/heartbeats.rb +173 -0
  34. data/lib/connection/netio.rb +322 -0
  35. data/lib/connection/utf8.rb +294 -0
  36. data/lib/connection/utils.rb +104 -0
  37. data/lib/stomp/client.rb +127 -179
  38. data/lib/stomp/codec.rb +5 -2
  39. data/lib/stomp/connection.rb +109 -865
  40. data/lib/stomp/constants.rb +52 -33
  41. data/lib/stomp/errors.rb +56 -5
  42. data/lib/stomp/ext/hash.rb +4 -0
  43. data/lib/stomp/message.rb +49 -29
  44. data/lib/stomp/sslparams.rb +83 -71
  45. data/lib/stomp/version.rb +3 -1
  46. data/lib/stomp.rb +18 -9
  47. data/stomp.gemspec +58 -3
  48. data/test/test_client.rb +28 -1
  49. data/test/test_codec.rb +8 -2
  50. data/test/test_connection.rb +29 -0
  51. data/test/test_connection1p.rb +31 -16
  52. data/test/test_helper.rb +20 -3
  53. data/test/test_message.rb +8 -3
  54. data/test/test_ssl.rb +10 -4
  55. data/test/tlogger.rb +16 -15
  56. metadata +59 -4
@@ -2,28 +2,28 @@
2
2
 
3
3
  module Stomp
4
4
 
5
- # Client side
6
- CMD_CONNECT = "CONNECT"
7
- CMD_STOMP = "STOMP"
8
- CMD_DISCONNECT = "DISCONNECT"
9
- CMD_SEND = "SEND"
10
- CMD_SUBSCRIBE = "SUBSCRIBE"
11
- CMD_UNSUBSCRIBE = "UNSUBSCRIBE"
12
- CMD_ACK = "ACK"
13
- CMD_NACK = "NACK"
14
- CMD_BEGIN = "BEGIN"
15
- CMD_COMMIT = "COMMIT"
16
- CMD_ABORT = "ABORT"
5
+ # Client side
6
+ CMD_CONNECT = "CONNECT"
7
+ CMD_STOMP = "STOMP"
8
+ CMD_DISCONNECT = "DISCONNECT"
9
+ CMD_SEND = "SEND"
10
+ CMD_SUBSCRIBE = "SUBSCRIBE"
11
+ CMD_UNSUBSCRIBE = "UNSUBSCRIBE"
12
+ CMD_ACK = "ACK"
13
+ CMD_NACK = "NACK"
14
+ CMD_BEGIN = "BEGIN"
15
+ CMD_COMMIT = "COMMIT"
16
+ CMD_ABORT = "ABORT"
17
17
 
18
- # Server side
19
- CMD_CONNECTED = "CONNECTED"
20
- CMD_MESSAGE = "MESSAGE"
21
- CMD_RECEIPT = "RECEIPT"
22
- CMD_ERROR = "ERROR"
18
+ # Server side
19
+ CMD_CONNECTED = "CONNECTED"
20
+ CMD_MESSAGE = "MESSAGE"
21
+ CMD_RECEIPT = "RECEIPT"
22
+ CMD_ERROR = "ERROR"
23
23
 
24
- # Protocols
25
- SPL_10 = "1.0"
26
- SPL_11 = "1.1"
24
+ # Protocols
25
+ SPL_10 = "1.0"
26
+ SPL_11 = "1.1"
27
27
 
28
28
  # Stomp 1.0 and 1.1
29
29
  SUPPORTED = [SPL_10, SPL_11]
@@ -38,44 +38,63 @@ module Stomp
38
38
  # New line
39
39
  #
40
40
  NL = "\n"
41
- NL_ASCII = 0x0a
41
+ NL_ASCII = 0x0a
42
42
  #
43
43
  # Back Slash
44
44
  #
45
45
  BACK_SLASH = "\\"
46
- BACK_SLASH_ASCII = 0x5c
46
+ BACK_SLASH_ASCII = 0x5c
47
47
  #
48
48
  # Literal colon
49
49
  #
50
50
  LITERAL_COLON = ":"
51
- COLON_ASCII = 0x3a
51
+ COLON_ASCII = 0x3a
52
52
  #
53
53
  # Literal letter c
54
54
  #
55
55
  LITERAL_C = "c"
56
- C_ASCII = 0x63
56
+ C_ASCII = 0x63
57
57
  #
58
58
  # Literal letter n
59
59
  #
60
60
  LITERAL_N = "n"
61
- N_ASCII = 0x6e
61
+ N_ASCII = 0x6e
62
62
  #
63
63
  # Codec from/to values.
64
64
  #
65
65
  ENCODE_VALUES = [
66
- "\\\\", "\\", # encoded, decoded
67
- "\\" + "n", "\n",
68
- "\\c", ":",
66
+ "\\\\", "\\", # encoded, decoded
67
+ "\\" + "n", "\n",
68
+ "\\c", ":",
69
69
  ]
70
70
 
71
71
  #
72
72
  DECODE_VALUES = [
73
- "\\\\\\\\", "\\", # encoded, decoded
74
- "\\" + "n", "\n",
75
- "\\c", ":",
73
+ "\\\\\\\\", "\\", # encoded, decoded
74
+ "\\" + "n", "\n",
75
+ "\\c", ":",
76
76
  ]
77
77
 
78
- DEFAULT_CIPHERS = [["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["AES256-SHA", "TLSv1/SSLv3", 256, 256], ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["AES128-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-MD5", "TLSv1/SSLv3", 128, 128], ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
79
- ["DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EXP-EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56], ["EXP-EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56], ["EXP-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56], ["EXP-RC2-CBC-MD5", "TLSv1/SSLv3", 40, 128], ["EXP-RC4-MD5", "TLSv1/SSLv3", 40, 128]]
78
+ DEFAULT_CIPHERS = [
79
+ ["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256],
80
+ ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256],
81
+ ["AES256-SHA", "TLSv1/SSLv3", 256, 256],
82
+ ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168],
83
+ ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168],
84
+ ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168],
85
+ ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128],
86
+ ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128],
87
+ ["AES128-SHA", "TLSv1/SSLv3", 128, 128],
88
+ ["RC4-SHA", "TLSv1/SSLv3", 128, 128],
89
+ ["RC4-MD5", "TLSv1/SSLv3", 128, 128],
90
+ ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
91
+ ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
92
+ ["DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
93
+ ["EXP-EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56],
94
+ ["EXP-EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56],
95
+ ["EXP-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56],
96
+ ["EXP-RC2-CBC-MD5", "TLSv1/SSLv3", 40, 128],
97
+ ["EXP-RC4-MD5", "TLSv1/SSLv3", 40, 128],
98
+ ]
80
99
 
81
100
  end
data/lib/stomp/errors.rb CHANGED
@@ -1,139 +1,190 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module Stomp
4
+
5
+ # Module level container for Stomp gem error classes.
4
6
  module Error
7
+
8
+ # InvalidFormat is raised if:
9
+ # * During frame parsing if a malformed frame is detected.
5
10
  class InvalidFormat < RuntimeError
6
11
  def message
7
12
  "Invalid message - invalid format"
8
13
  end
9
14
  end
10
15
 
16
+ # InvalidServerCommand is raised if:
17
+ # * An invalid STOMP COMMAND is received from the server.
11
18
  class InvalidServerCommand < RuntimeError
12
19
  def message
13
20
  "Invalid command from server"
14
21
  end
15
22
  end
16
23
 
24
+ # InvalidMessageLength is raised if:
25
+ # * An invalid message length is detected during a frame read.
17
26
  class InvalidMessageLength < RuntimeError
18
27
  def message
19
28
  "Invalid content length received"
20
29
  end
21
30
  end
22
31
 
32
+ # PacketParsingTimeout is raised if:
33
+ # * A frame read has started, but does not complete in 5 seconds.
34
+ # * Use :parse_timeout connect parameter to override the timeout.
23
35
  class PacketParsingTimeout < RuntimeError
24
36
  def message
25
37
  "Packet parsing timeout"
26
38
  end
27
39
  end
28
40
 
41
+ # SocketOpenTimeout is raised if:
42
+ # * A timeout occurs during a socket open.
29
43
  class SocketOpenTimeout < RuntimeError
30
44
  def message
31
45
  "Socket open timeout"
32
46
  end
33
47
  end
34
48
 
49
+ # NoCurrentConnection is raised if:
50
+ # * Any method is called when a current connection does not exist.
35
51
  class NoCurrentConnection < RuntimeError
36
52
  def message
37
53
  "no current connection exists"
38
54
  end
39
55
  end
40
-
56
+
57
+ # MaxReconnectAttempts is raised if:
58
+ # * The maximum number of retries has been reached for a reliable connection.
41
59
  class MaxReconnectAttempts < RuntimeError
42
60
  def message
43
61
  "Maximum number of reconnection attempts reached"
44
62
  end
45
63
  end
46
-
64
+
65
+ # DuplicateSubscription is raised if:
66
+ # * A duplicate subscription ID is detected in the current session.
47
67
  class DuplicateSubscription < RuntimeError
48
68
  def message
49
69
  "duplicate subscriptions are disallowed"
50
70
  end
51
71
  end
52
-
72
+
73
+ # ProtocolErrorConnect is raised if:
74
+ # * Incomplete Stomp 1.1 headers are detectd during a connect.
53
75
  class ProtocolErrorConnect < RuntimeError
54
76
  def message
55
77
  "protocol error on CONNECT"
56
78
  end
57
79
  end
58
-
80
+
81
+ # UnsupportedProtocolError is raised if:
82
+ # * No supported Stomp protocol levels are detected during a connect.
59
83
  class UnsupportedProtocolError < RuntimeError
60
84
  def message
61
85
  "unsupported protocol level(s)"
62
86
  end
63
87
  end
64
-
88
+
89
+ # InvalidHeartBeatHeaderError is raised if:
90
+ # * A "heart-beat" header is present, but the values are malformed.
65
91
  class InvalidHeartBeatHeaderError < RuntimeError
66
92
  def message
67
93
  "heart-beat header value is malformed"
68
94
  end
69
95
  end
70
96
 
97
+ # SubscriptionRequiredError is raised if:
98
+ # * No subscription id is specified for a Stomp 1.1 subscribe.
71
99
  class SubscriptionRequiredError < RuntimeError
72
100
  def message
73
101
  "a valid subscription id header is required"
74
102
  end
75
103
  end
76
104
 
105
+ # UTF8ValidationError is raised if:
106
+ # * Stomp 1.1 headers are not valid UTF8.
77
107
  class UTF8ValidationError < RuntimeError
78
108
  def message
79
109
  "header is invalid UTF8"
80
110
  end
81
111
  end
82
112
 
113
+ # MessageIDRequiredError is raised if:
114
+ # * No messageid parameter is specified for ACK or NACK.
83
115
  class MessageIDRequiredError < RuntimeError
84
116
  def message
85
117
  "a valid message id is required for ACK/NACK"
86
118
  end
87
119
  end
88
120
 
121
+ # SSLClientParamsError is raised if:
122
+ # * Incomplete SSLParams are specified for an SSL connect.
89
123
  class SSLClientParamsError < RuntimeError
90
124
  def message
91
125
  "certificate and key files are both required"
92
126
  end
93
127
  end
94
128
 
129
+ # StompServerError is raised if:
130
+ # * Invalid (nil) data is received from the Stomp server.
95
131
  class StompServerError < RuntimeError
96
132
  def message
97
133
  "Connected, header read is nil, is this really a Stomp Server?"
98
134
  end
99
135
  end
100
136
 
137
+ # SSLNoKeyFileError is raised if:
138
+ # * A supplied key file does not exist.
101
139
  class SSLNoKeyFileError < RuntimeError
102
140
  def message
103
141
  "client key file does not exist"
104
142
  end
105
143
  end
106
144
 
145
+ # SSLUnreadableKeyFileError is raised if:
146
+ # * A supplied key file is not readable.
107
147
  class SSLUnreadableKeyFileError < RuntimeError
108
148
  def message
109
149
  "client key file can not be read"
110
150
  end
111
151
  end
112
152
 
153
+ # SSLNoCertFileError is raised if:
154
+ # * A supplied SSL cert file does not exist.
113
155
  class SSLNoCertFileError < RuntimeError
114
156
  def message
115
157
  "client cert file does not exist"
116
158
  end
117
159
  end
118
160
 
161
+ # SSLUnreadableCertFileError is raised if:
162
+ # * A supplied SSL cert file is not readable.
119
163
  class SSLUnreadableCertFileError < RuntimeError
120
164
  def message
121
165
  "client cert file can not be read"
122
166
  end
123
167
  end
124
168
 
169
+ # SSLNoTruststoreFileError is raised if:
170
+ # * A supplied SSL trust store file does not exist.
125
171
  class SSLNoTruststoreFileError < RuntimeError
126
172
  def message
127
173
  "a client truststore file does not exist"
128
174
  end
129
175
  end
130
176
 
177
+ # SSLUnreadableTruststoreFileError is raised if:
178
+ # * A supplied SSL trust store file is not readable.
131
179
  class SSLUnreadableTruststoreFileError < RuntimeError
132
180
  def message
133
181
  "a client truststore file can not be read"
134
182
  end
135
183
  end
136
184
 
185
+ # LoggerConnectionError is not raised by the gem. It may be
186
+ # raised by client logic in callback logger methods to signal
187
+ # that a connection should not proceed.
137
188
  class LoggerConnectionError < RuntimeError
138
189
  end
139
190
 
@@ -1,10 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  class ::Hash
4
+
5
+ # Returns self with keys uncamelized and converted to symbols.
4
6
  def uncamelize_and_symbolize_keys
5
7
  self.uncamelize_and_stringify_keys.symbolize_keys
6
8
  end
7
9
 
10
+ # Returns self with keys uncamelized and converted to strings.
8
11
  def uncamelize_and_stringify_keys
9
12
  uncamelized = {}
10
13
  self.each_pair do |key, value|
@@ -15,6 +18,7 @@ class ::Hash
15
18
  uncamelized
16
19
  end
17
20
 
21
+ # Returns self with all keys symbolized.
18
22
  def symbolize_keys
19
23
  symbolized = {}
20
24
  self.each_pair do |key, value|
data/lib/stomp/message.rb CHANGED
@@ -2,39 +2,54 @@
2
2
 
3
3
  module Stomp
4
4
 
5
- # Container class for frames, misnamed technically
5
+ # Message is a container class for frames. Misnamed technically.
6
6
  class Message
7
- attr_accessor :command, :headers, :body, :original
8
7
 
9
- @@allowed_commands = [ Stomp::CMD_CONNECTED, Stomp::CMD_MESSAGE, Stomp::CMD_RECEIPT, Stomp::CMD_ERROR ]
8
+ public
10
9
 
10
+ # The COMMAND value.
11
+ attr_accessor :command
12
+
13
+ # The Headers Hash.
14
+ attr_accessor :headers
15
+
16
+ # The message Body.
17
+ attr_accessor :body
18
+
19
+ # The original input(s).
20
+ attr_accessor :original
21
+
22
+ # Commands that are allowed from the wire per the specifications.
23
+ @@allowed_commands = [ Stomp::CMD_CONNECTED, Stomp::CMD_MESSAGE, Stomp::CMD_RECEIPT, Stomp::CMD_ERROR ]
24
+
25
+ # initialize returns a Message from a raw physical frame.
11
26
  def initialize(frame, protocol11p = false)
12
- # p [ "00", frame, frame.encoding ]
27
+ # p [ "00", frame, frame.encoding ]
13
28
  # Set default empty values
14
29
  self.command = ''
15
30
  self.headers = {}
16
31
  self.body = ''
17
32
  self.original = frame
18
33
  return self if is_blank?(frame)
19
- # Figure out where individual parts of the frame begin and end.
20
- command_index = frame.index("\n")
21
- raise Stomp::Error::InvalidFormat, 'command index' unless command_index
22
- #
23
- headers_index = frame.index("\n\n", command_index+1)
24
- raise Stomp::Error::InvalidFormat, 'headers index' unless headers_index
25
- #
26
- lastnull_index = frame.rindex("\0")
27
- raise Stomp::Error::InvalidFormat, 'lastnull index' unless lastnull_index
28
-
29
- # Extract working copies of each frame part
30
- work_command = frame[0..command_index-1]
31
- raise Stomp::Error::InvalidServerCommand, "invalid command: #{work_command.inspect}" unless @@allowed_commands.include?(work_command)
32
- #
33
- work_headers = frame[command_index+1..headers_index-1]
34
- raise Stomp::Error::InvalidFormat, 'nil headers' unless work_headers
35
- #
36
- work_body = frame[headers_index+2..lastnull_index-1]
37
- raise Stomp::Error::InvalidFormat, 'nil body' unless work_body
34
+ # Figure out where individual parts of the frame begin and end.
35
+ command_index = frame.index("\n")
36
+ raise Stomp::Error::InvalidFormat, 'command index' unless command_index
37
+ #
38
+ headers_index = frame.index("\n\n", command_index+1)
39
+ raise Stomp::Error::InvalidFormat, 'headers index' unless headers_index
40
+ #
41
+ lastnull_index = frame.rindex("\0")
42
+ raise Stomp::Error::InvalidFormat, 'lastnull index' unless lastnull_index
43
+
44
+ # Extract working copies of each frame part
45
+ work_command = frame[0..command_index-1]
46
+ raise Stomp::Error::InvalidServerCommand, "invalid command: #{work_command.inspect}" unless @@allowed_commands.include?(work_command)
47
+ #
48
+ work_headers = frame[command_index+1..headers_index-1]
49
+ raise Stomp::Error::InvalidFormat, 'nil headers' unless work_headers
50
+ #
51
+ work_body = frame[headers_index+2..lastnull_index-1]
52
+ raise Stomp::Error::InvalidFormat, 'nil body' unless work_body
38
53
  # Set the frame values
39
54
  if protocol11p
40
55
  work_command.force_encoding(Stomp::UTF8) if work_command.respond_to?(:force_encoding)
@@ -42,7 +57,7 @@ module Stomp
42
57
  self.command = work_command
43
58
  work_headers.split("\n").map do |value|
44
59
  parsed_value = value.match /^([\r|\w|-]*):(.*)$/
45
- raise Stomp::Error::InvalidFormat, 'parsed header value' unless parsed_value
60
+ raise Stomp::Error::InvalidFormat, 'parsed header value' unless parsed_value
46
61
  #
47
62
  pk = parsed_value[1]
48
63
  pv = parsed_value[2]
@@ -71,7 +86,7 @@ module Stomp
71
86
  end
72
87
 
73
88
  body_length = -1
74
-
89
+
75
90
  if self.headers['content-length']
76
91
  body_length = self.headers['content-length'].to_i
77
92
  raise Stomp::Error::InvalidMessageLength if work_body.length != body_length
@@ -79,18 +94,23 @@ module Stomp
79
94
  self.body = work_body[0..body_length]
80
95
  end
81
96
 
97
+ # to_s returns a string prepresentation of this Message
82
98
  def to_s
83
99
  "<Stomp::Message headers=#{headers.inspect} body='#{body}' command='#{command}' >"
84
100
  end
85
101
 
102
+ private
103
+
104
+ # is_blank? tests if a data value is nil or empty.
105
+ def is_blank?(value)
106
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
107
+ end
108
+
109
+ # empty? tests if a Message has any blank parts.
86
110
  def empty?
87
111
  is_blank?(command) && is_blank?(headers) && is_blank?(body)
88
112
  end
89
113
 
90
- private
91
- def is_blank?(value)
92
- value.nil? || (value.respond_to?(:empty?) && value.empty?)
93
- end
94
114
  end
95
115
 
96
116
  end
@@ -1,72 +1,84 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module Stomp
4
- #
5
- # == Purpose
6
- #
7
- # Parameters for STOMP ssl connections.
8
- #
9
- class SSLParams
10
- # The trust store files. Normally the certificate of the CA that signed
11
- # the server's certificate. One file name, or a CSV list of file names.
12
- attr_accessor :ts_files
13
- # The client certificate file.
14
- attr_accessor :cert_file
15
- # The client private key file.
16
- attr_accessor :key_file
17
- # The client private key password.
18
- attr_accessor :key_password
19
- # SSL Connect Verify Result. The result of the handshake.
20
- attr_accessor :verify_result
21
- # The certificate of the connection peer (the server), received during
22
- # the handshake.
23
- attr_accessor :peer_cert
24
- # Optional list of SSL ciphers to be used. In the format documented for
25
- # Ruby's OpenSSL.
26
- attr_accessor :ciphers
27
- # Abcolute command to use Ruby default ciphers
28
- attr_reader :use_ruby_ciphers
29
- # Back reference to the OpenSSL::SSL::SSLContext instance, gem sets before connect
30
- attr_accessor :ctx # Set by the gem during connect, before the callbacks
31
- # Client wants file existance check now. true/value or false/nil
32
- attr_reader :fsck #
33
- #
34
- def initialize(opts={})
35
-
36
- # Server authentication parameters
37
- @ts_files = opts[:ts_files] # A trust store file, normally a CA's cert
38
- # or a CSV list of cert file names
39
-
40
- # Client authentication parameters
41
- @cert_file = opts[:cert_file] # Client cert
42
- @key_file = opts[:key_file] # Client key
43
- @key_password = opts[:key_password] # Client key password
44
- #
45
- raise Stomp::Error::SSLClientParamsError if @cert_file.nil? && !@key_file.nil?
46
- raise Stomp::Error::SSLClientParamsError if !@cert_file.nil? && @key_file.nil?
47
- #
48
- @ciphers = opts[:ciphers]
49
- @use_ruby_ciphers = opts[:use_ruby_ciphers] ? opts[:use_ruby_ciphers] : false
50
- #
51
- if opts[:fsck]
52
- if @cert_file
53
- raise Stomp::Error::SSLNoCertFileError if !File::exists?(@cert_file)
54
- raise Stomp::Error::SSLUnreadableCertFileError if !File::readable?(@cert_file)
55
- end
56
- if @key_file
57
- raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@key_file)
58
- raise Stomp::Error::SSLUnreadableKeyFileError if !File::readable?(@key_file)
59
- end
60
- if @ts_files
61
- tsa = @ts_files.split(",")
62
- tsa.each do |fn|
63
- raise Stomp::Error::SSLNoTruststoreFileError if !File::exists?(fn)
64
- raise Stomp::Error::SSLUnreadableTruststoreFileError if !File::readable?(fn)
65
- end
66
- end
67
- end
68
- end
69
- end # of class SSLParams
70
-
71
- end # of module Stomp
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Stomp
4
+ #
5
+ # == Purpose
6
+ #
7
+ # Parameters for STOMP ssl connections.
8
+ #
9
+ class SSLParams
10
+
11
+ # The trust store files. Normally the certificate of the CA that signed
12
+ # the server's certificate. One file name, or a CSV list of file names.
13
+ attr_accessor :ts_files
14
+
15
+ # The client certificate file.
16
+ attr_accessor :cert_file
17
+
18
+ # The client private key file.
19
+ attr_accessor :key_file
20
+
21
+ # The client private key password.
22
+ attr_accessor :key_password
23
+
24
+ # SSL Connect Verify Result. The result of the handshake.
25
+ attr_accessor :verify_result
26
+
27
+ # The certificate of the connection peer (the server), received during
28
+ # the handshake.
29
+ attr_accessor :peer_cert
30
+
31
+ # Optional list of SSL ciphers to be used. In the format documented for
32
+ # Ruby's OpenSSL.
33
+ attr_accessor :ciphers
34
+
35
+ # Absolute command to use Ruby default ciphers.
36
+ attr_reader :use_ruby_ciphers
37
+
38
+ # Back reference to the OpenSSL::SSL::SSLContext instance, gem sets before connect.
39
+ attr_accessor :ctx # Set by the gem during connect, before the callbacks
40
+
41
+ # Client wants file existance check on initialize. true/value or false/nil.
42
+ attr_reader :fsck #
43
+
44
+ # initialize returns a valid set of SSLParams or raises an error.
45
+ def initialize(opts={})
46
+
47
+ # Server authentication parameters
48
+ @ts_files = opts[:ts_files] # A trust store file, normally a CA's cert
49
+ # or a CSV list of cert file names
50
+
51
+ # Client authentication parameters
52
+ @cert_file = opts[:cert_file] # Client cert
53
+ @key_file = opts[:key_file] # Client key
54
+ @key_password = opts[:key_password] # Client key password
55
+ #
56
+ raise Stomp::Error::SSLClientParamsError if @cert_file.nil? && !@key_file.nil?
57
+ raise Stomp::Error::SSLClientParamsError if !@cert_file.nil? && @key_file.nil?
58
+ #
59
+ @ciphers = opts[:ciphers]
60
+ @use_ruby_ciphers = opts[:use_ruby_ciphers] ? opts[:use_ruby_ciphers] : false
61
+ #
62
+ if opts[:fsck]
63
+ if @cert_file
64
+ raise Stomp::Error::SSLNoCertFileError if !File::exists?(@cert_file)
65
+ raise Stomp::Error::SSLUnreadableCertFileError if !File::readable?(@cert_file)
66
+ end
67
+ if @key_file
68
+ raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@key_file)
69
+ raise Stomp::Error::SSLUnreadableKeyFileError if !File::readable?(@key_file)
70
+ end
71
+ if @ts_files
72
+ tsa = @ts_files.split(",")
73
+ tsa.each do |fn|
74
+ raise Stomp::Error::SSLNoTruststoreFileError if !File::exists?(fn)
75
+ raise Stomp::Error::SSLUnreadableTruststoreFileError if !File::readable?(fn)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ end # of class SSLParams
82
+
83
+ end # of module Stomp
72
84
 
data/lib/stomp/version.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module Stomp
4
+
5
+ # Define the gem version.
4
6
  module Version #:nodoc: all
5
7
  MAJOR = 1
6
8
  MINOR = 2
7
- PATCH = 4
9
+ PATCH = 5
8
10
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
9
11
  end
10
12
  end
data/lib/stomp.rb CHANGED
@@ -15,15 +15,24 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'stomp/constants' # Constants first
19
- require 'stomp/ext/hash'
20
- require 'stomp/connection'
21
- require 'stomp/client'
22
- require 'stomp/message'
23
- require 'stomp/version'
24
- require 'stomp/errors'
25
- require 'stomp/codec'
26
- require 'stomp/sslparams'
18
+ require 'stomp/constants' # Constants first
19
+ require 'stomp/ext/hash' # #Hash additions
20
+ require 'stomp/connection' # Main Stomp#Connection
21
+ require 'stomp/client' # Main Stomp#Client
22
+ require 'stomp/message' # Stomp#Message
23
+ require 'stomp/version' # Stomp#Version#STRING
24
+ require 'stomp/errors' # All Stomp# exceptions
25
+ require 'stomp/codec' # Stomp 1.1 codec
26
+ require 'stomp/sslparams' # Stomp SSL support
27
+
28
+ # Private methods in #Client
29
+ require 'client/utils' # private Client Utility methods
30
+
31
+ # Private methods in #Connection
32
+ require 'connection/utils' # private Connection Utility methods
33
+ require 'connection/netio' # private Network io methods
34
+ require 'connection/heartbeats' # private 1.1+ heartbeat related methods
35
+ require 'connection/utf8' # private 1.1+ UTF8 related methods
27
36
 
28
37
  module Stomp
29
38
  end