本文将介绍以下三种库:
1)动态连接库(动态加载模式)
2)动态连接库(预先加载模式)
3)静态库(编译时连接模式)
模块的函数调用流程:
static const cmd_rec my_cmds[] = {
AP_INIT_TAKE1("MyFirstDirective", my_first_cmd_func, my_ptr, OR_ALL,
"This is My First Directive"),
/* more directives as applicable */
{ NULL }
} ;
module MODULE_VAR_EXPORT module_name_module =
{
STANDARD20_MODULE_STUFF,
/* create per-directory config structures */
/* merge per-directory config structures */
/* create per-server config structures */
/* merge per-server config structures */
/* command handlers */
/* handlers */
/* register hooks */
};/* *
* filename :ap_config.h
* Apache Core dso variables are declared with AP_MODULE_DECLARE_DATA.
* This assures the appropriate indirection is invoked at compile time.
*
* @note AP_DECLARE_DATA extern type apr_variable; syntax is required for
* declarations within headers to properly import the variable.
* @code
* AP_DECLARE_DATA type apr_variable
* @endcode
*/
#define AP_DECLARE_DATA __declspec(dllexport)/**
* file http_config.h
* Module structures. Just about everything is dispatched through
* these, directly or indirectly (through the command and handler
* tables).
*/
typedef struct module_struct module;
struct module_struct {
/** API version, *not* module version; check that module is
* compatible with this version of the server.
*/
int version;
/** API minor version. Provides API feature milestones. Not checked
* during module init */
int minor_version;
/** Index to this modules structures in config vectors. */
int module_index;
/** The name of the module's C file */
const char *name;
/** The handle for the DSO. Internal use only */
void *dynamic_load_handle;
/** A pointer to the next module in the list
* @defvar module_struct *next */
struct module_struct *next;
/** Magic Cookie to identify a module structure; It's mainly
* important for the DSO facility (see also mod_so). */
unsigned long magic;
/** Function to allow MPMs to re-write command line arguments. This
* hook is only available to MPMs.
* @param The process that the server is running in.
*/
void (*rewrite_args) (process_rec *process);
/** Function to allow all modules to create per directory configuration
* structures.
* @param p The pool to use for all allocations.
* @param dir The directory currently being processed.
* @return The per-directory structure created
*/
void *(*create_dir_config) (apr_pool_t *p, char *dir);
/** Function to allow all modules to merge the per directory configuration
* structures for two directories.
* @param p The pool to use for all allocations.
* @param base_conf The directory structure created for the parent directory.
* @param new_conf The directory structure currently being processed.
* @return The new per-directory structure created
*/
void *(*merge_dir_config) (apr_pool_t *p, void *base_conf, void *new_conf);
/** Function to allow all modules to create per server configuration
* structures.
* @param p The pool to use for all allocations.
* @param s The server currently being processed.
* @return The per-server structure created
*/
void *(*create_server_config) (apr_pool_t *p, server_rec *s);
/** Function to allow all modules to merge the per server configuration
* structures for two servers.
* @param p The pool to use for all allocations.
* @param base_conf The directory structure created for the parent directory.
* @param new_conf The directory structure currently being processed.
* @return The new per-directory structure created
*/
void *(*merge_server_config) (apr_pool_t *p, void *base_conf,
void *new_conf);
/** A command_rec table that describes all of the directives this module
* defines. */
const command_rec *cmds;
/** A hook to allow modules to hook other points in the request processing.
* In this function, modules should call the ap_hook_*() functions to
* register an interest in a specific step in processing the current
* request.
* @param p the pool to use for all allocations
*/
void (*register_hooks) (apr_pool_t *p);
};ap_mod_list *ml;
ap_cfg_getline(char *buf, size_t bufsize, ap_configfile_t *cfp);
调用堆栈:
libhttpd.dll!load_module(cmd_parms_struct * cmd=0x0006fd0c, void * dummy=0x0006fb24, const char * modname=0x009fb940, const char * filename=0x009fb958) 行158 C
libhttpd.dll!invoke_cmd(const command_struct * cmd=0x6ff3cee8, cmd_parms_struct * parms=0x0006fd0c, void * mconfig=0x0006fb24, const char * args=0x009f5834) 行800 + 0x18 字节 C
> libhttpd.dll!execute_now(char * cmd_line=0x009fb8d0, const char * args=0x009f580b, cmd_parms_struct * parms=0x0006fd0c, apr_pool_t * p=0x0090b940, apr_pool_t * ptemp=0x009e2680, ap_directive_t * * sub_tree=0x0006fb24, ap_directive_t * parent=0x00000000) 行1441 + 0x15 字节 C
libhttpd.dll!ap_build_config_sub(apr_pool_t * p=0x0090b940, apr_pool_t * temp_pool=0x009e2680, const char * l=0x009f5800, cmd_parms_struct * parms=0x0006fd0c, ap_directive_t * * current=0x0006fb74, ap_directive_t * * curr_parent=0x0006fb78, ap_directive_t * * conftree=0x6ff5178c) 行1013 + 0x23 字节 C
libhttpd.dll!ap_build_config(cmd_parms_struct * parms=0x0006fd0c, apr_pool_t * p=0x0090b940, apr_pool_t * temp_pool=0x009e2680, ap_directive_t * * conftree=0x6ff5178c) 行1225 + 0x21 字节 C
libhttpd.dll!process_resource_config_nofnmatch(server_rec * s=0x009b7b10, const char * fname=0x009e8490, ap_directive_t * * conftree=0x6ff5178c, apr_pool_t * p=0x0090b940, apr_pool_t * ptemp=0x009e2680, unsigned int depth=0x00000000) 行1634 + 0x15 字节 C
libhttpd.dll!ap_process_resource_config(server_rec * s=0x009b7b10, const char * fname=0x009e8490, ap_directive_t * * conftree=0x6ff5178c, apr_pool_t * p=0x0090b940, apr_pool_t * ptemp=0x009e2680) 行1667 + 0x1b 字节 C
libhttpd.dll!ap_read_config(process_rec * process=0x009b30d0, apr_pool_t * ptemp=0x009e2680, const char * filename=0x00404d10, ap_directive_t * * conftree=0x6ff5178c) 行2026 + 0x19 字节 C
httpd.exe!main(int argc=0x00000001, const char * const * argv=0x00908b90) 行632 + 0x19 字节 C
httpd.exe!__tmainCRTStartup() 行586 + 0x19 字节 C
httpd.exe!mainCRTStartup() 行403 Cap_config_hash
静态组件的编译和调用:
//modules.c
AP_DECLARE_DATA module *ap_prelinked_modules[] = {
&core_module,
&win32_module,
&mpm_winnt_module,
&http_module,
&so_module,
NULL
};
ap_module_symbol_t ap_prelinked_module_symbols[] = {
{"core_module", &core_module},
{"win32_module", &win32_module},
{"mpm_winnt_module", &mpm_winnt_module},
{"http_module", &http_module},
{"so_module", &so_module},
{NULL, NULL}
};
AP_DECLARE_DATA module *ap_preloaded_modules[] = {
&core_module,
&win32_module,
&mpm_winnt_module,
&http_module,
&so_module,
NULL
};