From c397e37a057b8f59a54371785b58322ebfd09007 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Mon, 16 Jan 2023 16:24:08 +0200 Subject: [PATCH] implement RemoveMatch --- server.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server.c b/server.c index bd1992b..caab73a 100644 --- a/server.c +++ b/server.c @@ -551,11 +551,22 @@ int handle_add_match(bus_t *s, int i, wire_message_t *msg, wire_context_t *ctx, } int handle_remove_match(bus_t *s, int i, wire_message_t *msg, wire_context_t *ctx, wire_context_t *reply_ctx) { - TRYPTR(wire_get_string_check(ctx, 1, MATCH_RULE_MAX)); + char *match = TRYPTR(wire_get_string_check(ctx, 1, MATCH_RULE_MAX)); - STUB("handle_remove_match", "does nothing and returns success"); + bus_client_t *client = &s->clients[i]; + int left = client->match_count; + for (int j = 0; j < BUS_MAX_MATCH && left > 0; j++) { + left--; - _reply_begin("") {} _reply_end() + if (client->matches[j] && strcmp(client->matches[j]->rule_string, match) == 0) { + match_rule_free(client->matches[j]); + client->matches[j] = NULL; + _reply_begin("") {} _reply_end() + break; + } + } + + _reply_error("xyz.hippoz.jitterbug.MatchRuleNotFound"); return 0; }