From 88c506299c80a170ec3182a3abbd3d7c6639b434 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 30 Jan 2013 00:40:13 +0300 Subject: [PATCH] Allow spaces in device ID. Parse xsd:int values. --- api.coffee | 6 +++--- common.coffee | 4 ++-- tr-069.coffee | 15 ++++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api.coffee b/api.coffee index 2bda77d..613a448 100644 --- a/api.coffee +++ b/api.coffee @@ -6,9 +6,9 @@ db = require './db' mongodb = require 'mongodb' # regular expression objects -TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_]+)\/tasks\/?$/ -TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_]+)\/tags\/([a-zA-Z0-9\-\_]+)\/?$/ -PRESETS_REGEX = /^\/presets\/([a-zA-Z0-9\-\_]+)\/?$/ +TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tasks\/?$/ +TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tags\/([a-zA-Z0-9\-\_\%]+)\/?$/ +PRESETS_REGEX = /^\/presets\/([a-zA-Z0-9\-\_\%]+)\/?$/ connectionRequest = (deviceId, callback) -> db.devicesCollection.findOne({_id : deviceId}, {'InternetGatewayDevice.ManagementServer.ConnectionRequestURL._value' : 1}, (err, device)-> diff --git a/common.coffee b/common.coffee index b81f8c5..e670d59 100644 --- a/common.coffee +++ b/common.coffee @@ -25,9 +25,9 @@ exports.arrayToHash = (arr) -> 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 "#{deviceIdStruct['OUI']}-#{deviceIdStruct['ProductClass']}-#{deviceIdStruct['SerialNumber']}" - return "#{escape(deviceIdStruct['OUI'])}-#{escape(deviceIdStruct['SerialNumber'])}" + return "#{deviceIdStruct['OUI']}-#{deviceIdStruct['SerialNumber']}" exports.extend = (obj, mixin) -> diff --git a/tr-069.coffee b/tr-069.coffee index d9d022b..94ae9b5 100644 --- a/tr-069.coffee +++ b/tr-069.coffee @@ -46,11 +46,16 @@ parameterValueList = (xml) -> valueType = e.get('Value').attr('type').value().trim() name = e.get('Name').text().trim() value = e.get('Value').text().trim() - switch valueType - when 'xsd:boolean' - value = Boolean(JSON.parse(value)) - when 'xsd:unsignedInt' - value = JSON.parse(value) + try + switch valueType + when 'xsd:boolean' + value = Boolean(JSON.parse(value)) + when 'xsd:unsignedInt' + value = JSON.parse(value) + when 'xsd:int' + value = JSON.parse(value) + catch err + value = null valueList.push([name, value]) return valueList