From c18d0ffa08e0feb19d8451de980c93d63d464133 Mon Sep 17 00:00:00 2001 From: Todd Malsbary Date: Tue, 28 Feb 2017 17:10:38 -0800 Subject: [PATCH] Add support for application/ocf.vnd+ocf discovery payloads. - Remove baseURI and add anchor property. - Plumb content format through to parsing/converting payloads. Change-Id: I05d2a9263b085dec3683f6345190a4b4574ff2dc Signed-off-by: Todd Malsbary Reviewed-on: https://gerrit.iotivity.org/gerrit/17575 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai --- resource/csdk/include/octypes.h | 7 +- resource/csdk/resource-directory/SConscript | 2 +- .../resource-directory/unittests/rddatabase.cpp | 2 - resource/csdk/routing/src/routingmessageparser.c | 2 +- .../csdk/security/provisioning/src/cloud/aclid.c | 2 +- .../csdk/security/provisioning/src/cloud/crl.c | 2 +- resource/csdk/security/src/crlresource.c | 2 +- .../csdk/stack/include/internal/ocpayloadcbor.h | 5 +- .../csdk/stack/include/internal/ocserverrequest.h | 7 +- .../csdk/stack/include/internal/ocstackinternal.h | 3 + resource/csdk/stack/include/payload_logging.h | 8 +- resource/csdk/stack/src/ocobserve.c | 6 +- resource/csdk/stack/src/ocpayload.c | 3 +- resource/csdk/stack/src/ocpayloadconvert.c | 229 ++++++++++++---- resource/csdk/stack/src/ocpayloadparse.c | 293 +++++++++++++++------ resource/csdk/stack/src/ocresource.c | 1 + resource/csdk/stack/src/ocserverrequest.c | 12 +- resource/csdk/stack/src/ocstack.c | 35 ++- resource/csdk/stack/src/oickeepalive.c | 2 +- resource/csdk/stack/src/oicresourcedirectory.c | 12 +- resource/csdk/stack/test/cbortests.cpp | 15 +- resource/include/OCSerialization.h | 56 ++-- .../unittests/OCRepresentationEncodingTest.cpp | 116 ++++---- 23 files changed, 534 insertions(+), 288 deletions(-) diff --git a/resource/csdk/include/octypes.h b/resource/csdk/include/octypes.h index 566815b..caf7dfe 100644 --- a/resource/csdk/include/octypes.h +++ b/resource/csdk/include/octypes.h @@ -429,9 +429,6 @@ extern "C" { /** Resource URI used to discover Proxy */ #define OC_RSRVD_PROXY_OPTION_ID 35 -/** Base URI. */ -#define OC_RSRVD_BASE_URI "baseURI" - /** Unique value per collection/link. */ #define OC_RSRVD_INS "ins" @@ -1537,6 +1534,7 @@ typedef struct OCResourcePayload { char* uri; char* rel; + char* anchor; OCStringLL* types; OCStringLL* interfaces; uint8_t bitmap; @@ -1556,9 +1554,6 @@ typedef struct OCDiscoveryPayload /** Device Id */ char *sid; - /** A special case for handling RD address. */ - char* baseURI; - /** Name */ char *name; diff --git a/resource/csdk/resource-directory/SConscript b/resource/csdk/resource-directory/SConscript index c8c75aa..4bae87b 100755 --- a/resource/csdk/resource-directory/SConscript +++ b/resource/csdk/resource-directory/SConscript @@ -54,7 +54,7 @@ if 'SERVER' in rd_mode: if target_os != 'android': rd_env.PrependUnique(RPATH = [rd_env.get('BUILD_DIR')]) -rd_env.PrependUnique(LIBS = ['octbstack', 'oc', 'oc_logger']) +rd_env.PrependUnique(LIBS = ['octbstack', 'oc', 'oc_logger', 'connectivity_abstraction']) if target_os not in ['windows']: rd_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra', '-std=c++0x']) diff --git a/resource/csdk/resource-directory/unittests/rddatabase.cpp b/resource/csdk/resource-directory/unittests/rddatabase.cpp index 1e2666f..5fafd74 100644 --- a/resource/csdk/resource-directory/unittests/rddatabase.cpp +++ b/resource/csdk/resource-directory/unittests/rddatabase.cpp @@ -252,7 +252,6 @@ TEST_F(RDDatabaseTests, UpdateResources) OCDiscoveryPayload *discPayload = NULL; EXPECT_EQ(OC_STACK_OK, OCRDDatabaseDiscoveryPayloadCreate(OC_RSRVD_INTERFACE_LL, NULL, &discPayload)); - EXPECT_STREQ("192.168.1.1:12345", discPayload->baseURI); bool foundThermostat = false; bool foundLight = false; for (OCResourcePayload *resource = discPayload->resources; resource; resource = resource->next) @@ -308,7 +307,6 @@ TEST_F(RDDatabaseTests, AddAndUpdateResources) OCDiscoveryPayload *discPayload = NULL; EXPECT_EQ(OC_STACK_OK, OCRDDatabaseDiscoveryPayloadCreate(OC_RSRVD_INTERFACE_LL, NULL, &discPayload)); - EXPECT_STREQ("192.168.1.1:12345", discPayload->baseURI); bool foundThermostat = false; bool foundLight = false; bool foundLight2 = false; diff --git a/resource/csdk/routing/src/routingmessageparser.c b/resource/csdk/routing/src/routingmessageparser.c index 7ee337c..b4055af 100644 --- a/resource/csdk/routing/src/routingmessageparser.c +++ b/resource/csdk/routing/src/routingmessageparser.c @@ -222,7 +222,7 @@ OCStackResult RMPParseRequestPayload(const uint8_t* payload, size_t payloadSize, uint32_t *gatewayId) { OCPayload *ocPayload = NULL; - OCParsePayload(&ocPayload, PAYLOAD_TYPE_REPRESENTATION, payload, payloadSize); + OCParsePayload(&ocPayload, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, payload, payloadSize); OCRepPayload *repPayload = (OCRepPayload *)ocPayload; OCStackResult res = RMPParseResponsePayload(repPayload, gatewayId, NULL, NULL, NULL); if (OC_STACK_OK != res) diff --git a/resource/csdk/security/provisioning/src/cloud/aclid.c b/resource/csdk/security/provisioning/src/cloud/aclid.c index 6ce5ec3..acbfb57 100644 --- a/resource/csdk/security/provisioning/src/cloud/aclid.c +++ b/resource/csdk/security/provisioning/src/cloud/aclid.c @@ -177,7 +177,7 @@ static OCStackResult handleAclGetInfoResponse(void *ctx, void **data, OCClientRe return OC_STACK_INVALID_PARAM; } - result = OCConvertPayload(response->payload, &cbor, &size); + result = OCConvertPayload(response->payload, OC_FORMAT_CBOR, &cbor, &size); if (result != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "Can't convert OCPayload to cbor"); diff --git a/resource/csdk/security/provisioning/src/cloud/crl.c b/resource/csdk/security/provisioning/src/cloud/crl.c index f9798e9..5520222 100644 --- a/resource/csdk/security/provisioning/src/cloud/crl.c +++ b/resource/csdk/security/provisioning/src/cloud/crl.c @@ -173,7 +173,7 @@ OCStackResult OCCloudPostCRL(void* ctx, goto exit; } - result = OCConvertPayload((OCPayload *)payload, &cbor, &cbor_len); + result = OCConvertPayload((OCPayload *)payload, OC_FORMAT_CBOR, &cbor, &cbor_len); if (result != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "Can't convert OCPayload to cbor"); diff --git a/resource/csdk/security/src/crlresource.c b/resource/csdk/security/src/crlresource.c index 4634400..4d071f0 100644 --- a/resource/csdk/security/src/crlresource.c +++ b/resource/csdk/security/src/crlresource.c @@ -737,7 +737,7 @@ OCStackResult getLastUpdateFromDB(char **lastUpdate) goto exit; } - result = OCParsePayload(&payload, PAYLOAD_TYPE_REPRESENTATION, data, size); + result = OCParsePayload(&payload, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, data, size); if (result != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "Can't parse cbor data from DB"); diff --git a/resource/csdk/stack/include/internal/ocpayloadcbor.h b/resource/csdk/stack/include/internal/ocpayloadcbor.h index b2cc932..cb6a675 100644 --- a/resource/csdk/stack/include/internal/ocpayloadcbor.h +++ b/resource/csdk/stack/include/internal/ocpayloadcbor.h @@ -28,10 +28,11 @@ extern "C" { #endif -OCStackResult OCParsePayload(OCPayload** outPayload, OCPayloadType type, +OCStackResult OCParsePayload(OCPayload** outPayload, OCPayloadFormat format, OCPayloadType type, const uint8_t* payload, size_t payloadSize); -OCStackResult OCConvertPayload(OCPayload* payload, uint8_t** outPayload, size_t* size); +OCStackResult OCConvertPayload(OCPayload* payload, OCPayloadFormat format, + uint8_t** outPayload, size_t* size); #ifdef __cplusplus } diff --git a/resource/csdk/stack/include/internal/ocserverrequest.h b/resource/csdk/stack/include/internal/ocserverrequest.h index 47b9a35..b40fd93 100644 --- a/resource/csdk/stack/include/internal/ocserverrequest.h +++ b/resource/csdk/stack/include/internal/ocserverrequest.h @@ -111,6 +111,9 @@ typedef struct OCServerRequest /** Flag indicating notification.*/ uint8_t notificationFlag; + /** Payload format retrieved from the received request PDU. */ + OCPayloadFormat payloadFormat; + /** Payload Size.*/ size_t payloadSize; @@ -225,7 +228,7 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID, uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption, OCQualityOfService qos, char * query, OCHeaderOption * rcvdVendorSpecificHeaderOptions, - uint8_t * payload, CAToken_t requestToken, + OCPayloadFormat payloadFormat, uint8_t * payload, CAToken_t requestToken, uint8_t tokenLength, char * resourceUrl, size_t reqTotalSize, OCPayloadFormat acceptFormat, @@ -241,6 +244,7 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID, * @param endpoint Device address of the requester. * @param resource Resource handle. * @param queryBuf Resource query of request. + * @param payloadFormat Content format of payload. * @param payloadType Type of payload. * @param payload cbor value of the payload. * @param payloadSize Size of payload. @@ -261,6 +265,7 @@ OCStackResult FormOCEntityHandlerRequest( OCResourceHandle resource, char * queryBuf, OCPayloadType payloadType, + OCPayloadFormat payloadFormat, uint8_t * payload, size_t payloadSize, uint8_t numVendorOptions, diff --git a/resource/csdk/stack/include/internal/ocstackinternal.h b/resource/csdk/stack/include/internal/ocstackinternal.h index 1e256e2..293de85 100644 --- a/resource/csdk/stack/include/internal/ocstackinternal.h +++ b/resource/csdk/stack/include/internal/ocstackinternal.h @@ -80,6 +80,9 @@ typedef struct /** The REST method retrieved from received request PDU.*/ OCMethod method; + /** the provided payload format. */ + OCPayloadFormat payloadFormat; + /** the requested payload format. */ OCPayloadFormat acceptFormat; diff --git a/resource/csdk/stack/include/payload_logging.h b/resource/csdk/stack/include/payload_logging.h index f416806..2df6f45 100644 --- a/resource/csdk/stack/include/payload_logging.h +++ b/resource/csdk/stack/include/payload_logging.h @@ -217,10 +217,6 @@ INLINE_API void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payloa while(payload && payload->resources) { OIC_LOG_V(level, PL_TAG, "\tDI: %s", payload->sid); - if (payload->baseURI) - { - OIC_LOG_V(level, PL_TAG, "\tBase URI:%s", payload->baseURI); - } if (payload->name) { OIC_LOG_V(level, PL_TAG, "\tNAME: %s", payload->name); @@ -249,6 +245,10 @@ INLINE_API void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payloa { OIC_LOG_V(level, PL_TAG, "\tRelation:%s", res->rel); } + if (res->anchor) + { + OIC_LOG_V(level, PL_TAG, "\tAnchor:%s", res->anchor); + } OIC_LOG(level, PL_TAG, "\tResource Types:"); OCStringLL* strll = res->types; while(strll) diff --git a/resource/csdk/stack/src/ocobserve.c b/resource/csdk/stack/src/ocobserve.c index 82cfd2a..ac6e9e4 100644 --- a/resource/csdk/stack/src/ocobserve.c +++ b/resource/csdk/stack/src/ocobserve.c @@ -112,7 +112,7 @@ static OCStackResult SendObserveNotification(ResourceObserver *observer, result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET, 0, observer->resource->sequenceNum, qos, - observer->query, NULL, NULL, + observer->query, NULL, OC_FORMAT_UNDEFINED, NULL, observer->token, observer->tokenLength, observer->resUri, 0, observer->acceptFormat, observer->acceptVersion, &observer->devAddr); @@ -179,7 +179,7 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, OIC_LOG(DEBUG, TAG, "This notification is for Presence"); result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET, 0, resPtr->sequenceNum, qos, resourceObserver->query, - NULL, NULL, + NULL, OC_FORMAT_UNDEFINED, NULL, resourceObserver->token, resourceObserver->tokenLength, resourceObserver->resUri, 0, resourceObserver->acceptFormat, resourceObserver->acceptVersion, &resourceObserver->devAddr); @@ -267,7 +267,7 @@ OCStackResult SendListObserverNotification (OCResource * resource, result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET, 0, resource->sequenceNum, qos, observer->query, - NULL, NULL, observer->token, observer->tokenLength, + NULL, OC_FORMAT_UNDEFINED, NULL, observer->token, observer->tokenLength, observer->resUri, 0, observer->acceptFormat, observer->acceptVersion, &observer->devAddr); diff --git a/resource/csdk/stack/src/ocpayload.c b/resource/csdk/stack/src/ocpayload.c index 6a934be..6551d41 100644 --- a/resource/csdk/stack/src/ocpayload.c +++ b/resource/csdk/stack/src/ocpayload.c @@ -2076,12 +2076,14 @@ void OCDiscoveryResourceDestroy(OCResourcePayload* payload) OICFree(payload->uri); OICFree(payload->rel); + OICFree(payload->anchor); OCFreeOCStringLL(payload->types); OCFreeOCStringLL(payload->interfaces); OCDiscoveryEndpointDestroy(payload->eps); OCDiscoveryResourceDestroy(payload->next); OICFree(payload); } + void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload) { if (!payload) @@ -2089,7 +2091,6 @@ void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload) return; } OICFree(payload->sid); - OICFree(payload->baseURI); OCFreeOCStringLL(payload->type); OICFree(payload->name); OCFreeOCStringLL(payload->iface); diff --git a/resource/csdk/stack/src/ocpayloadconvert.c b/resource/csdk/stack/src/ocpayloadconvert.c index 9132bf8..65f1764 100755 --- a/resource/csdk/stack/src/ocpayloadconvert.c +++ b/resource/csdk/stack/src/ocpayloadconvert.c @@ -39,19 +39,17 @@ // Arbitrarily chosen size that seems to contain the majority of packages #define INIT_SIZE (255) -// Discovery Links Map with endpoints Length. -#define LINKS_MAP_LEN_WITH_EPS (5) - -// Discovery Links Map without endpoints Length. -#define LINKS_MAP_LEN_WITHOUT_EPS (4) +// Discovery Links Map Length. +#define LINKS_MAP_LEN (4) // Endpoint Map length, it contains "ep", "pri". #define EP_MAP_LEN (2) // Functions all return either a CborError, or a negative version of the OC_STACK return values -static int64_t OCConvertPayloadHelper(OCPayload *payload, uint8_t *outPayload, size_t *size); -static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *outPayload, - size_t *size); +static int64_t OCConvertPayloadHelper(OCPayload *payload, OCPayloadFormat format, + uint8_t *outPayload, size_t *size); +static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, OCPayloadFormat format, + uint8_t *outPayload, size_t *size); static int64_t OCConvertRepPayload(OCRepPayload *payload, uint8_t *outPayload, size_t *size); static int64_t OCConvertRepMap(CborEncoder *map, const OCRepPayload *payload); static int64_t OCConvertPresencePayload(OCPresencePayload *payload, uint8_t *outPayload, @@ -67,7 +65,8 @@ static int64_t AddTextStringToMap(CborEncoder *map, const char *key, size_t keyl static int64_t ConditionalAddTextStringToMap(CborEncoder *map, const char *key, size_t keylen, const char *value); -OCStackResult OCConvertPayload(OCPayload* payload, uint8_t** outPayload, size_t* size) +OCStackResult OCConvertPayload(OCPayload* payload, OCPayloadFormat format, + uint8_t** outPayload, size_t* size) { // TinyCbor Version 47a78569c0 or better on master is required for the re-allocation // strategy to work. If you receive the following assertion error, please do a git-pull @@ -101,7 +100,7 @@ OCStackResult OCConvertPayload(OCPayload* payload, uint8_t** outPayload, size_t* { out = (uint8_t *)OICCalloc(1, curSize); VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate payload"); - err = OCConvertPayloadHelper(payload, out, &curSize); + err = OCConvertPayloadHelper(payload, format, out, &curSize); if (CborErrorOutOfMemory != err) { @@ -136,12 +135,14 @@ exit: return ret; } -static int64_t OCConvertPayloadHelper(OCPayload* payload, uint8_t* outPayload, size_t* size) +static int64_t OCConvertPayloadHelper(OCPayload* payload, OCPayloadFormat format, + uint8_t* outPayload, size_t* size) { switch(payload->type) { case PAYLOAD_TYPE_DISCOVERY: - return OCConvertDiscoveryPayload((OCDiscoveryPayload*)payload, outPayload, size); + return OCConvertDiscoveryPayload((OCDiscoveryPayload*)payload, format, + outPayload, size); case PAYLOAD_TYPE_REPRESENTATION: return OCConvertRepPayload((OCRepPayload*)payload, outPayload, size); case PAYLOAD_TYPE_PRESENCE: @@ -207,8 +208,8 @@ static int64_t OCStringLLJoin(CborEncoder *map, char *type, OCStringLL *val) return err; } -static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *outPayload, - size_t *size) +static int64_t OCConvertDiscoveryPayloadCbor(OCDiscoveryPayload *payload, + uint8_t *outPayload, size_t *size) { CborEncoder encoder; int64_t err = CborNoError; @@ -227,10 +228,10 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o "di": "0685B960-736F-46F7-BEC0-9E6CBD61ADC1", links :[ // linksArray contains maps of resources { - href, rt, if, policy, eps // Resource 1 + href, rt, if, policy // Resource 1 }, { - href, rt, if, policy, eps // Resource 2 + href, rt, if, policy // Resource 2 }, . . @@ -275,17 +276,8 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting RT"); // Insert interfaces - if (payload->iface) - { - err |= OCStringLLJoin(&rootMap, OC_RSRVD_INTERFACE, payload->iface); - VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding interface types tag/value"); - } - - // Insert baseURI if present - err |= ConditionalAddTextStringToMap(&rootMap, OC_RSRVD_BASE_URI, - sizeof(OC_RSRVD_BASE_URI) - 1, - payload->baseURI); - VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting baseURI"); + err |= OCStringLLJoin(&rootMap, OC_RSRVD_INTERFACE, payload->iface); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding interface types tag/value"); // Insert Links into the root map. CborEncoder linkArray; @@ -303,7 +295,7 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o VERIFY_PARAM_NON_NULL(TAG, resource, "Failed retrieving resource"); // resource map inside the links array. - linkMapLen = resource->eps ? LINKS_MAP_LEN_WITH_EPS : LINKS_MAP_LEN_WITHOUT_EPS; + linkMapLen = LINKS_MAP_LEN; if (resource->rel) { ++linkMapLen; @@ -318,27 +310,19 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding uri to links map"); // Rel - Not a mandatory field - if (resource->rel) - { - err |= AddTextStringToMap(&linkMap, OC_RSRVD_REL, sizeof(OC_RSRVD_REL) - 1, - resource->rel); - VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding rel to links map"); - } + err |= ConditionalAddTextStringToMap(&linkMap, OC_RSRVD_REL, sizeof(OC_RSRVD_REL) - 1, + resource->rel); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding rel to links map"); // Resource Type - if (resource->types) - { - err |= OCStringLLJoin(&linkMap, OC_RSRVD_RESOURCE_TYPE, resource->types); - VERIFY_CBOR_SUCCESS(TAG, err, - "Failed adding resourceType tag/value to links map"); - } + err |= OCStringLLJoin(&linkMap, OC_RSRVD_RESOURCE_TYPE, resource->types); + VERIFY_CBOR_SUCCESS(TAG, err, + "Failed adding resourceType tag/value to links map"); + // Interface Types - if (resource->interfaces) - { - err |= OCStringLLJoin(&linkMap, OC_RSRVD_INTERFACE, resource->interfaces); - VERIFY_CBOR_SUCCESS(TAG, err, - "Failed adding interfaces tag/value to links map"); - } + err |= OCStringLLJoin(&linkMap, OC_RSRVD_INTERFACE, resource->interfaces); + VERIFY_CBOR_SUCCESS(TAG, err, + "Failed adding interfaces tag/value to links map"); // Policy CborEncoder policyMap; @@ -362,7 +346,7 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o err |= cbor_encode_boolean(&policyMap, resource->secure); VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding secure value to policy map"); - if (resource->secure || payload->baseURI) + if (resource->secure) { err |= cbor_encode_text_string(&policyMap, OC_RSRVD_HOSTING_PORT, sizeof(OC_RSRVD_HOSTING_PORT) - 1); @@ -397,6 +381,127 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o err |= cbor_encoder_close_container(&linkMap, &policyMap); VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing policy map"); + // Finished encoding a resource, close the map. + err |= cbor_encoder_close_container(&linkArray, &linkMap); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing link map"); + } + // Close links array inside the root map. + err |= cbor_encoder_close_container(&rootMap, &linkArray); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing link array"); + // close root map inside the root array. + err |= cbor_encoder_close_container(&rootArray, &rootMap); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing root map"); + + payload = payload->next; + } + + // Close the final root array. + err |= cbor_encoder_close_container(&encoder, &rootArray); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing root array"); + +exit: + return checkError(err, &encoder, outPayload, size); +} + +static int64_t OCConvertDiscoveryPayloadVndOcfCbor(OCDiscoveryPayload *payload, + uint8_t *outPayload, size_t *size) +{ + CborEncoder encoder; + int64_t err = CborNoError; + + cbor_encoder_init(&encoder, outPayload, *size, 0); + + /* + The format for the payload is "modelled" as JSON. + + [ // rootArray + { + href, anchor, rt, if, policy, eps // Resource 1 + }, + { + href, anchor, rt, if, policy, eps // Resource 2 + }, + . + . + . + ] + */ + + // Open the main root array + size_t arrayCount = 0; + for (OCDiscoveryPayload *temp = payload; temp; temp = temp->next) + { + arrayCount += OCDiscoveryPayloadGetResourceCount(temp); + } + CborEncoder rootArray; + err |= cbor_encoder_create_array(&encoder, &rootArray, arrayCount); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating discovery root array"); + + while (payload && payload->resources) + { + size_t resourceCount = OCDiscoveryPayloadGetResourceCount(payload); + for (size_t i = 0; i < resourceCount; ++i) + { + OCResourcePayload *resource = OCDiscoveryPayloadGetResource(payload, i); + + // Open a link map in the root array + CborEncoder linkMap; + err |= cbor_encoder_create_map(&rootArray, &linkMap, CborIndefiniteLength); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating discovery map"); + + // Uri + err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1, + resource->uri); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding uri to links map"); + + // Rel - Not a mandatory field + err |= ConditionalAddTextStringToMap(&linkMap, OC_RSRVD_REL, sizeof(OC_RSRVD_REL) - 1, + resource->rel); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding rel to links map"); + + // Anchor - Not a mandatory field + if (resource->anchor) + { + err |= AddTextStringToMap(&linkMap, OC_RSRVD_URI, sizeof(OC_RSRVD_URI) - 1, + resource->anchor); + } + else + { + char anchor[MAX_URI_LENGTH]; + snprintf(anchor, MAX_URI_LENGTH, "ocf://%s", payload->sid); + err |= AddTextStringToMap(&linkMap, OC_RSRVD_URI, sizeof(OC_RSRVD_URI) - 1, + anchor); + } + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding anchor to links map"); + + // Resource Type + err |= OCStringLLJoin(&linkMap, OC_RSRVD_RESOURCE_TYPE, resource->types); + VERIFY_CBOR_SUCCESS(TAG, err, + "Failed adding resourceType tag/value to links map"); + + // Interface Types + err |= OCStringLLJoin(&linkMap, OC_RSRVD_INTERFACE, resource->interfaces); + VERIFY_CBOR_SUCCESS(TAG, err, + "Failed adding interfaces tag/value to links map"); + + // Policy + CborEncoder policyMap; + err |= cbor_encode_text_string(&linkMap, OC_RSRVD_POLICY, + sizeof(OC_RSRVD_POLICY) - 1); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding policy tag to links map"); + err |= cbor_encoder_create_map(&linkMap, &policyMap, CborIndefiniteLength); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding policy map to links map"); + + // Bitmap + err |= cbor_encode_text_string(&policyMap, OC_RSRVD_BITMAP, + sizeof(OC_RSRVD_BITMAP) - 1); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding bitmap tag to policy map"); + err |= cbor_encode_uint(&policyMap, resource->bitmap); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding bitmap value to policy map"); + + err |= cbor_encoder_close_container(&linkMap, &policyMap); + VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing policy map"); + // Endpoints size_t epsCount = OCEndpointPayloadGetEndpointCount(resource->eps); @@ -405,7 +510,7 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o { CborEncoder epsArray; err |= cbor_encode_text_string(&linkMap, OC_RSRVD_ENDPOINTS, - sizeof(OC_RSRVD_ENDPOINTS) - 1); + sizeof(OC_RSRVD_ENDPOINTS) - 1); VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting endpoints array tag"); err |= cbor_encoder_create_array(&linkMap, &epsArray, epsCount); @@ -441,16 +546,11 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o err |= cbor_encoder_close_container(&linkMap, &epsArray); VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing endpoints map"); } - // Finsihed encoding a resource, close the map. - err |= cbor_encoder_close_container(&linkArray, &linkMap); + + // Finished encoding a resource, close the map. + err |= cbor_encoder_close_container(&rootArray, &linkMap); VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing link map"); } - // Close links array inside the root map. - err |= cbor_encoder_close_container(&rootMap, &linkArray); - VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing link array"); - // close root map inside the root array. - err |= cbor_encoder_close_container(&rootArray, &rootMap); - VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing root map"); payload = payload->next; } @@ -463,6 +563,19 @@ exit: return checkError(err, &encoder, outPayload, size); } +static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, OCPayloadFormat format, + uint8_t *outPayload, size_t *size) +{ + if (OC_FORMAT_VND_OCF_CBOR == format) + { + return OCConvertDiscoveryPayloadVndOcfCbor(payload, outPayload, size); + } + else + { + return OCConvertDiscoveryPayloadCbor(payload, outPayload, size); + } +} + static int64_t OCConvertArrayItem(CborEncoder *array, const OCRepPayloadValueArray *valArray, size_t index) { @@ -798,6 +911,10 @@ exit: static int64_t AddTextStringToMap(CborEncoder* map, const char* key, size_t keylen, const char* value) { + if (!key || !value) + { + return CborErrorInvalidUtf8TextString; + } int64_t err = cbor_encode_text_string(map, key, keylen); if (CborNoError != err) { diff --git a/resource/csdk/stack/src/ocpayloadparse.c b/resource/csdk/stack/src/ocpayloadparse.c index fdab5fb..0696fc5 100755 --- a/resource/csdk/stack/src/ocpayloadparse.c +++ b/resource/csdk/stack/src/ocpayloadparse.c @@ -45,14 +45,15 @@ */ #define UINT64_MAX_STRLEN 20 -static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *arrayVal); +static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, OCPayloadFormat format, + CborValue *arrayVal); static CborError OCParseSingleRepPayload(OCRepPayload **outPayload, CborValue *repParent, bool isRoot); static OCStackResult OCParseRepPayload(OCPayload **outPayload, CborValue *arrayVal); static OCStackResult OCParsePresencePayload(OCPayload **outPayload, CborValue *arrayVal); static OCStackResult OCParseSecurityPayload(OCPayload **outPayload, const uint8_t *payload, size_t size); -OCStackResult OCParsePayload(OCPayload **outPayload, OCPayloadType payloadType, - const uint8_t *payload, size_t payloadSize) +OCStackResult OCParsePayload(OCPayload **outPayload, OCPayloadFormat payloadFormat, + OCPayloadType payloadType, const uint8_t *payload, size_t payloadSize) { OCStackResult result = OC_STACK_MALFORMED_RESPONSE; CborError err; @@ -72,7 +73,7 @@ OCStackResult OCParsePayload(OCPayload **outPayload, OCPayloadType payloadType, switch(payloadType) { case PAYLOAD_TYPE_DISCOVERY: - result = OCParseDiscoveryPayload(outPayload, &rootValue); + result = OCParseDiscoveryPayload(outPayload, payloadFormat, &rootValue); break; case PAYLOAD_TYPE_REPRESENTATION: result = OCParseRepPayload(outPayload, &rootValue); @@ -173,14 +174,14 @@ exit: return err; } -static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *rootValue) +static OCStackResult OCParseDiscoveryPayloadCbor(OCPayload **outPayload, + CborValue *rootValue) { OCStackResult ret = OC_STACK_INVALID_PARAM; OCResourcePayload *resource = NULL; OCDiscoveryPayload *temp = NULL; OCDiscoveryPayload *rootPayload = NULL; OCDiscoveryPayload *curPayload = NULL; - OCEndpointPayload *endpoint = NULL; size_t len = 0; CborError err = CborNoError; *outPayload = NULL; @@ -220,15 +221,6 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue * } } - // BaseURI - Not a mandatory field - err = cbor_value_map_find_value(&rootMap, OC_RSRVD_BASE_URI, &curVal); - VERIFY_CBOR_SUCCESS(TAG, err, "to find uri tag"); - if (cbor_value_is_text_string(&curVal)) - { - err = cbor_value_dup_text_string(&curVal, &(temp->baseURI), &len, NULL); - VERIFY_CBOR_SUCCESS(TAG, err, "to find base uri value"); - } - // RT - Not a mandatory field err = cbor_value_map_find_value(&rootMap, OC_RSRVD_RESOURCE_TYPE, &curVal); if (cbor_value_is_valid(&curVal)) @@ -286,12 +278,13 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue * VERIFY_CBOR_SUCCESS(TAG, err, "to find rel value"); } - // ResourceTypes + // Resource Types err = OCParseStringLL(&resourceMap, OC_RSRVD_RESOURCE_TYPE, &resource->types); VERIFY_CBOR_SUCCESS(TAG, err, "to find resource type tag/value"); // Interface Types err = OCParseStringLL(&resourceMap, OC_RSRVD_INTERFACE, &resource->interfaces); + // TODO Why this block? It adds oic.if.ll if we don't parse anything: if (CborNoError != err) { if (!OCResourcePayloadAddStringLL(&resource->interfaces, OC_RSRVD_INTERFACE_LL)) @@ -359,64 +352,6 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue * } #endif #endif - // Endpoints - CborValue epsMap; - err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_ENDPOINTS, &epsMap); - VERIFY_CBOR_SUCCESS(TAG, err, "to find eps tag"); - - if (cbor_value_is_array(&epsMap)) - { - CborValue epMap; - err = cbor_value_enter_container(&epsMap, &epMap); - VERIFY_CBOR_SUCCESS(TAG, err, "to enter endpoint map"); - - while (cbor_value_is_map(&epMap)) - { - endpoint = NULL; - int pri = 0; - char *endpointStr = NULL; - endpoint = (OCEndpointPayload *)OICCalloc(1, sizeof(OCEndpointPayload)); - VERIFY_PARAM_NON_NULL(TAG, endpoint, "Failed allocating endpoint payload"); - - // ep - err = cbor_value_map_find_value(&epMap, OC_RSRVD_ENDPOINT, &curVal); - VERIFY_CBOR_SUCCESS(TAG, err, "to find endpoint tag"); - err = cbor_value_dup_text_string(&curVal, &endpointStr, &len, NULL); - VERIFY_CBOR_SUCCESS(TAG, err, "to find endpoint value"); - - OCStackResult parseResult = OCParseEndpointString(endpointStr, endpoint); - OICFree(endpointStr); - - if (OC_STACK_OK == parseResult) - { - // pri - err = cbor_value_map_find_value(&epMap, OC_RSRVD_PRIORITY, &curVal); - VERIFY_CBOR_SUCCESS(TAG, err, "to find priority tag"); - err = cbor_value_get_int(&curVal, &pri); - VERIFY_CBOR_SUCCESS(TAG, err, "to find priority value"); - endpoint->pri = (uint16_t)pri; - OCResourcePayloadAddNewEndpoint(resource, endpoint); - endpoint = NULL; - } - else - { - if (OC_STACK_ADAPTER_NOT_ENABLED == parseResult) - { - OIC_LOG(ERROR, TAG, "Ignore unrecognized endpoint info"); - } - // destroy endpoint - OCDiscoveryEndpointDestroy(endpoint); - endpoint = NULL; - } - - err = cbor_value_advance(&epMap); - VERIFY_CBOR_SUCCESS(TAG, err, "to advance endpoint map"); - } - - err = cbor_value_leave_container(&epsMap, &epMap); - VERIFY_CBOR_SUCCESS(TAG, err, "to leave eps map"); - } - err = cbor_value_advance(&resourceMap); VERIFY_CBOR_SUCCESS(TAG, err, "to advance resource map"); @@ -457,12 +392,222 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue * return OC_STACK_OK; exit: + OCDiscoveryResourceDestroy(resource); + OCDiscoveryPayloadDestroy(rootPayload); + return ret; +} + +static OCStackResult OCParseDiscoveryPayloadVndOcfCbor(OCPayload **outPayload, CborValue *rootValue) +{ + OCStackResult ret = OC_STACK_INVALID_PARAM; + OCResourcePayload *resource = NULL; + OCDiscoveryPayload *rootPayload = NULL; + OCEndpointPayload *endpoint = NULL; + size_t len = 0; + CborError err = CborNoError; + *outPayload = NULL; + + VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid Parameter outPayload"); + VERIFY_PARAM_NON_NULL(TAG, rootValue, "Invalid Parameter rootValue"); + if (cbor_value_is_array(rootValue)) + { + // Root value is already inside the main root array + + // Enter the main root array and start iterating through the array processing + // each resource which shows up as a map. + CborValue resourceMap; + err = cbor_value_enter_container(rootValue, &resourceMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to enter root array"); + + while (cbor_value_is_map(&resourceMap)) + { + int bitmap; + + resource = (OCResourcePayload *)OICCalloc(1, sizeof(OCResourcePayload)); + VERIFY_PARAM_NON_NULL(TAG, resource, "Failed allocating resource payload"); + + // Uri + CborValue curVal; + err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_HREF, &curVal); + VERIFY_CBOR_SUCCESS(TAG, err, "to find href tag"); + err = cbor_value_dup_text_string(&curVal, &(resource->uri), &len, NULL); + VERIFY_CBOR_SUCCESS(TAG, err, "to find href value"); + + // Rel - Not a mandatory field + err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_REL, &curVal); + VERIFY_CBOR_SUCCESS(TAG, err, "to find rel tag"); + if (cbor_value_is_valid(&curVal)) + { + err = cbor_value_dup_text_string(&curVal, &(resource->rel), &len, NULL); + VERIFY_CBOR_SUCCESS(TAG, err, "to find rel value"); + } + + // Anchor - Not a mandatory field + err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_URI, &curVal); + VERIFY_CBOR_SUCCESS(TAG, err, "to find anchor tag"); + if (cbor_value_is_text_string(&curVal)) + { + err = cbor_value_dup_text_string(&curVal, &(resource->anchor), &len, NULL); + VERIFY_CBOR_SUCCESS(TAG, err, "to find anchor value"); + } + + // Resource Types + err = OCParseStringLL(&resourceMap, OC_RSRVD_RESOURCE_TYPE, &resource->types); + VERIFY_CBOR_SUCCESS(TAG, err, "to find resource type tag/value"); + + // Interface Types + err = OCParseStringLL(&resourceMap, OC_RSRVD_INTERFACE, &resource->interfaces); + if (CborNoError != err) + { + if (!OCResourcePayloadAddStringLL(&resource->interfaces, OC_RSRVD_INTERFACE_LL)) + { + OIC_LOG(ERROR, TAG, "Failed to add string to StringLL"); + goto exit; + } + } + + // Policy + CborValue policyMap; + err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_POLICY, &policyMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to find policy tag"); + + // Bitmap + err = cbor_value_map_find_value(&policyMap, OC_RSRVD_BITMAP, &curVal); + VERIFY_CBOR_SUCCESS(TAG, err, "to find bitmap tag"); + err = cbor_value_get_int(&curVal, &bitmap); + VERIFY_CBOR_SUCCESS(TAG, err, "to find bitmap value"); + resource->bitmap = (uint8_t)bitmap; + + // Endpoints + CborValue epsMap; + err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_ENDPOINTS, &epsMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to find eps tag"); + + if (cbor_value_is_array(&epsMap)) + { + CborValue epMap; + err = cbor_value_enter_container(&epsMap, &epMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to enter endpoint map"); + + while (cbor_value_is_map(&epMap)) + { + endpoint = NULL; + int pri = 0; + char *endpointStr = NULL; + endpoint = (OCEndpointPayload *)OICCalloc(1, sizeof(OCEndpointPayload)); + VERIFY_PARAM_NON_NULL(TAG, endpoint, "Failed allocating endpoint payload"); + + // ep + err = cbor_value_map_find_value(&epMap, OC_RSRVD_ENDPOINT, &curVal); + VERIFY_CBOR_SUCCESS(TAG, err, "to find endpoint tag"); + err = cbor_value_dup_text_string(&curVal, &endpointStr, &len, NULL); + VERIFY_CBOR_SUCCESS(TAG, err, "to find endpoint value"); + + OCStackResult parseResult = OCParseEndpointString(endpointStr, endpoint); + OICFree(endpointStr); + + if (OC_STACK_OK == parseResult) + { + // pri + err = cbor_value_map_find_value(&epMap, OC_RSRVD_PRIORITY, &curVal); + VERIFY_CBOR_SUCCESS(TAG, err, "to find priority tag"); + err = cbor_value_get_int(&curVal, &pri); + VERIFY_CBOR_SUCCESS(TAG, err, "to find priority value"); + endpoint->pri = (uint16_t)pri; + OCResourcePayloadAddNewEndpoint(resource, endpoint); + endpoint = NULL; + } + else + { + if (OC_STACK_ADAPTER_NOT_ENABLED == parseResult) + { + OIC_LOG(ERROR, TAG, "Ignore unrecognized endpoint info"); + } + // destroy endpoint + OCDiscoveryEndpointDestroy(endpoint); + endpoint = NULL; + } + + err = cbor_value_advance(&epMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to advance endpoint map"); + } + + err = cbor_value_leave_container(&epsMap, &epMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to leave eps map"); + } + + err = cbor_value_advance(&resourceMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to advance resource map"); + + // Parse di from anchor + if (!resource->anchor || strncmp(resource->anchor, "ocf://", 6)) + { + OIC_LOG_V(ERROR, TAG, "Ignore unrecognized anchor %s", resource->anchor); + OCDiscoveryResourceDestroy(resource); + } + else + { + char *di = OICStrdup(resource->anchor + 6); + char *slash = strchr(di, '/'); + if (slash) + { + *slash = '\0'; + } + OCDiscoveryPayload **temp = &rootPayload; + while (*temp) + { + if (!strcmp((*temp)->sid, di)) + { + OCDiscoveryPayloadAddNewResource(*temp, resource); + OICFree(di); + break; + } + temp = &(*temp)->next; + } + if (!*temp) + { + *temp = OCDiscoveryPayloadCreate(); + VERIFY_PARAM_NON_NULL(TAG, *temp, "Failed error initializing discovery payload"); + (*temp)->sid = di; + OCDiscoveryPayloadAddNewResource(*temp, resource); + } + } + } + + err = cbor_value_leave_container(rootValue, &resourceMap); + VERIFY_CBOR_SUCCESS(TAG, err, "to leave resource map"); + } + else + { + OIC_LOG(ERROR, TAG, "Malformed packet "); + goto exit; + } + + *outPayload = (OCPayload *)rootPayload; + OIC_LOG_PAYLOAD(DEBUG, *outPayload); + + return OC_STACK_OK; + +exit: OCDiscoveryEndpointDestroy(endpoint); OCDiscoveryResourceDestroy(resource); OCDiscoveryPayloadDestroy(rootPayload); return ret; } +static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, OCPayloadFormat format, + CborValue *rootValue) +{ + if (OC_FORMAT_VND_OCF_CBOR == format) + { + return OCParseDiscoveryPayloadVndOcfCbor(outPayload, rootValue); + } + else + { + return OCParseDiscoveryPayloadCbor(outPayload, rootValue); + } +} + static OCRepPayloadPropType DecodeCborType(CborType type) { switch (type) diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index d4436ad..1e0d4e9 100755 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -1660,6 +1660,7 @@ static OCStackResult EHRequest(OCEntityHandlerRequest *ehRequest, OCPayloadType (OCResourceHandle)resource, request->query, type, + request->payloadFormat, request->payload, request->payloadSize, request->numRcvdVendorSpecificHeaderOptions, diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index f824454..b4c3014 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -275,8 +275,8 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID, uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption, OCQualityOfService qos, char * query, OCHeaderOption * rcvdVendorSpecificHeaderOptions, - uint8_t * payload, CAToken_t requestToken, uint8_t tokenLength, - char * resourceUrl, size_t reqTotalSize, OCPayloadFormat acceptFormat, + OCPayloadFormat payloadFormat, uint8_t * payload, CAToken_t requestToken, + uint8_t tokenLength, char * resourceUrl, size_t reqTotalSize, OCPayloadFormat acceptFormat, uint16_t acceptVersion, const OCDevAddr *devAddr) { if (!request) @@ -323,6 +323,7 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID, // last character memcpy(serverRequest->payload, payload, reqTotalSize); serverRequest->payloadSize = reqTotalSize; + serverRequest->payloadFormat = payloadFormat; } serverRequest->requestComplete = 0; @@ -371,6 +372,7 @@ OCStackResult FormOCEntityHandlerRequest( OCResourceHandle resource, char * queryBuf, OCPayloadType payloadType, + OCPayloadFormat payloadFormat, uint8_t * payload, size_t payloadSize, uint8_t numVendorOptions, @@ -392,7 +394,7 @@ OCStackResult FormOCEntityHandlerRequest( if(payload && payloadSize) { - if(OCParsePayload(&entityHandlerRequest->payload, payloadType, + if(OCParsePayload(&entityHandlerRequest->payload, payloadFormat, payloadType, payload, payloadSize) != OC_STACK_OK) { return OC_STACK_ERROR; @@ -647,8 +649,8 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse) // No preference set by the client, so default to CBOR then case OC_FORMAT_CBOR: case OC_FORMAT_VND_OCF_CBOR: - if((result = OCConvertPayload(ehResponse->payload, &responseInfo.info.payload, - &responseInfo.info.payloadSize)) + if((result = OCConvertPayload(ehResponse->payload, serverRequest->acceptFormat, + &responseInfo.info.payload, &responseInfo.info.payloadSize)) != OC_STACK_OK) { OIC_LOG(ERROR, TAG, "Error converting payload"); diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index eec1d28..ce57949 100755 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -680,7 +680,8 @@ OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t stat OC_REST_NOMETHOD, &observer->devAddr, (OCResourceHandle)NULL, - NULL, PAYLOAD_TYPE_REPRESENTATION, + NULL, + PAYLOAD_TYPE_REPRESENTATION, OC_FORMAT_CBOR, NULL, 0, 0, NULL, OC_OBSERVE_DEREGISTER, observer->observeId, @@ -736,7 +737,8 @@ OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t stat OC_REST_NOMETHOD, &observer->devAddr, (OCResourceHandle)NULL, - NULL, PAYLOAD_TYPE_REPRESENTATION, + NULL, + PAYLOAD_TYPE_REPRESENTATION, OC_FORMAT_CBOR, NULL, 0, 0, NULL, OC_OBSERVE_DEREGISTER, observer->observeId, @@ -1221,6 +1223,7 @@ OCStackResult HandlePresenceResponse(const CAEndpoint_t *endpoint, if (responseInfo->info.payload) { result = OCParsePayload(&response->payload, + CAToOCPayloadFormat(responseInfo->info.payloadFormat), PAYLOAD_TYPE_PRESENCE, responseInfo->info.payload, responseInfo->info.payloadSize); @@ -1694,6 +1697,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp if (OCResultToSuccess(response->result) || PAYLOAD_TYPE_REPRESENTATION == type) { if (OC_STACK_OK != OCParsePayload(&response->payload, + CAToOCPayloadFormat(responseInfo->info.payloadFormat), type, responseInfo->info.payload, responseInfo->info.payloadSize)) @@ -2135,10 +2139,11 @@ OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest) protocolRequest->numRcvdVendorSpecificHeaderOptions, protocolRequest->observationOption, protocolRequest->qos, protocolRequest->query, protocolRequest->rcvdVendorSpecificHeaderOptions, - protocolRequest->payload, protocolRequest->requestToken, - protocolRequest->tokenLength, protocolRequest->resourceUrl, - protocolRequest->reqTotalSize, protocolRequest->acceptFormat, - protocolRequest->acceptVersion, &protocolRequest->devAddr); + protocolRequest->payloadFormat, protocolRequest->payload, + protocolRequest->requestToken, protocolRequest->tokenLength, + protocolRequest->resourceUrl, protocolRequest->reqTotalSize, + protocolRequest->acceptFormat, protocolRequest->acceptVersion, + &protocolRequest->devAddr); if (OC_STACK_OK != result) { OIC_LOG(ERROR, TAG, "Error adding server request"); @@ -2243,6 +2248,7 @@ void OCHandleRequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque if ((requestInfo->info.payload) && (0 < requestInfo->info.payloadSize)) { + serverRequest.payloadFormat = CAToOCPayloadFormat(requestInfo->info.payloadFormat); serverRequest.reqTotalSize = requestInfo->info.payloadSize; serverRequest.payload = (uint8_t *) OICMalloc(requestInfo->info.payloadSize); if (!serverRequest.payload) @@ -3232,14 +3238,6 @@ OCStackResult OCDoRequest(OCDoHandle *handle, if (payload) { - if((result = - OCConvertPayload(payload, &requestInfo.info.payload, &requestInfo.info.payloadSize)) - != OC_STACK_OK) - { - OIC_LOG(ERROR, TAG, "Failed to create CBOR Payload"); - goto exit; - } - uint16_t payloadVersion = OC_SPEC_VERSION_VALUE; CAPayloadFormat_t payloadFormat = CA_FORMAT_APPLICATION_CBOR; // From OCF onwards, check version option settings @@ -3272,6 +3270,15 @@ OCStackResult OCDoRequest(OCDoHandle *handle, requestInfo.info.payloadVersion = payloadVersion; requestInfo.info.payloadFormat = payloadFormat; + + if((result = + OCConvertPayload(payload, CAToOCPayloadFormat(requestInfo.info.payloadFormat), + &requestInfo.info.payload, &requestInfo.info.payloadSize)) + != OC_STACK_OK) + { + OIC_LOG(ERROR, TAG, "Failed to create CBOR Payload"); + goto exit; + } } else { diff --git a/resource/csdk/stack/src/oickeepalive.c b/resource/csdk/stack/src/oickeepalive.c index 91b0147..68c72b3 100644 --- a/resource/csdk/stack/src/oickeepalive.c +++ b/resource/csdk/stack/src/oickeepalive.c @@ -472,7 +472,7 @@ OCEntityHandlerResult HandleKeepAlivePOSTRequest(OCServerRequest *request, } OCPayload *ocPayload = NULL; - OCParsePayload(&ocPayload, PAYLOAD_TYPE_REPRESENTATION, + OCParsePayload(&ocPayload, request->payloadFormat, PAYLOAD_TYPE_REPRESENTATION, request->payload, request->payloadSize); OCRepPayload *repPayload = (OCRepPayload *)ocPayload; diff --git a/resource/csdk/stack/src/oicresourcedirectory.c b/resource/csdk/stack/src/oicresourcedirectory.c index 80a002b..3e18cd2 100644 --- a/resource/csdk/stack/src/oicresourcedirectory.c +++ b/resource/csdk/stack/src/oicresourcedirectory.c @@ -199,13 +199,12 @@ static OCStackResult ResourcePayloadCreate(sqlite3_stmt *stmt, OCDiscoveryPayloa resourcePayload->bitmap = (uint8_t)(bitmap & (OC_OBSERVABLE | OC_DISCOVERABLE)); resourcePayload->secure = ((bitmap & OC_SECURE) != 0); - const char address[] = "SELECT di, address FROM RD_DEVICE_LIST " + const char address[] = "SELECT di FROM RD_DEVICE_LIST " "INNER JOIN RD_DEVICE_LINK_LIST ON RD_DEVICE_LINK_LIST.DEVICE_ID = RD_DEVICE_LIST.ID " "WHERE RD_DEVICE_LINK_LIST.DEVICE_ID=@deviceId"; int addressSize = (int)sizeof(address); const uint8_t di_index = 0; - const uint8_t address_index = 1; sqlite3_stmt *stmt1 = 0; VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, address, addressSize, &stmt1, NULL)); @@ -215,14 +214,7 @@ static OCStackResult ResourcePayloadCreate(sqlite3_stmt *stmt, OCDiscoveryPayloa if (SQLITE_ROW == res || SQLITE_DONE == res) { const unsigned char *di = sqlite3_column_text(stmt1, di_index); - const unsigned char *tempAddress = sqlite3_column_text(stmt1, address_index); - OIC_LOG_V(DEBUG, TAG, " %s %s", di, tempAddress); - discPayload->baseURI = OICStrdup((char *)tempAddress); - if (!discPayload->baseURI) - { - result = OC_STACK_NO_MEMORY; - goto exit; - } + OIC_LOG_V(DEBUG, TAG, " %s", di); discPayload->sid = OICStrdup((char *)di); if (!discPayload->sid) { diff --git a/resource/csdk/stack/test/cbortests.cpp b/resource/csdk/stack/test/cbortests.cpp index 3518245..9b7bcb2 100644 --- a/resource/csdk/stack/test/cbortests.cpp +++ b/resource/csdk/stack/test/cbortests.cpp @@ -107,7 +107,8 @@ TEST_F(CborByteStringTest, ByteStringConvertParseTest) // Convert OCPayload to CBOR uint8_t *payload_cbor = NULL; size_t payload_cbor_size = 0; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*) payload_in, &payload_cbor, &payload_cbor_size)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*) payload_in, OC_FORMAT_CBOR, + &payload_cbor, &payload_cbor_size)); #ifdef CBOR_BIN_STRING_DEBUG FILE *fp = fopen("binstring.cbor", "wb+"); @@ -120,7 +121,7 @@ TEST_F(CborByteStringTest, ByteStringConvertParseTest) // Parse CBOR back to OCPayload OCPayload* payload_out = NULL; - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&payload_out, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&payload_out, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, payload_cbor, payload_cbor_size)); OCByteString quakedata_out = {NULL, 0}; @@ -194,7 +195,8 @@ TEST_F(CborByteStringTest, ByteStringArrayConvertParseTest ) // Convert OCPayload to CBOR uint8_t *payload_cbor = NULL; size_t payload_cbor_size = 0; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*) payload_in, &payload_cbor, &payload_cbor_size)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*) payload_in, OC_FORMAT_CBOR, + &payload_cbor, &payload_cbor_size)); #ifdef CBOR_BIN_STRING_DEBUG FILE *fp = fopen("binstringarr.cbor", "wb+"); if (fp) @@ -206,7 +208,7 @@ TEST_F(CborByteStringTest, ByteStringArrayConvertParseTest ) // Parse CBOR back to OCPayload OCPayload* payload_out = NULL; - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&payload_out, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&payload_out, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, payload_cbor, payload_cbor_size)); OCByteString* quakedata_out = NULL; @@ -252,7 +254,8 @@ TEST(CborHeterogeneousArrayTest, ConvertParseTest) // Convert OCPayload to CBOR uint8_t *payload_cbor = NULL; size_t payload_cbor_size = 0; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*) payload_in, &payload_cbor, &payload_cbor_size)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*) payload_in, OC_FORMAT_CBOR, + &payload_cbor, &payload_cbor_size)); #ifdef CBOR_BIN_STRING_DEBUG FILE *fp = fopen("binstringhetarr.cbor", "wb+"); if (fp) @@ -275,7 +278,7 @@ TEST(CborHeterogeneousArrayTest, ConvertParseTest) // Parse CBOR back to OCPayload OCPayload* payload_out = NULL; - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&payload_out, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&payload_out, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, payload_cbor, payload_cbor_size)); // Compare values diff --git a/resource/include/OCSerialization.h b/resource/include/OCSerialization.h index a3ee22b..36050a7 100644 --- a/resource/include/OCSerialization.h +++ b/resource/include/OCSerialization.h @@ -105,19 +105,24 @@ namespace OC epsVector = EpsLLToVector(eps); } - if (payload->baseURI) + m_resources.push_back(std::shared_ptr( + new OC::OCResource(cw, currentDevAddr, + std::string(res->uri), + std::string(payload->sid), + res->bitmap, + StringLLToVector(res->types), + StringLLToVector(res->interfaces), + epsVector + ))); + +#ifdef TCP_ADAPTER + if (res->tcpPort != 0) { - OCDevAddr rdPubAddr = currentDevAddr; - - std::string baseURI = std::string(payload->baseURI); - size_t len = baseURI.length(); - int addressLen = baseURI.find_first_of(":"); - std::string ipaddress = baseURI.substr(0, addressLen); - int port = atoi(baseURI.substr(addressLen + 1, len).c_str()); - OICStrcpy(rdPubAddr.addr, addressLen + 1, ipaddress.c_str()); - rdPubAddr.port = port; + OCDevAddr tcpDevAddr = currentDevAddr; + tcpDevAddr.port = res->tcpPort; + tcpDevAddr.adapter = OC_ADAPTER_TCP; m_resources.push_back(std::shared_ptr( - new OC::OCResource(cw, rdPubAddr, + new OC::OCResource(cw, tcpDevAddr, std::string(res->uri), std::string(payload->sid), res->bitmap, @@ -126,36 +131,7 @@ namespace OC epsVector ))); } - else - { - m_resources.push_back(std::shared_ptr( - new OC::OCResource(cw, currentDevAddr, - std::string(res->uri), - std::string(payload->sid), - res->bitmap, - StringLLToVector(res->types), - StringLLToVector(res->interfaces), - epsVector - ))); - -#ifdef TCP_ADAPTER - if (res->tcpPort != 0) - { - OCDevAddr tcpDevAddr = currentDevAddr; - tcpDevAddr.port = res->tcpPort; - tcpDevAddr.adapter = OC_ADAPTER_TCP; - m_resources.push_back(std::shared_ptr( - new OC::OCResource(cw, tcpDevAddr, - std::string(res->uri), - std::string(payload->sid), - res->bitmap, - StringLLToVector(res->types), - StringLLToVector(res->interfaces), - epsVector - ))); - } #endif - } res = res->next; } payload = payload->next; diff --git a/resource/unittests/OCRepresentationEncodingTest.cpp b/resource/unittests/OCRepresentationEncodingTest.cpp index f48f9af..e0c3a45 100644 --- a/resource/unittests/OCRepresentationEncodingTest.cpp +++ b/resource/unittests/OCRepresentationEncodingTest.cpp @@ -87,8 +87,8 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; OCPayload* parsedDevice; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)device, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)device, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OICFree(cborData); OCRepPayload *parsedRep = (OCRepPayload *)parsedDevice; @@ -146,8 +146,8 @@ namespace OCRepresentationEncodingTest dt1[0] = OICStrdup("ocf.res.1.1.0"); dt1[1] = OICStrdup("ocf.sh.1.1.0"); OCRepPayloadSetStringArray(device, OC_RSRVD_DATA_MODEL_VERSION, (const char**)dt1, dim1); - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)device, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)device, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OICFree(cborData); OICFree(dt1[0]); OICFree(dt1[1]); @@ -209,8 +209,8 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; OCPayload* parsedPlatform = NULL; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)platform, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedPlatform, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)platform, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedPlatform, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OICFree(cborData); OCRepPayload *platform1 = (OCRepPayload *)parsedPlatform; @@ -300,8 +300,8 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)presence, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_PRESENCE, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)presence, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_PRESENCE, cborData, cborSize)); OCPayloadDestroy((OCPayload*)presence); OICFree(cborData); @@ -339,8 +339,8 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload*)cstart); OICFree(cborData); @@ -387,8 +387,8 @@ namespace OCRepresentationEncodingTest uint8_t *cborData = NULL; size_t cborSize = 0; OCPayload *cparsed = NULL; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload*)cstart); OICFree(cborData); @@ -437,9 +437,9 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload*)cstart); OICFree(cborData); @@ -512,8 +512,8 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload *)cstart); OICFree(cborData); @@ -608,8 +608,8 @@ namespace OCRepresentationEncodingTest uint8_t* cborData; size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload *)cstart); OICFree(cborData); @@ -706,9 +706,9 @@ namespace OCRepresentationEncodingTest uint8_t *cborData; size_t cborSize; OCPayload *cparsed; - OCStackResult result = OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize); + OCStackResult result = OCConvertPayload((OCPayload *)cstart, OC_FORMAT_CBOR, &cborData, &cborSize); EXPECT_EQ(OC_STACK_OK, result); - result = OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + result = OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize); EXPECT_EQ(OC_STACK_OK, result); @@ -869,8 +869,8 @@ namespace OCRepresentationEncodingTest uint8_t *cborData; size_t cborSize; OCPayload *cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload *)cstart); OICFree(cborData); @@ -1021,8 +1021,8 @@ namespace OCRepresentationEncodingTest uint8_t *cborData; size_t cborSize; OCPayload *cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCPayloadDestroy((OCPayload *)cstart); OICFree(cborData); @@ -1076,8 +1076,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1110,8 +1110,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1144,8 +1144,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1177,8 +1177,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1212,8 +1212,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1249,8 +1249,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1286,8 +1286,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1323,8 +1323,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_DISCOVERY, cborData, cborSize)); EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed)); @@ -1353,8 +1353,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1378,8 +1378,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1404,8 +1404,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1430,8 +1430,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1458,8 +1458,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1488,8 +1488,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1518,8 +1518,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1548,8 +1548,8 @@ namespace OCRepresentationEncodingTest size_t cborSize; OCPayload* cparsed; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload* parsedPayload = (OCRepPayload*)cparsed; @@ -1591,8 +1591,8 @@ namespace OCRepresentationEncodingTest size_t cborSize = 0; OCPayload *cparsed = NULL; - EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)repPayload, &cborData, &cborSize)); - EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION, + EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)repPayload, OC_FORMAT_CBOR, &cborData, &cborSize)); + EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize)); OCRepPayload *parsedPayload = (OCRepPayload *)cparsed; -- 2.7.4