cc1plus: all warnings being treated as errors fix 55/29355/7
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Thu, 28 Mar 2019 07:44:47 +0000 (09:44 +0200)
committerAleksey Volkov <a.volkov@samsung.com>
Thu, 4 Apr 2019 12:41:53 +0000 (12:41 +0000)
1) error: missing initializer for member OicSecKey::len
2) ISO C++ forbids converting a string constant to 'char*'
3) _POSIX_C_SOURCE redefined

Change-Id: Ib74fd60f124d58213afc9855b71c38ba6d00503c
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
15 files changed:
resource/csdk/security/include/experimental/securevirtualresourcetypes.h
resource/csdk/security/include/internal/credresource.h
resource/csdk/security/provisioning/sample/autoprovisioningclient.c
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/src/SConscript
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/oxmjustworks.c
resource/csdk/security/provisioning/src/oxmmanufacturercert.c
resource/csdk/security/provisioning/src/oxmrandompin.c
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/provisioning/src/provisioningdatabasemanager.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/src/credresource.c
resource/csdk/security/src/csrresource.c

index 0473d4e..0059d34 100644 (file)
@@ -411,6 +411,15 @@ struct OicUuid
     uint8_t             id[UUID_LENGTH];
 };
 
+
+#ifndef OC_ZERO_UUID
+#   if (__STDC_VERSION__ >= 199901L)
+#       define OC_ZERO_UUID {.id={0}}
+#   else
+#       define OC_ZERO_UUID {{0}}
+#   endif
+#endif
+
 /**
  * /oic/sec/jwk (JSON Web Key) data type.
  * See JSON Web Key (JWK)  draft-ietf-jose-json-web-key-41
@@ -426,6 +435,14 @@ struct OicSecKey
 
 };
 
+#ifndef OC_INIT_SEC_KEY
+#   if (__STDC_VERSION__ >= 199901L)
+#       define OC_INIT_SEC_KEY(_data, _len, _encoding) {.data=(_data), .len=(_len), .encoding=(_encoding)}
+#   else
+#       define OC_INIT_SEC_KEY(_data, _len, _encoding) {(_data), (_len), (_encoding)}
+#   endif
+#endif
+
 struct OicSecOpt
 {
     uint8_t                *data;
index 9d78bea..b5501b6 100644 (file)
@@ -210,7 +210,7 @@ int32_t GetDtlsPskCredentials( CADtlsPskCredType_t type,
               unsigned char *result, size_t result_length);
 
 /*
- * This internal callback is used to retrieve UUIDs from CRED 
+ * This internal callback is used to retrieve UUIDs from CRED
  * entries that have matching publicData.
  *
  * @param ctx context holding UUID list
@@ -344,4 +344,12 @@ void FreeCred(OicSecCred_t *cred);
  */
 bool IsCredRowneruuidTheNilUuid();
 
+#ifndef OC_CBOR_VALUE_INIT
+#   if (__STDC_VERSION__ >= 199901L)
+#       define OC_CBOR_VALUE_INIT {.parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0}
+#   else
+#       define OC_CBOR_VALUE_INIT {NULL, NULL, 0, 0, 0, 0}
+#   endif
+#endif
+
 #endif //IOTVT_SRM_CREDR_H
index 6eb897d..16fdc06 100644 (file)
@@ -173,7 +173,7 @@ static void provisionCredCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr,
 }
 
 /* Function of type OCProvisionResultCB from \resource\csdk\security\provisioning\include\pmtypes.h */
-void provisionTrustChainCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
+void provisionTrustChainCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
 {
     if(!hasError)
     {
@@ -571,9 +571,9 @@ static int doGetRequest(const char* uri, int dev_num)
         return -1;
     }
 
-    /* 
-     * Make sure the OCDevAddr passed to OCDoRequest contains the remote peer's UUID, 
-     * so that PSK lookup succeeds. 
+    /*
+     * Make sure the OCDevAddr passed to OCDoRequest contains the remote peer's UUID,
+     * so that PSK lookup succeeds.
      */
     if (!OCConvertUuidToString(device->doxm->deviceID.id, device->endpoint.remoteId))
     {
index c3e28c4..21bf3d2 100644 (file)
@@ -230,7 +230,7 @@ static void provisionCredCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr,
 }
 
 /* Function of type OCProvisionResultCB from \resource\csdk\security\provisioning\include\pmtypes.h */
-void provisionTrustChainCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
+void provisionTrustChainCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
 {
     if (!hasError)
     {
index 4b86b71..bcbaa84 100644 (file)
@@ -28,7 +28,10 @@ if provisioning_lib_env.get('WITH_TCP') == True and provisioning_lib_env.get('WI
 
 target_os = provisioning_lib_env.get('TARGET_OS')
 
-provisioning_lib_env.AppendUnique(CPPPATH=['#resource/csdk/security/include/experimental'])
+provisioning_lib_env.AppendUnique(CPPPATH=[
+    '#resource/csdk/security/include/experimental',
+    '#extlibs/sqlite3'
+])
 
 provisioning_lib_env.PrependUnique(LIBS=['coap'])
 
index ed513e8..aa43351 100755 (executable)
@@ -1574,15 +1574,8 @@ OCStackResult OC_CALL OCSaveTrustCertChain(const uint8_t *trustCertChain, size_t
  */
 OCStackResult OC_CALL OCSaveOwnCertChain(const char* cert, const char* key, uint16_t *credId)
 {
-    OicSecKey_t ownCert = { 0 };
-    ownCert.data = (uint8_t*) cert;
-    ownCert.len = strlen(cert) + 1;
-    ownCert.encoding = OIC_ENCODING_PEM;
-
-    OicSecKey_t ownKey = { 0 };
-    ownKey.data = (uint8_t*) key;
-    ownKey.len = strlen(key) + 1;
-    ownKey.encoding = OIC_ENCODING_PEM;
+    OicSecKey_t ownCert = OC_INIT_SEC_KEY((uint8_t*)cert, strlen(cert) + 1, OIC_ENCODING_PEM);
+    OicSecKey_t ownKey = OC_INIT_SEC_KEY((uint8_t*) key, strlen(key) + 1, OIC_ENCODING_PEM);
 
     return SRPSaveOwnCertChain(&ownCert, &ownKey, credId);
 }
@@ -1599,10 +1592,7 @@ OCStackResult OC_CALL OCSaveOwnCertChain(const char* cert, const char* key, uint
  */
 OCStackResult OC_CALL OCSaveOwnRoleCert(const char* cert, uint16_t *credId)
 {
-    OicSecKey_t ownCert = { 0 };
-    ownCert.data = (uint8_t*)cert;
-    ownCert.len = strlen(cert) + 1;
-    ownCert.encoding = OIC_ENCODING_PEM;
+    OicSecKey_t ownCert = OC_INIT_SEC_KEY((uint8_t*)cert, strlen(cert) + 1, OIC_ENCODING_PEM);
 
     return SRPSaveOwnRoleCert(&ownCert, credId);
 }
index 46bd4e5..0ba399c 100644 (file)
@@ -525,7 +525,7 @@ static void SetResult(OTMContext_t* otmCtx, const OCStackResult res)
         {
             OIC_LOG(WARNING, TAG, "Failed to revert  is DTLS credential handler.");
         }
-        OicUuid_t emptyUuid = { .id={0}};
+        OicUuid_t emptyUuid = OC_ZERO_UUID;
         SetUuidForPinBasedOxm(&emptyUuid);
     }
     else if(OIC_MANUFACTURER_CERTIFICATE == otmCtx->selectedDeviceInfo->doxm->oxmSel ||
@@ -622,7 +622,7 @@ static CAResult_t OwnershipTransferSessionEstablished(const CAEndpoint_t *endpoi
     {
         uint8_t preMutualVerifNum[OWNER_PSK_LENGTH_128] = {0};
         uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN] = {0};
-        OicUuid_t deviceID = {.id = {0}};
+        OicUuid_t deviceID = OC_ZERO_UUID;
 
         //Generate mutualVerifNum
         char label[LABEL_LEN] = {0};
@@ -706,7 +706,7 @@ static CAResult_t OwnershipTransferSessionFailed(const CAEndpoint_t *endpoint,
     {
         OIC_LOG(ERROR, TAG, "The PIN number may be incorrect.");
 
-        OicUuid_t emptyUuid = {.id={0}};
+        OicUuid_t emptyUuid = OC_ZERO_UUID;
         memcpy(&(newDevDoxm->owner), &emptyUuid, sizeof(OicUuid_t));
         newDevDoxm->owned = false;
         otmCtx->attemptCnt++;
@@ -764,7 +764,7 @@ CAResult_t DTLSHandshakeCB(const CAEndpoint_t *endpoint, const CAErrorInfo_t *in
 
     CAResult_t result = CA_STATUS_OK;
     bool emptyOwnerUuid = false;
-    OicUuid_t emptyUuid = {.id={0}};
+    OicUuid_t emptyUuid = OC_ZERO_UUID;
     bool matching = false;
     OicSecDoxm_t* newDevDoxm = NULL;
     OTMContext_t* otmCtx = NULL;
@@ -836,7 +836,7 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
     CopyDevAddrToEndpoint(&selectedDeviceInfo->endpoint, &endpoint);
     endpoint.port = getSecurePort(selectedDeviceInfo);
 
-    OicUuid_t ownerDeviceID = {.id={0}};
+    OicUuid_t ownerDeviceID = OC_ZERO_UUID;
     if (OC_STACK_OK != GetDoxmDeviceID(&ownerDeviceID))
     {
         OIC_LOG(ERROR, TAG, "Error while retrieving Owner's device ID");
@@ -1390,7 +1390,7 @@ static OCStackApplicationResult OwnerCredentialHandler(void *ctx, OCDoHandle UNU
                   */
                 if(OIC_RANDOM_DEVICE_PIN == otmCtx->selectedDeviceInfo->doxm->oxmSel)
                 {
-                    OicUuid_t emptyUuid = { .id={0}};
+                    OicUuid_t emptyUuid = OC_ZERO_UUID;
                     SetUuidForPinBasedOxm(&emptyUuid);
 
                     caResult = CAregisterPskCredentialsHandler(GetDtlsPskCredentials);
@@ -1402,7 +1402,7 @@ static OCStackApplicationResult OwnerCredentialHandler(void *ctx, OCDoHandle UNU
                     }
                 }
     #ifdef __WITH_TLS__
-                otmCtx->selectedDeviceInfo->connType |= CT_FLAG_SECURE;
+                otmCtx->selectedDeviceInfo->connType = (OCConnectivityType)(otmCtx->selectedDeviceInfo->connType | CT_FLAG_SECURE);
     #endif
                 res = PostOwnerAcl(otmCtx, GET_ACL_VER(otmCtx->selectedDeviceInfo->specVer));
                 if(OC_STACK_OK != res)
@@ -1761,7 +1761,7 @@ static OCStackResult PostOwnerCredential(OTMContext_t* otmCtx)
     cbData.cd = NULL;
 
     //Generate owner credential for new device
-    OicUuid_t credSubjectId = {.id={0}};
+    OicUuid_t credSubjectId = OC_ZERO_UUID;
     secPayload->base.type = PAYLOAD_TYPE_SECURITY;
     const OicSecCred_t* ownerCredential = GetCredResourceData(&(deviceInfo->doxm->deviceID));
     if (NULL == ownerCredential)
@@ -3027,7 +3027,7 @@ OCStackResult ConfigSelfOwnership(void)
         return OC_STACK_ERROR;
     }
 
-    OicUuid_t deviceID = {.id={0}};
+    OicUuid_t deviceID = OC_ZERO_UUID;
     if ( OC_STACK_OK != GetDoxmDeviceID(&deviceID) )
     {
         OIC_LOG (ERROR, TAG, "Unable to retrieve doxm Device ID");
index f65674b..84da62d 100644 (file)
@@ -66,7 +66,7 @@ OCStackResult CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx,
         return OC_STACK_INVALID_PARAM;
     }
 
-    OicUuid_t uuidPT = {.id={0}};
+    OicUuid_t uuidPT = OC_ZERO_UUID;
 
     if (OC_STACK_OK != GetDoxmDeviceID(&uuidPT))
     {
index 1ba8554..ee90611 100644 (file)
@@ -85,7 +85,7 @@ OCStackResult CreateMCertificateBasedOwnerTransferPayload(OTMContext_t* otmCtx,
         return OC_STACK_INVALID_PARAM;
     }
 
-    OicUuid_t uuidPT = {.id={0}};
+    OicUuid_t uuidPT = OC_ZERO_UUID;
     *payload = NULL;
     *size = 0;
 
index ca383de..c302f2f 100644 (file)
@@ -64,7 +64,7 @@ OCStackResult CreatePinBasedOwnerTransferPayload(OTMContext_t* otmCtx, uint8_t *
         return OC_STACK_INVALID_PARAM;
     }
 
-    OicUuid_t uuidPT = {.id={0}};
+    OicUuid_t uuidPT = OC_ZERO_UUID;
     *payload = NULL;
     *size = 0;
 
index 3219b06..37a56b2 100644 (file)
@@ -333,7 +333,8 @@ OCStackResult MoveDeviceList(OCProvisionDev_t **ppDstDevicesList,
         return OC_STACK_INVALID_PARAM;
     }
 
-    OCProvisionDev_t *ptr = GetDevice(ppSrcDevicesList, endpoint->addr, endpoint->port);
+    OCProvisionDev_t *ptr = NULL;
+    ptr = GetDevice(ppSrcDevicesList, endpoint->addr, endpoint->port);
     if(ptr)
     {
         LL_DELETE(*ppSrcDevicesList, ptr);
@@ -1576,7 +1577,7 @@ OCStackResult PMMultipleOwnerDeviceDiscovery(unsigned short waittime, bool isMul
     const char *DOXM_MOM_ENABLE_MULTICAST_QUERY = "/oic/sec/doxm?mom!=0&owned=TRUE";
     const char *DOXM_MULTIPLE_OWNED_MULTICAST_QUERY = "/oic/sec/doxm?owned=TRUE";
 
-    DiscoveryInfo *pDInfo = OICCalloc(1, sizeof(DiscoveryInfo));
+    DiscoveryInfo *pDInfo = (DiscoveryInfo *)OICCalloc(1, sizeof(DiscoveryInfo));
     if(NULL == pDInfo)
     {
         OIC_LOG(ERROR, TAG, "PMDeviceDiscovery : Memory allocation failed.");
index d52f276..02a9ae7 100644 (file)
@@ -24,7 +24,7 @@
 #include <stdlib.h>
 #include <limits.h>
 
-#include <sqlite3.h>
+#include "sqlite3.h"
 #include "experimental/logger.h"
 #include "oic_malloc.h"
 #include "provisioningdatabasemanager.h"
index f312f26..c68b8d2 100644 (file)
 
 #define TAG "OIC_SRPAPI"
 
+
+#ifndef OC_INIT_OC_CALLBACK_DATA
+#   if (__STDC_VERSION__ >= 199901L)
+#       define OC_INIT_OC_CALLBACK_DATA(ctx, handler, deleter) {.context=(ctx), .cb=(handler), .cd=(deleter)}
+#   else
+#       define OC_INIT_OC_CALLBACK_DATA(ctx, handler, deleter) {(ctx), (handler), (deleter)}
+#   endif
+#endif
+
 static trustCertChainContext_t g_trustCertChainNotifier;
 
 /**
@@ -639,11 +648,7 @@ static OCStackResult provisionCredentials(OicSecCred_t *cred,
         }
         OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-        OCCallbackData cbData;
-        memset(&cbData, 0, sizeof(cbData));
-        cbData.cb = responseHandler;
-        cbData.context = (void *)credData;
-        cbData.cd = NULL;
+        OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(credData, responseHandler, NULL);
 
         OCDoHandle handle = NULL;
         OCMethod method = OC_REST_POST;
@@ -718,7 +723,7 @@ static OCStackResult ProvisionCredentialsDos(void *ctx, OicSecCred_t *cred,
         }
         OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-        OCCallbackData cbData = { .context = NULL, .cb = NULL, .cd = NULL };
+        OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
         cbData.cb = responseHandler;
         cbData.context = ctx;
         cbData.cd = NULL;
@@ -907,7 +912,7 @@ OCStackResult SetDOS(const Data_t *data, OicSecDeviceOnboardingState_t dos,
         return OC_STACK_INVALID_PARAM;
     }
 
-    OCCallbackData cbData = { .context = NULL, .cb = NULL, .cd = NULL };
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     OCMethod method = OC_REST_POST;
     OCDoHandle handle = NULL;
     OCProvisionDev_t *targetDev = NULL;
@@ -1235,7 +1240,7 @@ static OCStackApplicationResult ProvisionTrustChainCB(void *ctx, OCDoHandle UNUS
         }
         OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-        OCCallbackData cbData =  {.context = NULL, .cb = NULL, .cd = NULL};
+        OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
         cbData.cb = ProvisionCB;
         cbData.context = ctx;
         cbData.cd = NULL;
@@ -1315,7 +1320,7 @@ static OCStackApplicationResult ProvisionSecurityProfileInfoCB(void *ctx, OCDoHa
         }
         OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-        OCCallbackData cbData =  {.context = NULL, .cb = NULL, .cd = NULL};
+        OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
         cbData.cb = ProvisionCB;
         cbData.context = ctx;
         cbData.cd = NULL;
@@ -1611,7 +1616,7 @@ static OCStackApplicationResult ProvisionCertificateCB(void *ctx, OCDoHandle han
     const OCProvisionDev_t *pDev = NULL;
     OicSecCred_t *cred = NULL;
     OCSecurityPayload *secPayload = NULL;
-    OCCallbackData cbData =  {.context = ctx, .cb = ProvisionCB, .cd = NULL};
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(ctx, ProvisionCB, NULL);
     OCDoHandle lHandle = NULL;
     int secureFlag = 0;//don't send private data(key)
 
@@ -1687,7 +1692,7 @@ OCStackResult SRPProvisionCertificate(void *ctx,
     OCStackResult ret = OC_STACK_ERROR;
     Data_t *data = NULL;
     OicSecCred_t *cred = NULL;
-    OicSecKey_t deviceCert = { 0 };
+    OicSecKey_t deviceCert = OC_INIT_SEC_KEY(NULL, 0, OIC_ENCODING_UNKNOW);
 
     OicUuid_t provTooldeviceID =   {{0,}};
     if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
@@ -1866,7 +1871,7 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k
             /* pemCert is the cerficiate to be provisioned */
             VERIFY_NOT_NULL_RETURN(TAG, pemCert, ERROR, OC_STACK_INVALID_PARAM);
 
-            OicSecKey_t deviceCert = { 0 };
+            OicSecKey_t deviceCert = OC_INIT_SEC_KEY(NULL, 0, OIC_ENCODING_UNKNOW);
             deviceCert.data = (uint8_t*) pemCert; /* Casting away const is OK here */
             deviceCert.len = strlen(pemCert) + 1;
             deviceCert.encoding = OIC_ENCODING_PEM;
@@ -2216,11 +2221,7 @@ static OCStackResult SendDeleteCredentialRequest(void* ctx,
         return OC_STACK_ERROR;
     }
 
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(cbData));
-    cbData.context = ctx;
-    cbData.cb = respHandler;
-    cbData.cd = NULL;
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(ctx, respHandler, NULL);
     OIC_LOG_V(INFO, TAG, "URI: %s",reqBuf);
 
     OIC_LOG(DEBUG, TAG, "Sending remove credential request to resource server");
@@ -2284,11 +2285,7 @@ static OCStackResult SendDeleteACLRequest(void* ctx,
         return OC_STACK_ERROR;
     }
 
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(cbData));
-    cbData.context = ctx;
-    cbData.cb = respHandler;
-    cbData.cd = NULL;
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(ctx, respHandler, NULL);
     OIC_LOG_V(INFO, TAG, "URI: %s",reqBuf);
 
     OIC_LOG(DEBUG, TAG, "Sending remove ACL request to resource server");
@@ -2632,7 +2629,7 @@ static OCStackApplicationResult SRPRemoveDeviceCB(void *delDevCtx, OCDoHandle ha
 
     if (clientResponse)
     {
-        OicUuid_t revDevUuid = {.id={0}};
+        OicUuid_t revDevUuid = OC_ZERO_UUID;
         if(UUID_LENGTH == clientResponse->identity.id_length)
         {
             memcpy(revDevUuid.id, clientResponse->identity.id, sizeof(revDevUuid.id));
@@ -2711,7 +2708,7 @@ static OCStackApplicationResult SRPSyncDeviceCredCB(void *delDevCtx, OCDoHandle
     OCProvisionResultCB resultCallback = removeData->resultCallback;
     if (clientResponse)
     {
-        OicUuid_t revDevUuid = {.id={0}};
+        OicUuid_t revDevUuid = OC_ZERO_UUID;
         if(UUID_LENGTH == clientResponse->identity.id_length)
         {
             memcpy(revDevUuid.id, clientResponse->identity.id, sizeof(revDevUuid.id));
@@ -2808,7 +2805,21 @@ static OCStackApplicationResult SRPResetDeviceCB(void *ctx, OCDoHandle UNUSED,
     // Delete Cred and ACL related to the target device.
     const OicSecCred_t *cred = NULL;
     OCProvisionDev_t * pTargetDev = (OCProvisionDev_t *)ctx;
-    CAEndpoint_t endpoint = {.adapter = CA_DEFAULT_ADAPTER};
+    CAEndpoint_t endpoint =
+#if (__STDC_VERSION__ >= 199901L)
+    {.adapter = CA_DEFAULT_ADAPTER, .flags = CA_DEFAULT_FLAGS,
+        .port = 0, .addr = {0}, .ifindex = 0, .remoteId = {0}
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+        ,.routeData = {0}
+#endif
+        };
+#else
+    {CA_DEFAULT_ADAPTER, CA_DEFAULT_FLAGS, 0, {0}, 0, {0}
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+        ,{0}
+#endif
+        };
+#endif
     CAResult_t caResult = CA_STATUS_FAILED;
     OCStackResult res = OC_STACK_OK;
 
@@ -3392,7 +3403,7 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
         return OC_STACK_NO_MEMORY;
     }
 
-    OCCallbackData cbData = { .context = NULL, .cb = NULL, .cd = NULL };
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     OCMethod method = OC_REST_POST;
     OCDoHandle handle = NULL;
     OCProvisionDev_t *targetDev = NULL;
@@ -3571,7 +3582,7 @@ OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDevi
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     cbData.cb = &SRPGetCredResourceCB;
     GetSecData_t* GetSecData = (GetSecData_t*)OICCalloc(1, sizeof(GetSecData_t));
     if (NULL == GetSecData)
@@ -3708,7 +3719,7 @@ OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDevic
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData =  OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     cbData.cb = &SRPGetACLResourceCB;
     GetSecData_t* GetSecData = (GetSecData_t*)OICCalloc(1, sizeof(GetSecData_t));
     if (NULL == GetSecData)
@@ -3942,7 +3953,7 @@ OCStackResult SRPGetCSRResource(void *ctx, const OCProvisionDev_t *selectedDevic
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData =  OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     cbData.cb = &SRPGetCSRResourceCB;
     GetCsrData_t* getCsrData = (GetCsrData_t*)OICCalloc(1, sizeof(GetCsrData_t));
     if (NULL == getCsrData)
@@ -3998,7 +4009,7 @@ OCStackResult SRPGetSpResource(void *ctx, const OCProvisionDev_t *selectedDevice
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData = OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     cbData.cb = &SRPGetSpResourceCB;
     GetSpData_t* getSpData = (GetSpData_t*)OICCalloc(1, sizeof(GetSpData_t));
     if (NULL == getSpData)
@@ -4175,7 +4186,7 @@ OCStackResult SRPGetRolesResource(void *ctx, const OCProvisionDev_t *selectedDev
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData =  OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     cbData.cb = &SRPGetRolesResourceCB;
     GetRolesData_t *getRolesData = (GetRolesData_t*)OICCalloc(1, sizeof(GetRolesData_t));
     if (NULL == getRolesData)
@@ -4275,7 +4286,7 @@ OCStackResult SRPDeleteRoleCertificateByCredId(void* ctx, const OCProvisionDev_t
 
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-    OCCallbackData cbData =  {.context=NULL, .cb=NULL, .cd=NULL};
+    OCCallbackData cbData =  OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
     cbData.cb = &SRPDeleteRoleCertificateCB;
     GetSecData_t *getSecData = (GetSecData_t*)OICCalloc(1, sizeof(GetSecData_t));
     if (NULL == getSecData)
@@ -4389,7 +4400,7 @@ static OCStackApplicationResult ProvisionAclCB(void *ctx, OCDoHandle UNUSED,
         }
 
         // if rowneruuid is empty, set it to device ID
-        OicUuid_t emptyOwner = {.id = {0} };
+        OicUuid_t emptyOwner = OC_ZERO_UUID;
         if (memcmp(&(aclData->acl->rownerID.id), &emptyOwner, UUID_IDENTITY_SIZE) == 0)
         {
             OIC_LOG(DEBUG, TAG, "Set Rowner to PT's deviceId, because Rowner of ACL is empty");
@@ -4441,7 +4452,7 @@ static OCStackApplicationResult ProvisionAclCB(void *ctx, OCDoHandle UNUSED,
         }
         OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
-        OCCallbackData cbData =  {.context = NULL, .cb = NULL, .cd = NULL};
+        OCCallbackData cbData =  OC_INIT_OC_CALLBACK_DATA(NULL, NULL, NULL);
         cbData.cb = ProvisionCB;
         cbData.context = ctx;
         cbData.cd = NULL;
index e4f64bc..14b7d87 100644 (file)
@@ -86,6 +86,14 @@ static const char PEM_END_CRT[] = "-----END CERTIFICATE-----";
 #include <intsafe.h>
 #endif
 
+#ifndef OC_PARSER_ITER_INIT
+#   if (__STDC_VERSION__ >= 199901L)
+#       define OC_PARSER_ITER_INIT {.attrPos = NULL, .attrLen = 0, .valPos = NULL, .valLen = 0, .pi = {0, NULL, NULL, 0, NULL, 0}}
+#   else
+#       define OC_PARSER_ITER_INIT {NULL, 0, NULL, 0, {0, NULL, NULL, 0, NULL, 0}}
+#   endif
+#endif
+
 /** Max credential types number used for TLS */
 #define MAX_TYPE 2
 /** Default cbor payload size. This value is increased in case of CborErrorOutOfMemory.
@@ -100,7 +108,7 @@ static const uint8_t ROLEID_MAP_SIZE = 1;
 
 static OicSecCred_t        *gCred = NULL;
 static OCResourceHandle    gCredHandle = NULL;
-static OicUuid_t           gRownerId = { .id = { 0 } };
+static OicUuid_t           gRownerId = OC_ZERO_UUID;
 
 typedef enum CredCompareResult{
     CRED_CMP_EQUAL = 0,
@@ -149,7 +157,7 @@ static bool CheckSubjectOfCertificate(OicSecCred_t* cred, OicUuid_t deviceID)
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
     VERIFY_NOT_NULL_RETURN(TAG, cred, ERROR, false);
 
-    const OicUuid_t emptyUuid = { .id = { 0 } };
+    const OicUuid_t emptyUuid = OC_ZERO_UUID;
 
     if ( SIGNED_ASYMMETRIC_KEY == cred->credType
         && 0 != strcmp(cred->credUsage, TRUST_CA) )
@@ -184,7 +192,7 @@ static bool CheckSubjectOfCertificate(OicSecCred_t* cred, OicUuid_t deviceID)
  */
 static bool IsValidCredential(const OicSecCred_t* cred)
 {
-    OicUuid_t emptyUuid = {.id={0}};
+    OicUuid_t emptyUuid = OC_ZERO_UUID;
 
 
     OIC_LOG(DEBUG, TAG, "IN IsValidCredential");
@@ -264,7 +272,7 @@ exit:
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
 static bool IsEmptyCred(const OicSecCred_t* cred)
 {
-    OicUuid_t emptyUuid = {.id={0}};
+    OicUuid_t emptyUuid = OC_ZERO_UUID;
 
     VERIFY_SUCCESS(TAG, (0 == memcmp(cred->subject.id, emptyUuid.id, sizeof(emptyUuid))), DEBUG);
     VERIFY_SUCCESS(TAG, !IsNonEmptyRole(&cred->roleId), DEBUG);
@@ -545,7 +553,7 @@ static CborError DeserializeEncodingFromCborInternal(CborValue *map, char *name,
 
 CborError DeserializeEncodingFromCbor(CborValue *rootMap, OicSecKey_t *value)
 {
-    CborValue map = { .parser = NULL };
+    CborValue map = OC_CBOR_VALUE_INIT;
     CborError cborFindResult = cbor_value_enter_container(rootMap, &map);
     size_t len = 0;
 
@@ -579,7 +587,7 @@ CborError DeserializeEncodingFromCbor(CborValue *rootMap, OicSecKey_t *value)
 
 CborError DeserializeSecOptFromCbor(CborValue *rootMap, OicSecOpt_t *value)
 {
-    CborValue map = { .parser = NULL };
+    CborValue map = OC_CBOR_VALUE_INIT;
     CborError cborFindResult = cbor_value_enter_container(rootMap, &map);
     size_t len = 0;
     value->revstat = false;
@@ -1025,8 +1033,14 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
     char* roleIdTagName = NULL;
     char* name = NULL;
     OCStackResult ret = OC_STACK_ERROR;
-    CborValue credCbor = { .parser = NULL };
-    CborParser parser = { .end = NULL };
+    CborValue credCbor = OC_CBOR_VALUE_INIT ;
+    CborParser parser =
+#   if (__STDC_VERSION__ >= 199901L)
+    { .end = NULL, .flags = 0};
+#   else
+    { NULL, 0};
+#   endif
+
     CborError cborFindResult = CborNoError;
     cbor_parser_init(cborPayload, size, 0, &parser, &credCbor);
 
@@ -1038,7 +1052,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
     OicSecCred_t *headCred = NULL;
 
     // Enter CRED Root Map
-    CborValue CredRootMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
+    CborValue CredRootMap = OC_CBOR_VALUE_INIT;
     cborFindResult = cbor_value_enter_container(&credCbor, &CredRootMap);
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering CRED Root Map.");
 
@@ -1063,7 +1077,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                 // Enter CREDS Array
                 size_t tempLen = 0;
                 int credCount = 0;
-                CborValue credArray = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
+                CborValue credArray = OC_CBOR_VALUE_INIT;
                 cborFindResult = cbor_value_enter_container(&CredRootMap, &credArray);
                 VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding Cred Array.");
 
@@ -1071,7 +1085,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                 {
                     credCount++;
                     //CredId -- Mandatory
-                    CborValue credMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
+                    CborValue credMap = OC_CBOR_VALUE_INIT;
                     cborFindResult = cbor_value_enter_container(&credArray, &credMap);
                     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding Cred Map.");
                     OicSecCred_t *cred = NULL;
@@ -1420,7 +1434,7 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr
     OIC_LOG_BUFFER(DEBUG, TAG, cred->subject.id, sizeof(cred->subject.id));
     if (cred->privateData.data)
     {
-        OIC_LOG_V(DEBUG, TAG, "GenerateCredential : privateData len: %"PRIuPTR, cred->privateData.len);
+        OIC_LOG_V(DEBUG, TAG, "GenerateCredential : privateData len: %" PRIuPTR, cred->privateData.len);
         OIC_LOG_BUFFER(DEBUG, TAG, cred->privateData.data, cred->privateData.len);
     }
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
@@ -1463,7 +1477,7 @@ static OCStackResult CopyPayload(uint8_t **payload, size_t *payloadSize, const D
         /* Need more memory to copy encrypted payload out. */
         OICClearMemory(*payload, *payloadSize);
         OICFree(*payload);
-        *payload = OICMalloc(source->cbData);
+        *payload = (uint8_t*)OICMalloc(source->cbData);
 
         if (NULL == *payload)
         {
@@ -1952,8 +1966,7 @@ static OCStackResult RemoveCredentialByCredIds(CredIdList_t *credIdList)
 static bool GetCredIdsFromQueryString(const char *query, CredIdList_t **credid)
 {
     bool found = false;
-    OicParseQueryIter_t parseIter = { .attrPos = NULL };
-
+    OicParseQueryIter_t parseIter = OC_PARSER_ITER_INIT;
     ParseQueryIterInit((unsigned char *) query, &parseIter);
 
     while (GetNextQuery (&parseIter))
@@ -2031,7 +2044,7 @@ static OCStackResult RemoveAllCredentials(void)
  */
 static bool GetSubjectFromQueryString(const char *query, OicUuid_t *subject)
 {
-    OicParseQueryIter_t parseIter = { .attrPos = NULL };
+    OicParseQueryIter_t parseIter = OC_PARSER_ITER_INIT;
 
     ParseQueryIterInit((unsigned char *) query, &parseIter);
 
@@ -2189,7 +2202,7 @@ static bool FillPrivateDataOfSubOwnerPSK(OicSecCred_t* receivedCred, const CAEnd
         int encodeResult = mbedtls_base64_encode(NULL, 0, &b64OutSize, subOwnerPSK, OWNER_PSK_LENGTH_128);
         VERIFY_SUCCESS(TAG, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL == encodeResult, ERROR);
         size_t b64BufSize = b64OutSize;
-        b64Buf = OICCalloc(1, b64BufSize);
+        b64Buf = (unsigned char*)OICCalloc(1, b64BufSize);
         VERIFY_NOT_NULL(TAG, b64Buf, ERROR);
         encodeResult = mbedtls_base64_encode(b64Buf, b64BufSize, &b64OutSize, subOwnerPSK, OWNER_PSK_LENGTH_128);
         VERIFY_SUCCESS(TAG, 0 == encodeResult, ERROR);
@@ -2223,7 +2236,7 @@ static OCEntityHandlerResult HandleNewCredential(OCEntityHandlerRequest *ehReque
     OCEntityHandlerResult ret = OC_EH_INTERNAL_SERVER_ERROR;
 
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
-    OicUuid_t emptyUuid = {.id={0}};
+    OicUuid_t emptyUuid = OC_ZERO_UUID;
     const OicSecDoxm_t *doxm = GetDoxmResourceData();
     if( NO_SECURITY_MODE != cred->credType
         && doxm
@@ -2555,7 +2568,7 @@ static OCEntityHandlerResult HandleDeleteRequest(const OCEntityHandlerRequest *e
 
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
     CredIdList_t *credIdList = NULL;
-    OicUuid_t subject = { .id= { 0 } };
+    OicUuid_t subject = OC_ZERO_UUID;
 
     if (NULL == ehRequest->query)
     {
@@ -2738,7 +2751,7 @@ OCStackResult InitCredResource(void)
     if (gCred)
     {
         OicUuid_t deviceID;
-        OicUuid_t emptyUuid = {.id={0}};
+        OicUuid_t emptyUuid = OC_ZERO_UUID;
 
         ret = GetDoxmDeviceID(&deviceID);
         if (ret != OC_STACK_OK)
@@ -2962,7 +2975,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type,
         case CA_DTLS_PSK_HINT:
         case CA_DTLS_PSK_IDENTITY:
             {
-                OicUuid_t deviceID = {.id={0}};
+                OicUuid_t deviceID = OC_ZERO_UUID;
                 // Retrieve Device ID from doxm resource
                 if ( OC_STACK_OK != GetDoxmDeviceID(&deviceID) )
                 {
@@ -3110,7 +3123,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type,
                                 size_t pinLength = 0;
                                 if (OIC_ENCODING_RAW == wildCardCred->privateData.encoding)
                                 {
-                                    pinBuffer = OICCalloc(1, wildCardCred->privateData.len + 1);
+                                    pinBuffer = (char*)OICCalloc(1, wildCardCred->privateData.len + 1);
                                     if(NULL == pinBuffer)
                                     {
                                         OIC_LOG (ERROR, TAG, "Failed to allocate memory.");
@@ -3128,7 +3141,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type,
                                         goto exit;
                                     }
                                     size_t pinBufSize = pinLength;
-                                    pinBuffer = OICCalloc(1, pinBufSize);
+                                    pinBuffer = (char*)OICCalloc(1, pinBufSize);
                                     if (NULL == pinBuffer)
                                     {
                                         OIC_LOG (ERROR, TAG, "Failed to allocate memory.");
index 9682462..915b67a 100644 (file)
@@ -243,15 +243,21 @@ OCStackResult CBORPayloadToCSR(const uint8_t *cborPayload, size_t size, uint8_t
     }
 
     OCStackResult ret = OC_STACK_ERROR;
-    CborValue csrCbor = { .parser = NULL };
-    CborParser parser = { .end = NULL };
+    CborValue csrCbor = OC_CBOR_VALUE_INIT;
+    CborParser parser =
+#   if (__STDC_VERSION__ >= 199901L)
+    { .end = NULL, .flags = 0 };
+#   else
+    { NULL, 0 };
+#   endif
+
     CborError cborFindResult = CborNoError;
     uint8_t* cborCsr = NULL;
     size_t cborCsrLen = 0;
     char* tagName = NULL;
     size_t len = 0;
 
-    CborValue csrRootMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
+    CborValue csrRootMap = OC_CBOR_VALUE_INIT;
 
     cborFindResult = cbor_parser_init(cborPayload, size, 0, &parser, &csrCbor);
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed to initialize parser.");
@@ -374,8 +380,21 @@ static OCEntityHandlerResult HandleCsrGetRequest(OCEntityHandlerRequest * ehRequ
     char *myUuidStr = NULL;
     char *myDNStr = NULL;
     size_t myDNStrLen = 0;
-    ByteArray_t keyData = { .data = NULL, .len = 0 };
-    OCByteString csr = { .bytes = NULL, .len = 0 };
+
+    ByteArray_t keyData =
+#   if (__STDC_VERSION__ >= 199901L)
+    { .data = NULL, .len = 0 };
+#   else
+    { NULL, 0 };
+#   endif
+
+    OCByteString csr =
+#   if (__STDC_VERSION__ >= 199901L)
+    { .bytes = NULL, .len = 0 };
+#   else
+    { NULL, 0 };
+#   endif
+
     size_t size = 0;
     uint8_t *payload = NULL;