*
* *****************************************************************/
+#include "iotivity_config.h"
#include <stdlib.h>
#include <string.h>
#include "ocstack.h"
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
+#if defined (__TIZENRT__)
+#include <apps/netutils/cJSON.h>
+#else
#include "cJSON.h"
+#endif
#include "base64.h"
#include "ocpayload.h"
+#include "ocpayloadcbor.h"
#include "payload_logging.h"
#include "resourcemanager.h"
#include "pconfresource.h"
#include "doxmresource.h"
#include "srmutility.h"
#include "ocserverrequest.h"
-#include <stdlib.h>
#include "psinterface.h"
#include "security_internals.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
-#define TAG "SRM-PCONF"
+#define TAG "OIC_SRM_PCONF"
static const uint16_t CBOR_SIZE = 1024;
static const uint64_t CBOR_MAX_SIZE = 4400;
cborEncoderResult = cbor_encoder_close_container(&encoder, &pconfMap);
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to close pconfMap");
- *size = encoder.ptr - outPayload;
+ *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
*payload = outPayload;
ret = OC_STACK_OK;
exit:
// reallocate and try again!
OICFree(outPayload);
// Since the allocated initial memory failed, double the memory.
- cborLen += encoder.ptr - encoder.end;
+ cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
cborEncoderResult = CborNoError;
ret = PconfToCBORPayload(pconf, payload, &cborLen);
*size = cborLen;
char *name = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&pconfMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&pconfMap))
{
cborFindResult = cbor_value_dup_text_string(&pconfMap, &name, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
if (name)
{
//EDP -- Mandatory
- if(0 == strcmp(OIC_JSON_EDP_NAME, name))
+ if(0 == strcmp(OIC_JSON_EDP_NAME, name) && cbor_value_is_boolean(&pconfMap))
{
cborFindResult = cbor_value_get_boolean(&pconfMap, &pconf->edp);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
cborFindResult = cbor_value_enter_container(&pconfMap, &prm);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to eneter array");
- while (cbor_value_is_valid(&prm))
+ while (cbor_value_is_valid(&prm) && cbor_value_is_integer(&prm))
{
- cborFindResult = cbor_value_get_int(&prm, (int *)&pconf->prm[i++]);
+ int prm_val;
+
+ cborFindResult = cbor_value_get_int(&prm, &prm_val);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
+ pconf->prm[i++] = (OicSecPrm_t)prm_val;
cborFindResult = cbor_value_advance(&prm);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance value");
}
}
//PIN -- Mandatory
- if (0 == strcmp(OIC_JSON_PIN_NAME, name))
+ if (0 == strcmp(OIC_JSON_PIN_NAME, name) && cbor_value_is_byte_string(&pconfMap))
{
uint8_t *pin = NULL;
cborFindResult = cbor_value_dup_byte_string(&pconfMap, &pin, &len, NULL);
char* name = NULL;
size_t len = 0;
CborType type = cbor_value_get_type(&pdAclMap);
- if (type == CborTextStringType)
+ if (type == CborTextStringType && cbor_value_is_text_string(&pdAclMap))
{
cborFindResult = cbor_value_dup_text_string(&pdAclMap, &name,
&len, NULL);
if (name)
{
// Resources -- Mandatory
- if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0)
+ if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
{
int i = 0;
CborValue resources = { .parser = NULL };
cborFindResult = cbor_value_enter_container(&resources, &rMap);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
- while(cbor_value_is_valid(&rMap))
+ while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
{
char *rMapName = NULL;
size_t rMapNameLen = 0;
}
// Permissions -- Mandatory
- if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0 && cbor_value_is_unsigned_integer(&pdAclMap))
{
- cborFindResult = cbor_value_get_uint64(&pdAclMap,
- (uint64_t *) &pdacl->permission);
+ uint64_t permission = 0;
+ cborFindResult = cbor_value_get_uint64(&pdAclMap, &permission);
+ pdacl->permission = (uint16_t)permission;
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
}
// Period -- Not mandatory
- if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0 && cbor_value_is_array(&pdAclMap))
{
int i = 0;
CborValue period = { .parser = NULL };
pdacl->periods = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*));
VERIFY_NON_NULL(TAG, pdacl->periods, ERROR);
- while (cbor_value_is_text_string(&period))
+ while (cbor_value_is_text_string(&period) && cbor_value_is_text_string(&period))
{
cborFindResult = cbor_value_dup_text_string(&period,
&pdacl->periods[i++], &len, NULL);
}
// Recurrence -- Not mandatory
- if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0)
+ if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
{
int i = 0;
CborValue recurrences = { .parser = NULL };
pdacl->recurrences = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*));
VERIFY_NON_NULL(TAG, pdacl->recurrences, ERROR);
- while (cbor_value_is_text_string(&recurrences))
+ while (cbor_value_is_text_string(&recurrences) && cbor_value_is_text_string(&recurrences))
{
cborFindResult = cbor_value_dup_text_string(&recurrences,
&pdacl->recurrences[i++], &len, NULL);
}
//PDDev -- Mandatory
- if (strcmp(name, OIC_JSON_PDDEV_LIST_NAME) == 0)
+ if (strcmp(name, OIC_JSON_PDDEV_LIST_NAME) == 0 && cbor_value_is_array(&pconfMap))
{
int i = 0;
CborValue pddevs = { .parser = NULL };
pconf->pddevs = (OicUuid_t *)OICMalloc(pconf->pddevLen * sizeof(OicUuid_t));
VERIFY_NON_NULL(TAG, pconf->pddevs, ERROR);
- while (cbor_value_is_valid(&pddevs))
+ while (cbor_value_is_valid(&pddevs) && cbor_value_is_text_string(&pddevs))
{
char *pddev = NULL;
cborFindResult = cbor_value_dup_text_string(&pddevs, &pddev, &len, NULL);
}
//Mandatory - Device Id
- if (0 == strcmp(OIC_JSON_DEVICE_ID_NAME, name))
+ if (0 == strcmp(OIC_JSON_DEVICE_ID_NAME, name) && cbor_value_is_text_string(&pconfMap))
{
char *deviceId = NULL;
cborFindResult = cbor_value_dup_text_string(&pconfMap, &deviceId, &len, NULL);
}
// ROwner -- Mandatory
- if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name))
+ if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name) && cbor_value_is_text_string(&pconfMap))
{
char *rowner = NULL;
cborFindResult = cbor_value_dup_text_string(&pconfMap, &rowner, &len, NULL);
{
uint8_t* payload = NULL;
size_t size = 0;
+ const OicSecDoxm_t *m_doxm = NULL;
OCEntityHandlerResult ehRet = OC_EH_OK;
OicSecPconf_t pconf;
OIC_LOG (DEBUG, TAG, "Pconf EntityHandle processing GET request");
- if (true == GetDoxmResourceData()->dpc)
+ m_doxm = GetDoxmResourceData();
+ if (NULL == m_doxm)
+ {
+ OIC_LOG (DEBUG, TAG, "Doxm resource Data is NULL");
+ }
+
+ if ((m_doxm) && (true == m_doxm->dpc))
{
//Making response elements for Get request
if( (true == gPconf->edp) &&
OCStackResult res=OC_STACK_OK;
OicSecPconf_t* newPconf = NULL;
- if (true == GetDoxmResourceData()->dpc)
+ if (NULL != GetDoxmResourceData() && true == GetDoxmResourceData()->dpc)
{
// Convert CBOR PCONF data into binary. This will also validate the PCONF data received.
uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
// Update storage
if(OC_EH_ERROR != ehRet && true == UpdatePersistentStorage(gPconf))
{
- ehRet = OC_EH_RESOURCE_CREATED;
+ ehRet = OC_EH_CHANGED;
}
DeletePconfBinData(newPconf);
ret = OCCreateResource(&gPconfHandle,
OIC_RSRC_TYPE_SEC_PCONF,
- OIC_MI_DEF,
+ OC_RSRVD_INTERFACE_DEFAULT,
OIC_RSRC_PCONF_URI,
PconfEntityHandler,
NULL,