From 69ddc10b31d158e5ceeab9d2e0fc78b9b1a4c244 Mon Sep 17 00:00:00 2001 From: Klaus Kämpf Date: Thu, 8 Sep 2011 09:05:16 +0200 Subject: wsmancli allow debugging of invalid response XML sing wsmancli, when the response XML is invalid (such as due to invalid characters) an error is displayed with only a partial view of the XML and no other information that could tell us where exactly the problem is. In debug mode (using -d option), it would be useful if the tool could dump the raw XML for further analysis before it could be interpreted by libxml functions. Patch by Chris Poblete --- src/wsman.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/wsman.c b/src/wsman.c index 4c34e78..8a70481 100644 --- a/src/wsman.c +++ b/src/wsman.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include @@ -407,12 +407,11 @@ static char wsman_parse_options(int argc, char **argv) } - - static void wsman_output(WsManClient * cl, WsXmlDocH doc) { FILE *f = stdout; const char *filename = output_file; + const char *badxml = NULL; WS_LASTERR_Code err; err = wsmc_get_last_error(cl); @@ -421,19 +420,28 @@ static void wsman_output(WsManClient * cl, WsXmlDocH doc) } if (!doc) { error("doc with NULL content"); - return; + badxml = (char*)u_buf_ptr(cl->connection->response); + if ((-1 == debug_level) || (NULL == badxml)) { + goto error1; + } } if (filename) { f = fopen(filename, "w"); if (f == NULL) { error("Could not open file for writing"); - return; + goto error1; } } - ws_xml_dump_node_tree(f, ws_xml_get_doc_root(doc)); + if (NULL != badxml) { + fprintf(f, "%s", badxml); // on debug mode, output the bad xml + } else { + ws_xml_dump_node_tree(f, ws_xml_get_doc_root(doc)); + } if (f != stdout) { fclose(f); } + +error1: return; } -- cgit