1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

audit_logging: add method to replace the object for a given key with a new object

Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Jule Anger 2022-03-22 16:06:37 +01:00
parent 6412c39bbf
commit 4ef2d36615
2 changed files with 50 additions and 0 deletions

View File

@ -905,6 +905,52 @@ int json_add_guid(struct json_object *object,
return ret; return ret;
} }
/*
* @brief Replaces the object for a given key with a given json object.
*
* If key already exists, the value will be replaced. Otherwise the given
* value will be added under the given key.
*
* @param object the JSON object to be updated.
* @param key the key which will be updated.
* @param new_obj the new value object to be inserted.
*
* @return 0 the operation was successful
* -1 the operation failed (e.j. if one of the paramters is invalid)
*/
int json_update_object(struct json_object *object,
const char *key,
struct json_object *new_obj)
{
int ret = 0;
if (json_is_invalid(object)) {
DBG_ERR("Unable to update key [%s], "
"target object is invalid\n",
key);
return JSON_ERROR;
}
if (json_is_invalid(new_obj)) {
DBG_ERR("Unable to update key [%s], "
"new object is invalid\n",
key);
return JSON_ERROR;
}
if (key == NULL) {
DBG_ERR("Unable to add null String as key\n");
return JSON_ERROR;
}
ret = json_object_set(object->root, key, new_obj->root);
if (ret != 0) {
DBG_ERR("Unable to update object\n");
return ret;
}
return ret;
}
/* /*
* @brief Convert a JSON object into a string * @brief Convert a JSON object into a string
* *

View File

@ -87,6 +87,10 @@ _WARN_UNUSED_RESULT_ int json_add_guid(struct json_object *object,
const char *name, const char *name,
const struct GUID *guid); const struct GUID *guid);
_WARN_UNUSED_RESULT_ int json_update_object(struct json_object *object,
const char *key,
struct json_object *new_obj);
_WARN_UNUSED_RESULT_ struct json_object json_get_array( _WARN_UNUSED_RESULT_ struct json_object json_get_array(
struct json_object *object, const char *name); struct json_object *object, const char *name);
_WARN_UNUSED_RESULT_ struct json_object json_get_object( _WARN_UNUSED_RESULT_ struct json_object json_get_object(