Skip to content

Commit 23229eb

Browse files
committed
Make libxml stream context externally visible and use it in html_document
1 parent 603b954 commit 23229eb

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

ext/dom/html_document.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,8 @@ PHP_METHOD(DOM_HTMLDocument, createFromFile)
715715
dom_setup_parser_encoding_manually((const lxb_char_t *) buf, encoding_data, &decoding_encoding_ctx, &application_data);
716716
}
717717

718-
// TODO: context from LIBXML(stream_context) ???
719718
// TODO: https://mimesniff.spec.whatwg.org/#parsing-a-mime-type
720-
stream = php_stream_open_wrapper_ex(filename, "rb", REPORT_ERRORS, /* opened_path */ NULL, /* context */ NULL);
719+
stream = php_stream_open_wrapper_ex(filename, "rb", REPORT_ERRORS, /* opened_path */ NULL, /* context */ php_libxml_get_stream_context());
721720
if (!stream) {
722721
if (!EG(exception)) {
723722
zend_throw_exception_ex(NULL, 0, "Cannot open file '%s'", filename);

ext/libxml/libxml.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ static PHP_GINIT_FUNCTION(libxml)
369369
libxml_globals->entity_loader_callback = empty_fcall_info_cache;
370370
}
371371

372+
PHP_LIBXML_API php_stream_context *php_libxml_get_stream_context(void)
373+
{
374+
return php_stream_context_from_zval(Z_ISUNDEF(LIBXML(stream_context)) ? NULL : &LIBXML(stream_context), false);
375+
}
376+
372377
/* Channel libxml file io layer through the PHP streams subsystem.
373378
* This allows use of ftps:// and https:// urls */
374379

@@ -436,7 +441,7 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
436441
}
437442
}
438443

439-
context = php_stream_context_from_zval(Z_ISUNDEF(LIBXML(stream_context))? NULL : &LIBXML(stream_context), 0);
444+
context = php_libxml_get_stream_context();
440445

441446
ret_val = php_stream_open_wrapper_ex(path_to_open, (char *)mode, REPORT_ERRORS, NULL, context);
442447
if (ret_val) {

ext/libxml/php_libxml.h

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ PHP_LIBXML_API void php_libxml_switch_context(zval *context, zval *oldcontext);
139139
PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg);
140140
PHP_LIBXML_API bool php_libxml_disable_entity_loader(bool disable);
141141
PHP_LIBXML_API void php_libxml_set_old_ns(xmlDocPtr doc, xmlNsPtr ns);
142+
PHP_LIBXML_API php_stream_context *php_libxml_get_stream_context(void);
142143

143144
/* Init/shutdown functions*/
144145
PHP_LIBXML_API void php_libxml_initialize(void);

0 commit comments

Comments
 (0)