paho-mqtt 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: 6e96a49570aa770ba8c03e15a22b3f07dab8c537
4
- data.tar.gz: 33be02b618285d8493528df49641583e432398df
3
+ metadata.gz: 59165a42d0455ead88b2d98f90ffded161270bd5
4
+ data.tar.gz: 4b1518662800f85b79bc02ed79d694ec4c8d1d60
5
5
  SHA512:
6
- metadata.gz: 19536ea5cd1d728654965db904f9fee6a204afb783979b178b835d735f947199778523c332941fec72dec1d21e6a853c5d2eb91ea45f51cf67119209a2115862
7
- data.tar.gz: 285e5abeabd2aabdd9ccc6072da616868b311870e875cfe5cd57f22d80acf766cd9acc4ab961869f73d7fd69b75ab26b487b4def1a6b2af3280b41833aa5d82e
6
+ metadata.gz: da53418b2eca67e6815ca89f1923c14eb205eaad902026becb715a3910b56718a1d75c0d89db4f4f92ec126d726844a02eb45f70385ada6b9c3981c9bb97c95b
7
+ data.tar.gz: e96111e7f79286a660a90932f56bdf273d548816e93eb4df423103530990552b0eb3c1e6f6a6fd10f5cb247c4135d0238a2bc2f459ae8800cb9a959491e2a1f9
@@ -117,6 +117,51 @@ module PahoMqtt
117
117
  @logger.is_a?(Logger)
118
118
  end
119
119
 
120
+ def match_filter(topics, filters)
121
+ check_topics(topics, filters)
122
+ index = 0
123
+ rc = false
124
+ topic = topics.split('/')
125
+ filter = filters.split('/')
126
+ while index < [topic.length, filter.length].max do
127
+ if is_end?(topic[index], filter[index])
128
+ break
129
+ elsif is_wildcard?(filter[index])
130
+ rc = index == (filter.length - 1)
131
+ break
132
+ elsif keep_running?(filter[index], topic[index])
133
+ index = index + 1
134
+ else
135
+ break
136
+ end
137
+ end
138
+ is_matching?(rc, topic.length, filter.length, index)
139
+ end
140
+
141
+ def keep_running?(filter_part, topic_part)
142
+ filter_part == topic_part || filter_part == '+'
143
+ end
144
+
145
+ def is_wildcard?(filter_part)
146
+ filter_part == '#'
147
+ end
148
+
149
+ def is_end?(topic_part, filter_part)
150
+ topic_part.nil? || filter_part.nil?
151
+ end
152
+
153
+ def is_matching?(rc, topic_length, filter_length, index)
154
+ rc || index == [topic_length, filter_length].max
155
+ end
156
+
157
+ def check_topics(topics, filters)
158
+ if topics.is_a?(String) && filters.is_a?(String)
159
+ else
160
+ @logger.error("Topics or Wildcards are not found as String.") if logger?
161
+ raise ArgumentError
162
+ end
163
+ end
164
+
120
165
  class Exception < ::Exception
121
166
  end
122
167
 
@@ -70,6 +70,10 @@ module PahoMqtt
70
70
  self.send("#{k}=", v)
71
71
  end
72
72
 
73
+ if @ssl
74
+ @ssl_context = OpenSSL::SSL::SSLContext.new
75
+ end
76
+
73
77
  if @port.nil?
74
78
  if @ssl
75
79
  @port = DEFAULT_SSL_PORT
@@ -92,7 +96,7 @@ module PahoMqtt
92
96
  @ssl ||= true
93
97
  @ssl_context = SSLHelper.config_ssl_context(cert_path, key_path, ca_path)
94
98
  end
95
-
99
+
96
100
  def connect(host=@host, port=@port, keep_alive=@keep_alive, persistent=@persistent, blocking=@blocking)
97
101
  @persistent = persistent
98
102
  @blocking = blocking
@@ -102,7 +106,7 @@ module PahoMqtt
102
106
  @connection_state_mutex.synchronize {
103
107
  @connection_state = MQTT_CS_NEW
104
108
  }
105
- @mqtt_thread.kill unless @mqtt_thread.nil?
109
+ @mqtt_thread.kill unless @mqtt_thread.nil?
106
110
  init_connection
107
111
  @connection_helper.send_connect(session_params)
108
112
  begin
@@ -249,7 +253,7 @@ module PahoMqtt
249
253
  def remove_topic_callback(topic)
250
254
  @handler.clear_topic_callback(topic)
251
255
  end
252
-
256
+
253
257
  def on_connack(&block)
254
258
  @handler.on_connack = block if block_given?
255
259
  @handler.on_connack
@@ -141,7 +141,7 @@ module PahoMqtt
141
141
  qos = packet.qos
142
142
  if @publisher.do_publish(qos, id) == MQTT_ERR_SUCCESS
143
143
  @on_message.call(packet) unless @on_message.nil?
144
- @registered_callback.assoc(packet.topic).last.call(packet) if @registered_callback.any? { |pair| pair.first == packet.topic}
144
+ check_callback(packet)
145
145
  end
146
146
  end
147
147
 
@@ -267,5 +267,17 @@ module PahoMqtt
267
267
  raise PacketException
268
268
  end
269
269
  end
270
+
271
+ def check_callback(packet)
272
+ callbacks = []
273
+ @registered_callback.each do |reccord|
274
+ callbacks.push(reccord.last) if PahoMqtt.match_filter(packet.topic, reccord.first)
275
+ end
276
+ unless callbacks.empty?
277
+ callbacks.each do |callback|
278
+ callback.call(packet)
279
+ end
280
+ end
281
+ end
270
282
  end
271
283
  end
@@ -89,7 +89,7 @@ module PahoMqtt
89
89
 
90
90
  @subscribed_mutex.synchronize {
91
91
  to_unsub.each do |filter|
92
- @subscribed_topics.delete_if { |topic| match_filter(topic.first, filter) }
92
+ @subscribed_topics.delete_if { |topic| PahoMqtt.match_filter(topic.first, filter) }
93
93
  end
94
94
  }
95
95
  MQTT_ERR_SUCCESS
@@ -148,53 +148,5 @@ module PahoMqtt
148
148
  end
149
149
  MQTT_ERR_SUCCESS
150
150
  end
151
-
152
-
153
- private
154
-
155
- def match_filter(topics, filters)
156
- check_topics(topics, filters)
157
- index = 0
158
- rc = false
159
- topic = topics.split('/')
160
- filter = filters.split('/')
161
- while index < [topic.length, filter.length].max do
162
- if is_end?(topic[index], filter[index])
163
- break
164
- elsif is_wildcard?(filter[index])
165
- rc = index == (filter.length - 1)
166
- break
167
- elsif keep_running?(filter[index], topic[index])
168
- index = index + 1
169
- else
170
- break
171
- end
172
- end
173
- is_matching?(rc, topic.length, filter.length, index)
174
- end
175
-
176
- def keep_running?(filter_part, topic_part)
177
- filter_part == topic_part || filter_part == '+'
178
- end
179
-
180
- def is_wildcard?(filter_part)
181
- filter_part == '#'
182
- end
183
-
184
- def is_end?(topic_part, filter_part)
185
- topic_part.nil? || filter_part.nil?
186
- end
187
-
188
- def is_matching?(rc, topic_length, filter_length, index)
189
- rc || index == [topic_length, filter_length].max
190
- end
191
-
192
- def check_topics(topics, filters)
193
- if topics.is_a?(String) && filters.is_a?(String)
194
- else
195
- @logger.error("Topics or Wildcards are not found as String.") if PahoMqtt.logger?
196
- raise ArgumentError
197
- end
198
- end
199
151
  end
200
152
  end
@@ -1,3 +1,3 @@
1
1
  module PahoMqtt
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paho-mqtt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Goudet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-28 00:00:00.000000000 Z
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -118,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.6.7
121
+ rubygems_version: 2.6.11
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: A simple mqtt client gem
125
125
  test_files: []
126
- has_rdoc: