diff options
Diffstat (limited to 'ext/libxml/libxml.c')
-rw-r--r-- | ext/libxml/libxml.c | 337 |
1 files changed, 169 insertions, 168 deletions
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index f8ccd82562..63f422ff5c 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -79,6 +79,9 @@ static zend_class_entry *libxmlerror_class_entry; /* {{{ dynamically loadable module stuff */ #ifdef COMPILE_DL_LIBXML +#ifdef ZTS +ZEND_TSRMLS_CACHE_DEFINE; +#endif ZEND_GET_MODULE(libxml) #endif /* COMPILE_DL_LIBXML */ /* }}} */ @@ -86,6 +89,7 @@ ZEND_GET_MODULE(libxml) /* {{{ function prototypes */ static PHP_MINIT_FUNCTION(libxml); static PHP_RINIT_FUNCTION(libxml); +static PHP_RSHUTDOWN_FUNCTION(libxml); static PHP_MSHUTDOWN_FUNCTION(libxml); static PHP_MINFO_FUNCTION(libxml); static int php_libxml_post_deactivate(void); @@ -138,7 +142,7 @@ zend_module_entry libxml_module_entry = { PHP_MINIT(libxml), /* extension-wide startup function */ PHP_MSHUTDOWN(libxml), /* extension-wide shutdown function */ PHP_RINIT(libxml), /* per-request startup function */ - NULL, /* per-request shutdown function */ + PHP_RSHUTDOWN(libxml), /* per-request shutdown function */ PHP_MINFO(libxml), /* information function */ NO_VERSION_YET, PHP_MODULE_GLOBALS(libxml), /* globals descriptor */ @@ -151,16 +155,16 @@ zend_module_entry libxml_module_entry = { /* }}} */ /* {{{ internal functions for interoperability */ -static int php_libxml_clear_object(php_libxml_node_object *object TSRMLS_DC) +static int php_libxml_clear_object(php_libxml_node_object *object) { if (object->properties) { object->properties = NULL; } - php_libxml_decrement_node_ptr(object TSRMLS_CC); - return php_libxml_decrement_doc_ref(object TSRMLS_CC); + php_libxml_decrement_node_ptr(object); + return php_libxml_decrement_doc_ref(object); } -static int php_libxml_unregister_node(xmlNodePtr nodep TSRMLS_DC) +static int php_libxml_unregister_node(xmlNodePtr nodep) { php_libxml_node_object *wrapper; @@ -169,7 +173,7 @@ static int php_libxml_unregister_node(xmlNodePtr nodep TSRMLS_DC) if (nodeptr != NULL) { wrapper = nodeptr->_private; if (wrapper) { - php_libxml_clear_object(wrapper TSRMLS_CC); + php_libxml_clear_object(wrapper); } else { if (nodeptr->node != NULL && nodeptr->node->type != XML_DOCUMENT_NODE) { nodeptr->node->_private = NULL; @@ -220,7 +224,7 @@ static void php_libxml_node_free(xmlNodePtr node) } } -static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC) +static void php_libxml_node_free_list(xmlNodePtr node) { xmlNodePtr curnode; @@ -234,7 +238,7 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC) case XML_ENTITY_DECL: break; case XML_ENTITY_REF_NODE: - php_libxml_node_free_list((xmlNodePtr) node->properties TSRMLS_CC); + php_libxml_node_free_list((xmlNodePtr) node->properties); break; case XML_ATTRIBUTE_NODE: if ((node->doc != NULL) && (((xmlAttrPtr) node)->atype == XML_ATTRIBUTE_ID)) { @@ -245,16 +249,16 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC) case XML_DOCUMENT_TYPE_NODE: case XML_NAMESPACE_DECL: case XML_TEXT_NODE: - php_libxml_node_free_list(node->children TSRMLS_CC); + php_libxml_node_free_list(node->children); break; default: - php_libxml_node_free_list(node->children TSRMLS_CC); - php_libxml_node_free_list((xmlNodePtr) node->properties TSRMLS_CC); + php_libxml_node_free_list(node->children); + php_libxml_node_free_list((xmlNodePtr) node->properties); } curnode = node->next; xmlUnlinkNode(node); - if (php_libxml_unregister_node(node TSRMLS_CC) == 0) { + if (php_libxml_unregister_node(node) == 0) { node->doc = NULL; } php_libxml_node_free(node); @@ -267,22 +271,27 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC) /* {{{ startup, shutdown and info functions */ static PHP_GINIT_FUNCTION(libxml) { - libxml_globals->stream_context = NULL; - libxml_globals->error_buffer.c = NULL; +#if defined(COMPILE_DL_LIBXML) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE; +#endif + ZVAL_UNDEF(&libxml_globals->stream_context); + libxml_globals->error_buffer.s = NULL; libxml_globals->error_list = NULL; + ZVAL_UNDEF(&libxml_globals->entity_loader.object); libxml_globals->entity_loader.fci.size = 0; libxml_globals->entity_loader_disabled = 0; } -static void _php_libxml_destroy_fci(zend_fcall_info *fci) +static void _php_libxml_destroy_fci(zend_fcall_info *fci, zval *object) { if (fci->size > 0) { zval_ptr_dtor(&fci->function_name); - if (fci->object_ptr != NULL) { - zval_ptr_dtor(&fci->object_ptr); - } fci->size = 0; } + if (!Z_ISUNDEF_P(object)) { + zval_ptr_dtor(object); + ZVAL_UNDEF(object); + } } /* Channel libxml file io layer through the PHP streams subsystem. @@ -299,7 +308,6 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char int isescaped=0; xmlURI *uri; - TSRMLS_FETCH(); uri = xmlParseURI(filename); if (uri && (uri->scheme == NULL || @@ -324,9 +332,9 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char that the streams layer puts out at times, but for libxml we may try to open files that don't exist, but it is not a failure in xml processing (eg. DTD files) */ - wrapper = php_stream_locate_url_wrapper(resolved_path, &path_to_open, 0 TSRMLS_CC); + wrapper = php_stream_locate_url_wrapper(resolved_path, &path_to_open, 0); if (wrapper && read_only && wrapper->wops->url_stat) { - if (wrapper->wops->url_stat(wrapper, path_to_open, PHP_STREAM_URL_STAT_QUIET, &ssbuf, NULL TSRMLS_CC) == -1) { + if (wrapper->wops->url_stat(wrapper, path_to_open, PHP_STREAM_URL_STAT_QUIET, &ssbuf, NULL) == -1) { if (isescaped) { xmlFree(resolved_path); } @@ -334,8 +342,8 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char } } - context = php_stream_context_from_zval(LIBXML(stream_context), 0); - + context = php_stream_context_from_zval(Z_ISUNDEF(LIBXML(stream_context))? NULL : &LIBXML(stream_context), 0); + ret_val = php_stream_open_wrapper_ex(path_to_open, (char *)mode, REPORT_ERRORS, NULL, context); if (isescaped) { xmlFree(resolved_path); @@ -355,19 +363,16 @@ static void *php_libxml_streams_IO_open_write_wrapper(const char *filename) static int php_libxml_streams_IO_read(void *context, char *buffer, int len) { - TSRMLS_FETCH(); return php_stream_read((php_stream*)context, buffer, len); } static int php_libxml_streams_IO_write(void *context, const char *buffer, int len) { - TSRMLS_FETCH(); return php_stream_write((php_stream*)context, buffer, len); } static int php_libxml_streams_IO_close(void *context) { - TSRMLS_FETCH(); return php_stream_close((php_stream*)context); } @@ -376,7 +381,6 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc) { xmlParserInputBufferPtr ret; void *context = NULL; - TSRMLS_FETCH(); if (LIBXML(entity_loader_disabled)) { return NULL; @@ -460,7 +464,6 @@ static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg) xmlError error_copy; int ret; - TSRMLS_FETCH(); memset(&error_copy, 0, sizeof(xmlError)); @@ -475,7 +478,7 @@ static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg) error_copy.int1 = 0; error_copy.int2 = 0; error_copy.ctxt = NULL; - error_copy.message = xmlStrdup(msg); + error_copy.message = (char*)xmlStrdup((xmlChar*)msg); error_copy.file = NULL; error_copy.str1 = NULL; error_copy.str2 = NULL; @@ -488,7 +491,7 @@ static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg) } } -static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg TSRMLS_DC) +static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg) { xmlParserCtxtPtr parser; @@ -496,19 +499,19 @@ static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg TSR if (parser != NULL && parser->input != NULL) { if (parser->input->filename) { - php_error_docref(NULL TSRMLS_CC, level, "%s in %s, line: %d", msg, parser->input->filename, parser->input->line); + php_error_docref(NULL, level, "%s in %s, line: %d", msg, parser->input->filename, parser->input->line); } else { - php_error_docref(NULL TSRMLS_CC, level, "%s in Entity, line: %d", msg, parser->input->line); + php_error_docref(NULL, level, "%s in Entity, line: %d", msg, parser->input->line); } } } -void php_libxml_issue_error(int level, const char *msg TSRMLS_DC) +void php_libxml_issue_error(int level, const char *msg) { if (LIBXML(error_list)) { _php_list_set_error_structure(NULL, msg); } else { - php_error_docref(NULL TSRMLS_CC, level, "%s", msg); + php_error_docref(NULL, level, "%s", msg); } } @@ -517,7 +520,6 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c char *buf; int len, len_iter, output = 0; - TSRMLS_FETCH(); len = vspprintf(&buf, 0, *msg, ap); len_iter = len; @@ -534,17 +536,17 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c if (output == 1) { if (LIBXML(error_list)) { - _php_list_set_error_structure(NULL, LIBXML(error_buffer).c); + _php_list_set_error_structure(NULL, LIBXML(error_buffer).s->val); } else { switch (error_type) { case PHP_LIBXML_CTX_ERROR: - php_libxml_ctx_error_level(E_WARNING, ctx, LIBXML(error_buffer).c TSRMLS_CC); + php_libxml_ctx_error_level(E_WARNING, ctx, LIBXML(error_buffer).s->val); break; case PHP_LIBXML_CTX_WARNING: - php_libxml_ctx_error_level(E_NOTICE, ctx, LIBXML(error_buffer).c TSRMLS_CC); + php_libxml_ctx_error_level(E_NOTICE, ctx, LIBXML(error_buffer).s->val); break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", LIBXML(error_buffer).c); + php_error_docref(NULL, E_WARNING, "%s", LIBXML(error_buffer).s->val); } } smart_str_free(&LIBXML(error_buffer)); @@ -556,76 +558,75 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL, { xmlParserInputPtr ret = NULL; const char *resource = NULL; - zval *public = NULL, - *system = NULL, - *ctxzv = NULL, - **params[] = {&public, &system, &ctxzv}, - *retval_ptr = NULL; - int retval; + zval *ctxzv, retval; + zval params[3]; + int status; zend_fcall_info *fci; - TSRMLS_FETCH(); fci = &LIBXML(entity_loader).fci; - + if (fci->size == 0) { /* no custom user-land callback set up; delegate to original loader */ return _php_libxml_default_entity_loader(URL, ID, context); } - ALLOC_INIT_ZVAL(public); if (ID != NULL) { - ZVAL_STRING(public, ID, 1); + ZVAL_STRING(¶ms[0], ID); + } else { + ZVAL_UNDEF(¶ms[0]); } - ALLOC_INIT_ZVAL(system); if (URL != NULL) { - ZVAL_STRING(system, URL, 1); + ZVAL_STRING(¶ms[1], URL); + } else { + ZVAL_UNDEF(¶ms[1]); } - MAKE_STD_ZVAL(ctxzv); + ctxzv = ¶ms[2]; array_init_size(ctxzv, 4); #define ADD_NULL_OR_STRING_KEY(memb) \ if (context->memb == NULL) { \ - add_assoc_null_ex(ctxzv, #memb, sizeof(#memb)); \ + add_assoc_null_ex(ctxzv, #memb, sizeof(#memb) - 1); \ } else { \ - add_assoc_string_ex(ctxzv, #memb, sizeof(#memb), \ - (char *)context->memb, 1); \ + add_assoc_string_ex(ctxzv, #memb, sizeof(#memb) - 1, \ + (char *)context->memb); \ } - + ADD_NULL_OR_STRING_KEY(directory) ADD_NULL_OR_STRING_KEY(intSubName) ADD_NULL_OR_STRING_KEY(extSubURI) ADD_NULL_OR_STRING_KEY(extSubSystem) - + #undef ADD_NULL_OR_STRING_KEY - - fci->retval_ptr_ptr = &retval_ptr; - fci->params = params; - fci->param_count = sizeof(params)/sizeof(*params); + + fci->retval = &retval; + fci->params = params; + fci->param_count = sizeof(params)/sizeof(*params); fci->no_separation = 1; - - retval = zend_call_function(fci, &LIBXML(entity_loader).fcc TSRMLS_CC); - if (retval != SUCCESS || fci->retval_ptr_ptr == NULL) { + + status = zend_call_function(fci, &LIBXML(entity_loader).fcc); + if (status != SUCCESS || Z_ISUNDEF(retval)) { php_libxml_ctx_error(context, "Call to user entity loader callback '%s' has failed", - fci->function_name); + Z_STRVAL(fci->function_name)); } else { + /* retval_ptr = *fci->retval_ptr_ptr; if (retval_ptr == NULL) { php_libxml_ctx_error(context, "Call to user entity loader callback '%s' has failed; " "probably it has thrown an exception", fci->function_name); - } else if (Z_TYPE_P(retval_ptr) == IS_STRING) { + } else */ if (Z_TYPE(retval) == IS_STRING) { is_string: - resource = Z_STRVAL_P(retval_ptr); - } else if (Z_TYPE_P(retval_ptr) == IS_RESOURCE) { + resource = Z_STRVAL(retval); + } else if (Z_TYPE(retval) == IS_RESOURCE) { php_stream *stream; - php_stream_from_zval_no_verify(stream, &retval_ptr); + php_stream_from_zval_no_verify(stream, &retval); if (stream == NULL) { php_libxml_ctx_error(context, "The user entity loader callback '%s' has returned a " "resource, but it is not a stream", - fci->function_name); + Z_STRVAL(fci->function_name)); } else { /* TODO: allow storing the encoding in the stream context? */ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; @@ -635,21 +636,21 @@ is_string: "input buffer"); } else { /* make stream not being closed when the zval is freed */ - zend_list_addref(stream->rsrc_id); + ++GC_REFCOUNT(stream->res); pib->context = stream; pib->readcallback = php_libxml_streams_IO_read; pib->closecallback = php_libxml_streams_IO_close; - + ret = xmlNewIOInputStream(context, pib, enc); if (ret == NULL) { xmlFreeParserInputBuffer(pib); } } } - } else if (Z_TYPE_P(retval_ptr) != IS_NULL) { + } else if (Z_TYPE(retval) != IS_NULL) { /* retval not string nor resource nor null; convert to string */ - SEPARATE_ZVAL(&retval_ptr); - convert_to_string(retval_ptr); + SEPARATE_ZVAL(&retval); + convert_to_string(&retval); goto is_string; } /* else is null; don't try anything */ } @@ -667,19 +668,16 @@ is_string: } } - zval_ptr_dtor(&public); - zval_ptr_dtor(&system); - zval_ptr_dtor(&ctxzv); - if (retval_ptr != NULL) { - zval_ptr_dtor(&retval_ptr); - } + zval_ptr_dtor(¶ms[0]); + zval_ptr_dtor(¶ms[1]); + zval_ptr_dtor(¶ms[2]); + zval_ptr_dtor(&retval); return ret; } static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(const char *URL, const char *ID, xmlParserCtxtPtr context) { - TSRMLS_FETCH(); /* Check whether we're running in a PHP context, since the entity loader * we've defined is an application level (true global) setting. @@ -728,17 +726,21 @@ PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...) va_end(args); } +static void php_libxml_exports_dtor(zval *zv) +{ + free(Z_PTR_P(zv)); +} PHP_LIBXML_API void php_libxml_initialize(void) { if (!_php_libxml_initialized) { /* we should be the only one's to ever init!! */ xmlInitParser(); - + _php_libxml_default_entity_loader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader); - zend_hash_init(&php_libxml_exports, 0, NULL, NULL, 1); + zend_hash_init(&php_libxml_exports, 0, NULL, php_libxml_exports_dtor, 1); _php_libxml_initialized = 1; } @@ -752,20 +754,20 @@ PHP_LIBXML_API void php_libxml_shutdown(void) #endif xmlCleanupParser(); zend_hash_destroy(&php_libxml_exports); - + xmlSetExternalEntityLoader(_php_libxml_default_entity_loader); _php_libxml_initialized = 0; } } -PHP_LIBXML_API zval *php_libxml_switch_context(zval *context TSRMLS_DC) +PHP_LIBXML_API void php_libxml_switch_context(zval *context, zval *oldcontext) { - zval *oldcontext; - - oldcontext = LIBXML(stream_context); - LIBXML(stream_context) = context; - return oldcontext; - + if (oldcontext) { + ZVAL_COPY_VALUE(oldcontext, &LIBXML(stream_context)); + } + if (context) { + ZVAL_COPY_VALUE(&LIBXML(stream_context), context); + } } static PHP_MINIT_FUNCTION(libxml) @@ -821,7 +823,7 @@ static PHP_MINIT_FUNCTION(libxml) REGISTER_LONG_CONSTANT("LIBXML_ERR_FATAL", XML_ERR_FATAL, CONST_CS | CONST_PERSISTENT); INIT_CLASS_ENTRY(ce, "LibXMLError", NULL); - libxmlerror_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + libxmlerror_class_entry = zend_register_internal_class(&ce); if (sapi_module.name) { static const char * const supported_sapis[] = { @@ -846,7 +848,7 @@ static PHP_MINIT_FUNCTION(libxml) xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename); xmlOutputBufferCreateFilenameDefault(php_libxml_output_buffer_create_filename); } - + return SUCCESS; } @@ -862,6 +864,12 @@ static PHP_RINIT_FUNCTION(libxml) return SUCCESS; } +static PHP_RSHUTDOWN_FUNCTION(libxml) +{ + _php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object); + + return SUCCESS; +} static PHP_MSHUTDOWN_FUNCTION(libxml) { @@ -878,7 +886,6 @@ static PHP_MSHUTDOWN_FUNCTION(libxml) static int php_libxml_post_deactivate(void) { - TSRMLS_FETCH(); /* reset libxml generic error handling */ if (_php_libxml_per_request_initialization) { xmlSetGenericErrorFunc(NULL, NULL); @@ -888,11 +895,8 @@ static int php_libxml_post_deactivate(void) } xmlSetStructuredErrorFunc(NULL, NULL); - if (LIBXML(stream_context)) { - /* the steam_context resource will be released by resource list destructor */ - efree(LIBXML(stream_context)); - LIBXML(stream_context) = NULL; - } + /* the steam_context resource will be released by resource list destructor */ + ZVAL_UNDEF(&LIBXML(stream_context)); smart_str_free(&LIBXML(error_buffer)); if (LIBXML(error_list)) { zend_llist_destroy(LIBXML(error_list)); @@ -900,8 +904,6 @@ static int php_libxml_post_deactivate(void) LIBXML(error_list) = NULL; } xmlResetLastError(); - - _php_libxml_destroy_fci(&LIBXML(entity_loader).fci); return SUCCESS; } @@ -918,32 +920,31 @@ static PHP_MINFO_FUNCTION(libxml) } /* }}} */ -/* {{{ proto void libxml_set_streams_context(resource streams_context) +/* {{{ proto void libxml_set_streams_context(resource streams_context) Set the streams context for the next libxml document load or write */ static PHP_FUNCTION(libxml_set_streams_context) { zval *arg; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg) == FAILURE) { return; } - if (LIBXML(stream_context)) { + if (!Z_ISUNDEF(LIBXML(stream_context))) { zval_ptr_dtor(&LIBXML(stream_context)); - LIBXML(stream_context) = NULL; + ZVAL_UNDEF(&LIBXML(stream_context)); } - Z_ADDREF_P(arg); - LIBXML(stream_context) = arg; + ZVAL_COPY(&LIBXML(stream_context), arg); } /* }}} */ -/* {{{ proto bool libxml_use_internal_errors([boolean use_errors]) +/* {{{ proto bool libxml_use_internal_errors([boolean use_errors]) Disable libxml errors and allow user to fetch error information as needed */ static PHP_FUNCTION(libxml_use_internal_errors) { xmlStructuredErrorFunc current_handler; zend_bool use_errors=0, retval; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &use_errors) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &use_errors) == FAILURE) { return; } @@ -976,28 +977,28 @@ static PHP_FUNCTION(libxml_use_internal_errors) } /* }}} */ -/* {{{ proto object libxml_get_last_error() +/* {{{ proto object libxml_get_last_error() Retrieve last error from libxml */ static PHP_FUNCTION(libxml_get_last_error) { xmlErrorPtr error; error = xmlGetLastError(); - + if (error) { object_init_ex(return_value, libxmlerror_class_entry); add_property_long(return_value, "level", error->level); add_property_long(return_value, "code", error->code); add_property_long(return_value, "column", error->int2); if (error->message) { - add_property_string(return_value, "message", error->message, 1); + add_property_string(return_value, "message", error->message); } else { - add_property_stringl(return_value, "message", "", 0, 1); + add_property_stringl(return_value, "message", "", 0); } if (error->file) { - add_property_string(return_value, "file", error->file, 1); + add_property_string(return_value, "file", error->file); } else { - add_property_stringl(return_value, "file", "", 0, 1); + add_property_stringl(return_value, "file", "", 0); } add_property_long(return_value, "line", error->line); } else { @@ -1010,7 +1011,7 @@ static PHP_FUNCTION(libxml_get_last_error) Retrieve array of errors */ static PHP_FUNCTION(libxml_get_errors) { - + xmlErrorPtr error; if (array_init(return_value) == FAILURE) { @@ -1022,25 +1023,24 @@ static PHP_FUNCTION(libxml_get_errors) error = zend_llist_get_first(LIBXML(error_list)); while (error != NULL) { - zval *z_error; - MAKE_STD_ZVAL(z_error); + zval z_error; - object_init_ex(z_error, libxmlerror_class_entry); - add_property_long(z_error, "level", error->level); - add_property_long(z_error, "code", error->code); - add_property_long(z_error, "column", error->int2); + object_init_ex(&z_error, libxmlerror_class_entry); + add_property_long_ex(&z_error, "level", sizeof("level") - 1, error->level); + add_property_long_ex(&z_error, "code", sizeof("code") - 1, error->code); + add_property_long_ex(&z_error, "column", sizeof("column") - 1, error->int2 ); if (error->message) { - add_property_string(z_error, "message", error->message, 1); + add_property_string_ex(&z_error, "message", sizeof("message") - 1, error->message); } else { - add_property_stringl(z_error, "message", "", 0, 1); + add_property_stringl_ex(&z_error, "message", sizeof("message") - 1, "", 0); } if (error->file) { - add_property_string(z_error, "file", error->file, 1); + add_property_string_ex(&z_error, "file", sizeof("file") - 1, error->file); } else { - add_property_stringl(z_error, "file", "", 0, 1); + add_property_stringl_ex(&z_error, "file", sizeof("file") - 1, "", 0); } - add_property_long(z_error, "line", error->line); - add_next_index_zval(return_value, z_error); + add_property_long_ex(&z_error, "line", sizeof("line") - 1, error->line); + add_next_index_zval(return_value, &z_error); error = zend_llist_get_next(LIBXML(error_list)); } @@ -1048,7 +1048,7 @@ static PHP_FUNCTION(libxml_get_errors) } /* }}} */ -/* {{{ proto void libxml_clear_errors() +/* {{{ proto void libxml_clear_errors() Clear last error from libxml */ static PHP_FUNCTION(libxml_clear_errors) { @@ -1059,50 +1059,51 @@ static PHP_FUNCTION(libxml_clear_errors) } /* }}} */ -PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable TSRMLS_DC) +PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable) /* {{{ */ { zend_bool old = LIBXML(entity_loader_disabled); LIBXML(entity_loader_disabled) = disable; return old; -} +} /* }}} */ -/* {{{ proto bool libxml_disable_entity_loader([boolean disable]) +/* {{{ proto bool libxml_disable_entity_loader([boolean disable]) Disable/Enable ability to load external entities */ static PHP_FUNCTION(libxml_disable_entity_loader) { zend_bool disable = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &disable) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &disable) == FAILURE) { return; } - RETURN_BOOL(php_libxml_disable_entity_loader(disable TSRMLS_CC)); + RETURN_BOOL(php_libxml_disable_entity_loader(disable)); } /* }}} */ -/* {{{ proto void libxml_set_external_entity_loader(callback resolver_function) +/* {{{ proto void libxml_set_external_entity_loader(callback resolver_function) Changes the default external entity loader */ static PHP_FUNCTION(libxml_set_external_entity_loader) { zend_fcall_info fci; zend_fcall_info_cache fcc; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!", &fci, &fcc) + if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!", &fci, &fcc) == FAILURE) { return; } - - _php_libxml_destroy_fci(&LIBXML(entity_loader).fci); - + + _php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object); + if (fci.size > 0) { /* argument not null */ LIBXML(entity_loader).fci = fci; - Z_ADDREF_P(fci.function_name); - if (fci.object_ptr != NULL) { - Z_ADDREF_P(fci.object_ptr); + Z_ADDREF(fci.function_name); + if (fci.object != NULL) { + ZVAL_OBJ(&LIBXML(entity_loader).object, fci.object); + Z_ADDREF(LIBXML(entity_loader).object); } LIBXML(entity_loader).fcc = fcc; } - + RETURN_TRUE; } /* }}} */ @@ -1134,36 +1135,36 @@ int php_libxml_xmlCheckUTF8(const unsigned char *s) return 1; } -int php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function) +zval *php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function) { php_libxml_func_handler export_hnd; - + /* Initialize in case this module hasn't been loaded yet */ php_libxml_initialize(); export_hnd.export_func = export_function; - return zend_hash_add(&php_libxml_exports, ce->name, ce->name_length + 1, &export_hnd, sizeof(export_hnd), NULL); + return zend_hash_add_mem(&php_libxml_exports, ce->name, &export_hnd, sizeof(export_hnd)); } -PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object TSRMLS_DC) +PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object) { zend_class_entry *ce = NULL; xmlNodePtr node = NULL; php_libxml_func_handler *export_hnd; - if (object->type == IS_OBJECT) { + if (Z_TYPE_P(object) == IS_OBJECT) { ce = Z_OBJCE_P(object); while (ce->parent != NULL) { ce = ce->parent; } - if (zend_hash_find(&php_libxml_exports, ce->name, ce->name_length + 1, (void **) &export_hnd) == SUCCESS) { - node = export_hnd->export_func(object TSRMLS_CC); + if ((export_hnd = zend_hash_find_ptr(&php_libxml_exports, ce->name))) { + node = export_hnd->export_func(object); } } return node; } -PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data TSRMLS_DC) +PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data) { int ret_refcount = -1; @@ -1172,7 +1173,7 @@ PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, if (object->node->node == node) { return object->node->refcount; } else { - php_libxml_decrement_node_ptr(object TSRMLS_CC); + php_libxml_decrement_node_ptr(object); } } if (node->_private != NULL) { @@ -1195,7 +1196,7 @@ PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, return ret_refcount; } -PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object TSRMLS_DC) +PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object) { int ret_refcount = -1; php_libxml_node_ptr *obj_node; @@ -1208,14 +1209,14 @@ PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object obj_node->node->_private = NULL; } efree(obj_node); - } + } object->node = NULL; } return ret_refcount; } -PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp TSRMLS_DC) +PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp) { int ret_refcount = -1; @@ -1233,7 +1234,7 @@ PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, return ret_refcount; } -PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object TSRMLS_DC) +PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object) { int ret_refcount = -1; @@ -1258,7 +1259,7 @@ PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object T return ret_refcount; } -PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node TSRMLS_DC) +PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node) { if (!node) { return; @@ -1270,7 +1271,7 @@ PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node TSRMLS_DC) break; default: if (node->parent == NULL || node->type == XML_NAMESPACE_DECL) { - php_libxml_node_free_list((xmlNodePtr) node->children TSRMLS_CC); + php_libxml_node_free_list((xmlNodePtr) node->children); switch (node->type) { /* Skip property freeing for the following types */ case XML_ATTRIBUTE_DECL: @@ -1282,19 +1283,19 @@ PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node TSRMLS_DC) case XML_TEXT_NODE: break; default: - php_libxml_node_free_list((xmlNodePtr) node->properties TSRMLS_CC); + php_libxml_node_free_list((xmlNodePtr) node->properties); } - if (php_libxml_unregister_node(node TSRMLS_CC) == 0) { + if (php_libxml_unregister_node(node) == 0) { node->doc = NULL; } php_libxml_node_free(node); } else { - php_libxml_unregister_node(node TSRMLS_CC); + php_libxml_unregister_node(node); } } } -PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *object TSRMLS_DC) +PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *object) { int ret_refcount = -1; xmlNodePtr nodep; @@ -1303,9 +1304,9 @@ PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *o if (object != NULL && object->node != NULL) { obj_node = (php_libxml_node_ptr *) object->node; nodep = object->node->node; - ret_refcount = php_libxml_decrement_node_ptr(object TSRMLS_CC); + ret_refcount = php_libxml_decrement_node_ptr(object); if (ret_refcount == 0) { - php_libxml_node_free_resource(nodep TSRMLS_CC); + php_libxml_node_free_resource(nodep); } else { if (obj_node && object == obj_node->_private) { obj_node->_private = NULL; @@ -1314,7 +1315,7 @@ PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *o } if (object != NULL && object->document != NULL) { /* Safe to call as if the resource were freed then doc pointer is NULL */ - php_libxml_decrement_doc_ref(object TSRMLS_CC); + php_libxml_decrement_doc_ref(object); } } /* }}} */ |