Percent escaping OUI, serial number, product class in device ID string

This commit is contained in:
Zaid Abdulla committed 2013-02-08 19:19:48 +03:00
1 parent 4878d4a312
commit 84418818f8
1 file changed
+11 -2
+11 -2
View File
@@ -23,11 +23,20 @@ exports.arrayToHash = (arr) ->
exports.getDeviceId = (deviceIdStruct) -> exports.getDeviceId = (deviceIdStruct) ->
# Percent escaping function. Escapes everything except alphanumerics and underscore
esc = (str) ->
str.replace(/[^A-Za-z0-9_]/g, (chr) ->
buf = new require('buffer').Buffer(chr)
rep = ''
rep += "%#{b.toString(16).toUpperCase()}" for b in buf
return rep
)
# Guaranteeing globally unique id as defined in TR-069 # Guaranteeing globally unique id as defined in TR-069
if deviceIdStruct['ProductClass'] if deviceIdStruct['ProductClass']
return "#{deviceIdStruct['OUI']}-#{deviceIdStruct['ProductClass']}-#{deviceIdStruct['SerialNumber']}" return "#{esc(deviceIdStruct['OUI'])}-#{esc(deviceIdStruct['ProductClass'])}-#{esc(deviceIdStruct['SerialNumber'])}"
return "#{deviceIdStruct['OUI']}-#{deviceIdStruct['SerialNumber']}" return "#{esc(deviceIdStruct['OUI'])}-#{esc(deviceIdStruct['SerialNumber'])}"
exports.extend = (obj, mixin) -> exports.extend = (obj, mixin) ->