REMOVE command
authorChristian Thaeter <ct@pipapo.org>
Mon, 8 Oct 2007 15:03:47 +0000 (17:03 +0200)
committerChristian Thaeter <ct@pipapo.org>
Mon, 8 Oct 2007 15:03:47 +0000 (17:03 +0200)
rxpd.c

diff --git a/rxpd.c b/rxpd.c
index 27cf0fb..455e253 100644 (file)
--- a/rxpd.c
+++ b/rxpd.c
@@ -649,11 +649,50 @@ rxpd_connection_cmd_PREPEND (int fd, short event, void* ptr)
   rxpd_connection_APPEND_PREPEND_helper (fd, event, ptr, 0);
 }
 
+
 void
 rxpd_connection_cmd_REMOVE (int fd, short event, void* ptr)
 {
   struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-  rxpd_buffer_printf (&self->out, "#ERROR: unimplemented command %s\n", &__func__[20]);
+
+  if (event == EV_READ)
+    {
+      int again = -1;
+      char* line;
+      while (line = rxpd_buffer_readline (&self->in, ++again))
+        {
+          LLIST_FOREACH (&self->file->rules, n)
+            {
+              struct rxpd_rule* rule = (struct rxpd_rule*)n;
+              if (strcmp (rule->string, line) == 0)
+                {
+                  LList tmp = llist_prev (n);
+                  rxpd_rule_delete (rule);
+                  n = tmp;
+                  rxpd_buffer_printf (&self->out, "#OK:\n");
+                  goto done;
+                }
+            }
+          rxpd_buffer_printf (&self->out, "#ERROR: line not found\n");
+        done:
+          ;
+        }
+    }
+  else if (!self->file)
+    {
+      rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
+      close (fd);
+      return;
+    }
+
+  if (rxpd_buffer_state (&self->in) == RXPD_OK)
+    rxpd_connection_schedule (self);
+  else
+    {
+      if (rxpd_buffer_state (&self->in) == RXPD_ERROR)
+        rxpd_buffer_printf (&self->out, "#ERROR:\n");
+      close (fd);
+    }
 }
 
 void