From 2a3cbad2b38af2eae0d9651d6ad60ac4fcd18bf2 Mon Sep 17 00:00:00 2001 From: Habib Virji Date: Mon, 7 Dec 2015 14:10:13 +0000 Subject: [PATCH] Change DEVICE payload in correct format. Removes enclosing array, href and rep from the device payload. It changes structure from [{ href: "", rep: { device payload } }] to { device payload } Change-Id: I374d3c1e6dca24a0ae97f56ac0c5e40d3cbf09e0 Signed-off-by: Habib Virji Reviewed-on: https://gerrit.iotivity.org/gerrit/4435 Tested-by: jenkins-iotivity --- resource/csdk/stack/include/ocpayload.h | 2 +- resource/csdk/stack/include/octypes.h | 1 - resource/csdk/stack/include/payload_logging.h | 1 - resource/csdk/stack/src/ocpayload.c | 9 +-- resource/csdk/stack/src/ocpayloadconvert.c | 61 ++++++------------- resource/csdk/stack/src/ocpayloadparse.c | 69 +++++++++------------- resource/csdk/stack/src/ocresource.c | 3 +- resource/src/OCRepresentation.cpp | 1 - .../unittests/OCRepresentationEncodingTest.cpp | 8 +-- 9 files changed, 50 insertions(+), 105 deletions(-) diff --git a/resource/csdk/stack/include/ocpayload.h b/resource/csdk/stack/include/ocpayload.h index bc6ccce..b42d61f 100755 --- a/resource/csdk/stack/include/ocpayload.h +++ b/resource/csdk/stack/include/ocpayload.h @@ -208,7 +208,7 @@ OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, si void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload); // Device Payload -OCDevicePayload* OCDevicePayloadCreate(const char* uri, const uint8_t* sid, const char* dname, +OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname, const char* specVer, const char* dmVer); void OCDevicePayloadDestroy(OCDevicePayload* payload); diff --git a/resource/csdk/stack/include/octypes.h b/resource/csdk/stack/include/octypes.h index 45beceb..2134186 100644 --- a/resource/csdk/stack/include/octypes.h +++ b/resource/csdk/stack/include/octypes.h @@ -1142,7 +1142,6 @@ typedef struct typedef struct { OCPayload base; - char* uri; uint8_t* sid; char* deviceName; char* specVersion; diff --git a/resource/csdk/stack/include/payload_logging.h b/resource/csdk/stack/include/payload_logging.h index bfbfbde..4531fdc 100644 --- a/resource/csdk/stack/include/payload_logging.h +++ b/resource/csdk/stack/include/payload_logging.h @@ -206,7 +206,6 @@ static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* pay static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload) { OC_LOG(level, PL_TAG, "Payload Type: Device"); - OC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri); OC_LOG(level, PL_TAG, "\tSID:"); OC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE); OC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName); diff --git a/resource/csdk/stack/src/ocpayload.c b/resource/csdk/stack/src/ocpayload.c index 32c698e..96c1d5f 100755 --- a/resource/csdk/stack/src/ocpayload.c +++ b/resource/csdk/stack/src/ocpayload.c @@ -1592,7 +1592,7 @@ void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload) OICFree(payload); } -OCDevicePayload* OCDevicePayloadCreate(const char* uri, const uint8_t* sid, const char* dname, +OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname, const char* specVer, const char* dmVer) { @@ -1605,12 +1605,6 @@ OCDevicePayload* OCDevicePayloadCreate(const char* uri, const uint8_t* sid, cons payload->base.type = PAYLOAD_TYPE_DEVICE; - payload->uri = OICStrdup(uri); - if(uri && !payload->uri) - { - goto exit; - } - if(sid) { payload->sid = (uint8_t*)OICMalloc(UUID_SIZE); @@ -1653,7 +1647,6 @@ void OCDevicePayloadDestroy(OCDevicePayload* payload) return; } - OICFree(payload->uri); OICFree(payload->sid); OICFree(payload->deviceName); OICFree(payload->specVersion); diff --git a/resource/csdk/stack/src/ocpayloadconvert.c b/resource/csdk/stack/src/ocpayloadconvert.c index c6df806..6efe2c3 100644 --- a/resource/csdk/stack/src/ocpayloadconvert.c +++ b/resource/csdk/stack/src/ocpayloadconvert.c @@ -407,53 +407,30 @@ static int64_t OCConvertDevicePayload(OCDevicePayload* payload, uint8_t* outPayl int64_t err = 0; cbor_encoder_init(&encoder, outPayload, *size, 0); - CborEncoder rootArray; - err = err | cbor_encoder_create_array(&encoder, &rootArray, 1); - - { - CborEncoder map; - err = err | cbor_encoder_create_map(&rootArray, &map, CborIndefiniteLength); - - // uri - err = err | ConditionalAddTextStringToMap(&map, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1, - payload->uri); - - // Rep Map - { - CborEncoder repMap; - err = err | cbor_encode_text_string(&map, OC_RSRVD_REPRESENTATION, - sizeof(OC_RSRVD_REPRESENTATION) - 1); - err = err | cbor_encoder_create_map(&map, &repMap, CborIndefiniteLength); - - // Device ID - err = err | cbor_encode_text_string(&repMap, OC_RSRVD_DEVICE_ID, - sizeof(OC_RSRVD_DEVICE_ID) - 1); - err = err | cbor_encode_byte_string(&repMap, payload->sid, UUID_SIZE); - - // Device Name - err = err | ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DEVICE_NAME, - sizeof(OC_RSRVD_DEVICE_NAME) - 1, - payload->deviceName); + CborEncoder repMap; + err = err | cbor_encoder_create_map(&encoder, &repMap, CborIndefiniteLength); - // Device Spec Version - err = err | ConditionalAddTextStringToMap(&repMap, OC_RSRVD_SPEC_VERSION, - sizeof(OC_RSRVD_SPEC_VERSION) - 1, - payload->specVersion); + // Device ID + err = err | cbor_encode_text_string(&repMap, OC_RSRVD_DEVICE_ID, + sizeof(OC_RSRVD_DEVICE_ID) - 1); + err = err | cbor_encode_byte_string(&repMap, payload->sid, UUID_SIZE); - // Device data Model Version - err = err | ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DATA_MODEL_VERSION, - sizeof(OC_RSRVD_DATA_MODEL_VERSION) - 1, - payload->dataModelVersion); + // Device Name + err = err | ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DEVICE_NAME, + sizeof(OC_RSRVD_DEVICE_NAME) - 1, + payload->deviceName); - err = err | cbor_encoder_close_container(&map, &repMap); - } + // Device Spec Version + err = err | ConditionalAddTextStringToMap(&repMap, OC_RSRVD_SPEC_VERSION, + sizeof(OC_RSRVD_SPEC_VERSION) - 1, + payload->specVersion); - // Close Map - err = err | cbor_encoder_close_container(&rootArray, &map); - } + // Device data Model Version + err = err | ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DATA_MODEL_VERSION, + sizeof(OC_RSRVD_DATA_MODEL_VERSION) - 1, + payload->dataModelVersion); - // Close main array - err = err | cbor_encoder_close_container(&encoder, &rootArray); + err = err | cbor_encoder_close_container(&encoder, &repMap); return checkError(err, &encoder, outPayload, size); } diff --git a/resource/csdk/stack/src/ocpayloadparse.c b/resource/csdk/stack/src/ocpayloadparse.c index b3e5665..7bd7211 100644 --- a/resource/csdk/stack/src/ocpayloadparse.c +++ b/resource/csdk/stack/src/ocpayloadparse.c @@ -472,59 +472,45 @@ static OCStackResult OCParseDevicePayload(OCPayload** outPayload, CborValue* roo bool err = false; - CborValue arrayVal; - err = err || cbor_value_enter_container(rootValue, &arrayVal); - - if(cbor_value_is_map(&arrayVal)) + if(cbor_value_is_map(rootValue)) { - char* uri = NULL; uint8_t* sid = NULL; char* dname = NULL; char* specVer = NULL; char* dmVer = NULL; - CborValue curVal; - err = err || cbor_value_map_find_value(&arrayVal, OC_RSRVD_HREF, &curVal); - size_t len; - err = err || cbor_value_dup_text_string(&curVal, &uri, &len, NULL); - // Representation + CborValue repVal; + // Device ID + err = err || cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_ID, &repVal); + size_t len; + if(cbor_value_is_valid(&repVal)) { - err = err || cbor_value_map_find_value(&arrayVal, OC_RSRVD_REPRESENTATION, &curVal); - - CborValue repVal; - // Device ID - err = err || cbor_value_map_find_value(&curVal, OC_RSRVD_DEVICE_ID, &repVal); - if(cbor_value_is_valid(&repVal)) - { - err = err || cbor_value_dup_byte_string(&repVal, &sid, &len, NULL); - } - // Device Name - err = err || cbor_value_map_find_value(&curVal, OC_RSRVD_DEVICE_NAME, &repVal); - if(cbor_value_is_valid(&repVal)) - { - err = err || cbor_value_dup_text_string(&repVal, &dname, &len, NULL); - } - // Device Spec Version - err = err || cbor_value_map_find_value(&curVal, OC_RSRVD_SPEC_VERSION, &repVal); - if(cbor_value_is_valid(&repVal)) - { - err = err || cbor_value_dup_text_string(&repVal, &specVer, &len, NULL); - } + err = err || cbor_value_dup_byte_string(&repVal, &sid, &len, NULL); + } + // Device Name + err = err || cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_NAME, &repVal); + if(cbor_value_is_valid(&repVal)) + { + err = err || cbor_value_dup_text_string(&repVal, &dname, &len, NULL); + } + // Device Spec Version + err = err || cbor_value_map_find_value(rootValue, OC_RSRVD_SPEC_VERSION, &repVal); + if(cbor_value_is_valid(&repVal)) + { + err = err || cbor_value_dup_text_string(&repVal, &specVer, &len, NULL); + } - // Data Model Version - err = err || cbor_value_map_find_value(&curVal, OC_RSRVD_DATA_MODEL_VERSION, &repVal); - if (cbor_value_is_valid(&repVal)) - { - err = err || cbor_value_dup_text_string(&repVal, &dmVer, &len, NULL); - } + // Data Model Version + err = err || cbor_value_map_find_value(rootValue, OC_RSRVD_DATA_MODEL_VERSION, &repVal); + if (cbor_value_is_valid(&repVal)) + { + err = err || cbor_value_dup_text_string(&repVal, &dmVer, &len, NULL); } - err = err || cbor_value_advance(&arrayVal); - err = err || cbor_value_leave_container(rootValue, &arrayVal); + err = err || cbor_value_advance(rootValue); if(err) { - OICFree(uri); OICFree(sid); OICFree(dname); OICFree(specVer); @@ -533,9 +519,8 @@ static OCStackResult OCParseDevicePayload(OCPayload** outPayload, CborValue* roo return OC_STACK_MALFORMED_RESPONSE; } - *outPayload = (OCPayload*)OCDevicePayloadCreate(uri, sid, dname, specVer, dmVer); + *outPayload = (OCPayload*)OCDevicePayloadCreate(sid, dname, specVer, dmVer); - OICFree(uri); OICFree(sid); OICFree(dname); OICFree(specVer); diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index f6ca273..15649aa 100644 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -670,8 +670,7 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource } else { - payload = (OCPayload*) OCDevicePayloadCreate(OC_RSRVD_DEVICE_URI, - (const uint8_t*) &deviceId->id, savedDeviceInfo.deviceName, + payload = (OCPayload*) OCDevicePayloadCreate((const uint8_t*) &deviceId->id, savedDeviceInfo.deviceName, OC_SPEC_VERSION, OC_DATA_MODEL_VERSION); if (!payload) { diff --git a/resource/src/OCRepresentation.cpp b/resource/src/OCRepresentation.cpp index 5a1c982..2c91437 100644 --- a/resource/src/OCRepresentation.cpp +++ b/resource/src/OCRepresentation.cpp @@ -63,7 +63,6 @@ namespace OC void MessageContainer::setPayload(const OCDevicePayload* payload) { OCRepresentation rep; - rep.setUri(payload->uri); char uuidString[UUID_STRING_SIZE]; if(payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString)) { diff --git a/resource/unittests/OCRepresentationEncodingTest.cpp b/resource/unittests/OCRepresentationEncodingTest.cpp index 1b9668a..ea7b7c6 100644 --- a/resource/unittests/OCRepresentationEncodingTest.cpp +++ b/resource/unittests/OCRepresentationEncodingTest.cpp @@ -47,8 +47,6 @@ namespace OC // CBOR->OCPayload and OCPayload->OCRepresentation conversions namespace OCRepresentationEncodingTest { - - static const char uri1[] = "/testuri"; static const uint8_t sid1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; static const char devicename1[] = "device name"; static const char specver1[] = "spec version"; @@ -57,13 +55,11 @@ namespace OCRepresentationEncodingTest TEST(DeviceDiscoveryEncoding, Normal) { OCDevicePayload* device = OCDevicePayloadCreate( - uri1, sid1, devicename1, specver1, dmver1); - EXPECT_STREQ(uri1, device->uri); EXPECT_STREQ(devicename1, device->deviceName); EXPECT_STREQ(specver1, device->specVersion); EXPECT_STREQ(dmver1, device->dataModelVersion); @@ -82,7 +78,6 @@ namespace OCRepresentationEncodingTest cborData, cborSize)); OICFree(cborData); - EXPECT_STREQ(device->uri, ((OCDevicePayload*)parsedDevice)->uri); EXPECT_STREQ(device->deviceName, ((OCDevicePayload*)parsedDevice)->deviceName); EXPECT_STREQ(device->specVersion, ((OCDevicePayload*)parsedDevice)->specVersion); EXPECT_STREQ(device->dataModelVersion, ((OCDevicePayload*)parsedDevice)->dataModelVersion); @@ -94,15 +89,14 @@ namespace OCRepresentationEncodingTest mc.setPayload(parsedDevice); EXPECT_EQ(1u, mc.representations().size()); const OC::OCRepresentation& r = mc.representations()[0]; - EXPECT_STREQ(uri1, r.getUri().c_str()); EXPECT_STREQ(devicename1, r.getValue(OC_RSRVD_DEVICE_NAME).c_str()); EXPECT_STREQ(specver1, r.getValue(OC_RSRVD_SPEC_VERSION).c_str()); EXPECT_STREQ(dmver1, r.getValue(OC_RSRVD_DATA_MODEL_VERSION).c_str()); - OCPayloadDestroy(parsedDevice); } + static const char uri1[] = "/testuri"; static char pfid1[] = "pfid"; static char mfgnm1[] = "mfgnm"; static char mfgurl1[] = "mfgurl"; -- 2.7.4