From 52967d018c41c8325322cfd5447643c15f8574b7 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Sun, 21 Oct 2012 11:24:47 +0300 Subject: [PATCH] Better implementation for generating device id --- acs.coffee | 4 ++-- common.coffee | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/acs.coffee b/acs.coffee index 679593a..4c85dd8 100644 --- a/acs.coffee +++ b/acs.coffee @@ -105,14 +105,14 @@ else if reqParams.inform resParams.inform = true cookies.ID = sessionId = reqParams.sessionId - cookies.DeviceId = deviceId = reqParams.deviceId.SerialNumber + cookies.DeviceId = deviceId = common.getDeviceId(reqParams.deviceId) util.log("#{deviceId}: inform (#{reqParams.eventCodes}); retry count #{reqParams.retryCount}") devicesCollection.count({'_id' : deviceId}, (err, count) -> if not count util.log("#{deviceId}: new device detected") task = {device : deviceId, name : 'init', timestamp : mongo.Timestamp(), status: 0} tasksCollection.save(task, (err) -> - util.log("#{deviceId}: Added init task for #{task._id}") + util.log("#{deviceId}: Added init task #{task._id}") ) devicesCollection.update({'_id' : deviceId}, {'$set' : common.arrayToHash(reqParams.informParameterValues)}, {upsert: true, safe:true}, (err, modified) -> diff --git a/common.coffee b/common.coffee index 5b6ab79..093d3b5 100644 --- a/common.coffee +++ b/common.coffee @@ -1,8 +1,18 @@ exports.endsWith = (str, suffix) -> str.indexOf(suffix, str.length - suffix.length) isnt -1 + exports.arrayToHash = (arr) -> hash = {} for i in arr hash[i[0]] = i[1] return hash + + +exports.getDeviceId = (deviceIdStruct) -> + # Guaranteeing globally unique id as defined in TR-069 + if deviceIdStruct['ProductClass'] + return "#{escape(deviceIdStruct['OUI'])}-#{escape(deviceIdStruct['ProductClass'])}-#{escape(deviceIdStruct['SerialNumber'])}" + + return "#{escape(deviceIdStruct['OUI'])}-#{escape(deviceIdStruct['SerialNumber'])}" +