]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add a method to add profile items to json
authorJule Anger <janger@samba.org>
Fri, 5 Aug 2022 11:05:26 +0000 (13:05 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +0000 (12:56 +0000)
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 <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status_json.c
source3/utils/status_json.h
source3/utils/status_json_dummy.c

index b3c9d66d0fe4d229ea61e6830a79b8856626d35d..69b31e27f54163a51c28bb6ee7766b6e163fb442 100644 (file)
@@ -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(&section_json)) {
+               goto failure;
+       }
+       subsection_json = json_get_object(&section_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(&section_json, subsection,  &subsection_json);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_update_object(&state->root_json, section, &section_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       return 0;
+failure:
+       json_free(&section_json);
+       json_free(&subsection_json);
+       return -1;
+}
+
 int add_section_to_json(struct traverse_state *state,
                        const char *key)
 {
index 72ff4b359cc6f0b767eaa97957da608c54c99573..ef5d18139be85777281af70ebf734a3bca9c890a 100644 (file)
@@ -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,
index 03eb00e64a469c5ff1a91d2f4cfee8dd1b4a0533..3cd8531c2de2553917fdbff4c8c8bbf7472d9eb0 100644 (file)
@@ -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,