diff options
Diffstat (limited to 'xmlIO.c')
-rw-r--r-- | xmlIO.c | 69 |
1 files changed, 61 insertions, 8 deletions
@@ -135,6 +135,9 @@ typedef struct _xmlOutputCallback { static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK]; static int xmlOutputCallbackNr = 0; static int xmlOutputCallbackInitialized = 0; + +xmlOutputBufferPtr +xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder); #endif /* LIBXML_OUTPUT_ENABLED */ /************************************************************************ @@ -1720,7 +1723,7 @@ xmlIOHTTPOpenW(const char *post_uri, int compression) { /* Any character conversions should have been done before this */ - ctxt->doc_buff = xmlAllocOutputBuffer(NULL); + ctxt->doc_buff = xmlAllocOutputBufferInternal(NULL); } if (ctxt->doc_buff == NULL) { @@ -1731,7 +1734,7 @@ xmlIOHTTPOpenW(const char *post_uri, int compression) return (ctxt); } #endif /* LIBXML_OUTPUT_ENABLED */ - + #ifdef LIBXML_OUTPUT_ENABLED /** * xmlIOHTTPDfltOpenW @@ -2275,8 +2278,57 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { return(NULL); } + ret->encoder = encoder; + if (encoder != NULL) { + ret->conv = xmlBufferCreateSize(4000); + if (ret->conv == NULL) { + xmlFree(ret); + return(NULL); + } + + /* + * This call is designed to initiate the encoder state + */ + xmlCharEncOutFunc(encoder, ret->conv, NULL); + } else + ret->conv = NULL; + ret->writecallback = NULL; + ret->closecallback = NULL; + ret->context = NULL; + ret->written = 0; + + return(ret); +} + +/** + * xmlAllocOutputBufferInternal: + * @encoder: the encoding converter or NULL + * + * Create a buffered parser output + * + * Returns the new parser output or NULL + */ +xmlOutputBufferPtr +xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) { + xmlOutputBufferPtr ret; + + ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); + if (ret == NULL) { + xmlIOErrMemory("creating output buffer"); + return(NULL); + } + memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); + ret->buffer = xmlBufferCreate(); + if (ret->buffer == NULL) { + xmlFree(ret); + return(NULL); + } + + /* * For conversion buffers we use the special IO handling + * We don't do that from the exported API to avoid confusing + * user's code. */ ret->buffer->alloc = XML_BUFFER_ALLOC_IO; ret->buffer->contentIO = ret->buffer->content; @@ -2302,6 +2354,7 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { return(ret); } + #endif /* LIBXML_OUTPUT_ENABLED */ /** @@ -2502,7 +2555,7 @@ __xmlOutputBufferCreateFilename(const char *URI, if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { context = xmlGzfileOpenW(unescaped, compression); if (context != NULL) { - ret = xmlAllocOutputBuffer(encoder); + ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { ret->context = context; ret->writecallback = xmlGzfileWrite; @@ -2539,7 +2592,7 @@ __xmlOutputBufferCreateFilename(const char *URI, if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { context = xmlGzfileOpenW(URI, compression); if (context != NULL) { - ret = xmlAllocOutputBuffer(encoder); + ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { ret->context = context; ret->writecallback = xmlGzfileWrite; @@ -2572,7 +2625,7 @@ __xmlOutputBufferCreateFilename(const char *URI, /* * Allocate the Output buffer front-end. */ - ret = xmlAllocOutputBuffer(encoder); + ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { ret->context = context; ret->writecallback = xmlOutputCallbackTable[i].writecallback; @@ -2656,7 +2709,7 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { if (file == NULL) return(NULL); - ret = xmlAllocOutputBuffer(encoder); + ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { ret->context = file; ret->writecallback = xmlFileWrite; @@ -2814,7 +2867,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { if (fd < 0) return(NULL); - ret = xmlAllocOutputBuffer(encoder); + ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { ret->context = (void *) (long) fd; ret->writecallback = xmlFdWrite; @@ -2875,7 +2928,7 @@ xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, if (iowrite == NULL) return(NULL); - ret = xmlAllocOutputBuffer(encoder); + ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { ret->context = (void *) ioctx; ret->writecallback = iowrite; |