allow certain methods to be called statically again:

domdocument (all load methods)
   domimplementation (all methods)
switch to zend_parse_method_parameters for consistancy
insure object parameters are correct class types
convert zvals to correct type if needed for property writes
fix a few segfaults found while testing
This commit is contained in:
Rob Richards 2004-02-15 17:07:34 +00:00
parent b59989e716
commit c3a57206cc
6 changed files with 280 additions and 100 deletions

View File

@ -66,16 +66,16 @@ zend_function_entry php_dom_document_class_functions[] = {
PHP_FALIAS(adoptNode, dom_document_adopt_node, NULL)
PHP_FALIAS(normalizeDocument, dom_document_normalize_document, NULL)
PHP_FALIAS(renameNode, dom_document_rename_node, NULL)
PHP_FALIAS(load, dom_document_load, NULL)
PHP_ME(domdocument, load, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_FALIAS(save, dom_document_save, NULL)
PHP_FALIAS(loadXML, dom_document_loadxml, NULL)
PHP_ME(domdocument, loadXML, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_FALIAS(saveXML, dom_document_savexml, NULL)
PHP_FALIAS(domdocument, dom_document_document, NULL)
PHP_FALIAS(validate, dom_document_validate, NULL)
PHP_FALIAS(xinclude, dom_document_xinclude, NULL)
#if defined(LIBXML_HTML_ENABLED)
PHP_FALIAS(loadHTML, dom_document_load_html, NULL)
PHP_FALIAS(loadHTMLFile, dom_document_load_html_file, NULL)
PHP_ME(domdocument, loadHTML, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domdocument, loadHTMLFile, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_FALIAS(saveHTML, dom_document_save_html, NULL)
PHP_FALIAS(saveHTMLFile, dom_document_save_html_file, NULL)
#endif /* defined(LIBXML_HTML_ENABLED) */
@ -209,11 +209,21 @@ int dom_document_encoding_read(dom_object *obj, zval **retval TSRMLS_DC)
int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
xmlDoc *docp;
xmlCharEncodingHandlerPtr handler;
docp = (xmlDocPtr) dom_object_get_node(obj);
if (newval->type != IS_STRING) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_string(newval);
}
handler = xmlFindCharEncodingHandler(Z_STRVAL_P(newval));
if (handler != NULL) {
@ -222,11 +232,14 @@ int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
xmlFree((xmlChar *)docp->encoding);
}
docp->encoding = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
return SUCCESS;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Document Encoding");
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
@ -254,10 +267,19 @@ int dom_document_standalone_read(dom_object *obj, zval **retval TSRMLS_DC)
int dom_document_standalone_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
xmlDoc *docp;
int standalone;
docp = (xmlDocPtr) dom_object_get_node(obj);
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_long(newval);
standalone = Z_LVAL_P(newval);
if (standalone > 0) {
docp->standalone = 1;
@ -269,6 +291,10 @@ int dom_document_standalone_write(dom_object *obj, zval *newval TSRMLS_DC)
docp->standalone = 0;
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
@ -301,6 +327,7 @@ int dom_document_version_read(dom_object *obj, zval **retval TSRMLS_DC)
int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
xmlDoc *docp;
docp = (xmlDocPtr) dom_object_get_node(obj);
@ -308,8 +335,21 @@ int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC)
xmlFree((xmlChar *) docp->version );
}
if (newval->type != IS_STRING) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_string(newval);
}
docp->version = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
@ -336,13 +376,25 @@ int dom_document_strict_error_checking_read(dom_object *obj, zval **retval TSRML
int dom_document_strict_error_checking_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
dom_doc_props *doc_prop;
if (obj->document && newval->type == IS_BOOL) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_boolean(newval);
if (obj->document) {
doc_prop = dom_get_doc_props(obj->document);
doc_prop->stricterror = Z_LVAL_P(newval);
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
@ -367,13 +419,25 @@ int dom_document_format_output_read(dom_object *obj, zval **retval TSRMLS_DC)
int dom_document_format_output_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
dom_doc_props *doc_prop;
if (obj->document && newval->type == IS_BOOL) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_boolean(newval);
if (obj->document) {
doc_prop = dom_get_doc_props(obj->document);
doc_prop->formatoutput = Z_LVAL_P(newval);
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
/* }}} */
@ -397,13 +461,25 @@ int dom_document_validate_on_parse_read(dom_object *obj, zval **retval TSRMLS_DC
int dom_document_validate_on_parse_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
dom_doc_props *doc_prop;
if (obj->document && newval->type == IS_BOOL) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_boolean(newval);
if (obj->document) {
doc_prop = dom_get_doc_props(obj->document);
doc_prop->validateonparse = Z_LVAL_P(newval);
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
/* }}} */
@ -428,13 +504,25 @@ int dom_document_resolve_externals_read(dom_object *obj, zval **retval TSRMLS_DC
int dom_document_resolve_externals_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
dom_doc_props *doc_prop;
if (obj->document && newval->type == IS_BOOL) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_boolean(newval);
if (obj->document) {
doc_prop = dom_get_doc_props(obj->document);
doc_prop->resolveexternals = Z_LVAL_P(newval);
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
/* }}} */
@ -459,13 +547,25 @@ int dom_document_preserve_whitespace_read(dom_object *obj, zval **retval TSRMLS_
int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
dom_doc_props *doc_prop;
if (obj->document && newval->type == IS_BOOL) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_boolean(newval);
if (obj->document) {
doc_prop = dom_get_doc_props(obj->document);
doc_prop->preservewhitespace = Z_LVAL_P(newval);
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
/* }}} */
@ -490,13 +590,25 @@ int dom_document_substitue_entities_read(dom_object *obj, zval **retval TSRMLS_D
int dom_document_substitue_entities_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
dom_doc_props *doc_prop;
if (obj->document && newval->type == IS_BOOL) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_boolean(newval);
if (obj->document) {
doc_prop = dom_get_doc_props(obj->document);
doc_prop->substituteentities = Z_LVAL_P(newval);
}
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
/* }}} */
@ -527,6 +639,7 @@ int dom_document_document_uri_read(dom_object *obj, zval **retval TSRMLS_DC)
int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC)
{
zval value_copy;
xmlDoc *docp;
docp = (xmlDocPtr) dom_object_get_node(obj);
@ -534,8 +647,21 @@ int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC)
xmlFree((xmlChar *) docp->URL);
}
if (newval->type != IS_STRING) {
if(newval->refcount > 1) {
value_copy = *newval;
zval_copy_ctor(&value_copy);
newval = &value_copy;
}
convert_to_string(newval);
}
docp->URL = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
if (newval == &value_copy) {
zval_dtor(newval);
}
return SUCCESS;
}
@ -572,12 +698,17 @@ PHP_FUNCTION(dom_document_create_element)
int ret, name_len, value_len;
char *name, *value = NULL;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
if (name_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Element name is required");
RETURN_FALSE;
}
node = xmlNewDocNode(docp, NULL, name, value);
if (!node) {
RETURN_FALSE;
@ -600,7 +731,11 @@ PHP_FUNCTION(dom_document_create_document_fragment)
dom_object *intern;
int ret;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
node = xmlNewDocFragment(docp);
if (!node) {
@ -625,12 +760,12 @@ PHP_FUNCTION(dom_document_create_text_node)
dom_object *intern;
char *value;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
node = xmlNewDocText(docp, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
@ -654,12 +789,12 @@ PHP_FUNCTION(dom_document_create_comment)
dom_object *intern;
char *value;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
node = xmlNewDocComment(docp, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
@ -683,12 +818,12 @@ PHP_FUNCTION(dom_document_create_cdatasection)
dom_object *intern;
char *value;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
node = xmlNewCDataBlock(docp, (xmlChar *) value, value_len);
if (!node) {
RETURN_FALSE;
@ -708,16 +843,16 @@ PHP_FUNCTION(dom_document_create_processing_instruction)
zval *id, *rv = NULL;
xmlNode *node;
xmlDocPtr docp;
int ret, value_len, name_len;
int ret, value_len, name_len = 0;
dom_object *intern;
char *name, *value = NULL;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
@ -743,12 +878,12 @@ PHP_FUNCTION(dom_document_create_attribute)
dom_object *intern;
char *name;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
if (name_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name is required");
RETURN_FALSE;
@ -778,12 +913,12 @@ PHP_FUNCTION(dom_document_create_entity_reference)
int ret, name_len;
char *name;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
node = xmlNewReference(docp, name);
if (!node) {
RETURN_FALSE;
@ -807,12 +942,12 @@ PHP_FUNCTION(dom_document_get_elements_by_tag_name)
char *name;
xmlChar *local;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
local = xmlCharStrndup(name, name_len);
@ -835,12 +970,12 @@ PHP_FUNCTION(dom_document_import_node)
int ret;
long recursive = 0;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|l", &node, &recursive) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO|l", &id, dom_document_class_entry, &node, dom_node_class_entry, &recursive) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
DOM_GET_OBJ(nodep, node, xmlNodePtr, nodeobj);
if (nodep->type == XML_HTML_DOCUMENT_NODE || nodep->type == XML_DOCUMENT_NODE
@ -879,12 +1014,19 @@ PHP_FUNCTION(dom_document_create_element_ns)
int errorcode;
dom_object *intern;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
return;
}
if (name_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Element Name is required");
RETURN_FALSE;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
if (errorcode == 0) {
@ -939,12 +1081,17 @@ PHP_FUNCTION(dom_document_create_attribute_ns)
dom_object *intern;
int errorcode;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
return;
}
if (name_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Qualified Name is required");
RETURN_FALSE;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
root = xmlDocGetRootElement(docp);
if (root != NULL) {
errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
@ -998,12 +1145,12 @@ PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns)
char *uri, *name;
xmlChar *local, *nsuri;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
local = xmlCharStrndup(name, name_len);
@ -1026,11 +1173,12 @@ PHP_FUNCTION(dom_document_get_element_by_id)
dom_object *intern;
char *idname;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &idname, &idname_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &idname, &idname_len) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
attrp = xmlGetID(docp, (xmlChar *) idname);
if (attrp && attrp->parent) {
@ -1064,9 +1212,11 @@ PHP_FUNCTION(dom_document_normalize_document)
xmlDocPtr docp;
dom_object *intern;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
return;
}
DOM_NO_ARGS();
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
dom_normalize((xmlNodePtr) docp TSRMLS_CC);
}
@ -1092,7 +1242,7 @@ PHP_FUNCTION(dom_document_document)
dom_object *intern;
char *encoding, *version = NULL;
int encoding_len = 0, version_len = 0, refcount;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ss", &id, dom_document_class_entry, &version, &version_len, &encoding, &encoding_len) == FAILURE) {
return;
}
@ -1328,7 +1478,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
Since: DOM Level 3
*/
PHP_FUNCTION(dom_document_load)
PHP_METHOD(domdocument, load)
{
dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
}
@ -1338,7 +1488,7 @@ PHP_FUNCTION(dom_document_load)
URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-loadXML
Since: DOM Level 3
*/
PHP_FUNCTION(dom_document_loadxml)
PHP_METHOD(domdocument, loadXML)
{
dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
}
@ -1351,17 +1501,22 @@ PHP_FUNCTION(dom_document_save)
{
zval *id;
xmlDoc *docp;
int file_len, bytes, format;
int file_len = 0, bytes, format;
dom_object *intern;
dom_doc_props *doc_props;
char *file;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
return;
}
if (file_len == 0) {
php_error(E_WARNING, "Invalid Filename");
RETURN_FALSE;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
/* encoding handled by property on doc */
doc_props = dom_get_doc_props(intern->document);
@ -1390,12 +1545,12 @@ PHP_FUNCTION(dom_document_savexml)
dom_doc_props *doc_props;
int size, format;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|o", &nodep) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O", &id, dom_document_class_entry, &nodep, dom_node_class_entry) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
doc_props = dom_get_doc_props(intern->document);
format = doc_props->formatoutput;
@ -1475,7 +1630,11 @@ PHP_FUNCTION(dom_document_xinclude)
int err;
dom_object *intern;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
err = xmlXIncludeProcess (docp);
@ -1509,8 +1668,12 @@ PHP_FUNCTION(dom_document_validate)
xmlDoc *docp;
dom_object *intern;
xmlValidCtxt *cvp;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
if (docp->intSubset == NULL) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "No DTD given in XML-Document");
@ -1548,11 +1711,16 @@ _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
int is_valid;
char resolved_path[MAXPATHLEN + 1];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
return;
}
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (source_len == 0) {
php_error(E_WARNING, "Invalid Schema source");
RETURN_FALSE;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
switch (type) {
case DOM_LOAD_FILE:
@ -1633,11 +1801,16 @@ _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
int is_valid;
char resolved_path[MAXPATHLEN + 1];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
return;
}
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (source_len == 0) {
php_error(E_WARNING, "Invalid Schema source");
RETURN_FALSE;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
switch (type) {
case DOM_LOAD_FILE:
@ -1782,7 +1955,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode)
/* {{{ proto boolean domnode dom_document_load_html_file(string source);
Since: DOM extended
*/
PHP_FUNCTION(dom_document_load_html_file)
PHP_METHOD(domdocument, loadHTMLFile)
{
dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
}
@ -1791,7 +1964,7 @@ PHP_FUNCTION(dom_document_load_html_file)
/* {{{ proto boolean domnode dom_document_load_html(string source);
Since: DOM extended
*/
PHP_FUNCTION(dom_document_load_html)
PHP_METHOD(domdocument, loadHTML)
{
dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
}
@ -1809,12 +1982,17 @@ PHP_FUNCTION(dom_document_save_html_file)
dom_doc_props *doc_props;
char *file;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
return;
}
if (file_len == 0) {
php_error(E_WARNING, "Invalid Filename");
RETURN_FALSE;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
/* encoding handled by property on doc */
doc_props = dom_get_doc_props(intern->document);
@ -1839,7 +2017,11 @@ PHP_FUNCTION(dom_document_save_html)
xmlChar *mem;
int size;
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
return;
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
htmlDocDumpMemory(docp, &mem, &size);
if (!size) {

View File

@ -154,7 +154,7 @@ int dom_documenttype_system_id_read(dom_object *obj, zval **retval TSRMLS_DC)
ALLOC_ZVAL(*retval);
if (dtdptr->SystemID) {
ZVAL_STRING(*retval, (char *) (dtdptr->ExternalID), 1);
ZVAL_STRING(*retval, (char *) (dtdptr->SystemID), 1);
} else {
ZVAL_EMPTY_STRING(*retval);
}

View File

@ -93,10 +93,10 @@ PHP_FUNCTION(dom_domimplementationsource_get_domimplementation);
PHP_FUNCTION(dom_domimplementationsource_get_domimplementations);
/* domimplementation methods */
PHP_FUNCTION(dom_domimplementation_has_feature);
PHP_FUNCTION(dom_domimplementation_create_document_type);
PHP_FUNCTION(dom_domimplementation_create_document);
PHP_FUNCTION(dom_domimplementation_get_feature);
PHP_METHOD(domimplementation, hasFeature);
PHP_METHOD(domimplementation, createDocumentType);
PHP_METHOD(domimplementation, createDocument);
PHP_METHOD(domimplementation, getFeature);
/* domdocumentfragment methods */
PHP_FUNCTION(dom_documentfragment_documentfragment);
@ -121,16 +121,16 @@ PHP_FUNCTION(dom_document_normalize_document);
PHP_FUNCTION(dom_document_rename_node);
PHP_FUNCTION(dom_document_document);
/* convienience methods */
PHP_FUNCTION(dom_document_load);
PHP_METHOD(domdocument, load);
PHP_FUNCTION(dom_document_save);
PHP_FUNCTION(dom_document_loadxml);
PHP_METHOD(domdocument, loadXML);
PHP_FUNCTION(dom_document_savexml);
PHP_FUNCTION(dom_document_validate);
PHP_FUNCTION(dom_document_xinclude);
#if defined(LIBXML_HTML_ENABLED)
PHP_FUNCTION(dom_document_load_html);
PHP_FUNCTION(dom_document_load_html_file);
PHP_METHOD(domdocument, loadHTML);
PHP_METHOD(domdocument, loadHTMLFile);
PHP_FUNCTION(dom_document_save_html);
PHP_FUNCTION(dom_document_save_html_file);
#endif /* defined(LIBXML_HTML_ENABLED) */

View File

@ -35,10 +35,10 @@
*/
zend_function_entry php_dom_domimplementation_class_functions[] = {
PHP_FALIAS(hasFeature, dom_domimplementation_has_feature, NULL)
PHP_FALIAS(createDocumentType, dom_domimplementation_create_document_type, NULL)
PHP_FALIAS(createDocument, dom_domimplementation_create_document, NULL)
PHP_FALIAS(getFeature, dom_domimplementation_get_feature, NULL)
PHP_ME(domimplementation, getFeature, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domimplementation, hasFeature, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domimplementation, createDocumentType, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domimplementation, createDocument, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
{NULL, NULL, NULL}
};
@ -49,7 +49,7 @@ zend_function_entry php_dom_domimplementation_class_functions[] = {
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-5CED94D7
Since:
*/
PHP_FUNCTION(dom_domimplementation_has_feature)
PHP_METHOD(domimplementation, hasFeature)
{
int feature_len, version_len;
char *feature, *version;
@ -71,11 +71,11 @@ PHP_FUNCTION(dom_domimplementation_has_feature)
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocType
Since: DOM Level 2
*/
PHP_FUNCTION(dom_domimplementation_create_document_type)
PHP_METHOD(domimplementation, createDocumentType)
{
zval *rv = NULL;
xmlDtd *doctype;
int ret, name_len, publicid_len, systemid_len;
int ret, name_len = 0, publicid_len = 0, systemid_len = 0;
char *name, *publicid, *systemid;
xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
xmlURIPtr uri;
@ -125,7 +125,7 @@ PHP_FUNCTION(dom_domimplementation_create_document_type)
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocument
Since: DOM Level 2
*/
PHP_FUNCTION(dom_domimplementation_create_document)
PHP_METHOD(domimplementation, createDocument)
{
zval *node = NULL, *rv = NULL;
xmlDoc *docp;
@ -137,7 +137,7 @@ PHP_FUNCTION(dom_domimplementation_create_document)
char *prefix = NULL, *localname = NULL;
dom_object *doctobj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sso", &uri, &uri_len, &name, &name_len, &node) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssO", &uri, &uri_len, &name, &name_len, &node, dom_documenttype_class_entry) == FAILURE) {
return;
}
@ -228,7 +228,7 @@ PHP_FUNCTION(dom_domimplementation_create_document)
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementation3-getFeature
Since: DOM Level 3
*/
PHP_FUNCTION(dom_domimplementation_get_feature)
PHP_METHOD(domimplementation, getFeature)
{
DOM_NOT_IMPLEMENTED();
}

View File

@ -758,7 +758,6 @@ void dom_objects_free_storage(void *object TSRMLS_DC)
if (intern->ptr != NULL && ((php_libxml_node_ptr *)intern->ptr)->node != NULL) {
if (((xmlNodePtr) ((php_libxml_node_ptr *)intern->ptr)->node)->type != XML_DOCUMENT_NODE && ((xmlNodePtr) ((php_libxml_node_ptr *)intern->ptr)->node)->type != XML_HTML_DOCUMENT_NODE) {
// php_libxml_node_free_resource(dom_object_get_node(intern) TSRMLS_CC);
php_libxml_node_decrement_resource((php_libxml_node_object *) intern TSRMLS_CC);
} else {
php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
@ -1070,7 +1069,7 @@ int dom_has_feature(char *feature, char *version)
int retval = 0;
if (!(strcmp (version, "1.0") && strcmp (version,"2.0") && strcmp(version, ""))) {
if ((!strcasecmp(feature, "Core") && strcmp (version, "1.0")) || !strcasecmp(feature, "XML"))
if ((!strcasecmp(feature, "Core") && !strcmp (version, "1.0")) || !strcasecmp(feature, "XML"))
retval = 1;
}

View File

@ -113,12 +113,11 @@ int dom_processinginstruction_data_read(dom_object *obj, zval **retval TSRMLS_DC
if ((content = xmlNodeGetContent(nodep)) != NULL) {
ZVAL_STRING(*retval, content, 1);
xmlFree(content);
} else {
ZVAL_EMPTY_STRING(*retval);
}
xmlFree(content);
return SUCCESS;
}