rrichards               Fri Dec 12 08:54:07 2003 EDT

  Modified files:              
    /php-src/ext/libxml php_libxml.h libxml.c 
  Log:
  consolidate error handling
  
Index: php-src/ext/libxml/php_libxml.h
diff -u php-src/ext/libxml/php_libxml.h:1.4 php-src/ext/libxml/php_libxml.h:1.5
--- php-src/ext/libxml/php_libxml.h:1.4 Tue Dec  9 16:55:02 2003
+++ php-src/ext/libxml/php_libxml.h     Fri Dec 12 08:54:06 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_libxml.h,v 1.4 2003/12/09 21:55:02 rrichards Exp $ */
+/* $Id: php_libxml.h,v 1.5 2003/12/12 13:54:06 rrichards Exp $ */
 
 #ifndef PHP_LIBXML_H
 #define PHP_LIBXML_H
@@ -73,6 +73,9 @@
 void php_libxml_node_free_resource(xmlNodePtr node TSRMLS_DC);
 /* When object dtor is called as node may still be referenced */
 void php_libxml_node_decrement_resource(php_libxml_node_object *object TSRMLS_DC);
+void php_libxml_error_handler(void *ctx, const char *msg, ...);
+void php_libxml_ctx_warning(void *ctx, const char *msg, ...);
+void php_libxml_ctx_error(void *ctx, const char *msg, ...);
 
 #endif /* HAVE_LIBXML */
 
Index: php-src/ext/libxml/libxml.c
diff -u php-src/ext/libxml/libxml.c:1.10 php-src/ext/libxml/libxml.c:1.11
--- php-src/ext/libxml/libxml.c:1.10    Tue Dec  9 16:55:02 2003
+++ php-src/ext/libxml/libxml.c Fri Dec 12 08:54:06 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: libxml.c,v 1.10 2003/12/09 21:55:02 rrichards Exp $ */
+/* $Id: libxml.c,v 1.11 2003/12/12 13:54:06 rrichards Exp $ */
 
 #define IS_EXT_MODULE
 
@@ -43,6 +43,10 @@
 
 #include "php_libxml.h"
 
+#define PHP_LIBXML_ERROR 0
+#define PHP_LIBXML_CTX_ERROR 1
+#define PHP_LIBXML_CTX_WARNING 2
+
 /* a true global for initialization */
 int _php_libxml_initialized = 0;
 
@@ -294,22 +298,33 @@
        return php_stream_close((php_stream*)context);
 }
 
-static void php_libxml_error_handler(void *ctx, const char *msg, ...)
+static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg 
TSRMLS_DC)
+{
+       xmlParserCtxtPtr parser;
+
+       parser = (xmlParserCtxtPtr) ctx;
+
+       if (parser != NULL && parser->input != NULL) {
+               if (parser->input->filename) {
+                       php_error_docref(NULL TSRMLS_CC, level, "%s in %s, line: %d", 
msg, parser->input->filename, parser->input->line);
+               } else {
+                       php_error_docref(NULL TSRMLS_CC, level, "%s in Entity, line: 
%d", msg, parser->input->line);
+               }
+       }
+}
+
+static void php_libxml_internal_error_handler(int error_type, void *ctx, const char 
**msg, va_list ap)
 {
-       va_list ap;
        char *buf;
        int len, len_iter, output = 0;
 
        TSRMLS_FETCH();
 
-       va_start(ap, msg);
-       len = vspprintf(&buf, 0, msg, ap);
-       va_end(ap);
-
+       len = vspprintf(&buf, 0, *msg, ap);
        len_iter = len;
 
        /* remove any trailing \n */
-       while (len && buf[--len_iter] == '\n') {
+       while (len_iter && buf[--len_iter] == '\n') {
                buf[len_iter] = '\0';
                output = 1;
        }
@@ -319,12 +334,46 @@
        efree(buf);
 
        if (output == 1) {
-               php_error(E_WARNING, "%s", (char *) LIBXML(error_buffer));
+               switch (error_type) {
+                       case PHP_LIBXML_CTX_ERROR:
+                               php_libxml_ctx_error_level(E_WARNING, ctx, (char *) 
LIBXML(error_buffer) TSRMLS_CC);
+                               break;
+                       case PHP_LIBXML_CTX_WARNING:
+                               php_libxml_ctx_error_level(E_NOTICE, ctx, (char *) 
LIBXML(error_buffer) TSRMLS_CC);
+                               break;
+                       default:
+                               php_error(E_WARNING, "%s", (char *) 
LIBXML(error_buffer));
+               }
                smart_str_free(&LIBXML(error_buffer));
                LIBXML(error_buffer) = NULL;
        }
 }
 
+void php_libxml_ctx_error(void *ctx, const char *msg, ...)
+{
+       va_list args;
+       va_start(args, msg);
+       php_libxml_internal_error_handler(PHP_LIBXML_CTX_ERROR, ctx, &msg, args);
+       va_end(args);
+}
+
+void php_libxml_ctx_warning(void *ctx, const char *msg, ...)
+{
+       va_list args;
+       va_start(args, msg);
+       php_libxml_internal_error_handler(PHP_LIBXML_CTX_WARNING, ctx, &msg, args);
+       va_end(args);
+}
+
+void php_libxml_error_handler(void *ctx, const char *msg, ...)
+{
+       va_list args;
+       va_start(args, msg);
+       php_libxml_internal_error_handler(PHP_LIBXML_ERROR, ctx, &msg, args);
+       va_end(args);
+}
+
+
 PHP_LIBXML_API void php_libxml_initialize() {
        if (!_php_libxml_initialized) {
                /* we should be the only one's to ever init!! */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to