From 74720bb0ac4e5e34feb40be2ec4030471e0e1bfe Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Thu, 18 Oct 2007 19:06:39 +0200 Subject: [PATCH] DELETE command --- src/rxpd.h | 5 +++-- src/rxpd_connection_cmd.c | 17 +++++++++++++++++ src/rxpd_file.c | 12 ++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/rxpd.h b/src/rxpd.h index d5ecc98..60dc441 100644 --- a/src/rxpd.h +++ b/src/rxpd.h @@ -46,12 +46,13 @@ RXPD_CMD(PREPEND, "new rules in front of a list") \ RXPD_CMD(REMOVE, "rules from a list") \ RXPD_CMD(REPLACE, "a rule in a list with new rules") \ + RXPD_CMD(DELETE, "a list from memory") \ RXPD_CMD(LOAD, "a list from disk") \ RXPD_CMD(SAVE, "a list to disk") \ RXPD_CMD(EXPIRE, "aged rules from a list") \ RXPD_CMD(DUMP, "rules in a list") \ RXPD_CMD(LIST, "all existing lists") \ - RXPD_CMD(VERSION, "of this rxpd is "PACKAGE_STRING) \ + RXPD_CMD(VERSION, "of this rxpd is "PACKAGE_VERSION) \ RXPD_CMD(HELP, "is what you see right now") \ RXPD_CMD(SHUTDOWN, "the daemon") @@ -141,7 +142,7 @@ struct rxpd_file* rxpd_file_new (struct rxpd_base* base, const char* filename); void -rxpd_file_delete (PSplay file); +rxpd_file_delete (struct rxpd_file* file); int rxpd_file_load (struct rxpd_file* self); diff --git a/src/rxpd_connection_cmd.c b/src/rxpd_connection_cmd.c index 7e446c0..9008ec2 100644 --- a/src/rxpd_connection_cmd.c +++ b/src/rxpd_connection_cmd.c @@ -314,6 +314,23 @@ rxpd_connection_cmd_SAVE (int fd, short event, void* ptr) } } +void +rxpd_connection_cmd_DELETE (int fd, short event, void* ptr) +{ + (void) fd; + struct rxpd_connection* self = (struct rxpd_connection*) ptr; + + if (!event) + { + if (self->file) + { + rxpd_file_delete (self->file); + rxpd_buffer_printf (&self->out, "#OK:\n"); + } + rxpd_connection_delete (self); + } +} + void rxpd_connection_cmd_DUMP (int fd, short event, void* ptr) { diff --git a/src/rxpd_file.c b/src/rxpd_file.c index 75b551d..d49644b 100644 --- a/src/rxpd_file.c +++ b/src/rxpd_file.c @@ -57,18 +57,18 @@ rxpd_file_new (struct rxpd_base* base, const char* filename) } void -rxpd_file_delete (PSplay f) +rxpd_file_delete (struct rxpd_file* self) { - if (f) + if (self) { - struct rxpd_file* file = (struct rxpd_file*)f; - LLIST_WHILE_HEAD (&file->rules, n) + LLIST_WHILE_HEAD (&self->rules, n) { struct rxpd_rule* node = (struct rxpd_rule*)n; rxpd_rule_delete (node); } - free ((void*)file->filename); - free (f); + psplay_remove (&self->base->files, &self->node); + free ((void*)self->filename); + free (self); } } -- 2.20.1