From: Thies C. Arntzen Date: Sun, 5 Dec 1999 16:43:42 +0000 (+0000) Subject: @- added XML_Set_Object() function, now you can use the XML-Parser from X-Git-Tag: PRE_RETURN_REF_PATCH~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f17f3e4fa145d5b358bef68bd77e142fbc4394c2;p=php @- added XML_Set_Object() function, now you can use the XML-Parser from @ within an object. (Thies) (XML_Set_Object) new function. --- diff --git a/ext/xml/php_xml.h b/ext/xml/php_xml.h index ee582bee66..07ef8291b7 100644 --- a/ext/xml/php_xml.h +++ b/ext/xml/php_xml.h @@ -1,31 +1,21 @@ /* +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | + | PHP version 4.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + | Copyright (c) 1997, 1998, 1999 The PHP Group | +----------------------------------------------------------------------+ - | 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. | + | 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: Stig Sæther Bakken | + | Authors: Stig Sæther Bakken | + | Thies C. Arntzen | +----------------------------------------------------------------------+ - */ +*/ /* $Id$ */ @@ -67,8 +57,10 @@ typedef struct { char *externalEntityRefHandler; char *unknownEncodingHandler; - pval *data; - pval *info; + zval *object; + + zval *data; + zval *info; int level; int toffset; int curtag; @@ -107,6 +99,7 @@ enum php3_xml_option { #define XML_MAXLEVEL 255 /* XXX this should be dynamic */ PHP_FUNCTION(xml_parser_create); +PHP_FUNCTION(xml_set_object); PHP_FUNCTION(xml_set_element_handler); PHP_FUNCTION(xml_set_character_data_handler); PHP_FUNCTION(xml_set_processing_instruction_handler); diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 8886979bc0..047a0117d9 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -70,7 +70,7 @@ PHP_MSHUTDOWN_FUNCTION(xml); PHP_RSHUTDOWN_FUNCTION(xml); PHP_MINFO_FUNCTION(xml); -static void xml_destroy_parser(xml_parser *); +static void xml_parser_dtor(xml_parser *); static void xml_set_handler(char **, zval **); inline static unsigned short xml_encode_iso_8859_1(unsigned char); inline static char xml_decode_iso_8859_1(unsigned short); @@ -98,6 +98,7 @@ int _xml_externalEntityRefHandler(XML_Parser, const XML_Char *, const XML_Char function_entry xml_functions[] = { PHP_FE(xml_parser_create, NULL) + PHP_FE(xml_set_object, NULL) PHP_FE(xml_set_element_handler, NULL) PHP_FE(xml_set_character_data_handler, NULL) PHP_FE(xml_set_processing_instruction_handler, NULL) @@ -161,7 +162,7 @@ PHP_MINIT_FUNCTION(xml) ELS_FETCH(); - le_xml_parser = register_list_destructors(xml_destroy_parser, NULL); + le_xml_parser = register_list_destructors(xml_parser_dtor, NULL); #ifdef ZTS xml_globals_id = ts_allocate_id(sizeof(php_xml_globals), php_xml_init_globals, NULL); @@ -281,11 +282,18 @@ static zval *_xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encod /* }}} */ -/* {{{ xml_destroy_parser() */ +/* {{{ xml_parser_dtor() */ static void -xml_destroy_parser(xml_parser *parser) +xml_parser_dtor(xml_parser *parser) { + + if (parser->object) { +/* + zval_del_ref(&parser->object); +*/ + } + if (parser->parser) { XML_ParserFree(parser->parser); } @@ -369,11 +377,7 @@ xml_call_handler(xml_parser *parser, char *funcName, int argc, zval **argv) retval->type = IS_BOOL; retval->value.lval = 0; - /* We cannot call internal variables from a function module as - it breaks any chance of compiling it as a module on windows. - Instead, we create a callback function. */ - - result = call_user_function(EG(function_table), NULL, func, retval, argc, argv); + result = call_user_function(EG(function_table), parser->object, func, retval, argc, argv); if (result == FAILURE) { php_error(E_WARNING, "Unable to call %s()",funcName); @@ -1026,6 +1030,7 @@ PHP_FUNCTION(xml_parser_create) parser->parser = XML_ParserCreate(encoding); 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); @@ -1033,6 +1038,45 @@ PHP_FUNCTION(xml_parser_create) } /* }}} */ +/* {{{ proto int xml_set_object(int pind,object &obj) + Set up object which should be used for callbacks */ +PHP_FUNCTION(xml_set_object) +{ + xml_parser *parser; + zval **pind, **mythis; + + if (ARG_COUNT(ht) != 2 || + getParametersEx(2, &pind, &mythis) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if ((*mythis)->type != IS_OBJECT) { + php_error(E_WARNING,"arg 2 has wrong type"); + RETURN_FALSE; + } + + if (! ParameterPassedByReference(ht,2)) { + php_error(E_WARNING,"arg 2 not passed by reference"); + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(parser,xml_parser *,pind, -1, "XML Parser", le_xml_parser); + + if (parser->object) { +/* + zval_del_ref(&parser->object); +*/ + } + + parser->object = *mythis; +/* + zval_add_ref(&parser->object); +*/ + + RETVAL_TRUE; +} +/* }}} */ + /* {{{ proto int xml_set_element_handler(int pind, string shdl, string ehdl) Set up start and end element handlers */ PHP_FUNCTION(xml_set_element_handler)