mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-28 00:21:53 +03:00
applied Peter Jacobi encoding cleanup patch, and also avoided a possible
* parser.c parserInternals.c tree.c: applied Peter Jacobi encoding cleanup patch, and also avoided a possible memory leak Daniel
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Tue Jul 29 12:46:08 EDT 2003 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* parser.c parserInternals.c tree.c: applied Peter Jacobi encoding
|
||||||
|
cleanup patch, and also avoided a possible memory leak
|
||||||
|
|
||||||
Tue Jul 29 09:28:09 EDT 2003 Daniel Veillard <daniel@veillard.com>
|
Tue Jul 29 09:28:09 EDT 2003 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* encoding.c: fix the previous commit
|
* encoding.c: fix the previous commit
|
||||||
|
33
parser.c
33
parser.c
@ -7575,38 +7575,21 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
|
|||||||
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
|
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
|
||||||
}
|
}
|
||||||
if (encoding != NULL) {
|
if (encoding != NULL) {
|
||||||
xmlCharEncoding enc;
|
|
||||||
xmlCharEncodingHandlerPtr handler;
|
xmlCharEncodingHandlerPtr handler;
|
||||||
|
|
||||||
if (ctxt->input->encoding != NULL)
|
if (ctxt->input->encoding != NULL)
|
||||||
xmlFree((xmlChar *) ctxt->input->encoding);
|
xmlFree((xmlChar *) ctxt->input->encoding);
|
||||||
ctxt->input->encoding = encoding;
|
ctxt->input->encoding = encoding;
|
||||||
|
|
||||||
enc = xmlParseCharEncoding((const char *) encoding);
|
handler = xmlFindCharEncodingHandler((const char *) encoding);
|
||||||
/*
|
if (handler != NULL) {
|
||||||
* registered set of known encodings
|
xmlSwitchToEncoding(ctxt, handler);
|
||||||
*/
|
|
||||||
if (enc != XML_CHAR_ENCODING_ERROR) {
|
|
||||||
xmlSwitchEncoding(ctxt, enc);
|
|
||||||
if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
|
|
||||||
ctxt->input->encoding = NULL;
|
|
||||||
xmlFree(encoding);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
|
||||||
* fallback for unknown encodings
|
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||||
*/
|
ctxt->sax->error(ctxt->userData,
|
||||||
handler = xmlFindCharEncodingHandler((const char *) encoding);
|
"Unsupported encoding %s\n", encoding);
|
||||||
if (handler != NULL) {
|
return(NULL);
|
||||||
xmlSwitchToEncoding(ctxt, handler);
|
|
||||||
} else {
|
|
||||||
ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
|
|
||||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
|
||||||
ctxt->sax->error(ctxt->userData,
|
|
||||||
"Unsupported encoding %s\n", encoding);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1780,13 +1780,13 @@ xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* "UTF-16" can be used for both LE and BE
|
* "UTF-16" can be used for both LE and BE
|
||||||
*/
|
|
||||||
if ((!xmlStrncmp(BAD_CAST ctxt->input->buf->encoder->name,
|
if ((!xmlStrncmp(BAD_CAST ctxt->input->buf->encoder->name,
|
||||||
BAD_CAST "UTF-16", 6)) &&
|
BAD_CAST "UTF-16", 6)) &&
|
||||||
(!xmlStrncmp(BAD_CAST handler->name,
|
(!xmlStrncmp(BAD_CAST handler->name,
|
||||||
BAD_CAST "UTF-16", 6))) {
|
BAD_CAST "UTF-16", 6))) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: this is a bit dangerous, but that's what it
|
* Note: this is a bit dangerous, but that's what it
|
||||||
|
39
tree.c
39
tree.c
@ -961,6 +961,11 @@ xmlNewDoc(const xmlChar *version) {
|
|||||||
cur->standalone = -1;
|
cur->standalone = -1;
|
||||||
cur->compression = -1; /* not initialized */
|
cur->compression = -1; /* not initialized */
|
||||||
cur->doc = cur;
|
cur->doc = cur;
|
||||||
|
/*
|
||||||
|
* The in memory encoding is always UTF8
|
||||||
|
* This field will never change and would
|
||||||
|
* be obsolete if not for binary compatibility.
|
||||||
|
*/
|
||||||
cur->charset = XML_CHAR_ENCODING_UTF8;
|
cur->charset = XML_CHAR_ENCODING_UTF8;
|
||||||
|
|
||||||
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
|
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
|
||||||
@ -7830,7 +7835,6 @@ xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
|
|||||||
int format) {
|
int format) {
|
||||||
int dummy = 0;
|
int dummy = 0;
|
||||||
|
|
||||||
xmlCharEncoding doc_charset;
|
|
||||||
xmlOutputBufferPtr out_buff = NULL;
|
xmlOutputBufferPtr out_buff = NULL;
|
||||||
xmlCharEncodingHandlerPtr conv_hdlr = NULL;
|
xmlCharEncodingHandlerPtr conv_hdlr = NULL;
|
||||||
|
|
||||||
@ -7863,16 +7867,6 @@ xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
|
|||||||
if (txt_encoding == NULL)
|
if (txt_encoding == NULL)
|
||||||
txt_encoding = (const char *) out_doc->encoding;
|
txt_encoding = (const char *) out_doc->encoding;
|
||||||
if (txt_encoding != NULL) {
|
if (txt_encoding != NULL) {
|
||||||
doc_charset = xmlParseCharEncoding(txt_encoding);
|
|
||||||
|
|
||||||
if (out_doc->charset != XML_CHAR_ENCODING_UTF8) {
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"xmlDocDumpFormatMemoryEnc: Source document not in UTF8\n");
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (doc_charset != XML_CHAR_ENCODING_UTF8) {
|
|
||||||
conv_hdlr = xmlGetCharEncodingHandler(doc_charset);
|
|
||||||
if (conv_hdlr == NULL)
|
|
||||||
conv_hdlr = xmlFindCharEncodingHandler(txt_encoding);
|
conv_hdlr = xmlFindCharEncodingHandler(txt_encoding);
|
||||||
if ( conv_hdlr == NULL ) {
|
if ( conv_hdlr == NULL ) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
@ -7884,7 +7878,6 @@ xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) {
|
if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
@ -8048,25 +8041,12 @@ xmlDocFormatDump(FILE *f, xmlDocPtr cur, int format) {
|
|||||||
encoding = (const char *) cur->encoding;
|
encoding = (const char *) cur->encoding;
|
||||||
|
|
||||||
if (encoding != NULL) {
|
if (encoding != NULL) {
|
||||||
xmlCharEncoding enc;
|
|
||||||
|
|
||||||
enc = xmlParseCharEncoding(encoding);
|
|
||||||
|
|
||||||
if (cur->charset != XML_CHAR_ENCODING_UTF8) {
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"xmlDocDump: document not in UTF8\n");
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
if (enc != XML_CHAR_ENCODING_UTF8) {
|
|
||||||
handler = xmlGetCharEncodingHandler(enc);
|
|
||||||
if (handler == NULL)
|
|
||||||
handler = xmlFindCharEncodingHandler(encoding);
|
handler = xmlFindCharEncodingHandler(encoding);
|
||||||
if (handler == NULL) {
|
if (handler == NULL) {
|
||||||
xmlFree((char *) cur->encoding);
|
xmlFree((char *) cur->encoding);
|
||||||
cur->encoding = NULL;
|
cur->encoding = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
buf = xmlOutputBufferCreateFile(f, handler);
|
buf = xmlOutputBufferCreateFile(f, handler);
|
||||||
if (buf == NULL) return(-1);
|
if (buf == NULL) return(-1);
|
||||||
xmlDocContentDumpOutput(buf, cur, NULL, format);
|
xmlDocContentDumpOutput(buf, cur, NULL, format);
|
||||||
@ -8150,7 +8130,6 @@ xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur,
|
|||||||
const char * encoding, int format ) {
|
const char * encoding, int format ) {
|
||||||
xmlOutputBufferPtr buf;
|
xmlOutputBufferPtr buf;
|
||||||
xmlCharEncodingHandlerPtr handler = NULL;
|
xmlCharEncodingHandlerPtr handler = NULL;
|
||||||
xmlCharEncoding enc;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (cur == NULL)
|
if (cur == NULL)
|
||||||
@ -8161,17 +8140,9 @@ xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur,
|
|||||||
|
|
||||||
if (encoding != NULL) {
|
if (encoding != NULL) {
|
||||||
|
|
||||||
enc = xmlParseCharEncoding(encoding);
|
|
||||||
if (cur->charset != XML_CHAR_ENCODING_UTF8) {
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"xmlSaveFormatFileEnc: document not in UTF8\n");
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
if (enc != XML_CHAR_ENCODING_UTF8) {
|
|
||||||
handler = xmlFindCharEncodingHandler(encoding);
|
handler = xmlFindCharEncodingHandler(encoding);
|
||||||
if (handler == NULL)
|
if (handler == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB_H
|
#ifdef HAVE_ZLIB_H
|
||||||
|
Reference in New Issue
Block a user