summaryrefslogtreecommitdiff
path: root/ext/dom/domimplementation.c
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2003-07-25 17:25:50 (GMT)
committerRob Richards <rrichards@php.net>2003-07-25 17:25:50 (GMT)
commit618d6c904dd5c7c28d8f2c67e66e7fbcda8d6c8b (patch)
treee64e20898ebe9f9688118c384c85aa876f571e41 /ext/dom/domimplementation.c
parent9b38350af403415bf11ae5d11c93e553667c8c2e (diff)
downloadphp-618d6c904dd5c7c28d8f2c67e66e7fbcda8d6c8b.tar.gz
doctype and namespace fix
memory leak fix
Diffstat (limited to 'ext/dom/domimplementation.c')
-rw-r--r--ext/dom/domimplementation.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/ext/dom/domimplementation.c b/ext/dom/domimplementation.c
index 1a9f8a4..fccae0b 100644
--- a/ext/dom/domimplementation.c
+++ b/ext/dom/domimplementation.c
@@ -130,7 +130,7 @@ PHP_FUNCTION(dom_domimplementation_create_document)
zval *node = NULL, *rv = NULL;
xmlDoc *docp;
xmlNode *nodep;
- xmlDtdPtr doctype = NULL, dtd = NULL;
+ xmlDtdPtr doctype = NULL;
xmlNsPtr nsptr = NULL;
int ret, uri_len = 0, name_len = 0;
char *uri, *name;
@@ -142,7 +142,7 @@ PHP_FUNCTION(dom_domimplementation_create_document)
return;
}
- if (doctype != NULL) {
+ if (node != NULL) {
DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj);
if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid DocumentType object");
@@ -192,20 +192,16 @@ PHP_FUNCTION(dom_domimplementation_create_document)
xmlFreeURI(uristruct);
if (uri_len > 0) {
- if (prefix == NULL) {
+ if ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL) {
php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
- xmlFree(localname);
- RETURN_FALSE;
- } else {
- if ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL) {
- php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
+ if (prefix != NULL) {
xmlFree(prefix);
- xmlFree(localname);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
- RETURN_FALSE;
}
+ xmlFree(localname);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ RETURN_FALSE;
}
+
}
if (prefix != NULL) {
xmlFree(prefix);
@@ -223,24 +219,42 @@ PHP_FUNCTION(dom_domimplementation_create_document)
}
if (doctype != NULL) {
- dtd = xmlCreateIntSubset (docp, doctype->name,
- doctype->ExternalID, doctype->SystemID);
+ docp->intSubset = doctype;
+ doctype->parent = docp;
+ doctype->doc = docp;
+ docp->children = (xmlNodePtr) doctype;
+ docp->last = (xmlNodePtr) doctype;
}
if (localname != NULL) {
nodep = xmlNewDocNode (docp, nsptr, localname, NULL);
if (!nodep) {
+ if (doctype != NULL) {
+ docp->intSubset = NULL;
+ doctype->parent = NULL;
+ doctype->doc = NULL;
+ docp->children = NULL;
+ docp->last = NULL;
+ }
xmlFreeDoc(docp);
xmlFree(localname);
/* Need some type of error here */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error");
RETURN_FALSE;
}
+
+ nodep->nsDef = nsptr;
+
xmlDocSetRootElement(docp, nodep);
xmlFree(localname);
}
DOM_RET_OBJ(rv, (xmlNodePtr) docp, &ret, NULL);
+
+ if (doctype != NULL) {
+ doctobj->document = ((dom_object *)((node_ptr *)docp->_private)->_private)->document;
+ increment_document_reference(doctobj, docp TSRMLS_CC);
+ }
}
/* }}} end dom_domimplementation_create_document */