From 25ff515b398da61171a570baee641290374cec1a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Jul 2024 11:22:58 +0200 Subject: sd-varlink: make our internal Varlink API public as sd-varlink.[ch] It's time. sd-json was already done earlier in this cycle, let's now make sd-varlink public too. This is mostly just a search/replace job of epical proportions. I left some functions internal (mostly IDL handling), and I turned some static inline calls into regular calls. --- src/shared/varlink-io.systemd.service.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/shared/varlink-io.systemd.service.c') diff --git a/src/shared/varlink-io.systemd.service.c b/src/shared/varlink-io.systemd.service.c index 87479e3758..666778bd41 100644 --- a/src/shared/varlink-io.systemd.service.c +++ b/src/shared/varlink-io.systemd.service.c @@ -2,35 +2,36 @@ #include +#include "macro.h" #include "varlink-io.systemd.service.h" -static VARLINK_DEFINE_METHOD(Ping); +static SD_VARLINK_DEFINE_METHOD(Ping); -static VARLINK_DEFINE_METHOD(Reload); +static SD_VARLINK_DEFINE_METHOD(Reload); -static VARLINK_DEFINE_METHOD( +static SD_VARLINK_DEFINE_METHOD( SetLogLevel, - VARLINK_DEFINE_INPUT(level, VARLINK_INT, 0)); + SD_VARLINK_DEFINE_INPUT(level, SD_VARLINK_INT, 0)); -VARLINK_DEFINE_INTERFACE( +SD_VARLINK_DEFINE_INTERFACE( io_systemd_service, "io.systemd.service", &vl_method_Ping, &vl_method_Reload, &vl_method_SetLogLevel); -int varlink_method_ping(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int varlink_method_ping(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { assert(link); if (sd_json_variant_elements(parameters) > 0) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); log_debug("Received io.systemd.service.Ping"); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -int varlink_method_set_log_level(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { +int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { static const sd_json_dispatch_field dispatch_table[] = { { "level", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int64, 0, SD_JSON_MANDATORY }, {} @@ -46,25 +47,25 @@ int varlink_method_set_log_level(Varlink *link, sd_json_variant *parameters, Var /* NOTE: The method does have 1 parameter, but we must compare to 2 here, because * sd_json_variant_elements() breaks abstraction and exposes internal structure of JsonObject. */ if (sd_json_variant_elements(parameters) != 2) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - r = varlink_dispatch(link, parameters, dispatch_table, &level); + r = sd_varlink_dispatch(link, parameters, dispatch_table, &level); if (r != 0) return r; if (LOG_PRI(level) != level) - return varlink_error_invalid_parameter(link, parameters); + return sd_varlink_error_invalid_parameter(link, parameters); - r = varlink_get_peer_uid(link, &uid); + r = sd_varlink_get_peer_uid(link, &uid); if (r < 0) return r; if (uid != getuid() && uid != 0) - return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, parameters); + return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, parameters); log_debug("Received io.systemd.service.SetLogLevel(%" PRIi64 ")", level); log_set_max_level(level); - return varlink_reply(link, NULL); + return sd_varlink_reply(link, NULL); } -- cgit v1.2.3