From e8d05b263ed736bd37065c367861516eb5cf6eec Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Thu, 4 Jan 2007 21:05:02 -0500 Subject: [PATCH] Added the DUMP command which shows the in memory document. --- PROTOCOL | 5 +++++ src/commands.c | 18 +++++++++++++++++- src/commands.h | 1 + src/pwmd.c | 5 ++++- src/xml.c | 2 +- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/PROTOCOL b/PROTOCOL index 1228d08e..ecf6588f 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -95,6 +95,11 @@ HELP [] comand. +DUMP + Show the in memory document. Useful for pruning empty elements which + aren't shown with the LIST command. + + QUIT Closes the connection. Use the SAVE command before this command as any changes will be lost. diff --git a/src/commands.c b/src/commands.c index fc5de48a..4e8d7081 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1546,7 +1546,7 @@ gboolean help_command(struct client_s *client, const gchar *what) if (!what || !*what) line = "NFO Try 'HELP COMMAND' for command help\n" - "NFO OPEN LIST GET STORE DELETE ATTR CACHE SAVE QUIT\n"; + "NFO OPEN LIST GET STORE DELETE ATTR CACHE SAVE DUMP QUIT\n"; else if (g_ascii_strcasecmp(what, "GET") == 0) line = "NFO syntax: GET account element [ element ...]\n" @@ -1594,6 +1594,10 @@ gboolean help_command(struct client_s *client, const gchar *what) line = "NFO syntax: CACHE [CLEARALL | CLEAR | ISCACHED ]\n" "NFO tests or clears the cache entry for \n"; + else if (g_ascii_strcasecmp(what, "DUMP") == 0) + line = + "NFO syntax: DUMP\n" + "NFO shows the in memory XML document\n"; else { send_error(client, EPWMD_COMMAND_SYNTAX); return FALSE; @@ -1602,3 +1606,15 @@ gboolean help_command(struct client_s *client, const gchar *what) send_to_client(client, "%sOK \n", line); return TRUE; } + +gboolean dump_command(struct client_s *client) +{ + xmlChar *xml; + gssize len; + + xmlDocDumpMemory(client->doc, &xml, &len); + send_to_client(client, "BEGIN %li\n%s", len, xml); + memset(xml, 0, len); + xmlFree(xml); + return TRUE; +} diff --git a/src/commands.h b/src/commands.h index 4858fd0a..9ea131d1 100644 --- a/src/commands.h +++ b/src/commands.h @@ -28,5 +28,6 @@ gboolean list_command(struct client_s *client, gchar *str); gboolean attr_command(struct client_s *client, gchar **req); gboolean cache_command(struct client_s *client, gchar **req); gboolean help_command(struct client_s *client, const gchar *what); +gboolean dump_command(struct client_s *client); #endif diff --git a/src/pwmd.c b/src/pwmd.c index 51b96109..1fa5834e 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -251,7 +251,6 @@ static gint input_parser(gchar *str) if ((req = split_input_line(t, " ", 4)) != NULL) { if (attr_command(cl, req) == TRUE) send_to_client(cl, "OK \n"); - xmlDocDump(stderr, cl->doc); } else send_error(cl, EPWMD_COMMAND_SYNTAX); @@ -295,6 +294,10 @@ static gint input_parser(gchar *str) if (cache_command(cl, req) == TRUE) send_to_client(cl, "OK \n"); } + else if (g_ascii_strncasecmp(p, "DUMP", 4) == 0) { + if (dump_command(cl) == TRUE) + send_to_client(cl, "OK \n"); + } else send_error(cl, EPWMD_COMMAND_SYNTAX); } diff --git a/src/xml.c b/src/xml.c index 414e3b03..5f06657d 100644 --- a/src/xml.c +++ b/src/xml.c @@ -85,7 +85,7 @@ gchar *new_document() "\n" "\n" "]>\n" - "\n"; + ""; return g_strdup(line); } -- 2.11.4.GIT