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

📄 mod_cache.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 4 页
字号:
{    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->no_last_mod_ignore = flag;    conf->no_last_mod_ignore_set = 1;    return NULL;}static const char *set_cache_ignore_cachecontrol(cmd_parms *parms,                                                 void *dummy, int flag){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->ignorecachecontrol = flag;    conf->ignorecachecontrol_set = 1;    return NULL;}static const char *set_cache_store_private(cmd_parms *parms, void *dummy,                                           int flag){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->store_private = flag;    conf->store_private_set = 1;    return NULL;}static const char *set_cache_store_nostore(cmd_parms *parms, void *dummy,                                           int flag){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->store_nostore = flag;    conf->store_nostore_set = 1;    return NULL;}static const char *add_ignore_header(cmd_parms *parms, void *dummy,                                     const char *header){    cache_server_conf *conf;    char **new;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    if (!strncasecmp(header, "None", 4)) {        /* if header None is listed clear array */        conf->ignore_headers->nelts = 0;    }    else {        if ((conf->ignore_headers_set == CACHE_IGNORE_HEADERS_UNSET) ||            (conf->ignore_headers->nelts)) {            /* Only add header if no "None" has been found in header list             * so far.             * (When 'None' is passed, IGNORE_HEADERS_SET && nelts == 0.)             */            new = (char **)apr_array_push(conf->ignore_headers);            (*new) = (char *)header;        }    }    conf->ignore_headers_set = CACHE_IGNORE_HEADERS_SET;    return NULL;}static const char *add_cache_enable(cmd_parms *parms, void *dummy,                                    const char *type,                                    const char *url){    cache_server_conf *conf;    struct cache_enable *new;    if (*type == '/') {        return apr_psprintf(parms->pool,          "provider (%s) starts with a '/'.  Are url and provider switched?",          type);    }    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    new = apr_array_push(conf->cacheenable);    new->type = type;    if (apr_uri_parse(parms->pool, url, &(new->url))) {        return NULL;    }    if (new->url.path) {        new->pathlen = strlen(new->url.path);    } else {        new->pathlen = 1;        new->url.path = "/";    }    return NULL;}static const char *add_cache_disable(cmd_parms *parms, void *dummy,                                     const char *url){    cache_server_conf *conf;    struct cache_disable *new;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    new = apr_array_push(conf->cachedisable);    if (apr_uri_parse(parms->pool, url, &(new->url))) {        return NULL;    }    if (new->url.path) {        new->pathlen = strlen(new->url.path);    } else {        new->pathlen = 1;        new->url.path = "/";    }    return NULL;}static const char *set_cache_maxex(cmd_parms *parms, void *dummy,                                   const char *arg){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->maxex = (apr_time_t) (atol(arg) * MSEC_ONE_SEC);    conf->maxex_set = 1;    return NULL;}static const char *set_cache_defex(cmd_parms *parms, void *dummy,                                   const char *arg){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->defex = (apr_time_t) (atol(arg) * MSEC_ONE_SEC);    conf->defex_set = 1;    return NULL;}static const char *set_cache_factor(cmd_parms *parms, void *dummy,                                    const char *arg){    cache_server_conf *conf;    double val;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    if (sscanf(arg, "%lg", &val) != 1) {        return "CacheLastModifiedFactor value must be a float";    }    conf->factor = val;    conf->factor_set = 1;    return NULL;}static const char *set_cache_ignore_querystring(cmd_parms *parms, void *dummy,                                                int flag){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->ignorequerystring = flag;    conf->ignorequerystring_set = 1;    return NULL;}static int cache_post_config(apr_pool_t *p, apr_pool_t *plog,                             apr_pool_t *ptemp, server_rec *s){    /* This is the means by which unusual (non-unix) os's may find alternate     * means to run a given command (e.g. shebang/registry parsing on Win32)     */    cache_generate_key = APR_RETRIEVE_OPTIONAL_FN(ap_cache_generate_key);    if (!cache_generate_key) {        cache_generate_key = cache_generate_key_default;    }    return OK;}static const command_rec cache_cmds[] ={    /* XXX     * Consider a new config directive that enables loading specific cache     * implememtations (like mod_cache_mem, mod_cache_file, etc.).     * Rather than using a LoadModule directive, admin would use something     * like CacheModule  mem_cache_module | file_cache_module, etc,     * which would cause the approprpriate cache module to be loaded.     * This is more intuitive that requiring a LoadModule directive.     */    AP_INIT_TAKE2("CacheEnable", add_cache_enable, NULL, RSRC_CONF,                  "A cache type and partial URL prefix below which "                  "caching is enabled"),    AP_INIT_TAKE1("CacheDisable", add_cache_disable, NULL, RSRC_CONF,                  "A partial URL prefix below which caching is disabled"),    AP_INIT_TAKE1("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF,                  "The maximum time in seconds to cache a document"),    AP_INIT_TAKE1("CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF,                  "The default time in seconds to cache a document"),    AP_INIT_FLAG("CacheIgnoreNoLastMod", set_cache_ignore_no_last_mod, NULL,                 RSRC_CONF,                 "Ignore Responses where there is no Last Modified Header"),    AP_INIT_FLAG("CacheIgnoreCacheControl", set_cache_ignore_cachecontrol,                 NULL, RSRC_CONF,                 "Ignore requests from the client for uncached content"),    AP_INIT_FLAG("CacheStorePrivate", set_cache_store_private,                 NULL, RSRC_CONF,                 "Ignore 'Cache-Control: private' and store private content"),    AP_INIT_FLAG("CacheStoreNoStore", set_cache_store_nostore,                 NULL, RSRC_CONF,                 "Ignore 'Cache-Control: no-store' and store sensitive content"),    AP_INIT_ITERATE("CacheIgnoreHeaders", add_ignore_header, NULL, RSRC_CONF,                    "A space separated list of headers that should not be "                    "stored by the cache"),    AP_INIT_FLAG("CacheIgnoreQueryString", set_cache_ignore_querystring,                 NULL, RSRC_CONF,                 "Ignore query-string when caching"),    AP_INIT_TAKE1("CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF,                  "The factor used to estimate Expires date from "                  "LastModified date"),    {NULL}};static void register_hooks(apr_pool_t *p){    /* cache initializer */    /* cache handler */    ap_hook_quick_handler(cache_url_handler, NULL, NULL, APR_HOOK_FIRST);    /* cache filters     * XXX The cache filters need to run right after the handlers and before     * any other filters. Consider creating AP_FTYPE_CACHE for this purpose.     *     * Depending on the type of request (subrequest / main request) they     * need to be run before AP_FTYPE_CONTENT_SET / after AP_FTYPE_CONTENT_SET     * filters. Thus create two filter handles for each type:     * cache_save_filter_handle / cache_out_filter_handle to be used by     * main requests and     * cache_save_subreq_filter_handle / cache_out_subreq_filter_handle     * to be run by subrequest     */    /*     * CACHE_SAVE must go into the filter chain after a possible DEFLATE     * filter to ensure that the compressed content is stored.     * Incrementing filter type by 1 ensures his happens.     */    cache_save_filter_handle =        ap_register_output_filter("CACHE_SAVE",                                  cache_save_filter,                                  NULL,                                  AP_FTYPE_CONTENT_SET+1);    /*     * CACHE_SAVE_SUBREQ must go into the filter chain before SUBREQ_CORE to     * handle subrequsts. Decrementing filter type by 1 ensures this     * happens.     */    cache_save_subreq_filter_handle =        ap_register_output_filter("CACHE_SAVE_SUBREQ",                                  cache_save_filter,                                  NULL,                                  AP_FTYPE_CONTENT_SET-1);    /*     * CACHE_OUT must go into the filter chain after a possible DEFLATE     * filter to ensure that already compressed cache objects do not     * get compressed again. Incrementing filter type by 1 ensures     * his happens.     */    cache_out_filter_handle =        ap_register_output_filter("CACHE_OUT",                                  cache_out_filter,                                  NULL,                                  AP_FTYPE_CONTENT_SET+1);    /*     * CACHE_OUT_SUBREQ must go into the filter chain before SUBREQ_CORE to     * handle subrequsts. Decrementing filter type by 1 ensures this     * happens.     */    cache_out_subreq_filter_handle =        ap_register_output_filter("CACHE_OUT_SUBREQ",                                  cache_out_filter,                                  NULL,                                  AP_FTYPE_CONTENT_SET-1);    /* CACHE_REMOVE_URL has to be a protocol filter to ensure that is     * run even if the response is a canned error message, which     * removes the content filters.     */    cache_remove_url_filter_handle =        ap_register_output_filter("CACHE_REMOVE_URL",                                  cache_remove_url_filter,                                  NULL,                                  AP_FTYPE_PROTOCOL);    ap_hook_post_config(cache_post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);}module AP_MODULE_DECLARE_DATA cache_module ={    STANDARD20_MODULE_STUFF,    NULL,                   /* create per-directory config structure */    NULL,                   /* merge per-directory config structures */    create_cache_config,    /* create per-server config structure */    merge_cache_config,     /* merge per-server config structures */    cache_cmds,             /* command apr_table_t */    register_hooks};

⌨️ 快捷键说明

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