Skip to content

Commit f17f3e4

Browse files
author
Thies C. Arntzen
committed
@- added XML_Set_Object() function, now you can use the XML-Parser from
@ within an object. (Thies) (XML_Set_Object) new function.
1 parent d9a8628 commit f17f3e4

File tree

2 files changed

+70
-33
lines changed

2 files changed

+70
-33
lines changed

ext/xml/php_xml.h

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
/*
22
+----------------------------------------------------------------------+
3-
| PHP HTML Embedded Scripting Language Version 3.0 |
3+
| PHP version 4.0 |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
5+
| Copyright (c) 1997, 1998, 1999 The PHP Group |
66
+----------------------------------------------------------------------+
7-
| This program is free software; you can redistribute it and/or modify |
8-
| it under the terms of one of the following licenses: |
9-
| |
10-
| A) the GNU General Public License as published by the Free Software |
11-
| Foundation; either version 2 of the License, or (at your option) |
12-
| any later version. |
13-
| |
14-
| B) the PHP License as published by the PHP Development Team and |
15-
| included in the distribution in the file: LICENSE |
16-
| |
17-
| This program is distributed in the hope that it will be useful, |
18-
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
19-
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20-
| GNU General Public License for more details. |
21-
| |
22-
| You should have received a copy of both licenses referred to here. |
23-
| If you did not, or have any questions about PHP licensing, please |
24-
| contact core@php.net. |
7+
| This source file is subject to version 2.0 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available at through the world-wide-web at |
10+
| http://www.php.net/license/2_0.txt. |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| license@php.net so we can mail you a copy immediately. |
2514
+----------------------------------------------------------------------+
26-
| Authors: Stig Sæther Bakken <ssb@guardian.no> |
15+
| Authors: Stig Sæther Bakken <ssb@fast.no> |
16+
| Thies C. Arntzen <thies@digicol.de> |
2717
+----------------------------------------------------------------------+
28-
*/
18+
*/
2919

3020
/* $Id$ */
3121

@@ -67,8 +57,10 @@ typedef struct {
6757
char *externalEntityRefHandler;
6858
char *unknownEncodingHandler;
6959

70-
pval *data;
71-
pval *info;
60+
zval *object;
61+
62+
zval *data;
63+
zval *info;
7264
int level;
7365
int toffset;
7466
int curtag;
@@ -107,6 +99,7 @@ enum php3_xml_option {
10799
#define XML_MAXLEVEL 255 /* XXX this should be dynamic */
108100

109101
PHP_FUNCTION(xml_parser_create);
102+
PHP_FUNCTION(xml_set_object);
110103
PHP_FUNCTION(xml_set_element_handler);
111104
PHP_FUNCTION(xml_set_character_data_handler);
112105
PHP_FUNCTION(xml_set_processing_instruction_handler);

ext/xml/xml.c

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ PHP_MSHUTDOWN_FUNCTION(xml);
7070
PHP_RSHUTDOWN_FUNCTION(xml);
7171
PHP_MINFO_FUNCTION(xml);
7272

73-
static void xml_destroy_parser(xml_parser *);
73+
static void xml_parser_dtor(xml_parser *);
7474
static void xml_set_handler(char **, zval **);
7575
inline static unsigned short xml_encode_iso_8859_1(unsigned char);
7676
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
9898

9999
function_entry xml_functions[] = {
100100
PHP_FE(xml_parser_create, NULL)
101+
PHP_FE(xml_set_object, NULL)
101102
PHP_FE(xml_set_element_handler, NULL)
102103
PHP_FE(xml_set_character_data_handler, NULL)
103104
PHP_FE(xml_set_processing_instruction_handler, NULL)
@@ -161,7 +162,7 @@ PHP_MINIT_FUNCTION(xml)
161162

162163
ELS_FETCH();
163164

164-
le_xml_parser = register_list_destructors(xml_destroy_parser, NULL);
165+
le_xml_parser = register_list_destructors(xml_parser_dtor, NULL);
165166

166167
#ifdef ZTS
167168
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
281282

282283
/* }}} */
283284

284-
/* {{{ xml_destroy_parser() */
285+
/* {{{ xml_parser_dtor() */
285286

286287
static void
287-
xml_destroy_parser(xml_parser *parser)
288+
xml_parser_dtor(xml_parser *parser)
288289
{
290+
291+
if (parser->object) {
292+
/*
293+
zval_del_ref(&parser->object);
294+
*/
295+
}
296+
289297
if (parser->parser) {
290298
XML_ParserFree(parser->parser);
291299
}
@@ -369,11 +377,7 @@ xml_call_handler(xml_parser *parser, char *funcName, int argc, zval **argv)
369377
retval->type = IS_BOOL;
370378
retval->value.lval = 0;
371379

372-
/* We cannot call internal variables from a function module as
373-
it breaks any chance of compiling it as a module on windows.
374-
Instead, we create a callback function. */
375-
376-
result = call_user_function(EG(function_table), NULL, func, retval, argc, argv);
380+
result = call_user_function(EG(function_table), parser->object, func, retval, argc, argv);
377381

378382
if (result == FAILURE) {
379383
php_error(E_WARNING, "Unable to call %s()",funcName);
@@ -1026,13 +1030,53 @@ PHP_FUNCTION(xml_parser_create)
10261030
parser->parser = XML_ParserCreate(encoding);
10271031
parser->target_encoding = encoding;
10281032
parser->case_folding = 1;
1033+
parser->object = NULL;
10291034
XML_SetUserData(parser->parser, parser);
10301035

10311036
ZEND_REGISTER_RESOURCE(return_value,parser,le_xml_parser);
10321037
parser->index = return_value->value.lval;
10331038
}
10341039
/* }}} */
10351040

1041+
/* {{{ proto int xml_set_object(int pind,object &obj)
1042+
Set up object which should be used for callbacks */
1043+
PHP_FUNCTION(xml_set_object)
1044+
{
1045+
xml_parser *parser;
1046+
zval **pind, **mythis;
1047+
1048+
if (ARG_COUNT(ht) != 2 ||
1049+
getParametersEx(2, &pind, &mythis) == FAILURE) {
1050+
WRONG_PARAM_COUNT;
1051+
}
1052+
1053+
if ((*mythis)->type != IS_OBJECT) {
1054+
php_error(E_WARNING,"arg 2 has wrong type");
1055+
RETURN_FALSE;
1056+
}
1057+
1058+
if (! ParameterPassedByReference(ht,2)) {
1059+
php_error(E_WARNING,"arg 2 not passed by reference");
1060+
RETURN_FALSE;
1061+
}
1062+
1063+
ZEND_FETCH_RESOURCE(parser,xml_parser *,pind, -1, "XML Parser", le_xml_parser);
1064+
1065+
if (parser->object) {
1066+
/*
1067+
zval_del_ref(&parser->object);
1068+
*/
1069+
}
1070+
1071+
parser->object = *mythis;
1072+
/*
1073+
zval_add_ref(&parser->object);
1074+
*/
1075+
1076+
RETVAL_TRUE;
1077+
}
1078+
/* }}} */
1079+
10361080
/* {{{ proto int xml_set_element_handler(int pind, string shdl, string ehdl)
10371081
Set up start and end element handlers */
10381082
PHP_FUNCTION(xml_set_element_handler)

0 commit comments

Comments
 (0)