From 8e452058c075b91cd9dc50eb73422e9b0f3bbc4d Mon Sep 17 00:00:00 2001 From: Klaus Kämpf Date: Fri, 5 Nov 2010 12:02:13 +0100 Subject: Output enumeration results to separate output files In an enumerate operation where output to file is requested and the response require more than one pull, only the last pull is saved to file. The rest of the response is overwritten. Our proposal solution is for each pull response, it is saved to a file with numbered suffix. This is only applicable to an enumerate operation and an enumeration context is returned. Also included is a minor fix to file open from read/write to write mode. I find no reason for the operation to read the output file. --- src/wsman.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wsman.c b/src/wsman.c index 1809cc9..67ad2b7 100644 --- a/src/wsman.c +++ b/src/wsman.c @@ -424,7 +424,7 @@ static void wsman_output(WsManClient * cl, WsXmlDocH doc) return; } if (filename) { - f = fopen(filename, "w+"); + f = fopen(filename, "w"); if (f == NULL) { error("Could not open file for writing"); return; @@ -437,6 +437,22 @@ static void wsman_output(WsManClient * cl, WsXmlDocH doc) return; } +/* + * output pull results to separate files (appending "-" to the name) + * + */ +static void wsman_output_pull(WsManClient * cl, WsXmlDocH doc, int index) +{ + char *strbuf, *origfile = output_file; + int count = strlen(output_file) + 16; + + strbuf = (char*)calloc(count, 1); + snprintf(strbuf, count, "%s-%u.xml", output_file, index); + output_file = strbuf; + wsman_output(cl, doc); + output_file = origfile; + free(strbuf); +} static void initialize_logging(void) { @@ -910,11 +926,13 @@ int main(int argc, char **argv) if (step) break; + + int index = 0; while (enumContext != NULL && enumContext[0] != 0) { doc = wsmc_action_pull(cl, resource_uri, options, filter, enumContext); - wsman_output(cl, doc); + wsman_output_pull(cl, doc, ++index); if (wsmc_get_response_code(cl) != 200 && wsmc_get_response_code(cl) != 400 -- cgit