version 1.1.1.2, 2013/07/22 01:22:19
|
version 1.1.1.3, 2014/06/15 19:53:30
|
Line 96
|
Line 96
|
#endif |
#endif |
#include <libxml/globals.h> |
#include <libxml/globals.h> |
|
|
|
#include "buf.h" |
|
#include "enc.h" |
|
|
/* #define VERBOSE_FAILURE */ |
/* #define VERBOSE_FAILURE */ |
/* #define DEBUG_EXTERNAL_ENTITIES */ |
/* #define DEBUG_EXTERNAL_ENTITIES */ |
/* #define DEBUG_INPUT */ |
/* #define DEBUG_INPUT */ |
Line 768 int
|
Line 771 int
|
xmlCheckFilename (const char *path) |
xmlCheckFilename (const char *path) |
{ |
{ |
#ifdef HAVE_STAT |
#ifdef HAVE_STAT |
struct stat stat_buffer; | struct stat stat_buffer; |
#endif |
#endif |
if (path == NULL) | if (path == NULL) |
return(0); | return(0); |
|
|
#ifdef HAVE_STAT |
#ifdef HAVE_STAT |
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
|
/* |
|
* On Windows stat and wstat do not work with long pathname, |
|
* which start with '\\?\' |
|
*/ |
|
if ((path[0] == '\\') && (path[1] == '\\') && (path[2] == '?') && |
|
(path[3] == '\\') ) |
|
return 1; |
|
|
if (xmlWrapStat(path, &stat_buffer) == -1) |
if (xmlWrapStat(path, &stat_buffer) == -1) |
return 0; |
return 0; |
#else |
#else |
Line 789 xmlCheckFilename (const char *path)
|
Line 800 xmlCheckFilename (const char *path)
|
return 1; |
return 1; |
} |
} |
|
|
static int | int |
xmlNop(void) { |
xmlNop(void) { |
return(0); |
return(0); |
} |
} |
Line 990 xmlFileOpenW (const char *filename) {
|
Line 1001 xmlFileOpenW (const char *filename) {
|
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
fd = xmlWrapOpen(path, 1); |
fd = xmlWrapOpen(path, 1); |
#else |
#else |
fd = fopen(path, "wb"); | fd = fopen(path, "wb"); |
#endif /* WIN32 */ |
#endif /* WIN32 */ |
|
|
if (fd == NULL) xmlIOErr(0, path); |
if (fd == NULL) xmlIOErr(0, path); |
Line 2036 xmlIOHTTPCloseWrite( void * context, const char * http
|
Line 2047 xmlIOHTTPCloseWrite( void * context, const char * http
|
/* Pull the data out of the memory output buffer */ |
/* Pull the data out of the memory output buffer */ |
|
|
xmlOutputBufferPtr dctxt = ctxt->doc_buff; |
xmlOutputBufferPtr dctxt = ctxt->doc_buff; |
http_content = (char *)dctxt->buffer->content; | http_content = (char *) xmlBufContent(dctxt->buffer); |
content_lgth = dctxt->buffer->use; | content_lgth = xmlBufUse(dctxt->buffer); |
} |
} |
|
|
if ( http_content == NULL ) { |
if ( http_content == NULL ) { |
Line 2404 xmlAllocParserInputBuffer(xmlCharEncoding enc) {
|
Line 2415 xmlAllocParserInputBuffer(xmlCharEncoding enc) {
|
return(NULL); |
return(NULL); |
} |
} |
memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); |
memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); |
ret->buffer = xmlBufferCreateSize(2 * xmlDefaultBufferSize); | ret->buffer = xmlBufCreateSize(2 * xmlDefaultBufferSize); |
if (ret->buffer == NULL) { |
if (ret->buffer == NULL) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
} |
} |
ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; | xmlBufSetAllocationScheme(ret->buffer, XML_BUFFER_ALLOC_DOUBLEIT); |
ret->encoder = xmlGetCharEncodingHandler(enc); |
ret->encoder = xmlGetCharEncodingHandler(enc); |
if (ret->encoder != NULL) |
if (ret->encoder != NULL) |
ret->raw = xmlBufferCreateSize(2 * xmlDefaultBufferSize); | ret->raw = xmlBufCreateSize(2 * xmlDefaultBufferSize); |
else |
else |
ret->raw = NULL; |
ret->raw = NULL; |
ret->readcallback = NULL; |
ret->readcallback = NULL; |
Line 2443 xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder
|
Line 2454 xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder
|
return(NULL); |
return(NULL); |
} |
} |
memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
ret->buffer = xmlBufferCreate(); | ret->buffer = xmlBufCreate(); |
if (ret->buffer == NULL) { |
if (ret->buffer == NULL) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
} |
} |
|
|
/* try to avoid a performance problem with Windows realloc() */ |
/* try to avoid a performance problem with Windows realloc() */ |
if (ret->buffer->alloc == XML_BUFFER_ALLOC_EXACT) | if (xmlBufGetAllocationScheme(ret->buffer) == XML_BUFFER_ALLOC_EXACT) |
ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; | xmlBufSetAllocationScheme(ret->buffer, XML_BUFFER_ALLOC_DOUBLEIT); |
|
|
ret->encoder = encoder; |
ret->encoder = encoder; |
if (encoder != NULL) { |
if (encoder != NULL) { |
ret->conv = xmlBufferCreateSize(4000); | ret->conv = xmlBufCreateSize(4000); |
if (ret->conv == NULL) { |
if (ret->conv == NULL) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
Line 2464 xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder
|
Line 2475 xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder
|
/* |
/* |
* This call is designed to initiate the encoder state |
* This call is designed to initiate the encoder state |
*/ |
*/ |
xmlCharEncOutFunc(encoder, ret->conv, NULL); | xmlCharEncOutput(ret, 1); |
} else |
} else |
ret->conv = NULL; |
ret->conv = NULL; |
ret->writecallback = NULL; |
ret->writecallback = NULL; |
Line 2493 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr
|
Line 2504 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr
|
return(NULL); |
return(NULL); |
} |
} |
memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
ret->buffer = xmlBufferCreate(); | ret->buffer = xmlBufCreate(); |
if (ret->buffer == NULL) { |
if (ret->buffer == NULL) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
Line 2502 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr
|
Line 2513 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr
|
|
|
/* |
/* |
* For conversion buffers we use the special IO handling |
* 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; | xmlBufSetAllocationScheme(ret->buffer, XML_BUFFER_ALLOC_IO); |
ret->buffer->contentIO = ret->buffer->content; | |
|
|
ret->encoder = encoder; |
ret->encoder = encoder; |
if (encoder != NULL) { |
if (encoder != NULL) { |
ret->conv = xmlBufferCreateSize(4000); | ret->conv = xmlBufCreateSize(4000); |
if (ret->conv == NULL) { |
if (ret->conv == NULL) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
Line 2519 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr
|
Line 2527 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr
|
/* |
/* |
* This call is designed to initiate the encoder state |
* This call is designed to initiate the encoder state |
*/ |
*/ |
xmlCharEncOutFunc(encoder, ret->conv, NULL); | xmlCharEncOutput(ret, 1); |
} else |
} else |
ret->conv = NULL; |
ret->conv = NULL; |
ret->writecallback = NULL; |
ret->writecallback = NULL; |
Line 2543 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) {
|
Line 2551 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) {
|
if (in == NULL) return; |
if (in == NULL) return; |
|
|
if (in->raw) { |
if (in->raw) { |
xmlBufferFree(in->raw); | xmlBufFree(in->raw); |
in->raw = NULL; |
in->raw = NULL; |
} |
} |
if (in->encoder != NULL) { |
if (in->encoder != NULL) { |
Line 2553 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) {
|
Line 2561 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) {
|
in->closecallback(in->context); |
in->closecallback(in->context); |
} |
} |
if (in->buffer != NULL) { |
if (in->buffer != NULL) { |
xmlBufferFree(in->buffer); | xmlBufFree(in->buffer); |
in->buffer = NULL; |
in->buffer = NULL; |
} |
} |
|
|
Line 2585 xmlOutputBufferClose(xmlOutputBufferPtr out)
|
Line 2593 xmlOutputBufferClose(xmlOutputBufferPtr out)
|
} |
} |
written = out->written; |
written = out->written; |
if (out->conv) { |
if (out->conv) { |
xmlBufferFree(out->conv); | xmlBufFree(out->conv); |
out->conv = NULL; |
out->conv = NULL; |
} |
} |
if (out->encoder != NULL) { |
if (out->encoder != NULL) { |
xmlCharEncCloseFunc(out->encoder); |
xmlCharEncCloseFunc(out->encoder); |
} |
} |
if (out->buffer != NULL) { |
if (out->buffer != NULL) { |
xmlBufferFree(out->buffer); | xmlBufFree(out->buffer); |
out->buffer = NULL; |
out->buffer = NULL; |
} |
} |
|
|
Line 2922 xmlOutputBufferCreateBuffer(xmlBufferPtr buffer,
|
Line 2930 xmlOutputBufferCreateBuffer(xmlBufferPtr buffer,
|
return(ret); |
return(ret); |
} |
} |
|
|
|
/** |
|
* xmlOutputBufferGetContent: |
|
* @out: an xmlOutputBufferPtr |
|
* |
|
* Gives a pointer to the data currently held in the output buffer |
|
* |
|
* Returns a pointer to the data or NULL in case of error |
|
*/ |
|
const xmlChar * |
|
xmlOutputBufferGetContent(xmlOutputBufferPtr out) { |
|
if ((out == NULL) || (out->buffer == NULL)) |
|
return(NULL); |
|
|
|
return(xmlBufContent(out->buffer)); |
|
} |
|
|
|
/** |
|
* xmlOutputBufferGetSize: |
|
* @out: an xmlOutputBufferPtr |
|
* |
|
* Gives the length of the data currently held in the output buffer |
|
* |
|
* Returns 0 in case or error or no data is held, the size otherwise |
|
*/ |
|
size_t |
|
xmlOutputBufferGetSize(xmlOutputBufferPtr out) { |
|
if ((out == NULL) || (out->buffer == NULL)) |
|
return(0); |
|
|
|
return(xmlBufUse(out->buffer)); |
|
} |
|
|
|
|
#endif /* LIBXML_OUTPUT_ENABLED */ |
#endif /* LIBXML_OUTPUT_ENABLED */ |
|
|
/** |
/** |
Line 2974 xmlParserInputBufferCreateMem(const char *mem, int siz
|
Line 3015 xmlParserInputBufferCreateMem(const char *mem, int siz
|
ret->context = (void *) mem; |
ret->context = (void *) mem; |
ret->readcallback = (xmlInputReadCallback) xmlNop; |
ret->readcallback = (xmlInputReadCallback) xmlNop; |
ret->closecallback = NULL; |
ret->closecallback = NULL; |
errcode = xmlBufferAdd(ret->buffer, (const xmlChar *) mem, size); | errcode = xmlBufAdd(ret->buffer, (const xmlChar *) mem, size); |
if (errcode != 0) { |
if (errcode != 0) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
Line 3011 xmlParserInputBufferCreateStatic(const char *mem, int
|
Line 3052 xmlParserInputBufferCreateStatic(const char *mem, int
|
return(NULL); |
return(NULL); |
} |
} |
memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); |
memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); |
ret->buffer = xmlBufferCreateStatic((void *)mem, (size_t) size); | ret->buffer = xmlBufCreateStatic((void *)mem, (size_t) size); |
if (ret->buffer == NULL) { |
if (ret->buffer == NULL) { |
xmlFree(ret); |
xmlFree(ret); |
return(NULL); |
return(NULL); |
} |
} |
ret->encoder = xmlGetCharEncodingHandler(enc); |
ret->encoder = xmlGetCharEncodingHandler(enc); |
if (ret->encoder != NULL) |
if (ret->encoder != NULL) |
ret->raw = xmlBufferCreateSize(2 * xmlDefaultBufferSize); | ret->raw = xmlBufCreateSize(2 * xmlDefaultBufferSize); |
else |
else |
ret->raw = NULL; |
ret->raw = NULL; |
ret->compressed = -1; |
ret->compressed = -1; |
Line 3187 xmlParserInputBufferPush(xmlParserInputBufferPtr in,
|
Line 3228 xmlParserInputBufferPush(xmlParserInputBufferPtr in,
|
* Store the data in the incoming raw buffer |
* Store the data in the incoming raw buffer |
*/ |
*/ |
if (in->raw == NULL) { |
if (in->raw == NULL) { |
in->raw = xmlBufferCreate(); | in->raw = xmlBufCreate(); |
} |
} |
ret = xmlBufferAdd(in->raw, (const xmlChar *) buf, len); | ret = xmlBufAdd(in->raw, (const xmlChar *) buf, len); |
if (ret != 0) |
if (ret != 0) |
return(-1); |
return(-1); |
|
|
/* |
/* |
* convert as much as possible to the parser reading buffer. |
* convert as much as possible to the parser reading buffer. |
*/ |
*/ |
use = in->raw->use; | use = xmlBufUse(in->raw); |
nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); | nbchars = xmlCharEncInput(in, 1); |
if (nbchars < 0) { |
if (nbchars < 0) { |
xmlIOErr(XML_IO_ENCODER, NULL); |
xmlIOErr(XML_IO_ENCODER, NULL); |
in->error = XML_IO_ENCODER; |
in->error = XML_IO_ENCODER; |
return(-1); |
return(-1); |
} |
} |
in->rawconsumed += (use - in->raw->use); | in->rawconsumed += (use - xmlBufUse(in->raw)); |
} else { |
} else { |
nbchars = len; |
nbchars = len; |
ret = xmlBufferAdd(in->buffer, (xmlChar *) buf, nbchars); | ret = xmlBufAdd(in->buffer, (xmlChar *) buf, nbchars); |
if (ret != 0) |
if (ret != 0) |
return(-1); |
return(-1); |
} |
} |
#ifdef DEBUG_INPUT |
#ifdef DEBUG_INPUT |
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"I/O: pushed %d chars, buffer %d/%d\n", |
"I/O: pushed %d chars, buffer %d/%d\n", |
nbchars, in->buffer->use, in->buffer->size); | nbchars, xmlBufUse(in->buffer), xmlBufLength(in->buffer)); |
#endif |
#endif |
return(nbchars); |
return(nbchars); |
} |
} |
Line 3251 xmlParserInputBufferGrow(xmlParserInputBufferPtr in, i
|
Line 3292 xmlParserInputBufferGrow(xmlParserInputBufferPtr in, i
|
char *buffer = NULL; |
char *buffer = NULL; |
int res = 0; |
int res = 0; |
int nbchars = 0; |
int nbchars = 0; |
int buffree; |
|
unsigned int needSize; |
|
|
|
if ((in == NULL) || (in->error)) return(-1); |
if ((in == NULL) || (in->error)) return(-1); |
if ((len <= MINLEN) && (len != 4)) |
if ((len <= MINLEN) && (len != 4)) |
len = MINLEN; |
len = MINLEN; |
|
|
buffree = in->buffer->size - in->buffer->use; | if (xmlBufAvail(in->buffer) <= 0) { |
if (buffree <= 0) { | |
xmlIOErr(XML_IO_BUFFER_FULL, NULL); |
xmlIOErr(XML_IO_BUFFER_FULL, NULL); |
in->error = XML_IO_BUFFER_FULL; |
in->error = XML_IO_BUFFER_FULL; |
return(-1); |
return(-1); |
} |
} |
|
|
needSize = in->buffer->use + len + 1; | if (xmlBufGrow(in->buffer, len + 1) < 0) { |
if (needSize > in->buffer->size){ | xmlIOErrMemory("growing input buffer"); |
if (!xmlBufferResize(in->buffer, needSize)){ | in->error = XML_ERR_NO_MEMORY; |
xmlIOErrMemory("growing input buffer"); | return(-1); |
in->error = XML_ERR_NO_MEMORY; | |
return(-1); | |
} | |
} |
} |
buffer = (char *)&in->buffer->content[in->buffer->use]; | buffer = (char *)xmlBufEnd(in->buffer); |
|
|
/* |
/* |
* Call the read method for this I/O type. |
* Call the read method for this I/O type. |
Line 3298 xmlParserInputBufferGrow(xmlParserInputBufferPtr in, i
|
Line 3333 xmlParserInputBufferGrow(xmlParserInputBufferPtr in, i
|
* Store the data in the incoming raw buffer |
* Store the data in the incoming raw buffer |
*/ |
*/ |
if (in->raw == NULL) { |
if (in->raw == NULL) { |
in->raw = xmlBufferCreate(); | in->raw = xmlBufCreate(); |
} |
} |
res = xmlBufferAdd(in->raw, (const xmlChar *) buffer, len); | res = xmlBufAdd(in->raw, (const xmlChar *) buffer, len); |
if (res != 0) |
if (res != 0) |
return(-1); |
return(-1); |
|
|
/* |
/* |
* convert as much as possible to the parser reading buffer. |
* convert as much as possible to the parser reading buffer. |
*/ |
*/ |
use = in->raw->use; | use = xmlBufUse(in->raw); |
nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); | nbchars = xmlCharEncInput(in, 1); |
if (nbchars < 0) { |
if (nbchars < 0) { |
xmlIOErr(XML_IO_ENCODER, NULL); |
xmlIOErr(XML_IO_ENCODER, NULL); |
in->error = XML_IO_ENCODER; |
in->error = XML_IO_ENCODER; |
return(-1); |
return(-1); |
} |
} |
in->rawconsumed += (use - in->raw->use); | in->rawconsumed += (use - xmlBufUse(in->raw)); |
} else { |
} else { |
nbchars = len; |
nbchars = len; |
in->buffer->use += nbchars; | xmlBufAddLen(in->buffer, nbchars); |
buffer[nbchars] = 0; | |
} |
} |
#ifdef DEBUG_INPUT |
#ifdef DEBUG_INPUT |
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"I/O: read %d chars, buffer %d/%d\n", | "I/O: read %d chars, buffer %d\n", |
nbchars, in->buffer->use, in->buffer->size); | nbchars, xmlBufUse(in->buffer)); |
#endif |
#endif |
return(nbchars); |
return(nbchars); |
} |
} |
Line 3345 xmlParserInputBufferRead(xmlParserInputBufferPtr in, i
|
Line 3379 xmlParserInputBufferRead(xmlParserInputBufferPtr in, i
|
if ((in == NULL) || (in->error)) return(-1); |
if ((in == NULL) || (in->error)) return(-1); |
if (in->readcallback != NULL) |
if (in->readcallback != NULL) |
return(xmlParserInputBufferGrow(in, len)); |
return(xmlParserInputBufferGrow(in, len)); |
else if ((in->buffer != NULL) && | else if (xmlBufGetAllocationScheme(in->buffer) == XML_BUFFER_ALLOC_IMMUTABLE) |
(in->buffer->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) | |
return(0); |
return(0); |
else |
else |
return(-1); |
return(-1); |
Line 3391 xmlOutputBufferWrite(xmlOutputBufferPtr out, int len,
|
Line 3424 xmlOutputBufferWrite(xmlOutputBufferPtr out, int len,
|
* Store the data in the incoming raw buffer |
* Store the data in the incoming raw buffer |
*/ |
*/ |
if (out->conv == NULL) { |
if (out->conv == NULL) { |
out->conv = xmlBufferCreate(); | out->conv = xmlBufCreate(); |
} |
} |
ret = xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk); | ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk); |
if (ret != 0) |
if (ret != 0) |
return(-1); |
return(-1); |
|
|
if ((out->buffer->use < MINLEN) && (chunk == len)) | if ((xmlBufUse(out->buffer) < MINLEN) && (chunk == len)) |
goto done; |
goto done; |
|
|
/* |
/* |
* convert as much as possible to the parser reading buffer. |
* convert as much as possible to the parser reading buffer. |
*/ |
*/ |
ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); | ret = xmlCharEncOutput(out, 0); |
if ((ret < 0) && (ret != -3)) { |
if ((ret < 0) && (ret != -3)) { |
xmlIOErr(XML_IO_ENCODER, NULL); |
xmlIOErr(XML_IO_ENCODER, NULL); |
out->error = XML_IO_ENCODER; |
out->error = XML_IO_ENCODER; |
return(-1); |
return(-1); |
} |
} |
nbchars = out->conv->use; | nbchars = xmlBufUse(out->conv); |
} else { |
} else { |
ret = xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk); | ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk); |
if (ret != 0) |
if (ret != 0) |
return(-1); |
return(-1); |
nbchars = out->buffer->use; | nbchars = xmlBufUse(out->buffer); |
} |
} |
buf += chunk; |
buf += chunk; |
len -= chunk; |
len -= chunk; |
Line 3428 xmlOutputBufferWrite(xmlOutputBufferPtr out, int len,
|
Line 3461 xmlOutputBufferWrite(xmlOutputBufferPtr out, int len,
|
*/ |
*/ |
if (out->encoder != NULL) { |
if (out->encoder != NULL) { |
ret = out->writecallback(out->context, |
ret = out->writecallback(out->context, |
(const char *)out->conv->content, nbchars); | (const char *)xmlBufContent(out->conv), nbchars); |
if (ret >= 0) |
if (ret >= 0) |
xmlBufferShrink(out->conv, ret); | xmlBufShrink(out->conv, ret); |
} else { |
} else { |
ret = out->writecallback(out->context, |
ret = out->writecallback(out->context, |
(const char *)out->buffer->content, nbchars); | (const char *)xmlBufContent(out->buffer), nbchars); |
if (ret >= 0) |
if (ret >= 0) |
xmlBufferShrink(out->buffer, ret); | xmlBufShrink(out->buffer, ret); |
} |
} |
if (ret < 0) { |
if (ret < 0) { |
xmlIOErr(XML_IO_WRITE, NULL); |
xmlIOErr(XML_IO_WRITE, NULL); |
Line 3479 xmlEscapeContent(unsigned char* out, int *outlen,
|
Line 3512 xmlEscapeContent(unsigned char* out, int *outlen,
|
inend = in + (*inlen); |
inend = in + (*inlen); |
|
|
while ((in < inend) && (out < outend)) { |
while ((in < inend) && (out < outend)) { |
if (*in == '<') { | if (*in == '<') { |
if (outend - out < 4) break; |
if (outend - out < 4) break; |
*out++ = '&'; |
*out++ = '&'; |
*out++ = 'l'; |
*out++ = 'l'; |
Line 3543 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
Line 3576 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
|
|
if ((out == NULL) || (out->error) || (str == NULL) || |
if ((out == NULL) || (out->error) || (str == NULL) || |
(out->buffer == NULL) || |
(out->buffer == NULL) || |
(out->buffer->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) return(-1); | (xmlBufGetAllocationScheme(out->buffer) == XML_BUFFER_ALLOC_IMMUTABLE)) |
| return(-1); |
len = strlen((const char *)str); |
len = strlen((const char *)str); |
if (len < 0) return(0); |
if (len < 0) return(0); |
if (out->error) return(-1); |
if (out->error) return(-1); |
Line 3556 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
Line 3590 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
* how many bytes to consume and how many bytes to store. |
* how many bytes to consume and how many bytes to store. |
*/ |
*/ |
cons = len; |
cons = len; |
chunk = (out->buffer->size - out->buffer->use) - 1; | chunk = xmlBufAvail(out->buffer) - 1; |
|
|
/* |
/* |
* make sure we have enough room to save first, if this is |
* make sure we have enough room to save first, if this is |
* not the case force a flush, but make sure we stay in the loop |
* not the case force a flush, but make sure we stay in the loop |
*/ |
*/ |
if (chunk < 40) { |
if (chunk < 40) { |
if (xmlBufferGrow(out->buffer, out->buffer->size + 100) < 0) | if (xmlBufGrow(out->buffer, 100) < 0) |
return(-1); |
return(-1); |
oldwritten = -1; |
oldwritten = -1; |
continue; |
continue; |
Line 3577 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
Line 3611 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
* Store the data in the incoming raw buffer |
* Store the data in the incoming raw buffer |
*/ |
*/ |
if (out->conv == NULL) { |
if (out->conv == NULL) { |
out->conv = xmlBufferCreate(); | out->conv = xmlBufCreate(); |
} |
} |
ret = escaping(out->buffer->content + out->buffer->use , | ret = escaping(xmlBufEnd(out->buffer) , |
&chunk, str, &cons); |
&chunk, str, &cons); |
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ |
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ |
return(-1); |
return(-1); |
out->buffer->use += chunk; | xmlBufAddLen(out->buffer, chunk); |
out->buffer->content[out->buffer->use] = 0; | |
|
|
if ((out->buffer->use < MINLEN) && (cons == len)) | if ((xmlBufUse(out->buffer) < MINLEN) && (cons == len)) |
goto done; |
goto done; |
|
|
/* |
/* |
* convert as much as possible to the output buffer. |
* convert as much as possible to the output buffer. |
*/ |
*/ |
ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); | ret = xmlCharEncOutput(out, 0); |
if ((ret < 0) && (ret != -3)) { |
if ((ret < 0) && (ret != -3)) { |
xmlIOErr(XML_IO_ENCODER, NULL); |
xmlIOErr(XML_IO_ENCODER, NULL); |
out->error = XML_IO_ENCODER; |
out->error = XML_IO_ENCODER; |
return(-1); |
return(-1); |
} |
} |
nbchars = out->conv->use; | nbchars = xmlBufUse(out->conv); |
} else { |
} else { |
ret = escaping(out->buffer->content + out->buffer->use , | ret = escaping(xmlBufEnd(out->buffer), &chunk, str, &cons); |
&chunk, str, &cons); | |
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ |
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ |
return(-1); |
return(-1); |
out->buffer->use += chunk; | xmlBufAddLen(out->buffer, chunk); |
out->buffer->content[out->buffer->use] = 0; | nbchars = xmlBufUse(out->buffer); |
nbchars = out->buffer->use; | |
} |
} |
str += cons; |
str += cons; |
len -= cons; |
len -= cons; |
Line 3620 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
Line 3651 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
*/ |
*/ |
if (out->encoder != NULL) { |
if (out->encoder != NULL) { |
ret = out->writecallback(out->context, |
ret = out->writecallback(out->context, |
(const char *)out->conv->content, nbchars); | (const char *)xmlBufContent(out->conv), nbchars); |
if (ret >= 0) |
if (ret >= 0) |
xmlBufferShrink(out->conv, ret); | xmlBufShrink(out->conv, ret); |
} else { |
} else { |
ret = out->writecallback(out->context, |
ret = out->writecallback(out->context, |
(const char *)out->buffer->content, nbchars); | (const char *)xmlBufContent(out->buffer), nbchars); |
if (ret >= 0) |
if (ret >= 0) |
xmlBufferShrink(out->buffer, ret); | xmlBufShrink(out->buffer, ret); |
} |
} |
if (ret < 0) { |
if (ret < 0) { |
xmlIOErr(XML_IO_WRITE, NULL); |
xmlIOErr(XML_IO_WRITE, NULL); |
Line 3635 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
Line 3666 xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, con
|
return(ret); |
return(ret); |
} |
} |
out->written += ret; |
out->written += ret; |
} else if (out->buffer->size - out->buffer->use < MINLEN) { | } else if (xmlBufAvail(out->buffer) < MINLEN) { |
xmlBufferResize(out->buffer, out->buffer->size + MINLEN); | xmlBufGrow(out->buffer, MINLEN); |
} |
} |
written += nbchars; |
written += nbchars; |
} while ((len > 0) && (oldwritten != written)); |
} while ((len > 0) && (oldwritten != written)); |
Line 3694 xmlOutputBufferFlush(xmlOutputBufferPtr out) {
|
Line 3725 xmlOutputBufferFlush(xmlOutputBufferPtr out) {
|
*/ |
*/ |
if ((out->conv != NULL) && (out->encoder != NULL)) { |
if ((out->conv != NULL) && (out->encoder != NULL)) { |
/* |
/* |
* convert as much as possible to the parser reading buffer. | * convert as much as possible to the parser output buffer. |
*/ |
*/ |
nbchars = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); | do { |
if (nbchars < 0) { | nbchars = xmlCharEncOutput(out, 0); |
xmlIOErr(XML_IO_ENCODER, NULL); | if (nbchars < 0) { |
out->error = XML_IO_ENCODER; | xmlIOErr(XML_IO_ENCODER, NULL); |
return(-1); | out->error = XML_IO_ENCODER; |
} | return(-1); |
| } |
| } while (nbchars); |
} |
} |
|
|
/* |
/* |
Line 3710 xmlOutputBufferFlush(xmlOutputBufferPtr out) {
|
Line 3743 xmlOutputBufferFlush(xmlOutputBufferPtr out) {
|
if ((out->conv != NULL) && (out->encoder != NULL) && |
if ((out->conv != NULL) && (out->encoder != NULL) && |
(out->writecallback != NULL)) { |
(out->writecallback != NULL)) { |
ret = out->writecallback(out->context, |
ret = out->writecallback(out->context, |
(const char *)out->conv->content, out->conv->use); | (const char *)xmlBufContent(out->conv), |
| xmlBufUse(out->conv)); |
if (ret >= 0) |
if (ret >= 0) |
xmlBufferShrink(out->conv, ret); | xmlBufShrink(out->conv, ret); |
} else if (out->writecallback != NULL) { |
} else if (out->writecallback != NULL) { |
ret = out->writecallback(out->context, |
ret = out->writecallback(out->context, |
(const char *)out->buffer->content, out->buffer->use); | (const char *)xmlBufContent(out->buffer), |
| xmlBufUse(out->buffer)); |
if (ret >= 0) |
if (ret >= 0) |
xmlBufferShrink(out->buffer, ret); | xmlBufShrink(out->buffer, ret); |
} |
} |
if (ret < 0) { |
if (ret < 0) { |
xmlIOErr(XML_IO_FLUSH, NULL); |
xmlIOErr(XML_IO_FLUSH, NULL); |