1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 #include "cainterface.h"
28 #include "oic_malloc.h"
29 #include "oic_string.h"
30 #include "ocpayload.h"
31 #include "ocpayloadcbor.h"
32 #include "payload_logging.h"
33 #include "secureresourcemanager.h"
34 #include "srmresourcestrings.h"
35 #include "srmutility.h"
36 #include "aclresource.h"
37 #include "pstatresource.h"
38 #include "doxmresource.h"
39 #include "amaclresource.h"
40 #include "credresource.h"
41 #include "svcresource.h"
42 #include "security_internals.h"
44 #define TAG "OIC_JSON2CBOR"
45 #define MAX_RANGE ((size_t)-1)
46 //SVR database buffer block size
48 #define DB_FILE_SIZE_BLOCK 1023
50 static OicSecPstat_t* JSONToPstatBin(const char * jsonStr);
51 static OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr);
52 static OicSecAcl_t *JSONToAclBin(const char * jsonStr);
53 static OicSecSvc_t* JSONToSvcBin(const char * jsonStr);
54 static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr);
55 static OicSecCred_t* JSONToCredBin(const char * jsonStr);
57 static size_t GetJSONFileSize(const char *jsonFileName)
61 char buffer[DB_FILE_SIZE_BLOCK];
62 FILE* fp = fopen(jsonFileName, "r");
67 bytesRead = fread(buffer, 1, DB_FILE_SIZE_BLOCK, fp);
68 if (bytesRead >=(MAX_RANGE - size))
74 } while (bytesRead > 0);
80 static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName)
85 uint8_t *aclCbor = NULL;
86 uint8_t *pstatCbor = NULL;
87 uint8_t *doxmCbor = NULL;
88 uint8_t *amaclCbor = NULL;
89 uint8_t *svcCbor = NULL;
90 uint8_t *credCbor = NULL;
91 cJSON *jsonRoot = NULL;
92 OCStackResult ret = OC_STACK_ERROR;
93 size_t size = GetJSONFileSize(jsonFileName);
96 OIC_LOG (ERROR, TAG, "Failed converting to JSON");
100 jsonStr = (char *)OICMalloc(size + 1);
101 VERIFY_NON_NULL(TAG, jsonStr, FATAL);
103 fp = fopen(jsonFileName, "r");
106 size_t bytesRead = fread(jsonStr, 1, size, fp);
107 jsonStr[bytesRead] = '\0';
109 OIC_LOG_V(DEBUG, TAG, "Read %zu bytes", bytesRead);
115 OIC_LOG (ERROR, TAG, "Unable to open JSON file!!");
119 jsonRoot = cJSON_Parse(jsonStr);
121 cJSON *value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME);
122 //printf("ACL json : \n%s\n", cJSON_PrintUnformatted(value));
123 size_t aclCborSize = 0;
126 OicSecAcl_t *acl = JSONToAclBin(jsonStr);
127 VERIFY_NON_NULL(TAG, acl, FATAL);
128 ret = AclToCBORPayload(acl, &aclCbor, &aclCborSize);
129 if(OC_STACK_OK != ret)
131 OIC_LOG (ERROR, TAG, "Failed converting Acl to Cbor Payload");
135 printf("ACL Cbor Size: %zd\n", aclCborSize);
139 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
140 size_t pstatCborSize = 0;
143 OicSecPstat_t *pstat = JSONToPstatBin(jsonStr);
144 VERIFY_NON_NULL(TAG, pstat, FATAL);
145 ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize, false);
146 if(OC_STACK_OK != ret)
148 OIC_LOG (ERROR, TAG, "Failed converting Pstat to Cbor Payload");
149 DeletePstatBinData(pstat);
152 printf("PSTAT Cbor Size: %zd\n", pstatCborSize);
153 DeletePstatBinData(pstat);
155 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME);
156 size_t doxmCborSize = 0;
159 OicSecDoxm_t *doxm = JSONToDoxmBin(jsonStr);
160 VERIFY_NON_NULL(TAG, doxm, FATAL);
161 ret = DoxmToCBORPayload(doxm, &doxmCbor, &doxmCborSize, false);
162 if(OC_STACK_OK != ret)
164 OIC_LOG (ERROR, TAG, "Failed converting Doxm to Cbor Payload");
165 DeleteDoxmBinData(doxm);
168 printf("DOXM Cbor Size: %zd\n", doxmCborSize);
169 DeleteDoxmBinData(doxm);
171 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME);
172 size_t amaclCborSize = 0;
175 OicSecAmacl_t *amacl = JSONToAmaclBin(jsonStr);
176 VERIFY_NON_NULL(TAG, amacl, FATAL);
177 ret = AmaclToCBORPayload(amacl, &amaclCbor, &amaclCborSize);
178 if(OC_STACK_OK != ret)
180 OIC_LOG (ERROR, TAG, "Failed converting Amacl to Cbor Payload");
181 DeleteAmaclList(amacl);
184 printf("AMACL Cbor Size: %zd\n", amaclCborSize);
185 DeleteAmaclList(amacl);
187 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME);
188 size_t svcCborSize = 0;
191 OicSecSvc_t *svc = JSONToSvcBin(jsonStr);
192 VERIFY_NON_NULL(TAG, svc, FATAL);
193 ret = SVCToCBORPayload(svc, &svcCbor, &svcCborSize);
194 if(OC_STACK_OK != ret)
196 OIC_LOG (ERROR, TAG, "Failed converting Svc to Cbor Payload");
200 printf("SVC Cbor Size: %zd\n", svcCborSize);
203 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME);
204 //printf("CRED json : \n%s\n", cJSON_PrintUnformatted(value));
205 size_t credCborSize = 0;
209 OicSecCred_t *cred = JSONToCredBin(jsonStr);
210 VERIFY_NON_NULL(TAG, cred, FATAL);
211 ret = CredToCBORPayload(cred, &credCbor, &credCborSize, secureFlag);
212 if(OC_STACK_OK != ret)
214 OIC_LOG (ERROR, TAG, "Failed converting Cred to Cbor Payload");
215 DeleteCredList(cred);
218 printf("CRED Cbor Size: %zd\n", credCborSize);
219 DeleteCredList(cred);
223 size_t cborSize = aclCborSize + pstatCborSize + doxmCborSize + svcCborSize + credCborSize + amaclCborSize;
225 printf("Total Cbor Size : %zd\n", cborSize);
226 cborSize += 255; // buffer margin for adding map and byte string
227 uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborSize);
228 VERIFY_NON_NULL(TAG, outPayload, ERROR);
229 cbor_encoder_init(&encoder, outPayload, cborSize, 0);
231 CborError cborEncoderResult = cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength);
232 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Creating Main Map.");
235 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_ACL_NAME, strlen(OIC_JSON_ACL_NAME));
236 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Name.");
237 cborEncoderResult = cbor_encode_byte_string(&map, aclCbor, aclCborSize);
238 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Value.");
241 if (pstatCborSize > 0)
243 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_PSTAT_NAME, strlen(OIC_JSON_PSTAT_NAME));
244 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Name.");
245 cborEncoderResult = cbor_encode_byte_string(&map, pstatCbor, pstatCborSize);
246 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Value.");
248 if (doxmCborSize > 0)
250 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_DOXM_NAME, strlen(OIC_JSON_DOXM_NAME));
251 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding DOXM Name.");
252 cborEncoderResult = cbor_encode_byte_string(&map, doxmCbor, doxmCborSize);
253 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding DOXM Value.");
255 if (amaclCborSize > 0)
257 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_AMACL_NAME, strlen(OIC_JSON_AMACL_NAME));
258 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding AMACL Name.");
259 cborEncoderResult = cbor_encode_byte_string(&map, amaclCbor, amaclCborSize);
260 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding AMACL Value.");
264 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_SVC_NAME, strlen(OIC_JSON_SVC_NAME));
265 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SVC Name.");
266 cborEncoderResult = cbor_encode_byte_string(&map, svcCbor, svcCborSize);
267 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SVC Value.");
269 if (credCborSize > 0)
271 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_CRED_NAME, strlen(OIC_JSON_CRED_NAME));
272 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Name.");
273 cborEncoderResult = cbor_encode_byte_string(&map, credCbor, credCborSize);
274 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Value.");
277 cborEncoderResult = cbor_encoder_close_container(&encoder, &map);
278 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Container.");
280 size_t s = cbor_encoder_get_buffer_size(&encoder, outPayload);
281 OIC_LOG_V(DEBUG, TAG, "Payload size %zu", s);
283 fp1 = fopen(cborFileName, "w");
286 size_t bytesWritten = fwrite(outPayload, 1, s, fp1);
287 if (bytesWritten == s)
289 OIC_LOG_V(DEBUG, TAG, "Written %zu bytes", bytesWritten);
293 OIC_LOG_V(ERROR, TAG, "Failed writing %zu bytes", s);
300 cJSON_Delete(jsonRoot);
311 OicSecAcl_t* JSONToAclBin(const char * jsonStr)
313 OCStackResult ret = OC_STACK_ERROR;
314 OicSecAcl_t * headAcl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
315 cJSON *jsonRoot = NULL;
317 VERIFY_NON_NULL(TAG, jsonStr, ERROR);
319 jsonRoot = cJSON_Parse(jsonStr);
320 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
322 cJSON *jsonAclMap = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME);
323 VERIFY_NON_NULL(TAG, jsonAclMap, ERROR);
325 cJSON *jsonAclObj = NULL;
328 jsonAclObj = cJSON_GetObjectItem(jsonAclMap, OIC_JSON_ACLIST_NAME);
329 VERIFY_NON_NULL(TAG, jsonAclObj, ERROR);
332 cJSON *jsonAclArray = NULL;
333 jsonAclArray = cJSON_GetObjectItem(jsonAclObj, OIC_JSON_ACES_NAME);
334 VERIFY_NON_NULL(TAG, jsonAclArray, ERROR);
336 if (cJSON_Array == jsonAclArray->type)
339 int numAcl = cJSON_GetArraySize(jsonAclArray);
342 VERIFY_SUCCESS(TAG, numAcl > 0, INFO);
345 cJSON *jsonAcl = cJSON_GetArrayItem(jsonAclArray, idx);
346 VERIFY_NON_NULL(TAG, jsonAcl, ERROR);
348 OicSecAce_t *ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t));
349 VERIFY_NON_NULL(TAG, ace, ERROR);
350 LL_APPEND(headAcl->aces, ace);
352 size_t jsonObjLen = 0;
353 cJSON *jsonObj = NULL;
354 jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_SUBJECTID_NAME);
355 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
356 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
357 if(strcmp(jsonObj->valuestring, WILDCARD_RESOURCE_URI) == 0)
359 ace->subjectuuid.id[0] = '*';
363 ret = ConvertStrToUuid(jsonObj->valuestring, &ace->subjectuuid);
364 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
366 // Resources -- Mandatory
367 jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_RESOURCES_NAME);
368 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
369 VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR);
371 size_t resourcesLen = (size_t)cJSON_GetArraySize(jsonObj);
372 VERIFY_SUCCESS(TAG, resourcesLen > 0, ERROR);
374 for(size_t idxx = 0; idxx < resourcesLen; idxx++)
376 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
377 VERIFY_NON_NULL(TAG, rsrc, ERROR);
379 cJSON *jsonRsrc = cJSON_GetArrayItem(jsonObj, idxx);
380 VERIFY_NON_NULL(TAG, jsonRsrc, ERROR);
383 size_t jsonRsrcObjLen = 0;
384 cJSON *jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_HREF_NAME);
385 VERIFY_NON_NULL(TAG, jsonRsrcObj, ERROR);
386 VERIFY_SUCCESS(TAG, cJSON_String == jsonRsrcObj->type, ERROR);
388 jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1;
389 rsrc->href = (char*)OICMalloc(jsonRsrcObjLen);
390 VERIFY_NON_NULL(TAG, (rsrc->href), ERROR);
391 OICStrcpy(rsrc->href, jsonRsrcObjLen, jsonRsrcObj->valuestring);
394 jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_REL_NAME);
397 jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1;
398 rsrc->rel = (char*)OICMalloc(jsonRsrcObjLen);
399 VERIFY_NON_NULL(TAG, (rsrc->rel), ERROR);
400 OICStrcpy(rsrc->rel, jsonRsrcObjLen, jsonRsrcObj->valuestring);
404 jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_RT_NAME);
405 if(jsonRsrcObj && cJSON_Array == jsonRsrcObj->type)
407 rsrc->typeLen = (size_t)cJSON_GetArraySize(jsonRsrcObj);
408 VERIFY_SUCCESS(TAG, (0 < rsrc->typeLen), ERROR);
409 rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*));
410 VERIFY_NON_NULL(TAG, (rsrc->types), ERROR);
411 for(size_t i = 0; i < rsrc->typeLen; i++)
413 cJSON *jsonRsrcType = cJSON_GetArrayItem(jsonRsrcObj, i);
414 VERIFY_NON_NULL(TAG, jsonRsrcType, ERROR);
415 rsrc->types[i] = OICStrdup(jsonRsrcType->valuestring);
416 VERIFY_NON_NULL(TAG, (rsrc->types[i]), ERROR);
421 jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_IF_NAME);
422 if(jsonRsrcObj && cJSON_Array == jsonRsrcObj->type)
424 rsrc->interfaceLen = (size_t)cJSON_GetArraySize(jsonRsrcObj);
425 VERIFY_SUCCESS(TAG, (0 < rsrc->interfaceLen), ERROR);
426 rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*));
427 VERIFY_NON_NULL(TAG, (rsrc->interfaces), ERROR);
428 for(size_t i = 0; i < rsrc->interfaceLen; i++)
430 cJSON *jsonInterface = cJSON_GetArrayItem(jsonRsrcObj, i);
431 VERIFY_NON_NULL(TAG, jsonInterface, ERROR);
432 rsrc->interfaces[i] = OICStrdup(jsonInterface->valuestring);
433 VERIFY_NON_NULL(TAG, (rsrc->interfaces[i]), ERROR);
437 LL_APPEND(ace->resources, rsrc);
440 // Permissions -- Mandatory
441 jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_PERMISSION_NAME);
442 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
443 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
444 ace->permission = jsonObj->valueint;
446 //Validity -- Not Mandatory
447 cJSON *jsonValidityObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_VALIDITY_NAME);
450 VERIFY_SUCCESS(TAG, cJSON_Array == jsonValidityObj->type, ERROR);
451 size_t validityLen = (size_t) cJSON_GetArraySize(jsonValidityObj);
452 VERIFY_SUCCESS(TAG, (0 < validityLen), ERROR);
454 cJSON *jsonValidity = NULL;
455 for(size_t i = 0; i < validityLen; i++)
457 jsonValidity = cJSON_GetArrayItem(jsonValidityObj, i);
458 VERIFY_NON_NULL(TAG, jsonValidity, ERROR);
459 VERIFY_SUCCESS(TAG, (jsonValidity->type == cJSON_Array), ERROR);
461 OicSecValidity_t* validity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t));
462 VERIFY_NON_NULL(TAG, validity, ERROR);
463 LL_APPEND(ace->validities, validity);
466 cJSON* jsonPeriod = cJSON_GetArrayItem(jsonValidity, 0);
469 VERIFY_SUCCESS(TAG, (cJSON_String == jsonPeriod->type), ERROR);
471 jsonObjLen = strlen(jsonPeriod->valuestring) + 1;
472 validity->period = (char*)OICMalloc(jsonObjLen);
473 VERIFY_NON_NULL(TAG, validity->period, ERROR);
474 OICStrcpy(validity->period, jsonObjLen, jsonPeriod->valuestring);
478 cJSON* jsonRecurObj = cJSON_GetArrayItem(jsonValidity, 1);
481 VERIFY_SUCCESS(TAG, (cJSON_Array == jsonRecurObj->type), ERROR);
482 validity->recurrenceLen = (size_t) cJSON_GetArraySize(jsonRecurObj);
483 VERIFY_SUCCESS(TAG, (0 < validity->recurrenceLen), ERROR);
485 validity->recurrences = (char**)OICCalloc(validity->recurrenceLen, sizeof(char*));
486 VERIFY_NON_NULL(TAG, validity->recurrences, ERROR);
488 cJSON *jsonRecur = NULL;
489 for(size_t i = 0; i < validity->recurrenceLen; i++)
491 jsonRecur = cJSON_GetArrayItem(jsonRecurObj, i);
492 VERIFY_NON_NULL(TAG, jsonRecur, ERROR);
493 jsonObjLen = strlen(jsonRecur->valuestring) + 1;
494 validity->recurrences[i] = (char*)OICMalloc(jsonObjLen);
495 VERIFY_NON_NULL(TAG, validity->recurrences[i], ERROR);
496 OICStrcpy(validity->recurrences[i], jsonObjLen, jsonRecur->valuestring);
501 } while( ++idx < numAcl);
506 jsonAclObj = cJSON_GetObjectItem(jsonAclMap, OIC_JSON_ROWNERID_NAME);
507 VERIFY_NON_NULL(TAG, jsonAclObj, ERROR);
508 VERIFY_SUCCESS(TAG, cJSON_String == jsonAclObj->type, ERROR);
509 ret = ConvertStrToUuid(jsonAclObj->valuestring, &headAcl->rownerID);
510 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
515 cJSON_Delete(jsonRoot);
516 if (OC_STACK_OK != ret)
518 DeleteACLList(headAcl);
524 OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr)
526 printf("IN JSONToDoxmBin\n");
532 OCStackResult ret = OC_STACK_ERROR;
533 OicSecDoxm_t *doxm = NULL;
534 cJSON *jsonDoxm = NULL;
535 cJSON *jsonObj = NULL;
537 size_t jsonObjLen = 0;
539 cJSON *jsonRoot = cJSON_Parse(jsonStr);
540 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
542 jsonDoxm = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME);
543 VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
545 doxm = (OicSecDoxm_t *)OICCalloc(1, sizeof(OicSecDoxm_t));
546 VERIFY_NON_NULL(TAG, doxm, ERROR);
548 //OxmType -- not Mandatory
549 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_TYPE_NAME);
550 if ((jsonObj) && (cJSON_Array == jsonObj->type))
552 doxm->oxmTypeLen = (size_t)cJSON_GetArraySize(jsonObj);
553 VERIFY_SUCCESS(TAG, doxm->oxmTypeLen > 0, ERROR);
555 doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(char *));
556 VERIFY_NON_NULL(TAG, (doxm->oxmType), ERROR);
558 for (size_t i = 0; i < doxm->oxmTypeLen ; i++)
560 cJSON *jsonOxmTy = cJSON_GetArrayItem(jsonObj, i);
561 VERIFY_NON_NULL(TAG, jsonOxmTy, ERROR);
563 jsonObjLen = strlen(jsonOxmTy->valuestring) + 1;
564 doxm->oxmType[i] = (char*)OICMalloc(jsonObjLen);
565 VERIFY_NON_NULL(TAG, doxm->oxmType[i], ERROR);
566 strncpy((char *)doxm->oxmType[i], (char *)jsonOxmTy->valuestring, jsonObjLen);
570 //Oxm -- not Mandatory
571 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXMS_NAME);
572 if (jsonObj && cJSON_Array == jsonObj->type)
574 doxm->oxmLen = (size_t)cJSON_GetArraySize(jsonObj);
575 VERIFY_SUCCESS(TAG, doxm->oxmLen > 0, ERROR);
577 doxm->oxm = (OicSecOxm_t*)OICCalloc(doxm->oxmLen, sizeof(OicSecOxm_t));
578 VERIFY_NON_NULL(TAG, doxm->oxm, ERROR);
580 for (size_t i = 0; i < doxm->oxmLen ; i++)
582 cJSON *jsonOxm = cJSON_GetArrayItem(jsonObj, i);
583 VERIFY_NON_NULL(TAG, jsonOxm, ERROR);
584 doxm->oxm[i] = (OicSecOxm_t)jsonOxm->valueint;
588 //OxmSel -- Mandatory
589 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_SEL_NAME);
592 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
593 doxm->oxmSel = (OicSecOxm_t)jsonObj->valueint;
597 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_SUPPORTED_CRED_TYPE_NAME);
600 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
601 doxm->sct = (OicSecCredType_t)jsonObj->valueint;
605 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OWNED_NAME);
608 VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type), ERROR);
609 doxm->owned = jsonObj->valueint;
613 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DPC_NAME);
616 VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type), ERROR);
617 doxm->dpc = jsonObj->valueint;
620 #ifdef _ENABLE_MULTIPLE_OWNER_
621 //mom -- Not Mandatory
622 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_MOM_NAME);
625 VERIFY_SUCCESS(TAG, (cJSON_Number == jsonObj->type), ERROR);
626 doxm->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t));
627 VERIFY_NON_NULL(TAG, doxm->mom, ERROR);
628 doxm->mom->mode = (OicSecMomType_t)jsonObj->valueint;
630 #endif //_ENABLE_MULTIPLE_OWNER_
632 //DeviceId -- Mandatory
633 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVICE_ID_NAME);
636 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
637 if (cJSON_String == jsonObj->type)
639 //Check for empty string, in case DeviceId field has not been set yet
640 if (jsonObj->valuestring[0])
642 ret = ConvertStrToUuid(jsonObj->valuestring, &doxm->deviceID);
643 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
648 //rowner -- Mandatory
649 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_ROWNERID_NAME);
650 if (true == doxm->owned)
652 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
656 ret = ConvertStrToUuid(jsonObj->valuestring, &doxm->rownerID);
657 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
660 //Owner -- will be empty when device status is unowned.
661 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVOWNERID_NAME);
662 if (true == doxm->owned)
664 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
668 ret = ConvertStrToUuid(jsonObj->valuestring, &doxm->owner);
669 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
675 cJSON_Delete(jsonRoot);
676 if (OC_STACK_OK != ret)
678 DeleteDoxmBinData(doxm);
681 printf("OUT JSONToDoxmBin\n");
685 OicSecPstat_t* JSONToPstatBin(const char * jsonStr)
687 printf("IN JSONToPstatBin\n");
693 OCStackResult ret = OC_STACK_ERROR;
694 OicSecPstat_t *pstat = NULL;
695 cJSON *jsonPstat = NULL;
696 cJSON *jsonObj = NULL;
698 cJSON *jsonRoot = cJSON_Parse(jsonStr);
699 VERIFY_NON_NULL(TAG, jsonRoot, INFO);
701 jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
702 VERIFY_NON_NULL(TAG, jsonPstat, INFO);
704 pstat = (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
705 VERIFY_NON_NULL(TAG, pstat, INFO);
706 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ISOP_NAME);
707 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
708 VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type) , ERROR);
709 pstat->isOp = jsonObj->valueint;
711 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_DEVICE_ID_NAME);
712 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
713 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
714 ret = ConvertStrToUuid(jsonObj->valuestring, &pstat->deviceID);
715 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
717 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ROWNERID_NAME);
718 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
719 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
720 ret = ConvertStrToUuid(jsonObj->valuestring, &pstat->rownerID);
721 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
723 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_CM_NAME);
724 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
725 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
726 pstat->cm = (OicSecDpm_t)jsonObj->valueint;
728 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_TM_NAME);
729 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
730 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
731 pstat->tm = (OicSecDpm_t)jsonObj->valueint;
733 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_OM_NAME);
734 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
735 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
736 pstat->om = (OicSecDpom_t)jsonObj->valueint;
738 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_SM_NAME);
739 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
740 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
742 pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
743 pstat->sm[0] = (OicSecDpom_t)jsonObj->valueint;
748 cJSON_Delete(jsonRoot);
749 if (OC_STACK_OK != ret)
751 OIC_LOG(ERROR, TAG, "JSONToPstatBin failed");
753 printf("OUT JSONToPstatBin\n");
757 static OicEncodingType_t GetEncodingTypeFromStr(const char* encodingType)
759 if (strcmp(OIC_SEC_ENCODING_RAW, encodingType) == 0)
761 return OIC_ENCODING_RAW;
763 if (strcmp(OIC_SEC_ENCODING_BASE64, encodingType) == 0)
765 return OIC_ENCODING_BASE64;
767 if (strcmp(OIC_SEC_ENCODING_PEM, encodingType) == 0)
769 return OIC_ENCODING_PEM;
771 if (strcmp(OIC_SEC_ENCODING_DER, encodingType) == 0)
773 return OIC_ENCODING_DER;
775 OIC_LOG(WARNING, TAG, "Unknow encoding type dectected!");
776 OIC_LOG(WARNING, TAG, "json2cbor will use \"oic.sec.encoding.raw\" as default encoding type.");
777 return OIC_ENCODING_RAW;
780 OicSecCred_t * JSONToCredBin(const char * jsonStr)
784 OIC_LOG(ERROR, TAG,"JSONToCredBin jsonStr in NULL");
788 OicSecCred_t *headCred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t));
789 OCStackResult ret = OC_STACK_ERROR;
790 cJSON *jsonRoot = NULL;
791 VERIFY_NON_NULL(TAG, headCred, ERROR);
793 jsonRoot = cJSON_Parse(jsonStr);
794 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
796 cJSON *jsonCredMap = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME);
797 VERIFY_NON_NULL(TAG, jsonCredMap, ERROR);
800 cJSON *jsonCredArray = NULL;
801 jsonCredArray = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_CREDS_NAME);
802 VERIFY_NON_NULL(TAG, jsonCredArray, ERROR);
804 if (cJSON_Array == jsonCredArray->type)
806 int numCred = cJSON_GetArraySize(jsonCredArray);
807 VERIFY_SUCCESS(TAG, numCred > 0, ERROR);
811 cJSON *jsonCred = cJSON_GetArrayItem(jsonCredArray, idx);
812 VERIFY_NON_NULL(TAG, jsonCred, ERROR);
814 OicSecCred_t *cred = NULL;
821 cred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t));
822 OicSecCred_t *temp = headCred;
829 VERIFY_NON_NULL(TAG, cred, ERROR);
831 size_t jsonObjLen = 0;
832 cJSON *jsonObj = NULL;
834 //CredId -- Mandatory
835 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDID_NAME);
838 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
839 cred->credId = jsonObj->valueint;
842 //subject -- Mandatory
843 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_SUBJECTID_NAME);
844 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
845 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
846 if(strcmp(jsonObj->valuestring, WILDCARD_RESOURCE_URI) == 0)
848 cred->subject.id[0] = '*';
852 ret = ConvertStrToUuid(jsonObj->valuestring, &cred->subject);
853 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
856 //CredType -- Mandatory
857 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDTYPE_NAME);
858 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
859 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
860 cred->credType = (OicSecCredType_t)jsonObj->valueint;
861 //PrivateData is mandatory for some of the credential types listed below.
862 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PRIVATEDATA_NAME);
866 cJSON *jsonPriv = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
867 VERIFY_NON_NULL(TAG, jsonPriv, ERROR);
868 jsonObjLen = strlen(jsonPriv->valuestring);
869 cred->privateData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
870 VERIFY_NON_NULL(TAG, (cred->privateData.data), ERROR);
871 memcpy(cred->privateData.data, jsonPriv->valuestring, jsonObjLen);
872 cred->privateData.len = jsonObjLen;
874 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
875 VERIFY_NON_NULL(TAG, jsonEncoding, ERROR);
876 cred->privateData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
878 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
879 //PublicData is mandatory only for SIGNED_ASYMMETRIC_KEY credentials type.
880 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PUBLICDATA_NAME);
884 cJSON *jsonPub = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
885 VERIFY_NON_NULL(TAG, jsonPub, ERROR);
886 jsonObjLen = strlen(jsonPub->valuestring);
887 cred->publicData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
888 VERIFY_NON_NULL(TAG, (cred->publicData.data), ERROR);
889 memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen);
890 cred->publicData.len = jsonObjLen;
894 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_OPTDATA_NAME);
897 cJSON *jsonOpt = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
898 VERIFY_NON_NULL(TAG, jsonOpt, ERROR);
899 jsonObjLen = strlen(jsonOpt->valuestring);
900 cred->optionalData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
901 VERIFY_NON_NULL(TAG, (cred->optionalData.data), ERROR);
902 memcpy(cred->optionalData.data, jsonOpt->valuestring, jsonObjLen);
903 cred->optionalData.len = jsonObjLen;
905 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
906 VERIFY_NON_NULL(TAG, jsonEncoding, ERROR);
907 cred->optionalData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
911 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDUSAGE_NAME);
914 jsonObjLen = strlen(jsonObj->valuestring);
915 cred->credUsage = OICStrdup(jsonObj->valuestring);
916 VERIFY_NON_NULL(TAG, (cred->credUsage), ERROR);
919 #endif // defined(__WITH_DTLS__) || defined(__WITH_TLS__)
921 //Period -- Not Mandatory
922 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PERIOD_NAME);
923 if(jsonObj && cJSON_String == jsonObj->type)
925 jsonObjLen = strlen(jsonObj->valuestring) + 1;
926 cred->period = (char *)OICMalloc(jsonObjLen);
927 VERIFY_NON_NULL(TAG, cred->period, ERROR);
928 strncpy(cred->period, jsonObj->valuestring, jsonObjLen);
931 } while( ++idx < numCred);
935 cJSON *jsonCredObj = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_ROWNERID_NAME);
936 VERIFY_NON_NULL(TAG, jsonCredObj, ERROR);
937 VERIFY_SUCCESS(TAG, cJSON_String == jsonCredObj->type, ERROR);
938 ret = ConvertStrToUuid(jsonCredObj->valuestring, &headCred->rownerID);
939 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
943 cJSON_Delete(jsonRoot);
944 if (OC_STACK_OK != ret)
946 DeleteCredList(headCred);
952 static OicSecSvc_t* JSONToSvcBin(const char * jsonStr)
954 OCStackResult ret = OC_STACK_ERROR;
955 OicSecSvc_t * headSvc = NULL;
956 OicSecSvc_t * prevSvc = NULL;
957 cJSON *jsonRoot = NULL;
958 cJSON *jsonSvcArray = NULL;
960 VERIFY_NON_NULL(TAG, jsonStr, ERROR);
962 jsonRoot = cJSON_Parse(jsonStr);
963 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
965 jsonSvcArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME);
966 VERIFY_NON_NULL(TAG, jsonSvcArray, INFO);
968 if (cJSON_Array == jsonSvcArray->type)
970 int numSvc = cJSON_GetArraySize(jsonSvcArray);
973 VERIFY_SUCCESS(TAG, numSvc > 0, INFO);
976 cJSON *jsonSvc = cJSON_GetArrayItem(jsonSvcArray, idx);
977 VERIFY_NON_NULL(TAG, jsonSvc, ERROR);
979 OicSecSvc_t *svc = (OicSecSvc_t*)OICCalloc(1, sizeof(OicSecSvc_t));
980 VERIFY_NON_NULL(TAG, svc, ERROR);
982 headSvc = (headSvc) ? headSvc : svc;
988 cJSON *jsonObj = NULL;
989 unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {0};
991 B64Result b64Ret = B64_OK;
993 // Service Device Identity
994 jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_DEVICE_ID);
995 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
996 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
998 b64Ret = b64Decode(jsonObj->valuestring, strlen(jsonObj->valuestring), base64Buff,
999 sizeof(base64Buff), &outLen);
1000 VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(svc->svcdid.id)), ERROR);
1001 memcpy(svc->svcdid.id, base64Buff, outLen);
1004 jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_TYPE);
1005 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1006 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
1007 svc->svct = (OicSecSvcType_t)jsonObj->valueint;
1010 jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_OWNERS_NAME);
1011 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1012 VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR);
1014 svc->ownersLen = (size_t)cJSON_GetArraySize(jsonObj);
1015 VERIFY_SUCCESS(TAG, svc->ownersLen > 0, ERROR);
1016 svc->owners = (OicUuid_t*)OICCalloc(svc->ownersLen, sizeof(OicUuid_t));
1017 VERIFY_NON_NULL(TAG, (svc->owners), ERROR);
1022 cJSON *jsonOwnr = cJSON_GetArrayItem(jsonObj, idxx);
1023 VERIFY_NON_NULL(TAG, jsonOwnr, ERROR);
1024 VERIFY_SUCCESS(TAG, cJSON_String == jsonOwnr->type, ERROR);
1026 b64Ret = b64Decode(jsonOwnr->valuestring, strlen(jsonOwnr->valuestring), base64Buff,
1027 sizeof(base64Buff), &outLen);
1029 VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(svc->owners[idxx].id)),
1031 memcpy(svc->owners[idxx].id, base64Buff, outLen);
1032 } while ( ++idxx < svc->ownersLen);
1035 } while( ++idx < numSvc);
1041 cJSON_Delete(jsonRoot);
1042 if (OC_STACK_OK != ret)
1044 DeleteSVCList(headSvc);
1050 static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr)
1052 OCStackResult ret = OC_STACK_ERROR;
1053 OicSecAmacl_t * headAmacl = (OicSecAmacl_t*)OICCalloc(1, sizeof(OicSecAmacl_t));
1055 cJSON *jsonRoot = NULL;
1056 cJSON *jsonAmacl = NULL;
1058 VERIFY_NON_NULL(TAG, jsonStr, ERROR);
1060 jsonRoot = cJSON_Parse(jsonStr);
1061 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
1063 jsonAmacl = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME);
1064 VERIFY_NON_NULL(TAG, jsonAmacl, INFO);
1066 cJSON *jsonObj = NULL;
1068 // Resources -- Mandatory
1069 jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_RESOURCES_NAME);
1070 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1073 cJSON *jsonRlistArray = cJSON_GetObjectItem(jsonObj, OIC_JSON_RLIST_NAME);
1074 VERIFY_NON_NULL(TAG, jsonRlistArray, ERROR);
1075 VERIFY_SUCCESS(TAG, cJSON_Array == jsonRlistArray->type, ERROR);
1077 headAmacl->resourcesLen = (size_t)cJSON_GetArraySize(jsonRlistArray);
1078 headAmacl->resources = (char**)OICCalloc(headAmacl->resourcesLen, sizeof(char*));
1082 cJSON *jsonRsrc = cJSON_GetArrayItem(jsonRlistArray, idxx);
1083 VERIFY_NON_NULL(TAG, jsonRsrc, ERROR);
1085 cJSON *jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_HREF_NAME);
1086 VERIFY_NON_NULL(TAG, jsonRsrcObj, ERROR);
1087 VERIFY_SUCCESS(TAG, cJSON_String == jsonRsrcObj->type, ERROR);
1089 size_t jsonRsrcObjLen = 0;
1090 jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1;
1091 headAmacl->resources[idxx] = (char*)OICMalloc(jsonRsrcObjLen);
1092 VERIFY_NON_NULL(TAG, (headAmacl->resources[idxx]), ERROR);
1093 OICStrcpy(headAmacl->resources[idxx], jsonRsrcObjLen, jsonRsrcObj->valuestring);
1095 } while ( ++idxx < headAmacl->resourcesLen);
1098 jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_AMS_NAME);
1099 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1100 VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR);
1102 headAmacl->amssLen = (size_t)cJSON_GetArraySize(jsonObj);
1103 VERIFY_SUCCESS(TAG, headAmacl->amssLen > 0, ERROR);
1104 headAmacl->amss = (OicUuid_t*)OICCalloc(headAmacl->amssLen, sizeof(OicUuid_t));
1105 VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR);
1110 cJSON *jsonAms = cJSON_GetArrayItem(jsonObj, idxx);
1111 VERIFY_NON_NULL(TAG, jsonAms, ERROR);
1112 VERIFY_SUCCESS(TAG, cJSON_String == jsonAms->type, ERROR);
1114 memcpy(headAmacl->amss[idxx].id, (OicUuid_t *)jsonAms->valuestring, strlen(jsonAms->valuestring));
1116 } while ( ++idxx < headAmacl->amssLen);
1119 // Rowner -- Mandatory
1120 jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_ROWNERID_NAME);
1121 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1122 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
1124 ret = ConvertStrToUuid(jsonObj->valuestring, &headAmacl->rownerID);
1125 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
1130 cJSON_Delete(jsonRoot);
1131 if (OC_STACK_OK != ret)
1133 DeleteAmaclList(headAmacl);
1139 int main(int argc, char* argv[])
1143 printf("JSON File Name: %s\n CBOR File Name: %s \n", argv[1], argv[2]);
1144 ConvertJsonToCBOR(argv[1], argv[2]);
1148 printf("This program requires two inputs:\n");
1149 printf("1. First input is a json file tha will be converted to cbor. \n");
1150 printf("2. Second input is a resulting cbor file that will store converted cbor. \n");
1151 printf("\t json2cbor <json_file_name> <cbor_file_name>. \n");