Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bringing in patch for json_transform_dict_array #2

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/busctl/busctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1732,12 +1732,15 @@ static int json_transform_variant(sd_bus_message *m, const char *contents, JsonV
}

static int json_transform_dict_array(sd_bus_message *m, JsonVariant **ret) {
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
JsonVariant **elements = NULL;
size_t n_elements = 0;
int r;

assert(m);
assert(ret);

CLEANUP_ARRAY(elements, n_elements, json_variant_unref_many);

for (;;) {
const char *contents;
char type;
Expand All @@ -1754,28 +1757,31 @@ static int json_transform_dict_array(sd_bus_message *m, JsonVariant **ret) {

assert(type == 'e');

if (!GREEDY_REALLOC(elements, n_elements + 2))
return log_oom();

r = sd_bus_message_enter_container(m, type, contents);
if (r < 0)
return bus_log_parse_error(r);

r = json_transform_and_append(m, &array);
r = json_transform_one(m, elements + n_elements);
if (r < 0)
return r;

r = json_transform_and_append(m, &array);
n_elements++;

r = json_transform_one(m, elements + n_elements);
if (r < 0)
return r;

n_elements++;

r = sd_bus_message_exit_container(m);
if (r < 0)
return bus_log_parse_error(r);
}

if (!array)
return json_variant_new_array(ret, NULL, 0);

*ret = TAKE_PTR(array);
return 0;
return json_variant_new_object(ret, elements, n_elements);
}

static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
Expand Down
Loading