[普通]Apache 的hook 一览总结

作者(passion) 阅读(1169次) 评论(0) 分类( apache)

本章的重要内容:

  • 关于hook的调用顺序

  • 钩子函数的调用顺序是:「设定的初期化」「进程的初期化」「连接」「请求」

  • 关于RUN_ALL,RUN_FIRST

  • RUN_FIRST  类型的hook 是:被调用的 hook函数的返回值为 OK 或者是 DECLINE(出错)时,后面的hook是不被执行的。


  • RUN_ALL 类型的hook 是:被调用的 hook函数的返回值不为DECLINE(出错)时,已经加载的hook将被全部执行。

  • 关于hook 登録函数 ap_hook_xxx() 的参数

  • ap_hook_xxx() 的参数全部相同.具体的请参照下面.



/**
 * Run the header parser functions for each module
 * @param r The current request
 * @return OK or DECLINED
 */
AP_DECLARE_HOOK(int,header_parser,(request_rec *r))
/**
 * Run the pre_config function for each module
 * @param pconf The config pool
 * @param plog The logging streams pool
 * @param ptemp The temporary pool
 * @return OK or DECLINED on success anything else is a error
 */
AP_DECLARE_HOOK(int,pre_config,(apr_pool_t *pconf,apr_pool_t *plog,
                                apr_pool_t *ptemp))
/**
 * Run the check_config function for each module
 * @param pconf The config pool
 * @param plog The logging streams pool
 * @param ptemp The temporary pool
 * @param s the server to operate upon
 * @return OK or DECLINED on success anything else is a error
 */
AP_DECLARE_HOOK(int,check_config,(apr_pool_t *pconf, apr_pool_t *plog,
                                  apr_pool_t *ptemp, server_rec *s))
/**
 * Run the test_config function for each module; this hook is run
 * only if the server was invoked to test the configuration syntax.
 * @param pconf The config pool
 * @param s The list of server_recs
 * @note To avoid reordering problems due to different buffering, hook
 *       functions should only apr_file_*() to print to stdout/stderr and
 *       not simple printf()/fprintf().
 *     
 */
AP_DECLARE_HOOK(void,test_config,(apr_pool_t *pconf, server_rec *s))
/**
 * Run the post_config function for each module
 * @param pconf The config pool
 * @param plog The logging streams pool
 * @param ptemp The temporary pool
 * @param s The list of server_recs
 * @return OK or DECLINED on success anything else is a error
 */
AP_DECLARE_HOOK(int,post_config,(apr_pool_t *pconf,apr_pool_t *plog,
                                 apr_pool_t *ptemp,server_rec *s))
/**
 * Run the open_logs functions for each module
 * @param pconf The config pool
 * @param plog The logging streams pool
 * @param ptemp The temporary pool
 * @param s The list of server_recs
 * @return OK or DECLINED on success anything else is a error
 */
AP_DECLARE_HOOK(int,open_logs,(apr_pool_t *pconf,apr_pool_t *plog,
                               apr_pool_t *ptemp,server_rec *s))
/**
 * Run the child_init functions for each module
 * @param pchild The child pool
 * @param s The list of server_recs in this server
 */
AP_DECLARE_HOOK(void,child_init,(apr_pool_t *pchild, server_rec *s))
/**
 * Run the handler functions for each module
 * @param r The request_rec
 * @remark non-wildcard handlers should HOOK_MIDDLE, wildcard HOOK_LAST
 */
AP_DECLARE_HOOK(int,handler,(request_rec *r))
/**
 * Run the quick handler functions for each module. The quick_handler
 * is run before any other requests hooks are called (location_walk,
 * directory_walk, access checking, et. al.). This hook was added
 * to provide a quick way to serve content from a URI keyed cache.
 *
 * @param r The request_rec
 * @param lookup_uri Controls whether the caller actually wants content or not.
 * lookup is set when the quick_handler is called out of
 * ap_sub_req_lookup_uri()
 */
AP_DECLARE_HOOK(int,quick_handler,(request_rec *r, int lookup_uri))
/**
 * Retrieve the optional functions for each module.
 * This is run immediately before the server starts. Optional functions should
 * be registered during the hook registration phase.
 */
AP_DECLARE_HOOK(void,optional_fn_retrieve,(void))
/**
 * Allow modules to open htaccess files or perform operations before doing so
 * @param r The current request
 * @param dir_name The directory for which the htaccess file should be opened
 * @param access_name The filename  for which the htaccess file should be opened
 * @param conffile Where the pointer to the opened ap_configfile_t must be
 *        stored
 * @param full_name Where the full file name of the htaccess file must be
 *        stored.
 * @return APR_SUCCESS on success,
 *         APR_ENOENT or APR_ENOTDIR if no htaccess file exists,
 *         AP_DECLINED to let later modules do the opening,
 *         any other error code on error.
 */
AP_DECLARE_HOOK(apr_status_t,open_htaccess,
                (request_rec *r, const char *dir_name, const char *access_name,
                 ap_configfile_t **conffile, const char **full_name))

Index

設定初期化
RUN_ALLap_hook_pre_config()
RUN_ALLap_hook_open_logs()
RUN_ALLap_hook_post_config()
VOIDap_hook_optional_fn_retrieve()
进程初期化
RUN_ALLap_hook_pre_mpm()
VOIDap_hook_child_init()
连接
RUN_FIRSTap_hook_create_connection()
RUN_ALLap_hook_pre_connection()
RUN_FIRSTap_hook_process_connection()
请求(Request)
RUN_ALLap_hook_create_request()
RUN_ALLap_hook_post_read_request()
RUN_FIRSTap_hook_quick_handler()
RUN_FIRSTap_hook_translate_name()
RUN_FIRSTap_hook_map_to_storage()
RUN_ALLap_hook_header_parser()
RUN_ALLap_hook_access_checker()
RUN_FIRSTap_hook_check_user_id()
RUN_FIRSTap_hook_auth_checker()
RUN_FIRSTap_hook_type_checker()
RUN_ALLap_hook_fixups()
VOIDap_hook_insert_filter()
RUN_FIRSTap_hook_handler()
RUN_ALLap_hook_log_transaction()
出错 ERRor
VOIDap_hook_insert_error_filter()
VOIDap_hook_error_log()
必要時
RUN_FIRSTap_hook_default_port()
RUN_FIRSTap_hook_http_method()
随时被调用?
RUN_ALLap_hook_fatal_exception()
RUN_ALLap_hook_get_mgmt_items()
RUN_FIRSTap_hook_uexec_identity()

説明

ap_hook_pre_config()RUN_ALL
Run the pre_config function for each module
int x_pre_config(apr_pool_t *pconf,                 apr_pool_t *plog,                 apr_pool_t *ptemp)returnOK or DECLINED on success anything else is a errorpconfThe config poolplogThe logging streams poolptempThe temporary pool
ap_hook_open_logs()RUN_ALL
Run the open_logs functions for each module
int x_open_logs(apr_pool_t *pconf,                apr_pool_t *plog,                apr_pool_t *ptemp,                server_rec *s)returnOK or DECLINED on success anything else is a errorpconfThe config poolplogThe logging streams poolptempThe temporary poolsThe list of server_recs
ap_hook_post_config()RUN_ALL
Run the post_config function for each module
int x_post_config(apr_pool_t *pconf,                  apr_pool_t *plog,                  apr_pool_t *ptemp,                  server_rec *s)returnOK or DECLINED on success anything else is a errorpconfThe config poolplogThe logging streams poolptempThe temporary poolsThe list of server_recs
ap_hook_optional_fn_retrieve()
Retrieve the optional functions for each module. This is run immediately before the server starts. Optional functions should be registered during the hook registration phase.
void x_optional_fn_retrieve(void)
ap_hook_pre_mpm()RUN_ALL
Hook for post scoreboard creation, pre mpm.
int x_pre_mpm(apr_pool_t *p,              ap_scoreboard_e sb_type)returnOK or DECLINE on success; anything else is a errorpApache pool to allocate from.sb_type
ap_hook_child_init()
Run the child_init functions for each module
void x_child_init(apr_pool_t *pchild,                  server_rec *s)pchildThe child poolsThe list of server_recs in this server
ap_hook_create_connection()RUN_FIRST
create_connection is a RUN_FIRST hook which allows modules to create connections. In general, you should not install filters with the create_connection hook. If you require vhost configuration information to make filter installation decisions, you must use the pre_connection or install_network_transport hook. This hook should close the connection if it encounters a fatal error condition.
conn_rec * x_create_connection(apr_pool_t *p,                               server_rec *server,                               apr_socket_t *csd,                               long conn_id,                               void *sbh,                               apr_bucket_alloc_t *alloc)returnAn allocated connection record or NULL.server pThe pool from which to allocate the connection recordcsdThe socket that has been acceptedconn_idA unique identifier for this connection. The ID only needs to be unique at that time, not forever.sbhA handle to scoreboard information for this connection.alloc 
ap_hook_pre_connection()RUN_ALL
This hook gives protocol modules an opportunity to set everything up before calling the protocol handler. All pre-connection hooks are run until one returns something other than ok or decline
Apache の付属文書によれば,accept()直後に呼ばれる
int x_pre_connection(conn_rec *c,                     void *csd)returnOK or DECLINEDcThe connection on which the request has been received.csdThe mechanism on which this connection is to be read. Most times this will be a socket, but it is up to the module that accepts the request to determine the exact type.
ap_hook_process_connection()RUN_FIRST
This hook implements different protocols. After a connection has been established, the protocol module must read and serve the request. This function does that for each protocol module. The first protocol module to handle the request is the last module run.
int x_process_connection(conn_rec *c)returnOK or DECLINEDcThe connection on which the request has been received.
ap_hook_create_request()RUN_ALL
Gives modules a chance to create their request_config entry when the request is created.
int x_create_request(request_rec *r)returnOK or DECLINEDrThe current request
ap_hook_post_read_request()RUN_ALL
This hook allows modules to affect the request immediately after the request has been read, and before any other phases have been processes. This allows modules to make decisions based upon the input header fields
int x_post_read_request(request_rec *r)returnOK or DECLINEDrThe current request
ap_hook_quick_handler()RUN_FIRST
Run the quick handler functions for each module. The quick_handler is run before any other requests hooks are called (location_walk, directory_walk, access checking, et. al.). This hook was added to provide a quick way to serve content from a URI keyed cache.
Apache の付属文書によれば,キャッシュモジュールが使用している.
int x_quick_handler(request_rec *r,                    int lookup_uri)rThe request_reclookup_uriControls whether the caller actually wants content or not. lookup is set when the quick_handler is called out of ap_sub_req_lookup_uri()
ap_hook_translate_name()RUN_FIRST
This hook allow modules an opportunity to translate the URI into an actual filename. If no modules do anything special, the server's default rules will be followed.
int x_translate_name(request_rec *r)returnOK, DECLINED, or HTTP_...rThe current request
ap_hook_map_to_storage()RUN_FIRST
This hook allow modules to set the per_dir_config based on their own context (such as sections) and responds to contextless requests such as TRACE that need no security or filesystem mapping. based on the filesystem.
int x_map_to_storage(request_rec *r)returnDONE (or HTTP_) if this contextless request was just fulfilled (such as TRACE), OK if this is not a file, and DECLINED if this is a file. The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk and file_walk the r->filename.rThe current request
ap_hook_header_parser()RUN_ALL
Run the header parser functions for each module
int x_header_parser(request_rec *r)returnOK or DECLINEDrThe current request
ap_hook_access_checker()RUN_ALL
This hook is used to apply additional access control to this resource. It runs *before* a user is authenticated, so this hook is really to apply additional restrictions independent of a user. It also runs independent of 'Require' directive usage.
int x_access_checker(request_rec *r)returnOK, DECLINED, or HTTP_...rthe current request
ap_hook_check_user_id()RUN_FIRST
This hook is used to analyze the request headers, authenticate the user, and set the user information in the request record (r->user and r->ap_auth_type). This hook is only run when Apache determines that authentication/authorization is required for this resource (as determined by the 'Require' directive). It runs after the access_checker hook, and before the auth_checker hook.
int x_check_user_id(request_rec *r)returnOK, DECLINED, or HTTP_...rThe current request
ap_hook_auth_checker()RUN_FIRST
This hook is used to check to see if the resource being requested is available for the authenticated user (r->user and r->ap_auth_type). It runs after the access_checker and check_user_id hooks. Note that it will *only* be called if Apache determines that access control has been applied to this resource (through a 'Require' directive).
int x_auth_checker(request_rec *r)returnOK, DECLINED, or HTTP_...rthe current request
ap_hook_type_checker()RUN_FIRST
This routine is called to determine and/or set the various document type information bits, like Content-type (via r->content_type), language, et cetera.
int x_type_checker(request_rec *r)returnOK, DECLINED, or HTTP_...rthe current request
ap_hook_fixups()RUN_ALL
Allows modules to perform module-specific fixing of header fields. This is invoked just before any content-handler
int x_fixups(request_rec *r)returnOK, DECLINED, or HTTP_...rThe current request
ap_hook_insert_filter()
This hook allows modules to insert filters for the current request
void x_insert_filter(request_rec *r)rthe current request
ap_hook_handler()RUN_FIRST
Run the handler functions for each module non-wildcard handlers should HOOK_MIDDLE, wildcard HOOK_LAST
int x_handler(request_rec *r)rThe request_rec
ap_hook_log_transaction()RUN_ALL
This hook allows modules to perform any module-specific logging activities over and above the normal server things.
int x_log_transaction(request_rec *r)returnOK, DECLINED, or HTTP_...rThe current request
ap_hook_insert_error_filter()
This hook allows modules to insert filters for the current error response
void x_insert_error_filter(request_rec *r)rthe current request
ap_hook_error_log()

void x_error_log(const char *file,                 int line,                 int level,                 apr_status_t status,                 const server_rec *s,                 const request_rec *r,                 apr_pool_t *pool,                 const char *errstr)
ap_hook_default_port()RUN_FIRST
Return the default port from the current request
apr_port_t x_default_port(const request_rec *r)returnThe current portrThe current request
ap_hook_http_method()RUN_FIRST
This hook allows modules to retrieve the http method from a request. This allows Apache modules to easily extend the methods that Apache understands
ここで言う"method" は scheme の間違いのようです.実際,Apache 2.2 では ap_hook_http_scheme() に変更されています.
const char * x_http_method(const request_rec *r)returnThe http method from the requestrThe current request
ap_hook_fatal_exception()RUN_ALL

int x_fatal_exception(ap_exception_info_t *ei)
ap_hook_get_mgmt_items()RUN_ALL
This hook provdes a way for modules to provide metrics/statistics about their operational status.
int x_get_mgmt_items(apr_pool_t *p,                     const char * val,                     apr_hash_t *ht)pA pool to use to create entries in the hash tablevalThe name of the parameter(s) that is wanted. This is tree-structured would be in the form ('*' is all the tree, 'module.*' all of the module , 'module.foo.*', or 'module.foo.bar' )htThe hash table to store the results. Keys are item names, and the values point to ap_mgmt_item_t structures.
ap_hook_get_suexec_identity()RUN_FIRST

ap_unix_identity_t * x_get_suexec_identity(const request_rec *r)


« 上一篇:wifi共享上网(至尊版wifi)
« 下一篇:ASP.NET附加数据库文件的方式,如何发布到IIS7而不导致SQLServer出错
在这里写下您精彩的评论
  • 微信

  • QQ

  • 支付宝

返回首页
返回首页 img
返回顶部~
返回顶部 img