summaryrefslogtreecommitdiff
path: root/ext/xml/xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/xml/xml.c')
-rw-r--r--ext/xml/xml.c128
1 files changed, 62 insertions, 66 deletions
diff --git a/ext/xml/xml.c b/ext/xml/xml.c
index 7f1bb30571..f927afd764 100644
--- a/ext/xml/xml.c
+++ b/ext/xml/xml.c
@@ -70,7 +70,7 @@ ZEND_GET_MODULE(xml)
/* }}} */
-#define SKIP_TAGSTART(str) ((str) + (parser->toffset > strlen(str) ? strlen(str) : parser->toffset))
+#define SKIP_TAGSTART(str) ((str) + (parser->toffset > (int)strlen(str) ? strlen(str) : parser->toffset))
/* {{{ function prototypes */
@@ -212,7 +212,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_xml_parser_get_option, 0, 0, 2)
ZEND_ARG_INFO(0, option)
ZEND_END_ARG_INFO()
-const zend_function_entry xml_functions[] = {
+static const zend_function_entry xml_functions[] = {
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)
@@ -270,7 +270,7 @@ zend_module_entry xml_module_entry = {
/* 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[] = {
+const xml_encoding xml_encodings[] = {
{ (XML_Char *)"ISO-8859-1", xml_decode_iso_8859_1, xml_encode_iso_8859_1 },
{ (XML_Char *)"US-ASCII", xml_decode_us_ascii, xml_encode_us_ascii },
{ (XML_Char *)"UTF-8", NULL, NULL },
@@ -280,7 +280,7 @@ xml_encoding xml_encodings[] = {
static XML_Memory_Handling_Suite php_xml_mem_hdlrs;
/* True globals, no need for thread safety */
-static int le_xml_parser;
+static int le_xml_parser;
/* }}} */
@@ -343,7 +343,7 @@ PHP_MINIT_FUNCTION(xml)
REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_WHITE", PHP_XML_OPTION_SKIP_WHITE, CONST_CS|CONST_PERSISTENT);
/* this object should not be pre-initialised at compile time,
- as the order of members may vary */
+ 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;
@@ -391,7 +391,7 @@ static void _xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encodi
static void xml_parser_dtor(zend_resource *rsrc)
{
xml_parser *parser = (xml_parser *)rsrc->ptr;
-
+
if (parser->parser) {
XML_ParserFree(parser->parser);
}
@@ -469,7 +469,7 @@ static void xml_set_handler(zval *handler, zval *data)
/* {{{ xml_call_handler() */
static void xml_call_handler(xml_parser *parser, zval *handler, zend_function *function_ptr, int argc, zval *argv, zval *retval)
{
- int i;
+ int i;
ZVAL_UNDEF(retval);
if (parser && handler && !EG(exception)) {
@@ -498,10 +498,10 @@ static void xml_call_handler(xml_parser *parser, zval *handler, zend_function *f
Z_TYPE_P(obj) == IS_OBJECT &&
Z_TYPE_P(method) == IS_STRING) {
php_error_docref(NULL, E_WARNING, "Unable to call handler %s::%s()", ZSTR_VAL(Z_OBJCE_P(obj)->name), Z_STRVAL_P(method));
- } else
+ } else
php_error_docref(NULL, E_WARNING, "Unable to call handler");
}
- }
+ }
for (i = 0; i < argc; i++) {
zval_ptr_dtor(&argv[i]);
}
@@ -537,9 +537,9 @@ inline static char xml_decode_us_ascii(unsigned short c)
/* }}} */
/* {{{ xml_get_encoding() */
-static xml_encoding *xml_get_encoding(const XML_Char *name)
+static const xml_encoding *xml_get_encoding(const XML_Char *name)
{
- xml_encoding *enc = &xml_encodings[0];
+ const xml_encoding *enc = &xml_encodings[0];
while (enc && enc->name) {
if (strcasecmp((char *)name, (char *)enc->name) == 0) {
@@ -558,7 +558,7 @@ PHP_XML_API zend_string *xml_utf8_encode(const char *s, size_t len, const XML_Ch
zend_string *str;
unsigned int c;
unsigned short (*encoder)(unsigned char) = NULL;
- xml_encoding *enc = xml_get_encoding(encoding);
+ const xml_encoding *enc = xml_get_encoding(encoding);
if (enc) {
encoder = enc->encoding_function;
@@ -608,7 +608,7 @@ PHP_XML_API zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XM
size_t pos = 0;
unsigned int c;
char (*decoder)(unsigned short) = NULL;
- xml_encoding *enc = xml_get_encoding(encoding);
+ const xml_encoding *enc = xml_get_encoding(encoding);
zend_string *str;
if (enc) {
@@ -683,10 +683,10 @@ static void _xml_add_to_info(xml_parser *parser,char *name)
zval values;
array_init(&values);
element = zend_hash_str_update(Z_ARRVAL(parser->info), name, strlen(name), &values);
- }
-
+ }
+
add_next_index_long(element, parser->curtag);
-
+
parser->curtag++;
}
/* }}} */
@@ -735,12 +735,12 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
attributes += 2;
- zend_string_release(att);
+ zend_string_release_ex(att, 0);
}
-
+
xml_call_handler(parser, &parser->startElementHandler, parser->startElementPtr, 3, args, &retval);
zval_ptr_dtor(&retval);
- }
+ }
if (!Z_ISUNDEF(parser->data)) {
if (parser->level <= XML_MAXLEVEL) {
@@ -773,7 +773,7 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
atcnt++;
attributes += 2;
- zend_string_release(att);
+ zend_string_release_ex(att, 0);
}
if (atcnt) {
@@ -788,7 +788,7 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
}
}
- zend_string_release(tag_name);
+ zend_string_release_ex(tag_name, 0);
}
}
/* }}} */
@@ -797,12 +797,11 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
void _xml_endElementHandler(void *userData, const XML_Char *name)
{
xml_parser *parser = (xml_parser *)userData;
- zend_string *tag_name;
if (parser) {
zval retval, args[2];
- tag_name = _xml_decode_tag(parser, (const char *)name);
+ zend_string *tag_name = _xml_decode_tag(parser, (const char *)name);
if (!Z_ISUNDEF(parser->endElementHandler)) {
ZVAL_COPY(&args[0], &parser->index);
@@ -810,7 +809,7 @@ void _xml_endElementHandler(void *userData, const XML_Char *name)
xml_call_handler(parser, &parser->endElementHandler, parser->endElementPtr, 2, args, &retval);
zval_ptr_dtor(&retval);
- }
+ }
if (!Z_ISUNDEF(parser->data)) {
zval tag;
@@ -819,20 +818,20 @@ void _xml_endElementHandler(void *userData, const XML_Char *name)
add_assoc_string(parser->ctag, "type", "complete");
} else {
array_init(&tag);
-
+
_xml_add_to_info(parser, ZSTR_VAL(tag_name) + parser->toffset);
add_assoc_string(&tag, "tag", SKIP_TAGSTART(ZSTR_VAL(tag_name))); /* cast to avoid gcc-warning */
add_assoc_string(&tag, "type", "close");
add_assoc_long(&tag, "level", parser->level);
-
+
zend_hash_next_index_insert(Z_ARRVAL(parser->data), &tag);
}
parser->lastwasopen = 0;
}
- zend_string_release(tag_name);
+ zend_string_release_ex(tag_name, 0);
if ((parser->ltags) && (parser->level <= XML_MAXLEVEL)) {
efree(parser->ltags[parser->level-1]);
@@ -856,7 +855,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
_xml_xmlchar_zval(s, len, parser->target_encoding, &args[1]);
xml_call_handler(parser, &parser->characterDataHandler, parser->characterDataPtr, 2, args, &retval);
zval_ptr_dtor(&retval);
- }
+ }
if (!Z_ISUNDEF(parser->data)) {
size_t i;
@@ -881,18 +880,18 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
if (doprint || (! parser->skipwhite)) {
if (parser->lastwasopen) {
zval *myval;
-
+
/* check if the current tag already has a value - if yes append to that! */
if ((myval = zend_hash_str_find(Z_ARRVAL_P(parser->ctag), "value", sizeof("value") - 1))) {
int newlen = Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value);
Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - ZSTR_LEN(decoded_value),
ZSTR_VAL(decoded_value), ZSTR_LEN(decoded_value) + 1);
- zend_string_release(decoded_value);
+ zend_string_release_ex(decoded_value, 0);
} else {
add_assoc_str(parser->ctag, "value", decoded_value);
}
-
+
} else {
zval tag;
zval *curtag, *mytype, *myval;
@@ -905,7 +904,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - ZSTR_LEN(decoded_value),
ZSTR_VAL(decoded_value), ZSTR_LEN(decoded_value) + 1);
- zend_string_release(decoded_value);
+ zend_string_release_ex(decoded_value, 0);
return;
}
}
@@ -929,7 +928,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
}
}
} else {
- zend_string_release(decoded_value);
+ zend_string_release_ex(decoded_value, 0);
}
}
}
@@ -970,8 +969,8 @@ void _xml_defaultHandler(void *userData, const XML_Char *s, int len)
/* }}} */
/* {{{ _xml_unparsedEntityDeclHandler() */
-void _xml_unparsedEntityDeclHandler(void *userData,
- const XML_Char *entityName,
+void _xml_unparsedEntityDeclHandler(void *userData,
+ const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
@@ -1092,9 +1091,9 @@ static void php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAMETERS, int ns_supp
char *ns_param = NULL;
size_t ns_param_len = 0;
-
+
XML_Char *encoding;
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS(), (ns_support ? "|ss": "|s"), &encoding_param, &encoding_param_len, &ns_param, &ns_param_len) == FAILURE) {
RETURN_FALSE;
}
@@ -1139,15 +1138,15 @@ static void php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAMETERS, int ns_supp
}
/* }}} */
-/* {{{ proto resource xml_parser_create([string encoding])
+/* {{{ 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);
+ php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
-/* {{{ proto resource xml_parser_create_ns([string encoding [, string sep]])
+/* {{{ proto resource xml_parser_create_ns([string encoding [, string sep]])
Create an XML parser */
PHP_FUNCTION(xml_parser_create_ns)
{
@@ -1155,7 +1154,7 @@ PHP_FUNCTION(xml_parser_create_ns)
}
/* }}} */
-/* {{{ proto int xml_set_object(resource parser, object &obj)
+/* {{{ proto int xml_set_object(resource parser, object &obj)
Set up object which should be used for callbacks */
PHP_FUNCTION(xml_set_object)
{
@@ -1184,7 +1183,7 @@ PHP_FUNCTION(xml_set_object)
}
/* }}} */
-/* {{{ proto int xml_set_element_handler(resource parser, string shdl, string ehdl)
+/* {{{ proto int xml_set_element_handler(resource parser, string shdl, string ehdl)
Set up start and end element handlers */
PHP_FUNCTION(xml_set_element_handler)
{
@@ -1206,7 +1205,7 @@ PHP_FUNCTION(xml_set_element_handler)
}
/* }}} */
-/* {{{ proto int xml_set_character_data_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_character_data_handler(resource parser, string hdl)
Set up character data handler */
PHP_FUNCTION(xml_set_character_data_handler)
{
@@ -1227,7 +1226,7 @@ PHP_FUNCTION(xml_set_character_data_handler)
}
/* }}} */
-/* {{{ proto int xml_set_processing_instruction_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_processing_instruction_handler(resource parser, string hdl)
Set up processing instruction (PI) handler */
PHP_FUNCTION(xml_set_processing_instruction_handler)
{
@@ -1248,7 +1247,7 @@ PHP_FUNCTION(xml_set_processing_instruction_handler)
}
/* }}} */
-/* {{{ proto int xml_set_default_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_default_handler(resource parser, string hdl)
Set up default handler */
PHP_FUNCTION(xml_set_default_handler)
{
@@ -1269,7 +1268,7 @@ PHP_FUNCTION(xml_set_default_handler)
}
/* }}} */
-/* {{{ proto int xml_set_unparsed_entity_decl_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_unparsed_entity_decl_handler(resource parser, string hdl)
Set up unparsed entity declaration handler */
PHP_FUNCTION(xml_set_unparsed_entity_decl_handler)
{
@@ -1290,7 +1289,7 @@ PHP_FUNCTION(xml_set_unparsed_entity_decl_handler)
}
/* }}} */
-/* {{{ proto int xml_set_notation_decl_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_notation_decl_handler(resource parser, string hdl)
Set up notation declaration handler */
PHP_FUNCTION(xml_set_notation_decl_handler)
{
@@ -1311,7 +1310,7 @@ PHP_FUNCTION(xml_set_notation_decl_handler)
}
/* }}} */
-/* {{{ proto int xml_set_external_entity_ref_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_external_entity_ref_handler(resource parser, string hdl)
Set up external entity reference handler */
PHP_FUNCTION(xml_set_external_entity_ref_handler)
{
@@ -1332,7 +1331,7 @@ PHP_FUNCTION(xml_set_external_entity_ref_handler)
}
/* }}} */
-/* {{{ proto int xml_set_start_namespace_decl_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_start_namespace_decl_handler(resource parser, string hdl)
Set up character data handler */
PHP_FUNCTION(xml_set_start_namespace_decl_handler)
{
@@ -1353,7 +1352,7 @@ PHP_FUNCTION(xml_set_start_namespace_decl_handler)
}
/* }}} */
-/* {{{ proto int xml_set_end_namespace_decl_handler(resource parser, string hdl)
+/* {{{ proto int xml_set_end_namespace_decl_handler(resource parser, string hdl)
Set up character data handler */
PHP_FUNCTION(xml_set_end_namespace_decl_handler)
{
@@ -1416,7 +1415,7 @@ PHP_FUNCTION(xml_parse_into_struct)
return;
}
- if (info) {
+ if (info) {
zval_ptr_dtor(info);
array_init(info);
}
@@ -1429,11 +1428,11 @@ PHP_FUNCTION(xml_parse_into_struct)
array_init(xdata);
ZVAL_COPY_VALUE(&parser->data, xdata);
-
+
if (info) {
ZVAL_COPY_VALUE(&parser->info, info);
}
-
+
parser->level = 0;
parser->ltags = safe_emalloc(XML_MAXLEVEL, sizeof(char *), 0);
@@ -1449,7 +1448,7 @@ PHP_FUNCTION(xml_parse_into_struct)
}
/* }}} */
-/* {{{ proto int xml_get_error_code(resource parser)
+/* {{{ proto int xml_get_error_code(resource parser)
Get XML parser error code */
PHP_FUNCTION(xml_get_error_code)
{
@@ -1486,7 +1485,7 @@ PHP_FUNCTION(xml_error_string)
}
/* }}} */
-/* {{{ proto int xml_get_current_line_number(resource parser)
+/* {{{ proto int xml_get_current_line_number(resource parser)
Get current line number for an XML parser */
PHP_FUNCTION(xml_get_current_line_number)
{
@@ -1524,7 +1523,7 @@ PHP_FUNCTION(xml_get_current_column_number)
}
/* }}} */
-/* {{{ proto int xml_get_current_byte_index(resource parser)
+/* {{{ proto int xml_get_current_byte_index(resource parser)
Get current byte index for an XML parser */
PHP_FUNCTION(xml_get_current_byte_index)
{
@@ -1543,7 +1542,7 @@ PHP_FUNCTION(xml_get_current_byte_index)
}
/* }}} */
-/* {{{ proto int xml_parser_free(resource parser)
+/* {{{ proto int xml_parser_free(resource parser)
Free an XML parser */
PHP_FUNCTION(xml_parser_free)
{
@@ -1571,7 +1570,7 @@ PHP_FUNCTION(xml_parser_free)
}
/* }}} */
-/* {{{ proto int xml_parser_set_option(resource parser, int option, mixed value)
+/* {{{ proto int xml_parser_set_option(resource parser, int option, mixed value)
Set options in an XML parser */
PHP_FUNCTION(xml_parser_set_option)
{
@@ -1589,23 +1588,20 @@ PHP_FUNCTION(xml_parser_set_option)
switch (opt) {
case PHP_XML_OPTION_CASE_FOLDING:
- convert_to_long_ex(val);
- parser->case_folding = Z_LVAL_P(val);
+ parser->case_folding = zval_get_long(val);
break;
case PHP_XML_OPTION_SKIP_TAGSTART:
- convert_to_long_ex(val);
- parser->toffset = Z_LVAL_P(val);
+ parser->toffset = zval_get_long(val);
if (parser->toffset < 0) {
php_error_docref(NULL, E_NOTICE, "tagstart ignored, because it is out of range");
parser->toffset = 0;
}
break;
case PHP_XML_OPTION_SKIP_WHITE:
- convert_to_long_ex(val);
- parser->skipwhite = Z_LVAL_P(val);
+ parser->skipwhite = zval_get_long(val);
break;
case PHP_XML_OPTION_TARGET_ENCODING: {
- xml_encoding *enc;
+ const xml_encoding *enc;
convert_to_string_ex(val);
enc = xml_get_encoding((XML_Char*)Z_STRVAL_P(val));
if (enc == NULL) {
@@ -1624,7 +1620,7 @@ PHP_FUNCTION(xml_parser_set_option)
}
/* }}} */
-/* {{{ proto int xml_parser_get_option(resource parser, int option)
+/* {{{ proto int xml_parser_get_option(resource parser, int option)
Get options from an XML parser */
PHP_FUNCTION(xml_parser_get_option)
{