WIP: pth transistion, 3rd step, commands basically ported
authorChristian Thaeter <ct@pipapo.org>
Sun, 21 Oct 2007 21:47:03 +0000 (23:47 +0200)
committerChristian Thaeter <ct@pipapo.org>
Sun, 21 Oct 2007 21:47:03 +0000 (23:47 +0200)
src/main.c
src/rxpd.h
src/rxpd_buffer.c
src/rxpd_connection.c
src/rxpd_connection_cmd.c
src/rxpd_socket.c

index 74c33e4..e54e469 100644 (file)
@@ -207,13 +207,14 @@ main (int argc, char** argv)
       rxpd_socket_spawn (socket);
     }
 
+  rxpd_log (rxpd, LOG_NOTICE, PACKAGE_STRING" running\n");
+
   LLIST_FOREACH (&rxpd->sockets, n)
     {
       struct rxpd_socket* socket = (struct rxpd_socket*)n;
       rxpd_socket_delete (rxpd_socket_join (socket));
     }
 
-
   rxpd_log (rxpd, LOG_NOTICE, PACKAGE_STRING" exited\n");
   rxpd_destroy ();
 
index 774aa27..a3c39cc 100644 (file)
@@ -216,7 +216,7 @@ struct rxpd_buffer*
 rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn);
 
 char*
-rxpd_buffer_readline (struct rxpd_buffer* self, int again);
+rxpd_buffer_readline (struct rxpd_buffer* self);
 
 int
 rxpd_buffer_printf (struct rxpd_buffer* self, const char* fmt, ...);
@@ -262,7 +262,7 @@ void*
 rxpd_connection_parse_cmd (void* ptr);
 
 /* generate prototypes for each defined command */
-#define RXPD_CMD(cmd, _) void rxpd_connection_cmd_##cmd (int fd, short event, void* ptr);
+#define RXPD_CMD(cmd, _) struct rxpd_connection* rxpd_connection_cmd_##cmd (struct rxpd_connection* self);
 RXPD_COMMANDS
 #undef RXPD_CMD
 
index 8f54bc0..5f489fe 100644 (file)
@@ -33,7 +33,7 @@ rxpd_buffer_init (struct rxpd_buffer* self, struct rxpd_connection* conn)
 
 
 char*
-rxpd_buffer_readline (struct rxpd_buffer* self, int again)
+rxpd_buffer_readline (struct rxpd_buffer* self)
 {
   int fd = self->conn->fd;
 
@@ -46,44 +46,44 @@ rxpd_buffer_readline (struct rxpd_buffer* self, int again)
       // TODO handle \r's
     }
 
-  if (!again && self->state == RXPD_OK)   // we only read when again is 0, first iteration
-    {
-      ssize_t r = 0;
-      do
-        {
-          r = read(fd, self->eob, 4095 - (self->eob - self->buffer));
-        }
-      while (r == -1 && errno == EINTR);
-
-      if (r != -1)
-        {
-
-          if (r == 0)
-            {
-              shutdown (fd, SHUT_RD);
-              self->state = RXPD_EOF;
-            }
-
-          self->eob += r;
-        }
-      else
-        self->state = RXPD_ERROR;
-    }
-
-  // find next newline, terminate string there
-  for (char* i = self->buffer; i < self->eob; ++i)
-    {
-      if (*i == '\n')
-        {
-          *i = '\0';
-          self->eol = i;
-          break;
-        }
-    }
-
-  // TODO handle buffer overfulls
 
-  return (self->eob == self->buffer) ? NULL : self->buffer;
+  do {
+    // find next newline, terminate string there
+    for (char* i = self->buffer; i < self->eob; ++i)
+      {
+        if (*i == '\n')
+          {
+            *i = '\0';
+            self->eol = i;
+            // have line, return it
+            return (self->eob == self->buffer) ? NULL : self->buffer;
+          }
+      }
+
+    // else we have to read
+    if (self->state == RXPD_OK)
+      {
+        ssize_t r = 0;
+        do
+          {
+            r = pth_read (fd, self->eob, 4095 - (self->eob - self->buffer));
+          }
+        while (r == -1 && errno == EINTR);
+
+        if (r != -1)
+          {
+            if (r == 0)
+              {
+                shutdown (fd, SHUT_RD);
+                self->state = RXPD_EOF;
+              }
+            self->eob += r;
+          }
+        else
+          self->state = RXPD_ERROR;
+      }
+  } while (1);  // TODO while (!buffer overfulls)  
+  return NULL;
 }
 
 /*
@@ -100,13 +100,13 @@ rxpd_buffer_write(int fd, short event, void* ptr)
 int
 rxpd_buffer_printf (struct rxpd_buffer* self, const char* fmt, ...)
 {
-  // for now we do a blocking write, needs to be fixed some day
+  // for now we do a blocking write, needs to be fixed some day, timeout!
   va_list ap;
   va_start(ap, fmt);
   int n = vsnprintf (self->buffer, 4096, fmt, ap);
   va_end(ap);
 
-  write (self->conn->fd, self->buffer, n);
+  pth_write (self->conn->fd, self->buffer, n);
 
   if (n>4095)
     return 0;
index bf06dbd..1f048be 100644 (file)
@@ -27,7 +27,7 @@ rxpd_connection_new (struct rxpd_socket* socket)
   struct rxpd_connection* self;
   self = rxpd_malloc (sizeof (struct rxpd_connection));
 
-  self->fd = accept (socket->fd, NULL, 0);
+  self->fd = pth_accept (socket->fd, NULL, 0);
   if (self->fd == -1)
     abort ();
 
@@ -131,7 +131,7 @@ rxpd_connection_parse_cmd (void* ptr)
   struct rxpd_base* base = self->socket->base;
 
   char* line;
-  line = rxpd_buffer_readline (&self->in, 0);
+  line = rxpd_buffer_readline (&self->in);
 
   if (!line)
     {
@@ -160,6 +160,7 @@ rxpd_connection_parse_cmd (void* ptr)
   for (i = cmds; i->cmd; ++i)
     if (strncmp (line, i->cmd, i->sz) == 0)
       break;
+
   if (!i->cmd)
     {
       rxpd_log (base, LOG_ERR, "no command\n");
@@ -193,19 +194,19 @@ rxpd_connection_parse_cmd (void* ptr)
         }
     }
 
+
+  //TODO memleak have to call connection_destroy instead just returning
+
   // dispatch
   switch (i->nr)
     {
-#define RXPD_CMD(cmd, _)                                                        \
-case RXPD_CMD_##cmd:                                                            
-
+#define RXPD_CMD(cmd, _)                        \
+case RXPD_CMD_##cmd:                            \
+  return rxpd_connection_cmd_##cmd (ptr);       \
 
-  //event_set (&self->ev, self->fd, EV_READ, rxpd_connection_cmd_##cmd, self);    
-  //rxpd_connection_cmd_##cmd (fd, 0, ptr);                                       
   break;
       RXPD_COMMANDS
 #undef RXPD_CMD
-        ;
     }
   return NULL;
 }
index af14b38..94da7d1 100644 (file)
 
 #include "rxpd.h"
 
-void
-rxpd_connection_cmd_CHECK (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_CHECK (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
+  char* line;
 
-  if (event == EV_READ)
+  while ((line = rxpd_buffer_readline (&self->in)))
     {
-      int again = -1;
-      char* line;
-      while ((line = rxpd_buffer_readline (&self->in, ++again)))
+      if (*line == '\0')
         {
-          if (*line == '\0')
-            {
-              rxpd_buffer_printf (&self->out, "#OK:\n");
-            }
-          else
+          rxpd_buffer_printf (&self->out, "#OK:\n");
+        }
+      else
+        {
+          LLIST_FOREACH (&self->file->rules, n)
             {
-              LLIST_FOREACH (&self->file->rules, n)
+              struct rxpd_rule* rule = (struct rxpd_rule*)n;
+              if (rule->string[0] != '#')
                 {
-                  struct rxpd_rule* rule = (struct rxpd_rule*)n;
-                  if (rule->string[0] != '#')
+                  if (regexec (&rule->rx, line, 0, NULL, 0) == 0)
                     {
-                      if (regexec (&rule->rx, line, 0, NULL, 0) == 0)
-                        {
-                          if (rule->atime != (time_t) -1)
-                            time (&rule->atime);
-
-                          rxpd_buffer_printf (&self->out, "%s\n", rule->string);
-                          break;
-                        }
+                      if (rule->atime != (time_t) -1)
+                        time (&rule->atime);
+
+                      rxpd_buffer_printf (&self->out, "%s\n", rule->string);
+                      break;
                     }
                 }
             }
         }
     }
+#if 0
   else if (!self->file)
     {
       rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
       rxpd_connection_delete (self);
       return;
     }
-
   if (rxpd_buffer_state (&self->in) == RXPD_OK)
     rxpd_connection_schedule (self);
   else
@@ -72,34 +66,33 @@ rxpd_connection_cmd_CHECK (int fd, short event, void* ptr)
         rxpd_buffer_printf (&self->out, "#ERROR:\n");
       rxpd_connection_delete (self);
     }
+#endif
+
+  return self;
 }
 
 
 
 static void
-rxpd_connection_APPEND_PREPEND_helper (short event, void* ptr, int do_append)
+rxpd_connection_APPEND_PREPEND_helper (struct rxpd_connection* self)
 {
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
+  char* line;
 
-  if (event == EV_READ)
+  while ((line = rxpd_buffer_readline (&self->in)))
     {
-      int again = -1;
-      char* line;
-
-      while ((line = rxpd_buffer_readline (&self->in, ++again)))
+      if (*line)
         {
-          if (*line)
-            {
-              struct rxpd_rule* rule;
-              rule = rxpd_rule_new (line);
-              if (!rule)
-                abort();
+          struct rxpd_rule* rule;
+          rule = rxpd_rule_new (line);
+          if (!rule)
+            abort();
 
-              llist_insert_tail (&self->tmp_list, &rule->node);
-            }
-          else goto finish;     /* move along, look elsewhere! This goto is not harmful and saves some code. */
+          llist_insert_tail (&self->tmp_list, &rule->node);
         }
+      //          else goto finish;     /* move along, look elsewhere! This goto is not harmful and saves some code. */
     }
+
+#if 0
   else if (!event && !self->file)
     {
       rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
@@ -120,58 +113,52 @@ rxpd_connection_APPEND_PREPEND_helper (short event, void* ptr, int do_append)
           rxpd_buffer_printf (&self->out, "#OK:\n");
         }
 
-      if (do_append)
-        llist_insertlist_prev (&self->file->rules, &self->tmp_list);
-      else
-        llist_insertlist_next (&self->file->rules, &self->tmp_list);
       rxpd_connection_delete (self);
     }
+#endif
 }
 
-void
-rxpd_connection_cmd_APPEND (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_APPEND (struct rxpd_connection* self)
 {
-  (void) fd;
-  rxpd_connection_APPEND_PREPEND_helper (event, ptr, 1);
+  rxpd_connection_APPEND_PREPEND_helper (self);
+  llist_insertlist_prev (&self->file->rules, &self->tmp_list);
+  return self;
 }
 
-void
-rxpd_connection_cmd_PREPEND (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_PREPEND (struct rxpd_connection* self)
 {
-  (void) fd;
-  rxpd_connection_APPEND_PREPEND_helper (event, ptr, 0);
+  rxpd_connection_APPEND_PREPEND_helper (self);
+  llist_insertlist_next (&self->file->rules, &self->tmp_list);
+  return self;
 }
 
 
-void
-rxpd_connection_cmd_REMOVE (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_REMOVE (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
-  if (event == EV_READ)
+  char* line;
+  while ((line = rxpd_buffer_readline (&self->in)))
     {
-      int again = -1;
-      char* line;
-      while ((line = rxpd_buffer_readline (&self->in, ++again)))
+      LLIST_FOREACH (&self->file->rules, n)
         {
-          LLIST_FOREACH (&self->file->rules, n)
+          struct rxpd_rule* rule = (struct rxpd_rule*)n;
+          if (strcmp (rule->string, line) == 0)
             {
-              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;
-                }
+              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:
-          ;
         }
+      rxpd_buffer_printf (&self->out, "#ERROR: line not found\n");
+    done:
+      ;
     }
+
+#if 0
   else if (!self->file)
     {
       rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
@@ -187,6 +174,8 @@ rxpd_connection_cmd_REMOVE (int fd, short event, void* ptr)
         rxpd_buffer_printf (&self->out, "#ERROR:\n");
       rxpd_connection_delete (self);
     }
+#endif
+  return self;
 }
 
 
@@ -210,35 +199,30 @@ rxpd_connection_do_REPLACE (struct rxpd_connection* self)
   return 1;
 }
 
-void
-rxpd_connection_cmd_REPLACE (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_REPLACE (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
-  if (event == EV_READ)
+  char* line;
+  while ((line = rxpd_buffer_readline (&self->in)))
     {
-      int again = -1;
-      char* line;
-      while ((line = rxpd_buffer_readline (&self->in, ++again)))
+      if (self->tmp_str)
         {
-          if (self->tmp_str)
+          if (*line)
             {
-              if (*line)
-                {
-                  struct rxpd_rule* rule;
-                  rule = rxpd_rule_new (line);
-                  if (!rule)
-                    abort();
+              struct rxpd_rule* rule;
+              rule = rxpd_rule_new (line);
+              if (!rule)
+                abort();
 
-                  llist_insert_tail (&self->tmp_list, &rule->node);
-                }
-              /* TODO handle empty lines? */
+              llist_insert_tail (&self->tmp_list, &rule->node);
             }
-          else
-            self->tmp_str = rxpd_strdup (line);
+          /* TODO handle empty lines? */
         }
+      else
+        self->tmp_str = rxpd_strdup (line);
     }
+
+#if 0
   else if (!self->file)
     {
       rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
@@ -254,136 +238,118 @@ rxpd_connection_cmd_REPLACE (int fd, short event, void* ptr)
         rxpd_buffer_printf (&self->out, "#ERROR:\n");
       else
         {
-          if (rxpd_connection_do_REPLACE (self))
-            rxpd_buffer_printf (&self->out, "#OK:\n");
-          else
-            rxpd_buffer_printf (&self->out, "#ERROR: rule matching '%s'\n", self->tmp_str);
         }
 
       rxpd_connection_delete (self);
     }
+#endif
+  if (rxpd_connection_do_REPLACE (self))
+    rxpd_buffer_printf (&self->out, "#OK:\n");
+  else
+    rxpd_buffer_printf (&self->out, "#ERROR: rule matching '%s'\n", self->tmp_str);
+  return self;
 }
 
-void
-rxpd_connection_cmd_LOAD (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_LOAD (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
-  if (!event)
+  if (self->file)
     {
-      if (self->file)
+      if (rxpd_file_load (self->file))
         {
-          if (rxpd_file_load (self->file))
-            {
-              rxpd_buffer_printf (&self->out, "#OK:\n");
-            }
-          else
-            {
-              rxpd_buffer_printf (&self->out, "#ERROR: loading file '%s'\n", (const char*)self->file->node.key);
-            }
+          rxpd_buffer_printf (&self->out, "#OK:\n");
         }
       else
-        rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
-      rxpd_connection_delete (self);
+        {
+          rxpd_buffer_printf (&self->out, "#ERROR: loading file '%s'\n", (const char*)self->file->node.key);
+        }
     }
+  else
+    rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
+  return self;
 }
 
-void
-rxpd_connection_cmd_SAVE (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_SAVE (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
-  if (!event)
+  if (self->file)
     {
-      if (self->file)
+      if (rxpd_file_save (self->file))
         {
-          if (rxpd_file_save (self->file))
-            {
-              rxpd_buffer_printf (&self->out, "#OK:\n");
-            }
-          else
-            {
-              rxpd_buffer_printf (&self->out, "#ERROR: saving file '%s'\n", (const char*)self->file->node.key);
-            }
+          rxpd_buffer_printf (&self->out, "#OK:\n");
         }
       else
-        rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
-      rxpd_connection_delete (self);
+        {
+          rxpd_buffer_printf (&self->out, "#ERROR: saving file '%s'\n", (const char*)self->file->node.key);
+        }
     }
+  else
+    rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
+  return self;
 }
 
-void
-rxpd_connection_cmd_DELETE (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_DELETE (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
-  if (!event)
+  if (self->file)
     {
-      if (self->file)
-        {
-          rxpd_file_delete (self->file);
-          rxpd_buffer_printf (&self->out, "#OK:\n");
-        }
-      rxpd_connection_delete (self);
+      rxpd_file_delete (self->file);
+      rxpd_buffer_printf (&self->out, "#OK:\n");
     }
+  return self;
 }
 
-void
-rxpd_connection_cmd_FETCH (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_FETCH (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
   struct rxpd_base* base = self->socket->base;
 
-  if (event == EV_READ)
+  char* line;
+  line = rxpd_buffer_readline (&self->in);
+  if (*line)
     {
-      char* line;
-      line = rxpd_buffer_readline (&self->in, 0);
-      if (*line)
-        {
-          rxpd_file_rules_delete (self->file);
+      rxpd_file_rules_delete (self->file);
 
-          char* list = strrchr (line, '/');
-          // TODO error handling
-          if (!list)
-            rxpd_die ("syntax error");
+      char* list = strrchr (line, '/');
+      // TODO error handling
+      if (!list)
+        rxpd_die ("syntax error");
 
-          *list = '\0';
-          ++ list;
+      *list = '\0';
+      ++ list;
 
-          char* port = strrchr (line, ':');
-          // TODO error handling / unix domain sockets
-          if (!port)
-            rxpd_die ("syntax error");
+      char* port = strrchr (line, ':');
+      // TODO error handling / unix domain sockets
+      if (!port)
+        rxpd_die ("syntax error");
 
-          *port = '\0';
-          ++ port;
+      *port = '\0';
+      ++ port;
 
-          struct addrinfo* addrs = NULL;
-          int aierr;
+      struct addrinfo* addrs = NULL;
+      int aierr;
 
-          aierr = getaddrinfo (line, port, NULL, &addrs);
+      aierr = getaddrinfo (line, port, NULL, &addrs);
 
-          rxpd_log (base, LOG_INFO, "fetching list '%s' from '%s(%s)' at port '%s' to '%s'\n",
-                    list,
-                    line,
-                    inet_ntoa (((struct sockaddr_in*)addrs->ai_addr)->sin_addr),
-                    port,
-                    self->file->node.key);
+      rxpd_log (base, LOG_INFO, "fetching list '%s' from '%s(%s)' at port '%s' to '%s'\n",
+                list,
+                line,
+                inet_ntoa (((struct sockaddr_in*)addrs->ai_addr)->sin_addr),
+                port,
+                self->file->node.key);
 
-          if (aierr)
-            rxpd_die ("resolv error %s\n", gai_strerror (aierr));
+      if (aierr)
+        rxpd_die ("resolv error %s\n", gai_strerror (aierr));
 
-          // connect
-          // send dump
-          // add recieving event
+      // connect
+      // send dump
+      // add recieving event
 
-          freeaddrinfo (addrs);
-        }
+      freeaddrinfo (addrs);
     }
+
+
+#if 0
   else if (!self->file)
     {
       rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
@@ -393,20 +359,21 @@ rxpd_connection_cmd_FETCH (int fd, short event, void* ptr)
 
   if (!event && rxpd_buffer_state (&self->in) == RXPD_OK)
     rxpd_connection_schedule (self);
+#endif
+  return self;
 }
 
-void
-rxpd_connection_cmd_DUMP (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_DUMP (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
+#if 0
   if (!event && !self->file)
     {
       rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
       rxpd_connection_delete (self);
       return;
     }
+#endif
 
   if (llist_is_empty (&self->file->rules))
     rxpd_buffer_printf (&self->out, "#OK:\n");
@@ -423,8 +390,7 @@ rxpd_connection_cmd_DUMP (int fd, short event, void* ptr)
             rxpd_buffer_printf (&self->out, "%s\n", rule->string);
         }
     }
-
-  rxpd_connection_delete (self);
+  return self;
 }
 
 
@@ -442,46 +408,38 @@ walk_LIST (PSplay node, const enum psplay_order_e which, int level, void* data)
 }
 
 
-void
-rxpd_connection_cmd_LIST (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_LIST (struct rxpd_connection* self)
 {
-  (void) fd;
-  (void) event;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
   struct rxpd_base* base = self->socket->base;
 
   if (psplay_isempty_root (&base->files))
     rxpd_buffer_printf (&self->out, "#OK:\n");
   else
-    psplay_walk (&base->files, NULL, walk_LIST, 0, ptr);
-
-  rxpd_connection_delete (self);
+    psplay_walk (&base->files, NULL, walk_LIST, 0, self);
+  return self;
 }
 
-void
-rxpd_connection_cmd_SHUTDOWN (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_SHUTDOWN (struct rxpd_connection* self)
 {
-  (void) fd;
-  (void) event;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-  struct rxpd_base* base = self->socket->base;
+  //struct rxpd_base* base = self->socket->base;
   // destroy all sockets
+#if 0
   LLIST_WHILE_HEAD (&base->sockets, n)
     {
       struct rxpd_socket* socket = (struct rxpd_socket*)n;
       rxpd_socket_delete (socket);
     }
   rxpd_buffer_printf (&self->out, "#OK:\n");
-  rxpd_connection_delete (self);
+#endif
+  return self;
 }
 
 
-void
-rxpd_connection_cmd_VERSION (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_VERSION (struct rxpd_connection* self)
 {
-  (void) fd;
-  (void) event;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
   rxpd_buffer_printf (&self->out, PACKAGE_STRING "\n#\n"
                       "# Copyright (C)\n"
                       "#   2007,               Christian Thaeter <ct@pipapo.org>\n#\n"
@@ -489,58 +447,53 @@ rxpd_connection_cmd_VERSION (int fd, short event, void* ptr)
                       "# the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"
                       "# There is NO WARRANTY, to the extent permitted by law.\n#\n"
                       "# http://www.pipapo.org/pipawiki/RegexPolicyDaemon\n");
-  rxpd_connection_delete (self);
+  return self;
 }
 
-void
-rxpd_connection_cmd_HELP (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_HELP (struct rxpd_connection* self)
 {
-  (void) fd;
-  (void) event;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
   //struct rxpd_base* base = self->socket->base;
   rxpd_buffer_printf (&self->out, "# Available commands:\n#\n");
 #define RXPD_CMD(cmd, help)     rxpd_buffer_printf (&self->out, "# %s %s.\n", #cmd, help);
   RXPD_COMMANDS
 #undef RXPD_CMD
   rxpd_buffer_printf (&self->out, "#\n# general syntax is: 'COMMAND:listname\\n..data..'\n");
-  rxpd_connection_delete (self);
+  return self;
 }
 
-void
-rxpd_connection_cmd_EXPIRE (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_EXPIRE (struct rxpd_connection* self)
 {
-  (void) fd;
-  struct rxpd_connection* self = (struct rxpd_connection*) ptr;
   struct rxpd_base* base = self->socket->base;
 
-  if (event == EV_READ)
+  char* line;
+  while ((line = rxpd_buffer_readline (&self->in)))
     {
-      int again = -1;
-      char* line;
-      while ((line = rxpd_buffer_readline (&self->in, ++again)))
+      if (*line)
         {
-          if (*line)
-            {
-              time_t since = time (NULL) - atoi (line);
-              rxpd_log (base, LOG_INFO, "expire all entries in '%s' since %ld\n",
-                        (const char*) self->file->node.key, since);
+          time_t since = time (NULL) - atoi (line);
+          rxpd_log (base, LOG_INFO, "expire all entries in '%s' since %ld\n",
+                    (const char*) self->file->node.key, since);
 
-              LLIST_FOREACH (&self->file->rules, n)
+          LLIST_FOREACH (&self->file->rules, n)
+            {
+              struct rxpd_rule* rule = (struct rxpd_rule*)n;
+              if (rule->atime != -1 && rule->atime < since)
                 {
-                  struct rxpd_rule* rule = (struct rxpd_rule*)n;
-                  if (rule->atime != -1 && rule->atime < since)
-                    {
-                      n = llist_prev (n);
-                      rxpd_log (base, LOG_DEBUG, "expiring %ld:%s\n", rule->atime, rule->string);
-                      rxpd_buffer_printf (&self->out, "#OK: expiring '%s'\n", rule->string);
-                      rxpd_rule_delete (rule);
-                    }
+                  n = llist_prev (n);
+                  rxpd_log (base, LOG_DEBUG, "expiring %ld:%s\n", rule->atime, rule->string);
+                  rxpd_buffer_printf (&self->out, "#OK: expiring '%s'\n", rule->string);
+                  rxpd_rule_delete (rule);
                 }
             }
-          else
-            rxpd_buffer_printf (&self->out, "#OK:\n");
         }
+      else
+        rxpd_buffer_printf (&self->out, "#OK:\n");
+    }
+
+
+#if 0
     }
   else if (!self->file)
     {
@@ -557,11 +510,13 @@ rxpd_connection_cmd_EXPIRE (int fd, short event, void* ptr)
         rxpd_buffer_printf (&self->out, "#ERROR:\n");
       rxpd_connection_delete (self);
     }
+#endif
+  return self;
 }
 
 /* Template
-void
-rxpd_connection_cmd_ (int fd, short event, void* ptr)
+struct rxpd_connection*
+rxpd_connection_cmd_ (struct rxpd_connection* ptr)
 {
   (void) fd;
   (void) event;
index 263e9ee..e8a1e9c 100644 (file)
@@ -110,7 +110,6 @@ rxpd_socket_join (struct rxpd_socket* self)
 struct rxpd_socket*
 rxpd_socket_spawn (struct rxpd_socket* self)
 {
-      rxpd_log (NULL, LOG_NOTICE, "socket spawn\n");
   if (self)
     {
       if (self->accepter)