diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-15 13:40:24 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-15 14:15:21 +0200 |
commit | 12641ecd67875b7bf18db06c0afa40c37d804750 (patch) | |
tree | 1fbaf4210daf90a6f98a35a6cff7d2c6cf78310f /src/libsystemd | |
parent | network: add AF_TO_ADDRESS_FAMILY() helper (diff) | |
download | systemd-12641ecd67875b7bf18db06c0afa40c37d804750.tar.xz systemd-12641ecd67875b7bf18db06c0afa40c37d804750.zip |
sd-varlink: add new sd_varlink_error_is_invalid_parameter() helper
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/libsystemd.sym | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-varlink/sd-varlink.c | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index b3f46f90f1..e1836da08f 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -975,6 +975,7 @@ global: sd_varlink_error_errno; sd_varlink_error_invalid_parameter; sd_varlink_error_invalid_parameter_name; + sd_varlink_error_is_invalid_parameter; sd_varlink_error_to_errno; sd_varlink_errorb; sd_varlink_flush; diff --git a/src/libsystemd/sd-varlink/sd-varlink.c b/src/libsystemd/sd-varlink/sd-varlink.c index 70615bb3e3..fb42e3205d 100644 --- a/src/libsystemd/sd-varlink/sd-varlink.c +++ b/src/libsystemd/sd-varlink/sd-varlink.c @@ -4112,3 +4112,23 @@ _public_ int sd_varlink_error_to_errno(const char *error, sd_json_variant *param return -EBADR; /* Catch-all */ } + +_public_ int sd_varlink_error_is_invalid_parameter(const char *error, sd_json_variant *parameter, const char *name) { + + /* Returns true if the specified error result is an invalid parameter error for the parameter 'name' */ + + if (!streq_ptr(error, SD_VARLINK_ERROR_INVALID_PARAMETER)) + return false; + + if (!name) + return true; + + if (!sd_json_variant_is_object(parameter)) + return false; + + sd_json_variant *e = sd_json_variant_by_key(parameter, "parameter"); + if (!e || !sd_json_variant_is_string(e)) + return false; + + return streq(sd_json_variant_string(e), name); +} |