1999-04-22 10:48:28 +08:00
|
|
|
|
/*
|
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
|
| PHP Version 5 |
|
1999-04-22 10:48:28 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
2013-01-01 16:28:54 +08:00
|
|
|
|
| Copyright (c) 1997-2013 The PHP Group |
|
1999-04-22 10:48:28 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| 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. |
|
1999-04-22 10:48:28 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
2003-03-18 20:06:09 +08:00
|
|
|
|
| Authors: Stig S<EFBFBD>ther Bakken <ssb@php.net> |
|
2003-05-22 11:04:11 +08:00
|
|
|
|
| Thies C. Arntzen <thies@thieso.net> |
|
|
|
|
|
| Sterling Hughes <sterling@php.net> |
|
1999-04-22 10:48:28 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* $Id$ */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
#define IS_EXT_MODULE
|
1999-07-22 05:56:25 +08:00
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
#include "php.h"
|
2001-01-06 01:07:02 +08:00
|
|
|
|
|
2000-02-11 02:03:55 +08:00
|
|
|
|
#define PHP_XML_INTERNAL
|
1999-04-22 10:48:28 +08:00
|
|
|
|
#include "zend_variables.h"
|
1999-12-05 03:19:57 +08:00
|
|
|
|
#include "ext/standard/php_string.h"
|
2000-04-06 05:43:03 +08:00
|
|
|
|
#include "ext/standard/info.h"
|
2010-10-28 02:13:25 +08:00
|
|
|
|
#include "ext/standard/html.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2003-05-07 03:38:49 +08:00
|
|
|
|
#if HAVE_XML
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2003-05-07 03:38:49 +08:00
|
|
|
|
#include "php_xml.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
|
# include "ext/standard/head.h"
|
2003-10-20 07:17:56 +08:00
|
|
|
|
#ifdef LIBXML_EXPAT_COMPAT
|
|
|
|
|
#include "ext/libxml/php_libxml.h"
|
|
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
/* Short-term TODO list:
|
|
|
|
|
* - Implement XML_ExternalEntityParserCreate()
|
2001-12-14 17:42:39 +08:00
|
|
|
|
* - XML_SetCommentHandler
|
|
|
|
|
* - XML_SetCdataSectionHandler
|
|
|
|
|
* - XML_SetParamEntityParsing
|
1999-04-22 10:48:28 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Long-term TODO list:
|
|
|
|
|
* - Fix the expat library so you can install your own memory manager
|
|
|
|
|
* functions
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Known bugs:
|
|
|
|
|
* - Weird things happen with <![CDATA[]]> sections.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-06-16 02:33:09 +08:00
|
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(xml)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ dynamically loadable module stuff */
|
2000-05-23 17:33:51 +08:00
|
|
|
|
#ifdef COMPILE_DL_XML
|
2000-05-02 08:30:36 +08:00
|
|
|
|
ZEND_GET_MODULE(xml)
|
1999-12-04 22:45:38 +08:00
|
|
|
|
#endif /* COMPILE_DL_XML */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ function prototypes */
|
1999-09-20 20:51:20 +08:00
|
|
|
|
PHP_MINIT_FUNCTION(xml);
|
|
|
|
|
PHP_MINFO_FUNCTION(xml);
|
2006-06-16 02:33:09 +08:00
|
|
|
|
static PHP_GINIT_FUNCTION(xml);
|
1999-07-02 23:31:02 +08:00
|
|
|
|
|
2001-07-31 13:44:11 +08:00
|
|
|
|
static void xml_parser_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
2000-08-23 03:32:07 +08:00
|
|
|
|
static void xml_set_handler(zval **, zval **);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
inline static unsigned short xml_encode_iso_8859_1(unsigned char);
|
|
|
|
|
inline static char xml_decode_iso_8859_1(unsigned short);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
inline static unsigned short xml_encode_us_ascii(unsigned char);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
inline static char xml_decode_us_ascii(unsigned short);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
static zval *xml_call_handler(xml_parser *, zval *, zend_function *, int, zval **);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
static zval *_xml_xmlchar_zval(const XML_Char *, int, const XML_Char *);
|
|
|
|
|
static int _xml_xmlcharlen(const XML_Char *);
|
|
|
|
|
static void _xml_add_to_info(xml_parser *parser,char *name);
|
2001-08-13 02:44:42 +08:00
|
|
|
|
inline static char *_xml_decode_tag(xml_parser *parser, const char *tag);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2003-05-07 03:38:49 +08:00
|
|
|
|
void _xml_startElementHandler(void *, const XML_Char *, const XML_Char **);
|
|
|
|
|
void _xml_endElementHandler(void *, const XML_Char *);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
void _xml_characterDataHandler(void *, const XML_Char *, int);
|
|
|
|
|
void _xml_processingInstructionHandler(void *, const XML_Char *, const XML_Char *);
|
|
|
|
|
void _xml_defaultHandler(void *, const XML_Char *, int);
|
|
|
|
|
void _xml_unparsedEntityDeclHandler(void *, const XML_Char *, const XML_Char *, const XML_Char *, 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 *);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2001-01-05 14:36:51 +08:00
|
|
|
|
void _xml_startNamespaceDeclHandler(void *, const XML_Char *, const XML_Char *);
|
|
|
|
|
void _xml_endNamespaceDeclHandler(void *, const XML_Char *);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ extension definition structures */
|
2008-07-01 23:33:11 +08:00
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parser_create, 0, 0, 0)
|
|
|
|
|
ZEND_ARG_INFO(0, encoding)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parser_create_ns, 0, 0, 0)
|
|
|
|
|
ZEND_ARG_INFO(0, encoding)
|
|
|
|
|
ZEND_ARG_INFO(0, sep)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_object, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(1, obj)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_element_handler, 0, 0, 3)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, shdl)
|
|
|
|
|
ZEND_ARG_INFO(0, ehdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_character_data_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_processing_instruction_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_default_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_unparsed_entity_decl_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_notation_decl_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_external_entity_ref_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_start_namespace_decl_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_set_end_namespace_decl_handler, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, hdl)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parse, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, data)
|
|
|
|
|
ZEND_ARG_INFO(0, isfinal)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parse_into_struct, 0, 0, 3)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, data)
|
|
|
|
|
ZEND_ARG_INFO(1, values)
|
|
|
|
|
ZEND_ARG_INFO(1, index)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_get_error_code, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_error_string, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, code)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_get_current_line_number, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_get_current_column_number, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_get_current_byte_index, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parser_free, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parser_set_option, 0, 0, 3)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, option)
|
|
|
|
|
ZEND_ARG_INFO(0, value)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parser_get_option, 0, 0, 2)
|
|
|
|
|
ZEND_ARG_INFO(0, parser)
|
|
|
|
|
ZEND_ARG_INFO(0, option)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_utf8_encode, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, data)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_utf8_decode, 0, 0, 1)
|
|
|
|
|
ZEND_ARG_INFO(0, data)
|
|
|
|
|
ZEND_END_ARG_INFO()
|
2000-08-20 23:59:54 +08:00
|
|
|
|
|
2007-09-28 02:00:48 +08:00
|
|
|
|
const zend_function_entry xml_functions[] = {
|
2008-07-01 23:33:11 +08:00
|
|
|
|
PHP_FE(xml_parser_create, arginfo_xml_parser_create)
|
|
|
|
|
PHP_FE(xml_parser_create_ns, arginfo_xml_parser_create_ns)
|
|
|
|
|
PHP_FE(xml_set_object, arginfo_xml_set_object)
|
|
|
|
|
PHP_FE(xml_set_element_handler, arginfo_xml_set_element_handler)
|
|
|
|
|
PHP_FE(xml_set_character_data_handler, arginfo_xml_set_character_data_handler)
|
|
|
|
|
PHP_FE(xml_set_processing_instruction_handler, arginfo_xml_set_processing_instruction_handler)
|
|
|
|
|
PHP_FE(xml_set_default_handler, arginfo_xml_set_default_handler)
|
|
|
|
|
PHP_FE(xml_set_unparsed_entity_decl_handler,arginfo_xml_set_unparsed_entity_decl_handler)
|
|
|
|
|
PHP_FE(xml_set_notation_decl_handler, arginfo_xml_set_notation_decl_handler)
|
|
|
|
|
PHP_FE(xml_set_external_entity_ref_handler, arginfo_xml_set_external_entity_ref_handler)
|
|
|
|
|
PHP_FE(xml_set_start_namespace_decl_handler,arginfo_xml_set_start_namespace_decl_handler)
|
|
|
|
|
PHP_FE(xml_set_end_namespace_decl_handler, arginfo_xml_set_end_namespace_decl_handler)
|
|
|
|
|
PHP_FE(xml_parse, arginfo_xml_parse)
|
|
|
|
|
PHP_FE(xml_parse_into_struct, arginfo_xml_parse_into_struct)
|
|
|
|
|
PHP_FE(xml_get_error_code, arginfo_xml_get_error_code)
|
|
|
|
|
PHP_FE(xml_error_string, arginfo_xml_error_string)
|
|
|
|
|
PHP_FE(xml_get_current_line_number, arginfo_xml_get_current_line_number)
|
|
|
|
|
PHP_FE(xml_get_current_column_number, arginfo_xml_get_current_column_number)
|
|
|
|
|
PHP_FE(xml_get_current_byte_index, arginfo_xml_get_current_byte_index)
|
|
|
|
|
PHP_FE(xml_parser_free, arginfo_xml_parser_free)
|
|
|
|
|
PHP_FE(xml_parser_set_option, arginfo_xml_parser_set_option)
|
|
|
|
|
PHP_FE(xml_parser_get_option, arginfo_xml_parser_get_option)
|
|
|
|
|
PHP_FE(utf8_encode, arginfo_utf8_encode)
|
|
|
|
|
PHP_FE(utf8_decode, arginfo_utf8_decode)
|
2011-07-25 19:35:02 +08:00
|
|
|
|
PHP_FE_END
|
1999-04-22 10:48:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
2005-06-17 19:48:17 +08:00
|
|
|
|
#ifdef LIBXML_EXPAT_COMPAT
|
2007-09-28 02:00:48 +08:00
|
|
|
|
static const zend_module_dep xml_deps[] = {
|
2005-06-17 19:48:17 +08:00
|
|
|
|
ZEND_MOD_REQUIRED("libxml")
|
2011-08-06 22:47:44 +08:00
|
|
|
|
ZEND_MOD_END
|
2005-06-17 19:48:17 +08:00
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-12-18 04:55:31 +08:00
|
|
|
|
zend_module_entry xml_module_entry = {
|
2005-06-17 19:48:17 +08:00
|
|
|
|
#ifdef LIBXML_EXPAT_COMPAT
|
|
|
|
|
STANDARD_MODULE_HEADER_EX, NULL,
|
|
|
|
|
xml_deps,
|
|
|
|
|
#else
|
2001-10-12 07:33:59 +08:00
|
|
|
|
STANDARD_MODULE_HEADER,
|
2005-06-17 19:48:17 +08:00
|
|
|
|
#endif
|
2001-08-19 07:07:10 +08:00
|
|
|
|
"xml", /* extension name */
|
|
|
|
|
xml_functions, /* extension function list */
|
|
|
|
|
PHP_MINIT(xml), /* extension-wide startup function */
|
2005-02-08 06:16:46 +08:00
|
|
|
|
NULL, /* extension-wide shutdown function */
|
|
|
|
|
NULL, /* per-request startup function */
|
|
|
|
|
NULL, /* per-request shutdown function */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
PHP_MINFO(xml), /* information function */
|
2001-10-12 07:33:59 +08:00
|
|
|
|
NO_VERSION_YET,
|
2006-06-16 02:33:09 +08:00
|
|
|
|
PHP_MODULE_GLOBALS(xml), /* globals descriptor */
|
|
|
|
|
PHP_GINIT(xml), /* globals ctor */
|
|
|
|
|
NULL, /* globals dtor */
|
|
|
|
|
NULL, /* post deactivate */
|
|
|
|
|
STANDARD_MODULE_PROPERTIES_EX
|
1999-04-22 10:48:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* All the encoding functions are set to NULL right now, since all
|
|
|
|
|
* the encoding is currently done internally by expat/xmltok.
|
|
|
|
|
*/
|
|
|
|
|
xml_encoding xml_encodings[] = {
|
|
|
|
|
{ "ISO-8859-1", xml_decode_iso_8859_1, xml_encode_iso_8859_1 },
|
|
|
|
|
{ "US-ASCII", xml_decode_us_ascii, xml_encode_us_ascii },
|
|
|
|
|
{ "UTF-8", NULL, NULL },
|
2001-08-19 07:07:10 +08:00
|
|
|
|
{ NULL, NULL, NULL }
|
1999-04-22 10:48:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
2003-05-07 23:21:31 +08:00
|
|
|
|
static XML_Memory_Handling_Suite php_xml_mem_hdlrs;
|
|
|
|
|
|
1999-09-20 20:51:20 +08:00
|
|
|
|
/* True globals, no need for thread safety */
|
|
|
|
|
static int le_xml_parser;
|
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ startup, shutdown and info functions */
|
2006-06-16 02:33:09 +08:00
|
|
|
|
static PHP_GINIT_FUNCTION(xml)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
2006-06-16 02:33:09 +08:00
|
|
|
|
xml_globals->default_encoding = "UTF-8";
|
1999-09-20 20:51:20 +08:00
|
|
|
|
}
|
1999-08-18 23:40:54 +08:00
|
|
|
|
|
2003-05-07 23:21:31 +08:00
|
|
|
|
static void *php_xml_malloc_wrapper(size_t sz)
|
|
|
|
|
{
|
|
|
|
|
return emalloc(sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *php_xml_realloc_wrapper(void *ptr, size_t sz)
|
|
|
|
|
{
|
|
|
|
|
return erealloc(ptr, sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void php_xml_free_wrapper(void *ptr)
|
|
|
|
|
{
|
2003-12-08 15:15:32 +08:00
|
|
|
|
if (ptr != NULL) {
|
|
|
|
|
efree(ptr);
|
|
|
|
|
}
|
2003-05-07 23:21:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-20 20:51:20 +08:00
|
|
|
|
PHP_MINIT_FUNCTION(xml)
|
|
|
|
|
{
|
2000-10-26 01:44:02 +08:00
|
|
|
|
le_xml_parser = zend_register_list_destructors_ex(xml_parser_dtor, NULL, "xml", module_number);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_NONE", XML_ERROR_NONE, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_NO_MEMORY", XML_ERROR_NO_MEMORY, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_SYNTAX", XML_ERROR_SYNTAX, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_NO_ELEMENTS", XML_ERROR_NO_ELEMENTS, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_INVALID_TOKEN", XML_ERROR_INVALID_TOKEN, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_UNCLOSED_TOKEN", XML_ERROR_UNCLOSED_TOKEN, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_PARTIAL_CHAR", XML_ERROR_PARTIAL_CHAR, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_TAG_MISMATCH", XML_ERROR_TAG_MISMATCH, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_DUPLICATE_ATTRIBUTE", XML_ERROR_DUPLICATE_ATTRIBUTE, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_JUNK_AFTER_DOC_ELEMENT", XML_ERROR_JUNK_AFTER_DOC_ELEMENT, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_PARAM_ENTITY_REF", XML_ERROR_PARAM_ENTITY_REF, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_UNDEFINED_ENTITY", XML_ERROR_UNDEFINED_ENTITY, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_RECURSIVE_ENTITY_REF", XML_ERROR_RECURSIVE_ENTITY_REF, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_ASYNC_ENTITY", XML_ERROR_ASYNC_ENTITY, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_BAD_CHAR_REF", XML_ERROR_BAD_CHAR_REF, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_BINARY_ENTITY_REF", XML_ERROR_BINARY_ENTITY_REF, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF", XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_MISPLACED_XML_PI", XML_ERROR_MISPLACED_XML_PI, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_UNKNOWN_ENCODING", XML_ERROR_UNKNOWN_ENCODING, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_INCORRECT_ENCODING", XML_ERROR_INCORRECT_ENCODING, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_UNCLOSED_CDATA_SECTION", XML_ERROR_UNCLOSED_CDATA_SECTION, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_ERROR_EXTERNAL_ENTITY_HANDLING", XML_ERROR_EXTERNAL_ENTITY_HANDLING, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
|
1999-12-18 11:20:53 +08:00
|
|
|
|
REGISTER_LONG_CONSTANT("XML_OPTION_CASE_FOLDING", PHP_XML_OPTION_CASE_FOLDING, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_OPTION_TARGET_ENCODING", PHP_XML_OPTION_TARGET_ENCODING, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_TAGSTART", PHP_XML_OPTION_SKIP_TAGSTART, CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_WHITE", PHP_XML_OPTION_SKIP_WHITE, CONST_CS|CONST_PERSISTENT);
|
2003-05-07 03:38:49 +08:00
|
|
|
|
|
2003-05-07 23:21:31 +08:00
|
|
|
|
/* this object should not be pre-initialised at compile time,
|
|
|
|
|
as the order of members may vary */
|
|
|
|
|
|
|
|
|
|
php_xml_mem_hdlrs.malloc_fcn = php_xml_malloc_wrapper;
|
|
|
|
|
php_xml_mem_hdlrs.realloc_fcn = php_xml_realloc_wrapper;
|
|
|
|
|
php_xml_mem_hdlrs.free_fcn = php_xml_free_wrapper;
|
|
|
|
|
|
2003-11-05 00:15:52 +08:00
|
|
|
|
#ifdef LIBXML_EXPAT_COMPAT
|
|
|
|
|
REGISTER_STRING_CONSTANT("XML_SAX_IMPL", "libxml", CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
#else
|
|
|
|
|
REGISTER_STRING_CONSTANT("XML_SAX_IMPL", "expat", CONST_CS|CONST_PERSISTENT);
|
|
|
|
|
#endif
|
2003-12-17 01:14:06 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-20 20:51:20 +08:00
|
|
|
|
PHP_MINFO_FUNCTION(xml)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
2001-07-30 14:18:13 +08:00
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
php_info_print_table_row(2, "XML Support", "active");
|
|
|
|
|
php_info_print_table_row(2, "XML Namespace Support", "active");
|
2003-11-05 00:15:52 +08:00
|
|
|
|
#if defined(LIBXML_DOTTED_VERSION) && defined(LIBXML_EXPAT_COMPAT)
|
2003-05-25 15:23:41 +08:00
|
|
|
|
php_info_print_table_row(2, "libxml2 Version", LIBXML_DOTTED_VERSION);
|
|
|
|
|
#else
|
|
|
|
|
php_info_print_table_row(2, "EXPAT Version", XML_ExpatVersion());
|
|
|
|
|
#endif
|
2001-07-30 14:18:13 +08:00
|
|
|
|
php_info_print_table_end();
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ extension-internal functions */
|
1999-10-01 21:44:07 +08:00
|
|
|
|
static zval *_xml_resource_zval(long value)
|
|
|
|
|
{
|
|
|
|
|
zval *ret;
|
2001-07-30 12:58:07 +08:00
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
|
1999-10-01 21:44:07 +08:00
|
|
|
|
MAKE_STD_ZVAL(ret);
|
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
Z_TYPE_P(ret) = IS_RESOURCE;
|
|
|
|
|
Z_LVAL_P(ret) = value;
|
1999-10-01 21:44:07 +08:00
|
|
|
|
|
1999-10-07 20:27:40 +08:00
|
|
|
|
zend_list_addref(value);
|
|
|
|
|
|
1999-10-01 21:44:07 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static zval *_xml_string_zval(const char *str)
|
|
|
|
|
{
|
|
|
|
|
zval *ret;
|
|
|
|
|
int len = strlen(str);
|
|
|
|
|
MAKE_STD_ZVAL(ret);
|
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
Z_TYPE_P(ret) = IS_STRING;
|
|
|
|
|
Z_STRLEN_P(ret) = len;
|
|
|
|
|
Z_STRVAL_P(ret) = estrndup(str, len);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static zval *_xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encoding)
|
|
|
|
|
{
|
|
|
|
|
zval *ret;
|
|
|
|
|
MAKE_STD_ZVAL(ret);
|
|
|
|
|
|
|
|
|
|
if (s == NULL) {
|
2001-07-11 20:42:25 +08:00
|
|
|
|
ZVAL_FALSE(ret);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
if (len == 0) {
|
|
|
|
|
len = _xml_xmlcharlen(s);
|
|
|
|
|
}
|
2001-09-26 05:58:48 +08:00
|
|
|
|
Z_TYPE_P(ret) = IS_STRING;
|
|
|
|
|
Z_STRVAL_P(ret) = xml_utf8_decode(s, len, &Z_STRLEN_P(ret), encoding);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-12-06 00:43:42 +08:00
|
|
|
|
/* {{{ xml_parser_dtor() */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
static void xml_parser_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
|
xml_parser *parser = (xml_parser *)rsrc->ptr;
|
1999-12-06 00:43:42 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (parser->parser) {
|
|
|
|
|
XML_ParserFree(parser->parser);
|
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
if (parser->ltags) {
|
1999-10-20 22:02:32 +08:00
|
|
|
|
int inx;
|
|
|
|
|
for (inx = 0; inx < parser->level; inx++)
|
|
|
|
|
efree(parser->ltags[ inx ]);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
efree(parser->ltags);
|
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (parser->startElementHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->startElementHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->endElementHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->endElementHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->characterDataHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->characterDataHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->processingInstructionHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->processingInstructionHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->defaultHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->defaultHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->unparsedEntityDeclHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->unparsedEntityDeclHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->notationDeclHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->notationDeclHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->externalEntityRefHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->externalEntityRefHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->unknownEncodingHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->unknownEncodingHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2001-01-05 14:36:51 +08:00
|
|
|
|
if (parser->startNamespaceDeclHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->startNamespaceDeclHandler);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
if (parser->endNamespaceDeclHandler) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->endNamespaceDeclHandler);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (parser->baseURI) {
|
|
|
|
|
efree(parser->baseURI);
|
|
|
|
|
}
|
2004-04-08 00:24:17 +08:00
|
|
|
|
if (parser->object) {
|
|
|
|
|
zval_ptr_dtor(&parser->object);
|
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
efree(parser);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_set_handler() */
|
|
|
|
|
static void xml_set_handler(zval **handler, zval **data)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
2002-04-13 13:06:33 +08:00
|
|
|
|
/* If we have already a handler, release it */
|
|
|
|
|
if (*handler) {
|
|
|
|
|
zval_ptr_dtor(handler);
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-03 04:05:13 +08:00
|
|
|
|
/* IS_ARRAY might indicate that we're using array($obj, 'method') syntax */
|
2008-07-17 17:53:42 +08:00
|
|
|
|
if (Z_TYPE_PP(data) != IS_ARRAY && Z_TYPE_PP(data) != IS_OBJECT) {
|
2006-08-16 06:47:11 +08:00
|
|
|
|
|
2003-07-03 04:05:13 +08:00
|
|
|
|
convert_to_string_ex(data);
|
2006-08-16 06:47:11 +08:00
|
|
|
|
if (Z_STRLEN_PP(data) == 0) {
|
|
|
|
|
*handler = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-07-03 04:05:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 21:34:50 +08:00
|
|
|
|
zval_add_ref(data);
|
|
|
|
|
|
2000-08-23 03:32:07 +08:00
|
|
|
|
*handler = *data;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_call_handler() */
|
2003-05-22 11:04:11 +08:00
|
|
|
|
static zval *xml_call_handler(xml_parser *parser, zval *handler, zend_function *function_ptr, int argc, zval **argv)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
2005-03-11 09:11:54 +08:00
|
|
|
|
int i;
|
2001-07-27 18:16:41 +08:00
|
|
|
|
TSRMLS_FETCH();
|
1999-05-27 09:34:18 +08:00
|
|
|
|
|
2005-03-11 09:11:54 +08:00
|
|
|
|
if (parser && handler && !EG(exception)) {
|
2003-05-22 11:04:11 +08:00
|
|
|
|
zval ***args;
|
2000-08-23 03:32:07 +08:00
|
|
|
|
zval *retval;
|
1999-09-25 02:02:58 +08:00
|
|
|
|
int result;
|
2003-08-05 18:29:03 +08:00
|
|
|
|
zend_fcall_info fci;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2003-08-12 08:58:52 +08:00
|
|
|
|
args = safe_emalloc(sizeof(zval **), argc, 0);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
args[i] = &argv[i];
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-05 18:29:03 +08:00
|
|
|
|
fci.size = sizeof(fci);
|
|
|
|
|
fci.function_table = EG(function_table);
|
|
|
|
|
fci.function_name = handler;
|
|
|
|
|
fci.symbol_table = NULL;
|
2008-11-28 03:01:23 +08:00
|
|
|
|
fci.object_ptr = parser->object;
|
2003-08-05 18:29:03 +08:00
|
|
|
|
fci.retval_ptr_ptr = &retval;
|
|
|
|
|
fci.param_count = argc;
|
|
|
|
|
fci.params = args;
|
|
|
|
|
fci.no_separation = 0;
|
|
|
|
|
/*fci.function_handler_cache = &function_ptr;*/
|
|
|
|
|
|
|
|
|
|
result = zend_call_function(&fci, NULL TSRMLS_CC);
|
1999-09-25 02:02:58 +08:00
|
|
|
|
if (result == FAILURE) {
|
2000-08-23 03:32:07 +08:00
|
|
|
|
zval **method;
|
|
|
|
|
zval **obj;
|
|
|
|
|
|
|
|
|
|
if (Z_TYPE_P(handler) == IS_STRING) {
|
2002-12-06 05:53:25 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(handler));
|
2001-09-26 05:58:48 +08:00
|
|
|
|
} else if (zend_hash_index_find(Z_ARRVAL_P(handler), 0, (void **) &obj) == SUCCESS &&
|
|
|
|
|
zend_hash_index_find(Z_ARRVAL_P(handler), 1, (void **) &method) == SUCCESS &&
|
2000-08-23 03:32:07 +08:00
|
|
|
|
Z_TYPE_PP(obj) == IS_OBJECT &&
|
|
|
|
|
Z_TYPE_PP(method) == IS_STRING) {
|
2002-12-06 05:53:25 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s::%s()", Z_OBJCE_PP(obj)->name, Z_STRVAL_PP(method));
|
2001-08-19 07:07:10 +08:00
|
|
|
|
} else
|
2002-12-06 05:53:25 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler");
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-10-07 20:27:40 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
for (i = 0; i < argc; i++) {
|
2003-05-22 11:04:11 +08:00
|
|
|
|
zval_ptr_dtor(args[i]);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2003-05-22 11:04:11 +08:00
|
|
|
|
efree(args);
|
1999-10-07 20:27:40 +08:00
|
|
|
|
|
1999-09-25 02:02:58 +08:00
|
|
|
|
if (result == FAILURE) {
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
2005-03-11 09:11:54 +08:00
|
|
|
|
return EG(exception) ? NULL : retval;
|
1999-09-25 02:02:58 +08:00
|
|
|
|
}
|
2005-03-11 09:11:54 +08:00
|
|
|
|
} else {
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
zval_ptr_dtor(&argv[i]);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_encode_iso_8859_1() */
|
|
|
|
|
inline static unsigned short xml_encode_iso_8859_1(unsigned char c)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
return (unsigned short)c;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_decode_iso_8859_1() */
|
|
|
|
|
inline static char xml_decode_iso_8859_1(unsigned short c)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
return (char)(c > 0xff ? '?' : c);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_encode_us_ascii() */
|
|
|
|
|
inline static unsigned short xml_encode_us_ascii(unsigned char c)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
return (unsigned short)c;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_decode_us_ascii() */
|
|
|
|
|
inline static char xml_decode_us_ascii(unsigned short c)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
return (char)(c > 0x7f ? '?' : c);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ xml_get_encoding() */
|
|
|
|
|
static xml_encoding *xml_get_encoding(const XML_Char *name)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_encoding *enc = &xml_encodings[0];
|
|
|
|
|
|
|
|
|
|
while (enc && enc->name) {
|
|
|
|
|
if (strcasecmp(name, enc->name) == 0) {
|
|
|
|
|
return enc;
|
|
|
|
|
}
|
|
|
|
|
enc++;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ xml_utf8_encode */
|
2006-08-02 23:21:54 +08:00
|
|
|
|
PHPAPI char *xml_utf8_encode(const char *s, int len, int *newlen, const XML_Char *encoding)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
int pos = len;
|
|
|
|
|
char *newbuf;
|
2004-01-17 03:11:33 +08:00
|
|
|
|
unsigned int c;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
unsigned short (*encoder)(unsigned char) = NULL;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_encoding *enc = xml_get_encoding(encoding);
|
|
|
|
|
|
|
|
|
|
*newlen = 0;
|
|
|
|
|
if (enc) {
|
|
|
|
|
encoder = enc->encoding_function;
|
|
|
|
|
} else {
|
|
|
|
|
/* If the target encoding was unknown, fail */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (encoder == NULL) {
|
|
|
|
|
/* If no encoder function was specified, return the data as-is.
|
|
|
|
|
*/
|
2001-08-19 07:43:04 +08:00
|
|
|
|
newbuf = emalloc(len + 1);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
memcpy(newbuf, s, len);
|
|
|
|
|
*newlen = len;
|
2001-08-19 07:43:04 +08:00
|
|
|
|
newbuf[*newlen] = '\0';
|
1999-04-22 10:48:28 +08:00
|
|
|
|
return newbuf;
|
|
|
|
|
}
|
|
|
|
|
/* This is the theoretical max (will never get beyond len * 2 as long
|
|
|
|
|
* as we are converting from single-byte characters, though) */
|
2003-08-12 08:58:52 +08:00
|
|
|
|
newbuf = safe_emalloc(len, 4, 1);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
while (pos > 0) {
|
|
|
|
|
c = encoder ? encoder((unsigned char)(*s)) : (unsigned short)(*s);
|
|
|
|
|
if (c < 0x80) {
|
2000-02-03 02:42:04 +08:00
|
|
|
|
newbuf[(*newlen)++] = (char) c;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
} else if (c < 0x800) {
|
|
|
|
|
newbuf[(*newlen)++] = (0xc0 | (c >> 6));
|
|
|
|
|
newbuf[(*newlen)++] = (0x80 | (c & 0x3f));
|
|
|
|
|
} else if (c < 0x10000) {
|
|
|
|
|
newbuf[(*newlen)++] = (0xe0 | (c >> 12));
|
|
|
|
|
newbuf[(*newlen)++] = (0xc0 | ((c >> 6) & 0x3f));
|
|
|
|
|
newbuf[(*newlen)++] = (0x80 | (c & 0x3f));
|
|
|
|
|
} else if (c < 0x200000) {
|
|
|
|
|
newbuf[(*newlen)++] = (0xf0 | (c >> 18));
|
|
|
|
|
newbuf[(*newlen)++] = (0xe0 | ((c >> 12) & 0x3f));
|
|
|
|
|
newbuf[(*newlen)++] = (0xc0 | ((c >> 6) & 0x3f));
|
|
|
|
|
newbuf[(*newlen)++] = (0x80 | (c & 0x3f));
|
|
|
|
|
}
|
|
|
|
|
pos--;
|
|
|
|
|
s++;
|
2001-08-19 07:07:10 +08:00
|
|
|
|
}
|
2001-07-09 14:49:34 +08:00
|
|
|
|
newbuf[*newlen] = 0;
|
|
|
|
|
newbuf = erealloc(newbuf, (*newlen)+1);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
return newbuf;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ xml_utf8_decode */
|
|
|
|
|
PHPAPI char *xml_utf8_decode(const XML_Char *s, int len, int *newlen, const XML_Char *encoding)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
2010-10-28 02:13:25 +08:00
|
|
|
|
size_t pos = 0;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
char *newbuf = emalloc(len + 1);
|
2009-08-27 13:05:42 +08:00
|
|
|
|
unsigned int c;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
char (*decoder)(unsigned short) = NULL;
|
|
|
|
|
xml_encoding *enc = xml_get_encoding(encoding);
|
|
|
|
|
|
|
|
|
|
*newlen = 0;
|
|
|
|
|
if (enc) {
|
|
|
|
|
decoder = enc->decoding_function;
|
|
|
|
|
}
|
|
|
|
|
if (decoder == NULL) {
|
|
|
|
|
/* If the target encoding was unknown, or no decoder function
|
|
|
|
|
* was specified, return the UTF-8-encoded data as-is.
|
|
|
|
|
*/
|
|
|
|
|
memcpy(newbuf, s, len);
|
|
|
|
|
*newlen = len;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
newbuf[*newlen] = '\0';
|
1999-04-22 10:48:28 +08:00
|
|
|
|
return newbuf;
|
|
|
|
|
}
|
2010-10-28 02:13:25 +08:00
|
|
|
|
|
|
|
|
|
while (pos < (size_t)len) {
|
|
|
|
|
int status = FAILURE;
|
|
|
|
|
c = php_next_utf8_char((const unsigned char*)s, (size_t) len, &pos, &status);
|
|
|
|
|
|
|
|
|
|
if (status == FAILURE || c > 0xFFU) {
|
|
|
|
|
c = '?';
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2010-10-28 02:13:25 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
newbuf[*newlen] = decoder ? decoder(c) : c;
|
|
|
|
|
++*newlen;
|
2001-08-19 07:07:10 +08:00
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (*newlen < len) {
|
1999-05-21 18:06:25 +08:00
|
|
|
|
newbuf = erealloc(newbuf, *newlen + 1);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
newbuf[*newlen] = '\0';
|
1999-04-22 10:48:28 +08:00
|
|
|
|
return newbuf;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_xmlcharlen() */
|
1999-10-01 21:44:07 +08:00
|
|
|
|
static int _xml_xmlcharlen(const XML_Char *s)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
|
|
while (*s) {
|
|
|
|
|
len++;
|
|
|
|
|
s++;
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
1999-07-21 22:43:12 +08:00
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_zval_strdup() */
|
1999-10-01 21:44:07 +08:00
|
|
|
|
PHPAPI char *_xml_zval_strdup(zval *val)
|
1999-07-21 22:43:12 +08:00
|
|
|
|
{
|
2001-09-26 05:58:48 +08:00
|
|
|
|
if (Z_TYPE_P(val) == IS_STRING) {
|
|
|
|
|
char *buf = emalloc(Z_STRLEN_P(val) + 1);
|
|
|
|
|
memcpy(buf, Z_STRVAL_P(val), Z_STRLEN_P(val));
|
|
|
|
|
buf[Z_STRLEN_P(val)] = '\0';
|
1999-07-21 22:43:12 +08:00
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ _xml_add_to_info */
|
1999-10-01 21:44:07 +08:00
|
|
|
|
static void _xml_add_to_info(xml_parser *parser,char *name)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
{
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval **element, *values;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
|
|
|
|
if (! parser->info) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
if (zend_hash_find(Z_ARRVAL_P(parser->info),name,strlen(name) + 1,(void **) &element) == FAILURE) {
|
1999-10-01 21:44:07 +08:00
|
|
|
|
MAKE_STD_ZVAL(values);
|
|
|
|
|
|
2003-01-19 03:28:10 +08:00
|
|
|
|
array_init(values);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
zend_hash_update(Z_ARRVAL_P(parser->info), name, strlen(name)+1, (void *) &values, sizeof(zval*), (void **) &element);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 23:31:02 +08:00
|
|
|
|
add_next_index_long(*element,parser->curtag);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
|
|
|
|
parser->curtag++;
|
|
|
|
|
}
|
2001-08-13 02:44:42 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_decode_tag() */
|
2001-08-13 02:44:42 +08:00
|
|
|
|
static char *_xml_decode_tag(xml_parser *parser, const char *tag)
|
|
|
|
|
{
|
|
|
|
|
char *newstr;
|
|
|
|
|
int out_len;
|
|
|
|
|
|
|
|
|
|
newstr = xml_utf8_decode(tag, strlen(tag), &out_len, parser->target_encoding);
|
|
|
|
|
|
|
|
|
|
if (parser->case_folding) {
|
|
|
|
|
php_strtoupper(newstr, out_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newstr;
|
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_startElementHandler() */
|
2003-05-07 03:38:49 +08:00
|
|
|
|
void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Char **attributes)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
2003-05-27 08:50:00 +08:00
|
|
|
|
const char **attrs = (const char **) attributes;
|
2001-08-13 02:44:42 +08:00
|
|
|
|
char *tag_name;
|
|
|
|
|
char *att, *val;
|
2001-08-13 02:57:35 +08:00
|
|
|
|
int val_len;
|
2001-08-13 02:44:42 +08:00
|
|
|
|
zval *retval, *args[3];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
if (parser) {
|
|
|
|
|
parser->level++;
|
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
tag_name = _xml_decode_tag(parser, name);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
|
|
|
|
if (parser->startElementHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
2010-01-05 21:03:40 +08:00
|
|
|
|
args[1] = _xml_string_zval(((char *) tag_name) + parser->toffset);
|
1999-08-08 19:37:50 +08:00
|
|
|
|
MAKE_STD_ZVAL(args[2]);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
array_init(args[2]);
|
2001-08-13 02:44:42 +08:00
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
while (attributes && *attributes) {
|
2001-08-13 02:44:42 +08:00
|
|
|
|
att = _xml_decode_tag(parser, attributes[0]);
|
|
|
|
|
val = xml_utf8_decode(attributes[1], strlen(attributes[1]), &val_len, parser->target_encoding);
|
|
|
|
|
|
|
|
|
|
add_assoc_stringl(args[2], att, val, val_len, 0);
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
attributes += 2;
|
2001-08-13 02:44:42 +08:00
|
|
|
|
|
|
|
|
|
efree(att);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->startElementHandler, parser->startElementPtr, 3, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser->data) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *tag, *atr;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
int atcnt = 0;
|
|
|
|
|
|
1999-10-01 21:44:07 +08:00
|
|
|
|
MAKE_STD_ZVAL(tag);
|
|
|
|
|
MAKE_STD_ZVAL(atr);
|
1999-07-02 23:45:52 +08:00
|
|
|
|
|
1999-07-02 23:31:02 +08:00
|
|
|
|
array_init(tag);
|
|
|
|
|
array_init(atr);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
_xml_add_to_info(parser,((char *) tag_name) + parser->toffset);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
add_assoc_string(tag,"tag",((char *) tag_name) + parser->toffset,1); /* cast to avoid gcc-warning */
|
1999-07-02 23:31:02 +08:00
|
|
|
|
add_assoc_string(tag,"type","open",1);
|
|
|
|
|
add_assoc_long(tag,"level",parser->level);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
parser->ltags[parser->level-1] = estrdup(tag_name);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
parser->lastwasopen = 1;
|
|
|
|
|
|
2003-05-27 08:50:00 +08:00
|
|
|
|
attributes = (const XML_Char **) attrs;
|
2001-08-13 02:44:42 +08:00
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
while (attributes && *attributes) {
|
2001-08-13 02:44:42 +08:00
|
|
|
|
att = _xml_decode_tag(parser, attributes[0]);
|
|
|
|
|
val = xml_utf8_decode(attributes[1], strlen(attributes[1]), &val_len, parser->target_encoding);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
add_assoc_stringl(atr,att,val,val_len,0);
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
atcnt++;
|
|
|
|
|
attributes += 2;
|
2001-08-13 02:44:42 +08:00
|
|
|
|
|
|
|
|
|
efree(att);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (atcnt) {
|
2001-09-26 05:58:48 +08:00
|
|
|
|
zend_hash_add(Z_ARRVAL_P(tag),"attributes",sizeof("attributes"),&atr,sizeof(zval*),NULL);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
} else {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&atr);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
zend_hash_next_index_insert(Z_ARRVAL_P(parser->data),&tag,sizeof(zval*),(void *) &parser->ctag);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
efree(tag_name);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_endElementHandler() */
|
2003-05-07 03:38:49 +08:00
|
|
|
|
void _xml_endElementHandler(void *userData, const XML_Char *name)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
2001-08-13 02:44:42 +08:00
|
|
|
|
char *tag_name;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
if (parser) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *retval, *args[2];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
tag_name = _xml_decode_tag(parser, name);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
|
|
|
|
if (parser->endElementHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
2010-01-05 21:03:40 +08:00
|
|
|
|
args[1] = _xml_string_zval(((char *) tag_name) + parser->toffset);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->endElementHandler, parser->endElementPtr, 2, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser->data) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *tag;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
|
|
|
|
if (parser->lastwasopen) {
|
1999-07-02 23:31:02 +08:00
|
|
|
|
add_assoc_string(*(parser->ctag),"type","complete",1);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
} else {
|
1999-10-01 21:44:07 +08:00
|
|
|
|
MAKE_STD_ZVAL(tag);
|
1999-07-02 23:31:02 +08:00
|
|
|
|
|
|
|
|
|
array_init(tag);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
_xml_add_to_info(parser,((char *) tag_name) + parser->toffset);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
add_assoc_string(tag,"tag",((char *) tag_name) + parser->toffset,1); /* cast to avoid gcc-warning */
|
1999-07-02 23:31:02 +08:00
|
|
|
|
add_assoc_string(tag,"type","close",1);
|
|
|
|
|
add_assoc_long(tag,"level",parser->level);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
zend_hash_next_index_insert(Z_ARRVAL_P(parser->data),&tag,sizeof(zval*),NULL);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parser->lastwasopen = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2001-08-13 02:44:42 +08:00
|
|
|
|
efree(tag_name);
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
if (parser->ltags) {
|
|
|
|
|
efree(parser->ltags[parser->level-1]);
|
|
|
|
|
}
|
2001-08-13 02:44:42 +08:00
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
parser->level--;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_characterDataHandler() */
|
1999-10-01 21:44:07 +08:00
|
|
|
|
void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
if (parser) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *retval, *args[2];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
if (parser->characterDataHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
args[1] = _xml_xmlchar_zval(s, len, parser->target_encoding);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->characterDataHandler, parser->characterDataPtr, 2, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser->data) {
|
|
|
|
|
int i;
|
|
|
|
|
int doprint = 0;
|
|
|
|
|
|
|
|
|
|
char *decoded_value;
|
|
|
|
|
int decoded_len;
|
|
|
|
|
|
|
|
|
|
decoded_value = xml_utf8_decode(s,len,&decoded_len,parser->target_encoding);
|
|
|
|
|
for (i = 0; i < decoded_len; i++) {
|
|
|
|
|
switch (decoded_value[i]) {
|
|
|
|
|
case ' ':
|
|
|
|
|
case '\t':
|
|
|
|
|
case '\n':
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
|
|
|
|
doprint = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (doprint) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (doprint || (! parser->skipwhite)) {
|
|
|
|
|
if (parser->lastwasopen) {
|
1999-10-20 22:58:03 +08:00
|
|
|
|
zval **myval;
|
|
|
|
|
|
|
|
|
|
/* check if the current tag already has a value - if yes append to that! */
|
2001-09-26 06:49:04 +08:00
|
|
|
|
if (zend_hash_find(Z_ARRVAL_PP(parser->ctag),"value",sizeof("value"),(void **) &myval) == SUCCESS) {
|
2001-09-26 05:58:48 +08:00
|
|
|
|
int newlen = Z_STRLEN_PP(myval) + decoded_len;
|
|
|
|
|
Z_STRVAL_PP(myval) = erealloc(Z_STRVAL_PP(myval),newlen+1);
|
2011-08-09 20:16:58 +08:00
|
|
|
|
strncpy(Z_STRVAL_PP(myval) + Z_STRLEN_PP(myval), decoded_value, decoded_len + 1);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
Z_STRLEN_PP(myval) += decoded_len;
|
1999-10-20 22:58:03 +08:00
|
|
|
|
efree(decoded_value);
|
|
|
|
|
} else {
|
|
|
|
|
add_assoc_string(*(parser->ctag),"value",decoded_value,0);
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
} else {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *tag;
|
2006-08-16 06:47:11 +08:00
|
|
|
|
zval **curtag, **mytype, **myval;
|
|
|
|
|
HashPosition hpos=NULL;
|
|
|
|
|
|
|
|
|
|
zend_hash_internal_pointer_end_ex(Z_ARRVAL_P(parser->data), &hpos);
|
|
|
|
|
|
|
|
|
|
if (hpos && (zend_hash_get_current_data_ex(Z_ARRVAL_P(parser->data), (void **) &curtag, &hpos) == SUCCESS)) {
|
|
|
|
|
if (zend_hash_find(Z_ARRVAL_PP(curtag),"type",sizeof("type"),(void **) &mytype) == SUCCESS) {
|
|
|
|
|
if (!strcmp(Z_STRVAL_PP(mytype), "cdata")) {
|
|
|
|
|
if (zend_hash_find(Z_ARRVAL_PP(curtag),"value",sizeof("value"),(void **) &myval) == SUCCESS) {
|
|
|
|
|
int newlen = Z_STRLEN_PP(myval) + decoded_len;
|
|
|
|
|
Z_STRVAL_PP(myval) = erealloc(Z_STRVAL_PP(myval),newlen+1);
|
2011-08-09 20:16:58 +08:00
|
|
|
|
strncpy(Z_STRVAL_PP(myval) + Z_STRLEN_PP(myval), decoded_value, decoded_len + 1);
|
2006-08-16 06:47:11 +08:00
|
|
|
|
Z_STRLEN_PP(myval) += decoded_len;
|
|
|
|
|
efree(decoded_value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-02 23:31:02 +08:00
|
|
|
|
|
1999-10-01 21:44:07 +08:00
|
|
|
|
MAKE_STD_ZVAL(tag);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
1999-07-02 23:31:02 +08:00
|
|
|
|
array_init(tag);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
1999-10-01 21:44:07 +08:00
|
|
|
|
_xml_add_to_info(parser,parser->ltags[parser->level-1] + parser->toffset);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
1999-07-02 23:31:02 +08:00
|
|
|
|
add_assoc_string(tag,"tag",parser->ltags[parser->level-1] + parser->toffset,1);
|
|
|
|
|
add_assoc_string(tag,"value",decoded_value,0);
|
|
|
|
|
add_assoc_string(tag,"type","cdata",1);
|
|
|
|
|
add_assoc_long(tag,"level",parser->level);
|
1999-10-20 22:58:03 +08:00
|
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
|
zend_hash_next_index_insert(Z_ARRVAL_P(parser->data),&tag,sizeof(zval*),NULL);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
efree(decoded_value);
|
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_processingInstructionHandler() */
|
|
|
|
|
void _xml_processingInstructionHandler(void *userData, const XML_Char *target, const XML_Char *data)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
|
|
|
|
|
|
|
|
|
if (parser && parser->processingInstructionHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *retval, *args[3];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
args[1] = _xml_xmlchar_zval(target, 0, parser->target_encoding);
|
|
|
|
|
args[2] = _xml_xmlchar_zval(data, 0, parser->target_encoding);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->processingInstructionHandler, parser->processingInstructionPtr, 3, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_defaultHandler() */
|
1999-10-01 21:44:07 +08:00
|
|
|
|
void _xml_defaultHandler(void *userData, const XML_Char *s, int len)
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
|
|
|
|
|
|
|
|
|
if (parser && parser->defaultHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *retval, *args[2];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
args[1] = _xml_xmlchar_zval(s, len, parser->target_encoding);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->defaultHandler, parser->defaultPtr, 2, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_unparsedEntityDeclHandler() */
|
|
|
|
|
void _xml_unparsedEntityDeclHandler(void *userData,
|
|
|
|
|
const XML_Char *entityName,
|
1999-04-22 10:48:28 +08:00
|
|
|
|
const XML_Char *base,
|
|
|
|
|
const XML_Char *systemId,
|
|
|
|
|
const XML_Char *publicId,
|
|
|
|
|
const XML_Char *notationName)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
|
|
|
|
|
|
|
|
|
if (parser && parser->unparsedEntityDeclHandler) {
|
1999-12-15 02:37:14 +08:00
|
|
|
|
zval *retval, *args[6];
|
1999-09-26 00:42:31 +08:00
|
|
|
|
|
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
args[1] = _xml_xmlchar_zval(entityName, 0, parser->target_encoding);
|
|
|
|
|
args[2] = _xml_xmlchar_zval(base, 0, parser->target_encoding);
|
|
|
|
|
args[3] = _xml_xmlchar_zval(systemId, 0, parser->target_encoding);
|
|
|
|
|
args[4] = _xml_xmlchar_zval(publicId, 0, parser->target_encoding);
|
|
|
|
|
args[5] = _xml_xmlchar_zval(notationName, 0, parser->target_encoding);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->unparsedEntityDeclHandler, parser->unparsedEntityDeclPtr, 6, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_notationDeclHandler() */
|
|
|
|
|
void _xml_notationDeclHandler(void *userData,
|
1999-04-22 10:48:28 +08:00
|
|
|
|
const XML_Char *notationName,
|
|
|
|
|
const XML_Char *base,
|
|
|
|
|
const XML_Char *systemId,
|
|
|
|
|
const XML_Char *publicId)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = (xml_parser *)userData;
|
|
|
|
|
|
|
|
|
|
if (parser && parser->notationDeclHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *retval, *args[5];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
args[1] = _xml_xmlchar_zval(notationName, 0, parser->target_encoding);
|
|
|
|
|
args[2] = _xml_xmlchar_zval(base, 0, parser->target_encoding);
|
|
|
|
|
args[3] = _xml_xmlchar_zval(systemId, 0, parser->target_encoding);
|
|
|
|
|
args[4] = _xml_xmlchar_zval(publicId, 0, parser->target_encoding);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->notationDeclHandler, parser->notationDeclPtr, 5, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_externalEntityRefHandler() */
|
|
|
|
|
int _xml_externalEntityRefHandler(XML_Parser parserPtr,
|
1999-04-22 10:48:28 +08:00
|
|
|
|
const XML_Char *openEntityNames,
|
|
|
|
|
const XML_Char *base,
|
|
|
|
|
const XML_Char *systemId,
|
|
|
|
|
const XML_Char *publicId)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser = XML_GetUserData(parserPtr);
|
|
|
|
|
int ret = 0; /* abort if no handler is set (should be configurable?) */
|
|
|
|
|
|
|
|
|
|
if (parser && parser->externalEntityRefHandler) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval *retval, *args[5];
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
1999-09-26 00:42:31 +08:00
|
|
|
|
args[0] = _xml_resource_zval(parser->index);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
args[1] = _xml_xmlchar_zval(openEntityNames, 0, parser->target_encoding);
|
|
|
|
|
args[2] = _xml_xmlchar_zval(base, 0, parser->target_encoding);
|
|
|
|
|
args[3] = _xml_xmlchar_zval(systemId, 0, parser->target_encoding);
|
|
|
|
|
args[4] = _xml_xmlchar_zval(publicId, 0, parser->target_encoding);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->externalEntityRefHandler, parser->externalEntityRefPtr, 5, args))) {
|
1999-04-22 10:48:28 +08:00
|
|
|
|
convert_to_long(retval);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
ret = Z_LVAL_P(retval);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
efree(retval);
|
|
|
|
|
} else {
|
|
|
|
|
ret = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2001-01-05 14:36:51 +08:00
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_startNamespaceDeclHandler() */
|
|
|
|
|
void _xml_startNamespaceDeclHandler(void *userData,const XML_Char *prefix, const XML_Char *uri)
|
2001-01-05 14:36:51 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->startNamespaceDeclHandler, parser->startNamespaceDeclPtr, 3, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-08-19 07:07:10 +08:00
|
|
|
|
/* {{{ _xml_endNamespaceDeclHandler() */
|
|
|
|
|
void _xml_endNamespaceDeclHandler(void *userData, const XML_Char *prefix)
|
2001-01-05 14:36:51 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
2003-05-22 11:04:11 +08:00
|
|
|
|
if ((retval = xml_call_handler(parser, parser->endNamespaceDeclHandler, parser->endNamespaceDeclPtr, 2, args))) {
|
2003-05-22 11:08:48 +08:00
|
|
|
|
zval_ptr_dtor(&retval);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
/************************* EXTENSION FUNCTIONS *************************/
|
|
|
|
|
|
2008-07-17 18:24:51 +08:00
|
|
|
|
static void php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAMETERS, int ns_support) /* {{{ */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2003-05-11 17:04:05 +08:00
|
|
|
|
int auto_detect = 0;
|
|
|
|
|
|
|
|
|
|
char *encoding_param = NULL;
|
|
|
|
|
int encoding_param_len = 0;
|
|
|
|
|
|
|
|
|
|
char *ns_param = NULL;
|
|
|
|
|
int ns_param_len = 0;
|
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
XML_Char *encoding;
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2003-05-11 17:04:05 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, (ns_support ? "|ss": "|s"), &encoding_param, &encoding_param_len, &ns_param, &ns_param_len) == FAILURE) {
|
|
|
|
|
RETURN_FALSE;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-11 17:04:05 +08:00
|
|
|
|
if (encoding_param != NULL) {
|
1999-04-22 10:48:28 +08:00
|
|
|
|
/* The supported encoding types are hardcoded here because
|
|
|
|
|
* we are limited to the encodings supported by expat/xmltok.
|
|
|
|
|
*/
|
2003-05-11 17:04:05 +08:00
|
|
|
|
if (encoding_param_len == 0) {
|
|
|
|
|
encoding = XML(default_encoding);
|
|
|
|
|
auto_detect = 1;
|
|
|
|
|
} else if (strcasecmp(encoding_param, "ISO-8859-1") == 0) {
|
1999-04-22 10:48:28 +08:00
|
|
|
|
encoding = "ISO-8859-1";
|
2003-05-11 17:04:05 +08:00
|
|
|
|
} else if (strcasecmp(encoding_param, "UTF-8") == 0) {
|
1999-04-22 10:48:28 +08:00
|
|
|
|
encoding = "UTF-8";
|
2003-05-11 17:04:05 +08:00
|
|
|
|
} else if (strcasecmp(encoding_param, "US-ASCII") == 0) {
|
1999-04-22 10:48:28 +08:00
|
|
|
|
encoding = "US-ASCII";
|
2003-05-11 17:04:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unsupported source encoding \"%s\"", encoding_param);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
1999-09-20 20:51:20 +08:00
|
|
|
|
encoding = XML(default_encoding);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-11 17:04:05 +08:00
|
|
|
|
if (ns_support && ns_param == NULL){
|
|
|
|
|
ns_param = ":";
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-26 20:29:42 +08:00
|
|
|
|
parser = ecalloc(1, sizeof(xml_parser));
|
2003-05-11 17:04:05 +08:00
|
|
|
|
parser->parser = XML_ParserCreate_MM((auto_detect ? NULL : encoding),
|
|
|
|
|
&php_xml_mem_hdlrs, ns_param);
|
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
parser->target_encoding = encoding;
|
|
|
|
|
parser->case_folding = 1;
|
1999-12-06 00:43:42 +08:00
|
|
|
|
parser->object = NULL;
|
2005-04-28 20:16:32 +08:00
|
|
|
|
parser->isparsing = 0;
|
|
|
|
|
|
1999-09-20 20:51:20 +08:00
|
|
|
|
XML_SetUserData(parser->parser, parser);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2003-05-11 17:04:05 +08:00
|
|
|
|
ZEND_REGISTER_RESOURCE(return_value, parser,le_xml_parser);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
parser->index = Z_LVAL_P(return_value);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-07-17 18:24:51 +08:00
|
|
|
|
/* }}} */
|
2003-05-11 17:04:05 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto resource xml_parser_create([string encoding])
|
|
|
|
|
Create an XML parser */
|
|
|
|
|
PHP_FUNCTION(xml_parser_create)
|
|
|
|
|
{
|
|
|
|
|
php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto resource xml_parser_create_ns([string encoding [, string sep]])
|
2001-01-05 14:36:51 +08:00
|
|
|
|
Create an XML parser */
|
|
|
|
|
PHP_FUNCTION(xml_parser_create_ns)
|
|
|
|
|
{
|
2003-05-11 17:04:05 +08:00
|
|
|
|
php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_object(resource parser, object &obj)
|
1999-12-06 00:43:42 +08:00
|
|
|
|
Set up object which should be used for callbacks */
|
|
|
|
|
PHP_FUNCTION(xml_set_object)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, *mythis;
|
1999-12-06 00:43:42 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ro", &pind, &mythis) == FAILURE) {
|
|
|
|
|
return;
|
1999-12-06 00:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-12-06 00:43:42 +08:00
|
|
|
|
|
2001-12-30 02:10:01 +08:00
|
|
|
|
/* please leave this commented - or ask thies@thieso.net before doing it (again) */
|
2001-08-19 07:07:10 +08:00
|
|
|
|
if (parser->object) {
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&parser->object);
|
1999-12-06 00:43:42 +08:00
|
|
|
|
}
|
2001-02-15 21:41:04 +08:00
|
|
|
|
|
2001-12-30 02:10:01 +08:00
|
|
|
|
/* please leave this commented - or ask thies@thieso.net before doing it (again) */
|
2003-04-03 09:00:45 +08:00
|
|
|
|
/* #ifdef ZEND_ENGINE_2
|
2001-02-15 21:41:04 +08:00
|
|
|
|
zval_add_ref(&parser->object);
|
2003-04-03 09:00:45 +08:00
|
|
|
|
#endif */
|
1999-12-06 00:43:42 +08:00
|
|
|
|
|
2004-04-08 00:24:17 +08:00
|
|
|
|
ALLOC_ZVAL(parser->object);
|
2009-12-08 09:57:37 +08:00
|
|
|
|
MAKE_COPY_ZVAL(&mythis, parser->object);
|
2004-04-08 00:24:17 +08:00
|
|
|
|
|
1999-12-06 00:43:42 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_element_handler(resource parser, string shdl, string ehdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up start and end element handlers */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_element_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **shdl, **ehdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZZ", &pind, &shdl, &ehdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->startElementHandler, shdl);
|
|
|
|
|
xml_set_handler(&parser->endElementHandler, ehdl);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetElementHandler(parser->parser, _xml_startElementHandler, _xml_endElementHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_character_data_handler(resource parser, string hdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up character data handler */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_character_data_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->characterDataHandler, hdl);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_processing_instruction_handler(resource parser, string hdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up processing instruction (PI) handler */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_processing_instruction_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->processingInstructionHandler, hdl);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetProcessingInstructionHandler(parser->parser, _xml_processingInstructionHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_default_handler(resource parser, string hdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up default handler */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_default_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->defaultHandler, hdl);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetDefaultHandler(parser->parser, _xml_defaultHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_unparsed_entity_decl_handler(resource parser, string hdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up unparsed entity declaration handler */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_unparsed_entity_decl_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->unparsedEntityDeclHandler, hdl);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetUnparsedEntityDeclHandler(parser->parser, _xml_unparsedEntityDeclHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_notation_decl_handler(resource parser, string hdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up notation declaration handler */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_notation_decl_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->notationDeclHandler, hdl);
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetNotationDeclHandler(parser->parser, _xml_notationDeclHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_external_entity_ref_handler(resource parser, string hdl)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set up external entity reference handler */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_set_external_entity_ref_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
xml_set_handler(&parser->externalEntityRefHandler, hdl);
|
2003-05-27 08:50:00 +08:00
|
|
|
|
XML_SetExternalEntityRefHandler(parser->parser, (void *) _xml_externalEntityRefHandler);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_start_namespace_decl_handler(resource parser, string hdl)
|
2001-01-05 14:36:51 +08:00
|
|
|
|
Set up character data handler */
|
|
|
|
|
PHP_FUNCTION(xml_set_start_namespace_decl_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
2001-01-05 14:36:51 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
|
|
|
|
|
xml_set_handler(&parser->startNamespaceDeclHandler, hdl);
|
|
|
|
|
XML_SetStartNamespaceDeclHandler(parser->parser, _xml_startNamespaceDeclHandler);
|
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_set_end_namespace_decl_handler(resource parser, string hdl)
|
2001-01-05 14:36:51 +08:00
|
|
|
|
Set up character data handler */
|
|
|
|
|
PHP_FUNCTION(xml_set_end_namespace_decl_handler)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **hdl;
|
2001-01-05 14:36:51 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pind, &hdl) == FAILURE) {
|
|
|
|
|
return;
|
2001-01-05 14:36:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
2001-01-05 14:36:51 +08:00
|
|
|
|
|
|
|
|
|
xml_set_handler(&parser->endNamespaceDeclHandler, hdl);
|
|
|
|
|
XML_SetEndNamespaceDeclHandler(parser->parser, _xml_endNamespaceDeclHandler);
|
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_parse(resource parser, string data [, int isFinal])
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Start parsing an XML document */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_parse)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 22:13:41 +08:00
|
|
|
|
zval *pind;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
char *data;
|
2008-08-24 10:13:23 +08:00
|
|
|
|
int data_len, ret;
|
2008-06-22 22:13:41 +08:00
|
|
|
|
long isFinal = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-08-24 10:13:23 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &pind, &data, &data_len, &isFinal) == FAILURE) {
|
2008-06-22 21:22:27 +08:00
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2005-04-28 20:16:32 +08:00
|
|
|
|
parser->isparsing = 1;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ret = XML_Parse(parser->parser, data, data_len, isFinal);
|
2005-04-28 20:16:32 +08:00
|
|
|
|
parser->isparsing = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_LONG(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2001-06-05 21:12:10 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
/* {{{ proto int xml_parse_into_struct(resource parser, string data, array &values [, array &index ])
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Parsing a XML document */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(xml_parse_into_struct)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **xdata, **info = NULL;
|
|
|
|
|
char *data;
|
|
|
|
|
int data_len, ret;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsZ|Z", &pind, &data, &data_len, &xdata, &info) == FAILURE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info) {
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval_dtor(*info);
|
1999-09-25 02:02:58 +08:00
|
|
|
|
array_init(*info);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-09-26 00:42:31 +08:00
|
|
|
|
zval_dtor(*xdata);
|
1999-09-25 02:02:58 +08:00
|
|
|
|
array_init(*xdata);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
1999-09-25 02:02:58 +08:00
|
|
|
|
parser->data = *xdata;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
|
parser->info = *info;
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
parser->level = 0;
|
2003-08-12 08:58:52 +08:00
|
|
|
|
parser->ltags = safe_emalloc(XML_MAXLEVEL, sizeof(char *), 0);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
1999-10-01 21:44:07 +08:00
|
|
|
|
XML_SetDefaultHandler(parser->parser, _xml_defaultHandler);
|
|
|
|
|
XML_SetElementHandler(parser->parser, _xml_startElementHandler, _xml_endElementHandler);
|
|
|
|
|
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
2005-04-28 20:16:32 +08:00
|
|
|
|
parser->isparsing = 1;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ret = XML_Parse(parser->parser, data, data_len, 1);
|
2005-04-28 20:16:32 +08:00
|
|
|
|
parser->isparsing = 0;
|
1999-05-21 18:06:25 +08:00
|
|
|
|
|
|
|
|
|
RETVAL_LONG(ret);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_get_error_code(resource parser)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Get XML parser error code */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_get_error_code)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_LONG((long)XML_GetErrorCode(parser->parser));
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
/* {{{ proto string xml_error_string(int code)
|
|
|
|
|
Get XML parser error string */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_error_string)
|
|
|
|
|
{
|
2008-06-22 21:22:27 +08:00
|
|
|
|
long code;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
char *str;
|
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
|
|
|
|
|
str = (char *)XML_ErrorString((int)code);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (str) {
|
|
|
|
|
RETVAL_STRING(str, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_get_current_line_number(resource parser)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Get current line number for an XML parser */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_get_current_line_number)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_LONG(XML_GetCurrentLineNumber(parser->parser));
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_get_current_column_number(resource parser)
|
2000-02-24 22:43:53 +08:00
|
|
|
|
Get current column number for an XML parser */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_get_current_column_number)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_LONG(XML_GetCurrentColumnNumber(parser->parser));
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_get_current_byte_index(resource parser)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Get current byte index for an XML parser */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_get_current_byte_index)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_LONG(XML_GetCurrentByteIndex(parser->parser));
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_parser_free(resource parser)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Free an XML parser */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_parser_free)
|
|
|
|
|
{
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind;
|
1999-09-20 20:51:20 +08:00
|
|
|
|
xml_parser *parser;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2005-04-28 20:16:32 +08:00
|
|
|
|
if (parser->isparsing == 1) {
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parser cannot be freed while it is parsing.");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
|
if (zend_list_delete(parser->index) == FAILURE) {
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_parser_set_option(resource parser, int option, mixed value)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Set options in an XML parser */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_parser_set_option)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind, **val;
|
|
|
|
|
long opt;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlZ", &pind, &opt, &val) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
switch (opt) {
|
1999-12-18 11:20:53 +08:00
|
|
|
|
case PHP_XML_OPTION_CASE_FOLDING:
|
1999-09-25 02:02:58 +08:00
|
|
|
|
convert_to_long_ex(val);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
parser->case_folding = Z_LVAL_PP(val);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
break;
|
1999-12-18 11:20:53 +08:00
|
|
|
|
case PHP_XML_OPTION_SKIP_TAGSTART:
|
1999-09-25 02:02:58 +08:00
|
|
|
|
convert_to_long_ex(val);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
parser->toffset = Z_LVAL_PP(val);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
break;
|
1999-12-18 11:20:53 +08:00
|
|
|
|
case PHP_XML_OPTION_SKIP_WHITE:
|
1999-09-25 02:02:58 +08:00
|
|
|
|
convert_to_long_ex(val);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
parser->skipwhite = Z_LVAL_PP(val);
|
1999-05-21 18:06:25 +08:00
|
|
|
|
break;
|
1999-12-18 11:20:53 +08:00
|
|
|
|
case PHP_XML_OPTION_TARGET_ENCODING: {
|
1999-09-25 02:02:58 +08:00
|
|
|
|
xml_encoding *enc;
|
|
|
|
|
convert_to_string_ex(val);
|
2001-09-26 05:58:48 +08:00
|
|
|
|
enc = xml_get_encoding(Z_STRVAL_PP(val));
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (enc == NULL) {
|
2002-12-06 05:53:25 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported target encoding \"%s\"", Z_STRVAL_PP(val));
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
parser->target_encoding = enc->name;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2002-12-06 05:53:25 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option");
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
RETVAL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-03-22 00:10:08 +08:00
|
|
|
|
/* {{{ proto int xml_parser_get_option(resource parser, int option)
|
1999-05-21 18:06:25 +08:00
|
|
|
|
Get options from an XML parser */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(xml_parser_get_option)
|
|
|
|
|
{
|
|
|
|
|
xml_parser *parser;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
zval *pind;
|
|
|
|
|
long opt;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &pind, &opt) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
ZEND_FETCH_RESOURCE(parser,xml_parser *, &pind, -1, "XML Parser", le_xml_parser);
|
1999-09-20 20:51:20 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
switch (opt) {
|
1999-12-18 11:20:53 +08:00
|
|
|
|
case PHP_XML_OPTION_CASE_FOLDING:
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_LONG(parser->case_folding);
|
|
|
|
|
break;
|
1999-12-18 11:20:53 +08:00
|
|
|
|
case PHP_XML_OPTION_TARGET_ENCODING:
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_STRING(parser->target_encoding, 1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-12-06 05:53:25 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option");
|
1999-04-22 10:48:28 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-01-27 15:23:21 +08:00
|
|
|
|
|
|
|
|
|
RETVAL_FALSE; /* never reached */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
/* {{{ proto string utf8_encode(string data)
|
|
|
|
|
Encodes an ISO-8859-1 string to UTF-8 */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(utf8_encode)
|
|
|
|
|
{
|
2008-06-22 21:22:27 +08:00
|
|
|
|
char *arg;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
XML_Char *encoded;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
int arg_len, len;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
|
|
|
|
|
encoded = xml_utf8_encode(arg, arg_len, &len, "ISO-8859-1");
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (encoded == NULL) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
RETVAL_STRINGL(encoded, len, 0);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
|
/* {{{ proto string utf8_decode(string data)
|
|
|
|
|
Converts a UTF-8 encoded string to ISO-8859-1 */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
PHP_FUNCTION(utf8_decode)
|
|
|
|
|
{
|
2008-06-22 21:22:27 +08:00
|
|
|
|
char *arg;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
XML_Char *decoded;
|
2008-06-22 21:22:27 +08:00
|
|
|
|
int arg_len, len;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
2008-06-22 21:22:27 +08:00
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
|
|
|
|
|
return;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
}
|
2008-06-22 21:22:27 +08:00
|
|
|
|
|
|
|
|
|
decoded = xml_utf8_decode(arg, arg_len, &len, "ISO-8859-1");
|
1999-04-22 10:48:28 +08:00
|
|
|
|
if (decoded == NULL) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
RETVAL_STRINGL(decoded, len, 0);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
|
|
|
|
* c-basic-offset: 4
|
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
|
* vim<600: sw=4 ts=4
|
1999-04-22 10:48:28 +08:00
|
|
|
|
*/
|