创建tags 文件:
php-5.3.3 目录下:
ctags -R .
ctags -R -a -f tags /path/to/httpd-2.2.16
如果需要tags使用绝对路径,则可以使用参数:
–tag-relative=no
1. mod_php.c的写法,主要是定义一些函数,然后通过模块结构体变量挂到apache的钩子上:
-
//…
-
// 1. 这个结构的名字php5_module是有严格要求的
-
module MODULE_VAR_EXPORT php5_module =
-
{
-
STANDARD_MODULE_STUFF,
-
php_init_handler, /* initializer */
-
php_create_dir, /* per-directory config creator */
-
php_merge_dir, /* dir merger */
-
NULL, /* per-server config creator */
-
NULL, /* merge server config */
-
php_commands, /* command table */
-
php_handlers, /* handlers */
-
NULL, /* filename translation */
-
NULL, /* check_user_id */
-
NULL, /* check auth */
-
NULL, /* check access */
-
NULL, /* type_checker */
-
NULL, /* fixups */
-
NULL /* logger */
-
#if MODULE_MAGIC_NUMBER >= 19970103
-
, NULL /* header parser */
-
#endif
-
#if MODULE_MAGIC_NUMBER >= 19970719
-
, NULL /* child_init */
-
#endif
-
#if MODULE_MAGIC_NUMBER >= 19970728
-
, php_child_exit_handler /* child_exit */
-
#endif
-
#if MODULE_MAGIC_NUMBER >= 19970902
-
, NULL /* post read-request *
-
#endif
-
};
2. apache模块结构的定义:
-
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. default -1*/
-
int module_index;
-
-
/** The name of the module’s C file */
-
const char *name;
-
/** The handle for the DSO. Internal use only , default null*/
-
void *dynamic_load_handle;
-
-
/** A pointer to the next module in the list
-
* @defvar module_struct *next , default null*/
-
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);
-
};
3. apache动态加载模块的过程。 动态加载模块时,严格检查模块名,包括httpd.conf中的module name(如: php5_module);对应的apache模块定义所在的文件的文件名(如: mod_php5.c)也是严格检查的。
-
static const char *load_module(cmd_parms *cmd, void *dummy,
-
const char *modname, const char *filename)
-
{
-
apr_dso_handle_t *modhandle;
-
apr_dso_handle_sym_t modsym;
-
module *modp;
-
const char *szModuleFile = ap_server_root_relative(cmd->pool, filename);
-
so_server_conf *sconf;
-
ap_module_symbol_t *modi;
-
//…
4. Apache conf 中的配置:
LoadModule php5_module modules/libphp5.so
5. apr 动态加载模块并获取指定符号(如:php5_module):
-
-
APR_DECLARE(apr_status_t) apr_dso_sym(apr_dso_handle_sym_t *ressym, apr_dso_handle_t *handle,
-
const char *symname)
-
{
-
int err;
-
-
if (symname == NULL)
-
return APR_ESYMNOTFOUND;
-
-
err = get_image_symbol(handle->handle, symname, B_SYMBOL_TYPE_ANY,
-
ressym);
-
-
if(err != B_OK)
-
return APR_ESYMNOTFOUND;
-
-
return APR_SUCCESS;
-
}
6. 一切准备完毕后:
将模块写入已加载的模块列表中: ap_add_loaded_module(modp, cmd->pool);
注册相关钩子函数:
apr_pool_cleanup_register(cmd->pool, modi, unload_module, apr_pool_cleanup_null);
Finally we need to run the configuration process for the module
ap_single_module_configure(cmd->pool, cmd->server, modp);