php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3384 Problems with the XML module
Submitted: 2000-02-02 06:38 UTC Modified: 2001-02-10 15:35 UTC
From: drew at elysium dot ltd dot uk Assigned: zeev (profile)
Status: Closed Package: Reproducible Crash
PHP Version: 3.0.14 OS: RH 6.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 + 13 = ?
Subscribe to this entry?

 
 [2000-02-02 06:38 UTC] drew at elysium dot ltd dot uk
I have been getting Segmentation faults in Apache children using the XML module.  I have modified the source for the XML module to try and make it more stable.  I have included the diff for my changes.  On the same note, I dont use the DAV module but it looks very similar to the XML module, so the changes I have made to the XML module might well apply to it.

The diff is VERY long, so if you need it E-Mailed to someone please let me know.

Rgds Drew

diff -c php-3.0.14.orig/functions/xml.c php-3.0.14/functions/xml.c
*** php-3.0.14.orig/functions/xml.c     Sat Jan  1 04:31:17 2000
--- php-3.0.14/functions/xml.c  Wed Feb  2 12:22:23 2000
***************
*** 89,100 ****
  inline static char xml_decode_us_ascii(unsigned short);
  static XML_Char *xml_utf8_encode(const char *, int, int *, const XML_Char *);
  static char *xml_utf8_decode(const XML_Char *, int, int *, const XML_Char *);
! static pval *xml_call_handler(xml_parser *, char *, int, pval **);
  static pval *php3i_xmlcharpval(const XML_Char *, int, const XML_Char *);
  static int php3i_xmlcharlen(const XML_Char *);
  static void php3i_add_to_info(xml_parser *parser,char *name);
  
- 
  void php3i_xml_startElementHandler(void *, const char *, const char **);
  void php3i_xml_endElementHandler(void *, const char *);
  void php3i_xml_characterDataHandler(void *, const XML_Char *, int);
--- 89,99 ----
  inline static char xml_decode_us_ascii(unsigned short);
  static XML_Char *xml_utf8_encode(const char *, int, int *, const XML_Char *);
  static char *xml_utf8_decode(const XML_Char *, int, int *, const XML_Char *);
! static int xml_call_handler(xml_parser *, char *, int, pval **);
  static pval *php3i_xmlcharpval(const XML_Char *, int, const XML_Char *);
  static int php3i_xmlcharlen(const XML_Char *);
  static void php3i_add_to_info(xml_parser *parser,char *name);
  
  void php3i_xml_startElementHandler(void *, const char *, const char **);
  void php3i_xml_endElementHandler(void *, const char *);
  void php3i_xml_characterDataHandler(void *, const XML_Char *, int);
***************
*** 108,145 ****
  /* {{{ extension definition structures */
  
  function_entry xml_functions[] = {
!     PHP_FE(xml_parser_create, NULL)
!     PHP_FE(xml_set_element_handler, NULL)
        PHP_FE(xml_set_character_data_handler, NULL)
        PHP_FE(xml_set_processing_instruction_handler, NULL)
        PHP_FE(xml_set_default_handler, NULL)
        PHP_FE(xml_set_unparsed_entity_decl_handler, NULL)
        PHP_FE(xml_set_notation_decl_handler, NULL)
        PHP_FE(xml_set_external_entity_ref_handler, NULL)
!     PHP_FE(xml_parse, NULL)
!     PHP_FE(xml_parse_into_struct, NULL)
!     PHP_FE(xml_get_error_code, NULL)
!     PHP_FE(xml_error_string, NULL)
!     PHP_FE(xml_get_current_line_number, NULL)
!     PHP_FE(xml_get_current_column_number, NULL)
!     PHP_FE(xml_get_current_byte_index, NULL)
!     PHP_FE(xml_parser_free, NULL)
        PHP_FE(xml_parser_set_option, NULL)
        PHP_FE(xml_parser_get_option, NULL)
        PHP_FE(utf8_encode, NULL)
        PHP_FE(utf8_decode, NULL)
!     {NULL, NULL, NULL}
  };
  
  php3_module_entry xml_module_entry = {
!     "XML",                /* extension name */
!     xml_functions,        /* extension function list */
!     php3_minit_xml,       /* extension-wide startup function */
!     php3_mshutdown_xml,   /* extension-wide shutdown function */
!     php3_rinit_xml,       /* per-request startup function */
!     php3_rshutdown_xml,   /* per-request shutdown function */
!     php3_info_xml,        /* information function */
!     STANDARD_MODULE_PROPERTIES
  };
  
  /* All the encoding functions are set to NULL right now, since all
--- 107,144 ----
  /* {{{ extension definition structures */
  
  function_entry xml_functions[] = {
!       PHP_FE(xml_parser_create, NULL)
!       PHP_FE(xml_set_element_handler, NULL)
        PHP_FE(xml_set_character_data_handler, NULL)
        PHP_FE(xml_set_processing_instruction_handler, NULL)
        PHP_FE(xml_set_default_handler, NULL)
        PHP_FE(xml_set_unparsed_entity_decl_handler, NULL)
        PHP_FE(xml_set_notation_decl_handler, NULL)
        PHP_FE(xml_set_external_entity_ref_handler, NULL)
!       PHP_FE(xml_parse, NULL)
!       PHP_FE(xml_parse_into_struct, NULL)
!       PHP_FE(xml_get_error_code, NULL)
!       PHP_FE(xml_error_string, NULL)
!       PHP_FE(xml_get_current_line_number, NULL)
!       PHP_FE(xml_get_current_column_number, NULL)
!       PHP_FE(xml_get_current_byte_index, NULL)
!       PHP_FE(xml_parser_free, NULL)
        PHP_FE(xml_parser_set_option, NULL)
        PHP_FE(xml_parser_get_option, NULL)
        PHP_FE(utf8_encode, NULL)
        PHP_FE(utf8_decode, NULL)
!       {NULL, NULL, NULL}
  };
  
  php3_module_entry xml_module_entry = {
!       "XML",                /* extension name */
!       xml_functions,        /* extension function list */
!       php3_minit_xml,       /* extension-wide startup function */
!       php3_mshutdown_xml,   /* extension-wide shutdown function */
!       php3_rinit_xml,       /* per-request startup function */
!       php3_rshutdown_xml,   /* per-request shutdown function */
!       php3_info_xml,        /* information function */
!       STANDARD_MODULE_PROPERTIES
  };
  
  /* All the encoding functions are set to NULL right now, since all
***************
*** 149,155 ****
        { "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                  },
!     { NULL,         NULL,                  NULL                  }
  };
  
  /* }}} */
--- 148,154 ----
        { "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                  },
!       { NULL,         NULL,                  NULL                  }
  };
  
  /* }}} */
***************
*** 159,167 ****
  
  int php3_minit_xml(INIT_FUNC_ARGS)
  {
!       XML_GLOBAL(php3_xml_module).le_xml_parser =
!               register_list_destructors(xml_destroy_parser, NULL);
! 
        XML_GLOBAL(php3_xml_module).default_encoding = "ISO-8859-1";
  
        REGISTER_LONG_CONSTANT("XML_ERROR_NONE", XML_ERROR_NONE, CONST_CS|CONST_PERSISTENT);
--- 158,164 ----
  
  int php3_minit_xml(INIT_FUNC_ARGS)
  {
!       XML_GLOBAL(php3_xml_module).le_xml_parser = register_list_destructors(xml_destroy_parser, NULL);
        XML_GLOBAL(php3_xml_module).default_encoding = "ISO-8859-1";
  
        REGISTER_LONG_CONSTANT("XML_ERROR_NONE", XML_ERROR_NONE, CONST_CS|CONST_PERSISTENT);
***************
*** 192,204 ****
        REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_TAGSTART", PHP3_XML_OPTION_SKIP_TAGSTART, CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_WHITE", PHP3_XML_OPTION_SKIP_WHITE, CONST_CS|CONST_PERSISTENT);
        
- 
        return SUCCESS;
  }
  
  /* }}} */
      /* {{{ php3_rinit_xml */
- 
  int php3_rinit_xml(INIT_FUNC_ARGS)
  {
      return SUCCESS;
--- 189,199 ----
***************
*** 206,243 ****
  
  /* }}} */
      /* {{{ php3_mshutdown_xml() */
- 
  int php3_mshutdown_xml()
  {
-       XML_TLS_VARS;
        return SUCCESS;
  }
  
  /* }}} */
      /* {{{ php3_rshutdown_xml() */
- 
  int php3_rshutdown_xml()
  {
!     return SUCCESS;
  }
  
  /* }}} */
      /* {{{ php3_info_xml() */
- 
  void php3_info_xml()
  {
!               PUTS("XML support active");
  }
  
  /* }}} */
  
  /* }}} */
  /* {{{ extension-internal functions */
- 
      /* {{{ xml_get_parser() */
! 
! static xml_parser *
! xml_get_parser(int parser_ind, const char *func, HashTable *list)
  {
        int type;
        xml_parser *parser;
--- 201,231 ----
  
  /* }}} */
      /* {{{ php3_mshutdown_xml() */
  int php3_mshutdown_xml()
  {
        return SUCCESS;
  }
  
  /* }}} */
      /* {{{ php3_rshutdown_xml() */
  int php3_rshutdown_xml()
  {
!       return SUCCESS;
  }
  
  /* }}} */
      /* {{{ php3_info_xml() */
  void php3_info_xml()
  {
!       PUTS("XML support active");
  }
  
  /* }}} */
  
  /* }}} */
  /* {{{ extension-internal functions */
      /* {{{ xml_get_parser() */
! static xml_parser *xml_get_parser(int parser_ind, const char *func, HashTable *list)
  {
        int type;
        xml_parser *parser;
***************
*** 248,261 ****
                php3_error(E_WARNING, "%s: invalid XML parser %d", func, parser_ind);
                return (xml_parser *)NULL;
        }
        return parser;
  }
  
  /* }}} */
      /* {{{ xml_destroy_parser() */
! 
! static void
! xml_destroy_parser(xml_parser *parser)
  {
        XML_TLS_VARS;
    
--- 236,248 ----
                php3_error(E_WARNING, "%s: invalid XML parser %d", func, parser_ind);
                return (xml_parser *)NULL;
        }
+ 
        return parser;
  }
  
  /* }}} */
      /* {{{ xml_destroy_parser() */
! static void xml_destroy_parser(xml_parser *parser)
  {
        XML_TLS_VARS;
    
***************
*** 301,309 ****
  
  /* }}} */
      /* {{{ xml_set_handler() */
! 
! static void
! xml_set_handler(char **nameBufp, pval *data)
  {
        if (data->value.str.len > 0) {
                if (*nameBufp != NULL) {
--- 288,294 ----
  
  /* }}} */
      /* {{{ xml_set_handler() */
! static void xml_set_handler(char **nameBufp, pval *data)
  {
        if (data->value.str.len > 0) {
                if (*nameBufp != NULL) {
***************
*** 320,397 ****
  
  /* }}} */
      /* {{{ xml_call_handler() */
! 
! static pval *
! xml_call_handler(xml_parser *parser, char *funcName, int argc, pval **argv)
  {
        if (parser && funcName) {
-               pval *retval, *func;
                int i;
!               HashTable *function_table;
  
-               func = php3i_string_pval(funcName);
-               retval = emalloc(sizeof(pval));
                /* We cannot call internal variables from a function module as
                   it breaks any chance of compiling it as a module on windows.
                   Instead, we create a callback function. */
!               function_table=php3i_get_function_table();
!               if (call_user_function(function_table, NULL, func, retval, argc, argv) == FAILURE) {
!                       php3tls_pval_destructor(retval);
!                       efree(retval);
!                       return NULL;
                }
!               php3tls_pval_destructor(func);
!               efree(func);
                for (i = 0; i < argc; i++) {
                        php3tls_pval_destructor(argv[i]);
                        efree(argv[i]);
                }
!               return retval;
        }
!       return NULL;
  }
  
  /* }}} */
      /* {{{ xml_encode_iso_8859_1() */
! 
! inline static unsigned short
! xml_encode_iso_8859_1(unsigned char c)
  {
        return (unsigned short)c;
  }
  
  /* }}} */
      /* {{{ xml_decode_iso_8859_1() */
! 
! inline static char
! xml_decode_iso_8859_1(unsigned short c)
  {
        return (char)(c > 0xff ? '?' : c);
  }
  
  /* }}} */
      /* {{{ xml_encode_us_ascii() */
! 
! inline static unsigned short
! xml_encode_us_ascii(unsigned char c)
  {
        return (unsigned short)c;
  }
  
  /* }}} */
      /* {{{ xml_decode_us_ascii() */
! 
! inline static char
! xml_decode_us_ascii(unsigned short c)
  {
        return (char)(c > 0x7f ? '?' : c);
  }
  
  /* }}} */
      /* {{{ xml_get_encoding() */
! 
! static xml_encoding *
! xml_get_encoding(const XML_Char *name)
  {
        xml_encoding *enc = &xml_encodings[0];
  
--- 305,372 ----
  
  /* }}} */
      /* {{{ xml_call_handler() */
! static int xml_call_handler(xml_parser *parser, char *funcName, int argc, pval **argv)
  {
        if (parser && funcName) {
                int i;
!               pval retval;
!               pval *function_name = php3i_string_pval(funcName);
  
                /* We cannot call internal variables from a function module as
                   it breaks any chance of compiling it as a module on windows.
                   Instead, we create a callback function. */
! 
!               if (call_user_function(&GLOBAL(function_table), NULL, function_name, &retval, argc, argv) == FAILURE) {
!                       php3tls_pval_destructor(function_name);
!                       efree(function_name);
! 
!                       return 0;
                }
! 
!               php3tls_pval_destructor(function_name);
!               efree(function_name);
! 
                for (i = 0; i < argc; i++) {
                        php3tls_pval_destructor(argv[i]);
                        efree(argv[i]);
                }
!               convert_to_long(&retval);
!               return retval.value.lval;
        }
!       return 0;
  }
  
  /* }}} */
      /* {{{ xml_encode_iso_8859_1() */
! inline static unsigned short xml_encode_iso_8859_1(unsigned char c)
  {
        return (unsigned short)c;
  }
  
  /* }}} */
      /* {{{ xml_decode_iso_8859_1() */
! inline static char xml_decode_iso_8859_1(unsigned short c)
  {
        return (char)(c > 0xff ? '?' : c);
  }
  
  /* }}} */
      /* {{{ xml_encode_us_ascii() */
! inline static unsigned short xml_encode_us_ascii(unsigned char c)
  {
        return (unsigned short)c;
  }
  
  /* }}} */
      /* {{{ xml_decode_us_ascii() */
! inline static char xml_decode_us_ascii(unsigned short c)
  {
        return (char)(c > 0x7f ? '?' : c);
  }
  
  /* }}} */
      /* {{{ xml_get_encoding() */
! static xml_encoding *xml_get_encoding(const XML_Char *name)
  {
        xml_encoding *enc = &xml_encodings[0];
  
***************
*** 401,413 ****
                }
                enc++;
        }
        return NULL;
  }
  
  /* }}} */
      /* {{{ xml_utf8_encode */
! static XML_Char *
! xml_utf8_encode(const char *s, int len, int *newlen, const XML_Char *encoding)
  {
        int pos = len;
        char *newbuf;
--- 376,388 ----
                }
                enc++;
        }
+ 
        return NULL;
  }
  
  /* }}} */
      /* {{{ xml_utf8_encode */
! static XML_Char *xml_utf8_encode(const char *s, int len, int *newlen, const XML_Char *encoding)
  {
        int pos = len;
        char *newbuf;
***************
*** 416,435 ****
        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.
!                */
                newbuf = emalloc(len);
                memcpy(newbuf, s, len);
                *newlen = len;
                return newbuf;
        }
        /* This is the theoretical max (will never get beyond len * 2 as long
         * as we are converting from single-byte characters, though) */
        newbuf = emalloc(len * 4);
--- 391,410 ----
        xml_encoding *enc = xml_get_encoding(encoding);
  
        *newlen = 0;
!       if (!enc) {
                /* If the target encoding was unknown, fail */
                return NULL;
        }
+ 
+       encoder = enc->encoding_function;
        if (encoder == NULL) {
!               /* If no encoder function was specified, return the data as-is. */
                newbuf = emalloc(len);
                memcpy(newbuf, s, len);
                *newlen = len;
                return newbuf;
        }
+ 
        /* This is the theoretical max (will never get beyond len * 2 as long
         * as we are converting from single-byte characters, though) */
        newbuf = emalloc(len * 4);
***************
*** 452,467 ****
                }
                pos--;
                s++;
-     }
-       if (*newlen < len * 4) {
-               newbuf = erealloc(newbuf, *newlen);
        }
        return newbuf;
  }
  /* }}} */
      /* {{{ xml_utf8_decode */
! static char *
! xml_utf8_decode(const XML_Char *s, int len, int *newlen, const XML_Char *encoding)
  {
        int pos = len;
        char *newbuf = emalloc(len + 1);
--- 427,444 ----
                }
                pos--;
                s++;
        }
+ 
+       if (*newlen < len * 4)
+               newbuf = erealloc(newbuf, *newlen + 1);
+       newbuf[*newlen] = '\0';
+ 
        return newbuf;
  }
+ 
  /* }}} */
      /* {{{ xml_utf8_decode */
! static char *xml_utf8_decode(const XML_Char *s, int len, int *newlen, const XML_Char *encoding)
  {
        int pos = len;
        char *newbuf = emalloc(len + 1);
***************
*** 473,487 ****
        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;
                newbuf[*newlen] = '\0';
                return newbuf;
        }
        while (pos > 0) {
                c = (unsigned char)(*s);
                if (c >= 0xf0) { /* four bytes encoded, 21 bits */
--- 450,465 ----
        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;
                newbuf[*newlen] = '\0';
                return newbuf;
        }
+ 
        while (pos > 0) {
                c = (unsigned char)(*s);
                if (c >= 0xf0) { /* four bytes encoded, 21 bits */
***************
*** 502,517 ****
                }
                newbuf[*newlen] = decoder ? decoder(c) : c;
                ++*newlen;
!     }
        if (*newlen < len) {
                newbuf = erealloc(newbuf, *newlen + 1);
        }
        newbuf[*newlen] = '\0';
        return newbuf;
  }
  /* }}} */
      /* {{{ php3i_xmlcharpval() */
- 
  static pval *php3i_xmlcharpval(const XML_Char *s, int len, const XML_Char *encoding)
  {
        pval *ret = emalloc(sizeof(pval));
--- 480,497 ----
                }
                newbuf[*newlen] = decoder ? decoder(c) : c;
                ++*newlen;
!       }
! 
        if (*newlen < len) {
                newbuf = erealloc(newbuf, *newlen + 1);
        }
        newbuf[*newlen] = '\0';
+ 
        return newbuf;
  }
+ 
  /* }}} */
      /* {{{ php3i_xmlcharpval() */
  static pval *php3i_xmlcharpval(const XML_Char *s, int len, const XML_Char *encoding)
  {
        pval *ret = emalloc(sizeof(pval));
***************
*** 523,536 ****
        if (len == 0) {
                len = php3i_xmlcharlen(s);
        }
        ret->type = IS_STRING;
        ret->value.str.val = xml_utf8_decode(s, len, &ret->value.str.len, encoding);
        return ret;
  }
  
  /* }}} */
      /* {{{ php3i_xmlcharlen() */
- 
  static int php3i_xmlcharlen(const XML_Char *s)
  {
        int len = 0;
--- 503,517 ----
        if (len == 0) {
                len = php3i_xmlcharlen(s);
        }
+ 
        ret->type = IS_STRING;
        ret->value.str.val = xml_utf8_decode(s, len, &ret->value.str.len, encoding);
+ 
        return ret;
  }
  
  /* }}} */
      /* {{{ php3i_xmlcharlen() */
  static int php3i_xmlcharlen(const XML_Char *s)
  {
        int len = 0;
***************
*** 539,544 ****
--- 520,526 ----
                len++;
                s++;
        }
+ 
        return len;
  }
  
***************
*** 548,584 ****
  {
        pval *element, values;
  
!       if (! parser->info) {
                return;
        }
  
!       if (_php3_hash_find(parser->info->value.ht,name,strlen(name) + 1,(void **) &element) == FAILURE) {
                if (array_init(&values) == FAILURE) {
                        php3_error(E_ERROR, "Unable to initialize array");
                        return;
                }
!               
!               _php3_hash_update(parser->info->value.ht, name, strlen(name)+1, (void *) &values, sizeof(pval), (void **) &element);
        } 
-                       
        add_next_index_long(element,parser->curtag);
- 
        
        parser->curtag++;
  }
  
  /* }}} */
! /* {{{ php3i_xml_startElementHandler() */
! 
! void php3i_xml_startElementHandler(void *userData, const char *name,
!                                                                  const char **attributes)
  {
        xml_parser *parser = (xml_parser *)userData;
        const char **attrs = attributes;
        XML_TLS_VARS;
  
        if (parser) {
!               pval *retval, *args[3];
  
                parser->level++;
  
--- 530,561 ----
  {
        pval *element, values;
  
!       if (!parser->info) {
                return;
        }
  
!       if (_php3_hash_find(parser->info->value.ht, name, strlen(name) + 1, (void **)&element) == FAILURE) {
                if (array_init(&values) == FAILURE) {
                        php3_error(E_ERROR, "Unable to initialize array");
                        return;
                }
!               _php3_hash_update(parser->info->value.ht, name, strlen(name) + 1, (void *)&values, sizeof(pval), (void **)&element);
        } 
        add_next_index_long(element,parser->curtag);
        
        parser->curtag++;
  }
  
  /* }}} */
!     /* {{{ php3i_xml_startElementHandler() */
! void php3i_xml_startElementHandler(void *userData, const char *name, const char **attributes)
  {
        xml_parser *parser = (xml_parser *)userData;
        const char **attrs = attributes;
        XML_TLS_VARS;
  
        if (parser) {
!               pval *args[3];
  
                parser->level++;
  
***************
*** 591,652 ****
                        args[1] = php3i_string_pval(name);
                        args[2] = emalloc(sizeof(pval));
                        array_init(args[2]);
                        while (attributes && *attributes) {
                                char *key = (char *)attributes[0];
                                char *value = (char *)attributes[1];
                                char *decoded_value;
!                               int decoded_len;
                                if (parser->case_folding) {
                                        key = _php3_strtoupper(estrdup(key));
                                }
!                               decoded_value = xml_utf8_decode(value, strlen(value),
!                                                                                               &decoded_len,
!                                                                                               parser->target_encoding);
                                
                                add_assoc_stringl(args[2], key, decoded_value, decoded_len, 0);
                                if (parser->case_folding) {
                                        efree(key);
                                }
                                attributes += 2;
                        }
!                       
!                       if ((retval = xml_call_handler(parser, parser->startElementHandler, 3, args))) {
!                               php3tls_pval_destructor(retval);
!                               efree(retval);
!                       }
                } 
  
                if (parser->data) {
-                       pval tag, atr;
                        int atcnt = 0;
  
                        array_init(&tag);
                        array_init(&atr);
  
!                       php3i_add_to_info(parser,((char *) name) + parser->toffset);
  
!                       add_assoc_string(&tag,"tag",((char *) name) + parser->toffset,1); /* cast to avoid gcc-warning */
!                       add_assoc_string(&tag,"type","open",1);
!                       add_assoc_long(&tag,"level",parser->level);
  
!                       parser->ltags[parser->level-1] = estrdup(name);
                        parser->lastwasopen = 1;
  
                        attributes = attrs;
                        while (attributes && *attributes) {
                                char *key = (char *)attributes[0];
                                char *value = (char *)attributes[1];
                                char *decoded_value;
!                               int decoded_len;
                                if (parser->case_folding) {
                                        key = _php3_strtoupper(estrdup(key));
                                }
!                               decoded_value = xml_utf8_decode(value, strlen(value),
!                                                                                               &decoded_len,
!                                                                                               parser->target_encoding);
                                
!                               add_assoc_stringl(&atr,key,decoded_value,decoded_len,0);
                                atcnt++;
                                if (parser->case_folding) {
                                        efree(key);
                                }
--- 568,626 ----
                        args[1] = php3i_string_pval(name);
                        args[2] = emalloc(sizeof(pval));
                        array_init(args[2]);
+ 
                        while (attributes && *attributes) {
+                               int decoded_len;
                                char *key = (char *)attributes[0];
                                char *value = (char *)attributes[1];
                                char *decoded_value;
! 
                                if (parser->case_folding) {
                                        key = _php3_strtoupper(estrdup(key));
                                }
!                               decoded_value = xml_utf8_decode(value, strlen(value), &decoded_len, parser->target_encoding);
                                
                                add_assoc_stringl(args[2], key, decoded_value, decoded_len, 0);
+ 
                                if (parser->case_folding) {
                                        efree(key);
                                }
                                attributes += 2;
                        }
!                       xml_call_handler(parser, parser->startElementHandler, 3, args);
                } 
  
                if (parser->data) {
                        int atcnt = 0;
+                       pval tag, atr;
  
                        array_init(&tag);
                        array_init(&atr);
  
!                       php3i_add_to_info(parser, ((char *)name) + parser->toffset);
  
!                       add_assoc_string(&tag, "tag", ((char *) name) + parser->toffset, 1); /* cast to avoid gcc-warning */
!                       add_assoc_string(&tag, "type", "open", 1);
!                       add_assoc_long(&tag, "level", parser->level);
  
!                       parser->ltags[parser->level - 1] = estrdup(name);
                        parser->lastwasopen = 1;
  
                        attributes = attrs;
                        while (attributes && *attributes) {
+                               int decoded_len;
                                char *key = (char *)attributes[0];
                                char *value = (char *)attributes[1];
                                char *decoded_value;
! 
                                if (parser->case_folding) {
                                        key = _php3_strtoupper(estrdup(key));
                                }
!                               decoded_value = xml_utf8_decode(value, strlen(value), &decoded_len, parser->target_encoding);
                                
!                               add_assoc_stringl(&atr, key, decoded_value, decoded_len, 0);
                                atcnt++;
+ 
                                if (parser->case_folding) {
                                        efree(key);
                                }
***************
*** 654,665 ****
                        }
  
                        if (atcnt) {
!                               _php3_hash_add(tag.value.ht,"attributes",sizeof("attributes"),&atr,sizeof(pval),NULL);
                        } else {
                                php3tls_pval_destructor(&atr);
                        }
! 
!                       _php3_hash_next_index_insert(parser->data->value.ht,&tag,sizeof(pval),(void *) &parser->ctag);
                }
  
                if (parser->case_folding) {
--- 628,638 ----
                        }
  
                        if (atcnt) {
!                               _php3_hash_add(tag.value.ht, "attributes", sizeof("attributes"), &atr, sizeof(pval), NULL);
                        } else {
                                php3tls_pval_destructor(&atr);
                        }
!                       _php3_hash_next_index_insert(parser->data->value.ht, &tag, sizeof(pval), (void *)&parser->ctag);
                }
  
                if (parser->case_folding) {
***************
*** 670,683 ****
  
  /* }}} */
      /* {{{ php3i_xml_endElementHandler() */
- 
  void php3i_xml_endElementHandler(void *userData, const char *name)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser) {
!               pval *retval, *args[2];
  
                if (parser->case_folding) {
                        name = _php3_strtoupper(estrdup(name));
--- 643,655 ----
  
  /* }}} */
      /* {{{ php3i_xml_endElementHandler() */
  void php3i_xml_endElementHandler(void *userData, const char *name)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser) {
!               pval *args[2];
  
                if (parser->case_folding) {
                        name = _php3_strtoupper(estrdup(name));
***************
*** 687,703 ****
                        args[0] = php3i_long_pval(parser->index);
                        args[1] = php3i_string_pval(name);
  
!                       if ((retval = xml_call_handler(parser, parser->endElementHandler, 2, args))) {
!                               php3tls_pval_destructor(retval);
!                               efree(retval);
!                       }
                } 
  
                if (parser->data) {
                        pval tag;
  
                        if (parser->lastwasopen) {
!                               add_assoc_string(parser->ctag,"type","complete",1);
                        } else {
                                array_init(&tag);
                                  
--- 659,672 ----
                        args[0] = php3i_long_pval(parser->index);
                        args[1] = php3i_string_pval(name);
  
!                       xml_call_handler(parser, parser->endElementHandler, 2, args);
                } 
  
                if (parser->data) {
                        pval tag;
  
                        if (parser->lastwasopen) {
!                               add_assoc_string(parser->ctag, "type", "complete", 1);
                        } else {
                                array_init(&tag);
                                  
***************
*** 709,715 ****
                                  
                                _php3_hash_next_index_insert(parser->data->value.ht,&tag,sizeof(pval),NULL);
                        }
- 
                        parser->lastwasopen = 0;
                }
  
--- 678,683 ----
***************
*** 717,723 ****
                        efree((char *)name);
                }
                if (parser->ltags) {
!                       efree(parser->ltags[parser->level-1]);
                }
                parser->level--;
        }
--- 685,691 ----
                        efree((char *)name);
                }
                if (parser->ltags) {
!                       efree(parser->ltags[parser->level - 1]);
                }
                parser->level--;
        }
***************
*** 725,765 ****
  
  /* }}} */
      /* {{{ php3i_xml_characterDataHandler() */
- 
  void php3i_xml_characterDataHandler(void *userData, const XML_Char *s, int len)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser) {
!               pval *retval, *args[2];
  
                if (parser->characterDataHandler) {
                        args[0] = php3i_long_pval(parser->index);
                        args[1] = php3i_xmlcharpval(s, len, parser->target_encoding);
!                       if ((retval = xml_call_handler(parser, parser->characterDataHandler, 2, args))) {
!                               php3tls_pval_destructor(retval);
!                               efree(retval);
!                       }
                } 
  
                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;
--- 693,729 ----
  
  /* }}} */
      /* {{{ php3i_xml_characterDataHandler() */
  void php3i_xml_characterDataHandler(void *userData, const XML_Char *s, int len)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser) {
!               pval *args[2];
  
                if (parser->characterDataHandler) {
                        args[0] = php3i_long_pval(parser->index);
                        args[1] = php3i_xmlcharpval(s, len, parser->target_encoding);
! 
!                       xml_call_handler(parser, parser->characterDataHandler, 2, args);
                } 
  
                if (parser->data) {
                        int i;
                        int doprint = 0;
                        int decoded_len;
+                       char *decoded_value;
                        
!                       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;
***************
*** 770,777 ****
                                        pval *myval;
                                        
                                        /* check if the current tag already has a value - if yes append to that! */
!                                       if (_php3_hash_find(parser->ctag->value.ht,"value",sizeof("value"),(void *) &myval) == SUCCESS) {
                                                int newlen = myval->value.str.len + decoded_len;
                                                myval->value.str.val = erealloc(myval->value.str.val,newlen+1);
                                                strcpy(myval->value.str.val + myval->value.str.len,decoded_value);
                                                myval->value.str.len += decoded_len;
--- 734,742 ----
                                        pval *myval;
                                        
                                        /* check if the current tag already has a value - if yes append to that! */
!                                       if (_php3_hash_find(parser->ctag->value.ht, "value", sizeof("value"), (void *) &myval) == SUCCESS) {
                                                int newlen = myval->value.str.len + decoded_len;
+ 
                                                myval->value.str.val = erealloc(myval->value.str.val,newlen+1);
                                                strcpy(myval->value.str.val + myval->value.str.len,decoded_value);
                                                myval->value.str.len += decoded_len;
***************
*** 784,797 ****
                                        
                                        array_init(&tag);
                                        
!                                       php3i_add_to_info(parser,parser->ltags[parser->level-1] + parser->toffset);
  
!                                       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);
                                        
!                                       _php3_hash_next_index_insert(parser->data->value.ht,&tag,sizeof(pval),NULL);
                                }
                        } else {
                                efree(decoded_value);
--- 749,762 ----
                                        
                                        array_init(&tag);
                                        
!                                       php3i_add_to_info(parser, parser->ltags[parser->level-1] + parser->toffset);
  
!                                       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);
                                        
!                                       _php3_hash_next_index_insert(parser->data->value.ht, &tag, sizeof(pval), NULL);
                                }
                        } else {
                                efree(decoded_value);
***************
*** 802,831 ****
  
  /* }}} */
      /* {{{ php3i_xml_processingInstructionHandler() */
! 
! void php3i_xml_processingInstructionHandler(void *userData,
!                                                                                       const XML_Char *target,
!                                                                                       const XML_Char *data)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser && parser->processingInstructionHandler) {
!               pval *retval, *args[3];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(target, 0, parser->target_encoding);
                args[2] = php3i_xmlcharpval(data, 0, parser->target_encoding);
!               if ((retval = xml_call_handler(parser, parser->processingInstructionHandler, 3, args))) {
!                       php3tls_pval_destructor(retval);
!                       efree(retval);
!               }
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_defaultHandler() */
- 
  void php3i_xml_defaultHandler(void *userData, const XML_Char *s, int len)
  {
        xml_parser *parser = (xml_parser *)userData;
--- 767,790 ----
  
  /* }}} */
      /* {{{ php3i_xml_processingInstructionHandler() */
! void php3i_xml_processingInstructionHandler(void *userData, const XML_Char *target, const XML_Char *data)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser && parser->processingInstructionHandler) {
!               pval *args[3];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(target, 0, parser->target_encoding);
                args[2] = php3i_xmlcharpval(data, 0, parser->target_encoding);
! 
!               xml_call_handler(parser, parser->processingInstructionHandler, 3, args);
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_defaultHandler() */
  void php3i_xml_defaultHandler(void *userData, const XML_Char *s, int len)
  {
        xml_parser *parser = (xml_parser *)userData;
***************
*** 836,863 ****
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(s, len, parser->target_encoding);
!               if ((retval = xml_call_handler(parser, parser->defaultHandler, 2, args))) {
!                       php3tls_pval_destructor(retval);
!                       efree(retval);
!               }
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_unparsedEntityDeclHandler() */
! 
! void php3i_xml_unparsedEntityDeclHandler(void *userData,
!                                                                                const XML_Char *entityName,
!                                                                                const XML_Char *base,
!                                                                                const XML_Char *systemId,
!                                                                                const XML_Char *publicId,
!                                                                                const XML_Char *notationName)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser && parser->unparsedEntityDeclHandler) {
!               pval *retval, *args[5];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(entityName, 0, parser->target_encoding);
--- 795,814 ----
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(s, len, parser->target_encoding);
! 
!               xml_call_handler(parser, parser->defaultHandler, 2, args);
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_unparsedEntityDeclHandler() */
! void php3i_xml_unparsedEntityDeclHandler(void *userData, const XML_Char *entityName, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser && parser->unparsedEntityDeclHandler) {
!               pval *args[6];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(entityName, 0, parser->target_encoding);
***************
*** 865,935 ****
                args[3] = php3i_xmlcharpval(systemId, 0, parser->target_encoding);
                args[4] = php3i_xmlcharpval(publicId, 0, parser->target_encoding);
                args[5] = php3i_xmlcharpval(notationName, 0, parser->target_encoding);
!               if ((retval = xml_call_handler(parser, parser->unparsedEntityDeclHandler, 6, args))) {
!                       php3tls_pval_destructor(retval);
!                       efree(retval);
!               }
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_notationDeclHandler() */
! 
! void
! php3i_xml_notationDeclHandler(void *userData,
!                                                         const XML_Char *notationName,
!                                                         const XML_Char *base,
!                                                         const XML_Char *systemId,
!                                                         const XML_Char *publicId)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser && parser->notationDeclHandler) {
!               pval *retval, *args[5];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(notationName, 0, parser->target_encoding);
                args[2] = php3i_xmlcharpval(base, 0, parser->target_encoding);
                args[3] = php3i_xmlcharpval(systemId, 0, parser->target_encoding);
                args[4] = php3i_xmlcharpval(publicId, 0, parser->target_encoding);
!               if ((retval = xml_call_handler(parser, parser->notationDeclHandler, 5, args))) {
!                       php3tls_pval_destructor(retval);
!                       efree(retval);
!               }
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_externalEntityRefHandler() */
! 
! int
! php3i_xml_externalEntityRefHandler(XML_Parser parserPtr,
!                                                                  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?) */
        XML_TLS_VARS;
  
        if (parser && parser->externalEntityRefHandler) {
!               pval *retval, *args[5];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(openEntityNames, 0, parser->target_encoding);
                args[2] = php3i_xmlcharpval(base, 0, parser->target_encoding);
                args[3] = php3i_xmlcharpval(systemId, 0, parser->target_encoding);
                args[4] = php3i_xmlcharpval(publicId, 0, parser->target_encoding);
!               if ((retval = xml_call_handler(parser, parser->externalEntityRefHandler, 5, args))) {
!                       convert_to_long(retval);
!                       ret = retval->value.lval;
!                       efree(retval);
!               } else {
!                       ret = 0;
!               }
        }
        return ret;
  }
  
--- 816,866 ----
                args[3] = php3i_xmlcharpval(systemId, 0, parser->target_encoding);
                args[4] = php3i_xmlcharpval(publicId, 0, parser->target_encoding);
                args[5] = php3i_xmlcharpval(notationName, 0, parser->target_encoding);
! 
!               xml_call_handler(parser, parser->unparsedEntityDeclHandler, 6, args);
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_notationDeclHandler() */
! void php3i_xml_notationDeclHandler(void *userData, const XML_Char *notationName, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
  {
        xml_parser *parser = (xml_parser *)userData;
        XML_TLS_VARS;
  
        if (parser && parser->notationDeclHandler) {
!               pval *args[5];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(notationName, 0, parser->target_encoding);
                args[2] = php3i_xmlcharpval(base, 0, parser->target_encoding);
                args[3] = php3i_xmlcharpval(systemId, 0, parser->target_encoding);
                args[4] = php3i_xmlcharpval(publicId, 0, parser->target_encoding);
! 
!               xml_call_handler(parser, parser->notationDeclHandler, 5, args);
        }
  }
  
  /* }}} */
      /* {{{ php3i_xml_externalEntityRefHandler() */
! int php3i_xml_externalEntityRefHandler(XML_Parser parserPtr, 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?) */
        XML_TLS_VARS;
  
        if (parser && parser->externalEntityRefHandler) {
!               pval *args[5];
  
                args[0] = php3i_long_pval(parser->index);
                args[1] = php3i_xmlcharpval(openEntityNames, 0, parser->target_encoding);
                args[2] = php3i_xmlcharpval(base, 0, parser->target_encoding);
                args[3] = php3i_xmlcharpval(systemId, 0, parser->target_encoding);
                args[4] = php3i_xmlcharpval(publicId, 0, parser->target_encoding);
! 
!               ret = xml_call_handler(parser, parser->externalEntityRefHandler, 5, args);
        }
+ 
        return ret;
  }
  
***************
*** 943,957 ****
     Create an XML parser */
  PHP_FUNCTION(xml_parser_create)
  {
-       xml_parser *parser;
        int id, argc;
        pval *encodingArg = NULL;
        XML_Char *encoding;
-       char thisfunc[] = "xml_parser_create";
        XML_TLS_VARS;
  
        argc = ARG_COUNT(ht);
- 
        if (argc > 1 || getParameters(ht, argc, &encodingArg) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
--- 874,886 ----
     Create an XML parser */
  PHP_FUNCTION(xml_parser_create)
  {
        int id, argc;
+       xml_parser *parser;
        pval *encodingArg = NULL;
        XML_Char *encoding;
        XML_TLS_VARS;
  
        argc = ARG_COUNT(ht);
        if (argc > 1 || getParameters(ht, argc, &encodingArg) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
***************
*** 961,978 ****
                /* The supported encoding types are hardcoded here because
                 * we are limited to the encodings supported by expat/xmltok.
                 */
!               if (strncasecmp(encodingArg->value.str.val, "ISO-8859-1",
!                                               encodingArg->value.str.len) == 0) {
                        encoding = "ISO-8859-1";
!               } else if (strncasecmp(encodingArg->value.str.val, "UTF-8",
!                                               encodingArg->value.str.len) == 0) {
                        encoding = "UTF-8";
!               } else if (strncasecmp(encodingArg->value.str.val, "US-ASCII",
!                                               encodingArg->value.str.len) == 0) {
                        encoding = "US-ASCII";
                } else { /* UTF-16 not supported */
!                       php3_error(E_WARNING, "%s: unsupported source encoding \"%s\"",
!                                          thisfunc, encodingArg->value.str.val);
                        RETURN_FALSE;
                }
        } else {
--- 890,903 ----
                /* The supported encoding types are hardcoded here because
                 * we are limited to the encodings supported by expat/xmltok.
                 */
!               if (strncasecmp(encodingArg->value.str.val, "ISO-8859-1", encodingArg->value.str.len) == 0) {
                        encoding = "ISO-8859-1";
!               } else if (strncasecmp(encodingArg->value.str.val, "UTF-8", encodingArg->value.str.len) == 0) {
                        encoding = "UTF-8";
!               } else if (strncasecmp(encodingArg->value.str.val, "US-ASCII", encodingArg->value.str.len) == 0) {
                        encoding = "US-ASCII";
                } else { /* UTF-16 not supported */
!                       php3_error(E_WARNING, "xml_parser_create: unsupported source encoding \"%s\"", encodingArg->value.str.val);
                        RETURN_FALSE;
                }
        } else {
***************
*** 984,990 ****
        parser->target_encoding = encoding;
        XML_SetUserData(parser->parser, parser);
        id = php3_list_insert(parser, XML_GLOBAL(php3_xml_module).le_xml_parser);
!       parser = xml_get_parser(id, thisfunc, list);
        parser->index = id;
        parser->case_folding = 1;
  
--- 909,916 ----
        parser->target_encoding = encoding;
        XML_SetUserData(parser->parser, parser);
        id = php3_list_insert(parser, XML_GLOBAL(php3_xml_module).le_xml_parser);
! 
!       parser = xml_get_parser(id, "xml_parser_create", list);
        parser->index = id;
        parser->case_folding = 1;
  
***************
*** 1000,1019 ****
        pval *pind, *shdl, *ehdl;
        XML_TLS_VARS;
  
!       if (ARG_COUNT(ht) != 3 ||
!               getParameters(ht, 3, &pind, &shdl, &ehdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
        convert_to_long(pind);
        convert_to_string(shdl);
        convert_to_string(ehdl);
        parser = xml_get_parser(pind->value.lval, "xml_set_element_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
        xml_set_handler(&parser->startElementHandler, shdl);
        xml_set_handler(&parser->endElementHandler, ehdl);
        XML_SetElementHandler(parser->parser, php3i_xml_startElementHandler, php3i_xml_endElementHandler);
        RETVAL_TRUE;
  }
  /* }}} */
--- 926,948 ----
        pval *pind, *shdl, *ehdl;
        XML_TLS_VARS;
  
!       if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &pind, &shdl, &ehdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(shdl);
        convert_to_string(ehdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_element_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->startElementHandler, shdl);
        xml_set_handler(&parser->endElementHandler, ehdl);
        XML_SetElementHandler(parser->parser, php3i_xml_startElementHandler, php3i_xml_endElementHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
***************
*** 1029,1042 ****
--- 958,975 ----
        if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pind, &hdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(hdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_character_data_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->characterDataHandler, hdl);
        XML_SetCharacterDataHandler(parser->parser, php3i_xml_characterDataHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
***************
*** 1052,1065 ****
--- 985,1002 ----
        if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pind, &hdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(hdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_processing_instruction_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->processingInstructionHandler, hdl);
        XML_SetProcessingInstructionHandler(parser->parser, php3i_xml_processingInstructionHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
***************
*** 1075,1088 ****
--- 1012,1029 ----
        if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pind, &hdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(hdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_default_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->defaultHandler, hdl);
        XML_SetDefaultHandler(parser->parser, php3i_xml_defaultHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
***************
*** 1098,1117 ****
--- 1039,1063 ----
        if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pind, &hdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(hdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_unparsed_entity_decl_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->unparsedEntityDeclHandler, hdl);
        XML_SetUnparsedEntityDeclHandler(parser->parser, php3i_xml_unparsedEntityDeclHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
  
  /* {{{ proto int xml_set_notation_decl_handler(int pind, string hdl) 
     Set up notation declaration handler */
+ 
  PHP_FUNCTION(xml_set_notation_decl_handler)
  {
        xml_parser *parser;
***************
*** 1121,1134 ****
--- 1067,1084 ----
        if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pind, &hdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(hdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_notation_decl_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->notationDeclHandler, hdl);
        XML_SetNotationDeclHandler(parser->parser, php3i_xml_notationDeclHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
***************
*** 1144,1157 ****
--- 1094,1111 ----
        if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pind, &hdl) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(hdl);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_set_external_entity_ref_handler", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        xml_set_handler(&parser->externalEntityRefHandler, hdl);
        XML_SetExternalEntityRefHandler(parser->parser, php3i_xml_externalEntityRefHandler);
+ 
        RETVAL_TRUE;
  }
  /* }}} */
***************
*** 1160,1207 ****
     Start parsing an XML document */
  PHP_FUNCTION(xml_parse)
  {
        xml_parser *parser;
        pval *pind, *data, *final;
-       int argc, isFinal, ret;
        XML_TLS_VARS;
  
        argc = ARG_COUNT(ht);
        if (argc < 2 || argc > 3 || getParameters(ht, argc, &pind, &data, &final) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
        convert_to_long(pind);
        convert_to_string(data);
        if (argc == 3) {
                convert_to_long(final);
                isFinal = final->value.lval;
-       } else {
-               isFinal = 0;
        }
        parser = xml_get_parser(pind->value.lval, "XML_Parse", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
        /* fflush(stdout); uups, that can't be serious?!?!?*/
        ret = XML_Parse(parser->parser, data->value.str.val, data->value.str.len, isFinal);
        RETVAL_LONG(ret);
  }
  
  /* }}} */
  /* {{{ proto int xml_parse_into_struct(int pind, string data, array &struct, array &index) 
     Parsing a XML document */
- 
  PHP_FUNCTION(xml_parse_into_struct)
  {
-       xml_parser *parser;
-       pval *pind, *data, *xdata,*info = 0;
        int argc, ret;
        XML_TLS_VARS;
  
        argc = ARG_COUNT(ht);
        if (getParameters(ht, 4, &pind, &data, &xdata,&info) == SUCCESS) {
                if (!ParameterPassedByReference(ht, 4)) {
                        php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
!             RETURN_FALSE;
                }
                array_init(info);
        } else if (getParameters(ht, 3, &pind, &data, &xdata) == FAILURE) {
--- 1114,1163 ----
     Start parsing an XML document */
  PHP_FUNCTION(xml_parse)
  {
+       int argc, isFinal = 0, ret;
        xml_parser *parser;
        pval *pind, *data, *final;
        XML_TLS_VARS;
  
        argc = ARG_COUNT(ht);
        if (argc < 2 || argc > 3 || getParameters(ht, argc, &pind, &data, &final) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        convert_to_string(data);
        if (argc == 3) {
                convert_to_long(final);
                isFinal = final->value.lval;
        }
+ 
        parser = xml_get_parser(pind->value.lval, "XML_Parse", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        /* fflush(stdout); uups, that can't be serious?!?!?*/
+ 
        ret = XML_Parse(parser->parser, data->value.str.val, data->value.str.len, isFinal);
+ 
        RETVAL_LONG(ret);
  }
  
  /* }}} */
  /* {{{ proto int xml_parse_into_struct(int pind, string data, array &struct, array &index) 
     Parsing a XML document */
  PHP_FUNCTION(xml_parse_into_struct)
  {
        int argc, ret;
+       xml_parser *parser;
+       pval *pind, *data, *xdata, *info = 0;
        XML_TLS_VARS;
  
        argc = ARG_COUNT(ht);
        if (getParameters(ht, 4, &pind, &data, &xdata,&info) == SUCCESS) {
                if (!ParameterPassedByReference(ht, 4)) {
                        php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
!                       RETURN_FALSE;
                }
                array_init(info);
        } else if (getParameters(ht, 3, &pind, &data, &xdata) == FAILURE) {
***************
*** 1217,1223 ****
        convert_to_string(data);
        array_init(xdata);
  
!       parser = xml_get_parser(pind->value.lval, "XML_Parse_Into_Struct", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
--- 1173,1179 ----
        convert_to_string(data);
        array_init(xdata);
  
!       parser = xml_get_parser(pind->value.lval, "xml_parse_into_struct", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
***************
*** 1248,1258 ****
--- 1204,1216 ----
        if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &pind) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
        parser = xml_get_parser(pind->value.lval, "xml_get_error_code", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        RETVAL_LONG((long)XML_GetErrorCode(parser->parser));
  }
  /* }}} */
***************
*** 1261,1278 ****
     Get XML parser error string */
  PHP_FUNCTION(xml_error_string)
  {
-       pval *code;
        char *str;
        XML_TLS_VARS;
  
        if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &code) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
        convert_to_long(code);
        str = (char *)XML_ErrorString((int)code->value.lval);
!       if (str) {
                RETVAL_STRING(str, 1);
-       }
  }
  /* }}} */
  
--- 1219,1237 ----
     Get XML parser error string */
  PHP_FUNCTION(xml_error_string)
  {
        char *str;
+       pval *code;
        XML_TLS_VARS;
  
        if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &code) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(code);
+ 
        str = (char *)XML_ErrorString((int)code->value.lval);
!       if (str)
                RETVAL_STRING(str, 1);
  }
  /* }}} */
  
***************
*** 1287,1297 ****
--- 1246,1259 ----
        if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &pind) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_get_current_line_number", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        RETVAL_LONG(XML_GetCurrentLineNumber(parser->parser));
  }
  /* }}} */
***************
*** 1307,1317 ****
--- 1269,1282 ----
        if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &pind) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
+ 
        convert_to_long(pind);
+ 
        parser = xml_get_parser(pind->value.lval, "xml_get_current_column_number", list);
        if (parser == NULL) {
                RETURN_FALSE;
        }
+ 
        RETVAL_LONG(XML_GetCurrentColumnNumber(parser->parser));
  }
  /* }}} */
***************
*** 1327,1343 ****
--- 1292,1312 ----
        if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &pind) == FAILURE) {
              

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-02-07 09:51 UTC] thies at cvs dot php dot net
this has nothing to do with the xml-module as far as i can see (did some poking with gdb & purify). 

this can only be fixed by one of the parser-guys

(i sent some description directly to zeev & andi)


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC