this patch tweaks the hook code to generate an
ap_hook_get_$hook_name() function for each hook that simply returns the
apr_array_header_t* of registered hooks.  mod_info can then use that info
to display the "Request Phase Participation" just as 1.3 does.  it will be
easy to add "Filter Participation", "Connection Participation", and
whatever other hooks might be of interest.  i'll do that if its ok to
commit this patch.

Index: modules/generators/mod_info.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/generators/mod_info.c,v
retrieving revision 1.35
diff -u -r1.35 mod_info.c
--- modules/generators/mod_info.c       2001/04/13 19:00:36     1.35
+++ modules/generators/mod_info.c       2001/05/13 19:29:08
@@ -92,6 +92,7 @@
 #include "http_log.h"
 #include "http_main.h"
 #include "http_protocol.h"
+#include "http_request.h"
 #include "util_script.h"
 #include "apr_strings.h"
 #include "apr_lib.h"
@@ -247,6 +248,86 @@
 
     }
 }
+
+typedef struct { /*XXX: should get something from apr_hooks.h instead */
+    void (*pFunc)(void); /* just to get the right size */
+    const char *szName;
+    const char * const *aszPredecessors;
+    const char * const *aszSuccessors;
+    int nOrder;
+} hook_struct_t;
+
+typedef apr_array_header_t * (*hook_get_t)(void);
+
+typedef struct {
+    const char *name;
+    hook_get_t get;
+} hook_lookup_t;
+
+static hook_lookup_t request_hooks[] = {
+    {"Post-Read Request", ap_hook_get_post_read_request},
+    {"Header Parse", ap_hook_get_header_parser},
+    {"Translate Path", ap_hook_get_translate_name},
+    {"Check Access", ap_hook_get_access_checker},
+    {"Verify User ID", ap_hook_get_check_user_id},
+    {"Verify User Access", ap_hook_get_auth_checker},
+    {"Check Type", ap_hook_get_type_checker},
+    {"Fixups", ap_hook_get_fixups},
+    {"Logging", ap_hook_get_log_transaction},
+    {NULL},
+};
+
+static int module_find_hook(module *modp,
+                            hook_get_t hook_get)
+{
+    int i;
+    apr_array_header_t *hooks = hook_get();
+    hook_struct_t *elts;
+
+    if (!hooks) {
+        return 0;
+    }
+
+    elts = (hook_struct_t *)hooks->elts;
+
+    for (i=0; i< hooks->nelts; i++) {
+        if (strcmp(elts[i].szName, modp->name) == 0) {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+static void module_participate(request_rec *r,
+                               module *modp,
+                               hook_lookup_t *lookup,
+                               int *comma)
+{
+    if (module_find_hook(modp, lookup->get)) {
+        if (*comma) {
+            ap_rputs(", ", r);
+        }
+        ap_rvputs(r, "<tt>", lookup->name, "</tt>", NULL);
+        *comma = 1;
+    }
+}
+
+static void module_request_hook_participate(request_rec *r, module *modp)
+{
+    int i, comma=0;
+
+    ap_rputs("<dt><strong>Request Phase Participation:</strong> \n", r);
+
+    for (i=0; request_hooks[i].name; i++) {
+        module_participate(r, modp, &request_hooks[i], &comma);
+    }
+
+    if (!comma) {
+        ap_rputs("<tt> <EM>none</EM></tt>", r);
+    }
+}
+
 static const char *find_more_info(server_rec *s, const char *module_name)
 {
     int i;
@@ -364,7 +445,12 @@
                     ap_rputs("<tt> <EM>none</EM></tt>", r);
                 }
 #else
-                ap_rputs("<tt> <EM>(code broken)</EM></tt>", r);
+                if (module_find_hook(modp, ap_hook_get_handler)) {
+                    ap_rputs("<tt> <EM>yes</EM></tt>", r);
+                }
+                else {
+                    ap_rputs("<tt> <EM>none</EM></tt>", r);
+                }
 #endif
                 ap_rputs("<dt><strong>Configuration Phase Participation:</strong> \n",
                       r);
@@ -399,6 +485,9 @@
                 if (!comma)
                     ap_rputs("<tt> <EM>none</EM></tt>", r);
                 comma = 0;
+
+                module_request_hook_participate(r, modp);
+
                 ap_rputs("<dt><strong>Module Directives:</strong> ", r);
                 cmd = modp->cmds;
                 if (cmd) {
Index: srclib/apr-util/include/apr_hooks.h
===================================================================
RCS file: /home/cvs/apr-util/include/apr_hooks.h,v
retrieving revision 1.38
diff -u -r1.38 apr_hooks.h
--- srclib/apr-util/include/apr_hooks.h 2001/02/16 04:17:10     1.38
+++ srclib/apr-util/include/apr_hooks.h 2001/05/13 19:29:08
@@ -67,12 +67,16 @@
  * @package Apache hooks functions
  */
 
+#define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
+link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void)
+
 #define APR_DECLARE_EXTERNAL_HOOK(ns,link,ret,name,args) \
 typedef ret ns##_HOOK_##name##_t args; \
 link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
                                       const char * const *aszPre, \
                                       const char * const *aszSucc, int nOrder); \
 link##_DECLARE(ret) ns##_run_##name args; \
+APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name); \
 typedef struct ns##_LINK_##name##_t \
     { \
     ns##_HOOK_##name##_t *pFunc; \
@@ -106,6 +110,10 @@
     pHook->szName=apr_current_hooking_module; \
     if(apr_debug_module_hooks) \
        apr_show_hook(#name,aszPre,aszSucc); \
+    } \
+    APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
+    { \
+        return _hooks.link_##name; \
     }
 
 /**

Reply via email to