From: Pawel Wasowski Date: Wed, 12 Aug 2020 10:47:26 +0000 (+0200) Subject: [Bluetooth] Add validators for BluetoothGATTServer*InitData objects X-Git-Tag: submit/tizen/20200831.125703~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F240708%2F15;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Bluetooth] Add validators for BluetoothGATTServer*InitData objects This commit adds ValidateBluetoothGATT*Init() functions, that validate BluetoothGATT{Service, Characteristic, Descriptor}Init objects and fill optional fields with default values. Verification: webapi-plugins build succeeds. Instantiating tizen.bluetooth in Chrome Dev Tools succeeds. The code will be further verified together with the code that relies on it. Verification results will be reported in the next commits. Change-Id: I1fc2017a8c970bd24a3cc3ef0a0c85ca7faf7569 Signed-off-by: Pawel Wasowski --- diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js index fa28ef2a..eed468ac 100755 --- a/src/bluetooth/bluetooth_api.js +++ b/src/bluetooth/bluetooth_api.js @@ -1619,6 +1619,7 @@ var BluetoothGATTService = function(data, address) { var serviceUuid_ = data.serviceUuid; //address_ is needed to control if device is still connected var address_ = address || data.address; + function servicesGetter() { var services = []; var result = native.callSync('BluetoothGATTClientServiceGetServices', { @@ -1685,9 +1686,54 @@ function NextGattServerEntityID() { return ++CurrentGATTServerEntityId; } +function IsUuidValid(uuid) { + return ( + BluetoothManager_UUIDIsValid16Bit(uuid) || + BluetoothManager_UUIDIsValid32Bit(uuid) || + BluetoothManager_UUIDIsValid128Bit(uuid) + ); +} + +var ValidateBluetoothGATTServerServiceInit = function(initData) { + initData = AV.validateArgs( + [ + initData['serviceUuid'], + initData['isPrimary'] || true, + initData['includedServices'] || [], + initData['characteristics'] || [] + ], + [ + { + name: 'serviceUuid', + type: AV.Types.STRING, + validator: IsUuidValid + }, + { + name: 'isPrimary', + type: AV.Types.BOOLEAN + }, + { + name: 'includedServices', + type: AV.Types.ARRAY + }, + { + name: 'characteristics', + type: AV.Types.ARRAY + } + ] + ); + + // "uuid" field is used to construct BluetoothGATTService, but it's not a part + // of BluetoothGATTServerServiceInit dictionary. + // In case of BluetoothGATTServerServices, its value is always the same as + // serviceUuid's. + initData.uuid = initData.serviceUuid; + return initData; +}; + //class BluetoothGATTServerService /////////////////////////// var BluetoothGATTServerService = function(data) { - // TODO: validate data and set default values + data = ValidateBluetoothGATTServerServiceInit(data); BluetoothGATTService.call(this, data, null); @@ -1964,9 +2010,111 @@ var BluetoothGATTCharacteristic = function(data, address) { }; }; +var ValidateBluetoothGATTServerCharacteristicInit = function(initData) { + return AV.validateArgs( + [ + initData['uuid'], + initData['descriptors'] || [], + initData['isBroadcast'] || false, + initData['hasExtendedProperties'] || false, + initData['isNotify'] || false, + initData['isIndication'] || false, + initData['isReadable'] || false, + initData['isSignedWrite'] || false, + initData['isWritable'] || false, + initData['isWriteNoResponse'] || false, + initData['readPermission'] || false, + initData['writePermission'] || false, + initData['encryptedReadPermission'] || false, + initData['encryptedWritePermission'] || false, + initData['encryptedSignedReadPermission'] || false, + initData['encryptedSignedWritePermission'] || false, + initData['readValueRequestCallback'] || null, + initData['writeValueRequestCallback'] || null + ], + [ + { + name: 'uuid', + type: AV.Types.STRING, + validator: IsUuidValid + }, + { + name: 'descriptors', + type: AV.Types.ARRAY + }, + { + name: 'isBroadcast', + type: AV.Types.BOOLEAN + }, + { + name: 'hasExtendedProperties', + type: AV.Types.BOOLEAN + }, + { + name: 'isNotify', + type: AV.Types.BOOLEAN + }, + { + name: 'isIndication', + type: AV.Types.BOOLEAN + }, + { + name: 'isReadable', + type: AV.Types.BOOLEAN + }, + { + name: 'isSignedWrite', + type: AV.Types.BOOLEAN + }, + { + name: 'isWritable', + type: AV.Types.BOOLEAN + }, + { + name: 'isWriteNoResponse', + type: AV.Types.BOOLEAN + }, + { + name: 'readPermission', + type: AV.Types.BOOLEAN + }, + { + name: 'writePermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedReadPermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedWritePermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedSignedReadPermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedSignedWritePermission', + type: AV.Types.BOOLEAN + }, + { + name: 'readValueRequestCallback', + type: AV.Types.FUNCTION, + nullable: true + }, + { + name: 'writeValueRequestCallback', + type: AV.Types.FUNCTION, + nullable: true + } + ] + ); +}; + //class BluetoothGATTServerCharacteristic /////////////////////////// var BluetoothGATTServerCharacteristic = function(data) { - // TODO: validate data and set default values + data = ValidateBluetoothGATTServerCharacteristicInit(data); BluetoothGATTCharacteristic.call(this, data, null); @@ -2262,15 +2410,72 @@ var BluetoothGATTDescriptor = function(data, address) { uuid: { enumerable: true, get: function() { - return uuid_; + return uuid_; }, - set: function() {}, + set: function() {} } }); }; +var ValidateBluetoothGATTServerDescriptorInit = function(initData) { + return AV.validateArgs( + [ + initData['uuid'], + initData['readPermission'] || false, + initData['writePermission'] || false, + initData['encryptedReadPermission'] || false, + initData['encryptedWritePermission'] || false, + initData['encryptedSignedReadPermission'] || false, + initData['encryptedSignedWritePermission'] || false, + initData['readValueRequestCallback'] || null, + initData['writeValueRequestCallback'] || null + ], + [ + { + name: 'uuid', + type: AV.Types.STRING, + validator: IsUuidValid + }, + { + name: 'readPermission', + type: AV.Types.BOOLEAN + }, + { + name: 'writePermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedReadPermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedWritePermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedSignedReadPermission', + type: AV.Types.BOOLEAN + }, + { + name: 'encryptedSignedWritePermission', + type: AV.Types.BOOLEAN + }, + { + name: 'readValueRequestCallback', + type: AV.Types.FUNCTION, + nullable: true + }, + { + name: 'writeValueRequestCallback', + type: AV.Types.FUNCTION, + nullable: true + } + ] + ); +}; + var BluetoothGATTServerDescriptor = function(data, address) { - // TODO: validate data and set default values + data = ValidateBluetoothGATTServerDescriptorInit(data); BluetoothGATTDescriptor.call(this, data, null);