From: Zbigniew Jędrzejewski-Szmek Date: Sun, 24 May 2020 10:51:51 +0000 (+0200) Subject: sd-bus: make name validation functions public X-Git-Tag: v246-rc1~288^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d2916409edb7bea9963c71052375a9919df28dc1;p=thirdparty%2Fsystemd.git sd-bus: make name validation functions public Those are fairly trivial to reimplement, but any non-trivial user of sd-bus is likely to need them. So let's expose them to save everyone the trouble. I'm keeping the internal functions and making the public ones thin wrappers, because for the internal uses we don't need the additional asserts, and also we can't expose _pure_ annotation easily, and dropping it would likely make the compiled code a bit less efficient. --- diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 1cfe3550896..cc396780ce8 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -700,6 +700,11 @@ global: LIBSYSTEMD_246 { global: + sd_bus_interface_name_is_valid; + sd_bus_service_name_is_valid; + sd_bus_member_name_is_valid; + sd_bus_object_path_is_valid; + sd_bus_call_methodv; sd_bus_call_method_asyncv; sd_bus_emit_signalv; @@ -707,6 +712,7 @@ global: sd_bus_reply_method_errorfv; sd_bus_reply_method_returnv; sd_bus_set_propertyv; + sd_path_lookup; sd_path_lookup_strv; } LIBSYSTEMD_245; diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 352a419e25d..7e13f4f73ba 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -354,6 +354,7 @@ bool interface_name_is_valid(const char *p) _pure_; bool service_name_is_valid(const char *p) _pure_; bool member_name_is_valid(const char *p) _pure_; bool object_path_is_valid(const char *p) _pure_; + char *object_path_startswith(const char *a, const char *b) _pure_; bool namespace_complex_pattern(const char *pattern, const char *value) _pure_; diff --git a/src/libsystemd/sd-bus/bus-type.c b/src/libsystemd/sd-bus/bus-type.c index 18564a53834..585f8424b3f 100644 --- a/src/libsystemd/sd-bus/bus-type.c +++ b/src/libsystemd/sd-bus/bus-type.c @@ -4,6 +4,7 @@ #include "sd-bus.h" +#include "bus-internal.h" #include "bus-type.h" bool bus_type_is_valid(char c) { @@ -135,3 +136,27 @@ int bus_type_get_size(char c) { return -EINVAL; } + +_public_ int sd_bus_interface_name_is_valid(const char *p) { + assert_return(p, -EINVAL); + + return interface_name_is_valid(p); +} + +_public_ int sd_bus_service_name_is_valid(const char *p) { + assert_return(p, -EINVAL); + + return service_name_is_valid(p); +} + +_public_ int sd_bus_member_name_is_valid(const char *p) { + assert_return(p, -EINVAL); + + return member_name_is_valid(p); +} + +_public_ int sd_bus_object_path_is_valid(const char *p) { + assert_return(p, -EINVAL); + + return object_path_is_valid(p); +} diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index 61b5a493c7c..d4b6befc8cb 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -124,6 +124,13 @@ typedef _sd_destroy_t sd_bus_destroy_t; #include "sd-bus-protocol.h" #include "sd-bus-vtable.h" +/* Naming */ + +int sd_bus_interface_name_is_valid(const char *p); +int sd_bus_service_name_is_valid(const char *p); +int sd_bus_member_name_is_valid(const char *p); +int sd_bus_object_path_is_valid(const char *p); + /* Connections */ int sd_bus_default(sd_bus **ret);