summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlaus Kämpf <kkaempf@suse.de>2010-11-05 12:02:13 +0100
committerKlaus Kämpf <kkaempf@suse.de>2010-11-05 12:02:13 +0100
commit8e452058c075b91cd9dc50eb73422e9b0f3bbc4d (patch)
tree2e0897af91a355f1f64917b96a7d09d864787912
parentad8ca62b6a7a0ab4422f69684d056df043ac7dab (diff)
downloadwsmancli-8e452058c075b91cd9dc50eb73422e9b0f3bbc4d.tar.gz
wsmancli-8e452058c075b91cd9dc50eb73422e9b0f3bbc4d.tar.xz
wsmancli-8e452058c075b91cd9dc50eb73422e9b0f3bbc4d.zip
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.
-rw-r--r--src/wsman.c22
1 files changed, 20 insertions, 2 deletions
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 "-<index>" 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