{
OCResource *pointer = NULL;
- char *str = NULL;
OCStackResult result = OC_STACK_ERROR;
OC_LOG(INFO, TAG, "Entering OCCreateResource");
insertResource(pointer);
// Set the uri
- str = OICStrdup(uri);
- if (!str)
+ pointer->uri = OICStrdup(uri);
+ if (!pointer->uri)
{
result = OC_STACK_NO_MEMORY;
goto exit;
}
- pointer->uri = str;
// Set properties. Set OC_ACTIVE
pointer->resourceProperties = (OCResourceProperty) (resourceProperties
{
// Deep delete of resource and other dynamic elements that it contains
deleteResource(pointer);
- OICFree(str);
}
return result;
}
return OC_STACK_ERROR;
}
+// Precondition is that the parameter has been checked to not equal NULL.
+static bool ValidateResourceTypeInterface(const char *resourceItemName)
+{
+ if (resourceItemName[0] < 'a' || resourceItemName[0] > 'z')
+ {
+ return false;
+ }
+
+ size_t index = 1;
+ while (resourceItemName[index] != '\0')
+ {
+ if (resourceItemName[index] != '.' &&
+ resourceItemName[index] != '-' &&
+ (resourceItemName[index] < 'a' || resourceItemName[index] > 'z') &&
+ (resourceItemName[index] < '0' || resourceItemName[index] > '9'))
+ {
+ return false;
+ }
+ ++index;
+ }
+
+ return true;
+}
OCStackResult BindResourceTypeToResource(OCResource* resource,
const char *resourceTypeName)
{
VERIFY_NON_NULL(resourceTypeName, ERROR, OC_STACK_INVALID_PARAM);
+ if (!ValidateResourceTypeInterface(resourceTypeName))
+ {
+ OC_LOG(ERROR, TAG, "resource type illegal (see RFC 6690)");
+ return OC_STACK_INVALID_PARAM;
+ }
+
pointer = (OCResourceType *) OICCalloc(1, sizeof(OCResourceType));
if (!pointer)
{
VERIFY_NON_NULL(resourceInterfaceName, ERROR, OC_STACK_INVALID_PARAM);
+ if (!ValidateResourceTypeInterface(resourceInterfaceName))
+ {
+ OC_LOG(ERROR, TAG, "resource /interface illegal (see RFC 6690)");
+ return OC_STACK_INVALID_PARAM;
+ }
+
OC_LOG_V(INFO, TAG, "Binding %s interface to %s", resourceInterfaceName, resource->uri);
pointer = (OCResourceInterface *) OICCalloc(1, sizeof(OCResourceInterface));
OCResourceResponse response;
OCResourceHandle resHandle;
- std::string resourceURI = "/a/light1";
+ std::string resourceURI = "/a/light2";
std::string resourceTypeName = "core.light";
std::string resourceInterface = DEFAULT_INTERFACE;
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
- EXPECT_EQ(OC_STACK_OK, OCCreateResource(&resHandle, resourceURI.c_str(),
- resourceTypeName.c_str(), resourceInterface.c_str(), nullptr, nullptr,
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&resHandle, resourceTypeName.c_str(),
+ resourceInterface.c_str(), resourceURI.c_str(), nullptr, nullptr,
resourceProperty));
EXPECT_EQ(NULL, response.getResourceHandle());
EXPECT_NO_THROW(response.setResourceHandle(resHandle));