OCEntityHandler entityHandler,
uint8_t resourceProperties)
{
-
- char *coordinatingURI = (char *)malloc(sizeof(char) *
- (strlen(resourceUri) + strlen(OIC_COORDINATING_FLAG)));
+ OCStackResult ret = OC_STACK_OK;
+ size_t coordinateUriLen = sizeof(char) * (strlen(resourceUri) +
+ strlen(OIC_COORDINATING_FLAG) + 1);
+ char *coordinatingURI = (char *)malloc(coordinateUriLen);
if(coordinatingURI == NULL)
{
OC_LOG_V(DEBUG, HOSTING_TAG, "memory alloc fail : coordinatingURI");
return OC_STACK_NO_MEMORY;
}
- snprintf(coordinatingURI, sizeof(coordinatingURI), "%s%s", resourceUri, OIC_COORDINATING_FLAG);
+ snprintf(coordinatingURI, coordinateUriLen,"%s%s", resourceUri, OIC_COORDINATING_FLAG);
OC_LOG_V(DEBUG, HOSTING_TAG, "requiredUri+coordinatingFlag = %s", coordinatingURI);
- return OCCreateResource(handle, resourceTypeName, resourceInterfaceName,
+ ret = OCCreateResource(handle, resourceTypeName, resourceInterfaceName,
coordinatingURI, entityHandler, resourceProperties);
+ free(coordinatingURI);
+ return ret;
}
/*
if (vList->headerNode == NULL)
{
OC_LOG(DEBUG, HOSTING_TAG, "This Discover Response is empty");
+ destroyMirrorResourceList(vList);
return ret;
}
MirrorResource *buildMirrorResource(cJSON *ocArray_sub)
{
-
MirrorResource *mirrorResource = NULL;
- char temp[OIC_STRING_MAX_VALUE] = {'\0'};
- strncpy(temp, cJSON_GetObjectItem(ocArray_sub, "href")->valuestring, sizeof(temp));
+ const char *curValuestring = cJSON_GetObjectItem(ocArray_sub, "href")->valuestring;
- if ( strstr(temp, OIC_COORDINATING_FLAG) )
+ if ( strstr(curValuestring, OIC_COORDINATING_FLAG) )
{
mirrorResource = createMirrorResource();
if(mirrorResource == NULL)
OC_LOG_V(DEBUG, HOSTING_TAG, "memory alloc fail for mirrorResource uri");
goto RET_ERROR;
}
- strncpy(mirrorResource->uri, temp, strlen(temp) - strlen(OIC_COORDINATING_FLAG));
- mirrorResource->uri[strlen(temp) - strlen(OIC_COORDINATING_FLAG)] = '\0';
+ strncpy(mirrorResource->uri, curValuestring, strlen(curValuestring) - strlen(OIC_COORDINATING_FLAG));
+ mirrorResource->uri[strlen(curValuestring) - strlen(OIC_COORDINATING_FLAG)] = '\0';
OC_LOG_V(DEBUG, HOSTING_TAG, "VirtualResource URI : %s", mirrorResource->uri);
cJSON *inArray_sub = cJSON_GetObjectItem(ocArray_sub, "prop");
cJSON *json = cJSON_CreateObject();
char nodeData[OIC_STRING_MAX_VALUE] = {'\0'};
- snprintf(nodeData, sizeof(foundMirrorResource->uri), "%s", foundMirrorResource->uri);
+ snprintf(nodeData, sizeof(nodeData), "%s", foundMirrorResource->uri);
cJSON_AddStringToObject(json, "href", nodeData);
cJSON *nodeRep = cJSON_Parse(cJSON_PrintUnformatted(foundMirrorResource->rep));
if (result != OC_STACK_OK)
{
OC_LOG_V(DEBUG, HOSTING_TAG, "Insert request list : fail3");
- return result;
+ destroyRequestHandle(requestAlive);
+ mirrorResource = mirrorResource->next;
+ continue;
}
result = requestQuery(requestAlive, OC_REST_GET, address, mirrorResource->uri);
{
OC_LOG_V(DEBUG, HOSTING_TAG, "enter buildEntityHandlerResponse");
OCEntityHandlerResponse response;
+ memset(&response, 0, sizeof(response));
OCEntityHandlerResult entityHandlerResult = OC_EH_OK;
char payload[MAX_RESPONSE_LENGTH] = {'\0'};
if (entityHandlerRequest->method == OC_REST_DELETE)
{
- memset(payload, '\0', sizeof(payload));
+ memset(payload, '\0', sizeof(char) * (maxPayloadSize + 1));
OC_LOG_V(DEBUG, HOSTING_TAG, "DELETE");
return OC_EH_RESOURCE_DELETED;
}
if (maxPayloadSize > strlen ((char *)responsePayload))
{
- strncpy(payload, responsePayload, sizeof(payload));
+ strncpy(payload, responsePayload, strlen ((char *)responsePayload));
entityHandlerResult = OC_EH_OK;
}
else
MirrorResource *findMirrorResourceUsingAddressAndURI(MirrorResourceList *mirrorResourceList,
const char *address, OICResourceCoordinatorParamType paramType, const char *uri)
{
- if (mirrorResourceList->headerNode == NULL)
+ if (mirrorResourceList == NULL || address == NULL)
{
- OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : Empty Virtual Resource List.");
+ OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : invalid parameter.");
return NULL;
}
- if (mirrorResourceList == NULL || address == NULL)
+ if (mirrorResourceList->headerNode == NULL)
{
- OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : invalid parameter.");
+ OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : Empty Virtual Resource List.");
return NULL;
}
if (mirrorResourceList->headerNode == NULL)
{
OC_LOG_V(DEBUG, VR_TAG, "Eject Virtual Resource : Empty Virtual Resource List.");
+ return OC_STACK_ERROR;
}
if (mirrorResource == mirrorResourceList->headerNode)
strcpy(clonedMirrorResource->address[i], sourceMirrorResource->address[i]);
}
- // copy prop ??
-
return clonedMirrorResource;
}
MirrorResourceList *findMirrorResourceListUsingAddress(MirrorResourceList *mirrorResourceList,
const char *address, OICResourceCoordinatorParamType paramType)
{
-
- MirrorResource *tempNode = mirrorResourceList->headerNode;
- while (tempNode != NULL)
- {
- OC_LOG_V(DEBUG, VR_TAG, "uri = %s", tempNode->uri);
- tempNode = tempNode->next;
- }
-
if (mirrorResourceList == NULL || address == NULL)
{
OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource List : invalid parameter.");
return NULL;
}
+ MirrorResource *tempNode = mirrorResourceList->headerNode;
+ while (tempNode != NULL)
+ {
+ OC_LOG_V(DEBUG, VR_TAG, "uri = %s", tempNode->uri);
+ tempNode = tempNode->next;
+ }
+
+
MirrorResourceList *resultMirrorResourceList = createMirrorResourceList();
MirrorResource *mirrorResource = mirrorResourceList->headerNode;
while (mirrorResource != NULL)