|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This module is used to load Apache modules at runtime. This means that the
|
|
Packit |
90a5c9 |
* server functionality can be extended without recompiling and even without
|
|
Packit |
90a5c9 |
* taking the server down at all. Only a HUP or AP_SIG_GRACEFUL signal
|
|
Packit |
90a5c9 |
* needs to be sent to the server to reload the dynamically loaded modules.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* To use, you'll first need to build your module as a shared library, then
|
|
Packit |
90a5c9 |
* update your configuration (httpd.conf) to get the Apache core to load the
|
|
Packit |
90a5c9 |
* module at start-up.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* The easiest way to build a module as a shared library is to use the
|
|
Packit |
90a5c9 |
* `SharedModule' command in the Configuration file, instead of `AddModule'.
|
|
Packit |
90a5c9 |
* You should also change the file extension from `.o' to `.so'. So, for
|
|
Packit |
90a5c9 |
* example, to build the status module as a shared library edit Configuration
|
|
Packit |
90a5c9 |
* and change
|
|
Packit |
90a5c9 |
* AddModule modules/standard/mod_status.o
|
|
Packit |
90a5c9 |
* to
|
|
Packit |
90a5c9 |
* SharedModule modules/standard/mod_status.so
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Run Configure and make. Now Apache's httpd binary will _not_ include
|
|
Packit |
90a5c9 |
* mod_status. Instead a shared object called mod_status.so will be build, in
|
|
Packit |
90a5c9 |
* the modules/standard directory. You can build most of the modules as shared
|
|
Packit |
90a5c9 |
* libraries like this.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* To use the shared module, move the .so file(s) into an appropriate
|
|
Packit |
90a5c9 |
* directory. You might like to create a directory called "modules" under you
|
|
Packit |
90a5c9 |
* server root for this (e.g. /usr/local/httpd/modules).
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Then edit your conf/httpd.conf file, and add LoadModule lines. For
|
|
Packit |
90a5c9 |
* example
|
|
Packit |
90a5c9 |
* LoadModule status_module modules/mod_status.so
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* The first argument is the module's structure name (look at the end of the
|
|
Packit |
90a5c9 |
* module source to find this). The second option is the path to the module
|
|
Packit |
90a5c9 |
* file, relative to the server root. Put these directives right at the top
|
|
Packit |
90a5c9 |
* of your httpd.conf file.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Now you can start Apache. A message will be logged at "debug" level to your
|
|
Packit |
90a5c9 |
* error_log to confirm that the module(s) are loaded (use "LogLevel debug"
|
|
Packit |
90a5c9 |
* directive to get these log messages).
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* If you edit the LoadModule directives while the server is live you can get
|
|
Packit |
90a5c9 |
* Apache to re-load the modules by sending it a HUP or AP_SIG_GRACEFUL
|
|
Packit |
90a5c9 |
* signal as normal. You can use this to dynamically change the capability
|
|
Packit |
90a5c9 |
* of your server without bringing it down.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Because currently there is only limited builtin support in the Configure
|
|
Packit |
90a5c9 |
* script for creating the shared library files (`.so'), please consult your
|
|
Packit |
90a5c9 |
* vendors cc(1), ld(1) and dlopen(3) manpages to find out the appropriate
|
|
Packit |
90a5c9 |
* compiler and linker flags and insert them manually into the Configuration
|
|
Packit |
90a5c9 |
* file under CFLAGS_SHLIB, LDFLAGS_SHLIB and LDFLAGS_SHLIB_EXPORT.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* If you still have problems figuring out the flags both try the paper
|
|
Packit |
90a5c9 |
* http://developer.netscape.com/library/documentation/enterprise
|
|
Packit |
90a5c9 |
* /unix/svrplug.htm#1013807
|
|
Packit |
90a5c9 |
* or install a Perl 5 interpreter on your platform and then run the command
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* $ perl -V:usedl -V:ccdlflags -V:cccdlflags -V:lddlflags
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* This gives you what type of dynamic loading Perl 5 uses on your platform
|
|
Packit |
90a5c9 |
* and which compiler and linker flags Perl 5 uses to create the shared object
|
|
Packit |
90a5c9 |
* files.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Another location where you can find useful hints is the `ltconfig' script
|
|
Packit |
90a5c9 |
* of the GNU libtool 1.2 package. Search for your platform name inside the
|
|
Packit |
90a5c9 |
* various "case" constructs.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr.h"
|
|
Packit |
90a5c9 |
#include "apr_dso.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_errno.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "ap_config.h"
|
|
Packit |
90a5c9 |
#include "httpd.h"
|
|
Packit |
90a5c9 |
#include "http_config.h"
|
|
Packit |
90a5c9 |
#include "http_log.h"
|
|
Packit |
90a5c9 |
#include "http_core.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "mod_so.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
module AP_MODULE_DECLARE_DATA so_module;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Server configuration to keep track of actually
|
|
Packit |
90a5c9 |
* loaded modules and the corresponding module name.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct so_server_conf {
|
|
Packit |
90a5c9 |
apr_array_header_t *loaded_modules;
|
|
Packit |
90a5c9 |
} so_server_conf;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void *so_sconf_create(apr_pool_t *p, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
so_server_conf *soc;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
soc = (so_server_conf *)apr_pcalloc(p, sizeof(so_server_conf));
|
|
Packit |
90a5c9 |
soc->loaded_modules = apr_array_make(p, DYNAMIC_MODULE_LIMIT,
|
|
Packit |
90a5c9 |
sizeof(ap_module_symbol_t));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return (void *)soc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef NO_DLOPEN
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This is the cleanup for a loaded shared object. It unloads the module.
|
|
Packit |
90a5c9 |
* This is called as a cleanup function from the core.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t unload_module(void *data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modi = (ap_module_symbol_t*)data;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* only unload if module information is still existing */
|
|
Packit |
90a5c9 |
if (modi->modp == NULL)
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* remove the module pointer from the core structure */
|
|
Packit |
90a5c9 |
ap_remove_loaded_module(modi->modp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* destroy the module information */
|
|
Packit |
90a5c9 |
modi->modp = NULL;
|
|
Packit |
90a5c9 |
modi->name = NULL;
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *dso_load(cmd_parms *cmd, apr_dso_handle_t **modhandlep,
|
|
Packit |
90a5c9 |
const char *filename, const char **used_filename)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int retry = 0;
|
|
Packit |
90a5c9 |
const char *fullname = ap_server_root_relative(cmd->temp_pool, filename);
|
|
Packit |
90a5c9 |
char my_error[256];
|
|
Packit |
90a5c9 |
if (filename != NULL && ap_strchr_c(filename, '/') == NULL) {
|
|
Packit |
90a5c9 |
/* retry on error without path to use dlopen()'s search path */
|
|
Packit |
90a5c9 |
retry = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (fullname == NULL && !retry) {
|
|
Packit |
90a5c9 |
return apr_psprintf(cmd->temp_pool, "Invalid %s path %s",
|
|
Packit |
90a5c9 |
cmd->cmd->name, filename);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
*used_filename = fullname;
|
|
Packit |
90a5c9 |
if (apr_dso_load(modhandlep, fullname, cmd->pool) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (retry) {
|
|
Packit |
90a5c9 |
*used_filename = filename;
|
|
Packit |
90a5c9 |
if (apr_dso_load(modhandlep, filename, cmd->pool) == APR_SUCCESS)
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return apr_pstrcat(cmd->temp_pool, "Cannot load ", filename,
|
|
Packit |
90a5c9 |
" into server: ",
|
|
Packit |
90a5c9 |
apr_dso_error(*modhandlep, my_error, sizeof(my_error)),
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This is called for the directive LoadModule and actually loads
|
|
Packit |
90a5c9 |
* a shared object file into the address space of the server process.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *load_module(cmd_parms *cmd, void *dummy,
|
|
Packit |
90a5c9 |
const char *modname, const char *filename)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_dso_handle_t *modhandle;
|
|
Packit |
90a5c9 |
apr_dso_handle_sym_t modsym;
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
const char *module_file;
|
|
Packit |
90a5c9 |
so_server_conf *sconf;
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modi;
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modie;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
const char *error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* we need to setup this value for dummy to make sure that we don't try
|
|
Packit |
90a5c9 |
* to add a non-existent tree into the build when we return to
|
|
Packit |
90a5c9 |
* execute_now.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
*(ap_directive_t **)dummy = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* check for already existing module
|
|
Packit |
90a5c9 |
* If it already exists, we have nothing to do
|
|
Packit |
90a5c9 |
* Check both dynamically-loaded modules and statically-linked modules.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
sconf = (so_server_conf *)ap_get_module_config(cmd->server->module_config,
|
|
Packit |
90a5c9 |
&so_module);
|
|
Packit |
90a5c9 |
modie = (ap_module_symbol_t *)sconf->loaded_modules->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < sconf->loaded_modules->nelts; i++) {
|
|
Packit |
90a5c9 |
modi = &modie[i];
|
|
Packit |
90a5c9 |
if (modi->name != NULL && strcmp(modi->name, modname) == 0) {
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, cmd->pool, APLOGNO(01574)
|
|
Packit |
90a5c9 |
"module %s is already loaded, skipping",
|
|
Packit |
90a5c9 |
modname);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; ap_preloaded_modules[i]; i++) {
|
|
Packit |
90a5c9 |
const char *preload_name;
|
|
Packit |
90a5c9 |
apr_size_t preload_len;
|
|
Packit |
90a5c9 |
apr_size_t thismod_len;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
modp = ap_preloaded_modules[i];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* make sure we're comparing apples with apples
|
|
Packit |
90a5c9 |
* make sure name of preloaded module is mod_FOO.c
|
|
Packit |
90a5c9 |
* make sure name of structure being loaded is FOO_module
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (memcmp(modp->name, "mod_", 4)) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
preload_name = modp->name + strlen("mod_");
|
|
Packit |
90a5c9 |
preload_len = strlen(preload_name) - 2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (strlen(modname) <= strlen("_module")) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
thismod_len = strlen(modname) - strlen("_module");
|
|
Packit |
90a5c9 |
if (strcmp(modname + thismod_len, "_module")) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (thismod_len != preload_len) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!memcmp(modname, preload_name, preload_len)) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(cmd->pool, "module ", modname,
|
|
Packit |
90a5c9 |
" is built-in and can't be loaded",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
modi = apr_array_push(sconf->loaded_modules);
|
|
Packit |
90a5c9 |
modi->name = modname;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Load the file into the Apache address space
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
error = dso_load(cmd, &modhandle, filename, &module_file);
|
|
Packit |
90a5c9 |
if (error)
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, cmd->pool, APLOGNO(01575)
|
|
Packit |
90a5c9 |
"loaded module %s from %s", modname, module_file);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Retrieve the pointer to the module structure through the module name:
|
|
Packit |
90a5c9 |
* First with the hidden variant (prefix `AP_') and then with the plain
|
|
Packit |
90a5c9 |
* symbol name.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (apr_dso_sym(&modsym, modhandle, modname) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
char my_error[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return apr_pstrcat(cmd->pool, "Can't locate API module structure `",
|
|
Packit |
90a5c9 |
modname, "' in file ", module_file, ": ",
|
|
Packit |
90a5c9 |
apr_dso_error(modhandle, my_error, sizeof(my_error)),
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
modp = (module*) modsym;
|
|
Packit |
90a5c9 |
modp->dynamic_load_handle = (apr_dso_handle_t *)modhandle;
|
|
Packit |
90a5c9 |
modi->modp = modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Make sure the found module structure is really a module structure
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (modp->magic != MODULE_MAGIC_COOKIE) {
|
|
Packit |
90a5c9 |
return apr_psprintf(cmd->pool, "API module structure '%s' in file %s "
|
|
Packit |
90a5c9 |
"is garbled - expected signature %08lx but saw "
|
|
Packit |
90a5c9 |
"%08lx - perhaps this is not an Apache module DSO, "
|
|
Packit |
90a5c9 |
"or was compiled for a different Apache version?",
|
|
Packit |
90a5c9 |
modname, module_file,
|
|
Packit |
90a5c9 |
MODULE_MAGIC_COOKIE, modp->magic);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Add this module to the Apache core structures
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
error = ap_add_loaded_module(modp, cmd->pool, modname);
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Register a cleanup in the config apr_pool_t (normally pconf). When
|
|
Packit |
90a5c9 |
* we do a restart (or shutdown) this cleanup will cause the
|
|
Packit |
90a5c9 |
* shared object to be unloaded.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(cmd->pool, modi, unload_module, apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Finally we need to run the configuration process for the module
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_single_module_configure(cmd->pool, cmd->server, modp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This implements the LoadFile directive and loads an arbitrary
|
|
Packit |
90a5c9 |
* shared object file into the address space of the server process.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *load_file(cmd_parms *cmd, void *dummy, const char *filename)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_dso_handle_t *handle;
|
|
Packit |
90a5c9 |
const char *used_file, *error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
error = dso_load(cmd, &handle, filename, &used_file);
|
|
Packit |
90a5c9 |
if (error)
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, APLOGNO(01576)
|
|
Packit |
90a5c9 |
"loaded file %s", used_file);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static module *ap_find_loaded_module_symbol(server_rec *s, const char *modname)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
so_server_conf *sconf;
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modi;
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modie;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sconf = (so_server_conf *)ap_get_module_config(s->module_config,
|
|
Packit |
90a5c9 |
&so_module);
|
|
Packit |
90a5c9 |
modie = (ap_module_symbol_t *)sconf->loaded_modules->elts;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < sconf->loaded_modules->nelts; i++) {
|
|
Packit |
90a5c9 |
modi = &modie[i];
|
|
Packit |
90a5c9 |
if (modi->name != NULL && strcmp(modi->name, modname) == 0) {
|
|
Packit |
90a5c9 |
return modi->modp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void dump_loaded_modules(apr_pool_t *p, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modie;
|
|
Packit |
90a5c9 |
ap_module_symbol_t *modi;
|
|
Packit |
90a5c9 |
so_server_conf *sconf;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
apr_file_t *out = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!ap_exists_config_define("DUMP_MODULES")) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_file_open_stdout(&out, p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_file_printf(out, "Loaded Modules:\n");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sconf = (so_server_conf *)ap_get_module_config(s->module_config,
|
|
Packit |
90a5c9 |
&so_module);
|
|
Packit |
90a5c9 |
for (i = 0; ; i++) {
|
|
Packit |
90a5c9 |
modi = &ap_prelinked_module_symbols[i];
|
|
Packit |
90a5c9 |
if (modi->name != NULL) {
|
|
Packit |
90a5c9 |
apr_file_printf(out, " %s (static)\n", modi->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
modie = (ap_module_symbol_t *)sconf->loaded_modules->elts;
|
|
Packit |
90a5c9 |
for (i = 0; i < sconf->loaded_modules->nelts; i++) {
|
|
Packit |
90a5c9 |
modi = &modie[i];
|
|
Packit |
90a5c9 |
if (modi->name != NULL) {
|
|
Packit |
90a5c9 |
apr_file_printf(out, " %s (shared)\n", modi->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#else /* not NO_DLOPEN */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *load_file(cmd_parms *cmd, void *dummy, const char *filename)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, cmd->pool, APLOGNO(01577)
|
|
Packit |
90a5c9 |
"WARNING: LoadFile not supported on this platform");
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *load_module(cmd_parms *cmd, void *dummy,
|
|
Packit |
90a5c9 |
const char *modname, const char *filename)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, cmd->pool, APLOGNO(01578)
|
|
Packit |
90a5c9 |
"WARNING: LoadModule not supported on this platform");
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif /* NO_DLOPEN */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void register_hooks(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
#ifndef NO_DLOPEN
|
|
Packit |
90a5c9 |
APR_REGISTER_OPTIONAL_FN(ap_find_loaded_module_symbol);
|
|
Packit |
90a5c9 |
ap_hook_test_config(dump_loaded_modules, NULL, NULL, APR_HOOK_MIDDLE);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const command_rec so_cmds[] = {
|
|
Packit |
90a5c9 |
AP_INIT_TAKE2("LoadModule", load_module, NULL, RSRC_CONF | EXEC_ON_READ,
|
|
Packit |
90a5c9 |
"a module name and the name of a shared object file to load it from"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE("LoadFile", load_file, NULL, RSRC_CONF | EXEC_ON_READ,
|
|
Packit |
90a5c9 |
"shared object file or library to load into the server at runtime"),
|
|
Packit |
90a5c9 |
{ NULL }
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_MODULE(so) = {
|
|
Packit |
90a5c9 |
STANDARD20_MODULE_STUFF,
|
|
Packit |
90a5c9 |
NULL, /* create per-dir config */
|
|
Packit |
90a5c9 |
NULL, /* merge per-dir config */
|
|
Packit |
90a5c9 |
so_sconf_create, /* server config */
|
|
Packit |
90a5c9 |
NULL, /* merge server config */
|
|
Packit |
90a5c9 |
so_cmds, /* command apr_table_t */
|
|
Packit |
90a5c9 |
register_hooks /* register hooks */
|
|
Packit |
90a5c9 |
};
|