#include "httpd.h"
#include "http_config.h"
#include <nwadv.h>
module MODULE_VAR_EXPORT nlm_module;
static int been_there_done_that = 0;
char *load_module(cmd_parms *cmd, void *dummy, char *modname, char *filename)
{
module *modp;
int nlmHandle;
const char *szModuleFile = ap_server_root_relative(cmd->pool, filename);
if (been_there_done_that)
return NULL;
nlmHandle = FindNLMHandle(filename);
if (nlmHandle == NULL) {
spawnlp(P_NOWAIT, szModuleFile, NULL);
nlmHandle = FindNLMHandle(filename);
if (nlmHandle == NULL)
return ap_pstrcat(cmd->pool, "Cannot load ", szModuleFile,
" into server", NULL);
}
modp = (module *) ImportSymbol(nlmHandle, modname);
if (!modp)
return ap_pstrcat(cmd->pool, "Can't find module ", modname,
" in file ", filename, NULL);
ap_add_module(modp);
if (modp->create_server_config)
((void**)cmd->server->module_config)[modp->module_index] =
(*modp->create_server_config)(cmd->pool, cmd->server);
if (modp->create_dir_config)
((void**)cmd->server->lookup_defaults)[modp->module_index] =
(*modp->create_dir_config)(cmd->pool, NULL);
return NULL;
}
char *load_file(cmd_parms *cmd, void *dummy, char *filename)
{
if (been_there_done_that)
return NULL;
if (spawnlp(P_NOWAIT, ap_server_root_relative(cmd->pool, filename), NULL))
return ap_pstrcat(cmd->pool, "Cannot load ", filename, " into server", NULL);
return NULL;
}
void check_loaded_modules(server_rec *dummy, pool *p)
{
if (been_there_done_that)
return;
been_there_done_that = 1;
}
command_rec nlm_cmds[] = {
{ "LoadModule", load_module, NULL, RSRC_CONF, TAKE2,
"a module name, and the name of a file to load it from"},
{ "LoadFile", load_file, NULL, RSRC_CONF, ITERATE,
"files or libraries to link into the server at runtime"},
{ NULL }
};
module nlm_module = {
STANDARD_MODULE_STUFF,
check_loaded_modules,
NULL,
NULL,
NULL,
NULL,
nlm_cmds,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};