VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT array length.");
}
- VERIFY_SUCCESS(TAG, (0 != rsrc->typeLen), ERROR);
-
- rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*));
- VERIFY_NON_NULL(TAG, rsrc->types, ERROR);
+ if (0 != rsrc->typeLen)
+ {
+ rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*));
+ VERIFY_NON_NULL(TAG, rsrc->types, ERROR);
- cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering RT Array.");
+ cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering RT Array.");
- for(size_t i = 0; cbor_value_is_valid(&resourceTypes) && cbor_value_is_text_string(&resourceTypes); i++)
- {
- cborFindResult = cbor_value_dup_text_string(&resourceTypes, &(rsrc->types[i]), &readLen, NULL);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding resource type.");
- cborFindResult = cbor_value_advance(&resourceTypes);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing resource type.");
+ for(size_t i = 0; cbor_value_is_valid(&resourceTypes) && cbor_value_is_text_string(&resourceTypes); i++)
+ {
+ cborFindResult = cbor_value_dup_text_string(&resourceTypes, &(rsrc->types[i]), &readLen, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding resource type.");
+ cborFindResult = cbor_value_advance(&resourceTypes);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing resource type.");
+ }
}
}
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF array length.");
}
- VERIFY_SUCCESS(TAG, (0 != rsrc->interfaceLen), ERROR);
-
- rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*));
- VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR);
+ if (0 != rsrc->interfaceLen)
+ {
+ rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*));
+ VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR);
- cborFindResult = cbor_value_enter_container(&rMap, &interfaces);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering IF Array.");
+ cborFindResult = cbor_value_enter_container(&rMap, &interfaces);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering IF Array.");
- for(size_t i = 0; cbor_value_is_valid(&interfaces) && cbor_value_is_text_string(&interfaces); i++)
- {
- cborFindResult = cbor_value_dup_text_string(&interfaces, &(rsrc->interfaces[i]), &readLen, NULL);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF type.");
- cborFindResult = cbor_value_advance(&interfaces);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing IF type.");
+ for(size_t i = 0; cbor_value_is_valid(&interfaces) && cbor_value_is_text_string(&interfaces); i++)
+ {
+ cborFindResult = cbor_value_dup_text_string(&interfaces, &(rsrc->interfaces[i]), &readLen, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF type.");
+ cborFindResult = cbor_value_advance(&interfaces);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing IF type.");
+ }
}
}
for (size_t i = 0; i < res->typeLen; i++)
{
- OIC_LOG_V(INFO, TAG, "if[%zu] = %s", i, res->types[i]);
+ OIC_LOG_V(INFO, TAG, "rt[%zu] = %s", i, res->types[i]);
}
for (size_t i = 0; i < res->interfaceLen; i++)
{
{
OIC_LOG_V(INFO, TAG, "recurrences[%zu] = %s", i, vals->recurrences[i]);
}
+
+ vals = vals->next;
}
ace = ace->next;
OIC_LOG_V(DEBUG, TAG, "OUT: %s", __func__);
return ret;
}
+
+/**
+ * This method add new ACE to ACL
+ *
+ * @param subject of the ACE
+ * @param href resource string
+ * @param rel resource string
+ * @param types string array
+ * @param typeLen string array size
+ * @param interfaces string array
+ * @param interfaceLen string array size
+ * @param permission value
+ *
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult AddACE(const OicUuid_t *subject, const char *href, const char *rel,
+ const char **types, size_t typeLen,
+ const char **interfaces, size_t interfaceLen,
+ uint16_t permission)
+{
+ OCStackResult ret = OC_EH_ERROR;
+
+ OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
+
+ if (!gAcl)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s: gAcl is NULL", __func__);
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (!subject)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s: Invalid Parameter", __func__);
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ OicSecAce_t newAce;
+ OicSecRsrc_t resources;
+ memcpy(&newAce.subjectuuid, subject, sizeof(OicUuid_t));
+ resources.href = href;
+ resources.rel = rel;
+ resources.types = types;
+ resources.typeLen = typeLen;
+ resources.interfaces = interfaces;
+ resources.interfaceLen = interfaceLen;
+ resources.next = NULL;
+ newAce.resources = &resources;
+ newAce.permission = permission;
+ newAce.validities = NULL;
+#ifdef MULTIPLE_OWNER
+ newAce.eownerID = NULL;
+#endif
+ newAce.next = NULL;
+
+ //Check existing ACE's
+ OicSecAce_t *existAce = NULL;
+ OicSecAce_t *tempAce = NULL;
+ LL_FOREACH_SAFE(gAcl->aces, existAce, tempAce)
+ {
+ if (IsSameACE(&newAce, existAce))
+ {
+ OIC_LOG(DEBUG, TAG, "Duplicated ACE dectected.");
+ return OC_STACK_DUPLICATE_REQUEST;
+ }
+ }
+
+ // Add new ACE to ACL
+ OIC_LOG(DEBUG, TAG, "NEW ACE dectected.");
+ OicSecAce_t *insertAce = DuplicateACE(&newAce);
+ if (insertAce)
+ {
+ OIC_LOG(DEBUG, TAG, "Appending new ACE..");
+ LL_APPEND(gAcl->aces, insertAce);
+
+ // Update persistant storage
+ uint8_t *payload = NULL;
+ size_t size = 0;
+ if (OC_STACK_OK == AclToCBORPayload(gAcl, &payload, &size))
+ {
+ if (OC_STACK_OK == UpdateSecureResourceInPS(OIC_JSON_ACL_NAME, payload, size))
+ {
+ ret = OC_STACK_OK;
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "UpdateSecureResourceInPS failed");
+ }
+ OICFree(payload);
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "AclToCBORPayload failed");
+ }
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "Failed to duplicate ACE.");
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "OUT: %s", __func__);
+
+ return ret;
+}