module YalgaarApis
Public Instance Methods
channelValidation(channel); @brief - <To channelValidation>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To channelValidation and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 206 def channelValidation(channel) validString=/^([A-Za-z0-9_@-])*$/ temp=validString.match(channel) #~ #puts temp return temp #~ return 1 end
decryption(channel); @brief - <To decryption>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To decryption and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 250 def decryption(msg) begin cipher = OpenSSL::Cipher.new(@@aesType) cipher.decrypt() cipher.key = @@aesSecretKey tempkey = Base64.decode64(msg) crypt = cipher.update(tempkey) crypt << cipher.final() return crypt rescue Exception => exc puts "Message for the decryption log file for message #{msg} = #{exc.message}" end end
encryption(channel); @brief - <To encryption>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To encryption and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 233 def encryption(msg) begin cipher = OpenSSL::Cipher.new(@@aesType) cipher.encrypt() cipher.key = @@aesSecretKey crypt = cipher.update(msg) + cipher.final() crypt_string = (Base64.encode64(crypt)) return crypt_string rescue Exception => exc puts ("Message for the encryption log file for message #{msg} = #{exc.message}") end end
generateUUID(length); @brief - <To Generate uuid as given length>
@param <Length> : <length for how long uuid generating> DESCRIPTION:<To Generate UUID as given length> @bug Known Issues: 1.<max 50 bytes UUID generating using this method.
# File lib/mqttbridge/YalgaarInitModule.rb, line 151 def generateUUID(len) if len>50 len=10 end character_set = ["A".."Z", "a".."z", "0".."9",'_','-','@'] chars = character_set.map{|x| x.is_a?(Range) ? x.to_a : x }.flatten Array.new(len){ chars.sample }.join end
messageParsing(length); @brief - <To messageParsing>
@param <topic,message,isEncrpt> : <length for how long uuid generating> DESCRIPTION:<To messageParsing and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 164 def messageParsing(topic,message,isEncrpt) begin parse_topic=topic.split("$")[2] #puts "ParseTopic is :#{ parse_topic}" if parse_topic == "channels" @@lChannelList.call(message) elsif parse_topic == "users" @@lUserList.call(message) elsif parse_topic == "history" @@lHistoryCallback.call(message) else messageAck = JSON.parse(message) # puts "ParseTopic is :#{ messageAck}" if messageAck["uuid"] != @@uuid && messageAck["isPresence"] == true @@lPresenceCallback.call(message) elsif messageAck["uuid"] == @@uuid && messageAck["isPresence"] == true #@@lSubCallback.call(message) else if isEncrpt==1 cyperText=decryption(message) #~ puts cyperText @@lSubCallback.call(cyperText) else @@lSubCallback.call(message) end end end rescue JSON::ParserError if isEncrpt==1 cyperText=decryption(message) #~ puts cyperText @@lSubCallback.call(cyperText) else @@lSubCallback.call(message) end end end
pubACK(channel); @brief - <To channelValidation>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To channelValidation and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 115 def pubACK(errorCode) #~ puts "in puback" #~ puts errorCode if errorCode.is_a?(Array) #~ puts errorCode[0] #~ if errorCode[0] != 0 errmesg=showErrCode(errorCode[0]) @@lErrorConnectionCallback.call(errmesg) #~ puts errorCode #~ end else #~ puts errorCode #~ if errorCode != 0 errmesg=showErrCode(errorCode) @@lErrorConnectionCallback.call(errmesg) #~ puts errorCode #~ end end end
showErrCode(code); @brief - <To decryption>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To decryption and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 267 def showErrCode(code) case code when YALGAAR_CONNECT_SUCCESS @@isConnected=true errMessage="Successfully connected with server" when YALGAAR_DISCONNECT_SUCCESS @@isConnected=false errMessage="Successfully Disconnected with server" when YALGAAR_101 errMessage="ClientId should not be null." when YALGAAR_102 errMessage="Invalid ClientId." when YALGAAR_103 errMessage="Invalid ClientKey.ClientKey is not registered." when YALGAAR_104 errMessage="Invalid Uuid.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50." when YALGAAR_105 errMessage="ClientKey is not active." when YALGAAR_106 errMessage="SSL is not enable." when YALGAAR_107 errMessage="The maximum connection limit has been reached." when YALGAAR_108 errMessage="Invalid subscribe channel." when YALGAAR_109 errMessage="Invalid subscribe channel.ClientKey does not match." when YALGAAR_110 errMessage="Multiple subscribe channels are not allowed. Multiplexing is not enable." when YALGAAR_111 errMessage="Invalid subscribe channel.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50." when YALGAAR_112 errMessage="Storage is not enable." when YALGAAR_113 errMessage="Presence is not enable." when YALGAAR_114 errMessage="Entered history channel has not been subscribed." when YALGAAR_115 errMessage="Message can not be null." when YALGAAR_116 errMessage="Invalid publish channel." when YALGAAR_117 errMessage="Invalid publish channel.ClientKey does not match." when YALGAAR_118 errMessage="Message count exceeds maximum limit." when YALGAAR_119 errMessage="Message size exceeds maximum limit." when YALGAAR_120 errMessage="Invalid publish channel.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50." when YALGAAR_121 errMessage="Invalid UnSubscribe channel." when YALGAAR_122 errMessage="Invalid UnSubscribe channel.ClientKey does not match." when YALGAAR_123 errMessage="Invalid UnSubscribe channel.Only alpha numeric,hyphens,@,underscore allowed and maximum length must be 50." when YALGAAR_150 errMessage="Invalid IsSecure Flag." when YALGAAR_NO_SERVER_CONNECTION errMessage="No server connection found." when YALGAAR_INVALID_AES_TYPE errMessage="Invalid AES Type." else errMessage="Success" end errMessage end
subACK(channel); @brief - <To channelValidation>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To channelValidation and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 139 def subACK(errorCode) if errorCode[0] != 0 errmesg=showErrCode(errorCode[0]) @@lEroorCallback.call(errmesg) end end
uidValidation(channel); @brief - <To uidValidation>
@param <channel> : <length for how long uuid generating> DESCRIPTION:<To uidValidation and callback
# File lib/mqttbridge/YalgaarInitModule.rb, line 218 def uidValidation(uid) if uid.length < 50 validString=/^([A-Za-z0-9_@-])*$/ temp=validString.match(uid) # puts temp else temp=0 end return temp end