version 1.1.1.2, 2013/07/22 01:22:20
|
version 1.1.1.3, 2014/06/15 19:53:29
|
Line 30
|
Line 30
|
#include <libxml/globals.h> |
#include <libxml/globals.h> |
#include <libxml/uri.h> |
#include <libxml/uri.h> |
|
|
|
#include "buf.h" |
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Getting/Setting encoding meta tags * | * Getting/Setting encoding meta tags * |
* * |
* * |
************************************************************************/ |
************************************************************************/ |
|
|
/** |
/** |
* htmlGetMetaEncoding: |
* htmlGetMetaEncoding: |
* @doc: the document |
* @doc: the document |
* | * |
* Encoding definition lookup in the Meta tags |
* Encoding definition lookup in the Meta tags |
* |
* |
* Returns the current encoding as flagged in the HTML source |
* Returns the current encoding as flagged in the HTML source |
Line 126 found_meta:
|
Line 128 found_meta:
|
|
|
found_content: |
found_content: |
encoding = xmlStrstr(content, BAD_CAST"charset="); |
encoding = xmlStrstr(content, BAD_CAST"charset="); |
if (encoding == NULL) | if (encoding == NULL) |
encoding = xmlStrstr(content, BAD_CAST"Charset="); |
encoding = xmlStrstr(content, BAD_CAST"Charset="); |
if (encoding == NULL) | if (encoding == NULL) |
encoding = xmlStrstr(content, BAD_CAST"CHARSET="); |
encoding = xmlStrstr(content, BAD_CAST"CHARSET="); |
if (encoding != NULL) { |
if (encoding != NULL) { |
encoding += 8; |
encoding += 8; |
} else { |
} else { |
encoding = xmlStrstr(content, BAD_CAST"charset ="); |
encoding = xmlStrstr(content, BAD_CAST"charset ="); |
if (encoding == NULL) | if (encoding == NULL) |
encoding = xmlStrstr(content, BAD_CAST"Charset ="); |
encoding = xmlStrstr(content, BAD_CAST"Charset ="); |
if (encoding == NULL) | if (encoding == NULL) |
encoding = xmlStrstr(content, BAD_CAST"CHARSET ="); |
encoding = xmlStrstr(content, BAD_CAST"CHARSET ="); |
if (encoding != NULL) |
if (encoding != NULL) |
encoding += 9; |
encoding += 9; |
Line 314 static const char* htmlBooleanAttrs[] = {
|
Line 316 static const char* htmlBooleanAttrs[] = {
|
* @name: the name of the attribute to check |
* @name: the name of the attribute to check |
* |
* |
* Determine if a given attribute is a boolean attribute. |
* Determine if a given attribute is a boolean attribute. |
* | * |
* returns: false if the attribute is not boolean, true otherwise. |
* returns: false if the attribute is not boolean, true otherwise. |
*/ |
*/ |
int |
int |
Line 338 xmlOutputBufferPtr
|
Line 340 xmlOutputBufferPtr
|
xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder); |
xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder); |
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Output error handlers * | * Output error handlers * |
* * |
* * |
************************************************************************/ |
************************************************************************/ |
/** |
/** |
Line 387 htmlSaveErr(int code, xmlNodePtr node, const char *ext
|
Line 389 htmlSaveErr(int code, xmlNodePtr node, const char *ext
|
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* 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); |
|
|
|
/** |
/** |
* htmlNodeDumpFormat: | * htmlBufNodeDumpFormat: |
* @buf: the HTML buffer output | * @buf: the xmlBufPtr output |
* @doc: the document |
* @doc: the document |
* @cur: the current node |
* @cur: the current node |
* @format: should formatting spaces been added |
* @format: should formatting spaces been added |
Line 406 htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xm
|
Line 404 htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xm
|
* |
* |
* Returns the number of byte written or -1 in case of error |
* Returns the number of byte written or -1 in case of error |
*/ |
*/ |
static int | static size_t |
htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, | htmlBufNodeDumpFormat(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur, |
int format) { |
int format) { |
unsigned int use; | size_t use; |
int ret; |
int ret; |
xmlOutputBufferPtr outbuf; |
xmlOutputBufferPtr outbuf; |
|
|
Line 432 htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xm
|
Line 430 htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xm
|
outbuf->context = NULL; |
outbuf->context = NULL; |
outbuf->written = 0; |
outbuf->written = 0; |
|
|
use = buf->use; | use = xmlBufUse(buf); |
htmlNodeDumpFormatOutput(outbuf, doc, cur, NULL, format); |
htmlNodeDumpFormatOutput(outbuf, doc, cur, NULL, format); |
xmlFree(outbuf); |
xmlFree(outbuf); |
ret = buf->use - use; | ret = xmlBufUse(buf) - use; |
return (ret); |
return (ret); |
} |
} |
|
|
Line 452 htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xm
|
Line 450 htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xm
|
*/ |
*/ |
int |
int |
htmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur) { |
htmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur) { |
|
xmlBufPtr buffer; |
|
size_t ret; |
|
|
|
if ((buf == NULL) || (cur == NULL)) |
|
return(-1); |
|
|
xmlInitParser(); |
xmlInitParser(); |
|
buffer = xmlBufFromBuffer(buf); |
|
if (buffer == NULL) |
|
return(-1); |
|
|
return(htmlNodeDumpFormat(buf, doc, cur, 1)); | ret = htmlBufNodeDumpFormat(buffer, doc, cur, 1); |
| |
| xmlBufBackToBuffer(buffer); |
| |
| if (ret > INT_MAX) |
| return(-1); |
| return((int) ret); |
} |
} |
|
|
/** |
/** |
Line 499 htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc,
|
Line 512 htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc,
|
if (handler == NULL) |
if (handler == NULL) |
handler = xmlFindCharEncodingHandler("ascii"); |
handler = xmlFindCharEncodingHandler("ascii"); |
|
|
/* | /* |
* save the content to a temp buffer. |
* save the content to a temp buffer. |
*/ |
*/ |
buf = xmlOutputBufferCreateFile(out, handler); |
buf = xmlOutputBufferCreateFile(out, handler); |
Line 595 htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, i
|
Line 608 htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, i
|
|
|
xmlOutputBufferFlush(buf); |
xmlOutputBufferFlush(buf); |
if (buf->conv != NULL) { |
if (buf->conv != NULL) { |
*size = buf->conv->use; | *size = xmlBufUse(buf->conv); |
*mem = xmlStrndup(buf->conv->content, *size); | *mem = xmlStrndup(xmlBufContent(buf->conv), *size); |
} else { |
} else { |
*size = buf->buffer->use; | *size = xmlBufUse(buf->buffer); |
*mem = xmlStrndup(buf->buffer->content, *size); | *mem = xmlStrndup(xmlBufContent(buf->buffer), *size); |
} |
} |
(void)xmlOutputBufferClose(buf); |
(void)xmlOutputBufferClose(buf); |
} |
} |
Line 621 htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *si
|
Line 634 htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *si
|
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Dumping HTML tree content to an I/O output buffer * | * Dumping HTML tree content to an I/O output buffer * |
* * |
* * |
************************************************************************/ |
************************************************************************/ |
|
|
Line 632 void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNs
|
Line 645 void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNs
|
* @buf: the HTML buffer output |
* @buf: the HTML buffer output |
* @doc: the document |
* @doc: the document |
* @encoding: the encoding string |
* @encoding: the encoding string |
* | * |
* TODO: check whether encoding is needed |
* TODO: check whether encoding is needed |
* |
* |
* Dump the HTML document DTD, if any. |
* Dump the HTML document DTD, if any. |
Line 650 htmlDtdDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr do
|
Line 663 htmlDtdDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr do
|
xmlOutputBufferWriteString(buf, (const char *)cur->name); |
xmlOutputBufferWriteString(buf, (const char *)cur->name); |
if (cur->ExternalID != NULL) { |
if (cur->ExternalID != NULL) { |
xmlOutputBufferWriteString(buf, " PUBLIC "); |
xmlOutputBufferWriteString(buf, " PUBLIC "); |
xmlBufferWriteQuotedString(buf->buffer, cur->ExternalID); | xmlBufWriteQuotedString(buf->buffer, cur->ExternalID); |
if (cur->SystemID != NULL) { |
if (cur->SystemID != NULL) { |
xmlOutputBufferWriteString(buf, " "); |
xmlOutputBufferWriteString(buf, " "); |
xmlBufferWriteQuotedString(buf->buffer, cur->SystemID); | xmlBufWriteQuotedString(buf->buffer, cur->SystemID); |
} | } |
} else if (cur->SystemID != NULL) { |
} else if (cur->SystemID != NULL) { |
xmlOutputBufferWriteString(buf, " SYSTEM "); |
xmlOutputBufferWriteString(buf, " SYSTEM "); |
xmlBufferWriteQuotedString(buf->buffer, cur->SystemID); | xmlBufWriteQuotedString(buf->buffer, cur->SystemID); |
} |
} |
xmlOutputBufferWriteString(buf, ">\n"); |
xmlOutputBufferWriteString(buf, ">\n"); |
} |
} |
Line 677 htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr d
|
Line 690 htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr d
|
xmlChar *value; |
xmlChar *value; |
|
|
/* |
/* |
* TODO: The html output method should not escape a & character | * The html output method should not escape a & character |
* occurring in an attribute value immediately followed by | * occurring in an attribute value immediately followed by |
* a { character (see Section B.7.1 of the HTML 4.0 Recommendation). | * a { character (see Section B.7.1 of the HTML 4.0 Recommendation). |
| * This is implemented in xmlEncodeEntitiesReentrant |
*/ |
*/ |
|
|
if (cur == NULL) { |
if (cur == NULL) { |
Line 707 htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr d
|
Line 721 htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr d
|
|
|
while (IS_BLANK_CH(*tmp)) tmp++; |
while (IS_BLANK_CH(*tmp)) tmp++; |
|
|
escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+"); | /* |
| * the < and > have already been escaped at the entity level |
| * And doing so here breaks server side includes |
| */ |
| escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+<>"); |
if (escaped != NULL) { |
if (escaped != NULL) { |
xmlBufferWriteQuotedString(buf->buffer, escaped); | xmlBufWriteQuotedString(buf->buffer, escaped); |
xmlFree(escaped); |
xmlFree(escaped); |
} else { |
} else { |
xmlBufferWriteQuotedString(buf->buffer, value); | xmlBufWriteQuotedString(buf->buffer, value); |
} |
} |
} else { |
} else { |
xmlBufferWriteQuotedString(buf->buffer, value); | xmlBufWriteQuotedString(buf->buffer, value); |
} |
} |
xmlFree(value); |
xmlFree(value); |
} else { |
} else { |
Line 1105 htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
Line 1123 htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
|
|
if ((cur == NULL) || (filename == NULL)) |
if ((cur == NULL) || (filename == NULL)) |
return(-1); |
return(-1); |
| |
xmlInitParser(); |
xmlInitParser(); |
|
|
encoding = (const char *) htmlGetMetaEncoding(cur); |
encoding = (const char *) htmlGetMetaEncoding(cur); |
Line 1136 htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
Line 1154 htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
if (handler == NULL) |
if (handler == NULL) |
handler = xmlFindCharEncodingHandler("ascii"); |
handler = xmlFindCharEncodingHandler("ascii"); |
|
|
/* | /* |
* save the content to a temp buffer. |
* save the content to a temp buffer. |
*/ |
*/ |
buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); |
buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); |
Line 1156 htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
Line 1174 htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
* @encoding: the document encoding |
* @encoding: the document encoding |
* |
* |
* Dump an HTML document to a file using a given encoding. |
* Dump an HTML document to a file using a given encoding. |
* | * |
* returns: the number of byte written or -1 in case of failure. |
* returns: the number of byte written or -1 in case of failure. |
*/ |
*/ |
int |
int |
Line 1200 htmlSaveFileFormat(const char *filename, xmlDocPtr cur
|
Line 1218 htmlSaveFileFormat(const char *filename, xmlDocPtr cur
|
if (handler == NULL) |
if (handler == NULL) |
handler = xmlFindCharEncodingHandler("ascii"); |
handler = xmlFindCharEncodingHandler("ascii"); |
|
|
/* | /* |
* save the content to a temp buffer. |
* save the content to a temp buffer. |
*/ |
*/ |
buf = xmlOutputBufferCreateFilename(filename, handler, 0); |
buf = xmlOutputBufferCreateFilename(filename, handler, 0); |
Line 1220 htmlSaveFileFormat(const char *filename, xmlDocPtr cur
|
Line 1238 htmlSaveFileFormat(const char *filename, xmlDocPtr cur
|
* |
* |
* Dump an HTML document to a file using a given encoding |
* Dump an HTML document to a file using a given encoding |
* and formatting returns/spaces are added. |
* and formatting returns/spaces are added. |
* | * |
* returns: the number of byte written or -1 in case of failure. |
* returns: the number of byte written or -1 in case of failure. |
*/ |
*/ |
int |
int |