From: Jule Anger Date: Fri, 5 Aug 2022 11:05:26 +0000 (+0200) Subject: smbstatus: add a method to add profile items to json X-Git-Tag: samba-4.17.0rc1~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=03ed8d3a07c37f7e85e700b6db747fc0db97e24a;p=thirdparty%2Fsamba.git smbstatus: add a method to add profile items to json The method changes the json item of a given traverse_state. The root dictionary contains for each section a dictionary, which has a dictionary for each subsection. Signed-off-by: Jule Anger Reviewed-by: Ralph Boehme --- diff --git a/source3/utils/status_json.c b/source3/utils/status_json.c index b3c9d66d0fe..69b31e27f54 100644 --- a/source3/utils/status_json.c +++ b/source3/utils/status_json.c @@ -181,6 +181,45 @@ static const struct mask2txt lease_mask[] = { {0, NULL} }; +int add_profile_item_to_json(struct traverse_state *state, + const char *section, + const char *subsection, + const char *key, + uintmax_t value) +{ + struct json_object section_json, subsection_json; + int result = 0; + + section_json = json_get_object(&state->root_json, section); + if (json_is_invalid(§ion_json)) { + goto failure; + } + subsection_json = json_get_object(§ion_json, subsection); + if (json_is_invalid(&subsection_json)) { + goto failure; + } + + result = json_add_int(&subsection_json, key, value); + if (result < 0) { + goto failure; + } + + result = json_update_object(§ion_json, subsection, &subsection_json); + if (result < 0) { + goto failure; + } + result = json_update_object(&state->root_json, section, §ion_json); + if (result < 0) { + goto failure; + } + + return 0; +failure: + json_free(§ion_json); + json_free(&subsection_json); + return -1; +} + int add_section_to_json(struct traverse_state *state, const char *key) { diff --git a/source3/utils/status_json.h b/source3/utils/status_json.h index 72ff4b359cc..ef5d18139be 100644 --- a/source3/utils/status_json.h +++ b/source3/utils/status_json.h @@ -28,6 +28,12 @@ int add_section_to_json(struct traverse_state *state, int add_general_information_to_json(struct traverse_state *state); +int add_profile_item_to_json(struct traverse_state *state, + const char *section, + const char *subsection, + const char *key, + uintmax_t value); + int traverse_connections_json(struct traverse_state *state, const struct connections_data *crec, const char *encryption_cipher, diff --git a/source3/utils/status_json_dummy.c b/source3/utils/status_json_dummy.c index 03eb00e64a4..3cd8531c2de 100644 --- a/source3/utils/status_json_dummy.c +++ b/source3/utils/status_json_dummy.c @@ -35,6 +35,15 @@ int add_general_information_to_json(struct traverse_state *state) return 0; } +int add_profile_item_to_json(struct traverse_state *state, + const char *section, + const char *subsection, + const char *key, + uintmax_t value) +{ + return 0; +} + int traverse_connections_json(struct traverse_state *state, const struct connections_data *crec, const char *encryption_cipher,