diff options
author | Aron Xu <aron@debian.org> | 2014-07-09 04:01:07 +0800 |
---|---|---|
committer | Aron Xu <aron@debian.org> | 2014-07-09 04:01:07 +0800 |
commit | 7042e17490515a990a45aa7237d11bc49ab0eaf0 (patch) | |
tree | 62b661911406394bbeaca8951d660bb6d8aac0de /HTMLtree.c | |
parent | 2c8fe012ef1ff6e0613480dd182dec099aa9636e (diff) | |
download | libxml2-7042e17490515a990a45aa7237d11bc49ab0eaf0.tar.gz |
Imported Upstream version 2.8.0+dfsg1
Diffstat (limited to 'HTMLtree.c')
-rw-r--r-- | HTMLtree.c | 106 |
1 files changed, 44 insertions, 62 deletions
@@ -30,18 +30,16 @@ #include <libxml/globals.h> #include <libxml/uri.h> -#include "buf.h" - /************************************************************************ * * - * Getting/Setting encoding meta tags * + * Getting/Setting encoding meta tags * * * ************************************************************************/ /** * htmlGetMetaEncoding: * @doc: the document - * + * * Encoding definition lookup in the Meta tags * * Returns the current encoding as flagged in the HTML source @@ -128,17 +126,17 @@ found_meta: found_content: encoding = xmlStrstr(content, BAD_CAST"charset="); - if (encoding == NULL) + if (encoding == NULL) encoding = xmlStrstr(content, BAD_CAST"Charset="); - if (encoding == NULL) + if (encoding == NULL) encoding = xmlStrstr(content, BAD_CAST"CHARSET="); if (encoding != NULL) { encoding += 8; } else { encoding = xmlStrstr(content, BAD_CAST"charset ="); - if (encoding == NULL) + if (encoding == NULL) encoding = xmlStrstr(content, BAD_CAST"Charset ="); - if (encoding == NULL) + if (encoding == NULL) encoding = xmlStrstr(content, BAD_CAST"CHARSET ="); if (encoding != NULL) encoding += 9; @@ -316,7 +314,7 @@ static const char* htmlBooleanAttrs[] = { * @name: the name of the attribute to check * * Determine if a given attribute is a boolean attribute. - * + * * returns: false if the attribute is not boolean, true otherwise. */ int @@ -340,7 +338,7 @@ xmlOutputBufferPtr xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder); /************************************************************************ * * - * Output error handlers * + * Output error handlers * * * ************************************************************************/ /** @@ -389,13 +387,17 @@ htmlSaveErr(int code, xmlNodePtr node, const char *extra) /************************************************************************ * * - * Dumping HTML tree content to a simple buffer * + * Dumping HTML tree content to a simple buffer * * * ************************************************************************/ +static int +htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, + int format); + /** - * htmlBufNodeDumpFormat: - * @buf: the xmlBufPtr output + * htmlNodeDumpFormat: + * @buf: the HTML buffer output * @doc: the document * @cur: the current node * @format: should formatting spaces been added @@ -404,10 +406,10 @@ htmlSaveErr(int code, xmlNodePtr node, const char *extra) * * Returns the number of byte written or -1 in case of error */ -static size_t -htmlBufNodeDumpFormat(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur, +static int +htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int format) { - size_t use; + unsigned int use; int ret; xmlOutputBufferPtr outbuf; @@ -430,10 +432,10 @@ htmlBufNodeDumpFormat(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur, outbuf->context = NULL; outbuf->written = 0; - use = xmlBufUse(buf); + use = buf->use; htmlNodeDumpFormatOutput(outbuf, doc, cur, NULL, format); xmlFree(outbuf); - ret = xmlBufUse(buf) - use; + ret = buf->use - use; return (ret); } @@ -450,24 +452,9 @@ htmlBufNodeDumpFormat(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur, */ int htmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur) { - xmlBufPtr buffer; - size_t ret; - - if ((buf == NULL) || (cur == NULL)) - return(-1); - xmlInitParser(); - buffer = xmlBufFromBuffer(buf); - if (buffer == NULL) - return(-1); - - ret = htmlBufNodeDumpFormat(buffer, doc, cur, 1); - - xmlBufBackToBuffer(buffer); - if (ret > INT_MAX) - return(-1); - return((int) ret); + return(htmlNodeDumpFormat(buf, doc, cur, 1)); } /** @@ -512,7 +499,7 @@ htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc, if (handler == NULL) handler = xmlFindCharEncodingHandler("ascii"); - /* + /* * save the content to a temp buffer. */ buf = xmlOutputBufferCreateFile(out, handler); @@ -608,11 +595,11 @@ htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) { xmlOutputBufferFlush(buf); if (buf->conv != NULL) { - *size = xmlBufUse(buf->conv); - *mem = xmlStrndup(xmlBufContent(buf->conv), *size); + *size = buf->conv->use; + *mem = xmlStrndup(buf->conv->content, *size); } else { - *size = xmlBufUse(buf->buffer); - *mem = xmlStrndup(xmlBufContent(buf->buffer), *size); + *size = buf->buffer->use; + *mem = xmlStrndup(buf->buffer->content, *size); } (void)xmlOutputBufferClose(buf); } @@ -634,7 +621,7 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { /************************************************************************ * * - * Dumping HTML tree content to an I/O output buffer * + * Dumping HTML tree content to an I/O output buffer * * * ************************************************************************/ @@ -645,7 +632,7 @@ void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur); * @buf: the HTML buffer output * @doc: the document * @encoding: the encoding string - * + * * TODO: check whether encoding is needed * * Dump the HTML document DTD, if any. @@ -663,14 +650,14 @@ htmlDtdDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlOutputBufferWriteString(buf, (const char *)cur->name); if (cur->ExternalID != NULL) { xmlOutputBufferWriteString(buf, " PUBLIC "); - xmlBufWriteQuotedString(buf->buffer, cur->ExternalID); + xmlBufferWriteQuotedString(buf->buffer, cur->ExternalID); if (cur->SystemID != NULL) { xmlOutputBufferWriteString(buf, " "); - xmlBufWriteQuotedString(buf->buffer, cur->SystemID); - } + xmlBufferWriteQuotedString(buf->buffer, cur->SystemID); + } } else if (cur->SystemID != NULL) { xmlOutputBufferWriteString(buf, " SYSTEM "); - xmlBufWriteQuotedString(buf->buffer, cur->SystemID); + xmlBufferWriteQuotedString(buf->buffer, cur->SystemID); } xmlOutputBufferWriteString(buf, ">\n"); } @@ -690,10 +677,9 @@ htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur, xmlChar *value; /* - * The html output method should not escape a & character - * occurring in an attribute value immediately followed by - * a { character (see Section B.7.1 of the HTML 4.0 Recommendation). - * This is implemented in xmlEncodeEntitiesReentrant + * TODO: The html output method should not escape a & character + * occurring in an attribute value immediately followed by + * a { character (see Section B.7.1 of the HTML 4.0 Recommendation). */ if (cur == NULL) { @@ -721,19 +707,15 @@ htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur, while (IS_BLANK_CH(*tmp)) tmp++; - /* - * the < and > have already been escaped at the entity level - * And doing so here breaks server side includes - */ - escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+<>"); + escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+"); if (escaped != NULL) { - xmlBufWriteQuotedString(buf->buffer, escaped); + xmlBufferWriteQuotedString(buf->buffer, escaped); xmlFree(escaped); } else { - xmlBufWriteQuotedString(buf->buffer, value); + xmlBufferWriteQuotedString(buf->buffer, value); } } else { - xmlBufWriteQuotedString(buf->buffer, value); + xmlBufferWriteQuotedString(buf->buffer, value); } xmlFree(value); } else { @@ -1123,7 +1105,7 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) { if ((cur == NULL) || (filename == NULL)) return(-1); - + xmlInitParser(); encoding = (const char *) htmlGetMetaEncoding(cur); @@ -1154,7 +1136,7 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) { if (handler == NULL) handler = xmlFindCharEncodingHandler("ascii"); - /* + /* * save the content to a temp buffer. */ buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); @@ -1174,7 +1156,7 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) { * @encoding: the document encoding * * Dump an HTML document to a file using a given encoding. - * + * * returns: the number of byte written or -1 in case of failure. */ int @@ -1218,7 +1200,7 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur, if (handler == NULL) handler = xmlFindCharEncodingHandler("ascii"); - /* + /* * save the content to a temp buffer. */ buf = xmlOutputBufferCreateFilename(filename, handler, 0); @@ -1238,7 +1220,7 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur, * * Dump an HTML document to a file using a given encoding * and formatting returns/spaces are added. - * + * * returns: the number of byte written or -1 in case of failure. */ int |