From: Rui Hirokawa Date: Fri, 5 Jan 2001 06:36:51 +0000 (+0000) Subject: added libxml-1.95 support and some new functions related to namespace support. change... X-Git-Tag: php-4.0.5RC1~730 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32c3af8c39a99ff531220d9c56cdb879d5d8d440;p=php added libxml-1.95 support and some new functions related to namespace support. changed config.m4 to support xml extension as shared module. --- diff --git a/ext/xml/Makefile.in b/ext/xml/Makefile.in index 09024171f3..b685c9a67c 100644 --- a/ext/xml/Makefile.in +++ b/ext/xml/Makefile.in @@ -1,11 +1,11 @@ LTLIBRARY_NAME = libxml.la LTLIBRARY_SOURCES = xml.c -LTLIBRARY_DEPENDENCIES = expat/libexpat.la +LTLIBRARY_DEPENDENCIES = $(EXPAT_INTERNAL_LIBADD) LTLIBRARY_LIBADD = $(LTLIBRARY_DEPENDENCIES) LTLIBRARY_SHARED_NAME = xml.la -LTLIBRARY_SHARED_LIBADD = $(LTLIBRARY_LIBADD) +LTLIBRARY_SHARED_LIBADD = $(EXPAT_SHARED_LIBADD) -SUBDIRS = expat +SUBDIRS = $(EXPAT_SUBDIRS) include $(top_srcdir)/build/dynlib.mk diff --git a/ext/xml/config.m4 b/ext/xml/config.m4 index e48ec51592..ca5ea4f55b 100644 --- a/ext/xml/config.m4 +++ b/ext/xml/config.m4 @@ -16,13 +16,45 @@ PHP_ARG_ENABLE(xml,for XML support, [ --disable-xml Disable XML support using bundled expat lib], yes) if test "$PHP_XML" != "no"; then + + AC_MSG_CHECKING(for expat in default path) + for i in /usr/local /usr; do + if test -r $i/include/expat.h; then + EXPAT_DIR=$i + AC_MSG_RESULT(found in $i) + fi + done + AC_DEFINE(HAVE_LIBEXPAT, 1, [ ]) - CPPFLAGS="$CPPFLAGS -DXML_BYTE_ORDER=$order" - PHP_EXTENSION(xml, $ext_shared) - LIB_BUILD($ext_builddir/expat,$ext_shared,yes) - LIB_BUILD($ext_builddir/expat/xmlparse,$ext_shared,yes) - LIB_BUILD($ext_builddir/expat/xmltok,$ext_shared,yes) - AC_ADD_INCLUDE($ext_srcdir/expat/xmltok) - AC_ADD_INCLUDE($ext_srcdir/expat/xmlparse) - PHP_FAST_OUTPUT($ext_builddir/expat/Makefile $ext_builddir/expat/xmlparse/Makefile $ext_builddir/expat/xmltok/Makefile) + + if test -z "$EXPAT_DIR"; then + CPPFLAGS="$CPPFLAGS -DXML_BYTE_ORDER=$order" + EXPAT_INTERNAL_LIBADD="expat/libexpat.la" + PHP_SUBST(EXPAT_INTERNAL_LIBADD) + EXPAT_SUBDIRS="expat" + PHP_SUBST(EXPAT_SUBDIRS) + PHP_SUBST(EXPAT_SHARED_LIBADD) + PHP_EXTENSION(xml, $ext_shared) + LIB_BUILD($ext_builddir/expat,$ext_shared,yes) + LIB_BUILD($ext_builddir/expat/xmlparse,$ext_shared,yes) + LIB_BUILD($ext_builddir/expat/xmltok,$ext_shared,yes) + AC_ADD_INCLUDE($ext_srcdir/expat/xmltok) + AC_ADD_INCLUDE($ext_srcdir/expat/xmlparse) + PHP_FAST_OUTPUT($ext_builddir/expat/Makefile $ext_builddir/expat/xmlparse/Makefile $ext_builddir/expat/xmltok/Makefile) + + else + + if test -f $EXPAT/lib/libexpat.a -o -f $EXPAT_DIR/lib/libexpat.so ; then + AC_DEFINE(HAVE_LIBEXPAT2, 1, [ ]) + AC_ADD_INCLUDE($EXPAT_DIR/include) + AC_ADD_LIBRARY(expat) + else + AC_MSG_RESULT(not found) + AC_MSG_ERROR(Please reinstall the expat distribution) + fi + + PHP_SUBST(EXPAT_SHARED_LIBADD) + AC_ADD_LIBRARY_WITH_PATH(expat, $EXPAT_DIR/lib, EXPAT_SHARED_LIBADD) + PHP_EXTENSION(xml, $ext_shared) + fi fi diff --git a/ext/xml/php_xml.h b/ext/xml/php_xml.h index aacf900dea..253a9fc1d7 100644 --- a/ext/xml/php_xml.h +++ b/ext/xml/php_xml.h @@ -35,8 +35,12 @@ extern zend_module_entry xml_module_entry; #if defined(HAVE_LIBEXPAT) && defined(PHP_XML_INTERNAL) +#ifdef HAVE_LIBEXPAT2 +#include +#else #include #include +#endif #ifdef PHP_WIN32 #define PHP_XML_API __declspec(dllexport) @@ -67,7 +71,10 @@ typedef struct { zval *notationDeclHandler; zval *externalEntityRefHandler; zval *unknownEncodingHandler; - +#ifdef HAVE_LIBEXPAT2 + zval *startNamespaceDeclHandler; + zval *endNamespaceDeclHandler; +#endif zval *object; zval *data; @@ -107,6 +114,9 @@ enum php_xml_option { #define XML_MAXLEVEL 255 /* XXX this should be dynamic */ PHP_FUNCTION(xml_parser_create); +#ifdef HAVE_LIBEXPAT2 +PHP_FUNCTION(xml_parser_create_ns); +#endif PHP_FUNCTION(xml_set_object); PHP_FUNCTION(xml_set_element_handler); PHP_FUNCTION(xml_set_character_data_handler); @@ -115,6 +125,10 @@ PHP_FUNCTION(xml_set_default_handler); PHP_FUNCTION(xml_set_unparsed_entity_decl_handler); PHP_FUNCTION(xml_set_notation_decl_handler); PHP_FUNCTION(xml_set_external_entity_ref_handler); +#ifdef HAVE_LIBEXPAT2 +PHP_FUNCTION(xml_set_start_namespace_decl_handler); +PHP_FUNCTION(xml_set_end_namespace_decl_handler); +#endif PHP_FUNCTION(xml_parse); PHP_FUNCTION(xml_get_error_code); PHP_FUNCTION(xml_error_string); diff --git a/ext/xml/xml.c b/ext/xml/xml.c index afcf223644..5274807119 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -21,6 +21,7 @@ #define IS_EXT_MODULE #include "php.h" +#include "php_config.h" #define PHP_XML_INTERNAL #include "php_xml.h" #include "zend_variables.h" @@ -91,6 +92,10 @@ void _xml_unparsedEntityDeclHandler(void *, const XML_Char *, const XML_Char *, void _xml_notationDeclHandler(void *, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *); int _xml_externalEntityRefHandler(XML_Parser, const XML_Char *, const XML_Char *, const XML_Char *, const XML_Char *); +#ifdef HAVE_LIBEXPAT2 +void _xml_startNamespaceDeclHandler(void *, const XML_Char *, const XML_Char *); +void _xml_endNamespaceDeclHandler(void *, const XML_Char *); +#endif /* }}} */ /* {{{ extension definition structures */ @@ -98,6 +103,9 @@ static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_ function_entry xml_functions[] = { PHP_FE(xml_parser_create, NULL) +#ifdef HAVE_LIBEXPAT2 + PHP_FE(xml_parser_create_ns, NULL) +#endif PHP_FE(xml_set_object, second_arg_force_ref) PHP_FE(xml_set_element_handler, NULL) PHP_FE(xml_set_character_data_handler, NULL) @@ -106,6 +114,10 @@ function_entry xml_functions[] = { PHP_FE(xml_set_unparsed_entity_decl_handler, NULL) PHP_FE(xml_set_notation_decl_handler, NULL) PHP_FE(xml_set_external_entity_ref_handler, NULL) +#ifdef HAVE_LIBEXPAT2 + PHP_FE(xml_set_start_namespace_decl_handler, NULL) + PHP_FE(xml_set_end_namespace_decl_handler, NULL) +#endif PHP_FE(xml_parse, NULL) PHP_FE(xml_parse_into_struct, third_and_fourth_args_force_ref) PHP_FE(xml_get_error_code, NULL) @@ -221,7 +233,10 @@ PHP_MINFO_FUNCTION(xml) { php_info_print_table_start(); - php_info_print_table_row(2, "XML Support", "active"); + php_info_print_table_row(2, "XML Support", "active"); +#if HAVE_LIBEXPAT2 + php_info_print_table_row(2, "XML Namespace Support", "active"); +#endif php_info_print_table_end(); } @@ -319,6 +334,14 @@ xml_parser_dtor(zend_rsrc_list_entry *rsrc) if (parser->unknownEncodingHandler) { zval_del_ref(&parser->unknownEncodingHandler); } +#ifdef HAVE_LIBEXPAT2 + if (parser->startNamespaceDeclHandler) { + zval_del_ref(&parser->startNamespaceDeclHandler); + } + if (parser->endNamespaceDeclHandler) { + zval_del_ref(&parser->endNamespaceDeclHandler); + } +#endif if (parser->baseURI) { efree(parser->baseURI); } @@ -972,11 +995,57 @@ _xml_externalEntityRefHandler(XML_Parser parserPtr, /* }}} */ +#ifdef HAVE_LIBEXPAT2 + /* {{{ _xml_startNamespaceDeclHandler() */ + +void _xml_startNamespaceDeclHandler(void *userData, + const XML_Char *prefix, + const XML_Char *uri) +{ + xml_parser *parser = (xml_parser *)userData; + + if (parser && parser->startNamespaceDeclHandler) { + zval *retval, *args[3]; + + args[0] = _xml_resource_zval(parser->index); + args[1] = _xml_xmlchar_zval(prefix, 0, parser->target_encoding); + args[2] = _xml_xmlchar_zval(uri, 0, parser->target_encoding); + if ((retval = xml_call_handler(parser, parser->startNamespaceDeclHandler, 3, args))) { + zval_dtor(retval); + efree(retval); + } + } +} + +/* }}} */ + + /* {{{ _xml_endNamespaceDeclHandler() */ + +void _xml_endNamespaceDeclHandler(void *userData, + const XML_Char *prefix) +{ + xml_parser *parser = (xml_parser *)userData; + + if (parser && parser->endNamespaceDeclHandler) { + zval *retval, *args[2]; + + args[0] = _xml_resource_zval(parser->index); + args[1] = _xml_xmlchar_zval(prefix, 0, parser->target_encoding); + if ((retval = xml_call_handler(parser, parser->endNamespaceDeclHandler, 2, args))) { + zval_dtor(retval); + efree(retval); + } + } +} + +/* }}} */ +#endif + /* }}} */ /************************* EXTENSION FUNCTIONS *************************/ -/* {{{ proto int xml_parser_create(void) +/* {{{ proto int xml_parser_create([string encoding]) Create an XML parser */ PHP_FUNCTION(xml_parser_create) { @@ -1028,6 +1097,67 @@ PHP_FUNCTION(xml_parser_create) } /* }}} */ +#ifdef HAVE_LIBEXPAT2 +/* {{{ proto int xml_parser_create_ns([string encoding][, string sep]) + Create an XML parser */ +PHP_FUNCTION(xml_parser_create_ns) +{ + xml_parser *parser; + int argc; + zval **encodingArg, **sepArg; + XML_Char *encoding, *sep; + char thisfunc[] = "xml_parser_create"; + XMLLS_FETCH(); + + argc = ZEND_NUM_ARGS(); + + if (argc > 2 || zend_get_parameters_ex(argc, &encodingArg, &sepArg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (argc >= 1) { + convert_to_string_ex(encodingArg); + /* The supported encoding types are hardcoded here because + * we are limited to the encodings supported by expat/xmltok. + */ + if (strncasecmp((*encodingArg)->value.str.val, "ISO-8859-1", + (*encodingArg)->value.str.len) == 0) { + encoding = "ISO-8859-1"; + } else if (strncasecmp((*encodingArg)->value.str.val, "UTF-8", + (*encodingArg)->value.str.len) == 0) { + encoding = "UTF-8"; + } else if (strncasecmp((*encodingArg)->value.str.val, "US-ASCII", + (*encodingArg)->value.str.len) == 0) { + encoding = "US-ASCII"; + } else { /* UTF-16 not supported */ + php_error(E_WARNING, "%s: unsupported source encoding \"%s\"", + thisfunc, (*encodingArg)->value.str.val); + RETURN_FALSE; + } + } else { + encoding = XML(default_encoding); + } + + if (argc == 2){ + convert_to_string_ex(sepArg); + sep = (*sepArg)->value.str.val; + } else { + sep = ":"; + } + + parser = ecalloc(sizeof(xml_parser), 1); + parser->parser = XML_ParserCreateNS(encoding, sep[0]); + parser->target_encoding = encoding; + parser->case_folding = 1; + parser->object = NULL; + XML_SetUserData(parser->parser, parser); + + ZEND_REGISTER_RESOURCE(return_value,parser,le_xml_parser); + parser->index = return_value->value.lval; +} +/* }}} */ +#endif + /* {{{ proto int xml_set_object(int pind, object &obj) Set up object which should be used for callbacks */ PHP_FUNCTION(xml_set_object) @@ -1195,6 +1325,47 @@ PHP_FUNCTION(xml_set_external_entity_ref_handler) } /* }}} */ +#ifdef HAVE_LIBEXPAT2 + +/* {{{ proto int xml_set_start_namespace_decl_handler(int pind, string hdl) + Set up character data handler */ +PHP_FUNCTION(xml_set_start_namespace_decl_handler) +{ + xml_parser *parser; + zval **pind, **hdl; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pind, &hdl) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ZEND_FETCH_RESOURCE(parser,xml_parser *, pind, -1, "XML Parser", le_xml_parser); + + xml_set_handler(&parser->startNamespaceDeclHandler, hdl); + XML_SetStartNamespaceDeclHandler(parser->parser, _xml_startNamespaceDeclHandler); + RETVAL_TRUE; +} +/* }}} */ + +/* {{{ proto int xml_set_end_namespace_decl_handler(int pind, string hdl) + Set up character data handler */ +PHP_FUNCTION(xml_set_end_namespace_decl_handler) +{ + xml_parser *parser; + zval **pind, **hdl; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pind, &hdl) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ZEND_FETCH_RESOURCE(parser,xml_parser *, pind, -1, "XML Parser", le_xml_parser); + + xml_set_handler(&parser->endNamespaceDeclHandler, hdl); + XML_SetEndNamespaceDeclHandler(parser->parser, _xml_endNamespaceDeclHandler); + RETVAL_TRUE; +} +/* }}} */ +#endif + /* {{{ proto int xml_parse(int pind, string data [, int isFinal]) Start parsing an XML document */ PHP_FUNCTION(xml_parse)