Add a DUMPH command which dumps the atimes in a human readable format
authorChristian Thaeter <ct@pipapo.org>
Tue, 11 Dec 2007 15:43:51 +0000 (16:43 +0100)
committerChristian Thaeter <ct@pipapo.org>
Tue, 11 Dec 2007 15:43:51 +0000 (16:43 +0100)
src/rxpd.h
src/rxpd_connection_cmd.c
src/rxpd_file.c
tests/20simplecommands.tests

index 851fd1d..c3939b0 100644 (file)
@@ -64,6 +64,7 @@
   RXPD_CMD(EXPIRE,      "aged rules from a list")               \
   RXPD_CMD(FILTER,      "rules in a list")                      \
   RXPD_CMD(DUMP,        "rules in a list")                      \
+  RXPD_CMD(DUMPH,       "rules in a list, human readable atime")\
   RXPD_CMD(LIST,        "all existing lists")                   \
   RXPD_CMD(VERSION,     "of this rxpd is "PACKAGE_VERSION)      \
   RXPD_CMD(HELP,        "is what you see right now")            \
@@ -203,7 +204,7 @@ int
 rxpd_file_save (struct rxpd_file* self, int force);
 
 struct rxpd_file*
-rxpd_file_dump (struct rxpd_file* self, struct rxpd_buffer* out);
+rxpd_file_dump (struct rxpd_file* self, struct rxpd_buffer* out, const char* fmt);
 
 int
 rxpd_file_cmp (const void* A, const void* B);
index 1716ada..474f5b7 100644 (file)
@@ -408,7 +408,14 @@ void
 rxpd_connection_cmd_DUMP (struct rxpd_connection* self)
 {
   RXPD_FILENAME_REQUIRED;
-  rxpd_file_dump (self->file, &self->out);
+  rxpd_file_dump (self->file, &self->out, NULL);
+}
+
+void
+rxpd_connection_cmd_DUMPH (struct rxpd_connection* self)
+{
+  RXPD_FILENAME_REQUIRED;
+  rxpd_file_dump (self->file, &self->out, "%a, %d. %b. %Y, %T");
 }
 
 
index a66a9b3..017da59 100644 (file)
@@ -190,7 +190,7 @@ rxpd_file_save (struct rxpd_file* self, int force)
 }
 
 struct rxpd_file*
-rxpd_file_dump (struct rxpd_file* self, struct rxpd_buffer* out)
+rxpd_file_dump (struct rxpd_file* self, struct rxpd_buffer* out, const char* fmt)
 {
   if (self)
     {
@@ -204,7 +204,19 @@ rxpd_file_dump (struct rxpd_file* self, struct rxpd_buffer* out)
             {
               struct rxpd_rule* rule = (struct rxpd_rule*)n;
               if (rule->atime != (time_t)-1)
-                rxpd_buffer_printf (out, "%ld:%s\n", rule->atime, rule->string);
+                {
+                  if (fmt)
+                    {
+                      char buf[64];
+                      struct tm *time;
+
+                      time = gmtime(&rule->atime);
+                      strftime(buf, sizeof(buf)-1, fmt, time);
+                      rxpd_buffer_printf (out, "%s:%s\n", buf, rule->string);
+                    }
+                  else
+                    rxpd_buffer_printf (out, "%ld:%s\n", rule->atime, rule->string);
+                }
               else if (*rule->string != '#')
                 rxpd_buffer_printf (out, ":%s\n", rule->string);
               else
index 95d66b4..88ecf33 100644 (file)
@@ -51,6 +51,7 @@ out: # MERGE new rules from from other lists.
 out: # EXPIRE aged rules from a list.
 out: # FILTER rules in a list.
 out: # DUMP rules in a list.
+out: # DUMPH rules in a list, human readable atime.
 out: # LIST all existing lists.
 out: # VERSION of this rxpd is $version.
 out: # HELP is what you see right now.