- Uses the resource attribute of OCResource for storing and retrieving device and platform values.
- Removed global savedDeviceInfo and savedPlatformInfo. The information passed via
OCSetDeviceInfo and OCSetPlatformInfo is stored in rsrcAttributes.
- OCAttribute type change from char * to void * to store generic value, this was part of OCResource but was not used.
- Payload type PAYLOAD_TYPE_DEVICE and PAYLOAD_TYPE_PLATFORM is removed from PAYLOAD_TYPE as this was used only internally.
- Payload convert and parse for payload type device and platform is removed, as device and payload uri uses
OCRepresentation payload type.
- Delete function to delete resource attributes.
- OCDevicePayloadCreate and OCPlatformCreate is removed as this was only used internally, all values are now stored in
resource attributes.
- Moves OCSetDeviceInfo and OCSetPlatformInfo from ocstack to ocresource to avoid duplicate checking.
- Add set and get API to set parameter for /oic/d and /oic/p.
- OCGetResourceHandleAtUri accesible without ifdef RD_CLIENT.
- Updated Unit test to test the functionality.
- Add the OCSSetParam and OCGetParam in C++ and Java
Change-Id: If822ae95a70e681121528679de8da1375718de0c
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14377
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
}
}
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue0
+ (JNIEnv *env, jclass clazz, jint jType, jstring jPropName, jobjectArray jPropValue)
+{
+ try
+ {
+ OCPayloadType type = (OCPayloadType)jType;
+ std::string propName;
+ std::vector<std::string> propValue;
+ if (jPropName)
+ {
+ propName = env->GetStringUTFChars(jPropName, nullptr);
+ }
+ if (jPropValue)
+ {
+ JniUtils::convertJavaStrArrToStrVector(env, jPropValue, propValue);
+ }
+ OCStackResult result = OCPlatform::setPropertyValue(type, propName, propValue);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Failed to set property");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("Error is due to %s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+
+}
+
+/*
+* Class: org_iotivity_base_OcPlatform
+* Method: setPropertyValue0
+* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue1
+ (JNIEnv *env, jclass clazz, jint jType, jstring jPropName, jstring jPropValue)
+{
+ try
+ {
+ OCPayloadType type = (OCPayloadType)jType;
+ std::string propName;
+ std::string propValue;
+ if (jPropName)
+ {
+ propName = env->GetStringUTFChars(jPropName, nullptr);
+ }
+ if (jPropValue)
+ {
+ propValue = env->GetStringUTFChars(jPropValue, nullptr);
+ }
+ OCStackResult result = OCPlatform::setPropertyValue(type, propName, propValue);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Failed to set property");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("Error is due to %s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+}
+
+/*
+* Class: org_iotivity_base_OcPlatform
+* Method: getPropertyValue
+* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPropertyValue0
+ (JNIEnv *env, jclass clazz, jint jType, jstring jPropName, jstring jPropValue)
+{
+ try
+ {
+ OCPayloadType type = (OCPayloadType) jType;
+ std::string propName;
+ std::string propValue;
+
+ if (jPropName)
+ {
+ propName = env->GetStringUTFChars(jPropName, nullptr);
+ }
+ OCStackResult result = OCPlatform::getPropertyValue(type, propName, propValue);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Failed to get property value.");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("Error is due to %s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+}
+
/*
* Class: org_iotivity_base_OcPlatform
* Method: unregisterResource0
/*
* Class: org_iotivity_base_OcPlatform
+ * Method: setPropertyValue0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
+ */
+ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue0
+ (JNIEnv *, jclass, jint, jstring, jobjectArray);
+
+ /*
+ * Class: org_iotivity_base_OcPlatform
+ * Method: setPropertyValue1
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue1
+ (JNIEnv *, jclass, jint, jstring, jstring);
+
+ /*
+ * Class: org_iotivity_base_OcPlatform
+ * Method: getPropertyValue0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPropertyValue0
+ (JNIEnv *, jint, jstring, jstring);
+
+ /*
+ * Class: org_iotivity_base_OcPlatform
* Method: unregisterResource0
* Signature: (Lorg/iotivity/base/OcResourceHandle;)V
*/
) throws OcException;
/**
+ * Set param Info
+ *
+ * @param ocDeviceInfo object containing all the device specific information
+ * @throws OcException if failure
+ */
+ public static void setPropertyValue(
+ int path, String propName, String propValue) throws OcException {
+ OcPlatform.initCheck();
+ OcPlatform.setPropertyValue0(path, propName, propValue);
+ }
+
+ public static void setPropertyValue(
+ int path, String propName, List<String> propValue) throws OcException {
+ OcPlatform.initCheck();
+ OcPlatform.setPropertyValue1(path, propName, propValue.toArray(new String[propValue.size()]));
+ }
+
+ public static void getPropertyValue(
+ int path, String propName, String propValue) throws OcException {
+ OcPlatform.initCheck();
+ OcPlatform.getPropertyValue0(path, propName, propValue);
+ }
+
+ private static native void setPropertyValue0(
+ int path,
+ String propName,
+ String propValue
+ ) throws OcException;
+
+
+ private static native void setPropertyValue1(
+ int path,
+ String propName,
+ String[] propValue
+ ) throws OcException;
+
+ private static native void getPropertyValue0(
+ int path,
+ String propName,
+ String propValue
+ ) throws OcException;
+
+ /**
* Register Platform Info
*
* @param ocPlatformInfo object containing all the platform specific information
ConvertStrToUuid
convertTriggerEnumToString
+FindResourceByUri
OCBindResource
OCBindResourceHandler
OCBindResourceInsToResource
OCDoResponse
OCEncodeAddressForRFC6874
OCFreeOCStringLL
+OCGetDeviceId
OCGetDirectPairedDevices
+OCGetHeaderOption
OCGetNumberOfResources
OCGetNumberOfResourceInterfaces
OCGetNumberOfResourceTypes
+OCGetPropertyValue
OCGetResourceHandle
OCGetResourceHandleAtUri
OCGetResourceHandleFromCollection
OCNotifyAllObservers
OCNotifyListOfObservers
OCPayloadDestroy
-OCPlatformPayloadCreate
OCPresencePayloadCreate
OCProcess
OCRegisterPersistentStorageHandler
OCResourcePayloadAddStringLL
OCSecurityPayloadCreate
OCSetDefaultDeviceEntityHandler
+OCSetDeviceId
OCSetDeviceInfo
+OCSetHeaderOption
OCSetPlatformInfo
+OCSetPropertyValue
OCStartPresence
OCStop
OCStopPresence
OCStopMulticastServer
OCUnBindResource
-OCSetHeaderOption
-OCGetHeaderOption
-OCGetDeviceId
-OCSetDeviceId
-FindResourceByUri
/** The name of the attribute; used to look up the attribute in list.
* for a given attribute SHOULD not be changed once assigned.
*/
- const char *attrName;
+ char *attrName;
- /** value of the attribute as string.*/
- char *attrValue;
+ /** value of the attribute as void. To support both string and @OCStringLL value*/
+ void *attrValue;
} OCAttribute;
/**
const OCClientResponse *response);
#endif
+/**
+ * Delete all of the dynamically allocated elements that were created for the resource attributes.
+ *
+ * @param resourceAttr Specified resource attribute.
+ */
+void OCDeleteResourceAttributes(OCAttribute *rsrcAttributes);
+
#ifdef __cplusplus
}
#endif // __cplusplus
void OCDiscoveryResourceDestroy(OCResourcePayload* payload);
void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
-// Device Payload
-OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
- const OCStringLL *types, const char* specVer, const char* dmVer);
-void OCDevicePayloadDestroy(OCDevicePayload* payload);
-
-// Platform Payload
-OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
-OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
-void OCPlatformInfoDestroy(OCPlatformInfo *info);
-void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
-
// Presence Payload
OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
OCPresenceTrigger trigger, const char* resourceType);
*/
OCStackResult OCGetResourceIns(OCResourceHandle handle, uint8_t *ins);
+#endif
+
/**
- * This function gets a resource handle by resource uri.
- *
- * @param uri Uri of Resource to get Resource handle.
- *
- * @return Found resource handle or NULL if not found.
- */
+* This function gets a resource handle by resource uri.
+*
+* @param uri Uri of Resource to get Resource handle.
+*
+* @return Found resource handle or NULL if not found.
+*/
OCResourceHandle OCGetResourceHandleAtUri(const char *uri);
-#endif
-
#ifdef RD_SERVER
/**
* Search the RD database for queries.
size_t outputSize,
const char* inputAddress,
const char* end);
+
+/**
+ * Set the value of /oic/d and /oic/p properties. This function is a generic function that sets for
+ * all OCF defined properties.
+ *
+ * @param type the payload type for device and platform as defined in @ref OCPayloadType.
+ * @param propName the pre-defined property as per OCF spec.
+ * @param value the value of the property to be set.
+ *
+ * @return ::OC_STACK_OK on success and other value otherwise.
+ */
+OCStackResult OCSetPropertyValue(OCPayloadType type, const char *propName, const void *value);
+
+/**
+ * Get the value of /oic/d and /oic/p properties. This function is a generic function that get value
+ * for all OCF defined properties.
+ *
+ * @param type the payload type for device and platform as defined in @ref OCPayloadType.
+ * @param propName the pre-defined as per OCF spec.
+ * @param value this holds the return value. In case of error will be set to NULL.
+ *
+ * @return ::OC_STACK_OK on success and other value otherwise.
+ */
+OCStackResult OCGetPropertyValue(OCPayloadType type, const char *propName, void **value);
+
#ifdef __cplusplus
}
#endif // __cplusplus
#define MAX_QUERY_LENGTH (256)
#endif
+
/**
* Maximum length of the Manufacturer name supported by the server
* for manufacturer name.
+ * @deprecated use MAX_PLATFORM_NAME_LENGTH instead.
*/
-#define MAX_MANUFACTURER_NAME_LENGTH (16)
+#define MAX_MANUFACTURER_NAME_LENGTH (64)
/**
* Maximum length of the URL to the Manufacturer details supported by
* the server.
+ * @deprecated use MAX_PLATFORM_URL_LENGTH instead.
+ */
+#define MAX_MANUFACTURER_URL_LENGTH (256)
+
+/**
+ * Maximum length of the value supported by the server
+ * for platform property of type string.
+ */
+#define MAX_PLATFORM_NAME_LENGTH (64)
+
+/**
+ * Maximum length of the URL supported by the server
+ * for platform property of type url.
*/
-#define MAX_MANUFACTURER_URL_LENGTH (32)
+#define MAX_PLATFORM_URL_LENGTH (256)
/**
* Maximum number of resources which can be contained inside collection
/** System time for the platform. */
#define OC_RSRVD_SYSTEM_TIME "st"
+/** VID for the platform. */
+#define OC_RSRVD_VID "vid"
/**
* Device.
*/
#define OC_SPEC_VERSION "core.1.1.0"
/** Device Data Model version.*/
-#define OC_DATA_MODEL_VERSION "res.1.1.0"
-
+#define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.1.0"
/**
* These provide backward compatibility - their use is deprecated.
*/
/**
* This structure describes the platform properties. All non-Null properties will be
* included in a platform discovery request.
+ * @deprecated: Use OCSetPropertyValue to set platform value.
*/
typedef struct
{
* This structure is expected as input for device properties.
* device name is mandatory and expected from the application.
* device id of type UUID will be generated by the stack.
+ * @deprecated: Use OCSetPropertyValue to set device value.
*/
typedef struct
{
PAYLOAD_TYPE_INVALID,
/** The payload is an OCDiscoveryPayload */
PAYLOAD_TYPE_DISCOVERY,
- /** The payload is an OCDevicePayload */
+ /** The payload of the device */
PAYLOAD_TYPE_DEVICE,
- /** The payload is an OCPlatformPayload */
+ /** The payload type of the platform */
PAYLOAD_TYPE_PLATFORM,
/** The payload is an OCRepPayload */
PAYLOAD_TYPE_REPRESENTATION,
typedef struct
{
OCPayload base;
- char *sid;
- char* deviceName;
- char* specVersion;
- OCStringLL *dataModelVersions;
- OCStringLL *interfaces;
- OCStringLL *types;
-} OCDevicePayload;
-
-typedef struct
-{
- OCPayload base;
- char* uri;
- OCPlatformInfo info;
- OCStringLL* rt;
- OCStringLL* interfaces;
-} OCPlatformPayload;
-
-typedef struct
-{
- OCPayload base;
uint8_t* securityData;
size_t payloadSize;
} OCSecurityPayload;
}
}
-INLINE_API void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
-{
- OIC_LOG(level, PL_TAG, "Payload Type: Device");
- OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
- OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
- OIC_LOG_V(level, PL_TAG, "\tSpec Version:%s", payload->specVersion);
- if (payload->dataModelVersions)
- {
- OIC_LOG(level, PL_TAG, "\tData Model Version:");
- for (OCStringLL *strll = payload->dataModelVersions; strll; strll = strll->next)
- {
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- }
- }
- if (payload->types)
- {
- OIC_LOG(level, PL_TAG, "\tResource Type:");
- for (OCStringLL *strll = payload->types; strll; strll = strll->next)
- {
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- }
- }
- if (payload->interfaces)
- {
- OIC_LOG(level, PL_TAG, "\tInterface:");
- for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
- {
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- }
- }
-}
-
-INLINE_API void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
-{
- OIC_LOG(level, PL_TAG, "Payload Type: Platform");
- OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
- OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
- OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
- OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
- OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
- OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
- OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
- OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
- OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
- OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
- OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
- OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
-
- if (payload->rt)
- {
- OIC_LOG(level, PL_TAG, "\tResource Types:");
- for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
- {
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- }
- }
- if (payload->interfaces)
- {
- OIC_LOG(level, PL_TAG, "\tResource Interfaces:");
- for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
- {
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- }
- }
-}
-
INLINE_API void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
{
OIC_LOG(level, PL_TAG, "Payload Type: Presence");
case PAYLOAD_TYPE_DISCOVERY:
OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
break;
- case PAYLOAD_TYPE_DEVICE:
- OCPayloadLogDevice(level, (OCDevicePayload*)payload);
- break;
- case PAYLOAD_TYPE_PLATFORM:
- OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
- break;
case PAYLOAD_TYPE_PRESENCE:
OCPayloadLogPresence(level, (OCPresencePayload*)payload);
break;
bool success = true;
- if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
+ if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_PLATFORM_NAME_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
- if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
+ if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_PLATFORM_URL_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
bool success = true;
- if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
+ if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_PLATFORM_NAME_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
- if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
+ if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_PLATFORM_URL_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
case PAYLOAD_TYPE_DISCOVERY:
OCDiscoveryPayloadDestroy((OCDiscoveryPayload*)payload);
break;
- case PAYLOAD_TYPE_DEVICE:
- OCDevicePayloadDestroy((OCDevicePayload*)payload);
- break;
- case PAYLOAD_TYPE_PLATFORM:
- OCPlatformPayloadDestroy((OCPlatformPayload*)payload);
- break;
case PAYLOAD_TYPE_PRESENCE:
OCPresencePayloadDestroy((OCPresencePayload*)payload);
break;
break;
}
}
+
OCRepPayload* OCRepPayloadCreate()
{
OCRepPayload* payload = (OCRepPayload*)OICCalloc(1, sizeof(OCRepPayload));
bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, const char *value)
{
- char *dup = OICStrdup(value);
- VERIFY_PARAM_NON_NULL(TAG, dup, "Failed copying string");
+ char *dup = NULL;
VERIFY_PARAM_NON_NULL(TAG, value, "Invalid Parameters");
+ dup = OICStrdup(value);
+ VERIFY_PARAM_NON_NULL(TAG, dup, "Failed copying string");
if (!*stringLL)
{
OICFree(payload);
}
-OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
- const OCStringLL *types, const char* specVer, const char* dmVer)
-{
-
- OCDevicePayload* payload = (OCDevicePayload*)OICCalloc(1, sizeof(OCDevicePayload));
-
- if (!payload)
- {
- return NULL;
- }
-
- payload->base.type = PAYLOAD_TYPE_DEVICE;
- payload->sid = OICStrdup(sid);
- if (sid && !payload->sid)
- {
- goto exit;
- }
-
- payload->deviceName = OICStrdup(dname);
- if (dname && !payload->deviceName)
- {
- goto exit;
- }
-
- payload->specVersion = OICStrdup(specVer);
- if (specVer && !payload->specVersion)
- {
- goto exit;
- }
-
- payload->dataModelVersions = OCCreateOCStringLL(dmVer);
- if (!payload->dataModelVersions || (dmVer && !payload->dataModelVersions->value))
- {
- goto exit;
- }
-
- OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_DEFAULT);
- OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_READ);
-
- payload->types = CloneOCStringLL((OCStringLL *)types);
- if (types && !payload->types)
- {
- goto exit;
- }
-
- return payload;
-
-exit:
- OCDevicePayloadDestroy((OCDevicePayload*)payload);
- return NULL;
-}
-
-void OCDevicePayloadDestroy(OCDevicePayload* payload)
-{
- if (!payload)
- {
- return;
- }
-
- OICFree(payload->sid);
- OICFree(payload->deviceName);
- OICFree(payload->specVersion);
- OCFreeOCStringLL(payload->dataModelVersions);
- OCFreeOCStringLL(payload->types);
- OCFreeOCStringLL(payload->interfaces);
- OICFree(payload);
-}
-
-static void OCCopyPlatformInfo(const OCPlatformInfo* platformInfo, OCPlatformPayload* target)
-{
- if (!platformInfo || !target)
- {
- return;
- }
-
- target->info.platformID = OICStrdup(platformInfo->platformID);
- target->info.manufacturerName = OICStrdup(platformInfo->manufacturerName);
- target->info.manufacturerUrl = OICStrdup(platformInfo->manufacturerUrl);
- target->info.modelNumber = OICStrdup(platformInfo->modelNumber);
- target->info.dateOfManufacture = OICStrdup(platformInfo->dateOfManufacture);
- target->info.platformVersion = OICStrdup(platformInfo->platformVersion);
- target->info.operatingSystemVersion = OICStrdup(platformInfo->operatingSystemVersion);
- target->info.hardwareVersion = OICStrdup(platformInfo->hardwareVersion);
- target->info.firmwareVersion = OICStrdup(platformInfo->firmwareVersion);
- target->info.supportUrl = OICStrdup(platformInfo->supportUrl);
- target->info.systemTime = OICStrdup(platformInfo->systemTime);
-}
-
-OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo)
-{
- OCPlatformPayload* payload = (OCPlatformPayload*)OICCalloc(1, sizeof(OCPlatformPayload));
- if (!payload)
- {
- return NULL;
- }
-
- payload->base.type = PAYLOAD_TYPE_PLATFORM;
-
- payload->interfaces = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
- if (!payload->interfaces)
- {
- return NULL;
- }
- payload->interfaces->value = OICStrdup(OC_RSRVD_INTERFACE_READ);
- payload->rt = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
- if (!payload->rt)
- {
- return NULL;
- }
- payload->rt->value = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
- payload->info = *platformInfo;
-
- return payload;
-}
-
-OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo)
-{
- OCPlatformPayload* payload = (OCPlatformPayload*)OICCalloc(1, sizeof(OCPlatformPayload));
-
- if (!payload)
- {
- return NULL;
- }
-
- payload->base.type = PAYLOAD_TYPE_PLATFORM;
- OCResourcePayloadAddStringLL(&payload->rt, OC_RSRVD_RESOURCE_TYPE_PLATFORM);
-
- OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_DEFAULT);
- OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_READ);
-
- OCCopyPlatformInfo(platformInfo, payload);
-
- return payload;
-}
-
-void OCPlatformInfoDestroy(OCPlatformInfo *info)
-{
- OICFree(info->platformID);
- OICFree(info->manufacturerName);
- OICFree(info->manufacturerUrl);
- OICFree(info->modelNumber);
- OICFree(info->dateOfManufacture);
- OICFree(info->platformVersion);
- OICFree(info->operatingSystemVersion);
- OICFree(info->hardwareVersion);
- OICFree(info->firmwareVersion);
- OICFree(info->supportUrl);
- OICFree(info->systemTime);
-}
-
-void OCPlatformPayloadDestroy(OCPlatformPayload* payload)
-{
- if (!payload)
- {
- return;
- }
- OICFree(payload->uri);
- OCPlatformInfoDestroy(&payload->info);
- OCFreeOCStringLL(payload->rt);
- OCFreeOCStringLL(payload->interfaces);
- OICFree(payload);
-}
-
OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
OCPresenceTrigger trigger, const char* resourceType)
{
// Discovery Links Map Length.
#define LINKS_MAP_LEN 4
-// Default data model versions in CVS form
-#define DEFAULT_DATA_MODEL_VERSIONS "res.1.1.0,sh.1.1.0"
-
// 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 OCConvertDevicePayload(OCDevicePayload *payload, uint8_t *outPayload,
- size_t *size);
-static int64_t OCConvertPlatformPayload(OCPlatformPayload *payload, 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,
{
case PAYLOAD_TYPE_DISCOVERY:
return OCConvertDiscoveryPayload((OCDiscoveryPayload*)payload, outPayload, size);
- case PAYLOAD_TYPE_DEVICE:
- return OCConvertDevicePayload((OCDevicePayload*)payload, outPayload, size);
- case PAYLOAD_TYPE_PLATFORM:
- return OCConvertPlatformPayload((OCPlatformPayload*)payload, outPayload, size);
case PAYLOAD_TYPE_REPRESENTATION:
return OCConvertRepPayload((OCRepPayload*)payload, outPayload, size);
case PAYLOAD_TYPE_PRESENCE:
return checkError(err, &encoder, outPayload, size);
}
-static int64_t OCConvertDevicePayload(OCDevicePayload *payload, uint8_t *outPayload,
- size_t *size)
-{
- if (!payload)
- {
- return CborUnknownError;
- }
- int64_t err = CborNoError;
- CborEncoder encoder;
- char *dataModelVersions = 0;
-
- cbor_encoder_init(&encoder, outPayload, *size, 0);
- CborEncoder repMap;
- err |= cbor_encoder_create_map(&encoder, &repMap, CborIndefiniteLength);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating device map");
-
- // Resource Type
- if (payload->types)
- {
- OIC_LOG(INFO, TAG, "Payload has types");
- err |= OCStringLLJoin(&repMap, OC_RSRVD_RESOURCE_TYPE, payload->types);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding resource type tag/value.");
- }
-
- if (payload->interfaces)
- {
- OIC_LOG(INFO, TAG, "Payload has interface");
- err |= OCStringLLJoin(&repMap, OC_RSRVD_INTERFACE, payload->interfaces);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding interface type tag/value.");
- }
-
- // Device ID
- err |= AddTextStringToMap(&repMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1 , payload->sid);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding device id");
-
- // Device Name
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DEVICE_NAME,
- sizeof(OC_RSRVD_DEVICE_NAME) - 1, payload->deviceName);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding device name");
-
- // Device Spec Version
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_SPEC_VERSION,
- sizeof(OC_RSRVD_SPEC_VERSION) - 1, payload->specVersion);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding data spec version");
-
- // Device data Model Versions
- if (payload->dataModelVersions)
- {
- OIC_LOG(INFO, TAG, "Payload has data model versions");
- dataModelVersions = OCCreateString(payload->dataModelVersions);
- }
- else
- {
- dataModelVersions = OICStrdup(DEFAULT_DATA_MODEL_VERSIONS);
- }
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DATA_MODEL_VERSION,
- sizeof(OC_RSRVD_DATA_MODEL_VERSION) - 1, dataModelVersions);
- OICFree(dataModelVersions);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding data model versions");
-
- err |= cbor_encoder_close_container(&encoder, &repMap);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing device map");
-
-exit:
- return checkError(err, &encoder, outPayload, size);
-}
-
-static int64_t OCConvertPlatformPayload(OCPlatformPayload *payload, uint8_t *outPayload,
- size_t *size)
-{
- int64_t err = CborNoError;
- CborEncoder encoder;
-
- cbor_encoder_init(&encoder, outPayload, *size, 0);
-
- CborEncoder repMap;
- err |= cbor_encoder_create_map(&encoder, &repMap, CborIndefiniteLength);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating platform map");
-
- // Platform ID
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_PLATFORM_ID,
- sizeof(OC_RSRVD_PLATFORM_ID) - 1, payload->info.platformID);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding platform id");
-
- // MFG Name
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_MFG_NAME,
- sizeof(OC_RSRVD_MFG_NAME) - 1, payload->info.manufacturerName);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding mfg name");
-
- // MFG Url
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_MFG_URL,
- sizeof(OC_RSRVD_MFG_URL) - 1, payload->info.manufacturerUrl);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding mfg url");
-
- // Model Num
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_MODEL_NUM,
- sizeof(OC_RSRVD_MODEL_NUM) -1, payload->info.modelNumber);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding model num");
-
- // Date of Mfg
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_MFG_DATE,
- sizeof(OC_RSRVD_MFG_DATE) - 1, payload->info.dateOfManufacture);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding mfg date");
-
- // Platform Version
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_PLATFORM_VERSION,
- sizeof(OC_RSRVD_PLATFORM_VERSION) - 1, payload->info.platformVersion);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding platform version");
-
- // OS Version
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_OS_VERSION,
- sizeof(OC_RSRVD_OS_VERSION) - 1, payload->info.operatingSystemVersion);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding OS version");
-
- // Hardware Version
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_HARDWARE_VERSION,
- sizeof(OC_RSRVD_HARDWARE_VERSION) - 1, payload->info.hardwareVersion);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding HW version");
-
- // Firmware Version
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_FIRMWARE_VERSION,
- sizeof(OC_RSRVD_FIRMWARE_VERSION) - 1, payload->info.firmwareVersion);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding firmware version");
-
- // Support URL
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_SUPPORT_URL,
- sizeof(OC_RSRVD_SUPPORT_URL) - 1, payload->info.supportUrl);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding support url");
-
- // System Time
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_SYSTEM_TIME,
- sizeof(OC_RSRVD_SYSTEM_TIME) - 1, payload->info.systemTime);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding system time");
-
- // Resource type
- if (payload->rt)
- {
- err |= OCStringLLJoin(&repMap, OC_RSRVD_RESOURCE_TYPE, payload->rt);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding resource type.");
- }
-
- // Resource interfaces
- if (payload->interfaces)
- {
- err |= OCStringLLJoin(&repMap, OC_RSRVD_INTERFACE, payload->interfaces);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding platform interface type.");
- }
-
- // Close Map
- err |= cbor_encoder_close_container(&encoder, &repMap);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing rep map");
-
-exit:
- return checkError(err, &encoder, outPayload, size);
-}
-
static int64_t OCConvertArrayItem(CborEncoder *array, const OCRepPayloadValueArray *valArray,
size_t index)
{
#define TAG "OIC_RI_PAYLOADPARSE"
static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *arrayVal);
-static OCStackResult OCParseDevicePayload(OCPayload **outPayload, CborValue *arrayVal);
-static OCStackResult OCParsePlatformPayload(OCPayload **outPayload, 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);
case PAYLOAD_TYPE_DISCOVERY:
result = OCParseDiscoveryPayload(outPayload, &rootValue);
break;
- case PAYLOAD_TYPE_DEVICE:
- result = OCParseDevicePayload(outPayload, &rootValue);
- break;
- case PAYLOAD_TYPE_PLATFORM:
- result = OCParsePlatformPayload(outPayload, &rootValue);
- break;
case PAYLOAD_TYPE_REPRESENTATION:
result = OCParseRepPayload(outPayload, &rootValue);
break;
while (curPtr)
{
char *trimmed = InPlaceStringTrim(curPtr);
- if (trimmed[0] !='\0')
+ if (trimmed && strlen(trimmed) > 0)
{
if (!OCResourcePayloadAddStringLL(resource, trimmed))
{
return ret;
}
-static OCStackResult OCParseDevicePayload(OCPayload **outPayload, CborValue *rootValue)
-{
- OCStackResult ret = OC_STACK_INVALID_PARAM;
- CborError err = CborNoError;
- OCDevicePayload *out = NULL;
- VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid param outPayload");
- VERIFY_PARAM_NON_NULL(TAG, rootValue, "Invalid param rootValue");
-
- *outPayload = NULL;
-
- out = (OCDevicePayload *)OICCalloc(1, sizeof(OCDevicePayload));
- VERIFY_PARAM_NON_NULL(TAG, out, "Failed allocating device payload")
- out->base.type = PAYLOAD_TYPE_DEVICE;
- ret = OC_STACK_MALFORMED_RESPONSE;
-
- if (cbor_value_is_map(rootValue))
- {
- CborValue curVal;
- // Resource Type
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_RESOURCE_TYPE, &curVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find resource type tag");
-
- if (cbor_value_is_valid(&curVal))
- {
- err = OCParseStringLL(rootValue, OC_RSRVD_RESOURCE_TYPE, &out->types);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find rt type tag/value");
- }
-
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_INTERFACE, &curVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find interface tag");
- if (cbor_value_is_valid(&curVal))
- {
- err = OCParseStringLL(rootValue, OC_RSRVD_INTERFACE, &out->interfaces);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find interfaces tag/value");
- }
- // Device ID
- size_t len = 0;
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_ID, &curVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find device id tag");
- if (cbor_value_is_valid(&curVal))
- {
- if (cbor_value_is_byte_string(&curVal))
- {
- err = cbor_value_dup_byte_string(&curVal, (uint8_t **)&out->sid, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
- }
- else if (cbor_value_is_text_string(&curVal))
- {
- err = cbor_value_dup_text_string(&curVal, &out->sid, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
- }
- }
- // Device Name
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_NAME, &curVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find device name tag");
- if (cbor_value_is_valid(&curVal))
- {
- err = cbor_value_dup_text_string(&curVal, &out->deviceName, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find device name in device payload");
- }
- // Device Spec Version
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_SPEC_VERSION, &curVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find spec ver tag");
- if (cbor_value_is_valid(&curVal))
- {
- err = cbor_value_dup_text_string(&curVal, &out->specVersion, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find spec version in device payload");
- }
- // Data Model Versions
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_DATA_MODEL_VERSION, &curVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find data model versions tag");
- if (cbor_value_is_valid(&curVal))
- {
- size_t len = 0;
- char * str = NULL;
- err = cbor_value_dup_text_string(&curVal, &str, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find data model versions in device payload");
- out->dataModelVersions = OCCreateOCStringLL(str);
- OICFree(str);
- }
- err = cbor_value_advance(rootValue);
- VERIFY_CBOR_SUCCESS(TAG, err, "to advance device payload");
-
- *outPayload = (OCPayload *)out;
- return OC_STACK_OK;
- }
-
-exit:
- OCDevicePayloadDestroy(out);
- return ret;
-}
-
-static OCStackResult OCParsePlatformPayload(OCPayload **outPayload, CborValue *rootValue)
-{
- OCStackResult ret = OC_STACK_INVALID_PARAM;
- CborError err = CborNoError;
- OCPlatformInfo info = {0};
- OCStringLL* rt = NULL;
- OCStringLL* interfaces = NULL;
- OCPlatformPayload* out = NULL;
-
- VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid Parameter outPayload");
-
- if (cbor_value_is_map(rootValue))
- {
- CborValue repVal;
- size_t len = 0;
- ret = OC_STACK_MALFORMED_RESPONSE;
-
- // Platform ID
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_PLATFORM_ID, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find platform id tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.platformID), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find platformID in the platform payload");
- }
- // MFG Name
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_MFG_NAME, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find mfg name tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.manufacturerName), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find manufactureName in the platform payload");
- }
- // MFG URL
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_MFG_URL, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find mfg url tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.manufacturerUrl), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find manufactureUrl in the platform payload");
- }
- // Model Num
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_MODEL_NUM, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find model num tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.modelNumber), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find modelNumber in the platform payload");
- }
- // Date of Mfg
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_MFG_DATE, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find mfg date tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.dateOfManufacture), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find dateOfManufacture in the platform payload");
- }
- // Platform Version
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_PLATFORM_VERSION, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find platform ver tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.platformVersion), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find platformVersion in the platform payload");
- }
- // OS Version
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_OS_VERSION, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find os ver tag");
- if (cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.operatingSystemVersion), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find OSVersion in the platform payload");
- }
- // Hardware Version
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_HARDWARE_VERSION, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find hw ver tag");
- if(cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.hardwareVersion), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find HWVersion in the platform payload");
- }
- // Firmware Version
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_FIRMWARE_VERSION, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find fw ver tag");
- if(cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.firmwareVersion), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find firmwareVersion in the platform payload");
- }
- // Support URL
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_SUPPORT_URL, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find support url tag");
- if(cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.supportUrl), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find supportUrl in the platform payload");
- }
- // System Time
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_SYSTEM_TIME, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find sys time tag");
- if(cbor_value_is_valid(&repVal))
- {
- err = cbor_value_dup_text_string(&repVal, &(info.systemTime), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find systemTume in the platform payload");
- }
-
- // Resource type
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_RESOURCE_TYPE, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find resource type tag");
-
- if(cbor_value_is_valid(&repVal))
- {
- err = OCParseStringLL(rootValue, OC_RSRVD_RESOURCE_TYPE, &rt);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find resource type in the platform payload");
- }
-
- // Interface Types
- err = cbor_value_map_find_value(rootValue, OC_RSRVD_INTERFACE, &repVal);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find interface tag");
-
- if(cbor_value_is_valid(&repVal))
- {
- err = OCParseStringLL(rootValue, OC_RSRVD_INTERFACE, &interfaces);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find interfaces tag/value");
- }
-
- err = cbor_value_advance(rootValue);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find supportUrl in the platform payload");
-
- out = (OCPlatformPayload *)OCPlatformPayloadCreateAsOwner(&info);
- out->rt = rt;
- out->interfaces = interfaces;
- *outPayload = (OCPayload *)out;
- OIC_LOG_PAYLOAD(DEBUG, *outPayload);
- return OC_STACK_OK;
- }
-
-exit:
- OCPlatformInfoDestroy(&info);
- OIC_LOG(ERROR, TAG, "CBOR error In ParsePlatformPayload");
- return ret;
-}
-
static OCRepPayloadPropType DecodeCborType(CborType type)
{
switch (type)
/// Module Name
#define TAG "OIC_RI_RESOURCE"
-#define VERIFY_SUCCESS(op, successCode) { if (op != successCode) \
+#define VERIFY_SUCCESS(op) { if (op != (OC_STACK_OK)) \
{OIC_LOG_V(FATAL, TAG, "%s failed!!", #op); goto exit;} }
extern OCResource *headResource;
-static OCPlatformInfo savedPlatformInfo = {0};
-static OCDeviceInfo savedDeviceInfo = {0};
/**
* Prepares a Payload for response.
return result;
}
+bool appendOCStringLL(OCRepPayload *device, OCStringLL *dmv)
+{
+ int size = 0;
+ for (OCStringLL *ll = dmv; ll; ll = ll->next, size++);
+ size_t dim[MAX_REP_ARRAY_DEPTH] = {size, 0, 0};
+ char **dt = (char **)OICMalloc(sizeof(char *) * size);
+ int i = 0;
+ VERIFY_PARAM_NON_NULL(TAG, dt, "Data Model Version allocation failed.");
+ for (OCStringLL *ll = dmv; ll; ll = ll->next, i++)
+ {
+ dt[i] = OICStrdup(ll->value);
+ VERIFY_PARAM_NON_NULL(TAG, dt[i], "Data Model Version adding failed.");
+ }
+ if (!OCRepPayloadSetStringArrayAsOwner(device, OC_RSRVD_DATA_MODEL_VERSION, dt, dim))
+ {
+ goto exit;
+ }
+ return true;
+
+exit:
+ for (int i = 0; i < size; i++)
+ {
+ OICFree(dt[i]);
+ }
+ OICFree(dt);
+ return false;
+}
+
OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
OCRepPayload** payload)
{
OCAttribute *resAttrib = resourcePtr->rsrcAttributes;
while(resAttrib)
{
- OCRepPayloadSetPropString(tempPayload, resAttrib->attrName,
- resAttrib->attrValue);
+ if (resAttrib->attrName && resAttrib->attrValue)
+ {
+ if (0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, resAttrib->attrName))
+ {
+ appendOCStringLL(tempPayload, (OCStringLL *)resAttrib->attrValue);
+ }
+ else
+ {
+ OCRepPayloadSetPropString(tempPayload, resAttrib->attrName, (char *)resAttrib->attrValue);
+ }
+ }
resAttrib = resAttrib->next;
}
discPayload->uri = OICStrdup(OC_RSRVD_WELL_KNOWN_URI);
VERIFY_PARAM_NON_NULL(TAG, discPayload->uri, "Failed adding href to discovery payload.");
- if (savedDeviceInfo.deviceName)
- {
- discPayload->name = OICStrdup(savedDeviceInfo.deviceName);
- VERIFY_PARAM_NON_NULL(TAG, discPayload->name, "Failed adding name to discovery payload.");
- }
+ OCGetPropertyValue(PAYLOAD_TYPE_DEVICE, "deviceName", (void **)&discPayload->name);
+ VERIFY_PARAM_NON_NULL(TAG, discPayload->name, "Failed adding name to discovery payload.");
discPayload->type = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
VERIFY_PARAM_NON_NULL(TAG, discPayload->type, "Failed adding rt to discovery payload.");
}
OCStackResult discoveryResult = OC_STACK_ERROR;
+ if (request->method == OC_REST_PUT || request->method == OC_REST_POST ||
+ request->method == OC_REST_DELETE)
+ {
+ OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d",
+ request->resourceUrl, request->method);
+ return OC_STACK_UNAUTHORIZED_REQ;
+ }
+
OCPayload* payload = NULL;
char *interfaceQuery = NULL;
char *resourceTypeQuery = NULL;
#endif
)
{
- if (request->method == OC_REST_PUT || request->method == OC_REST_POST ||
- request->method == OC_REST_DELETE)
- {
- OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d",
- request->resourceUrl, request->method);
- discoveryResult = OC_STACK_UNAUTHORIZED_REQ;
- goto exit;
- }
-
discoveryResult = getQueryParamsForFiltering (virtualUriInRequest, request->query,
&interfaceQuery, &resourceTypeQuery);
- VERIFY_SUCCESS(discoveryResult, OC_STACK_OK);
+ VERIFY_SUCCESS(discoveryResult);
if (!interfaceQuery && !resourceTypeQuery)
{
// If no query is sent, default interface is used i.e. oic.if.ll.
discoveryResult = discoveryPayloadCreateAndAddDeviceId(&payload);
VERIFY_PARAM_NON_NULL(TAG, payload, "Failed creating Discovery Payload.");
- VERIFY_SUCCESS(discoveryResult, OC_STACK_OK);
+ VERIFY_SUCCESS(discoveryResult);
OCDiscoveryPayload *discPayload = (OCDiscoveryPayload *)payload;
if (baselineQuery)
{
discoveryResult = addDiscoveryBaselineCommonProperties(discPayload);
- VERIFY_SUCCESS(discoveryResult, OC_STACK_OK);
+ VERIFY_SUCCESS(discoveryResult);
}
OCResourceProperty prop = OC_DISCOVERABLE;
#ifdef MQ_BROKER
}
else if (virtualUriInRequest == OC_DEVICE_URI)
{
- if (request->method == OC_REST_PUT || request->method == OC_REST_POST ||
- request->method == OC_REST_DELETE)
- {
- OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d",
- request->resourceUrl, request->method);
- discoveryResult = OC_STACK_UNAUTHORIZED_REQ;
- goto exit;
- }
-
- const char* deviceId = OCGetServerInstanceIDString();
- VERIFY_PARAM_NON_NULL(TAG, deviceId, "Failed retrieving device id.");
- discoveryResult = OC_STACK_NO_MEMORY;
- dataModelVersions = OCCreateString(savedDeviceInfo.dataModelVersions);
- VERIFY_PARAM_NON_NULL(TAG, dataModelVersions, "Failed adding data model version.");
- payload = (OCPayload*) OCDevicePayloadCreate(deviceId, savedDeviceInfo.deviceName,
- savedDeviceInfo.types, savedDeviceInfo.specVersion, dataModelVersions);
- VERIFY_PARAM_NON_NULL(TAG, payload, "Failed adding device payload.");
- discoveryResult = OC_STACK_OK;
+ OCResource *resourcePtr = FindResourceByUri(OC_RSRVD_DEVICE_URI);
+ VERIFY_PARAM_NON_NULL(TAG, resourcePtr, "Device URI not found.");
+ discoveryResult = BuildResponseRepresentation(resourcePtr, (OCRepPayload **)&payload);
}
else if (virtualUriInRequest == OC_PLATFORM_URI)
{
- if (request->method == OC_REST_PUT || request->method == OC_REST_POST ||
- request->method == OC_REST_DELETE)
- {
- OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d",
- request->resourceUrl, request->method);
- discoveryResult = OC_STACK_UNAUTHORIZED_REQ;
- goto exit;
- }
-
- discoveryResult = OC_STACK_NO_MEMORY;
- payload = (OCPayload *)OCPlatformPayloadCreate(&savedPlatformInfo);
- VERIFY_PARAM_NON_NULL(TAG, payload, "Failed adding platform payload.");
- discoveryResult = OC_STACK_OK;
- }
+ OCResource *resourcePtr = FindResourceByUri(OC_RSRVD_PLATFORM_URI);
+ VERIFY_PARAM_NON_NULL(TAG, resourcePtr, "Platform URI not found.");
+ discoveryResult = BuildResponseRepresentation(resourcePtr, (OCRepPayload **)&payload);
+ }
#ifdef ROUTING_GATEWAY
else if (OC_GATEWAY_URI == virtualUriInRequest)
{
(OCObserveAction)request->observationOption,
(OCObservationId)0,
request->coapID);
- VERIFY_SUCCESS(result, OC_STACK_OK);
+ VERIFY_SUCCESS(result);
// At this point we know for sure that defaultDeviceHandler exists
ehResult = defaultDeviceHandler(OC_REQUEST_FLAG, &ehRequest,
(OCObserveAction)request->observationOption,
0,
request->coapID);
- VERIFY_SUCCESS(result, OC_STACK_OK);
+ VERIFY_SUCCESS(result);
if(ehRequest.obsInfo.action == OC_OBSERVE_NO_OPTION)
{
}
result = GenerateObserverId(&ehRequest.obsInfo.obsId);
- VERIFY_SUCCESS(result, OC_STACK_OK);
+ VERIFY_SUCCESS(result);
result = AddObserver ((const char*)(request->resourceUrl),
(const char *)(request->query),
return ret;
}
-void DeletePlatformInfo()
-{
- OIC_LOG(INFO, TAG, "Deleting platform info.");
-
- OICFree(savedPlatformInfo.platformID);
- savedPlatformInfo.platformID = NULL;
-
- OICFree(savedPlatformInfo.manufacturerName);
- savedPlatformInfo.manufacturerName = NULL;
-
- OICFree(savedPlatformInfo.manufacturerUrl);
- savedPlatformInfo.manufacturerUrl = NULL;
-
- OICFree(savedPlatformInfo.modelNumber);
- savedPlatformInfo.modelNumber = NULL;
-
- OICFree(savedPlatformInfo.dateOfManufacture);
- savedPlatformInfo.dateOfManufacture = NULL;
-
- OICFree(savedPlatformInfo.platformVersion);
- savedPlatformInfo.platformVersion = NULL;
-
- OICFree(savedPlatformInfo.operatingSystemVersion);
- savedPlatformInfo.operatingSystemVersion = NULL;
-
- OICFree(savedPlatformInfo.hardwareVersion);
- savedPlatformInfo.hardwareVersion = NULL;
-
- OICFree(savedPlatformInfo.firmwareVersion);
- savedPlatformInfo.firmwareVersion = NULL;
-
- OICFree(savedPlatformInfo.supportUrl);
- savedPlatformInfo.supportUrl = NULL;
-
- OICFree(savedPlatformInfo.systemTime);
- savedPlatformInfo.systemTime = NULL;
-}
-
-static OCStackResult DeepCopyPlatFormInfo(OCPlatformInfo info)
+OCStackResult OCSetPlatformInfo(OCPlatformInfo info)
{
- savedPlatformInfo.platformID = OICStrdup(info.platformID);
- savedPlatformInfo.manufacturerName = OICStrdup(info.manufacturerName);
- savedPlatformInfo.manufacturerUrl = OICStrdup(info.manufacturerUrl);
- savedPlatformInfo.modelNumber = OICStrdup(info.modelNumber);
- savedPlatformInfo.dateOfManufacture = OICStrdup(info.dateOfManufacture);
- savedPlatformInfo.platformVersion = OICStrdup(info.platformVersion);
- savedPlatformInfo.operatingSystemVersion = OICStrdup(info.operatingSystemVersion);
- savedPlatformInfo.hardwareVersion = OICStrdup(info.hardwareVersion);
- savedPlatformInfo.firmwareVersion = OICStrdup(info.firmwareVersion);
- savedPlatformInfo.supportUrl = OICStrdup(info.supportUrl);
- savedPlatformInfo.systemTime = OICStrdup(info.systemTime);
-
- if ((!savedPlatformInfo.platformID && info.platformID)||
- (!savedPlatformInfo.manufacturerName && info.manufacturerName)||
- (!savedPlatformInfo.manufacturerUrl && info.manufacturerUrl)||
- (!savedPlatformInfo.modelNumber && info.modelNumber)||
- (!savedPlatformInfo.dateOfManufacture && info.dateOfManufacture)||
- (!savedPlatformInfo.platformVersion && info.platformVersion)||
- (!savedPlatformInfo.operatingSystemVersion && info.operatingSystemVersion)||
- (!savedPlatformInfo.hardwareVersion && info.hardwareVersion)||
- (!savedPlatformInfo.firmwareVersion && info.firmwareVersion)||
- (!savedPlatformInfo.supportUrl && info.supportUrl)||
- (!savedPlatformInfo.systemTime && info.systemTime))
- {
- DeletePlatformInfo();
- return OC_STACK_INVALID_PARAM;
+ OCResource *resource = NULL;
+ if (!info.platformID || !info.manufacturerName)
+ {
+ OIC_LOG(ERROR, TAG, "No value specified.");
+ goto exit;
+ }
+ if (0 == strlen(info.platformID) || 0 == strlen(info.manufacturerName))
+ {
+ OIC_LOG(ERROR, TAG, "The passed value cannot be empty");
+ goto exit;
+ }
+ if ((info.manufacturerName && strlen(info.manufacturerName) > MAX_PLATFORM_NAME_LENGTH) ||
+ (info.manufacturerUrl && strlen(info.manufacturerUrl) > MAX_PLATFORM_URL_LENGTH) ||
+ (info.modelNumber && strlen(info.modelNumber) > MAX_PLATFORM_NAME_LENGTH) ||
+ (info.platformVersion && strlen(info.platformVersion) > MAX_PLATFORM_NAME_LENGTH) ||
+ (info.operatingSystemVersion && strlen(info.operatingSystemVersion) > MAX_PLATFORM_NAME_LENGTH) ||
+ (info.hardwareVersion && strlen(info.hardwareVersion) > MAX_PLATFORM_NAME_LENGTH) ||
+ (info.firmwareVersion && strlen(info.firmwareVersion) > MAX_PLATFORM_NAME_LENGTH) ||
+ (info.supportUrl && strlen(info.supportUrl) > MAX_PLATFORM_URL_LENGTH))
+ {
+ OIC_LOG(ERROR, TAG, "The passed value is bigger than permitted.");
+ goto exit;
}
+ resource = FindResourceByUri(OC_RSRVD_PLATFORM_URI);
+ if (!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Platform Resource does not exist.");
+ goto exit;
+ }
+ OIC_LOG(INFO, TAG, "Entering OCSetPlatformInfo");
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_ID, info.platformID));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_NAME, info.manufacturerName));
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_URL, info.manufacturerUrl);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MODEL_NUM, info.modelNumber);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_DATE, info.dateOfManufacture);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_VERSION, info.platformVersion);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_OS_VERSION, info.operatingSystemVersion);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_HARDWARE_VERSION, info.hardwareVersion);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_FIRMWARE_VERSION, info.firmwareVersion);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SUPPORT_URL, info.supportUrl);
+ OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SYSTEM_TIME, info.systemTime);
+ OIC_LOG(INFO, TAG, "Platform parameter initialized successfully.");
return OC_STACK_OK;
+exit:
+ return OC_STACK_INVALID_PARAM;
}
-OCStackResult SavePlatformInfo(OCPlatformInfo info)
+OCStackResult OCSetDeviceInfo(OCDeviceInfo info)
{
- DeletePlatformInfo();
+ OCStringLL *dataModelVersion = NULL;
+ OCResource *resource = FindResourceByUri(OC_RSRVD_DEVICE_URI);
+ if (!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Device Resource does not exist.");
+ goto exit;
+ }
+ if (!info.deviceName || info.deviceName[0] == '\0')
+ {
+ OIC_LOG(ERROR, TAG, "Null or empty device name.");
+ return OC_STACK_INVALID_PARAM;
+ }
- OCStackResult res = DeepCopyPlatFormInfo(info);
+ if (OCGetServerInstanceIDString() == NULL)
+ {
+ OIC_LOG(INFO, TAG, "Device ID generation failed");
+ goto exit;
+ }
- if (res != OC_STACK_OK)
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, info.deviceName));
+ for (OCStringLL *temp = info.types; temp; temp = temp->next)
{
- OIC_LOG_V(ERROR, TAG, "Failed to save platform info. errno(%d)", res);
+ if (temp->value)
+ {
+ VERIFY_SUCCESS(OCBindResourceTypeToResource(resource, temp->value));
+ }
+ }
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, info.specVersion ?
+ info.specVersion: OC_SPEC_VERSION));
+ if (info.dataModelVersions)
+ {
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, info.dataModelVersions));
}
else
{
- OIC_LOG(INFO, TAG, "Platform info saved.");
+ dataModelVersion = OCCreateOCStringLL(OC_DATA_MODEL_VERSION);
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersion));
}
+ OIC_LOG(INFO, TAG, "Device parameter initialized successfully.");
+ return OC_STACK_OK;
- return res;
-}
-
-void DeleteDeviceInfo()
-{
- OIC_LOG(INFO, TAG, "Deleting device info.");
-
- OICFree(savedDeviceInfo.deviceName);
- OCFreeOCStringLL(savedDeviceInfo.types);
- OICFree(savedDeviceInfo.specVersion);
- OCFreeOCStringLL(savedDeviceInfo.dataModelVersions);
- savedDeviceInfo.deviceName = NULL;
- savedDeviceInfo.specVersion = NULL;
- savedDeviceInfo.dataModelVersions = NULL;
+exit:
+ if (dataModelVersion)
+ {
+ OCFreeOCStringLL(dataModelVersion);
+ }
+ return OC_STACK_ERROR;
}
-static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
+OCStackResult OCGetAttribute(const OCResource *resource, const char *attribute, void **value)
{
- savedDeviceInfo.deviceName = OICStrdup(info.deviceName);
-
- if(!savedDeviceInfo.deviceName && info.deviceName)
+ if (!resource || !attribute)
{
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
+ return OC_STACK_INVALID_PARAM;
}
-
- if (info.types)
+ if (0 == strlen(attribute))
{
- savedDeviceInfo.types = CloneOCStringLL(info.types);
- OCStringLL *type = info.types;
- bool found = false;
- while (type)
- {
- if (type && type->value && 0 == strcmp(type->value, OC_RSRVD_RESOURCE_TYPE_DEVICE))
- {
- found = true;
- }
- type = type->next;
- }
- if (!found)
+ return OC_STACK_INVALID_PARAM;
+ }
+ for (OCAttribute *temp = resource->rsrcAttributes; temp; temp = temp->next)
+ {
+ if (0 == strcmp(attribute, temp->attrName))
{
- // Append the oic.wk.d at the start of rt link parameter value.
- OCStringLL *dest = (OCStringLL*)OICCalloc (1, sizeof (OCStringLL));
- if (!dest)
+ // A special case as this type return OCStringLL
+ if (0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, attribute))
{
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
+ *value = CloneOCStringLL((OCStringLL *)temp->attrValue);
+ return OC_STACK_OK;
}
- dest->value = OICStrdup (OC_RSRVD_RESOURCE_TYPE_DEVICE);
- if (!dest->value)
+ else
{
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
+ *value = OICStrdup((char *)temp->attrValue);
+ return OC_STACK_OK;
}
- dest->next = savedDeviceInfo.types;
- savedDeviceInfo.types = dest;
- }
- if(!savedDeviceInfo.types && info.types)
- {
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
}
}
+ return OC_STACK_NO_RESOURCE;
+}
- if (info.specVersion)
+OCStackResult OCGetPropertyValue(OCPayloadType type, const char *prop, void **value)
+{
+ if (!prop || *value)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (strlen(prop) == 0)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+ OCStackResult res = OC_STACK_NO_RESOURCE;
+ if (PAYLOAD_TYPE_DEVICE == type || PAYLOAD_TYPE_PLATFORM == type)
{
- savedDeviceInfo.specVersion = OICStrdup(info.specVersion);
- if(!savedDeviceInfo.specVersion && info.specVersion)
+ const char *pathType = (type == PAYLOAD_TYPE_DEVICE) ? OC_RSRVD_DEVICE_URI : OC_RSRVD_PLATFORM_URI;
+ OCResource *resource = FindResourceByUri(pathType);
+ if (!resource)
{
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
+ return OC_STACK_NO_RESOURCE;
}
+
+ res = OCGetAttribute(resource, prop, value);
+ }
+ return res;
+}
+
+OCStackResult OCSetAttribute(OCResource* resource, const char* attribute, const void* value)
+{
+ OCAttribute *resAttrib = (OCAttribute *)OICCalloc(1, sizeof(OCAttribute));
+ VERIFY_PARAM_NON_NULL(TAG, resAttrib, "Failed allocation OCAttribute");
+ resAttrib->attrName = OICStrdup(attribute);
+ VERIFY_PARAM_NON_NULL(TAG, resAttrib->attrName, "Failed allocating attribute name");
+ // A special case when value is of type OCStringLL
+ if (0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, attribute))
+ {
+ resAttrib->attrValue = CloneOCStringLL((OCStringLL *)value);
}
else
{
- savedDeviceInfo.specVersion = OICStrdup(OC_SPEC_VERSION);
- if(!savedDeviceInfo.specVersion && OC_SPEC_VERSION)
- {
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
- }
+ resAttrib->attrValue = OICStrdup((char *)value);
}
+ VERIFY_PARAM_NON_NULL(TAG, resAttrib->attrValue, "Failed allocating attribute value");
+ resAttrib->next = NULL;
- if (info.dataModelVersions)
+ if (!resource->rsrcAttributes)
{
- savedDeviceInfo.dataModelVersions = CloneOCStringLL(info.dataModelVersions);
- if(!savedDeviceInfo.dataModelVersions && info.dataModelVersions)
- {
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
- }
+ resource->rsrcAttributes = resAttrib;
}
else
{
- savedDeviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1,sizeof(OCStringLL));
- if (!savedDeviceInfo.dataModelVersions)
- {
- return OC_STACK_NO_MEMORY;
- }
- savedDeviceInfo.dataModelVersions->value = OICStrdup(OC_DATA_MODEL_VERSION);
- if(!savedDeviceInfo.dataModelVersions->value && OC_DATA_MODEL_VERSION)
+ OCAttribute *temp = resource->rsrcAttributes;
+ for (; temp->next; temp = temp->next)
{
- DeleteDeviceInfo();
- return OC_STACK_NO_MEMORY;
+ if (0 == strcmp(attribute, temp->attrName))
+ {
+ if (0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, temp->attrName))
+ {
+ OCFreeOCStringLL((OCStringLL *)temp->attrValue);
+ }
+ {
+ OICFree((char *)temp->attrValue);
+ }
+ break;
+ }
}
+ temp->next = resAttrib;
}
-
return OC_STACK_OK;
-}
-
-OCStackResult SaveDeviceInfo(OCDeviceInfo info)
-{
- OCStackResult res = OC_STACK_OK;
-
- DeleteDeviceInfo();
- res = DeepCopyDeviceInfo(info);
+exit:
+ OCDeleteResourceAttributes(resAttrib);
+ return OC_STACK_NO_MEMORY;
- VERIFY_SUCCESS(res, OC_STACK_OK);
+}
- if (OCGetServerInstanceIDString() == NULL)
+OCStackResult OCSetPropertyValue(OCPayloadType type, const char *prop, const void *value)
+{
+ if (!prop)
{
- OIC_LOG(INFO, TAG, "Device ID generation failed");
- res = OC_STACK_ERROR;
- goto exit;
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (strlen(prop) == 0)
+ {
+ return OC_STACK_INVALID_PARAM;
}
- OIC_LOG(INFO, TAG, "Device initialized successfully.");
- return OC_STACK_OK;
+ OCStackResult res = OC_STACK_ERROR;
+ if (PAYLOAD_TYPE_DEVICE == type || PAYLOAD_TYPE_PLATFORM == type)
+ {
+ const char *pathType = (type == PAYLOAD_TYPE_DEVICE) ? OC_RSRVD_DEVICE_URI : OC_RSRVD_PLATFORM_URI;
+ OCResource *resource = FindResourceByUri(pathType);
+ if (!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Resource does not exist.");
+ }
+ if (value)
+ {
+ res = OCSetAttribute(resource, prop, value);
+ }
+ }
-exit:
- DeleteDeviceInfo();
return res;
}
#endif
else if (strcmp(cbNode->requestUri, OC_RSRVD_DEVICE_URI) == 0)
{
- type = PAYLOAD_TYPE_DEVICE;
+ type = PAYLOAD_TYPE_REPRESENTATION;
}
else if (strcmp(cbNode->requestUri, OC_RSRVD_PLATFORM_URI) == 0)
{
- type = PAYLOAD_TYPE_PLATFORM;
+ type = PAYLOAD_TYPE_REPRESENTATION;
}
+
#ifdef ROUTING_GATEWAY
else if (strcmp(cbNode->requestUri, OC_RSRVD_GATEWAY_URI) == 0)
{
#endif
else if (strcmp(cbNode->requestUri, OC_RSRVD_RD_URI) == 0)
{
- type = PAYLOAD_TYPE_REPRESENTATION ;
+ type = PAYLOAD_TYPE_REPRESENTATION;
}
#ifdef TCP_ADAPTER
else if (strcmp(cbNode->requestUri, KEEPALIVE_RESOURCE_URI) == 0)
{
if (cbNode->requestUri)
{
- if (strcmp(OC_RSRVD_PLATFORM_URI, cbNode->requestUri) == 0)
+ if (0 == strcmp(OC_RSRVD_PLATFORM_URI, cbNode->requestUri))
{
- type = PAYLOAD_TYPE_PLATFORM;
+ type = PAYLOAD_TYPE_REPRESENTATION;
}
- else if (strcmp(OC_RSRVD_DEVICE_URI, cbNode->requestUri) == 0)
+ else if (0 == strcmp(OC_RSRVD_DEVICE_URI, cbNode->requestUri))
{
- type = PAYLOAD_TYPE_DEVICE;
+ type = PAYLOAD_TYPE_REPRESENTATION;
}
if (type == PAYLOAD_TYPE_INVALID)
{
OIC_LOG(INFO, TAG, "Exit HandleCARequests");
}
-bool validatePlatformInfo(OCPlatformInfo info)
-{
-
- if (!info.platformID)
- {
- OIC_LOG(ERROR, TAG, "No platform ID found.");
- return false;
- }
-
- if (info.manufacturerName)
- {
- size_t lenManufacturerName = strlen(info.manufacturerName);
-
- if(lenManufacturerName == 0 || lenManufacturerName > MAX_MANUFACTURER_NAME_LENGTH)
- {
- OIC_LOG(ERROR, TAG, "Manufacturer name fails length requirements.");
- return false;
- }
- }
- else
- {
- OIC_LOG(ERROR, TAG, "No manufacturer name present");
- return false;
- }
-
- if (info.manufacturerUrl)
- {
- if(strlen(info.manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH)
- {
- OIC_LOG(ERROR, TAG, "Manufacturer url fails length requirements.");
- return false;
- }
- }
- return true;
-}
-
//-----------------------------------------------------------------------------
// Public APIs
//-----------------------------------------------------------------------------
// Free memory dynamically allocated for resources
deleteAllResources();
- DeleteDeviceInfo();
- DeletePlatformInfo();
CATerminate();
TerminateScheduleResourceList();
// Remove all observers
return OC_STACK_OK;
}
-OCStackResult OCSetPlatformInfo(OCPlatformInfo platformInfo)
-{
- OIC_LOG(INFO, TAG, "Entering OCSetPlatformInfo");
-
- if(myStackMode == OC_SERVER || myStackMode == OC_CLIENT_SERVER || myStackMode == OC_GATEWAY)
- {
- if (validatePlatformInfo(platformInfo))
- {
- return SavePlatformInfo(platformInfo);
- }
- else
- {
- return OC_STACK_INVALID_PARAM;
- }
- }
- else
- {
- return OC_STACK_ERROR;
- }
-}
-
-OCStackResult OCSetDeviceInfo(OCDeviceInfo deviceInfo)
-{
- OIC_LOG(INFO, TAG, "Entering OCSetDeviceInfo");
-
- if (!deviceInfo.deviceName || deviceInfo.deviceName[0] == '\0')
- {
- OIC_LOG(ERROR, TAG, "Null or empty device name.");
- return OC_STACK_INVALID_PARAM;
- }
-
- if (deviceInfo.types)
- {
- OCStringLL *type = deviceInfo.types;
- OCResource *resource = findResource((OCResource *) deviceResource);
- if (!resource)
- {
- return OC_STACK_INVALID_PARAM;
- }
-
- while (type)
- {
- OCBindResourceTypeToResource(deviceResource, type->value);
- type = type->next;
- }
- }
- return SaveDeviceInfo(deviceInfo);
-}
-
OCStackResult OCCreateResource(OCResourceHandle *handle,
const char *resourceTypeName,
const char *resourceInterfaceName,
OICFree(resource->uri);
deleteResourceType(resource->rsrcType);
deleteResourceInterface(resource->rsrcInterface);
+ OCDeleteResourceAttributes(resource->rsrcAttributes);
}
void deleteResourceType(OCResourceType *resourceType)
}
}
+void OCDeleteResourceAttributes(OCAttribute *rsrcAttributes)
+{
+ OCAttribute *next = NULL;
+ for (OCAttribute *pointer = rsrcAttributes; pointer; pointer = next)
+ {
+ next = pointer->next;
+ if (pointer->attrName && 0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, pointer->attrName))
+ {
+ OCFreeOCStringLL((OCStringLL *)pointer->attrValue);
+ }
+ else
+ {
+ OICFree(pointer->attrValue);
+ }
+ OICFree(pointer->attrName);
+ OICFree(pointer);
+ }
+}
+
void insertResourceType(OCResource *resource, OCResourceType *resourceType)
{
OCResourceType *pointer = NULL;
static bool generated = false;
static char sidStr[UUID_STRING_SIZE];
- if(generated)
+ if (generated)
{
return sidStr;
}
const OicUuid_t *sid = OCGetServerInstanceID();
- if(OCConvertUuidToString(sid->id, sidStr) != RAND_UUID_OK)
+ if (sid && OCConvertUuidToString(sid->id, sidStr) != RAND_UUID_OK)
{
OIC_LOG(FATAL, TAG, "Generate UUID String for Server Instance failed!");
return NULL;
#include "ocstackinternal.h"
#include "logger.h"
#include "oic_malloc.h"
+ #include "oic_string.h"
}
#include "gtest/gtest.h"
char gDeviceUUID[] = "myDeviceUUID";
char gManufacturerName[] = "myName";
-char gTooLongManufacturerName[] = "extremelylongmanufacturername";
-char gManufacturerUrl[] = "www.foooooooooooooooo.baaaaaaaaaaaaar";
static OCPrm_t pmSel;
static char pinNumber;
static OCDPDev_t peer;
OCDiscoveryPayload *discoveryPayload = ((OCDiscoveryPayload *) clientResponse->payload);
EXPECT_TRUE(discoveryPayload != NULL);
OCResourcePayload *res = discoveryPayload->resources;
- size_t count = 0;
+ int count = 0;
for (OCResourcePayload *res1 = discoveryPayload->resources; res1; res1 = res1->next)
{
count++;
gManufacturerName,
0, 0, 0, 0, 0, 0, 0, 0, 0
};
- EXPECT_EQ(OC_STACK_ERROR, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
{
itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
-
+ char gTooLongManufacturerName[MAX_PLATFORM_NAME_LENGTH+2];
+ for (int i = 0; i <= MAX_PLATFORM_NAME_LENGTH; i++ )
+ {
+ gTooLongManufacturerName[i] = 'a';
+ }
+ gTooLongManufacturerName[MAX_PLATFORM_NAME_LENGTH+1] = '\0';
OCPlatformInfo info =
{
gDeviceUUID,
{
itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ char gManufacturerUrl[MAX_PLATFORM_URL_LENGTH+2];
+ for (int i = 0; i <= MAX_PLATFORM_URL_LENGTH; i++ )
+ {
+ gManufacturerUrl[i] = 'a';
+ }
+ gManufacturerUrl[MAX_PLATFORM_URL_LENGTH+1] = '\0';
OCPlatformInfo info =
{
gDeviceUUID,
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+TEST(StackStart, SetPlatformInfoWithOCSetPropertyValueAPI)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_ID, gDeviceUUID));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_NAME, gManufacturerName));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_URL, "http://www.iotivity.org"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MODEL_NUM, "S777"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_DATE, "15 Nov, 2016"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_OS_VERSION, "1.1"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_VERSION, "14"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_HARDWARE_VERSION, "0.1"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_FIRMWARE_VERSION, "0.1"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SUPPORT_URL, "http://www.iotivity.org"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SYSTEM_TIME, ""));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, "x.org.iotivity.AAAA", "value"));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, NULL, ""));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPropertyValue(PAYLOAD_TYPE_INVALID, NULL, NULL));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPropertyValue(PAYLOAD_TYPE_INVALID, NULL, NULL));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, GetPlatformInfoWithOCGetPropertyValueAPI)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_ID, gDeviceUUID));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_NAME, gManufacturerName));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_URL, "http://www.iotivity.org"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MODEL_NUM, "S777"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_DATE, "15 Nov, 2016"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_OS_VERSION, "1.1"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_VERSION, "14"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_HARDWARE_VERSION, "0.1"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_FIRMWARE_VERSION, "0.1"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SUPPORT_URL, "http://www.iotivity.org"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SYSTEM_TIME, ""));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, "x.org.iotivity.AAAA", "value"));
+
+ void *value = NULL;
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_ID, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ(gDeviceUUID, (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_NAME, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ(gManufacturerName, (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_URL, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("http://www.iotivity.org", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MODEL_NUM, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("S777", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_DATE, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("15 Nov, 2016", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_OS_VERSION, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("1.1", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_VERSION, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("14", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_HARDWARE_VERSION, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("0.1", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_FIRMWARE_VERSION, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("0.1", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SUPPORT_URL, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("http://www.iotivity.org", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_SYSTEM_TIME, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK,OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, "x.org.iotivity.AAAA", &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("value", (char *)value);
+ OICFree(value);
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetDeviceInfoAPI)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Sample"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, "specVersion"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, "x.org.iotivity.newproperty", "value"));
+ OCStringLL *dataModelVersions = OCCreateOCStringLL("Data Model Version");
+ EXPECT_TRUE(dataModelVersions != NULL);
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersions));
+ OCFreeOCStringLL(dataModelVersions);
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ EXPECT_TRUE(handle != NULL);
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPropertyValue(PAYLOAD_TYPE_INVALID, NULL, NULL));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPropertyValue(PAYLOAD_TYPE_INVALID, "", NULL));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, GetDeviceInfoAPI)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Sample"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, "specVersion"));
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, "x.org.iotivity.newproperty", "value"));
+ OCStringLL *dataModelVersions = OCCreateOCStringLL("Data Model Version");
+ EXPECT_TRUE(dataModelVersions != NULL);
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersions));
+ OCFreeOCStringLL(dataModelVersions);
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ EXPECT_TRUE(handle != NULL);
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
+
+ void *value = NULL;
+ EXPECT_EQ(OC_STACK_OK, OCGetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("Sample", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK, OCGetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("specVersion", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK, OCGetPropertyValue(PAYLOAD_TYPE_DEVICE, "x.org.iotivity.newproperty", &value));
+ ASSERT_TRUE(value != NULL);
+ EXPECT_STREQ("value", (char *)value);
+ OICFree(value);
+ value = NULL;
+
+ EXPECT_EQ(OC_STACK_OK, OCGetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, &value));
+ ASSERT_TRUE(value != NULL);
+ ASSERT_TRUE(((OCStringLL *)value)->value);
+ EXPECT_STREQ("Data Model Version", ((OCStringLL *)value)->value);
+ OCFreeOCStringLL((OCStringLL *) value);
+ value = NULL;
+
+ EXPECT_STREQ("oic.wk.d", OCGetResourceTypeName(handle, 0));
+ EXPECT_STREQ("oic.wk.tv", OCGetResourceTypeName(handle, 1));
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
TEST(StackDiscovery, DISABLED_DoResourceDeviceDiscovery)
{
itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
virtual OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler) = 0;
virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse) = 0;
+
+ virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value) = 0;
+ virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value) = 0;
};
}
virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
+ virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
+ virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
+
private:
void processFunc();
std::thread m_processThread;
OCConnectivityType connectivityType, FindResListCallback resourceHandler,
QualityOfService QoS = QualityOfService::LowQos);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::vector<std::string>& value);
/**
* API for Device Discovery
*
OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
FindPlatformCallback platformInfoHandler, QualityOfService QoS);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
+
/**
* This API registers a resource with the server
* @note This API applies to server side only.
public:
void setPayload(const OCPayload* rep);
- void setPayload(const OCDevicePayload* rep);
-
- void setPayload(const OCPlatformPayload* rep);
-
void setPayload(const OCRepPayload* rep);
OCRepPayload* getPayload() const;
{
if (clientResponse->payload == nullptr ||
(
- clientResponse->payload->type != PAYLOAD_TYPE_DEVICE &&
- clientResponse->payload->type != PAYLOAD_TYPE_PLATFORM &&
clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION
)
)
return result;
}
+ OCStackResult InProcServerWrapper::setPropertyValue(OCPayloadType type, const std::string& propName,
+ const std::string& propValue)
+ {
+ auto cLock = m_csdkLock.lock();
+ OCStackResult result = OC_STACK_ERROR;
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCSetPropertyValue(type, propName.c_str(), (void *)propValue.c_str());
+ }
+ return result;
+ }
+
+ OCStackResult InProcServerWrapper::getPropertyValue(OCPayloadType type, const std::string& propName,
+ std::string& propValue)
+ {
+ auto cLock = m_csdkLock.lock();
+ OCStackResult result = OC_STACK_ERROR;
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCGetPropertyValue(type, propName.c_str(), (void **)propValue.c_str());
+ }
+ return result;
+ }
+
OCStackResult InProcServerWrapper::registerResource(
OCResourceHandle& resourceHandle,
std::string& resourceURI,
return OCPlatform_impl::Instance().registerPlatformInfo(platformInfo);
}
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value)
+ {
+ return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
+ }
+
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value)
+ {
+ return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
+ }
+
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value)
+ {
+ return OCPlatform_impl::Instance().getPropertyValue(type, tag, value);
+ }
+
OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
{
return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
return checked_guard(m_server, &IServerWrapper::registerPlatformInfo, platformInfo);
}
+ OCStackResult OCPlatform_impl::setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value)
+ {
+
+ return checked_guard(m_server, &IServerWrapper::setPropertyValue, type, tag, value);
+ }
+
+ OCStackResult OCPlatform_impl::setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value)
+ {
+ for (const auto& h : value)
+ {
+ OCStackResult r;
+
+ if (OC_STACK_OK != (r = result_guard(setPropertyValue(type, tag, h))))
+ {
+ return r;
+ }
+ }
+
+ return OC_STACK_OK;
+ }
+
+ OCStackResult OCPlatform_impl::getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value)
+ {
+ return checked_guard(m_server, &IServerWrapper::getPropertyValue, type, tag, value);
+ }
+
OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
const std::shared_ptr< OCResource > resource)
{
case PAYLOAD_TYPE_REPRESENTATION:
setPayload(reinterpret_cast<const OCRepPayload*>(rep));
break;
- case PAYLOAD_TYPE_DEVICE:
- setPayload(reinterpret_cast<const OCDevicePayload*>(rep));
- break;
- case PAYLOAD_TYPE_PLATFORM:
- setPayload(reinterpret_cast<const OCPlatformPayload*>(rep));
- break;
default:
throw OC::OCException("Invalid Payload type in setPayload");
break;
}
}
- void MessageContainer::setPayload(const OCDevicePayload* payload)
- {
- if (payload == nullptr)
- {
- return;
- }
-
- OCRepresentation rep;
- rep[OC_RSRVD_DEVICE_ID] = (payload->sid) ?
- std::string(payload->sid) :
- std::string();
- rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
- std::string(payload->deviceName) :
- std::string();
- rep[OC_RSRVD_SPEC_VERSION] = payload->specVersion ?
- std::string(payload->specVersion) :
- std::string();
- for (OCStringLL *strll = payload->dataModelVersions; strll; strll = strll->next)
- {
- rep.addDataModelVersion(strll->value);
- }
- for (OCStringLL *strll = payload->types; strll; strll = strll->next)
- {
- rep.addResourceType(strll->value);
- }
- m_reps.push_back(std::move(rep));
- }
-
- void MessageContainer::setPayload(const OCPlatformPayload* payload)
- {
- if (payload == nullptr)
- {
- return;
- }
-
- OCRepresentation rep;
- rep[OC_RSRVD_PLATFORM_ID] = payload->info.platformID ?
- std::string(payload->info.platformID) :
- std::string();
- rep[OC_RSRVD_MFG_NAME] = payload->info.manufacturerName ?
- std::string(payload->info.manufacturerName) :
- std::string();
- rep[OC_RSRVD_MFG_URL] = payload->info.manufacturerUrl ?
- std::string(payload->info.manufacturerUrl) :
- std::string();
- rep[OC_RSRVD_MODEL_NUM] = payload->info.modelNumber ?
- std::string(payload->info.modelNumber) :
- std::string();
- rep[OC_RSRVD_MFG_DATE] = payload->info.dateOfManufacture ?
- std::string(payload->info.dateOfManufacture) :
- std::string();
- rep[OC_RSRVD_PLATFORM_VERSION] = payload->info.platformVersion ?
- std::string(payload->info.platformVersion) :
- std::string();
- rep[OC_RSRVD_OS_VERSION] = payload->info.operatingSystemVersion ?
- std::string(payload->info.operatingSystemVersion) :
- std::string();
- rep[OC_RSRVD_HARDWARE_VERSION] = payload->info.hardwareVersion ?
- std::string(payload->info.hardwareVersion) :
- std::string();
- rep[OC_RSRVD_FIRMWARE_VERSION] = payload->info.firmwareVersion ?
- std::string(payload->info.firmwareVersion) :
- std::string();
- rep[OC_RSRVD_SUPPORT_URL] = payload->info.supportUrl ?
- std::string(payload->info.supportUrl) :
- std::string();
- rep[OC_RSRVD_SYSTEM_TIME] = payload->info.systemTime ?
- std::string(payload->info.systemTime) :
- std::string();
-
- for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
- {
- rep.addResourceType(strll->value);
- }
- for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
- {
- rep.addResourceInterface(strll->value);
- }
-
- m_reps.push_back(std::move(rep));
- }
-
void MessageContainer::setPayload(const OCRepPayload* payload)
{
const OCRepPayload* pl = payload;
// CBOR->OCPayload and OCPayload->OCRepresentation conversions
namespace OCRepresentationEncodingTest
{
- static const char sid1[] = "646F6F72-4465-7669-6365-555549443030";
- static const char devicename1[] = "device name";
- static const char specver1[] = "spec version";
- static const char dmver1[] = "res.1.1.0";
- static OCStringLL *types = NULL;
+ static const char *sid1;
// Device Payloads
TEST(DeviceDiscoveryEncoding, Normal)
{
- OCResourcePayloadAddStringLL(&types, "oic.wk.d");
- OCResourcePayloadAddStringLL(&types, "oic.d.tv");
-
- OCDevicePayload* device = OCDevicePayloadCreate(
- sid1,
- devicename1,
- types,
- specver1,
- dmver1);
+ sid1 = OCGetServerInstanceIDString();
+ const char devicename1[] = "device name";
+ OCRepPayload *device = OCRepPayloadCreate();
EXPECT_TRUE(device);
- EXPECT_STREQ(sid1, device->sid);
- EXPECT_STREQ(devicename1, device->deviceName);
- EXPECT_STREQ(specver1, device->specVersion);
- EXPECT_TRUE(device->dataModelVersions);
- EXPECT_STREQ("res.1.1.0", device->dataModelVersions->value);
- EXPECT_FALSE(device->dataModelVersions->next);
- EXPECT_EQ(PAYLOAD_TYPE_DEVICE, ((OCPayload *)device)->type);
- EXPECT_STREQ("oic.wk.d", device->types->value);
- EXPECT_STREQ("oic.d.tv", device->types->next->value);
+ EXPECT_TRUE(OCRepPayloadAddResourceType(device, OC_RSRVD_RESOURCE_TYPE_DEVICE));
+ EXPECT_TRUE(OCRepPayloadAddResourceType(device, "oic.d.tv"));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_ID, sid1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_NAME, devicename1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_SPEC_VERSION, OC_SPEC_VERSION));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, "x.org.iotivity.newproperty", "value"));
+
+ size_t dim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+ char **dt = (char **)OICMalloc(sizeof(char *) * 1);
+ EXPECT_TRUE(dt);
+ dt[0] = OICStrdup(OC_DATA_MODEL_VERSION);
+ EXPECT_TRUE(OCRepPayloadSetStringArray(device, OC_RSRVD_DATA_MODEL_VERSION, (const char **)dt, dim));
+ OICFree(dt[0]);
+ OICFree(dt);
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_DEVICE,
- cborData, cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize));
OICFree(cborData);
- EXPECT_STREQ(device->sid, ((OCDevicePayload*)parsedDevice)->sid);
- EXPECT_STREQ(device->deviceName, ((OCDevicePayload*)parsedDevice)->deviceName);
- EXPECT_STREQ(device->specVersion, ((OCDevicePayload*)parsedDevice)->specVersion);
- EXPECT_STREQ(device->dataModelVersions->value, ((OCDevicePayload*)parsedDevice)->dataModelVersions->value);
- EXPECT_STREQ("oic.wk.d", ((OCDevicePayload*)parsedDevice)->types->value);
- EXPECT_STREQ("oic.d.tv", ((OCDevicePayload*)parsedDevice)->types->next->value);
- EXPECT_EQ(device->base.type, ((OCDevicePayload*)parsedDevice)->base.type);
+ OCRepPayload *parsedRep = (OCRepPayload *)parsedDevice;
+ char *value = NULL;
+ EXPECT_TRUE(OCRepPayloadGetPropString(parsedRep, OC_RSRVD_DEVICE_ID, &value));
+ EXPECT_STREQ(sid1, value);
+ OICFree(value);
+ EXPECT_TRUE(OCRepPayloadGetPropString(parsedRep, OC_RSRVD_DEVICE_NAME, &value));
+ EXPECT_STREQ(devicename1, value);
+ OICFree(value);
+ EXPECT_TRUE(OCRepPayloadGetPropString(parsedRep, OC_RSRVD_SPEC_VERSION, &value));
+ EXPECT_STREQ(OC_SPEC_VERSION, value);
+ OICFree(value);
+ EXPECT_TRUE(OCRepPayloadGetPropString(device, "x.org.iotivity.newproperty", &value));
+ EXPECT_STREQ("value", value);
+ OICFree(value);
+ char **dmv = NULL;
+ EXPECT_TRUE(OCRepPayloadGetStringArray(parsedRep, OC_RSRVD_DATA_MODEL_VERSION, &dmv, dim));
+ EXPECT_STREQ(OC_DATA_MODEL_VERSION, dmv[0]);
+ OICFree(dmv[0]);
+ OICFree(dmv);
+ EXPECT_STREQ("oic.wk.d", parsedRep->types->value);
+ EXPECT_STREQ("oic.d.tv", parsedRep->types->next->value);
+ EXPECT_EQ(device->base.type, parsedRep->base.type);
OCPayloadDestroy((OCPayload*)device);
const OC::OCRepresentation &r1 = mc1.representations()[0];
EXPECT_STREQ(sid1, r1.getValue<std::string>(OC_RSRVD_DEVICE_ID).c_str());
EXPECT_STREQ(devicename1, r1.getValue<std::string>(OC_RSRVD_DEVICE_NAME).c_str());
- EXPECT_STREQ(specver1, r1.getValue<std::string>(OC_RSRVD_SPEC_VERSION).c_str());
- EXPECT_STREQ("res.1.1.0", r1.getDataModelVersions()[0].c_str());
+ EXPECT_STREQ(OC_SPEC_VERSION, r1.getValue<std::string>(OC_RSRVD_SPEC_VERSION).c_str());
+ EXPECT_STREQ("value", r1.getValue<std::string>("x.org.iotivity.newproperty").c_str());
+ std::vector<std::string> dmv2 = r1.getValue<std::vector<std::string>>(OC_RSRVD_DATA_MODEL_VERSION);
+ EXPECT_STREQ(OC_DATA_MODEL_VERSION, dmv2[0].c_str());
OCPayloadDestroy(parsedDevice);
- static const char dmver2[] = "res.1.1.0,sh.1.1.0";
- device = OCDevicePayloadCreate(
- sid1,
- devicename1,
- types,
- specver1,
- dmver2);
-
- EXPECT_STREQ("res.1.1.0", device->dataModelVersions->value);
- EXPECT_TRUE(device->dataModelVersions->next);
- EXPECT_STREQ("sh.1.1.0", device->dataModelVersions->next->value);
- EXPECT_FALSE(device->dataModelVersions->next->next);
+ device = OCRepPayloadCreate();
+ EXPECT_TRUE(device);
+ EXPECT_TRUE(OCRepPayloadAddResourceType(device, OC_RSRVD_RESOURCE_TYPE_DEVICE));
+ EXPECT_TRUE(OCRepPayloadAddResourceType(device, "oic.d.tv"));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_NAME, devicename1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_ID, sid1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_SPEC_VERSION, OC_SPEC_VERSION));
+ size_t dim1[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
+ char **dt1 = (char **)OICMalloc(sizeof(char *) * 2);
+ EXPECT_TRUE(dt1);
+ dt1[0] = OICStrdup("res.1.1.0");
+ dt1[1] = OICStrdup("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_DEVICE,
- cborData, cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize));
OICFree(cborData);
- EXPECT_STREQ(device->dataModelVersions->value,
- ((OCDevicePayload *)parsedDevice)->dataModelVersions->value);
- EXPECT_STREQ(device->dataModelVersions->next->value,
- ((OCDevicePayload *)parsedDevice)->dataModelVersions->next->value);
+ OICFree(dt1[0]);
+ OICFree(dt1[1]);
+ OICFree(dt1);
+ char **dmv1 = NULL;
+ parsedRep = (OCRepPayload *)parsedDevice;
+ EXPECT_TRUE(OCRepPayloadGetStringArray(parsedRep, OC_RSRVD_DATA_MODEL_VERSION, &dmv1, dim));
+ EXPECT_STREQ("res.1.1.0", dmv1[0]);
+ EXPECT_STREQ("sh.1.1.0", dmv1[1]);
+ OICFree(dmv1[0]);
+ OICFree(dmv1[1]);
+ OICFree(dmv1);
OCPayloadDestroy((OCPayload *)device);
OC::MessageContainer mc2;
mc2.setPayload(parsedDevice);
EXPECT_EQ(1u, mc2.representations().size());
const OC::OCRepresentation r2 = mc2.representations()[0];
- EXPECT_STREQ("res.1.1.0", r2.getDataModelVersions()[0].c_str());
- EXPECT_STREQ("sh.1.1.0", r2.getDataModelVersions()[1].c_str());
-
+ std::vector<std::string> dmv3 = r2.getValue<std::vector<std::string>>(OC_RSRVD_DATA_MODEL_VERSION);
+ EXPECT_STREQ("res.1.1.0", dmv3[0].c_str());
+ EXPECT_STREQ("sh.1.1.0", dmv3[1].c_str());
OCPayloadDestroy(parsedDevice);
}
- static const char uri1[] = "/testuri";
- static char pfid1[] = "pfid";
- static char mfgnm1[] = "mfgnm";
- static char mfgurl1[] = "mfgurl";
- static char modelnum1[] = "modelnum";
- static char dom1[] = "dom";
- static char pfver1[] = "pfver";
- static char osver1[] = "osver";
- static char hwver1[] = "hwver";
- static char fwver1[] = "fwver";
- static char url1[] = "url";
- static char time1[] = "time";
-
// Platform Payloads
TEST(PlatformDiscoveryEncoding, Normal)
{
- OCPlatformInfo info {pfid1, mfgnm1, mfgurl1, modelnum1, dom1, pfver1, osver1, hwver1,
- fwver1, url1, time1};
- OCPlatformPayload* platform = OCPlatformPayloadCreate(&info);
- EXPECT_EQ(PAYLOAD_TYPE_PLATFORM, ((OCPayload*)platform)->type);
- EXPECT_STREQ(pfid1, platform->info.platformID);
- EXPECT_STREQ(mfgnm1, platform->info.manufacturerName);
- EXPECT_STREQ(mfgurl1, platform->info.manufacturerUrl);
- EXPECT_STREQ(modelnum1, platform->info.modelNumber);
- EXPECT_STREQ(dom1, platform->info.dateOfManufacture);
- EXPECT_STREQ(pfver1, platform->info.platformVersion);
- EXPECT_STREQ(osver1, platform->info.operatingSystemVersion);
- EXPECT_STREQ(hwver1, platform->info.hardwareVersion);
- EXPECT_STREQ(fwver1, platform->info.firmwareVersion);
- EXPECT_STREQ(url1, platform->info.supportUrl);
- EXPECT_STREQ(time1, platform->info.systemTime);
- EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, platform->interfaces->value);
- EXPECT_STREQ(OC_RSRVD_INTERFACE_READ, platform->interfaces->next->value);
- EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt->value);
+ static char pfid1[] = "646F6F72-4465-7669-6365-555549443030";
+ static char mfgnm1[] = "mfgnm";
+ static char mfgurl1[] = "http://www.iotivity.org";
+ static char modelnum1[] = "modelnum";
+ static char dom1[] = "dom";
+ static char pfver1[] = "pfver";
+ static char osver1[] = "osver";
+ static char hwver1[] = "hwver";
+ static char fwver1[] = "fwver";
+ static char url1[] = "http://www.iotivity.org";
+ static char time1[] = "20161122T143938Z";
+ static char vid1[] = "Manufacturer Freeform Text";
+ OCRepPayload *platform = OCRepPayloadCreate();
+ EXPECT_TRUE(platform != NULL);
+ EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, ((OCPayload*)platform)->type);
+ EXPECT_TRUE(OCRepPayloadAddResourceType(platform, (char *)OC_RSRVD_RESOURCE_TYPE_PLATFORM));
+ EXPECT_TRUE(OCRepPayloadAddInterface(platform, (char *)OC_RSRVD_INTERFACE_DEFAULT));
+ EXPECT_TRUE(OCRepPayloadAddInterface(platform, (char *)OC_RSRVD_INTERFACE_READ));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_PLATFORM_ID, pfid1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_MFG_NAME, mfgnm1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_MFG_URL, mfgurl1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_MODEL_NUM, modelnum1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_MFG_DATE, dom1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_OS_VERSION, osver1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_PLATFORM_VERSION, pfver1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_HARDWARE_VERSION, hwver1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_FIRMWARE_VERSION, fwver1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_SUPPORT_URL, url1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_SYSTEM_TIME, time1));
+ EXPECT_TRUE(OCRepPayloadSetPropString(platform, OC_RSRVD_VID, vid1));
+
uint8_t* cborData;
size_t cborSize;
- OCPayload* parsedPlatform;
+ OCPayload* parsedPlatform = NULL;
EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)platform, &cborData, &cborSize));
- EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedPlatform, PAYLOAD_TYPE_PLATFORM,
- cborData, cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedPlatform, PAYLOAD_TYPE_REPRESENTATION, cborData, cborSize));
OICFree(cborData);
- EXPECT_EQ(platform->base.type, ((OCPlatformPayload*)parsedPlatform)->base.type);
- OCPlatformPayload* platform2 = (OCPlatformPayload*)parsedPlatform;
- EXPECT_STREQ(platform->info.platformID, platform2->info.platformID);
- EXPECT_STREQ(platform->info.manufacturerName, platform->info.manufacturerName);
- EXPECT_STREQ(platform->info.manufacturerUrl, platform->info.manufacturerUrl);
- EXPECT_STREQ(platform->info.modelNumber, platform->info.modelNumber);
- EXPECT_STREQ(platform->info.dateOfManufacture, platform->info.dateOfManufacture);
- EXPECT_STREQ(platform->info.platformVersion, platform->info.platformVersion);
- EXPECT_STREQ(platform->info.operatingSystemVersion, platform->info.operatingSystemVersion);
- EXPECT_STREQ(platform->info.hardwareVersion, platform->info.hardwareVersion);
- EXPECT_STREQ(platform->info.firmwareVersion, platform->info.firmwareVersion);
- EXPECT_STREQ(platform->info.supportUrl, platform->info.supportUrl);
- EXPECT_STREQ(platform->info.systemTime, platform2->info.systemTime);
- EXPECT_STREQ(platform->interfaces->value, platform2->interfaces->value);
- EXPECT_STREQ(platform->rt->value, platform2->rt->value);
-
- OCPayloadDestroy((OCPayload*)platform);
+ OCRepPayload *platform1 = (OCRepPayload *)parsedPlatform;
+ EXPECT_EQ(platform->base.type, platform1->base.type);
+ char *value = NULL;
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_PLATFORM_ID, &value));
+ EXPECT_STREQ(pfid1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_MFG_NAME, &value));
+ EXPECT_STREQ(mfgnm1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_MFG_URL, &value));
+ EXPECT_STREQ(mfgurl1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_MODEL_NUM, &value));
+ EXPECT_STREQ(modelnum1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_MFG_DATE, &value));
+ EXPECT_STREQ(dom1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_OS_VERSION, &value));
+ EXPECT_STREQ(osver1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_PLATFORM_VERSION, &value));
+ EXPECT_STREQ(pfver1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_HARDWARE_VERSION, &value));
+ EXPECT_STREQ(hwver1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_FIRMWARE_VERSION, &value));
+ EXPECT_STREQ(fwver1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_SUPPORT_URL, &value));
+ EXPECT_STREQ(url1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_SYSTEM_TIME, &value));
+ EXPECT_STREQ(time1, value);
+ OICFree(value);
+
+ EXPECT_TRUE(OCRepPayloadGetPropString(platform1, OC_RSRVD_VID, &value));
+ EXPECT_STREQ(vid1, value);
+ OICFree(value);
+
+ EXPECT_STREQ(platform1->types->value, OC_RSRVD_RESOURCE_TYPE_PLATFORM);
+ EXPECT_STREQ(platform1->interfaces->value, OC_RSRVD_INTERFACE_DEFAULT);
+ EXPECT_STREQ(platform1->interfaces->next->value, OC_RSRVD_INTERFACE_READ);
OC::MessageContainer mc;
mc.setPayload(parsedPlatform);
EXPECT_STREQ(fwver1, r.getValue<std::string>(OC_RSRVD_FIRMWARE_VERSION).c_str());
EXPECT_STREQ(url1, r.getValue<std::string>(OC_RSRVD_SUPPORT_URL).c_str());
EXPECT_STREQ(time1, r.getValue<std::string>(OC_RSRVD_SYSTEM_TIME).c_str());
+ EXPECT_STREQ(vid1, r.getValue<std::string>(OC_RSRVD_VID).c_str());
- OCPayloadDestroy(parsedPlatform);
+ OCPayloadDestroy((OCPayload *)platform);
+ OCPayloadDestroy((OCPayload *)platform1);
}
+
TEST(PresencePayload, Normal)
{
+ static const char uri1[] = "/testuri";
uint32_t maxAge = 0;
uint32_t sequenceNumber = 0;
OCPresenceTrigger trigger = OC_PRESENCE_TRIGGER_CREATE;
case PAYLOAD_TYPE_DISCOVERY:
typeStr = "PAYLOAD_TYPE_DISCOVERY";
break;
- case PAYLOAD_TYPE_DEVICE:
- typeStr = "PAYLOAD_TYPE_DEVICE";
- break;
- case PAYLOAD_TYPE_PLATFORM:
- typeStr = "PAYLOAD_TYPE_PLATFORM";
- break;
case PAYLOAD_TYPE_REPRESENTATION:
typeStr = "PAYLOAD_TYPE_REPRESENTATION";
break;