]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Add ap_find_module_short_name() to quickly get the module short name
authorStefan Fritsch <sf@apache.org>
Mon, 19 Jul 2010 10:06:15 +0000 (10:06 +0000)
committerStefan Fritsch <sf@apache.org>
Mon, 19 Jul 2010 10:06:15 +0000 (10:06 +0000)
(i.e. symbol name with trailing "_module" removed) from the module_index.
To be used for logging.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@965408 13f79535-47bb-0310-9956-ffa450edef68

include/ap_mmn.h
include/http_config.h
modules/core/mod_so.c
server/config.c

index 76491c5da496cd05393914be339ad2ec1e860c40..2f285a2db63863066c6d6964551a715d6f063f46 100644 (file)
  * 20100714.0 (2.3.7-dev)  add access_checker_ex hook, add AUTHZ_DENIED_NO_USER
  *                         to authz_status, call authz providers twice to allow
  *                         authz without authenticated user
+ * 20100719.0 (2.3.7-dev)  Add symbol name parameter to ap_add_module and
+ *                         ap_add_loaded_module. Add ap_find_module_short_name
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
 
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
-#define MODULE_MAGIC_NUMBER_MAJOR 20100714
+#define MODULE_MAGIC_NUMBER_MAJOR 20100719
 #endif
 #define MODULE_MAGIC_NUMBER_MINOR 0                     /* 0...n */
 
index 63dd52441b65880e5f273e4e982421d766555974..27cff77a8ab9e71e344b4dbd30d20ab679ad19ad 100644 (file)
@@ -671,8 +671,10 @@ AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *fname);
  * Add a module to the server
  * @param m The module structure of the module to add
  * @param p The pool of the same lifetime as the module
+ * @param s The module's symbol name (used for logging)
  */
-AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p);
+AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
+                                       const char *s);
 
 /**
  * Remove a module from the server.  There are some caveats:
@@ -687,8 +689,10 @@ AP_DECLARE(void) ap_remove_module(module *m);
  * Add a module to the chained modules list and the list of loaded modules
  * @param mod The module structure of the module to add
  * @param p The pool with the same lifetime as the module
+ * @param s The module's symbol name (used for logging)
  */
-AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p);
+AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p,
+                                              const char *s);
 /**
  * Remove a module fromthe chained modules list and the list of loaded modules
  * @param mod the module structure of the module to remove
@@ -700,6 +704,12 @@ AP_DECLARE(void) ap_remove_loaded_module(module *mod);
  * @return the name of the module
  */
 AP_DECLARE(const char *) ap_find_module_name(module *m);
+/**
+ * Find the short name of the module identified by the specified module index
+ * @param module_index The module index to get the name for
+ * @return the name of the module
+ */
+AP_DECLARE(const char *) ap_find_module_short_name(int module_index);
 /**
  * Find a module based on the name of the module
  * @param name the name of the module
index 81eb2366bf8dd516e8feace3e51aed76939d02a3..7be9c0619eb7b565c2b8cf4201577a75702e432e 100644 (file)
@@ -278,7 +278,7 @@ static const char *load_module(cmd_parms *cmd, void *dummy,
     /*
      * Add this module to the Apache core structures
      */
-    error = ap_add_loaded_module(modp, cmd->pool);
+    error = ap_add_loaded_module(modp, cmd->pool, modname);
     if (error) {
         return error;
     }
index 07f8f256c89718cecd8c851babe5446b73ea6bc3..5f0ae48cdf12001edcd4aca938e474104e32adb1 100644 (file)
@@ -202,6 +202,9 @@ AP_DECLARE_DATA module **ap_loaded_modules=NULL;
 
 static apr_hash_t *ap_config_hash = NULL;
 
+/* a list of the module symbol names with the trailing "_module"removed */
+static char **ap_module_short_names = NULL;
+
 typedef int (*handler_func)(request_rec *);
 typedef void *(*dir_maker_func)(apr_pool_t *, char *);
 typedef void *(*merger_func)(apr_pool_t *, void *, void *);
@@ -520,8 +523,11 @@ static void ap_add_module_commands(module *m, apr_pool_t *p)
 
 /* One-time setup for precompiled modules --- NOT to be done on restart */
 
-AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
+AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
+                                       const char *sym_name)
 {
+    ap_module_symbol_t *sym = ap_prelinked_module_symbols;
+
     /* This could be called from a LoadModule httpd.conf command,
      * after the file has been linked and the module structure within it
      * teased out...
@@ -549,8 +555,30 @@ AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
                                 "reached. Please increase "
                                 "DYNAMIC_MODULE_LIMIT and recompile.", m->name);
         }
+
+    }
+    else if (!sym_name) {
+        while (sym->modp != NULL) {
+            if (sym->modp == m) {
+                sym_name = sym->name;
+                break;
+            }
+            sym++;
+        }
     }
 
+    if (sym_name) {
+        int len = strlen(sym_name);
+        int slen = strlen("_module");
+        if (len > slen && !strcmp(sym_name + len - slen, "_module")) {
+            len -= slen;
+        }
+
+        ap_module_short_names[m->module_index] = strdup(sym_name);
+        ap_module_short_names[m->module_index][len] = '\0';
+    }
+
+
     /* Some C compilers put a complete path into __FILE__, but we want
      * only the filename (e.g. mod_includes.c). So check for path
      * components (Unix and DOS), and remove them.
@@ -623,13 +651,17 @@ AP_DECLARE(void) ap_remove_module(module *m)
         modp->next = modp->next->next;
     }
 
+    free(ap_module_short_names[m->module_index]);
+    ap_module_short_names[m->module_index] = NULL;
+
     m->module_index = -1; /* simulate being unloaded, should
                            * be unnecessary */
     dynamic_modules--;
     total_modules--;
 }
 
-AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
+AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p,
+                                              const char *short_name)
 {
     module **m;
     const char *error;
@@ -637,7 +669,7 @@ AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
     /*
      *  Add module pointer to top of chained module list
      */
-    error = ap_add_module(mod, p);
+    error = ap_add_module(mod, p, short_name);
     if (error) {
         return error;
     }
@@ -709,12 +741,14 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
     conf_vector_length = max_modules;
 
     /*
-     *  Initialise list of loaded modules
+     *  Initialise list of loaded modules and short names
      */
     ap_loaded_modules = (module **)apr_palloc(process->pool,
         sizeof(module *) * conf_vector_length);
+    if (!ap_module_short_names)
+        ap_module_short_names = malloc(sizeof(char *) * conf_vector_length);
 
-    if (ap_loaded_modules == NULL) {
+    if (ap_loaded_modules == NULL || ap_module_short_names == NULL) {
         return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
     }
 
@@ -727,7 +761,7 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
      *   Initialize chain of linked (=activate) modules
      */
     for (m = ap_prelinked_modules; *m != NULL; m++) {
-        error = ap_add_module(*m, process->pconf);
+        error = ap_add_module(*m, process->pconf, NULL);
         if (error) {
             return error;
         }
@@ -743,6 +777,13 @@ AP_DECLARE(const char *) ap_find_module_name(module *m)
     return m->name;
 }
 
+AP_DECLARE(const char *) ap_find_module_short_name(int module_index)
+{
+        if (module_index < 0)
+                return "-";
+        return ap_module_short_names[module_index];
+}
+
 AP_DECLARE(module *) ap_find_linked_module(const char *name)
 {
     module *modp;