From 551ba3d82d48d1a2c4bf12683ac743abb00a0fd5 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Mon, 1 Jun 2026 16:48:55 +0200 Subject: [PATCH] MT#61856 control_ng: introduce NG commands table Introduce a common NG commands table `ng_command_defs` for all type of things: OP enum, name, escaped name, short name and most important the handler. This table operates on and returns a dedicated struct `ng_command_def`, which has all the information required on the command (like all type of things mentioned above) and may have either single-parameter or double-parameter signature (for cases with the `addr` requiring commands such as the offer command). Also add unified signatures for X and XA handlers, they will be used later accordingly. Most of those use single-parameter, and those exceptional use the second one. Also add dummy plug-functions for ping and block/unblock silence media. The ping one doesn't have any particular handler, but because a new structure of NG commands wants to see a real declaration of the func handler, just give it. For the block/unblock silence media, there aren't even handling of commands in the control NG, they are just dummy OPs, so fulfill the actual NG commands structure, and give them dummy funcs. Change-Id: I2064ddca1595079959a6c6843119556a8b6bf5d5 --- daemon/call_interfaces.c | 6 ++++++ daemon/control_ng.c | 24 ++++++++++++++++++++++++ include/call_interfaces.h | 1 + 3 files changed, 31 insertions(+) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index b9332a4a3..b81564ec0 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -720,6 +720,12 @@ out: return errstr; } +const char *call_ping_ng(ng_command_ctx_t *ctx) +{ + /* consider ping as always unconditionally ok */ + return NULL; +} + const char *call_offer_ng(ng_command_ctx_t *ctx, const char *addr) { diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 7e3c2c2ab..a28975515 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -31,6 +31,30 @@ const char magic_load_limit_strings[__LOAD_LIMIT_MAX][64] = { [LOAD_LIMIT_BW] = "Bandwidth limit exceeded", }; +typedef const char *(*ng_command_handler_t)(ng_command_ctx_t *ctx); +typedef const char *(*ng_command_addr_handler_t)(ng_command_ctx_t *ctx, + const char *addr); + +struct ng_command_def { + enum ng_opmode opmode; + const char *name; + const char *escaped_name; + const char *short_name; + /* Only one of handler/addr_handler should be set at a time */ + ng_command_handler_t handler; + ng_command_addr_handler_t addr_handler; +}; + +static const struct ng_command_def ng_command_defs[OP_COUNT] = { +#define X(op, name, esc, short_name, handler) \ + [op] = { op, name, esc, short_name, handler, NULL }, +#define XA(op, name, esc, short_name, handler) \ + [op] = { op, name, esc, short_name, NULL, handler }, + NG_COMMANDS(X, XA) +#undef XA +#undef X +}; + const char *ng_command_strings[OP_COUNT] = { #define X(op, name, esc, short_name, handler) [op] = name, #define XA(op, name, esc, short_name, handler) [op] = name, diff --git a/include/call_interfaces.h b/include/call_interfaces.h index 33233f444..732b806c9 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -28,6 +28,7 @@ str call_lookup_udp(char **); str call_delete_udp(char **); str call_query_udp(char **); +const char *call_ping_ng(ng_command_ctx_t *ctx); const char *call_offer_ng(ng_command_ctx_t *, const char *); const char *call_answer_ng(ng_command_ctx_t *); const char *call_delete_ng(ng_command_ctx_t *);