]> granicus.if.org Git - php/commitdiff
buffer error messages until newline is hit
authorRob Richards <rrichards@php.net>
Tue, 9 Dec 2003 21:55:02 +0000 (21:55 +0000)
committerRob Richards <rrichards@php.net>
Tue, 9 Dec 2003 21:55:02 +0000 (21:55 +0000)
ext/libxml/libxml.c
ext/libxml/php_libxml.h

index 49500d88aa8eb7a569c629503e5bf8854fef3889..f9e6ded171bf457ad0cd434f2fafbf7ae507db20 100644 (file)
@@ -221,6 +221,7 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC)
 static void php_libxml_init_globals(php_libxml_globals *libxml_globals_p TSRMLS_DC)
 {
        LIBXML(stream_context) = NULL;
+       LIBXML(error_buffer) = NULL;
 }
 #endif
 
@@ -297,19 +298,31 @@ static void php_libxml_error_handler(void *ctx, const char *msg, ...)
 {
        va_list ap;
        char *buf;
-       int len;
+       int len, len_iter, output = 0;
+
+       TSRMLS_FETCH();
 
        va_start(ap, msg);
        len = vspprintf(&buf, 0, msg, ap);
        va_end(ap);
-       
+
+       len_iter = len;
+
        /* remove any trailing \n */
-       while (len && buf[--len] == '\n') {
-               buf[len] = '\0';
+       while (len && buf[--len_iter] == '\n') {
+               buf[len_iter] = '\0';
+               output = 1;
        }
 
-       php_error(E_WARNING, "%s", buf);
+       smart_str_appendl(&LIBXML(error_buffer), buf, len);
+
        efree(buf);
+
+       if (output == 1) {
+               php_error(E_WARNING, "%s", (char *) LIBXML(error_buffer));
+               smart_str_free(&LIBXML(error_buffer));
+               LIBXML(error_buffer) = NULL;
+       }
 }
 
 PHP_LIBXML_API void php_libxml_initialize() {
@@ -357,6 +370,7 @@ PHP_MINIT_FUNCTION(libxml)
        ts_allocate_id(&libxml_globals_id, sizeof(php_libxml_globals), (ts_allocate_ctor) php_libxml_init_globals, NULL);
 #else
        LIBXML(stream_context) = NULL;
+       LIBXML(error_buffer) = NULL;
 #endif
 
        return SUCCESS;
@@ -378,6 +392,10 @@ PHP_MSHUTDOWN_FUNCTION(libxml)
 
 PHP_RSHUTDOWN_FUNCTION(libxml)
 {
+       if (LIBXML(error_buffer)) {
+               smart_str_free(&LIBXML(error_buffer));
+               LIBXML(error_buffer) = NULL;
+       }
        return SUCCESS;
 }
 
index 6ed39f88ef5f836da6554cc1063aaecfc75f4e35..11a63609e92b7090d6a3aff693b136316b431b09 100644 (file)
@@ -37,10 +37,12 @@ extern zend_module_entry libxml_module_entry;
 #define PHP_LIBXML_API
 #endif
 
+#include "ext/standard/php_smart_str.h"
 #include <libxml/tree.h>
 
 typedef struct {
        zval *stream_context;
+       smart_str *error_buffer;
 } php_libxml_globals;
 
 typedef struct _php_libxml_ref_obj {