From ad9b5927dca6baebf064a4c598b00d4ef5b963bd Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 24 Nov 1999 06:21:48 +0000 Subject: [PATCH] - new xml parser with dom support --- ext/domxml/Makefile.am | 6 + ext/domxml/config.h.stub | 3 + ext/domxml/config.m4 | 61 ++++ ext/domxml/domxml.c | 610 +++++++++++++++++++++++++++++++++++++++ ext/domxml/php3_domxml.h | 68 +++++ 5 files changed, 748 insertions(+) create mode 100644 ext/domxml/Makefile.am create mode 100644 ext/domxml/config.h.stub create mode 100644 ext/domxml/config.m4 create mode 100644 ext/domxml/domxml.c create mode 100644 ext/domxml/php3_domxml.h diff --git a/ext/domxml/Makefile.am b/ext/domxml/Makefile.am new file mode 100644 index 0000000000..df0c78924c --- /dev/null +++ b/ext/domxml/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_domxml.a +libphpext_domxml_a_SOURCES=domxml.c + diff --git a/ext/domxml/config.h.stub b/ext/domxml/config.h.stub new file mode 100644 index 0000000000..0a9d0706b5 --- /dev/null +++ b/ext/domxml/config.h.stub @@ -0,0 +1,3 @@ +/* Define if you have the gnome xml library */ +#define HAVE_DOMXML 0 + diff --git a/ext/domxml/config.m4 b/ext/domxml/config.m4 new file mode 100644 index 0000000000..d89c973446 --- /dev/null +++ b/ext/domxml/config.m4 @@ -0,0 +1,61 @@ +dnl $Id$ + +AC_MSG_CHECKING(whether to include DOM support) +AC_ARG_WITH(dom, +[ --with-dom[=DIR] Include DOM support (requires libxml >= 1.0). + DIR is the libxml install directory, + defaults to /usr.], +[ + case "$withval" in + no) + AC_MSG_RESULT(no) ;; + yes) + AC_MSG_RESULT(yes) + PHP_EXTENSION(domxml) + AC_CHECK_LIB(xml, xmlNewDoc, [AC_DEFINE(HAVE_DOMXML)], + [AC_MSG_ERROR(DOM module requires libxml >= 1.0)]) + AC_ADD_LIBRARY(xml) + ;; + *) + test -f $withval/include/gnome-xml/tree.h && DOMXML_INCLUDE="$withval/include/gnome-xml" + test -f $withval/include/tree.h && DOMXML_INCLUDE="$withval/include" + if test -n "$DOMXML_INCLUDE" ; then + AC_MSG_RESULT(yes) + PHP_EXTENSION(domxml) + old_LIBS=$LIBS + LIBS="$LIBS -L$withval/lib" + + if test $HAVE_ZLIB; then + old_withval=$withval + AC_MSG_CHECKING([for zlib (needed by DOM support)]) + AC_ARG_WITH(zlib-dir, + [ --with-zlib-dir[=DIR] zlib dir for pdflib 2.0 or include zlib support],[ + AC_MSG_RESULT( ) + if test -z $withval; then + withval="/usr/local" + fi + LIBS="$LIBS -L$withval/lib -lz" + AC_CHECK_LIB(z,deflate, ,[AC_MSG_RESULT(no)],) + AC_ADD_LIBRARY_WITH_PATH(z, $withval/lib) + ],[ + AC_MSG_RESULT(no) + AC_MSG_WARN(If configure fails try --with-zlib=) + ]) + withval=$old_withval + else + echo "checking for libz needed by pdflib 2.0... already zlib support" + LIBS="$LIBS -L$withval/lib -lz" + fi + + AC_CHECK_LIB(xml, xmlNewDoc, [AC_DEFINE(HAVE_DOMXML)], + [AC_MSG_ERROR(DOM module requires libxml >= 1.0.)]) + LIBS=$old_LIBS + AC_ADD_LIBRARY_WITH_PATH(xml, $withval/lib) + AC_ADD_INCLUDE($DOMXML_INCLUDE) + else + AC_MSG_RESULT(no) + fi ;; + esac +],[ + AC_MSG_RESULT(no) +]) diff --git a/ext/domxml/domxml.c b/ext/domxml/domxml.c new file mode 100644 index 0000000000..a51e3ee0f7 --- /dev/null +++ b/ext/domxml/domxml.c @@ -0,0 +1,610 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + + +#include "php.h" +#include "php3_domxml.h" + +#if HAVE_DOMXML + +static int le_domxmldocp; +static int le_domxmldtdp; +static int le_domxmlnodep; +static int le_domxmlattrp; +static zend_class_entry *domxmldoc_class_entry_ptr; +static zend_class_entry *domxmldtd_class_entry_ptr; +static zend_class_entry *domxmlnode_class_entry_ptr; +static zend_class_entry *domxmlattr_class_entry_ptr; + +function_entry php_domxml_functions[] = { + PHP_FE(getdom, NULL) + PHP_FE(domxml_root, NULL) + PHP_FE(domxml_attributes, NULL) + PHP_FALIAS(dom, getdom, NULL) + {NULL, NULL, NULL} +}; + + +static zend_function_entry php_domxmldoc_class_functions[] = { + PHP_FALIAS(root, domxml_root, NULL) + PHP_FALIAS(intdtd, domxml_intdtd, NULL) +}; + +static zend_function_entry php_domxmldtd_class_functions[] = { +}; + +static zend_function_entry php_domxmlnode_class_functions[] = { + PHP_FALIAS(lastchild, domxml_lastchild, NULL) + PHP_FALIAS(children, domxml_children, NULL) + PHP_FALIAS(parent, domxml_parent, NULL) + PHP_FALIAS(getattr, domxml_getattr, NULL) + PHP_FALIAS(setattr, domxml_getattr, NULL) + PHP_FALIAS(attributes, domxml_attributes, NULL) +}; + +static zend_function_entry php_domxmlattr_class_functions[] = { + PHP_FALIAS(name, domxml_attrname, NULL) +}; + +php3_module_entry php3_domxml_module_entry = { + "DOM", php_domxml_functions, PHP_MINIT(domxml), NULL, NULL, NULL, PHP_MINFO(domxml), STANDARD_MODULE_PROPERTIES +}; + + +PHP_MINIT_FUNCTION(domxml) +{ + zend_class_entry domxmldoc_class_entry; + zend_class_entry domxmldtd_class_entry; + zend_class_entry domxmlnode_class_entry; + zend_class_entry domxmlattr_class_entry; + + le_domxmldocp = register_list_destructors(xmlFreeDoc, NULL); + /* Freeing the document contains freeing the complete tree. + Therefore nodes, attributes etc. may not be freed seperately. + le_domxmlnodep = register_list_destructors(xmlFreeNode, NULL); + le_domxmlattrp = register_list_destructors(xmlFreeProp, NULL); + */ + + INIT_CLASS_ENTRY(domxmldoc_class_entry, "Dom document", php_domxmldoc_class_functions); + INIT_CLASS_ENTRY(domxmldtd_class_entry, "Dtd", php_domxmldtd_class_functions); + INIT_CLASS_ENTRY(domxmlnode_class_entry, "Dom node", php_domxmlnode_class_functions); + INIT_CLASS_ENTRY(domxmlattr_class_entry, "Dom Attribute", php_domxmlattr_class_functions); + + domxmldoc_class_entry_ptr = register_internal_class(&domxmldoc_class_entry); + domxmldtd_class_entry_ptr = register_internal_class(&domxmldtd_class_entry); + domxmlnode_class_entry_ptr = register_internal_class(&domxmlnode_class_entry); + domxmlattr_class_entry_ptr = register_internal_class(&domxmlattr_class_entry); + + REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE", XML_ELEMENT_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NODE", XML_ATTRIBUTE_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_TEXT_NODE", XML_TEXT_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_CDATA_SECTION_NODE", XML_CDATA_SECTION_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_ENTITY_REF_NODE", XML_ENTITY_REF_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_ENTITY_NODE", XML_ENTITY_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_PI_NODE", XML_PI_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_COMMENT_NODE", XML_COMMENT_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_DOCUMENT_NODE", XML_DOCUMENT_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_DOCUMENT_TYPE_NODE", XML_DOCUMENT_TYPE_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_DOCUMENT_FRAG_NODE", XML_DOCUMENT_FRAG_NODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_NOTATION_NODE", XML_NOTATION_NODE, CONST_CS | CONST_PERSISTENT); + return SUCCESS; +} + +PHP_MINFO_FUNCTION(domxml) +{ + PUTS("DOM/XML support active (compiled with libxml "); + PUTS(XML_DEFAULT_VERSION); + PUTS(".)"); +} + +/* {{{ proto string domxml_attrname([int dir_handle]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_attrname) +{ + pval *id, **tmp; + int id_to_find; + xmlNode *nodep; + xmlAttr *attr; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + attr = nodep->properties; + if (!attr) { + RETURN_FALSE; + } + while(attr) { + ret = php3_list_insert(attr, le_domxmlattrp); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmlattr_class_entry_ptr); + add_property_long(return_value, "attribute", ret); + attr = attr->next; + } +} +/* }}} */ + +/* {{{ proto string domxml_lastchild([int node]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_lastchild) +{ + pval *id, **tmp; + int id_to_find; + xmlNode *nodep, *last; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + last = nodep->last; + if (!last) { + RETURN_FALSE; + } + + ret = php3_list_insert(last, le_domxmlnodep); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmlnode_class_entry_ptr); + add_property_long(return_value, "node", ret); + add_property_long(return_value, "type", last->type); + add_property_stringl(return_value, "name", (char *) last->name, strlen(last->name), 1); + if(last->content) + add_property_stringl(return_value, "content", (char *) last->content, strlen(last->content), 1); +} +/* }}} */ + +/* {{{ proto string domxml_parent([int node]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_parent) +{ + pval *id, **tmp; + int id_to_find; + xmlNode *nodep, *last; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + last = nodep->parent; + if (!last) { + RETURN_FALSE; + } + + ret = php3_list_insert(last, le_domxmlnodep); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmlnode_class_entry_ptr); + add_property_long(return_value, "node", ret); + add_property_long(return_value, "type", last->type); + add_property_stringl(return_value, "name", (char *) last->name, strlen(last->name), 1); + if(last->content) + add_property_stringl(return_value, "content", (char *) last->content, strlen(last->content), 1); +} +/* }}} */ + +/* {{{ proto string domxml_children([int node]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_children) +{ + pval *id, **tmp; + int id_to_find; + xmlNode *nodep, *last; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + last = nodep->childs; + if (!last) { + RETURN_FALSE; + } + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + while(last) { + zval *child; + MAKE_STD_ZVAL(child); + + ret = php3_list_insert(last, le_domxmlnodep); + + /* construct a node object */ + object_init_ex(child, domxmlnode_class_entry_ptr); + add_property_stringl(child, "name", (char *) last->name, strlen(last->name), 1); + if(last->content) + add_property_stringl(child, "content", (char *) last->content, strlen(last->content), 1); + add_property_long(child, "node", ret); + add_property_long(child, "type", last->type); + zend_hash_next_index_insert(return_value->value.ht, &child, sizeof(zval *), NULL); + last = last->next; + } +} +/* }}} */ + +/* {{{ proto string domxml_getattr([int node], string attrname) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_getattr) +{ + pval *id, *arg1, **tmp; + int id_to_find; + xmlNode *nodep, *last; + char *value; + int type; + int ret; + + if ((ARG_COUNT(ht) == 1) && getParameters(ht, 1, &arg1) == SUCCESS) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + convert_to_string(arg1); + } else if ((ARG_COUNT(ht) == 2) && getParameters(ht, 2, &id, &arg1) == SUCCESS) { + convert_to_long(id); + id_to_find = id->value.lval; + convert_to_string(arg1); + } else { + WRONG_PARAM_COUNT; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + value = xmlGetProp(nodep, arg1->value.str.val); + if (!value) { + php_error(E_WARNING, "No such attribute '%s'", arg1->value.str.val); + RETURN_FALSE; + } + RETURN_STRING(value, 1); +} +/* }}} */ + +/* {{{ proto string domxml_setattr([int node], string attrname, string value) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_setattr) +{ + pval *id, *arg1, *arg2, **tmp; + int id_to_find; + xmlNode *nodep, *last; + xmlAttr *attr; + int type; + int ret; + + if ((ARG_COUNT(ht) == 2) && getParameters(ht, 2, &arg1, &arg2) == SUCCESS) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + convert_to_string(arg1); + convert_to_string(arg2); + } else if ((ARG_COUNT(ht) == 3) && getParameters(ht, 3, &id, &arg1, &arg2) == SUCCESS) { + convert_to_long(id); + id_to_find = id->value.lval; + convert_to_string(arg1); + convert_to_string(arg2); + } else { + WRONG_PARAM_COUNT; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + attr = xmlSetProp(nodep, arg1->value.str.val, arg2->value.str.val); + if (!attr) { + php_error(E_WARNING, "No such attribute '%s'", arg1->value.str.val); + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto string domxml_attributes([int node]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_attributes) +{ + pval *id, *arg1, **tmp; + int id_to_find; + xmlNode *nodep; + xmlAttr *attr; + char *value; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "node", sizeof("node"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my node (%d)", id); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + nodep = (xmlNode *)php3_list_find(id_to_find, &type); + if (!nodep || type != le_domxmlnodep) { + php_error(E_WARNING, "unable to find node identifier (%d)", id_to_find); + RETURN_FALSE; + } + + attr = nodep->properties; + if (!attr) { + RETURN_FALSE; + } + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + while(attr) { + add_assoc_string(return_value, (char *) attr->name, attr->val->content, 1); + attr = attr->next; + } +} +/* }}} */ + +/* {{{ proto string domxml_root([int dir_handle]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_root) +{ + pval *id, **tmp; + int id_to_find; + xmlDoc *docp; + xmlNode *node; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "doc", sizeof("doc"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + docp = (xmlDoc *)php3_list_find(id_to_find, &type); + if (!docp || type != le_domxmldocp) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + node = docp->root; + if (!node) { + RETURN_FALSE; + } + ret = php3_list_insert(node, le_domxmlnodep); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmlnode_class_entry_ptr); + add_property_long(return_value, "node", ret); + add_property_long(return_value, "type", node->type); + add_property_stringl(return_value, "name", (char *) node->name, strlen(node->name), 1); + if(node->content) + add_property_stringl(return_value, "content", (char *) node->content, strlen(node->content), 1); +} +/* }}} */ + +/* {{{ proto string domxml_dtd([int dir_handle]) +Read directory entry from dir_handle */ +PHP_FUNCTION(domxml_intdtd) +{ + pval *id, **tmp; + int id_to_find; + xmlDoc *docp; + xmlDtd *dtd; + int type; + int ret; + + if (ARG_COUNT(ht) == 0) { + id = getThis(); + if (id) { + if (zend_hash_find(id->value.obj.properties, "doc", sizeof("doc"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my handle property"); + RETURN_FALSE; + } + id_to_find = (*tmp)->value.lval; + } else { + RETURN_FALSE; + } + } else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_long(id); + id_to_find = id->value.lval; + } + + docp = (xmlDoc *)php3_list_find(id_to_find, &type); + if (!docp || type != le_domxmldocp) { + php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + dtd = docp->intSubset; + if (!dtd) { + RETURN_FALSE; + } + ret = php3_list_insert(dtd, le_domxmldtdp); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmldtd_class_entry_ptr); + add_property_long(return_value, "dtd", ret); + add_property_string(return_value, "extid", (char *) dtd->ExternalID, 1); + add_property_string(return_value, "sysid", (char *) dtd->SystemID, 1); + add_property_string(return_value, "name", (char *) dtd->name, 1); +} +/* }}} */ + +/* {{{ proto class dom(string directory) +Directory class with properties, handle and class and methods read, rewind and close */ +PHP_FUNCTION(getdom) +{ + pval *arg; + xmlDoc *docp; + int ret; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(arg); + + docp = xmlParseMemory(arg->value.str.val, arg->value.str.len); + if (!docp) { + RETURN_FALSE; + } + ret = php3_list_insert(docp, le_domxmldocp); + + /* construct an object with some methods */ + object_init_ex(return_value, domxmldoc_class_entry_ptr); + add_property_long(return_value, "doc", ret); + add_property_stringl(return_value, "version", (char *) docp->version, strlen(docp->version), 1); +} +/* }}} */ + +#endif /* HAVE_DOMXML */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/ext/domxml/php3_domxml.h b/ext/domxml/php3_domxml.h new file mode 100644 index 0000000000..13bf835ee9 --- /dev/null +++ b/ext/domxml/php3_domxml.h @@ -0,0 +1,68 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Uwe Steinmann (Uwe.Steinmann@fernuni-hagen.de | + | | + +----------------------------------------------------------------------+ + */ + + +/* $Id$ */ + +#ifndef _PHP3_DOMXML_H +#define _PHP3_DOMXML_H + +#if HAVE_DOMXML +#include + +extern php3_module_entry php3_domxml_module_entry; +#define php3_domxml_module_ptr &php3_domxml_module_entry + +/* directory functions */ +extern PHP_MINIT_FUNCTION(domxml); +extern PHP_MINFO_FUNCTION(domxml); +PHP_FUNCTION(getdom); + +/* Class Document methods */ +PHP_FUNCTION(domxml_root); +PHP_FUNCTION(domxml_intdtd); + +/* Class Node methods */ +PHP_FUNCTION(domxml_attributes); +PHP_FUNCTION(domxml_getattr); +PHP_FUNCTION(domxml_setattr); +PHP_FUNCTION(domxml_children); +PHP_FUNCTION(domxml_lastchild); +PHP_FUNCTION(domxml_parent); + +/* Class Attribute methods */ +PHP_FUNCTION(domxml_attrname); + +#else +#define php3_domxml_module_ptr NULL +#endif /* HAVE_DOMXML */ +#define phpext_domxml_ptr php3_domxml_module_ptr + +#endif /* _PHP3_DIR_H */ -- 2.40.0