cvs: /php4/ext/xml php_xml.h xml.c
| From: | Thies C. Arntzen | Date: | Sun, 05 Dec 1999 16:44:12 +0000 |
| Subject: | cvs: /php4/ext/xml php_xml.h xml.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-7448@lists.php.net to get a copy of this message | ||
thies Sun Dec 5 11:44:12 1999 EDT
Modified files:
/php4/ext/xml php_xml.h xml.c
Log:
@- added XML_Set_Object() function, now you can use the XML-Parser from
@ within an object. (Thies)
(XML_Set_Object) new function.
Index: php4/ext/xml/php_xml.h
diff -u php4/ext/xml/php_xml.h:1.2 php4/ext/xml/php_xml.h:1.3
--- php4/ext/xml/php_xml.h:1.2 Sun Dec 5 09:16:37 1999
+++ php4/ext/xml/php_xml.h Sun Dec 5 11:43:42 1999
@@ -1,33 +1,23 @@
/*
+----------------------------------------------------------------------+
- | 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 <ssb@guardian.no> |
+ | Authors: Stig Sæther Bakken <ssb@fast.no> |
+ | Thies C. Arntzen <thies@digicol.de> |
+----------------------------------------------------------------------+
- */
+*/
-/* $Id: php_xml.h,v 1.2 1999/12/05 14:16:37 rasmus Exp $ */
+/* $Id: php_xml.h,v 1.3 1999/12/05 16:43:42 thies Exp $ */
#ifndef _PHP_XML_H
# define _PHP_XML_H
@@ -67,8 +57,10 @@
char *externalEntityRefHandler;
char *unknownEncodingHandler;
- pval *data;
- pval *info;
+ zval *object;
+
+ zval *data;
+ zval *info;
int level;
int toffset;
int curtag;
@@ -107,6 +99,7 @@
#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);
Index: php4/ext/xml/xml.c
diff -u php4/ext/xml/xml.c:1.31 php4/ext/xml/xml.c:1.32
--- php4/ext/xml/xml.c:1.31 Sat Dec 4 14:16:10 1999
+++ php4/ext/xml/xml.c Sun Dec 5 11:43:42 1999
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: xml.c,v 1.31 1999/12/04 19:16:10 sas Exp $ */
+/* $Id: xml.c,v 1.32 1999/12/05 16:43:42 thies Exp $ */
#define IS_EXT_MODULE
#include "php.h"
@@ -70,7 +70,7 @@
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 @@
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 @@
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 @@
/* }}} */
-/* {{{ 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,12 +377,8 @@
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), parser->object, func, retval, argc, argv);
- result = call_user_function(EG(function_table), NULL, func, retval, argc, argv);
-
if (result == FAILURE) {
php_error(E_WARNING, "Unable to call %s()",funcName);
@@ -1026,10 +1030,50 @@
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);
parser->index = return_value->value.lval;
+}
+/* }}} */
+
+/* {{{ 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;
}
/* }}} */