#include <libxml/xmlschemas.h>
#endif
+#include "ext/libxml/php_libxml.h"
+
typedef struct _idsIterator idsIterator;
struct _idsIterator {
xmlChar *elementId;
xmlDoc *docp = NULL, *newdoc;
dom_doc_propsptr doc_prop;
dom_object *intern;
- char *source;
+ zstr source;
int source_len, refcount, ret;
zend_uchar source_type = IS_STRING;
long options = 0;
id = NULL;
}
- if (mode == DOM_LOAD_FILE) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|l", &source, &source_len, &source_type, &options) == FAILURE) {
- return;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &source, &source_len, &options) == FAILURE) {
- return;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|l", &source, &source_len, &source_type, &options) == FAILURE) {
+ return;
}
if (!source_len) {
}
if (source_type == IS_UNICODE) {
- if (php_stream_path_encode(NULL, &source, &source_len, (UChar*)source, source_len, REPORT_ERRORS, NULL) == FAILURE) {
- RETURN_FALSE;
+ if (mode == DOM_LOAD_FILE) {
+ if (php_stream_path_encode(NULL, &source.s, &source_len, source.u, source_len, REPORT_ERRORS, NULL) == FAILURE) {
+ RETURN_FALSE;
+ }
+ } else {
+ source.s = php_libxml_unicode_to_string(source.u, source_len, &source_len TSRMLS_CC);
}
}
- newdoc = dom_document_parser(id, mode, source, options TSRMLS_CC);
+ newdoc = dom_document_parser(id, mode, source.s, options TSRMLS_CC);
if (source_type == IS_UNICODE) {
- efree(source);
+ efree(source.s);
}
if (!newdoc)
#if defined(LIBXML_SCHEMAS_ENABLED)
-static void
-_dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
+static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
{
zval *id;
xmlDoc *docp;
dom_object *intern;
- char *source = NULL, *valid_file = NULL;
+ zstr source = NULL_ZSTR;
+ char *valid_file = NULL;
int source_len = 0;
xmlSchemaParserCtxtPtr parser;
xmlSchemaPtr sptr;
char resolved_path[MAXPATHLEN + 1];
zend_uchar source_type = IS_STRING;
- if (type == DOM_LOAD_FILE) {
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ot", &id, dom_document_class_entry, &source, &source_len, &source_type) == FAILURE) {
- return;
- }
- } else {
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OS", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
- return;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ot", &id, dom_document_class_entry, &source, &source_len, &source_type) == FAILURE) {
+ return;
}
if (source_len == 0) {
switch (type) {
case DOM_LOAD_FILE:
if (source_type == IS_UNICODE) {
- if (php_stream_path_encode(NULL, &source, &source_len, (UChar*)source, source_len, REPORT_ERRORS, NULL) == FAILURE) {
+ if (php_stream_path_encode(NULL, &source.s, &source_len, source.u, source_len, REPORT_ERRORS, NULL) == FAILURE) {
RETURN_FALSE;
}
}
- valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
+ valid_file = _dom_get_valid_file_path(source.s, resolved_path, MAXPATHLEN TSRMLS_CC);
if (!valid_file) {
if (source_type == IS_UNICODE) {
- efree(source);
+ efree(source.s);
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema file source");
RETURN_FALSE;
parser = xmlSchemaNewParserCtxt(valid_file);
if (source_type == IS_UNICODE) {
- efree(source);
+ efree(source.s);
}
break;
case DOM_LOAD_STRING:
- parser = xmlSchemaNewMemParserCtxt(source, source_len);
+ if (source_type == IS_UNICODE) {
+ source.s = php_libxml_unicode_to_string(source.u, source_len, &source_len TSRMLS_CC);
+ }
+ parser = xmlSchemaNewMemParserCtxt(source.s, source_len);
/* If loading from memory, we need to set the base directory for the document
but it is not apparent how to do that for schema's */
+ if (source_type == IS_UNICODE) {
+ efree(source.s);
+ }
break;
default:
return;
zval *id;
xmlDoc *docp;
dom_object *intern;
- char *source = NULL, *valid_file = NULL;
+ zstr source = NULL_ZSTR;
+ char *valid_file = NULL;
int source_len = 0;
xmlRelaxNGParserCtxtPtr parser;
xmlRelaxNGPtr sptr;
char resolved_path[MAXPATHLEN + 1];
zend_uchar source_type = IS_STRING;
- if (type == DOM_LOAD_FILE) {
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ot", &id, dom_document_class_entry, &source, &source_len, &source_type) == FAILURE) {
- return;
- }
- } else {
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OS", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
- return;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ot", &id, dom_document_class_entry, &source, &source_len, &source_type) == FAILURE) {
+ return;
}
if (source_len == 0) {
switch (type) {
case DOM_LOAD_FILE:
if (source_type == IS_UNICODE) {
- if (php_stream_path_encode(NULL, &source, &source_len, (UChar*)source, source_len, REPORT_ERRORS, NULL) == FAILURE) {
+ if (php_stream_path_encode(NULL, &source.s, &source_len, source.u, source_len, REPORT_ERRORS, NULL) == FAILURE) {
RETURN_FALSE;
}
}
- valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
+ valid_file = _dom_get_valid_file_path(source.s, resolved_path, MAXPATHLEN TSRMLS_CC);
if (!valid_file) {
if (source_type == IS_UNICODE) {
- efree(source);
+ efree(source.s);
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid RelaxNG file source");
RETURN_FALSE;
}
parser = xmlRelaxNGNewParserCtxt(valid_file);
if (source_type == IS_UNICODE) {
- efree(source);
+ efree(source.s);
}
break;
case DOM_LOAD_STRING:
- parser = xmlRelaxNGNewMemParserCtxt(source, source_len);
+ if (source_type == IS_UNICODE) {
+ source.s = php_libxml_unicode_to_string(source.u, source_len, &source_len TSRMLS_CC);
+ }
+ parser = xmlRelaxNGNewMemParserCtxt(source.s, source_len);
/* If loading from memory, we need to set the base directory for the document
but it is not apparent how to do that for schema's */
+ if (source_type == IS_UNICODE) {
+ efree(source.s);
+ }
break;
default:
return;
xmlDoc *docp = NULL, *newdoc;
dom_object *intern;
dom_doc_propsptr doc_prop;
- char *source;
+ zstr source;
int source_len, refcount, ret;
htmlParserCtxtPtr ctxt;
zend_uchar source_type = IS_STRING;
id = getThis();
- if (mode == DOM_LOAD_FILE) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &source, &source_len, &source_type) == FAILURE) {
- return;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &source, &source_len) == FAILURE) {
- return;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &source, &source_len, &source_type) == FAILURE) {
+ return;
}
if (!source_len) {
if (mode == DOM_LOAD_FILE) {
if (source_type == IS_UNICODE) {
- if (php_stream_path_encode(NULL, &source, &source_len, (UChar*)source, source_len, REPORT_ERRORS, NULL) == FAILURE) {
+ if (php_stream_path_encode(NULL, &source.s, &source_len, source.u, source_len, REPORT_ERRORS, NULL) == FAILURE) {
RETURN_FALSE;
}
}
- ctxt = htmlCreateFileParserCtxt(source, NULL);
+ ctxt = htmlCreateFileParserCtxt(source.s, NULL);
if (source_type == IS_UNICODE) {
- efree(source);
+ efree(source.s);
}
} else {
- source_len = xmlStrlen(source);
- ctxt = htmlCreateMemoryParserCtxt(source, source_len);
+ if (source_type == IS_UNICODE) {
+ source.s = php_libxml_unicode_to_string(source.u, source_len, &source_len TSRMLS_CC);
+ }
+
+ ctxt = htmlCreateMemoryParserCtxt(source.s, source_len);
+
+ if (source_type == IS_UNICODE) {
+ efree(source.s);
+ }
}
if (!ctxt) {