| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-json.h" |
| 4 |
|
| 5 |
#include "json-util.h" |
| 6 |
#include "path.h" |
| 7 |
#include "varlink-path.h" |
| 8 |
|
| 9 |
static int path_specs_build_json(sd_json_variant **ret, const char *name, void *userdata) { |
| 10 |
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; |
| 11 |
PathSpec *specs = userdata; |
| 12 |
int r; |
| 13 |
|
| 14 |
assert(ret); |
| 15 |
|
| 16 |
LIST_FOREACH(spec, k, specs) { |
| 17 |
r = sd_json_variant_append_arraybo( |
| 18 |
&v, |
| 19 |
JSON_BUILD_PAIR_ENUM("type", path_type_to_string(k->type)), |
| 20 |
SD_JSON_BUILD_PAIR_STRING("path", k->path)); |
| 21 |
if (r < 0) |
| 22 |
return r; |
| 23 |
} |
| 24 |
|
| 25 |
*ret = TAKE_PTR(v); |
| 26 |
return 0; |
| 27 |
} |
| 28 |
|
| 29 |
int path_context_build_json(sd_json_variant **ret, const char *name, void *userdata) { |
| 30 |
Path *p = ASSERT_PTR(PATH(userdata)); |
| 31 |
Unit *trigger = UNIT_TRIGGER(UNIT(p)); |
| 32 |
|
| 33 |
return sd_json_buildo( |
| 34 |
ASSERT_PTR(ret), |
| 35 |
JSON_BUILD_PAIR_CALLBACK_NON_NULL("Paths", path_specs_build_json, p->specs), |
| 36 |
JSON_BUILD_PAIR_STRING_NON_EMPTY("Unit", trigger ? trigger->id : NULL), |
| 37 |
SD_JSON_BUILD_PAIR_BOOLEAN("MakeDirectory", p->make_directory), |
| 38 |
SD_JSON_BUILD_PAIR_UNSIGNED("DirectoryMode", p->directory_mode), |
| 39 |
JSON_BUILD_PAIR_RATELIMIT("TriggerLimit", &p->trigger_limit)); |
| 40 |
} |
| 41 |
|
| 42 |
int path_runtime_build_json(sd_json_variant **ret, const char *name, void *userdata) { |
| 43 |
Path *p = ASSERT_PTR(PATH(userdata)); |
| 44 |
|
| 45 |
return sd_json_buildo( |
| 46 |
ASSERT_PTR(ret), |
| 47 |
JSON_BUILD_PAIR_ENUM("Result", path_result_to_string(p->result))); |
| 48 |
} |