cmd_CHECK implementation
authorChristian Thaeter <ct@pipapo.org>
Sat, 6 Oct 2007 16:46:19 +0000 (18:46 +0200)
committerChristian Thaeter <ct@pipapo.org>
Sat, 6 Oct 2007 16:46:19 +0000 (18:46 +0200)
rxpd.c

diff --git a/rxpd.c b/rxpd.c
index bff71bc..43e8bbc 100644 (file)
--- a/rxpd.c
+++ b/rxpd.c
@@ -557,17 +557,48 @@ case RXPD_CMD_##cmd:
   rxpd_connection_schedule (self);
 }
 
+
+
 void
 rxpd_connection_cmd_CHECK (int fd, short event, void* ptr)
 {
   struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-  LLIST_FOREACH (&self->file.rules, node)
-  
 
-    //rxpd_buffer_printf (&self->out, "#ERROR: unimplemented command %s\n", &__func__[20]);
+  int again = -1;
+  char* line;
+  while (line = rxpd_buffer_readline (&self->in, ++again))
+    {
 
+      if (*line == '\0')
+        {
+          rxpd_buffer_printf (&self->out, "#OK:\n");
+          break;
+        }
+      else
+        {
+          LLIST_FOREACH (&self->file->rules, n)
+            {
+              struct rxpd_rule* rule = (struct rxpd_rule*)n;
+              if (rule->string[0] != '#')
+                {
+                  if (regexec (&rule->rx, line, 0, NULL, 0) == 0)
+                    {
+                      rxpd_buffer_printf (&self->out, "%s\n", rule->string);
+                      break;
+                    }
+                }
+            }
+        }
+    }
 
-  rxpd_connection_schedule (self);
+  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