From 485aa8ee84ec0860b696c49b19ff6660dea8d4eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Sat, 13 Nov 2010 17:51:26 +0100 Subject: [PATCH] Allo saving XML to descriptor --- src/io.c | 9 ++++++--- src/io.h | 8 ++++++-- src/shigofumi.c | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/io.c b/src/io.c index a246cfa..ed7dbba 100644 --- a/src/io.c +++ b/src/io.c @@ -290,7 +290,6 @@ int load_data_from_file(const char *file, void **data, size_t *length, * in messages. */ int save_data_to_file(const char *file, int fd, const void *data, const size_t length, const char *mime_type, _Bool overwrite) { - int fd; ssize_t written, left = length; if (fd < 0 && !file) return -1; @@ -576,7 +575,11 @@ leave: } -int save_xml_to_file(const char *file, const xmlNodePtr node_list, +/* Save @node_list to file specified by descriptor @fd. If @fd is negative, @file + * file will be opened first. Descriptor is closed at the end of this + * function. Supply @file name even if @fd is positive, the name could be used + * in messages. */ +int save_xml_to_file(const char *file, int fd, const xmlNodePtr node_list, const char *mime_type, _Bool overwrite) { int retval = 0; xmlBufferPtr buffer = NULL; @@ -585,7 +588,7 @@ int save_xml_to_file(const char *file, const xmlNodePtr node_list, if (!retval) { /* And save buffer into file */ - retval = save_data_to_file(file, -1, buffer->content, buffer->use, + retval = save_data_to_file(file, fd, buffer->content, buffer->use, mime_type, overwrite); xmlBufferFree(buffer); } diff --git a/src/io.h b/src/io.h index f2c1b92..ec3fbb8 100644 --- a/src/io.h +++ b/src/io.h @@ -22,7 +22,7 @@ int load_data_from_file(const char *file, void **data, size_t *length, * function. Supply @file name even if @fd is positive, the name could be used * in messages. */ int save_data_to_file(const char *file, int fd, const void *data, - const size_t length, const char *mime_type, _Bool overwrite) { + const size_t length, const char *mime_type, _Bool overwrite); /* Parse @buffer as XML document and return @node_list specified by * @xpath_expression. @@ -40,7 +40,11 @@ void free_document_with_xml_node_list(struct isds_document **document); /* Serialize XML @node_list to automatically rellaocated libxml @buffer */ int serialize_xml_to_buffer(xmlBufferPtr *buffer, const xmlNodePtr node_list); -int save_xml_to_file(const char *file, const xmlNodePtr node_list, +/* Save @node_list to file specified by descriptor @fd. If @fd is negative, @file + * file will be opened first. Descriptor is closed at the end of this + * function. Supply @file name even if @fd is positive, the name could be used + * in messages. */ +int save_xml_to_file(const char *file, int fd, const xmlNodePtr node_list, const char *mime_type, _Bool overwrite); /* Return 0 if @path is directory, 1 if not, -1 if error occurred */ diff --git a/src/shigofumi.c b/src/shigofumi.c index 7f839bb..e1a3f14 100644 --- a/src/shigofumi.c +++ b/src/shigofumi.c @@ -2879,7 +2879,7 @@ static int shi_save_document(int argc, const char **argv) { /* Save document */ if (document->is_xml) - retval = save_xml_to_file(path, document->xml_node_list, + retval = save_xml_to_file(path, -1, document->xml_node_list, document->dmMimeType, overwrite); else retval = save_data_to_file(path, -1, document->data, @@ -2915,7 +2915,7 @@ static int shi_save_stamp(int argc, const char **argv) { return -1; } - return save_data_to_file(argv[1], -1 + return save_data_to_file(argv[1], -1, message->envelope->timestamp, message->envelope->timestamp_length, "application/timestamp-reply", overwrite); } -- 2.11.4.GIT