ClientCB *cbNode = NULL;
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(method == OC_REST_PRESENCE)
{ // Retrieve the presence callback structure for this specific requestUri.
cbNode = GetClientCB(NULL, 0, NULL, requestUri);
}
- #endif // WITH_PRESENCE
+#endif // WITH_PRESENCE
if(!cbNode)// If it does not already exist, create new node.
{
*handle = cbNode->handle;
}
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(method == OC_REST_PRESENCE && resourceTypeName)
{
// Amend the found or created node by adding a new resourceType to it.
{
OICFree(resourceTypeName);
}
- #else
+#else
OICFree(resourceTypeName);
- #endif
+#endif
return OC_STACK_OK;
- exit:
- return OC_STACK_NO_MEMORY;
+exit:
+ return OC_STACK_NO_MEMORY;
}
void DeleteClientCB(ClientCB * cbNode)
cbNode->deleteCallback(cbNode->context);
}
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(cbNode->presence)
{
OICFree(cbNode->presence->timeOut);
pointer = next;
}
}
- #endif // WITH_PRESENCE
+#endif // WITH_PRESENCE
OICFree(cbNode);
cbNode = NULL;
}
OC_LOG(INFO, TAG, "Entering ValidateQuery");
if (!query)
+ {
return OC_STACK_ERROR;
+ }
if(!ifParam || !rtParam)
{
}
token = strtok_r (NULL, OC_QUERY_SEPARATOR, &endStr);
}
+
if (numFields > NUM_FIELDS_IN_QUERY)
{
// current release supports one IF value, one RT value and no other params
static OCStackResult
HandleBatchInterface(OCEntityHandlerRequest *ehRequest)
{
+ if (!ehRequest)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
OCStackResult stackRet = OC_STACK_OK;
OCEntityHandlerResult ehResult = OC_EH_ERROR;
OCResource * collResource = (OCResource *) ehRequest->resource;
if(stackRet == OC_STACK_OK)
{
- OCRepPayloadSetUri(payload, collResource->uri);
+ if (collResource)
+ {
+ OCRepPayloadSetUri(payload, collResource->uri);
+ }
}
if(stackRet == OC_STACK_OK)
if (stackRet == OC_STACK_OK)
{
- for (int i = 0; i < MAX_CONTAINED_RESOURCES; i++)
+ for (uint8_t i = 0; i < MAX_CONTAINED_RESOURCES; i++)
{
OCResource* temp = collResource->rsrcResources[i];
if (temp)
if(resource)
{
uint8_t num = 0;
- for (int i = 0; i < MAX_CONTAINED_RESOURCES; i++)
+ for (uint8_t i = 0; i < MAX_CONTAINED_RESOURCES; i++)
{
if (resource->rsrcResources[i])
{
{
OC_LOG_V(INFO, TAG, "Current NON count for this observer is %d",
resourceObserver->lowQosCount);
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if((resourceObserver->forceHighQos \
|| resourceObserver->lowQosCount >= MAX_OBSERVER_NON_COUNT) \
&& method != OC_REST_PRESENCE)
- #else
+#else
if(resourceObserver->forceHighQos \
|| resourceObserver->lowQosCount >= MAX_OBSERVER_NON_COUNT)
- #endif
+#endif
{
resourceObserver->lowQosCount = 0;
// at some point we have to to send CON to check on the
if (resourceObserver->resource == resPtr)
{
numObs++;
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(method != OC_REST_PRESENCE)
{
- #endif
+#endif
qos = DetermineObserverQoS(method, resourceObserver, qos);
result = AddServerRequest(&request, 0, 0, 1, OC_REST_GET,
OCPayloadDestroy(ehRequest.payload);
}
}
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
}
else
{
OCPresencePayloadDestroy(presenceResBuf);
}
}
- #endif
+#endif
// Since we are in a loop, set an error flag to indicate at least one error occurred.
if (result != OC_STACK_OK)
uint8_t numOptions,
uint8_t observeFlag)
{
- if(!caHdrOpt)
+ if(!caHdrOpt || !ocHdrOpt)
{
return OC_STACK_INVALID_PARAM;
}
{
return OC_STACK_INVALID_PARAM;
}
- *observationOption = OC_OBSERVE_NO_OPTION;
if(!options || !numOptions)
{
return OC_STACK_INVALID_PARAM;
}
+ *observationOption = OC_OBSERVE_NO_OPTION;
+
for(uint8_t i = 0; i < *numOptions; i++)
{
if(options[i].protocolID == CA_COAP_ID &&
static void OCCopyPropertyValueArray(OCRepPayloadValue* dest, OCRepPayloadValue* source)
{
+ if(!dest || !source)
+ {
+ return;
+ }
+
size_t dimTotal = calcDimTotal(source->arr.dimensions);
switch(source->arr.type)
{
OCStringLL* cur = pl->interfaces;
ifPtr = ifPtr->next;
- while(ifPtr)
+ while(ifPtr && cur)
{
cur->next = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
if(!cur->next)
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);
static OCStackResult OCParseSecurityPayload(OCPayload** outPayload, CborValue* arrayVal)
{
+ if (!outPayload)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
bool err = false;
char * securityData = NULL;
static OCStackResult OCParseDiscoveryPayload(OCPayload** outPayload, CborValue* arrayVal)
{
+ if (!outPayload)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
bool err = false;
OCDiscoveryPayload* out = OCDiscoveryPayloadCreate();
static OCStackResult OCParseDevicePayload(OCPayload** outPayload, CborValue* arrayVal)
{
+ if (!outPayload)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
bool err = false;
if(cbor_value_is_map(arrayVal))
static OCStackResult OCParsePlatformPayload(OCPayload** outPayload, CborValue* arrayVal)
{
+ if (!outPayload)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
bool err = false;
if(cbor_value_is_map(arrayVal))
static bool OCParseSingleRepPayload(OCRepPayload** outPayload, CborValue* repParent)
{
+ if (!outPayload)
+ {
+ return false;
+ }
+
*outPayload = OCRepPayloadCreate();
OCRepPayload* curPayload = *outPayload;
bool err = false;
while(!err && cbor_value_is_valid(&repMap))
{
char* name;
- err = err || cbor_value_dup_text_string(&repMap, &name, &len, NULL);
+ err = err || cbor_value_dup_text_string(&repMap, &name, &len, NULL);
- err = err || cbor_value_advance(&repMap);
+ err = err || cbor_value_advance(&repMap);
int64_t intval = 0;
bool boolval = false;
}
static OCStackResult OCParseRepPayload(OCPayload** outPayload, CborValue* arrayVal)
{
+ if (!outPayload)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
bool err = false;
OCRepPayload* rootPayload = NULL;
static OCStackResult OCParsePresencePayload(OCPayload** outPayload, CborValue* arrayVal)
{
+ if (!outPayload)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
bool err = false;
if(cbor_value_is_map(arrayVal))
{
}
else
{
- OCResource *resourcePtr = NULL;
- resourcePtr = FindResourceByUri((const char*)request->resourceUrl);
+ OCResource *resourcePtr = FindResourceByUri((const char*)request->resourceUrl);
*resource = resourcePtr;
if (!resourcePtr)
{
return false;
}
- if ( resource->resourceProperties & OC_EXPLICIT_DISCOVERABLE)
+ if (resource->resourceProperties & OC_EXPLICIT_DISCOVERABLE)
{
/*
* At least one valid filter should be available to
return false;
}
}
- else if ( !(resource->resourceProperties & OC_ACTIVE) ||
+ else if (!(resource->resourceProperties & OC_ACTIVE) ||
!(resource->resourceProperties & OC_DISCOVERABLE))
{
OC_LOG_V(INFO, TAG, "%s not ACTIVE or DISCOVERABLE", resource->uri);
* request is unicast, it should send an error(RESOURCE_NOT_FOUND - 404) response.
*/
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if ((virtualUriInRequest == OC_PRESENCE) &&
(resource->resourceProperties & OC_ACTIVE))
{
SendPresenceNotification(resource->rsrcType, OC_PRESENCE_TRIGGER_CHANGE);
}
else
- #endif
+#endif
{
if(discoveryResult == OC_STACK_OK)
{
}
else
{
- OC_LOG(ERROR, TAG, "Platform info saved.");
+ OC_LOG(INFO, TAG, "Platform info saved.");
}
return res;
OC_LOG(INFO, TAG, "Device initialized successfully.");
return OC_STACK_OK;
- exit:
- DeleteDeviceInfo();
- return res;
-
+exit:
+ DeleteDeviceInfo();
+ return res;
}
*/
static OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle)
{
+ if (!response)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
OCServerResponse * serverResponse = NULL;
serverResponse = (OCServerResponse *) OICCalloc(1, sizeof(OCServerResponse));
char * resourceUrl, size_t reqTotalSize, OCPayloadFormat acceptFormat,
const OCDevAddr *devAddr)
{
+ if (!request)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
OCServerRequest * serverRequest = NULL;
serverRequest = (OCServerRequest *) OICCalloc(1, sizeof(OCServerRequest) +
CAResponseResult_t ConvertEHResultToCAResult (OCEntityHandlerResult result, OCMethod method)
{
- CAResponseResult_t caResult = CA_BAD_REQ;
+ CAResponseResult_t caResult;
switch (result)
{
{
responseInfo.info.type = CA_MSG_NONCONFIRM;
}
+ else
+ {
+ OC_LOG(ERROR, TAG, "default responseInfo type is NON");
+ responseInfo.info.type = CA_MSG_NONCONFIRM;
+ }
char rspToken[CA_MAX_TOKEN_LEN + 1] = {};
responseInfo.info.messageId = serverRequest->coapID;
responseInfo.info.options[0].optionLength = sizeof(uint32_t);
uint8_t* observationData = (uint8_t*)responseInfo.info.options[0].optionData;
uint32_t observationOption= serverRequest->observationOption;
- size_t i;
- for (i=sizeof(uint32_t); i; --i)
+
+ for (size_t i=sizeof(uint32_t); i; --i)
{
observationData[i-1] = observationOption & 0xFF;
observationOption >>=8;
#endif
};
- int size = sizeof(CAConnTypes)/ sizeof(CATransportAdapter_t);
+ size_t size = sizeof(CAConnTypes)/ sizeof(CATransportAdapter_t);
CATransportAdapter_t adapter = responseEndpoint.adapter;
// Default adapter, try to send response out on all adapters.
result = OC_STACK_OK;
OCStackResult tempResult = OC_STACK_OK;
- for(int i = 0; i < size; i++ )
+ for(size_t i = 0; i < size; i++ )
{
responseEndpoint.adapter = (CATransportAdapter_t)(adapter & CAConnTypes[i]);
if(responseEndpoint.adapter)
*/
OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse)
{
- OCStackResult stackRet = OC_STACK_ERROR;
- OCServerRequest * serverRequest = NULL;
- OCServerResponse * serverResponse = NULL;
-
if(!ehResponse || !ehResponse->payload)
{
OC_LOG(ERROR, TAG, "HandleAggregateResponse invalid parameters");
OC_LOG(INFO, TAG, "Inside HandleAggregateResponse");
- serverRequest = GetServerRequestUsingHandle((OCServerRequest *)ehResponse->requestHandle);
- serverResponse = GetServerResponseUsingHandle((OCServerRequest *)ehResponse->requestHandle);
+ OCServerRequest *serverRequest = GetServerRequestUsingHandle((OCServerRequest *)
+ ehResponse->requestHandle);
+ OCServerResponse *serverResponse = GetServerResponseUsingHandle((OCServerRequest *)
+ ehResponse->requestHandle);
+ OCStackResult stackRet = OC_STACK_ERROR;
if(serverRequest)
{
if(!serverResponse)