add the LIST command
authorChristian Thaeter <ct@pipapo.org>
Sun, 7 Oct 2007 07:04:55 +0000 (09:04 +0200)
committerChristian Thaeter <ct@pipapo.org>
Sun, 7 Oct 2007 07:04:55 +0000 (09:04 +0200)
rxpd.c

diff --git a/rxpd.c b/rxpd.c
index bebe05e..ca65340 100644 (file)
--- a/rxpd.c
+++ b/rxpd.c
@@ -653,11 +653,32 @@ rxpd_connection_cmd_DUMP (int fd, short event, void* ptr)
   rxpd_buffer_printf (&self->out, "#ERROR: unimplemented command %s\n", &__func__[20]);
 }
 
+
+static psplay_delete_t
+walk_LIST (PSplay node, const enum psplay_order_e which, int level, void* data)
+{
+  (void) level;
+  struct rxpd_file* file = (struct rxpd_file*) node;
+  struct rxpd_connection* conn = (struct rxpd_connection*) data;
+
+  if (which == PSPLAY_INORDER)
+    rxpd_buffer_printf (&conn->out, "%s\n", file->node.key);
+
+  return PSPLAY_CONT;
+}
+
+
 void
 rxpd_connection_cmd_LIST (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 (psplay_isempty_root (&self->base->files))
+    rxpd_buffer_printf (&self->out, "#OK:\n");
+  else
+    psplay_walk (&self->base->files, NULL, walk_LIST, 0, ptr);
+
+  close (fd);
 }
 
 void
@@ -666,4 +687,3 @@ rxpd_connection_cmd_SHUTDOWN (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]);
 }
-