yalgaar 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/doc/Encoding.html +250 -0
  3. data/doc/MQTT.html +119 -0
  4. data/doc/MQTT/Client.html +1520 -0
  5. data/doc/MQTT/Exception.html +104 -0
  6. data/doc/MQTT/MQTT.html +95 -0
  7. data/doc/MQTT/MQTT/MQTT.html +95 -0
  8. data/doc/MQTT/MQTT/MQTT/Packet.html +1263 -0
  9. data/doc/MQTT/MQTT/MQTT/Packet/Connack.html +433 -0
  10. data/doc/MQTT/MQTT/MQTT/Packet/Connect.html +596 -0
  11. data/doc/MQTT/MQTT/MQTT/Packet/Disconnect.html +214 -0
  12. data/doc/MQTT/MQTT/MQTT/Packet/Pingreq.html +212 -0
  13. data/doc/MQTT/MQTT/MQTT/Packet/Pingresp.html +212 -0
  14. data/doc/MQTT/MQTT/MQTT/Packet/Puback.html +235 -0
  15. data/doc/MQTT/MQTT/MQTT/Packet/Pubcomp.html +235 -0
  16. data/doc/MQTT/MQTT/MQTT/Packet/Publish.html +590 -0
  17. data/doc/MQTT/MQTT/MQTT/Packet/Pubrec.html +235 -0
  18. data/doc/MQTT/MQTT/MQTT/Packet/Pubrel.html +334 -0
  19. data/doc/MQTT/MQTT/MQTT/Packet/Suback.html +441 -0
  20. data/doc/MQTT/MQTT/MQTT/Packet/Subscribe.html +449 -0
  21. data/doc/MQTT/MQTT/MQTT/Packet/Unsuback.html +284 -0
  22. data/doc/MQTT/MQTT/MQTT/Packet/Unsubscribe.html +403 -0
  23. data/doc/MQTT/NotConnectedException.html +106 -0
  24. data/doc/MQTT/ProtocolException.html +105 -0
  25. data/doc/MQTT/Proxy.html +400 -0
  26. data/doc/MQTT/SN.html +116 -0
  27. data/doc/MQTT/SN/Packet.html +802 -0
  28. data/doc/MQTT/SN/Packet/Advertise.html +236 -0
  29. data/doc/MQTT/SN/Packet/Connack.html +259 -0
  30. data/doc/MQTT/SN/Packet/Connect.html +246 -0
  31. data/doc/MQTT/SN/Packet/Disconnect.html +231 -0
  32. data/doc/MQTT/SN/Packet/Gwinfo.html +241 -0
  33. data/doc/MQTT/SN/Packet/Pingreq.html +102 -0
  34. data/doc/MQTT/SN/Packet/Pingresp.html +102 -0
  35. data/doc/MQTT/SN/Packet/Puback.html +257 -0
  36. data/doc/MQTT/SN/Packet/Pubcomp.html +227 -0
  37. data/doc/MQTT/SN/Packet/Publish.html +255 -0
  38. data/doc/MQTT/SN/Packet/Pubrec.html +227 -0
  39. data/doc/MQTT/SN/Packet/Pubrel.html +227 -0
  40. data/doc/MQTT/SN/Packet/Regack.html +257 -0
  41. data/doc/MQTT/SN/Packet/Register.html +257 -0
  42. data/doc/MQTT/SN/Packet/Searchgw.html +223 -0
  43. data/doc/MQTT/SN/Packet/Suback.html +255 -0
  44. data/doc/MQTT/SN/Packet/Subscribe.html +255 -0
  45. data/doc/MQTT/SN/Packet/Unsuback.html +227 -0
  46. data/doc/MQTT/SN/Packet/Unsubscribe.html +255 -0
  47. data/doc/MQTT/SN/Packet/Willmsg.html +209 -0
  48. data/doc/MQTT/SN/Packet/Willmsgreq.html +102 -0
  49. data/doc/MQTT/SN/Packet/Willmsgresp.html +227 -0
  50. data/doc/MQTT/SN/Packet/Willmsgupd.html +209 -0
  51. data/doc/MQTT/SN/Packet/Willtopic.html +233 -0
  52. data/doc/MQTT/SN/Packet/Willtopicreq.html +102 -0
  53. data/doc/MQTT/SN/Packet/Willtopicresp.html +227 -0
  54. data/doc/MQTT/SN/Packet/Willtopicupd.html +232 -0
  55. data/doc/MQTT/SN/ProtocolException.html +105 -0
  56. data/doc/MYalgaar.html +212 -0
  57. data/doc/Object.html +396 -0
  58. data/doc/SSLcomDVCA_2_crt.html +115 -0
  59. data/doc/String.html +227 -0
  60. data/doc/YALGAAR.html +110 -0
  61. data/doc/Yalgaar.html +189 -0
  62. data/doc/YalgaarApis.html +619 -0
  63. data/doc/YalgaarChannelList.html +228 -0
  64. data/doc/YalgaarConnect.html +439 -0
  65. data/doc/YalgaarHistory.html +174 -0
  66. data/doc/YalgaarInit.html +206 -0
  67. data/doc/YalgaarPublish.html +196 -0
  68. data/doc/YalgaarSubcribe.html +266 -0
  69. data/doc/ca_crt.html +97 -0
  70. data/doc/css/fonts.css +167 -0
  71. data/doc/css/rdoc.css +590 -0
  72. data/doc/examples/SSLcomDVCA_2_crt.html +115 -0
  73. data/doc/fonts/Lato-Light.ttf +0 -0
  74. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  75. data/doc/fonts/Lato-Regular.ttf +0 -0
  76. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  77. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  78. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  79. data/doc/images/add.png +0 -0
  80. data/doc/images/arrow_up.png +0 -0
  81. data/doc/images/brick.png +0 -0
  82. data/doc/images/brick_link.png +0 -0
  83. data/doc/images/bug.png +0 -0
  84. data/doc/images/bullet_black.png +0 -0
  85. data/doc/images/bullet_toggle_minus.png +0 -0
  86. data/doc/images/bullet_toggle_plus.png +0 -0
  87. data/doc/images/date.png +0 -0
  88. data/doc/images/delete.png +0 -0
  89. data/doc/images/find.png +0 -0
  90. data/doc/images/macFFBgHack.png +0 -0
  91. data/doc/images/package.png +0 -0
  92. data/doc/images/page_green.png +0 -0
  93. data/doc/images/page_white_text.png +0 -0
  94. data/doc/images/page_white_width.png +0 -0
  95. data/doc/images/plugin.png +0 -0
  96. data/doc/images/ruby.png +0 -0
  97. data/doc/images/tag_blue.png +0 -0
  98. data/doc/images/tag_green.png +0 -0
  99. data/doc/images/transparent.png +0 -0
  100. data/doc/images/wrench.png +0 -0
  101. data/doc/images/wrench_orange.png +0 -0
  102. data/doc/images/zoom.png +0 -0
  103. data/doc/index.html +219 -0
  104. data/doc/js/darkfish.js +161 -0
  105. data/doc/js/jquery.js +4 -0
  106. data/doc/js/navigation.js +142 -0
  107. data/doc/js/navigation.js.gz +0 -0
  108. data/doc/js/search.js +109 -0
  109. data/doc/js/search_index.js +1 -0
  110. data/doc/js/search_index.js.gz +0 -0
  111. data/doc/js/searcher.js +228 -0
  112. data/doc/js/searcher.js.gz +0 -0
  113. data/doc/table_of_contents.html +1296 -0
  114. data/doc/yalgaar_gemspec.html +116 -0
  115. data/examples/SSLcomDVCA_2.crt +34 -0
  116. data/examples/channelList.rb +64 -0
  117. data/examples/connect.rb +37 -0
  118. data/examples/history.rb +37 -0
  119. data/examples/publish.rb +21 -0
  120. data/examples/subcribe.rb +53 -0
  121. data/examples/yalgaarUser.rb +92 -0
  122. data/lib/mqttbridge/YalgaarChannellist.rb +71 -0
  123. data/lib/mqttbridge/YalgaarConnect.rb +277 -0
  124. data/lib/mqttbridge/YalgaarHistory.rb +48 -0
  125. data/lib/mqttbridge/YalgaarInitModule.rb +333 -0
  126. data/lib/mqttbridge/YalgaarPublish.rb +39 -0
  127. data/lib/mqttbridge/YalgaarSubscribe.rb +99 -0
  128. data/lib/mqttbridge/client.rb +601 -0
  129. data/lib/mqttbridge/mqtt.rb +54 -0
  130. data/lib/mqttbridge/packet.rb +1113 -0
  131. data/lib/mqttbridge/patches/string_encoding.rb +34 -0
  132. data/lib/mqttbridge/proxy.rb +119 -0
  133. data/lib/mqttbridge/sn/packet.rb +763 -0
  134. data/lib/mqttbridge/version.rb +4 -0
  135. data/lib/yalgaar.rb +24 -0
  136. metadata +178 -0
@@ -0,0 +1,71 @@
1
+ #@fileName <YalgaarChannelist.rb>
2
+ #@brief - <methods>
3
+ #
4
+ #Revision Log:
5
+ # v1.0.1 : Aug 4, 2016 INITIAL OF PROGRAMMER - REVISION DETAIL_1 <- THIS IS THE LATEST REVISION
6
+ #Description:
7
+ #YalgaarInitModule contents methods and variables and enum..
8
+ #
9
+ #@bug Known Issues:
10
+ # 1. ISSUE NAME - NONE
11
+ # WORKAROUND - NONE
12
+ #@details Notes: NONE
13
+ #SLS MAKES NO REPRESENTATION, WARRANTY, OR CONDITION OF
14
+ #ANY KIND, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE OR IN
15
+ #ANY COMMUNICATION WITH YOU, INCLUDING, BUT NOT LIMITED TO,
16
+ #ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY
17
+ #QUALITY, FITNESS FOR ANY PARTICULAR PURPOSE,
18
+ #NONINFRINGEMENT, AND THEIR EQUIVALENTS.
19
+ #SLS Propritery and Confidential
20
+ #@copyright (C) 2016 SLS Corporation, All Rights Reserved.
21
+ #~ require_relative 'YalgaarInitModule'
22
+ #!/usr/bin/env ruby
23
+ require 'json'
24
+ require_relative 'YalgaarInitModule'
25
+ # Namespace module for YalgaarChannelList default variables...
26
+ module YalgaarChannelList
27
+ #~ include YalgaarInit
28
+ #~ include MQTT
29
+ include YalgaarInit
30
+ #~ include YalgaarApis
31
+ #yalgaarGetChannelList(message);
32
+ #@brief - <To yalgaarGetChannelList as given length>
33
+ #@param <Length> : <length for how long uuid generating>
34
+ #DESCRIPTION:<To yalgaarGetChannelList as given length>
35
+ def yalgaarGetChannelList(uid,lamda1,lamda2)
36
+ if @@isConnected==true
37
+ if uidValidation(uid)
38
+ topic=@@clientKey+'/'+uid+'/'+uid+'$'+'0'+'$'+'channels'
39
+ #~ puts topic
40
+ @@client.subscribe(topic)
41
+ @@lChannelList=lamda1
42
+ else
43
+ errmesg=showErrCode(YALGAAR_108)
44
+ lamda2.call(errmesg)
45
+ end
46
+ else
47
+ return YALGAAR_NO_SERVER_CONNECTION
48
+ end
49
+ end
50
+ #yalgaarGetUserList(message);
51
+ #@brief - <To yalgaarGetUserList as given length>
52
+ #@param <Length> : <length for how long uuid generating>
53
+ #DESCRIPTION:<To yalgaarGetUserList as given length>
54
+ def yalgaarGetUserList(channel,lamda1,lamda2)
55
+ if @@isConnected==true
56
+ if channelValidation(channel)
57
+ topic=@@clientKey+'/'+@@uuid+'/'+channel+'$'+'0'+'$'+'users'
58
+ #~ puts topic
59
+ @@client.subscribe(topic)
60
+ @@lUserList=lamda1
61
+ else
62
+ errmesg=showErrCode(YALGAAR_108)
63
+ lamda2.call(errmesg)
64
+ end
65
+ else
66
+ return YALGAAR_NO_SERVER_CONNECTION
67
+ end
68
+ end
69
+
70
+ end
71
+
@@ -0,0 +1,277 @@
1
+ #@fileName <YalgaarConnect.rb>
2
+ #@brief - <Connect all varialbes and common methods>
3
+ #
4
+ #Revision Log:
5
+ # v1.0.1 : Aug 4, 2016 INITIAL OF PROGRAMMER - REVISION DETAIL_1 <- THIS IS THE LATEST REVISION
6
+ #Description:
7
+ #YalgaarInitModule contents methods and variables and enum..
8
+ #
9
+ #@bug Known Issues:
10
+ # 1. ISSUE NAME - NONE
11
+ # WORKAROUND - NONE
12
+ #@details Notes: NONE
13
+ #SLS MAKES NO REPRESENTATION, WARRANTY, OR CONDITION OF
14
+ #ANY KIND, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE OR IN
15
+ #ANY COMMUNICATION WITH YOU, INCLUDING, BUT NOT LIMITED TO,
16
+ #ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY
17
+ #QUALITY, FITNESS FOR ANY PARTICULAR PURPOSE,
18
+ #NONINFRINGEMENT, AND THEIR EQUIVALENTS.
19
+ #SLS Propritery and Confidential
20
+ #@copyright (C) 2016 SLS Corporation, All Rights Reserved.
21
+ #!/usr/bin/env ruby
22
+ $LOAD_PATH << '.'
23
+ require_relative 'YalgaarInitModule'
24
+ # Namespace module for YalgaarConnect default variables...
25
+ module YalgaarConnect
26
+ #~ include YalgaarApis
27
+ #~ include YalgaarInit
28
+ include MQTT
29
+ include YalgaarInit
30
+ include YalgaarApis
31
+ #yalgaarConnect(*args,lamda);
32
+ #@brief - <To yalgaarConnect as given length>
33
+ #@param <Length> : <length for how long uuid generating>
34
+ #DESCRIPTION:<To yalgaarConnect as given length>
35
+ #@bug Known Issues:
36
+ #1.<max 50 bytes yalgaarConnect using this method.
37
+
38
+ def yalgaarConnect(*args,lamda)
39
+ #~ puts "yalgaarConnect"
40
+ #~ puts lamda
41
+ @@lErrorConnectionCallback=lamda
42
+ if args[0]==nil
43
+ errmesg=showErrCode(YALGAAR_103)
44
+ @@lErrorConnectionCallback.call(errmesg)
45
+ return
46
+ end
47
+ if args[1] != 1 && args[1] != 0
48
+ errmesg=showErrCode(YALGAAR_150)
49
+ @@lErrorConnectionCallback.call(errmesg)
50
+ return
51
+ end
52
+ #~ puts args.size
53
+ case args.size
54
+ when TWOARGV
55
+ isEncrpt=0
56
+ @@clientKey=args[0]
57
+ @@isSecure=args[1]
58
+ @@uuid=generateUUID(3)
59
+ #~ puts @@uuid
60
+
61
+ if @@isSecure==0
62
+ @@client = MQTT::Client.new
63
+ @@client.keep_alive=@@keepalive
64
+ @@client.ack_timeout=@@connectTimeout
65
+ @@client.host = @@host
66
+ @@client.port = DEFAULT_PORT
67
+ @@client.client_id = @@clientKey+'/'+@@uuid
68
+ begin
69
+ @@client.connect()
70
+ rescue Exception => e
71
+ #~ pubACK(e.message)
72
+ #~ lamda.call(e.message)
73
+ #~ exit(0)
74
+ end
75
+ else
76
+ @@client = MQTT::Client.new
77
+ @@client.keep_alive=@@keepalive
78
+ @@client.ack_timeout=@@connectTimeout
79
+ @@client.host = @@host
80
+ @@client.port = DEFAULT_SSL_PORT
81
+ @@client.client_id = @@clientKey+'/'+@@uuid
82
+ @@client.ssl = true
83
+ @@client.cert_file = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
84
+ begin
85
+ @@client.connect()
86
+ rescue Exception => e
87
+ #~ lamda.call(e.message)
88
+ #~ pubACK(e.message)
89
+ #~ exit(0)
90
+ end
91
+ end
92
+
93
+ th = Thread.new do |client|
94
+ @@client.get do |topic,message|
95
+ messageParsing(topic,message,isEncrpt)
96
+ end
97
+ end
98
+ when THREEARGV
99
+ isEncrpt=0
100
+ @@clientKey=args[0]
101
+ @@isSecure=args[1]
102
+ @@uuid=args[2]
103
+ if @@uuid == 0
104
+ @@uuid=generateUUID(3)
105
+ end
106
+
107
+ if @@isSecure==0
108
+ @@client = MQTT::Client.new
109
+ @@client.keep_alive=@@keepalive
110
+ @@client.ack_timeout=@@connectTimeout
111
+ @@client.host = @@host
112
+ @@client.port = DEFAULT_PORT
113
+ @@client.client_id = @@clientKey+'/'+@@uuid
114
+ begin
115
+ ret =@@client.connect()
116
+ puts ret
117
+ rescue Exception => e
118
+ #~ lamda.call(e.message)
119
+ #~ pubACK(e.message)
120
+ #~ exit(0)
121
+ end
122
+ else
123
+ @@client = MQTT::Client.new
124
+ @@client.keep_alive=@@keepalive
125
+ @@client.ack_timeout=@@connectTimeout
126
+ @@client.host = @@host
127
+ @@client.port = DEFAULT_SSL_PORT
128
+ @@client.client_id = @@clientKey+'/'+@@uuid
129
+ @@client.ssl = true
130
+ @@client.cert_file = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
131
+ begin
132
+ ret =@@client.connect()
133
+ puts ret
134
+ rescue Exception => e
135
+ #~ lamda.call(e.message)
136
+ #~ pubACK(e.message)
137
+ #~ exit(0)
138
+ end
139
+ end
140
+
141
+ th = Thread.new do |client|
142
+ @@client.get do |topic,message|
143
+ #~ puts "#{topic}: #{message}"
144
+ messageParsing(topic,message,isEncrpt)
145
+ end
146
+ end
147
+ when FOURARGV
148
+ isEncrpt=1
149
+ @@clientKey=args[0]
150
+ @@isSecure=args[1]
151
+ @@uuid=generateUUID(3)
152
+ @@aesSecretKey=args[2]
153
+ if args[3]==YALGAR_AES_128
154
+ @@aesType='AES-128-ECB'
155
+ elsif args[3]==YALGAR_AES_192
156
+ @@aesType='AES-192-ECB'
157
+ elsif args[3]==YALGAR_AES_256
158
+ @@aesType='AES-256-ECB'
159
+ else
160
+ errmesg=showErrCode(YALGAAR_INVALID_AES_TYPE)
161
+ @@lErrorConnectionCallback.call(errmesg)
162
+ return
163
+ end
164
+
165
+ if @@isSecure==0
166
+ @@client = MQTT::Client.new
167
+ @@client.keep_alive=@@keepalive
168
+ @@client.ack_timeout=@@connectTimeout
169
+ @@client.host = @@host
170
+ @@client.port = DEFAULT_PORT
171
+ @@client.client_id = @@clientKey+'/'+@@uuid
172
+ begin
173
+ @@client.connect()
174
+ rescue Exception => e
175
+ #~ lamda.call(e.message)
176
+ #~ pubACK(e.message)
177
+ #~ exit(0)
178
+ end
179
+ else
180
+ @@client = MQTT::Client.new
181
+ @@client.keep_alive=@@keepalive
182
+ @@client.ack_timeout=@@connectTimeout
183
+ @@client.host = @@host
184
+ @@client.port = DEFAULT_SSL_PORT
185
+ @@client.client_id = @@clientKey+'/'+@@uuid
186
+ @@client.ssl = true
187
+ @@client.cert_file = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
188
+ begin
189
+ @@client.connect()
190
+ rescue Exception => e
191
+ #~ lamda.call(e.message)
192
+ #~ pubACK(e.message)
193
+ #~ exit(0)
194
+ end
195
+ end
196
+
197
+ th = Thread.new do |client|
198
+ @@client.get do |topic,message|
199
+ messageParsing(topic,message,isEncrpt)
200
+ end
201
+ end
202
+ when FIVEARGV
203
+ isEncrpt=1
204
+ @@clientKey=args[0]
205
+ @@isSecure=args[1]
206
+ @@uuid=args[2]
207
+ if @@uuid==0
208
+ @@uuid=generateUUID(3)
209
+ end
210
+ @@aesSecretKey=args[3]
211
+ if args[4]==YALGAR_AES_128
212
+ @@aesType='AES-128-ECB'
213
+ elsif args[4]==YALGAR_AES_192
214
+ @@aesType='AES-192-ECB'
215
+ elsif args[4]==YALGAR_AES_256
216
+ @@aesType='AES-256-ECB'
217
+ else
218
+ errmesg=showErrCode(YALGAAR_INVALID_AES_TYPE)
219
+ @@lErrorConnectionCallback.call(errmesg)
220
+ return
221
+ end
222
+
223
+ if @@isSecure==0
224
+ @@client = MQTT::Client.new
225
+ @@client.keep_alive=@@keepalive
226
+ @@client.ack_timeout=@@connectTimeout
227
+ @@client.host = @@host
228
+ @@client.port = DEFAULT_PORT
229
+ @@client.client_id = @@clientKey+'/'+@@uuid
230
+ begin
231
+ @@client.connect()
232
+ rescue Exception => e
233
+ #~ lamda.call(e.message)
234
+ #~ pubACK(e.message)
235
+ #~ exit(0)
236
+ end
237
+ else
238
+ @@client = MQTT::Client.new
239
+ @@client.keep_alive=@@keepalive
240
+ @@client.ack_timeout=@@connectTimeout
241
+ @@client.host = @@host
242
+ @@client.port = DEFAULT_SSL_PORT
243
+ @@client.client_id = @@clientKey+'/'+@@uuid
244
+ @@client.ssl = true
245
+ @@client.cert_file = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
246
+ begin
247
+ @@client.connect()
248
+ rescue Exception => e
249
+ #~ lamda.call(e.message)
250
+ #~ pubACK(e.message)
251
+ #~ exit(0)
252
+ end
253
+ end
254
+ th = Thread.new do |client|
255
+ @@client.get do |topic,message|
256
+ #puts "#{topic}: #{message}"
257
+ messageParsing(topic,message,isEncrpt)
258
+ end
259
+ end
260
+ else
261
+ puts 'Invalid Arguments'
262
+ end
263
+ end
264
+ def yalgaarDisconnect(lamda)
265
+ begin
266
+ ret =@@client.disconnect(true)
267
+ rescue Exception => e
268
+ #~ lamda.call(e.message)
269
+ #~ exit(0)
270
+ end
271
+ errmesg=showErrCode(YALGAAR_DISCONNECT_SUCCESS)
272
+ lamda.call(errmesg)
273
+ #~ lamda.call("Disconnect success")
274
+ end
275
+ end
276
+
277
+
@@ -0,0 +1,48 @@
1
+ #@fileName <YalgaarHistory.rb>
2
+ #@brief - <methods>
3
+ #
4
+ #Revision Log:
5
+ # v1.0.1 : Aug 4, 2016 INITIAL OF PROGRAMMER - REVISION DETAIL_1 <- THIS IS THE LATEST REVISION
6
+ #Description:
7
+ #YalgaarInitModule contents methods and variables and enum..
8
+ #
9
+ #@bug Known Issues:
10
+ # 1. ISSUE NAME - NONE
11
+ # WORKAROUND - NONE
12
+ #@details Notes: NONE
13
+ #SLS MAKES NO REPRESENTATION, WARRANTY, OR CONDITION OF
14
+ #ANY KIND, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE OR IN
15
+ #ANY COMMUNICATION WITH YOU, INCLUDING, BUT NOT LIMITED TO,
16
+ #ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY
17
+ #QUALITY, FITNESS FOR ANY PARTICULAR PURPOSE,
18
+ #NONINFRINGEMENT, AND THEIR EQUIVALENTS.
19
+ #SLS Propritery and Confidential
20
+ #@copyright (C) 2016 SLS Corporation, All Rights Reserved.
21
+
22
+ #~ require_relative 'YalgaarInitModule'
23
+ # Namespace module for YalgaarHistory default variables...
24
+ #!/usr/bin/env ruby
25
+ require_relative 'YalgaarInitModule'
26
+ module YalgaarHistory
27
+ include YalgaarInit
28
+ #~ include MQTT
29
+ #yalgaarHistory(channel,count,lamda1,lamda2);
30
+ #@brief - <To yalgaarHistory as given length>
31
+ #@param <Length> : <length for how long uuid generating>
32
+ #DESCRIPTION:<To yalgaarHistory as given length>
33
+ def yalgaarHistory(channel,count,lamda1,lamda2)
34
+ if @@isConnected==true
35
+ if channelValidation(channel)
36
+ topic=@@clientKey+'/'+@@uuid+'/'+channel+'$'+count+'$history'
37
+ #~ puts topic
38
+ @@client.subscribe(topic)
39
+ @@lHistoryCallback=lamda1
40
+ else
41
+ errmesg=showErrCode(YALGAAR_108)
42
+ lamda2.call(errmesg)
43
+ end
44
+ else
45
+ return YALGAAR_NO_SERVER_CONNECTION
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,333 @@
1
+
2
+ #@fileName <YalgaarInitModule.rb>
3
+ #@brief - <Initialize all varialbes and common methods>
4
+ #
5
+ #Revision Log:
6
+ # v1.0.1 : Aug 4, 2016 INITIAL OF PROGRAMMER - REVISION DETAIL_1 <- THIS IS THE LATEST REVISION
7
+ #Description:
8
+ #YalgaarInitModule contents methods and variables and enum..
9
+ #
10
+ #@bug Known Issues:
11
+ # 1. ISSUE NAME - NONE
12
+ # WORKAROUND - NONE
13
+ #@details Notes: NONE
14
+ #SLS MAKES NO REPRESENTATION, WARRANTY, OR CONDITION OF
15
+ #ANY KIND, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE OR IN
16
+ #ANY COMMUNICATION WITH YOU, INCLUDING, BUT NOT LIMITED TO,
17
+ #ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY
18
+ #QUALITY, FITNESS FOR ANY PARTICULAR PURPOSE,
19
+ #NONINFRINGEMENT, AND THEIR EQUIVALENTS.
20
+ #SLS Propritery and Confidential
21
+ #@copyright (C) 2016 SLS Corporation, All Rights Reserved.
22
+ #!/usr/bin/env ruby
23
+ require 'rubygems'
24
+ require 'openssl'
25
+ require 'base64'
26
+ require 'json'
27
+ require_relative 'mqtt'
28
+ # Namespace module for YalgaarInit default variables...
29
+ module YalgaarInit
30
+ include MQTT
31
+
32
+ #YalgaarConnectionENUM for connection methods
33
+ YALGAARAESTYPEENUM=
34
+ [
35
+ YALGAR_AES_128=128,
36
+ YALGAR_AES_192=192,
37
+ YALGAR_AES_256=256
38
+ ]
39
+ YalgaarConnectionENUM=
40
+ [
41
+ NoARGV=0x00,
42
+ ONEARGV=0x01,
43
+ TWOARGV=0x02,
44
+ THREEARGV=0x03,
45
+ FOURARGV=0x04,
46
+ FIVEARGV=0x05,
47
+ MAXARGV=0xFF
48
+ ]
49
+ YalgaarErrorCodeENUM=
50
+ [
51
+ YALGAAR_CONNECT_SUCCESS=0,
52
+ YALGAAR_DISCONNECT_SUCCESS=1,
53
+ YALGAAR_101=101,
54
+ YALGAAR_102=102,
55
+ YALGAAR_103=103,
56
+ YALGAAR_104=104,
57
+ YALGAAR_105=105,
58
+ YALGAAR_106=106,
59
+ YALGAAR_107=107,
60
+ YALGAAR_108=108,
61
+ YALGAAR_109=109,
62
+ YALGAAR_110=110,
63
+ YALGAAR_111=111,
64
+ YALGAAR_112=112,
65
+ YALGAAR_113=113,
66
+ YALGAAR_114=114,
67
+ YALGAAR_115=115,
68
+ YALGAAR_116=116,
69
+ YALGAAR_117=117,
70
+ YALGAAR_118=118,
71
+ YALGAAR_119=119,
72
+ YALGAAR_120=120,
73
+ YALGAAR_121=121,
74
+ YALGAAR_122=122,
75
+ YALGAAR_123=123,
76
+ YALGAAR_150=150,
77
+ YALGAAR_NO_SERVER_CONNECTION=151,
78
+ YALGAAR_INVALID_AES_TYPE=152,
79
+ YALGAAR_MAX=200
80
+ ]
81
+ #init(message);
82
+ #@brief - <To init as given length>
83
+ #@param <Length> : <length for how long uuid generating>
84
+ #DESCRIPTION:<To userListCallback as given length>
85
+ def init
86
+ #~ puts "In init"
87
+ @@isConnected=false
88
+ @@clientKey=nil
89
+ @@isSecure=nil
90
+ @@uuid=nil
91
+ @@aesSecretKey=nil
92
+ @@aesType=nil
93
+ @@keepalive=30
94
+ @@connectTimeout=60
95
+ @@alive_time=200
96
+ @@client=nil
97
+ @@lErrorConnectionCallback=nil
98
+ @@lEroorCallback=nil
99
+ @@lSubCallback=nil
100
+ @@lPresenceCallback=nil
101
+ @@lHistoryCallback=nil
102
+ @@lChannelList=nil
103
+ @@lUserList=nil
104
+ @@host='192.168.60.6'
105
+ end
106
+ end
107
+
108
+ module YalgaarApis
109
+ include MQTT
110
+ include YalgaarInit
111
+ #pubACK(channel);
112
+ #@brief - <To channelValidation>
113
+ #@param <channel> : <length for how long uuid generating>
114
+ #DESCRIPTION:<To channelValidation and callback
115
+ def pubACK(errorCode)
116
+ #~ puts "in puback"
117
+ #~ puts errorCode
118
+ if errorCode.is_a?(Array)
119
+ #~ puts errorCode[0]
120
+ #~ if errorCode[0] != 0
121
+ errmesg=showErrCode(errorCode[0])
122
+ @@lErrorConnectionCallback.call(errmesg)
123
+ #~ puts errorCode
124
+ #~ end
125
+ else
126
+ #~ puts errorCode
127
+ #~ if errorCode != 0
128
+ errmesg=showErrCode(errorCode)
129
+ @@lErrorConnectionCallback.call(errmesg)
130
+ #~ puts errorCode
131
+ #~ end
132
+ end
133
+ end
134
+
135
+ #subACK(channel);
136
+ #@brief - <To channelValidation>
137
+ #@param <channel> : <length for how long uuid generating>
138
+ #DESCRIPTION:<To channelValidation and callback
139
+ def subACK(errorCode)
140
+ if errorCode[0] != 0
141
+ errmesg=showErrCode(errorCode[0])
142
+ @@lEroorCallback.call(errmesg)
143
+ end
144
+ end
145
+ #generateUUID(length);
146
+ #@brief - <To Generate uuid as given length>
147
+ #@param <Length> : <length for how long uuid generating>
148
+ #DESCRIPTION:<To Generate UUID as given length>
149
+ #@bug Known Issues:
150
+ #1.<max 50 bytes UUID generating using this method.
151
+ def generateUUID(len)
152
+ if len>50
153
+ len=10
154
+ end
155
+ character_set = ["A".."Z", "a".."z", "0".."9",'_','-','@']
156
+ chars = character_set.map{|x| x.is_a?(Range) ? x.to_a : x }.flatten
157
+ Array.new(len){ chars.sample }.join
158
+ end
159
+
160
+ #messageParsing(length);
161
+ #@brief - <To messageParsing>
162
+ #@param <topic,message,isEncrpt> : <length for how long uuid generating>
163
+ #DESCRIPTION:<To messageParsing and callback
164
+ def messageParsing(topic,message,isEncrpt)
165
+ begin
166
+ parse_topic=topic.split("$")[2]
167
+ #puts "ParseTopic is :#{ parse_topic}"
168
+ if parse_topic == "channels"
169
+ @@lChannelList.call(message)
170
+ elsif parse_topic == "users"
171
+ @@lUserList.call(message)
172
+ elsif parse_topic == "history"
173
+ @@lHistoryCallback.call(message)
174
+ else
175
+ messageAck = JSON.parse(message)
176
+ # puts "ParseTopic is :#{ messageAck}"
177
+ if messageAck["uuid"] != @@uuid && messageAck["isPresence"] == true
178
+ @@lPresenceCallback.call(message)
179
+ elsif messageAck["uuid"] == @@uuid && messageAck["isPresence"] == true
180
+ #@@lSubCallback.call(message)
181
+ else
182
+ if isEncrpt==1
183
+ cyperText=decryption(message)
184
+ #~ puts cyperText
185
+ @@lSubCallback.call(cyperText)
186
+ else
187
+ @@lSubCallback.call(message)
188
+ end
189
+ end
190
+ end
191
+ rescue JSON::ParserError
192
+ if isEncrpt==1
193
+ cyperText=decryption(message)
194
+ #~ puts cyperText
195
+ @@lSubCallback.call(cyperText)
196
+ else
197
+ @@lSubCallback.call(message)
198
+ end
199
+ end
200
+ end
201
+
202
+ #channelValidation(channel);
203
+ #@brief - <To channelValidation>
204
+ #@param <channel> : <length for how long uuid generating>
205
+ #DESCRIPTION:<To channelValidation and callback
206
+ def channelValidation(channel)
207
+ validString=/^([A-Za-z0-9_@-])*$/
208
+ temp=validString.match(channel)
209
+ #~ #puts temp
210
+ return temp
211
+ #~ return 1
212
+ end
213
+
214
+ #uidValidation(channel);
215
+ #@brief - <To uidValidation>
216
+ #@param <channel> : <length for how long uuid generating>
217
+ #DESCRIPTION:<To uidValidation and callback
218
+ def uidValidation(uid)
219
+ if uid.length < 50
220
+ validString=/^([A-Za-z0-9_@-])*$/
221
+ temp=validString.match(uid)
222
+ # puts temp
223
+ else
224
+ temp=0
225
+ end
226
+ return temp
227
+ end
228
+
229
+ #encryption(channel);
230
+ #@brief - <To encryption>
231
+ #@param <channel> : <length for how long uuid generating>
232
+ #DESCRIPTION:<To encryption and callback
233
+ def encryption(msg)
234
+ begin
235
+ cipher = OpenSSL::Cipher.new(@@aesType)
236
+ cipher.encrypt()
237
+ cipher.key = @@aesSecretKey
238
+ crypt = cipher.update(msg) + cipher.final()
239
+ crypt_string = (Base64.encode64(crypt))
240
+ return crypt_string
241
+ rescue Exception => exc
242
+ puts ("Message for the encryption log file for message #{msg} = #{exc.message}")
243
+ end
244
+ end
245
+
246
+ #decryption(channel);
247
+ #@brief - <To decryption>
248
+ #@param <channel> : <length for how long uuid generating>
249
+ #DESCRIPTION:<To decryption and callback
250
+ def decryption(msg)
251
+ begin
252
+ cipher = OpenSSL::Cipher.new(@@aesType)
253
+ cipher.decrypt()
254
+ cipher.key = @@aesSecretKey
255
+ tempkey = Base64.decode64(msg)
256
+ crypt = cipher.update(tempkey)
257
+ crypt << cipher.final()
258
+ return crypt
259
+ rescue Exception => exc
260
+ puts "Message for the decryption log file for message #{msg} = #{exc.message}"
261
+ end
262
+ end
263
+ #showErrCode(code);
264
+ #@brief - <To decryption>
265
+ #@param <channel> : <length for how long uuid generating>
266
+ #DESCRIPTION:<To decryption and callback
267
+ def showErrCode(code)
268
+ case code
269
+ when YALGAAR_CONNECT_SUCCESS
270
+ @@isConnected=true
271
+ errMessage="Successfully connected with server"
272
+ when YALGAAR_DISCONNECT_SUCCESS
273
+ @@isConnected=false
274
+ errMessage="Successfully Disconnected with server"
275
+ when YALGAAR_101
276
+ errMessage="ClientId should not be null."
277
+ when YALGAAR_102
278
+ errMessage="Invalid ClientId."
279
+ when YALGAAR_103
280
+ errMessage="Invalid ClientKey.ClientKey is not registered."
281
+ when YALGAAR_104
282
+ errMessage="Invalid Uuid.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50."
283
+ when YALGAAR_105
284
+ errMessage="ClientKey is not active."
285
+ when YALGAAR_106
286
+ errMessage="SSL is not enable."
287
+ when YALGAAR_107
288
+ errMessage="The maximum connection limit has been reached."
289
+ when YALGAAR_108
290
+ errMessage="Invalid subscribe channel."
291
+ when YALGAAR_109
292
+ errMessage="Invalid subscribe channel.ClientKey does not match."
293
+ when YALGAAR_110
294
+ errMessage="Multiple subscribe channels are not allowed. Multiplexing is not enable."
295
+ when YALGAAR_111
296
+ errMessage="Invalid subscribe channel.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50."
297
+ when YALGAAR_112
298
+ errMessage="Storage is not enable."
299
+ when YALGAAR_113
300
+ errMessage="Presence is not enable."
301
+ when YALGAAR_114
302
+ errMessage="Entered history channel has not been subscribed."
303
+ when YALGAAR_115
304
+ errMessage="Message can not be null."
305
+ when YALGAAR_116
306
+ errMessage="Invalid publish channel."
307
+ when YALGAAR_117
308
+ errMessage="Invalid publish channel.ClientKey does not match."
309
+ when YALGAAR_118
310
+ errMessage="Message count exceeds maximum limit."
311
+ when YALGAAR_119
312
+ errMessage="Message size exceeds maximum limit."
313
+ when YALGAAR_120
314
+ errMessage="Invalid publish channel.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50."
315
+ when YALGAAR_121
316
+ errMessage="Invalid UnSubscribe channel."
317
+ when YALGAAR_122
318
+ errMessage="Invalid UnSubscribe channel.ClientKey does not match."
319
+ when YALGAAR_123
320
+ errMessage="Invalid UnSubscribe channel.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50."
321
+ when YALGAAR_150
322
+ errMessage="Invalid IsSecure Flag."
323
+ when YALGAAR_NO_SERVER_CONNECTION
324
+ errMessage="No server connection found."
325
+ when YALGAAR_INVALID_AES_TYPE
326
+ errMessage="Invalid AES Type."
327
+ else
328
+ errMessage="Success"
329
+ end
330
+ errMessage
331
+ end
332
+ end
333
+