DELETE command
authorChristian Thaeter <ct@pipapo.org>
Thu, 18 Oct 2007 17:06:39 +0000 (19:06 +0200)
committerChristian Thaeter <ct@pipapo.org>
Thu, 18 Oct 2007 17:06:39 +0000 (19:06 +0200)
src/rxpd.h
src/rxpd_connection_cmd.c
src/rxpd_file.c

index d5ecc98..60dc441 100644 (file)
   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);
index 7e446c0..9008ec2 100644 (file)
@@ -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)
 {
index 75b551d..d49644b 100644 (file)
@@ -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);
     }
 }