⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_example.c

📁 最新apache的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
static void *x_create_dir_config(apr_pool_t *p, char *dirspec){    x_cfg *cfg;    char *dname = dirspec;    /*     * Allocate the space for our record from the pool supplied.     */    cfg = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));    /*     * Now fill in the defaults.  If there are any `parent' configuration     * records, they'll get merged as part of a separate callback.     */    cfg->local = 0;    cfg->congenital = 0;    cfg->cmode = CONFIG_MODE_DIRECTORY;    /*     * Finally, add our trace to the callback list.     */    dname = (dname != NULL) ? dname : "";    cfg->loc = apr_pstrcat(p, "DIR(", dname, ")", NULL);    trace_add(NULL, NULL, cfg, "x_create_dir_config()");    return (void *) cfg;}/* * This function gets called to merge two per-directory configuration * records.  This is typically done to cope with things like .htaccess files * or <Location> directives for directories that are beneath one for which a * configuration record was already created.  The routine has the * responsibility of creating a new record and merging the contents of the * other two into it appropriately.  If the module doesn't declare a merge * routine, the record for the closest ancestor location (that has one) is * used exclusively. * * The routine MUST NOT modify any of its arguments! * * The return value is a pointer to the created module-specific structure * containing the merged values. */static void *x_merge_dir_config(apr_pool_t *p, void *parent_conf,                                      void *newloc_conf){    x_cfg *merged_config = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));    x_cfg *pconf = (x_cfg *) parent_conf;    x_cfg *nconf = (x_cfg *) newloc_conf;    char *note;    /*     * Some things get copied directly from the more-specific record, rather     * than getting merged.     */    merged_config->local = nconf->local;    merged_config->loc = apr_pstrdup(p, nconf->loc);    /*     * Others, like the setting of the `congenital' flag, get ORed in.  The     * setting of that particular flag, for instance, is TRUE if it was ever     * true anywhere in the upstream configuration.     */    merged_config->congenital = (pconf->congenital | pconf->local);    /*     * If we're merging records for two different types of environment (server     * and directory), mark the new record appropriately.  Otherwise, inherit     * the current value.     */    merged_config->cmode =        (pconf->cmode == nconf->cmode) ? pconf->cmode : CONFIG_MODE_COMBO;    /*     * Now just record our being called in the trace list.  Include the     * locations we were asked to merge.     */    note = apr_pstrcat(p, "x_merge_dir_config(\"", pconf->loc, "\",\"",                   nconf->loc, "\")", NULL);    trace_add(NULL, NULL, merged_config, note);    return (void *) merged_config;}/* * This function gets called to create a per-server configuration * record.  It will always be called for the "default" server. * * The return value is a pointer to the created module-specific * structure. */static void *x_create_server_config(apr_pool_t *p, server_rec *s){    x_cfg *cfg;    char *sname = s->server_hostname;    /*     * As with the x_create_dir_config() reoutine, we allocate and fill     * in an empty record.     */    cfg = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));    cfg->local = 0;    cfg->congenital = 0;    cfg->cmode = CONFIG_MODE_SERVER;    /*     * Note that we were called in the trace list.     */    sname = (sname != NULL) ? sname : "";    cfg->loc = apr_pstrcat(p, "SVR(", sname, ")", NULL);    trace_add(s, NULL, cfg, "x_create_server_config()");    return (void *) cfg;}/* * This function gets called to merge two per-server configuration * records.  This is typically done to cope with things like virtual hosts and * the default server configuration  The routine has the responsibility of * creating a new record and merging the contents of the other two into it * appropriately.  If the module doesn't declare a merge routine, the more * specific existing record is used exclusively. * * The routine MUST NOT modify any of its arguments! * * The return value is a pointer to the created module-specific structure * containing the merged values. */static void *x_merge_server_config(apr_pool_t *p, void *server1_conf,                                         void *server2_conf){    x_cfg *merged_config = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));    x_cfg *s1conf = (x_cfg *) server1_conf;    x_cfg *s2conf = (x_cfg *) server2_conf;    char *note;    /*     * Our inheritance rules are our own, and part of our module's semantics.     * Basically, just note whence we came.     */    merged_config->cmode =        (s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO;    merged_config->local = s2conf->local;    merged_config->congenital = (s1conf->congenital | s1conf->local);    merged_config->loc = apr_pstrdup(p, s2conf->loc);    /*     * Trace our call, including what we were asked to merge.     */    note = apr_pstrcat(p, "x_merge_server_config(\"", s1conf->loc, "\",\"",                   s2conf->loc, "\")", NULL);    trace_add(NULL, NULL, merged_config, note);    return (void *) merged_config;}/* * This routine is called before the server processes the configuration * files.  There is no return value. */static int x_pre_config(apr_pool_t *pconf, apr_pool_t *plog,                        apr_pool_t *ptemp){    /*     * Log the call and exit.     */    trace_add(NULL, NULL, NULL, "x_pre_config()");    return OK;}/* * This routine is called to perform any module-specific fixing of header * fields, et cetera.  It is invoked just before any content-handler. * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */static int x_post_config(apr_pool_t *pconf, apr_pool_t *plog,                          apr_pool_t *ptemp, server_rec *s){    /*     * Log the call and exit.     */    trace_add(NULL, NULL, NULL, "x_post_config()");    return OK;}/* * This routine is called to perform any module-specific log file * openings. It is invoked just before the post_config phase * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */static int x_open_logs(apr_pool_t *pconf, apr_pool_t *plog,                        apr_pool_t *ptemp, server_rec *s){    /*     * Log the call and exit.     */    trace_add(s, NULL, NULL, "x_open_logs()");    return OK;}/* * All our process-death routine does is add its trace to the log. */static apr_status_t x_child_exit(void *data){    char *note;    server_rec *s = data;    char *sname = s->server_hostname;    /*     * The arbitrary text we add to our trace entry indicates for which server     * we're being called.     */    sname = (sname != NULL) ? sname : "";    note = apr_pstrcat(s->process->pool, "x_child_exit(", sname, ")", NULL);    trace_add(s, NULL, NULL, note);    return APR_SUCCESS;}/* * All our process initialiser does is add its trace to the log. */static void x_child_init(apr_pool_t *p, server_rec *s){    char *note;    char *sname = s->server_hostname;    /*     * Set up any module cells that ought to be initialised.     */    setup_module_cells();    /*     * The arbitrary text we add to our trace entry indicates for which server     * we're being called.     */    sname = (sname != NULL) ? sname : "";    note = apr_pstrcat(p, "x_child_init(", sname, ")", NULL);    trace_add(s, NULL, NULL, note);    apr_pool_cleanup_register(p, s, x_child_exit, x_child_exit);}/* * XXX: This routine is called XXX * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */#if 0static const char *x_http_method(const request_rec *r){    x_cfg *cfg;    cfg = our_dconfig(r);    /*     * Log the call and exit.     */    trace_add(r->server, NULL, cfg, "x_http_method()");    return "foo";}/* * XXX: This routine is called XXX * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */static apr_port_t x_default_port(const request_rec *r){    x_cfg *cfg;    cfg = our_dconfig(r);    /*     * Log the call and exit.     */    trace_add(r->server, NULL, cfg, "x_default_port()");    return 80;}#endif /*0*//* * XXX: This routine is called XXX * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */static void x_insert_filter(request_rec *r){    x_cfg *cfg;    cfg = our_dconfig(r);    /*     * Log the call and exit.     */    trace_add(r->server, NULL, cfg, "x_insert_filter()");}/* * XXX: This routine is called XXX * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */static int x_quick_handler(request_rec *r, int lookup_uri){    x_cfg *cfg;    cfg = our_dconfig(r);    /*     * Log the call and exit.     */    trace_add(r->server, NULL, cfg, "x_post_config()");    return DECLINED;}/* * This routine is called just after the server accepts the connection, * but before it is handed off to a protocol module to be served.  The point * of this hook is to allow modules an opportunity to modify the connection * as soon as possible. The core server uses this phase to setup the * connection record based on the type of connection that is being used. * * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the * server will still call any remaining modules with an handler for this * phase. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -