You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by sf...@apache.org on 2010/02/02 00:27:33 UTC

svn commit: r905454 - in /httpd/httpd/trunk: include/ap_mmn.h include/http_config.h modules/debugging/mod_dumpio.c server/core.c server/log.c server/main.c

Author: sf
Date: Mon Feb  1 23:27:32 2010
New Revision: 905454

URL: http://svn.apache.org/viewvc?rev=905454&view=rev
Log:
replace duplicate code with new function ap_parse_log_level()

Modified:
    httpd/httpd/trunk/include/ap_mmn.h
    httpd/httpd/trunk/include/http_config.h
    httpd/httpd/trunk/modules/debugging/mod_dumpio.c
    httpd/httpd/trunk/server/core.c
    httpd/httpd/trunk/server/log.c
    httpd/httpd/trunk/server/main.c

Modified: httpd/httpd/trunk/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_mmn.h?rev=905454&r1=905453&r2=905454&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_mmn.h (original)
+++ httpd/httpd/trunk/include/ap_mmn.h Mon Feb  1 23:27:32 2010
@@ -212,6 +212,7 @@
  *                         to proxy_ftp_dir_conf(mod_proxy_ftp)
  * 20091230.1 (2.3.5-dev)  add util_ldap_state_t.opTimeout
  * 20091230.2 (2.3.5-dev)  add ap_get_server_name_for_url()
+ * 20091230.3 (2.3.6-dev)  add ap_parse_log_level()
  *
  */
 
@@ -220,7 +221,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20091230
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 2                     /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 3                     /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a

Modified: httpd/httpd/trunk/include/http_config.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_config.h?rev=905454&r1=905453&r2=905454&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_config.h (original)
+++ httpd/httpd/trunk/include/http_config.h Mon Feb  1 23:27:32 2010
@@ -491,6 +491,14 @@
                                                 const char *arg);
 
 /**
+ * Parsing function for log level
+ * @param str The string to parse
+ * @param val The parsed log level
+ * @return An error string or NULL on success
+ */
+AP_DECLARE(const char *) ap_parse_log_level(const char *str, int *val);
+
+/**
  * Return true if the specified method is limited by being listed in
  * a <Limit> container, or by *not* being listed in a <LimitExcept>
  * container.

Modified: httpd/httpd/trunk/modules/debugging/mod_dumpio.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/debugging/mod_dumpio.c?rev=905454&r1=905453&r2=905454&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/debugging/mod_dumpio.c (original)
+++ httpd/httpd/trunk/modules/debugging/mod_dumpio.c Mon Feb  1 23:27:32 2010
@@ -244,34 +244,9 @@
     }
 
     if ((str = ap_getword_conf(cmd->pool, &arg))) {
-        if (!strcasecmp(str, "emerg")) {
-            ptr->loglevel = APLOG_EMERG;
-        }
-        else if (!strcasecmp(str, "alert")) {
-            ptr->loglevel = APLOG_ALERT;
-        }
-        else if (!strcasecmp(str, "crit")) {
-            ptr->loglevel = APLOG_CRIT;
-        }
-        else if (!strcasecmp(str, "error")) {
-            ptr->loglevel = APLOG_ERR;
-        }
-        else if (!strcasecmp(str, "warn")) {
-            ptr->loglevel = APLOG_WARNING;
-        }
-        else if (!strcasecmp(str, "notice")) {
-            ptr->loglevel = APLOG_NOTICE;
-        }
-        else if (!strcasecmp(str, "info")) {
-            ptr->loglevel = APLOG_INFO;
-        }
-        else if (!strcasecmp(str, "debug")) {
-            ptr->loglevel = APLOG_DEBUG;
-        }
-        else {
-            return "DumpIOLogLevel requires level keyword: one of "
-                   "emerg/alert/crit/error/warn/notice/info/debug";
-        }
+        err = ap_parse_log_level(str, &ptr->loglevel);
+        if (err != NULL)
+            return err;
     }
     else {
         return "DumpIOLogLevel requires level keyword";

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=905454&r1=905453&r2=905454&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Mon Feb  1 23:27:32 2010
@@ -2626,34 +2626,9 @@
     }
 
     if ((str = ap_getword_conf(cmd->pool, &arg))) {
-        if (!strcasecmp(str, "emerg")) {
-            cmd->server->loglevel = APLOG_EMERG;
-        }
-        else if (!strcasecmp(str, "alert")) {
-            cmd->server->loglevel = APLOG_ALERT;
-        }
-        else if (!strcasecmp(str, "crit")) {
-            cmd->server->loglevel = APLOG_CRIT;
-        }
-        else if (!strcasecmp(str, "error")) {
-            cmd->server->loglevel = APLOG_ERR;
-        }
-        else if (!strcasecmp(str, "warn")) {
-            cmd->server->loglevel = APLOG_WARNING;
-        }
-        else if (!strcasecmp(str, "notice")) {
-            cmd->server->loglevel = APLOG_NOTICE;
-        }
-        else if (!strcasecmp(str, "info")) {
-            cmd->server->loglevel = APLOG_INFO;
-        }
-        else if (!strcasecmp(str, "debug")) {
-            cmd->server->loglevel = APLOG_DEBUG;
-        }
-        else {
-            return "LogLevel requires level keyword: one of "
-                   "emerg/alert/crit/error/warn/notice/info/debug";
-        }
+        err = ap_parse_log_level(arg, &cmd->server->loglevel);
+        if (err != NULL)
+            return err;
     }
     else {
         return "LogLevel requires level keyword";

Modified: httpd/httpd/trunk/server/log.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/log.c?rev=905454&r1=905453&r2=905454&view=diff
==============================================================================
--- httpd/httpd/trunk/server/log.c (original)
+++ httpd/httpd/trunk/server/log.c Mon Feb  1 23:27:32 2010
@@ -1127,6 +1127,25 @@
     apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);
 }
 
+AP_DECLARE(const char *) ap_parse_log_level(const char *str, int *val)
+{
+    char *err = "Loglevel keyword must be one of emerg/alert/crit/error/warn/"
+                "notice/info/debug";
+    int i = 0;
+
+    if (str == NULL)
+        return err;
+
+    while (priorities[i].t_name != NULL) {
+        if (!strcasecmp(str, priorities[i].t_name)) {
+            *val = priorities[i].t_val;
+            return NULL;
+        }
+        i++;
+    }
+    return err;
+}
+
 AP_IMPLEMENT_HOOK_VOID(error_log,
                        (const char *file, int line, int level,
                         apr_status_t status, const server_rec *s,

Modified: httpd/httpd/trunk/server/main.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/main.c?rev=905454&r1=905453&r2=905454&view=diff
==============================================================================
--- httpd/httpd/trunk/server/main.c (original)
+++ httpd/httpd/trunk/server/main.c Mon Feb  1 23:27:32 2010
@@ -530,33 +530,8 @@
             break;
 
         case 'e':
-            if (strcasecmp(optarg, "emerg") == 0) {
-                ap_default_loglevel = APLOG_EMERG;
-            }
-            else if (strcasecmp(optarg, "alert") == 0) {
-                ap_default_loglevel = APLOG_ALERT;
-            }
-            else if (strcasecmp(optarg, "crit") == 0) {
-                ap_default_loglevel = APLOG_CRIT;
-            }
-            else if (strncasecmp(optarg, "err", 3) == 0) {
-                ap_default_loglevel = APLOG_ERR;
-            }
-            else if (strncasecmp(optarg, "warn", 4) == 0) {
-                ap_default_loglevel = APLOG_WARNING;
-            }
-            else if (strcasecmp(optarg, "notice") == 0) {
-                ap_default_loglevel = APLOG_NOTICE;
-            }
-            else if (strcasecmp(optarg, "info") == 0) {
-                ap_default_loglevel = APLOG_INFO;
-            }
-            else if (strcasecmp(optarg, "debug") == 0) {
-                ap_default_loglevel = APLOG_DEBUG;
-            }
-            else {
+            if (ap_parse_log_level(optarg, &ap_default_loglevel) != NULL)
                 usage(process);
-            }
             break;
 
         case 'E':



Re: svn commit: r905454 - in /httpd/httpd/trunk: include/ap_mmn.h include/http_config.h modules/debugging/mod_dumpio.c server/core.c server/log.c server/main.c

Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Thursday 04 February 2010, Jim Jagielski wrote:
> > +    char *err = "Loglevel keyword must be one of
> > emerg/alert/crit/error/warn/"
> > +                "notice/info/debug";
> > +    int i = 0;
> 
> Won't this be confusing that every error would refer to Loglevel,
>  even if the bad directive is "DumpIOLogLevel" for example? Why not
>  also pass the directive name as well?

True. I have clarified the error message in r907012. But I hope that 
DumpIOLogLevel will go away before 2.4 ;-)

Re: svn commit: r905454 - in /httpd/httpd/trunk: include/ap_mmn.h include/http_config.h modules/debugging/mod_dumpio.c server/core.c server/log.c server/main.c

Posted by Jim Jagielski <ji...@jaguNET.com>.
On Feb 1, 2010, at 6:27 PM, sf@apache.org wrote:
> -        else {
> -            return "DumpIOLogLevel requires level keyword: one of "
> -                   "emerg/alert/crit/error/warn/notice/info/debug";
> -        }
> +        err = ap_parse_log_level(str, &ptr->loglevel);
> +        if (err != NULL)
> +            return err;
>     }
...
> -        else {
> -            return "LogLevel requires level keyword: one of "
> -                   "emerg/alert/crit/error/warn/notice/info/debug";
> -        }
> +        err = ap_parse_log_level(arg, &cmd->server->loglevel);
> +        if (err != NULL)
> +            return err;
>     }
>     else {
>         return "LogLevel requires level keyword";
...

> +    char *err = "Loglevel keyword must be one of emerg/alert/crit/error/warn/"
> +                "notice/info/debug";
> +    int i = 0;

Won't this be confusing that every error would refer to Loglevel, even if the
bad directive is "DumpIOLogLevel" for example? Why not also pass the directive
name as well?