john            Fri Apr 16 11:46:42 2004 EDT

  Modified files:              
    /php-src/ext/tidy   tidy.c 
  Log:
  Modified error handling:
  
    - Trivial errors have been reduced to E_NOTICEs if possible
    - Bad, but not script-stopping errors (i.e. file not file) are E_WARNING
    - Truly bad things that make the extension unusable are not E_ERROR
    
    Exceptions are thrown only in a OO context for E_WARNINGs.
    
  
  
http://cvs.php.net/diff.php/php-src/ext/tidy/tidy.c?r1=1.43&r2=1.44&ty=u
Index: php-src/ext/tidy/tidy.c
diff -u php-src/ext/tidy/tidy.c:1.43 php-src/ext/tidy/tidy.c:1.44
--- php-src/ext/tidy/tidy.c:1.43        Wed Apr 14 15:01:45 2004
+++ php-src/ext/tidy/tidy.c     Fri Apr 16 11:46:41 2004
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: tidy.c,v 1.43 2004/04/14 19:01:45 fmk Exp $ */
+/* $Id: tidy.c,v 1.44 2004/04/16 15:46:41 john Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -153,7 +153,7 @@
 #define TIDY_SET_DEFAULT_CONFIG(_doc) \
        if (TG(default_config) && TG(default_config)[0]) { \
                if (tidyLoadConfig(_doc, TG(default_config)) < 0) { \
-                       zend_error(E_ERROR, "Unable to load Tidy configuration file at 
'%s'.", TG(default_config)); \
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load 
Tidy configuration file at '%s'.", TG(default_config)); \
                } \
        }
 /* }}} */
@@ -238,7 +238,7 @@
        PHP_FE(tidy_error_count,        NULL)
        PHP_FE(tidy_warning_count,      NULL)
        PHP_FE(tidy_access_count,       NULL)
-       PHP_FE(tidy_config_count,       NULL)
+       PHP_FE(tidy_config_count,       NULL) 
        PHP_FE(tidy_get_root,           NULL)
        PHP_FE(tidy_get_head,           NULL)
        PHP_FE(tidy_get_html,           NULL)
@@ -330,7 +330,7 @@
 
 void php_tidy_panic(ctmbstr msg)
 {
-       zend_error(E_ERROR, "Could not allocate memory for tidy! (Reason: %s)", (char 
*)msg);
+       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not allocate memory for tidy! 
(Reason: %s)", (char *)msg);
 }
 
 static void _php_tidy_throw_exception(char *message, ...)
@@ -346,7 +346,7 @@
     if(TG(inst)) {
         zend_throw_exception(tidy_ce_exception, msg, 0 TSRMLS_CC);
     } else {
-        php_error_docref(NULL TSRMLS_CC, E_ERROR, msg);
+        php_error_docref(NULL TSRMLS_CC, E_WARNING, msg);
     }
            
     va_end(ap);
@@ -361,12 +361,13 @@
        opt = tidyGetOptionByName(doc, optname);
 
        if (!opt) {
-               TIDY_THROW("Unknown Tidy Configuration Option '%s'", optname);
+        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown Tidy Configuration Option 
'%s'", optname);
                return FAILURE;
        }
        
        if (tidyOptIsReadOnly(opt)) {
-               TIDY_THROW("Attempt to set read-only option '%s'", optname);
+        
+        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Attempting to set read-only 
option '%s'", optname);
                return FAILURE;
        }
 
@@ -409,6 +410,8 @@
        TidyBuffer *errbuf;
        zval *config;
        
+    TIDY_SET_CONTEXT;
+    
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zsb", &arg1, 
&arg1_len, &config, &enc, &enc_len, &use_include_path) == FAILURE) {
                RETURN_FALSE;
        }
@@ -426,7 +429,7 @@
        tidyBufInit(errbuf);
        
        if (tidySetErrorBuffer(doc, errbuf) != 0) {
-               zend_error(E_ERROR, "Could not set Tidy error buffer");
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not set Tidy error 
buffer");
        }
        
        tidyOptSetBool(doc, TidyForceOutput, yes);
@@ -442,7 +445,7 @@
                convert_to_string_ex(&config);
                TIDY_SAFE_MODE_CHECK(Z_STRVAL_P(config));
                if (tidyLoadConfig(doc, Z_STRVAL_P(config)) < 0) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not load 
configuration file '%s'", Z_STRVAL_P(config));
+                       TIDY_THROW("Could not load configuration file '%s'", 
Z_STRVAL_P(config));
                        RETVAL_FALSE;
                }
        }
@@ -547,7 +550,7 @@
                        tidyBufInit(intern->ptdoc->errbuf);
 
                        if (tidySetErrorBuffer(intern->ptdoc->doc, 
intern->ptdoc->errbuf) != 0) {
-                               zend_error(E_ERROR, "Could not set Tidy error buffer");
+                               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not 
set Tidy error buffer");
                        }
 
                        tidyOptSetBool(intern->ptdoc->doc, TidyForceOutput, yes);
@@ -858,9 +861,10 @@
                 zend_hash_move_forward(ht_options)) {
                
                if(zend_hash_get_current_key(ht_options, &opt_name, &opt_indx, FALSE) 
== FAILURE) {
-                       TIDY_THROW("Could not retrieve key from option array");
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not retrieve 
key from option array");
                        return FAILURE;
                }
+        
                if(opt_name) {
                        _php_tidy_set_tidy_opt(doc, opt_name, *opt_val TSRMLS_CC);
                }
@@ -934,7 +938,7 @@
 {
        if (INI_BOOL("tidy.clean_output") == TRUE) {
                if (php_start_ob_buffer_named("ob_tidyhandler", 0, 1 TSRMLS_CC) == 
FAILURE) {
-                       zend_error(E_NOTICE, "Unable to use Tidy for output 
buffering.");
+                       zend_error(E_NOTICE, "Failure installing Tidy output 
buffering.");
                }
        }
 
@@ -951,7 +955,7 @@
        php_info_print_table_start();
        php_info_print_table_header(2, "Tidy support", "enabled");
        php_info_print_table_row(2, "libTidy Release", (char *)tidyReleaseDate());
-       php_info_print_table_row(2, "Extension Version", PHP_TIDY_MODULE_VERSION " 
($Id: tidy.c,v 1.43 2004/04/14 19:01:45 fmk Exp $)");
+       php_info_print_table_row(2, "Extension Version", PHP_TIDY_MODULE_VERSION " 
($Id: tidy.c,v 1.44 2004/04/16 15:46:41 john Exp $)");
        php_info_print_table_end();
 
        DISPLAY_INI_ENTRIES();
@@ -979,7 +983,7 @@
                tidyRelease(doc);
                tidyBufFree(&errbuf);
 
-               zend_error(E_ERROR, "Could not set Tidy error buffer");
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not set Tidy error 
buffer");
        }
 
        TIDY_SET_DEFAULT_CONFIG(doc);
@@ -1014,6 +1018,8 @@
        zval *options = NULL;
        
        PHPTidyObj *obj;
+    
+    TIDY_SET_CONTEXT;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zs", &input, 
&input_len, &options, &enc, &enc_len) == FAILURE) {
                RETURN_FALSE;
@@ -1069,6 +1075,7 @@
        zval *options = NULL;
        
        PHPTidyObj *obj;
+    TIDY_SET_CONTEXT;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zsb", &inputfile, 
&input_len,
                                                          &options, &enc, &enc_len, 
&use_include_path) == FAILURE) {
@@ -1090,6 +1097,7 @@
                INIT_ZVAL(*return_value);
                RETVAL_FALSE;
        }
+    
        efree(contents);
 }
 /* }}} */
@@ -1113,6 +1121,7 @@
    Repair a string using an optionally provided configuration file */
 PHP_FUNCTION(tidy_repair_string)
 {
+    TIDY_SET_CONTEXT;
        php_tidy_quick_repair(INTERNAL_FUNCTION_PARAM_PASSTHRU, FALSE);
 }
 /* }}} */
@@ -1121,6 +1130,7 @@
    Repair a file using an optionally provided configuration file */
 PHP_FUNCTION(tidy_repair_file)
 {
+    TIDY_SET_CONTEXT;
        php_tidy_quick_repair(INTERNAL_FUNCTION_PARAM_PASSTHRU, TRUE);
 }
 /* }}} */
@@ -1144,6 +1154,8 @@
    Get release date (version) for Tidy library */
 PHP_FUNCTION(tidy_get_release)
 {
+    TIDY_SET_CONTEXT;
+    
        if (ZEND_NUM_ARGS()) {
                WRONG_PARAM_COUNT;
        }
@@ -1281,7 +1293,8 @@
        int optname_len;
        TidyOption opt;
        TidyOptionType optt;
-       TIDY_SET_CONTEXT;
+       
+    TIDY_SET_CONTEXT;
 
        if (object) {
                if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &optname, 
&optname_len) == FAILURE) {
@@ -1296,6 +1309,7 @@
        obj = (PHPTidyObj *) zend_object_store_get_object(object TSRMLS_CC);
 
        opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
+    
        if (!opt) {
                TIDY_THROW("Unknown Tidy Configuration Option '%s'", optname);
                RETURN_FALSE;
@@ -1320,7 +1334,7 @@
                        break;
 
                default:
-                       TIDY_THROW("Unable to determine type of configuration 
constant");
+                       TIDY_THROW("Unable to determine type of configuration option");
                        break;
        }
 
@@ -1422,6 +1436,7 @@
    Returns a TidyNode Object representing the root of the tidy parse tree */
 PHP_FUNCTION(tidy_get_root)
 {
+    TIDY_SET_CONTEXT;
        php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_root_node);
 }
 /* }}} */
@@ -1430,6 +1445,7 @@
    Returns a TidyNode Object starting from the <HTML> tag of the tidy parse tree */
 PHP_FUNCTION(tidy_get_html)
 {
+    TIDY_SET_CONTEXT;
        php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_html_node);
 }
 /* }}} */
@@ -1438,6 +1454,7 @@
    Returns a TidyNode Object starting from the <HEAD> tag of the tidy parse tree */
 PHP_FUNCTION(tidy_get_head)
 {
+    TIDY_SET_CONTEXT;
        php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_head_node);
 }
 /* }}} */
@@ -1446,6 +1463,7 @@
    Returns a TidyNode Object starting from the <BODY> tag of the tidy parse tree */
 PHP_FUNCTION(tidy_get_body)
 {
+    TIDY_SET_CONTEXT;
        php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_body_node);
 }
 /* }}} */

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

Reply via email to