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

📄 core.c

📁 Apache HTTP Server 是一个功能强大的灵活的与HTTP/1.1相兼容的web服务器.这里给出的是Apache HTTP服务器的源码。
💻 C
📖 第 1 页 / 共 5 页
字号:
                ap_str_tolower(conn->local_host);            }        }        return conn->local_host;    }    /* default */    return r->server->server_hostname;}/* * Get the current server name from the request for the purposes * of using in a URL.  If the server name is an IPv6 literal * address, it will be returned in URL format (e.g., "[fe80::1]"). */static const char *get_server_name_for_url(request_rec *r){    const char *plain_server_name = ap_get_server_name(r);#if APR_HAVE_IPV6    if (ap_strchr_c(plain_server_name, ':')) { /* IPv6 literal? */        return apr_psprintf(r->pool, "[%s]", plain_server_name);    }#endif    return plain_server_name;}AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r){    apr_port_t port;    core_dir_config *d =      (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);    if (d->use_canonical_name == USE_CANONICAL_NAME_OFF        || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {        /* With UseCanonicalName off Apache will form self-referential         * URLs using the hostname and port supplied by the client if         * any are supplied (otherwise it will use the canonical name).         */        port = r->parsed_uri.port_str ? r->parsed_uri.port :               r->server->port ? r->server->port :               ap_default_port(r);    }    else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */        /* With UseCanonicalName on (and in all versions prior to 1.3)         * Apache will use the hostname and port specified in the         * ServerName directive to construct a canonical name for the         * server. (If no port was specified in the ServerName         * directive, Apache uses the port supplied by the client if         * any is supplied, and finally the default port for the protocol         * used.         */        port = r->server->port ? r->server->port :               r->connection->local_addr->port ? r->connection->local_addr->port :               ap_default_port(r);    }    /* default */    return port;}AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri,                                    request_rec *r){    unsigned port = ap_get_server_port(r);    const char *host = get_server_name_for_url(r);    if (ap_is_default_port(port, r)) {        return apr_pstrcat(p, ap_http_method(r), "://", host, uri, NULL);    }    return apr_psprintf(p, "%s://%s:%u%s", ap_http_method(r), host, port, uri);}AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r){    core_dir_config *d =      (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);    if (d->limit_req_body == AP_LIMIT_REQ_BODY_UNSET) {        return AP_DEFAULT_LIMIT_REQ_BODY;    }    return d->limit_req_body;}/***************************************************************** * * Commands... this module handles almost all of the NCSA httpd.conf * commands, but most of the old srm.conf is in the the modules. *//* returns a parent if it matches the given directive */static const ap_directive_t * find_parent(const ap_directive_t *dirp,                                          const char *what){    while (dirp->parent != NULL) {        dirp = dirp->parent;        /* ### it would be nice to have atom-ized directives */        if (strcasecmp(dirp->directive, what) == 0)            return dirp;    }    return NULL;}AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd,                                              unsigned forbidden){    const char *gt = (cmd->cmd->name[0] == '<'                      && cmd->cmd->name[strlen(cmd->cmd->name)-1] != '>')                         ? ">" : "";    const ap_directive_t *found;    if ((forbidden & NOT_IN_VIRTUALHOST) && cmd->server->is_virtual) {        return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,                           " cannot occur within <VirtualHost> section", NULL);    }    if ((forbidden & NOT_IN_LIMIT) && cmd->limited != -1) {        return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,                           " cannot occur within <Limit> section", NULL);    }    if ((forbidden & NOT_IN_DIR_LOC_FILE) == NOT_IN_DIR_LOC_FILE) {        if (cmd->path != NULL) {            return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,                            " cannot occur within <Directory/Location/Files> "                            "section", NULL);        }        if (cmd->cmd->req_override & EXEC_ON_READ) {            /* EXEC_ON_READ must be NOT_IN_DIR_LOC_FILE, if not, it will             * (deliberately) segfault below in the individual tests...             */            return NULL;        }    }        if (((forbidden & NOT_IN_DIRECTORY)         && ((found = find_parent(cmd->directive, "<Directory"))             || (found = find_parent(cmd->directive, "<DirectoryMatch"))))        || ((forbidden & NOT_IN_LOCATION)            && ((found = find_parent(cmd->directive, "<Location"))                || (found = find_parent(cmd->directive, "<LocationMatch"))))        || ((forbidden & NOT_IN_FILES)            && ((found = find_parent(cmd->directive, "<Files"))                || (found = find_parent(cmd->directive, "<FilesMatch"))))) {        return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,                           " cannot occur within ", found->directive,                           "> section", NULL);    }    return NULL;}static const char *set_access_name(cmd_parms *cmd, void *dummy,                                   const char *arg){    void *sconf = cmd->server->module_config;    core_server_config *conf = ap_get_module_config(sconf, &core_module);    const char *err = ap_check_cmd_context(cmd,                                           NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    conf->access_name = apr_pstrdup(cmd->pool, arg);    return NULL;}#ifdef GPROFstatic const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg){    void *sconf = cmd->server->module_config;    core_server_config *conf = ap_get_module_config(sconf, &core_module);    const char *err = ap_check_cmd_context(cmd,                                           NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    conf->gprof_dir = apr_pstrdup(cmd->pool, arg);    return NULL;}#endif /*GPROF*/static const char *set_add_default_charset(cmd_parms *cmd,                                           void *d_, const char *arg){    core_dir_config *d = d_;    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    if (!strcasecmp(arg, "Off")) {       d->add_default_charset = ADD_DEFAULT_CHARSET_OFF;    }    else if (!strcasecmp(arg, "On")) {       d->add_default_charset = ADD_DEFAULT_CHARSET_ON;       d->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;    }    else {       d->add_default_charset = ADD_DEFAULT_CHARSET_ON;       d->add_default_charset_name = arg;    }    return NULL;}static const char *set_document_root(cmd_parms *cmd, void *dummy,                                     const char *arg){    void *sconf = cmd->server->module_config;    core_server_config *conf = ap_get_module_config(sconf, &core_module);    const char *err = ap_check_cmd_context(cmd,                                           NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    /* TODO: ap_configtestonly && ap_docrootcheck && */    /* XXX Shouldn't this be relative to ServerRoot ??? */    if (apr_filepath_merge((char**)&conf->ap_document_root, NULL, arg,                           APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS        || !ap_is_directory(cmd->pool, arg)) {        if (cmd->server->is_virtual) {            ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0,                          cmd->pool,                          "Warning: DocumentRoot [%s] does not exist",                          arg);            conf->ap_document_root = arg;        }        else {            return "DocumentRoot must be a directory";        }    }    return NULL;}AP_DECLARE(void) ap_custom_response(request_rec *r, int status,                                    const char *string){    core_request_config *conf =        ap_get_module_config(r->request_config, &core_module);    int idx;    if (conf->response_code_strings == NULL) {        conf->response_code_strings =            apr_pcalloc(r->pool,                        sizeof(*conf->response_code_strings) * RESPONSE_CODES);    }    idx = ap_index_of_response(status);    conf->response_code_strings[idx] =       ((ap_is_url(string) || (*string == '/')) && (*string != '"')) ?       apr_pstrdup(r->pool, string) : apr_pstrcat(r->pool, "\"", string, NULL);}static const char *set_error_document(cmd_parms *cmd, void *conf_,                                      const char *errno_str, const char *msg){    core_dir_config *conf = conf_;    int error_number, index_number, idx500;    enum { MSG, LOCAL_PATH, REMOTE_PATH } what = MSG;    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    /* 1st parameter should be a 3 digit number, which we recognize;     * convert it into an array index     */    error_number = atoi(errno_str);    idx500 = ap_index_of_response(HTTP_INTERNAL_SERVER_ERROR);    if (error_number == HTTP_INTERNAL_SERVER_ERROR) {        index_number = idx500;    }    else if ((index_number = ap_index_of_response(error_number)) == idx500) {        return apr_pstrcat(cmd->pool, "Unsupported HTTP response code ",                           errno_str, NULL);    }    /* Heuristic to determine second argument. */    if (ap_strchr_c(msg,' '))        what = MSG;    else if (msg[0] == '/')        what = LOCAL_PATH;    else if (ap_is_url(msg))        what = REMOTE_PATH;    else        what = MSG;    /* The entry should be ignored if it is a full URL for a 401 error */    if (error_number == 401 && what == REMOTE_PATH) {        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server,                     "cannot use a full URL in a 401 ErrorDocument "                     "directive --- ignoring!");    }    else { /* Store it... */        if (conf->response_code_strings == NULL) {            conf->response_code_strings =                apr_pcalloc(cmd->pool,                            sizeof(*conf->response_code_strings) *                            RESPONSE_CODES);        }        if (strcmp(msg, "default") == 0) {            /* special case: ErrorDocument 404 default restores the             * canned server error response             */            conf->response_code_strings[index_number] = &errordocument_default;        }        else {            /* hack. Prefix a " if it is a msg; as that is what             * http_protocol.c relies on to distinguish between             * a msg and a (local) path.             */            conf->response_code_strings[index_number] = (what == MSG) ?                    apr_pstrcat(cmd->pool, "\"",msg,NULL) :                    apr_pstrdup(cmd->pool, msg);        }    }    return NULL;}static const char *set_override(cmd_parms *cmd, void *d_, const char *l){    core_dir_config *d = d_;    char *w;    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);    if (err != NULL) {        return err;    }    d->override = OR_NONE;    while (l[0]) {        w = ap_getword_conf(cmd->pool, &l);        if (!strcasecmp(w, "Limit")) {            d->override |= OR_LIMIT;        }        else if (!strcasecmp(w, "Options")) {            d->override |= OR_OPTIONS;        }        else if (!strcasecmp(w, "FileInfo")) {            d->override |= OR_FILEINFO;        }        else if (!strcasecmp(w, "AuthConfig")) {            d->override |= OR_AUTHCFG;        }        else if (!strcasecmp(w, "Indexes")) {            d->override |= OR_INDEXES;        }        else if (!strcasecmp(w, "None")) {            d->override = OR_NONE;        }        else if (!strcasecmp(w, "All")) {            d->override = OR_ALL;        }        else {            return apr_pstrcat(cmd->pool, "Illegal override option ", w, NULL);        }        d->override &= ~OR_UNSET;    }    return NULL;}static const char *set_options(cmd_parms *cmd, void *d_, const char *l){    core_dir_config *d = d_;    allow_options_t opt;    int first = 1;    char action;    while (l[0]) {        char *w = ap_getword_conf(cmd->pool, &l);        action = '\0';        if (*w == '+' || *w == '-') {            action = *(w++);        }        else if (first) {              d->opts = OPT_NONE;            first = 0;        }        if (!strcasecmp(w, "Indexes")) {            opt = OPT_INDEXES;        }        else if (!strcasecmp(w, "Includes")) {            opt = OPT_INCLUDES;        }        else if (!strcasecmp(w, "IncludesNOEXEC")) {            opt = (OPT_INCLUDES | OPT_INCNOEXEC);        }        else if (!strcasecmp(w, "FollowSymLinks")) {            opt = OPT_SYM_LINKS;        }        else if (!strcasecmp(w, "SymLinksIfOwnerMatch")) {            opt = OPT_SYM_OWNER;        }        else if (!strcasecmp(w, "execCGI")) {            opt = OPT_EXECCGI;        }        else if (!strcasecmp(w, "MultiViews")) {            opt = OPT_MULTI;        }        else if (!strcasecmp(w, "RunScripts")) { /* AI backcompat. Yuck */            opt = OPT_MULTI|OPT_EXECCGI;        }        else if (!strcasecmp(w, "None")) {            opt = OPT_NONE;        }        else if (!strcasecmp(w, "All")) {            opt = OPT_ALL;        }        else {            return apr_pstrcat(cmd->pool, "Illegal option ", w, NULL);        }        /* we ensure the invariant (d->opts_add & d->opts_remove) == 0 */        if (action == '-') {            d->opts_remove |= opt;            d->opts_add &= ~opt;            d->opts &= ~opt;        }        else if (action == '+') {

⌨️ 快捷键说明

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