httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1086441 - in /httpd/httpd/trunk: CHANGES modules/generators/mod_info.c
Date Mon, 28 Mar 2011 23:19:18 GMT
Author: sf
Date: Mon Mar 28 23:19:17 2011
New Revision: 1086441

URL: http://svn.apache.org/viewvc?rev=1086441&view=rev
Log:
mod_info: Dump config to stdout during startup if -DDUMP_CONFIG is 
specified.

This functionality should probably be moved into core, but for now
it's a lot better than nothing. And it may even help me debug some
other config related code.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/generators/mod_info.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1086441&r1=1086440&r2=1086441&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Mon Mar 28 23:19:17 2011
@@ -2,6 +2,9 @@
 
 Changes with Apache 2.3.12
 
+  *) mod_info: Dump config to stdout during startup if -DDUMP_CONFIG is
+     specified. [Stefan Fritsch]
+
   *) Restore visibility of DEFAULT_PIDLOG to core and modules.  MPM 
      helper function ap_remove_pid() added.  [Jeff Trawick]
 

Modified: httpd/httpd/trunk/modules/generators/mod_info.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/generators/mod_info.c?rev=1086441&r1=1086440&r2=1086441&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/generators/mod_info.c (original)
+++ httpd/httpd/trunk/modules/generators/mod_info.c Mon Mar 28 23:19:17 2011
@@ -61,6 +61,7 @@
 #include "http_request.h"
 #include "util_script.h"
 #include "ap_mpm.h"
+#include <stdio.h>
 
 typedef struct
 {
@@ -75,6 +76,9 @@ typedef struct
 
 module AP_MODULE_DECLARE_DATA info_module;
 
+/* current file name when doing -DDUMP_CONFIG */
+const char *dump_config_fn_info;
+
 static void *create_info_config(apr_pool_t * p, server_rec * s)
 {
     info_svr_conf *conf =
@@ -100,34 +104,74 @@ static void put_int_flush_right(request_
 {
     if (field > 1 || i > 9)
         put_int_flush_right(r, i / 10, field - 1);
-    if (i)
-        ap_rputc('0' + i % 10, r);
+    if (i) {
+        if (r)
+            ap_rputc('0' + i % 10, r);
+        else
+            putchar('0' + i % 10);
+    }
+    else {
+        if (r)
+            ap_rputs("&nbsp;", r);
+        else
+            printf(" ");
+    }
+}
+
+static void set_fn_info(request_rec *r, const char *name)
+{
+    if (r)
+        ap_set_module_config(r->request_config, &info_module, (void *)name);
+    else
+        dump_config_fn_info = name;
+}
+
+static const char *get_fn_info(request_rec *r)
+{
+    if (r)
+        return ap_get_module_config(r->request_config, &info_module);
     else
-        ap_rputs("&nbsp;", r);
+        return dump_config_fn_info;
 }
 
+
 static void mod_info_indent(request_rec * r, int nest,
                             const char *thisfn, int linenum)
 {
     int i;
-    const char *prevfn =
-        ap_get_module_config(r->request_config, &info_module);
+    const char *prevfn = get_fn_info(r);
     if (thisfn == NULL)
         thisfn = "*UNKNOWN*";
     if (prevfn == NULL || 0 != strcmp(prevfn, thisfn)) {
-        thisfn = ap_escape_html(r->pool, thisfn);
-        ap_rprintf(r, "<dd><tt><strong>In file: %s</strong></tt></dd>\n",
+        if (r) {
+            thisfn = ap_escape_html(r->pool, thisfn);
+            ap_rprintf(r, "<dd><tt><strong>In file: %s</strong></tt></dd>\n",
                    thisfn);
-        ap_set_module_config(r->request_config, &info_module,
-                             (void *) thisfn);
+        }
+        else {
+            printf("# In file: %s\n", thisfn);
+        }
+        set_fn_info(r, thisfn);
     }
 
-    ap_rputs("<dd><tt>", r);
-    put_int_flush_right(r, linenum > 0 ? linenum : 0, 4);
-    ap_rputs(":&nbsp;", r);
+    if (r) {
+        ap_rputs("<dd><tt>", r);
+        put_int_flush_right(r, linenum > 0 ? linenum : 0, 4);
+        ap_rputs(":&nbsp;", r);
+    }
+    else if (linenum > 0) {
+    	for (i = 1; i <= nest; ++i)
+            printf("  ");
+        putchar('#');
+        put_int_flush_right(r, linenum, 4);
+        printf(":\n");
+    }
 
     for (i = 1; i <= nest; ++i) {
-        ap_rputs("&nbsp;&nbsp;", r);
+        if (r)
+            ap_rputs("&nbsp;&nbsp;", r);
+        else
+            printf("  ");
     }
 }
 
@@ -135,18 +179,24 @@ static void mod_info_show_cmd(request_re
                               int nest)
 {
     mod_info_indent(r, nest, dir->filename, dir->line_num);
-    ap_rprintf(r, "%s <i>%s</i></tt></dd>\n",
-               ap_escape_html(r->pool, dir->directive),
-               ap_escape_html(r->pool, dir->args));
+    if (r)
+        ap_rprintf(r, "%s <i>%s</i></tt></dd>\n",
+                   ap_escape_html(r->pool, dir->directive),
+                   ap_escape_html(r->pool, dir->args));
+    else
+        printf("%s %s\n", dir->directive, dir->args);
 }
 
 static void mod_info_show_open(request_rec * r, const ap_directive_t * dir,
                                int nest)
 {
     mod_info_indent(r, nest, dir->filename, dir->line_num);
-    ap_rprintf(r, "%s %s</tt></dd>\n",
-               ap_escape_html(r->pool, dir->directive),
-               ap_escape_html(r->pool, dir->args));
+    if (r)
+        ap_rprintf(r, "%s %s</tt></dd>\n",
+                   ap_escape_html(r->pool, dir->directive),
+                   ap_escape_html(r->pool, dir->args));
+    else
+        printf("%s %s\n", dir->directive, dir->args);
 }
 
 static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
@@ -155,11 +205,17 @@ static void mod_info_show_close(request_
     const char *dirname = dir->directive;
     mod_info_indent(r, nest, dir->filename, 0);
     if (*dirname == '<') {
-        ap_rprintf(r, "&lt;/%s&gt;</tt></dd>",
-                   ap_escape_html(r->pool, dirname + 1));
+        if (r)
+            ap_rprintf(r, "&lt;/%s&gt;</tt></dd>",
+                       ap_escape_html(r->pool, dirname + 1));
+        else
+            printf("</%s>\n", dirname + 1);
     }
     else {
-        ap_rprintf(r, "/%s</tt></dd>", ap_escape_html(r->pool, dirname));
+        if (r)
+            ap_rprintf(r, "/%s</tt></dd>", ap_escape_html(r->pool, dirname));
+        else
+            printf("/%s\n", dirname);
     }
 }
 
@@ -189,7 +245,7 @@ static int mod_info_module_cmds(request_
     int shown = from;
     ap_directive_t *dir;
     if (level == 0)
-        ap_set_module_config(r->request_config, &info_module, NULL);
+        set_fn_info(r, NULL);
     for (dir = node; dir; dir = dir->next) {
         if (dir->first_child != NULL) {
             if (level < mod_info_module_cmds(r, cmds, dir->first_child,
@@ -797,9 +853,20 @@ static const command_rec info_cmds[] = {
     {NULL}
 };
 
+static int check_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
+                        server_rec *s)
+{
+    if (ap_exists_config_define("DUMP_CONFIG"))
+        mod_info_module_cmds(NULL, NULL, ap_conftree, 0, 0);
+
+    return DECLINED;
+}
+
+
 static void register_hooks(apr_pool_t * p)
 {
     ap_hook_handler(display_info, NULL, NULL, APR_HOOK_MIDDLE);
+    ap_hook_check_config(check_config, NULL, NULL, APR_HOOK_FIRST);
 }
 
 AP_DECLARE_MODULE(info) = {



Mime
View raw message