📄 mod_mime.c
字号:
| MULTIMATCH_ANY))) { return "Filters is incompatible with Any and NegotiatedOnly"; } m->multimatch |= MULTIMATCH_FILTERS; } else if (strcasecmp(include, "Handlers") == 0) { if (m->multimatch && (m->multimatch & (MULTIMATCH_NEGOTIATED | MULTIMATCH_ANY))) { return "Handlers is incompatible with Any and NegotiatedOnly"; } m->multimatch |= MULTIMATCH_HANDLERS; } else { return apr_psprintf(cmd->pool, "Unrecognized option '%s'", include); } return NULL;}static const command_rec mime_cmds[] ={ AP_INIT_ITERATE2("AddCharset", add_extension_info, (void *)APR_OFFSETOF(extension_info, charset_type), OR_FILEINFO, "a charset (e.g., iso-2022-jp), followed by one or more " "file extensions"), AP_INIT_ITERATE2("AddEncoding", add_extension_info, (void *)APR_OFFSETOF(extension_info, encoding_type), OR_FILEINFO, "an encoding (e.g., gzip), followed by one or more file extensions"), AP_INIT_ITERATE2("AddHandler", add_extension_info, (void *)APR_OFFSETOF(extension_info, handler), OR_FILEINFO, "a handler name followed by one or more file extensions"), AP_INIT_ITERATE2("AddInputFilter", add_extension_info, (void *)APR_OFFSETOF(extension_info, input_filters), OR_FILEINFO, "input filter name (or ; delimited names) followed by one or " "more file extensions"), AP_INIT_ITERATE2("AddLanguage", add_extension_info, (void *)APR_OFFSETOF(extension_info, language_type), OR_FILEINFO, "a language (e.g., fr), followed by one or more file extensions"), AP_INIT_ITERATE2("AddOutputFilter", add_extension_info, (void *)APR_OFFSETOF(extension_info, output_filters), OR_FILEINFO, "output filter name (or ; delimited names) followed by one or " "more file extensions"), AP_INIT_ITERATE2("AddType", add_extension_info, (void *)APR_OFFSETOF(extension_info, forced_type), OR_FILEINFO, "a mime type followed by one or more file extensions"), AP_INIT_TAKE1("DefaultLanguage", ap_set_string_slot, (void*)APR_OFFSETOF(mime_dir_config, default_language), OR_FILEINFO, "language to use for documents with no other language file extension"), AP_INIT_ITERATE("MultiviewsMatch", multiviews_match, NULL, OR_FILEINFO, "NegotiatedOnly (default), Handlers and/or Filters, or Any"), AP_INIT_ITERATE("RemoveCharset", remove_extension_info, (void *)APR_OFFSETOF(extension_info, charset_type), OR_FILEINFO, "one or more file extensions"), AP_INIT_ITERATE("RemoveEncoding", remove_extension_info, (void *)APR_OFFSETOF(extension_info, encoding_type), OR_FILEINFO, "one or more file extensions"), AP_INIT_ITERATE("RemoveHandler", remove_extension_info, (void *)APR_OFFSETOF(extension_info, handler), OR_FILEINFO, "one or more file extensions"), AP_INIT_ITERATE("RemoveInputFilter", remove_extension_info, (void *)APR_OFFSETOF(extension_info, input_filters), OR_FILEINFO, "one or more file extensions"), AP_INIT_ITERATE("RemoveLanguage", remove_extension_info, (void *)APR_OFFSETOF(extension_info, language_type), OR_FILEINFO, "one or more file extensions"), AP_INIT_ITERATE("RemoveOutputFilter", remove_extension_info, (void *)APR_OFFSETOF(extension_info, output_filters), OR_FILEINFO, "one or more file extensions"), AP_INIT_ITERATE("RemoveType", remove_extension_info, (void *)APR_OFFSETOF(extension_info, forced_type), OR_FILEINFO, "one or more file extensions"), AP_INIT_TAKE1("TypesConfig", set_types_config, NULL, RSRC_CONF, "the MIME types config file"), AP_INIT_FLAG("ModMimeUsePathInfo", ap_set_flag_slot, (void *)APR_OFFSETOF(mime_dir_config, use_path_info), ACCESS_CONF, "Set to 'yes' to allow mod_mime to use path info for type checking"), {NULL}};static apr_hash_t *mime_type_extensions;static int mime_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){ ap_configfile_t *f; char l[MAX_STRING_LEN]; const char *types_confname = ap_get_module_config(s->module_config, &mime_module); apr_status_t status; if (!types_confname) { types_confname = AP_TYPES_CONFIG_FILE; } types_confname = ap_server_root_relative(p, types_confname); if (!types_confname) { ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s, "Invalid mime types config path %s", (const char *)ap_get_module_config(s->module_config, &mime_module)); return HTTP_INTERNAL_SERVER_ERROR; } if ((status = ap_pcfg_openfile(&f, ptemp, types_confname)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, status, s, "could not open mime types config file %s.", types_confname); return HTTP_INTERNAL_SERVER_ERROR; } mime_type_extensions = apr_hash_make(p); while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) { const char *ll = l, *ct; if (l[0] == '#') { continue; } ct = ap_getword_conf(p, &ll); while (ll[0]) { char *ext = ap_getword_conf(p, &ll); ap_str_tolower(ext); apr_hash_set(mime_type_extensions, ext, APR_HASH_KEY_STRING, ct); } } ap_cfg_closefile(f); return OK;}static const char *zap_sp(const char *s){ if (s == NULL) { return (NULL); } if (*s == '\0') { return (s); } /* skip prefixed white space */ for (; *s == ' ' || *s == '\t' || *s == '\n'; s++) ; return (s);}static char *zap_sp_and_dup(apr_pool_t *p, const char *start, const char *end, apr_size_t *len){ while ((start < end) && apr_isspace(*start)) { start++; } while ((end > start) && apr_isspace(*(end - 1))) { end--; } if (len) { *len = end - start; } return apr_pstrmemdup(p, start, end - start);}static int is_token(char c){ int res; res = (apr_isascii(c) && apr_isgraph(c) && (strchr(tspecial, c) == NULL)) ? 1 : -1; return res;}static int is_qtext(char c){ int res; res = (apr_isascii(c) && (c != '"') && (c != '\\') && (c != '\n')) ? 1 : -1; return res;}static int is_quoted_pair(const char *s){ int res = -1; int c; if (((s + 1) != NULL) && (*s == '\\')) { c = (int) *(s + 1); if (apr_isascii(c)) { res = 1; } } return (res);}static content_type *analyze_ct(request_rec *r, const char *s){ const char *cp, *mp; char *attribute, *value; int quoted = 0; server_rec * ss = r->server; apr_pool_t * p = r->pool; content_type *ctp; param *pp, *npp; /* initialize ctp */ ctp = (content_type *)apr_palloc(p, sizeof(content_type)); ctp->type = NULL; ctp->subtype = NULL; ctp->param = NULL; mp = s; /* getting a type */ cp = mp; while (apr_isspace(*cp)) { cp++; } if (!*cp) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "mod_mime: analyze_ct: cannot get media type from '%s'", (const char *) mp); return (NULL); } ctp->type = cp; do { cp++; } while (*cp && (*cp != '/') && !apr_isspace(*cp) && (*cp != ';')); if (!*cp || (*cp == ';')) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media type from '%s'", (const char *) mp); return (NULL); } while (apr_isspace(*cp)) { cp++; } if (*cp != '/') { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "mod_mime: analyze_ct: cannot get media type from '%s'", (const char *) mp); return (NULL); } ctp->type_len = cp - ctp->type; cp++; /* skip the '/' */ /* getting a subtype */ while (apr_isspace(*cp)) { cp++; } if (!*cp) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media subtype."); return (NULL); } ctp->subtype = cp; do { cp++; } while (*cp && !apr_isspace(*cp) && (*cp != ';')); ctp->subtype_len = cp - ctp->subtype; while (apr_isspace(*cp)) { cp++; } if (*cp == '\0') { return (ctp); } /* getting parameters */ cp++; /* skip the ';' */ cp = zap_sp(cp); if (cp == NULL || *cp == '\0') { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media parameter."); return (NULL); } mp = cp; attribute = NULL; value = NULL; while (cp != NULL && *cp != '\0') { if (attribute == NULL) { if (is_token(*cp) > 0) { cp++; continue; } else if (*cp == ' ' || *cp == '\t' || *cp == '\n') { cp++; continue; } else if (*cp == '=') { attribute = zap_sp_and_dup(p, mp, cp, NULL); if (attribute == NULL || *attribute == '\0') { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media parameter."); return (NULL); } cp++; cp = zap_sp(cp); if (cp == NULL || *cp == '\0') { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media parameter."); return (NULL); } mp = cp; continue; } else { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss, "Cannot get media parameter."); return (NULL); } } else { if (mp == cp) { if (*cp == '"') { quoted = 1; cp++; } else { quoted = 0; } } if (quoted > 0) { while (quoted && *cp != '\0') { if (is_qtext(*cp) > 0) { cp++; } else if (is_quoted_pair(cp) > 0) { cp += 2; } else if (*cp == '"') {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -