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

📄 mod_alias.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 2 页
字号:
                                      const char *arg3){    return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 1);}static const command_rec alias_cmds[] ={    AP_INIT_TAKE2("Alias", add_alias, NULL, RSRC_CONF,                  "a fakename and a realname"),    AP_INIT_TAKE2("ScriptAlias", add_alias, "cgi-script", RSRC_CONF,                  "a fakename and a realname"),    AP_INIT_TAKE23("Redirect", add_redirect, (void *) HTTP_MOVED_TEMPORARILY,                   OR_FILEINFO,                   "an optional status, then document to be redirected and "                   "destination URL"),    AP_INIT_TAKE2("AliasMatch", add_alias_regex, NULL, RSRC_CONF,                  "a regular expression and a filename"),    AP_INIT_TAKE2("ScriptAliasMatch", add_alias_regex, "cgi-script", RSRC_CONF,                  "a regular expression and a filename"),    AP_INIT_TAKE23("RedirectMatch", add_redirect_regex,                   (void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO,                   "an optional status, then a regular expression and "                   "destination URL"),    AP_INIT_TAKE2("RedirectTemp", add_redirect2,                  (void *) HTTP_MOVED_TEMPORARILY, OR_FILEINFO,                  "a document to be redirected, then the destination URL"),    AP_INIT_TAKE2("RedirectPermanent", add_redirect2,                  (void *) HTTP_MOVED_PERMANENTLY, OR_FILEINFO,                  "a document to be redirected, then the destination URL"),    {NULL}};static int alias_matches(const char *uri, const char *alias_fakename){    const char *aliasp = alias_fakename, *urip = uri;    while (*aliasp) {        if (*aliasp == '/') {            /* any number of '/' in the alias matches any number in             * the supplied URI, but there must be at least one...             */            if (*urip != '/')                return 0;            do {                ++aliasp;            } while (*aliasp == '/');            do {                ++urip;            } while (*urip == '/');        }        else {            /* Other characters are compared literally */            if (*urip++ != *aliasp++)                return 0;        }    }    /* Check last alias path component matched all the way */    if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')        return 0;    /* Return number of characters from URI which matched (may be     * greater than length of alias, since we may have matched     * doubled slashes)     */    return urip - uri;}static char *try_alias_list(request_rec *r, apr_array_header_t *aliases,                            int doesc, int *status){    alias_entry *entries = (alias_entry *) aliases->elts;    ap_regmatch_t regm[AP_MAX_REG_MATCH];    char *found = NULL;    int i;    for (i = 0; i < aliases->nelts; ++i) {        alias_entry *p = &entries[i];        int l;        if (p->regexp) {            if (!ap_regexec(p->regexp, r->uri, AP_MAX_REG_MATCH, regm, 0)) {                if (p->real) {                    found = ap_pregsub(r->pool, p->real, r->uri,                                       AP_MAX_REG_MATCH, regm);                    if (found && doesc) {                        apr_uri_t uri;                        apr_uri_parse(r->pool, found, &uri);                        /* Do not escape the query string or fragment. */                        found = apr_uri_unparse(r->pool, &uri,                                                APR_URI_UNP_OMITQUERY);                        found = ap_escape_uri(r->pool, found);                        if (uri.query) {                            found = apr_pstrcat(r->pool, found, "?",                                                uri.query, NULL);                        }                        if (uri.fragment) {                            found = apr_pstrcat(r->pool, found, "#",                                                uri.fragment, NULL);                        }                    }                }                else {                    /* need something non-null */                    found = apr_pstrdup(r->pool, "");                }            }        }        else {            l = alias_matches(r->uri, p->fake);            if (l > 0) {                if (doesc) {                    char *escurl;                    escurl = ap_os_escape_path(r->pool, r->uri + l, 1);                    found = apr_pstrcat(r->pool, p->real, escurl, NULL);                }                else                    found = apr_pstrcat(r->pool, p->real, r->uri + l, NULL);            }        }        if (found) {            if (p->handler) {    /* Set handler, and leave a note for mod_cgi */                r->handler = p->handler;                apr_table_setn(r->notes, "alias-forced-type", r->handler);            }            /* XXX This is as SLOW as can be, next step, we optimize             * and merge to whatever part of the found path was already             * canonicalized.  After I finish eliminating os canonical.             * Better fail test for ap_server_root_relative needed here.             */            if (!doesc) {                found = ap_server_root_relative(r->pool, found);            }            if (found) {                *status = p->redir_status;            }            return found;        }    }    return NULL;}static int translate_alias_redir(request_rec *r){    ap_conf_vector_t *sconf = r->server->module_config;    alias_server_conf *serverconf = ap_get_module_config(sconf, &alias_module);    char *ret;    int status;    if (r->uri[0] != '/' && r->uri[0] != '\0') {        return DECLINED;    }    if ((ret = try_alias_list(r, serverconf->redirects, 1, &status)) != NULL) {        if (ap_is_HTTP_REDIRECT(status)) {            /* include QUERY_STRING if any */            if (r->args) {                ret = apr_pstrcat(r->pool, ret, "?", r->args, NULL);            }            apr_table_setn(r->headers_out, "Location", ret);        }        return status;    }    if ((ret = try_alias_list(r, serverconf->aliases, 0, &status)) != NULL) {        r->filename = ret;        return OK;    }    return DECLINED;}static int fixup_redir(request_rec *r){    void *dconf = r->per_dir_config;    alias_dir_conf *dirconf =    (alias_dir_conf *) ap_get_module_config(dconf, &alias_module);    char *ret;    int status;    /* It may have changed since last time, so try again */    if ((ret = try_alias_list(r, dirconf->redirects, 1, &status)) != NULL) {        if (ap_is_HTTP_REDIRECT(status)) {            if (ret[0] == '/') {                char *orig_target = ret;                ret = ap_construct_url(r->pool, ret, r);                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,                              "incomplete redirection target of '%s' for "                              "URI '%s' modified to '%s'",                              orig_target, r->uri, ret);            }            if (!ap_is_url(ret)) {                status = HTTP_INTERNAL_SERVER_ERROR;                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                              "cannot redirect '%s' to '%s'; "                              "target is not a valid absoluteURI or abs_path",                              r->uri, ret);            }            else {                /* append requested query only, if the config didn't                 * supply its own.                 */                if (r->args && !ap_strchr(ret, '?')) {                    ret = apr_pstrcat(r->pool, ret, "?", r->args, NULL);                }                apr_table_setn(r->headers_out, "Location", ret);            }        }        return status;    }    return DECLINED;}static void register_hooks(apr_pool_t *p){    static const char * const aszSucc[]={ "mod_userdir.c",                                          "mod_vhost_alias.c",NULL };    ap_hook_translate_name(translate_alias_redir,NULL,aszSucc,APR_HOOK_MIDDLE);    ap_hook_fixups(fixup_redir,NULL,NULL,APR_HOOK_MIDDLE);}module AP_MODULE_DECLARE_DATA alias_module ={    STANDARD20_MODULE_STUFF,    create_alias_dir_config,       /* dir config creater */    merge_alias_dir_config,        /* dir merger --- default is to override */    create_alias_config,           /* server config */    merge_alias_config,            /* merge server configs */    alias_cmds,                    /* command apr_table_t */    register_hooks                 /* register hooks */};

⌨️ 快捷键说明

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