--- embedaddon/php/ext/dom/document.c 2012/02/21 23:47:54 1.1 +++ embedaddon/php/ext/dom/document.c 2014/06/15 20:03:42 1.1.1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: document.c,v 1.1 2012/02/21 23:47:54 misho Exp $ */ +/* $Id: document.c,v 1.1.1.4 2014/06/15 20:03:42 misho Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -149,10 +149,12 @@ ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtml, 0, 0, 1) ZEND_ARG_INFO(0, source) + ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtmlfile, 0, 0, 1) ZEND_ARG_INFO(0, source) + ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0) @@ -259,7 +261,7 @@ int dom_document_doctype_read(dom_object *obj, zval ** return SUCCESS; } - if (NULL == (*retval = php_dom_create_object((xmlNodePtr) dtdptr, &ret, NULL, *retval, obj TSRMLS_CC))) { + if (NULL == (*retval = php_dom_create_object((xmlNodePtr) dtdptr, &ret, *retval, obj TSRMLS_CC))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object"); return FAILURE; } @@ -309,7 +311,7 @@ int dom_document_document_element_read(dom_object *obj return SUCCESS; } - if (NULL == (*retval = php_dom_create_object(root, &ret, NULL, *retval, obj TSRMLS_CC))) { + if (NULL == (*retval = php_dom_create_object(root, &ret, *retval, obj TSRMLS_CC))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object"); return FAILURE; } @@ -899,7 +901,7 @@ Since: */ PHP_FUNCTION(dom_document_create_element) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp; dom_object *intern; @@ -922,7 +924,7 @@ PHP_FUNCTION(dom_document_create_element) RETURN_FALSE; } - DOM_RET_OBJ(rv, node, &ret, intern); + DOM_RET_OBJ(node, &ret, intern); } /* }}} end dom_document_create_element */ @@ -932,7 +934,7 @@ Since: */ PHP_FUNCTION(dom_document_create_document_fragment) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp; dom_object *intern; @@ -949,7 +951,7 @@ PHP_FUNCTION(dom_document_create_document_fragment) RETURN_FALSE; } - DOM_RET_OBJ(rv, node, &ret, intern); + DOM_RET_OBJ(node, &ret, intern); } /* }}} end dom_document_create_document_fragment */ @@ -959,7 +961,7 @@ Since: */ PHP_FUNCTION(dom_document_create_text_node) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp; int ret, value_len; @@ -977,7 +979,7 @@ PHP_FUNCTION(dom_document_create_text_node) RETURN_FALSE; } - DOM_RET_OBJ(rv, node, &ret, intern); + DOM_RET_OBJ(node, &ret, intern); } /* }}} end dom_document_create_text_node */ @@ -987,7 +989,7 @@ Since: */ PHP_FUNCTION(dom_document_create_comment) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp; int ret, value_len; @@ -1005,7 +1007,7 @@ PHP_FUNCTION(dom_document_create_comment) RETURN_FALSE; } - DOM_RET_OBJ(rv, node, &ret, intern); + DOM_RET_OBJ(node, &ret, intern); } /* }}} end dom_document_create_comment */ @@ -1015,7 +1017,7 @@ Since: */ PHP_FUNCTION(dom_document_create_cdatasection) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp; int ret, value_len; @@ -1033,7 +1035,7 @@ PHP_FUNCTION(dom_document_create_cdatasection) RETURN_FALSE; } - DOM_RET_OBJ(rv, node, &ret, intern); + DOM_RET_OBJ(node, &ret, intern); } /* }}} end dom_document_create_cdatasection */ @@ -1043,7 +1045,7 @@ Since: */ PHP_FUNCTION(dom_document_create_processing_instruction) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp; int ret, value_len, name_len = 0; @@ -1068,7 +1070,7 @@ PHP_FUNCTION(dom_document_create_processing_instructio node->doc = docp; - DOM_RET_OBJ(rv, node, &ret, intern); + DOM_RET_OBJ(node, &ret, intern); } /* }}} end dom_document_create_processing_instruction */ @@ -1078,7 +1080,7 @@ Since: */ PHP_FUNCTION(dom_document_create_attribute) { - zval *id, *rv = NULL; + zval *id; xmlAttrPtr node; xmlDocPtr docp; int ret, name_len; @@ -1101,7 +1103,7 @@ PHP_FUNCTION(dom_document_create_attribute) RETURN_FALSE; } - DOM_RET_OBJ(rv, (xmlNodePtr) node, &ret, intern); + DOM_RET_OBJ((xmlNodePtr) node, &ret, intern); } /* }}} end dom_document_create_attribute */ @@ -1112,7 +1114,7 @@ Since: */ PHP_FUNCTION(dom_document_create_entity_reference) { - zval *id, *rv = NULL; + zval *id; xmlNode *node; xmlDocPtr docp = NULL; dom_object *intern; @@ -1135,7 +1137,7 @@ PHP_FUNCTION(dom_document_create_entity_reference) RETURN_FALSE; } - DOM_RET_OBJ(rv, (xmlNodePtr) node, &ret, intern); + DOM_RET_OBJ((xmlNodePtr) node, &ret, intern); } /* }}} end dom_document_create_entity_reference */ @@ -1171,7 +1173,6 @@ Since: DOM Level 2 */ PHP_FUNCTION(dom_document_import_node) { - zval *rv = NULL; zval *id, *node; xmlDocPtr docp; xmlNodePtr nodep, retnodep; @@ -1211,13 +1212,13 @@ PHP_FUNCTION(dom_document_import_node) nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href); if (nsptr == NULL) { int errorcode; - nsptr = dom_get_ns(root, nodep->ns->href, &errorcode, nodep->ns->prefix); + nsptr = dom_get_ns(root, (char *) nodep->ns->href, &errorcode, (char *) nodep->ns->prefix); } xmlSetNs(retnodep, nsptr); } } - DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret, intern); + DOM_RET_OBJ((xmlNodePtr) retnodep, &ret, intern); } /* }}} end dom_document_import_node */ @@ -1227,7 +1228,7 @@ Since: DOM Level 2 */ PHP_FUNCTION(dom_document_create_element_ns) { - zval *id, *rv = NULL; + zval *id; xmlDocPtr docp; xmlNodePtr nodep = NULL; xmlNsPtr nsptr = NULL; @@ -1280,7 +1281,7 @@ PHP_FUNCTION(dom_document_create_element_ns) nodep->ns = nsptr; - DOM_RET_OBJ(rv, nodep, &ret, intern); + DOM_RET_OBJ(nodep, &ret, intern); } /* }}} end dom_document_create_element_ns */ @@ -1290,7 +1291,7 @@ Since: DOM Level 2 */ PHP_FUNCTION(dom_document_create_attribute_ns) { - zval *id, *rv = NULL; + zval *id; xmlDocPtr docp; xmlNodePtr nodep = NULL, root; xmlNsPtr nsptr; @@ -1345,7 +1346,7 @@ PHP_FUNCTION(dom_document_create_attribute_ns) RETURN_FALSE; } - DOM_RET_OBJ(rv, nodep, &ret, intern); + DOM_RET_OBJ(nodep, &ret, intern); } /* }}} end dom_document_create_attribute_ns */ @@ -1382,7 +1383,7 @@ Since: DOM Level 2 */ PHP_FUNCTION(dom_document_get_element_by_id) { - zval *id, *rv = NULL; + zval *id; xmlDocPtr docp; xmlAttrPtr attrp; int ret, idname_len; @@ -1398,7 +1399,7 @@ PHP_FUNCTION(dom_document_get_element_by_id) attrp = xmlGetID(docp, (xmlChar *) idname); if (attrp && attrp->parent) { - DOM_RET_OBJ(rv, (xmlNodePtr) attrp->parent, &ret, intern); + DOM_RET_OBJ((xmlNodePtr) attrp->parent, &ret, intern); } else { RETVAL_NULL(); } @@ -1508,6 +1509,12 @@ char *_dom_get_valid_file_path(char *source, char *res if (uri->scheme != NULL) { /* absolute file uris - libxml only supports localhost or empty host */ +#ifdef PHP_WIN32 + if (strncasecmp(source, "file://",7) == 0 && ':' == source[8]) { + isFileUri = 1; + source += 7; + } else +#endif if (strncasecmp(source, "file:///",8) == 0) { isFileUri = 1; #ifdef PHP_WIN32 @@ -1660,7 +1667,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mod /* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) { - zval *id, *rv = NULL; + zval *id; xmlDoc *docp = NULL, *newdoc; dom_doc_propsptr doc_prop; dom_object *intern; @@ -1712,7 +1719,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAM RETURN_TRUE; } else { - DOM_RET_OBJ(rv, (xmlNodePtr) newdoc, &ret, NULL); + DOM_RET_OBJ((xmlNodePtr) newdoc, &ret, NULL); } } /* }}} end dom_parser_document */ @@ -1979,7 +1986,7 @@ static void _dom_document_schema_validate(INTERNAL_FUN int is_valid; char resolved_path[MAXPATHLEN + 1]; - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op", &id, dom_document_class_entry, &source, &source_len) == FAILURE) { return; } @@ -2068,7 +2075,7 @@ static void _dom_document_relaxNG_validate(INTERNAL_FU int is_valid; char resolved_path[MAXPATHLEN + 1]; - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op", &id, dom_document_class_entry, &source, &source_len) == FAILURE) { return; } @@ -2150,17 +2157,18 @@ PHP_FUNCTION(dom_document_relaxNG_validate_xml) static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */ { - zval *id, *rv = NULL; + zval *id; xmlDoc *docp = NULL, *newdoc; dom_object *intern; dom_doc_propsptr doc_prop; char *source; int source_len, refcount, ret; + long options = 0; htmlParserCtxtPtr ctxt; id = getThis(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &options) == FAILURE) { return; } @@ -2180,6 +2188,10 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS RETURN_FALSE; } + if (options) { + htmlCtxtUseOptions(ctxt, options); + } + ctxt->vctxt.error = php_libxml_ctx_error; ctxt->vctxt.warning = php_libxml_ctx_warning; if (ctxt->sax != NULL) { @@ -2218,7 +2230,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS RETURN_TRUE; } else { - DOM_RET_OBJ(rv, (xmlNodePtr) newdoc, &ret, NULL); + DOM_RET_OBJ((xmlNodePtr) newdoc, &ret, NULL); } } /* }}} */ @@ -2290,7 +2302,7 @@ PHP_FUNCTION(dom_document_save_html) xmlBufferPtr buf; dom_object *intern, *nodeobj; xmlChar *mem = NULL; - int size, format; + int size = 0, format; dom_doc_propsptr doc_props; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), @@ -2318,7 +2330,22 @@ PHP_FUNCTION(dom_document_save_html) RETURN_FALSE; } - size = htmlNodeDump(buf, docp, node); + if (node->type == XML_DOCUMENT_FRAG_NODE) { + int one_size; + + for (node = node->children; node; node = node->next) { + one_size = htmlNodeDump(buf, docp, node); + + if (one_size >= 0) { + size += one_size; + } else { + size = -1; + break; + } + } + } else { + size = htmlNodeDump(buf, docp, node); + } if (size >= 0) { mem = (xmlChar*) xmlBufferContent(buf); if (!mem) {