Loading modules/http/mod_mime.c +67 −37 Changes for modules/http/mod_mime.c: 67 added lines, 37 removed lines. Original line number Diff line number Diff line Loading @@ -153,8 +153,7 @@ module AP_MODULE_DECLARE_DATA mime_module; static void *create_mime_dir_config(apr_pool_t *p, char *dummy) { mime_dir_config *new = (mime_dir_config *) apr_palloc(p, sizeof(mime_dir_config)); mime_dir_config *new = apr_palloc(p, sizeof(mime_dir_config)); new->extension_mappings = NULL; new->remove_mappings = NULL; Loading Loading @@ -213,8 +212,7 @@ static void remove_items(apr_pool_t *p, apr_array_header_t *remove, attrib_info *suffix = (attrib_info *) remove->elts; int i; for (i = 0; i < remove->nelts; i++) { extension_info *exinfo = (extension_info*)apr_hash_get(mappings, extension_info *exinfo = apr_hash_get(mappings, suffix[i].name, APR_HASH_KEY_STRING); if (exinfo && *(const char**)((char *)exinfo + suffix[i].offset)) { Loading Loading @@ -283,20 +281,21 @@ static const char *add_extension_info(cmd_parms *cmd, void *m_, ap_str_tolower(value); ap_str_tolower(key); if (*key == '.') if (*key == '.') { ++key; } if (!m->extension_mappings) { m->extension_mappings = apr_hash_make(cmd->pool); exinfo = NULL; } else else { exinfo = (extension_info*)apr_hash_get(m->extension_mappings, key, APR_HASH_KEY_STRING); } if (!exinfo) { exinfo = apr_pcalloc(cmd->pool, sizeof(extension_info)); key = apr_pstrdup(cmd->pool, key); apr_hash_set(m->extension_mappings, key, APR_HASH_KEY_STRING, exinfo); apr_hash_set(m->extension_mappings, key, APR_HASH_KEY_STRING, exinfo); } *(const char**)((char *)exinfo + offset) = value; return NULL; Loading @@ -312,8 +311,9 @@ static const char *remove_extension_info(cmd_parms *cmd, void *m_, { mime_dir_config *m = (mime_dir_config *) m_; attrib_info *suffix; if (*ext == '.') if (*ext == '.') { ++ext; } if (!m->remove_mappings) { m->remove_mappings = apr_array_make(cmd->pool, 4, sizeof(*suffix)); } Loading Loading @@ -342,31 +342,36 @@ static const char *multiviews_match(cmd_parms *cmd, void *m_, mime_dir_config *m = (mime_dir_config *) m_; if (strcasecmp(include, "Any") == 0) { if (m->multimatch && (m->multimatch & ~MULTIMATCH_ANY)) if (m->multimatch && (m->multimatch & ~MULTIMATCH_ANY)) { return "Any is incompatible with NegotiatedOnly, " "Filters and Handlers"; } m->multimatch |= MULTIMATCH_ANY; } else if (strcasecmp(include, "NegotiatedOnly") == 0) { if (m->multimatch && (m->multimatch & ~MULTIMATCH_NEGOTIATED)) if (m->multimatch && (m->multimatch & ~MULTIMATCH_NEGOTIATED)) { return "Any is incompatible with NegotiatedOnly, " "Filters and Handlers"; } m->multimatch |= MULTIMATCH_NEGOTIATED; } else if (strcasecmp(include, "Filters") == 0) { if (m->multimatch && (m->multimatch & (MULTIMATCH_NEGOTIATED | MULTIMATCH_ANY))) | 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))) | MULTIMATCH_ANY))) { return "Handlers is incompatible with Any and NegotiatedOnly"; } m->multimatch |= MULTIMATCH_HANDLERS; } else else { return "Unrecognized option"; } return NULL; } Loading @@ -375,7 +380,8 @@ static const command_rec mime_cmds[] = { AP_INIT_ITERATE2("AddCharset", add_extension_info, (void *)APR_XtOffsetOf(extension_info, charset_type), OR_FILEINFO, "a charset (e.g., iso-2022-jp), followed by one or more file extensions"), "a charset (e.g., iso-2022-jp), followed by one or more " "file extensions"), AP_INIT_ITERATE2("AddEncoding", add_extension_info, (void *)APR_XtOffsetOf(extension_info, encoding_type), OR_FILEINFO, "an encoding (e.g., gzip), followed by one or more file extensions"), Loading @@ -384,13 +390,15 @@ AP_INIT_ITERATE2("AddHandler", add_extension_info, "a handler name followed by one or more file extensions"), AP_INIT_ITERATE2("AddInputFilter", add_extension_info, (void *)APR_XtOffsetOf(extension_info, input_filters), OR_FILEINFO, "input filter name (or ; delimited names) followed by one or more file extensions"), "input filter name (or ; delimited names) followed by one or " "more file extensions"), AP_INIT_ITERATE2("AddLanguage", add_extension_info, (void *)APR_XtOffsetOf(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_XtOffsetOf(extension_info, output_filters), OR_FILEINFO, "output filter name (or ; delimited names) followed by one or more file extensions"), "output filter name (or ; delimited names) followed by one or " "more file extensions"), AP_INIT_ITERATE2("AddType", add_extension_info, (void *)APR_XtOffsetOf(extension_info, forced_type), OR_FILEINFO, "a mime type followed by one or more file extensions"), Loading Loading @@ -431,17 +439,20 @@ static int mime_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, { ap_configfile_t *f; char l[MAX_STRING_LEN]; const char *types_confname = ap_get_module_config(s->module_config, &mime_module); const char *types_confname = ap_get_module_config(s->module_config, &mime_module); apr_status_t status; if (!types_confname) 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)); (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)) Loading @@ -457,8 +468,9 @@ static int mime_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) { const char *ll = l, *ct; if (l[0] == '#') if (l[0] == '#') { continue; } ct = ap_getword_conf(p, &ll); while (ll[0]) { Loading @@ -481,7 +493,8 @@ static const char *zap_sp(const char *s) } /* skip prefixed white space */ for (; *s == ' ' || *s == '\t' || *s == '\n'; s++); for (; *s == ' ' || *s == '\t' || *s == '\n'; s++) ; return (s); } Loading Loading @@ -765,10 +778,12 @@ static int find_ct(request_rec *r) /* Always drop the path leading up to the file name. */ if ((fn = strrchr(r->filename, '/')) == NULL) if ((fn = strrchr(r->filename, '/')) == NULL) { fn = r->filename; else } else { ++fn; } /* The exception list keeps track of those filename components that * are not associated with extensions indicating metadata. Loading @@ -784,8 +799,9 @@ static int find_ct(request_rec *r) const extension_info *exinfo = NULL; int found; if (*ext == '\0') /* ignore empty extensions "bad..html" */ if (*ext == '\0') { /* ignore empty extensions "bad..html" */ continue; } found = 0; Loading Loading @@ -816,16 +832,18 @@ static int find_ct(request_rec *r) found = 1; } if (exinfo->language_type) { if (!r->content_languages) if (!r->content_languages) { r->content_languages = apr_array_make(r->pool, 2, sizeof(char *)); } *((const char **)apr_array_push(r->content_languages)) = exinfo->language_type; found = 1; } if (exinfo->encoding_type) { if (!r->content_encoding) if (!r->content_encoding) { r->content_encoding = exinfo->encoding_type; } else { /* XXX should eliminate duplicate entities */ r->content_encoding = apr_pstrcat(r->pool, Loading @@ -842,9 +860,10 @@ static int find_ct(request_rec *r) */ if (exinfo->handler && r->proxyreq == PROXYREQ_NONE) { r->handler = exinfo->handler; if (conf->multimatch & MULTIMATCH_HANDLERS) if (conf->multimatch & MULTIMATCH_HANDLERS) { found = 1; } } /* XXX Two significant problems; 1, we don't check to see if we are * setting redundant filters. 2, we insert these in the types config * hook, which may be too early (dunno.) Loading @@ -855,25 +874,29 @@ static int find_ct(request_rec *r) && (filter = ap_getword(r->pool, &filters, ';'))) { ap_add_input_filter(filter, NULL, r, r->connection); } if (conf->multimatch & MULTIMATCH_FILTERS) if (conf->multimatch & MULTIMATCH_FILTERS) { found = 1; } } if (exinfo->output_filters && r->proxyreq == PROXYREQ_NONE) { const char *filter, *filters = exinfo->output_filters; while (*filters && (filter = ap_getword(r->pool, &filters, ';'))) { ap_add_output_filter(filter, NULL, r, r->connection); } if (conf->multimatch & MULTIMATCH_FILTERS) if (conf->multimatch & MULTIMATCH_FILTERS) { found = 1; } } } if (found || (conf->multimatch & MULTIMATCH_ANY)) if (found || (conf->multimatch & MULTIMATCH_ANY)) { found_metadata = 1; else } else { *((const char **) apr_array_push(exception_list)) = ext; } } /* * Need to set a notes entry on r for unrecognized elements. Loading Loading @@ -905,14 +928,19 @@ static int find_ct(request_rec *r) while (pp != NULL) { if (charset && !strcmp(pp->attr, "charset")) { if (!override) { ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, "; charset=", charset, ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, "; charset=", charset, NULL)); override = 1; } } else { ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, "; ", pp->attr, "=", pp->val, NULL)); Loading @@ -934,14 +962,16 @@ static int find_ct(request_rec *r) if (!r->content_languages && conf->default_language) { const char **new; if (!r->content_languages) if (!r->content_languages) { r->content_languages = apr_array_make(r->pool, 2, sizeof(char *)); } new = (const char **)apr_array_push(r->content_languages); *new = conf->default_language; } if (!r->content_type) if (!r->content_type) { return DECLINED; } return OK; } Loading Loading
modules/http/mod_mime.c +67 −37 Changes for modules/http/mod_mime.c: 67 added lines, 37 removed lines. Original line number Diff line number Diff line Loading @@ -153,8 +153,7 @@ module AP_MODULE_DECLARE_DATA mime_module; static void *create_mime_dir_config(apr_pool_t *p, char *dummy) { mime_dir_config *new = (mime_dir_config *) apr_palloc(p, sizeof(mime_dir_config)); mime_dir_config *new = apr_palloc(p, sizeof(mime_dir_config)); new->extension_mappings = NULL; new->remove_mappings = NULL; Loading Loading @@ -213,8 +212,7 @@ static void remove_items(apr_pool_t *p, apr_array_header_t *remove, attrib_info *suffix = (attrib_info *) remove->elts; int i; for (i = 0; i < remove->nelts; i++) { extension_info *exinfo = (extension_info*)apr_hash_get(mappings, extension_info *exinfo = apr_hash_get(mappings, suffix[i].name, APR_HASH_KEY_STRING); if (exinfo && *(const char**)((char *)exinfo + suffix[i].offset)) { Loading Loading @@ -283,20 +281,21 @@ static const char *add_extension_info(cmd_parms *cmd, void *m_, ap_str_tolower(value); ap_str_tolower(key); if (*key == '.') if (*key == '.') { ++key; } if (!m->extension_mappings) { m->extension_mappings = apr_hash_make(cmd->pool); exinfo = NULL; } else else { exinfo = (extension_info*)apr_hash_get(m->extension_mappings, key, APR_HASH_KEY_STRING); } if (!exinfo) { exinfo = apr_pcalloc(cmd->pool, sizeof(extension_info)); key = apr_pstrdup(cmd->pool, key); apr_hash_set(m->extension_mappings, key, APR_HASH_KEY_STRING, exinfo); apr_hash_set(m->extension_mappings, key, APR_HASH_KEY_STRING, exinfo); } *(const char**)((char *)exinfo + offset) = value; return NULL; Loading @@ -312,8 +311,9 @@ static const char *remove_extension_info(cmd_parms *cmd, void *m_, { mime_dir_config *m = (mime_dir_config *) m_; attrib_info *suffix; if (*ext == '.') if (*ext == '.') { ++ext; } if (!m->remove_mappings) { m->remove_mappings = apr_array_make(cmd->pool, 4, sizeof(*suffix)); } Loading Loading @@ -342,31 +342,36 @@ static const char *multiviews_match(cmd_parms *cmd, void *m_, mime_dir_config *m = (mime_dir_config *) m_; if (strcasecmp(include, "Any") == 0) { if (m->multimatch && (m->multimatch & ~MULTIMATCH_ANY)) if (m->multimatch && (m->multimatch & ~MULTIMATCH_ANY)) { return "Any is incompatible with NegotiatedOnly, " "Filters and Handlers"; } m->multimatch |= MULTIMATCH_ANY; } else if (strcasecmp(include, "NegotiatedOnly") == 0) { if (m->multimatch && (m->multimatch & ~MULTIMATCH_NEGOTIATED)) if (m->multimatch && (m->multimatch & ~MULTIMATCH_NEGOTIATED)) { return "Any is incompatible with NegotiatedOnly, " "Filters and Handlers"; } m->multimatch |= MULTIMATCH_NEGOTIATED; } else if (strcasecmp(include, "Filters") == 0) { if (m->multimatch && (m->multimatch & (MULTIMATCH_NEGOTIATED | MULTIMATCH_ANY))) | 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))) | MULTIMATCH_ANY))) { return "Handlers is incompatible with Any and NegotiatedOnly"; } m->multimatch |= MULTIMATCH_HANDLERS; } else else { return "Unrecognized option"; } return NULL; } Loading @@ -375,7 +380,8 @@ static const command_rec mime_cmds[] = { AP_INIT_ITERATE2("AddCharset", add_extension_info, (void *)APR_XtOffsetOf(extension_info, charset_type), OR_FILEINFO, "a charset (e.g., iso-2022-jp), followed by one or more file extensions"), "a charset (e.g., iso-2022-jp), followed by one or more " "file extensions"), AP_INIT_ITERATE2("AddEncoding", add_extension_info, (void *)APR_XtOffsetOf(extension_info, encoding_type), OR_FILEINFO, "an encoding (e.g., gzip), followed by one or more file extensions"), Loading @@ -384,13 +390,15 @@ AP_INIT_ITERATE2("AddHandler", add_extension_info, "a handler name followed by one or more file extensions"), AP_INIT_ITERATE2("AddInputFilter", add_extension_info, (void *)APR_XtOffsetOf(extension_info, input_filters), OR_FILEINFO, "input filter name (or ; delimited names) followed by one or more file extensions"), "input filter name (or ; delimited names) followed by one or " "more file extensions"), AP_INIT_ITERATE2("AddLanguage", add_extension_info, (void *)APR_XtOffsetOf(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_XtOffsetOf(extension_info, output_filters), OR_FILEINFO, "output filter name (or ; delimited names) followed by one or more file extensions"), "output filter name (or ; delimited names) followed by one or " "more file extensions"), AP_INIT_ITERATE2("AddType", add_extension_info, (void *)APR_XtOffsetOf(extension_info, forced_type), OR_FILEINFO, "a mime type followed by one or more file extensions"), Loading Loading @@ -431,17 +439,20 @@ static int mime_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, { ap_configfile_t *f; char l[MAX_STRING_LEN]; const char *types_confname = ap_get_module_config(s->module_config, &mime_module); const char *types_confname = ap_get_module_config(s->module_config, &mime_module); apr_status_t status; if (!types_confname) 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)); (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)) Loading @@ -457,8 +468,9 @@ static int mime_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) { const char *ll = l, *ct; if (l[0] == '#') if (l[0] == '#') { continue; } ct = ap_getword_conf(p, &ll); while (ll[0]) { Loading @@ -481,7 +493,8 @@ static const char *zap_sp(const char *s) } /* skip prefixed white space */ for (; *s == ' ' || *s == '\t' || *s == '\n'; s++); for (; *s == ' ' || *s == '\t' || *s == '\n'; s++) ; return (s); } Loading Loading @@ -765,10 +778,12 @@ static int find_ct(request_rec *r) /* Always drop the path leading up to the file name. */ if ((fn = strrchr(r->filename, '/')) == NULL) if ((fn = strrchr(r->filename, '/')) == NULL) { fn = r->filename; else } else { ++fn; } /* The exception list keeps track of those filename components that * are not associated with extensions indicating metadata. Loading @@ -784,8 +799,9 @@ static int find_ct(request_rec *r) const extension_info *exinfo = NULL; int found; if (*ext == '\0') /* ignore empty extensions "bad..html" */ if (*ext == '\0') { /* ignore empty extensions "bad..html" */ continue; } found = 0; Loading Loading @@ -816,16 +832,18 @@ static int find_ct(request_rec *r) found = 1; } if (exinfo->language_type) { if (!r->content_languages) if (!r->content_languages) { r->content_languages = apr_array_make(r->pool, 2, sizeof(char *)); } *((const char **)apr_array_push(r->content_languages)) = exinfo->language_type; found = 1; } if (exinfo->encoding_type) { if (!r->content_encoding) if (!r->content_encoding) { r->content_encoding = exinfo->encoding_type; } else { /* XXX should eliminate duplicate entities */ r->content_encoding = apr_pstrcat(r->pool, Loading @@ -842,9 +860,10 @@ static int find_ct(request_rec *r) */ if (exinfo->handler && r->proxyreq == PROXYREQ_NONE) { r->handler = exinfo->handler; if (conf->multimatch & MULTIMATCH_HANDLERS) if (conf->multimatch & MULTIMATCH_HANDLERS) { found = 1; } } /* XXX Two significant problems; 1, we don't check to see if we are * setting redundant filters. 2, we insert these in the types config * hook, which may be too early (dunno.) Loading @@ -855,25 +874,29 @@ static int find_ct(request_rec *r) && (filter = ap_getword(r->pool, &filters, ';'))) { ap_add_input_filter(filter, NULL, r, r->connection); } if (conf->multimatch & MULTIMATCH_FILTERS) if (conf->multimatch & MULTIMATCH_FILTERS) { found = 1; } } if (exinfo->output_filters && r->proxyreq == PROXYREQ_NONE) { const char *filter, *filters = exinfo->output_filters; while (*filters && (filter = ap_getword(r->pool, &filters, ';'))) { ap_add_output_filter(filter, NULL, r, r->connection); } if (conf->multimatch & MULTIMATCH_FILTERS) if (conf->multimatch & MULTIMATCH_FILTERS) { found = 1; } } } if (found || (conf->multimatch & MULTIMATCH_ANY)) if (found || (conf->multimatch & MULTIMATCH_ANY)) { found_metadata = 1; else } else { *((const char **) apr_array_push(exception_list)) = ext; } } /* * Need to set a notes entry on r for unrecognized elements. Loading Loading @@ -905,14 +928,19 @@ static int find_ct(request_rec *r) while (pp != NULL) { if (charset && !strcmp(pp->attr, "charset")) { if (!override) { ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, "; charset=", charset, ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, "; charset=", charset, NULL)); override = 1; } } else { ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, ap_set_content_type(r, apr_pstrcat(r->pool, r->content_type, "; ", pp->attr, "=", pp->val, NULL)); Loading @@ -934,14 +962,16 @@ static int find_ct(request_rec *r) if (!r->content_languages && conf->default_language) { const char **new; if (!r->content_languages) if (!r->content_languages) { r->content_languages = apr_array_make(r->pool, 2, sizeof(char *)); } new = (const char **)apr_array_push(r->content_languages); *new = conf->default_language; } if (!r->content_type) if (!r->content_type) { return DECLINED; } return OK; } Loading