FS-7496 Updated mime.types, added switch_core_mime_type2ext function and used it in mod_httapi. Now, file extensions defined in mime.types will be applied if mod_httapi downloads a file without one.

This commit is contained in:
Chris Rienzo 2015-04-30 14:24:41 -04:00
parent 518d74a4bc
commit b28f7acac1
9 changed files with 5724 additions and 2584 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -222,6 +222,7 @@ struct switch_runtime {
int64_t offset;
switch_event_t *global_vars;
switch_hash_t *mime_types;
switch_hash_t *mime_type_exts;
switch_hash_t *ptimes;
switch_memory_pool_t *memory_pool;
const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS];

View File

@ -2278,6 +2278,7 @@ SWITCH_DECLARE(uint8_t) switch_core_session_compare(switch_core_session_t *a, sw
SWITCH_DECLARE(uint8_t) switch_core_session_check_interface(switch_core_session_t *session, const switch_endpoint_interface_t *endpoint_interface);
SWITCH_DECLARE(switch_hash_index_t *) switch_core_mime_index(void);
SWITCH_DECLARE(const char *) switch_core_mime_ext2type(const char *ext);
SWITCH_DECLARE(const char *) switch_core_mime_type2ext(const char *type);
SWITCH_DECLARE(switch_status_t) switch_core_mime_add_type(const char *type, const char *ext);
SWITCH_DECLARE(switch_loadable_module_interface_t *) switch_loadable_module_create_module_interface(switch_memory_pool_t *pool, const char *name);

View File

@ -2780,12 +2780,7 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
}
if (zstr(ext) && headers && (ct = switch_event_get_header(headers, "content-type"))) {
if (switch_strcasecmp_any(ct, "audio/mpeg", "audio/x-mpeg", "audio/mp3", "audio/x-mp3", "audio/mpeg3",
"audio/x-mpeg3", "audio/mpg", "audio/x-mpg", "audio/x-mpegaudio", NULL)) {
newext = "mp3";
} else if (switch_strcasecmp_any(ct, "audio/x-wav", "audio/x-wave", "audio/wav", "audio/wave", NULL)) {
newext = "wav";
}
newext = switch_core_mime_type2ext(ct);
}
if (newext) {

View File

@ -1076,6 +1076,13 @@ SWITCH_DECLARE(const char *) switch_core_mime_ext2type(const char *ext)
return (const char *) switch_core_hash_find(runtime.mime_types, ext);
}
SWITCH_DECLARE(const char *) switch_core_mime_type2ext(const char *mime)
{
if (!mime) {
return NULL;
}
return (const char *) switch_core_hash_find(runtime.mime_type_exts, mime);
}
SWITCH_DECLARE(switch_hash_index_t *) switch_core_mime_index(void)
{
@ -1084,37 +1091,41 @@ SWITCH_DECLARE(switch_hash_index_t *) switch_core_mime_index(void)
SWITCH_DECLARE(switch_status_t) switch_core_mime_add_type(const char *type, const char *ext)
{
const char *check;
char *ptype = NULL;
char *ext_list = NULL;
int argc = 0;
char *argv[20] = { 0 };
int x;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(type);
switch_assert(ext);
check = (const char *) switch_core_hash_find(runtime.mime_types, ext);
ptype = switch_core_permanent_strdup(type);
ext_list = strdup(ext);
if (!check) {
char *ptype = switch_core_permanent_strdup(type);
char *ext_list = strdup(ext);
int argc = 0;
char *argv[20] = { 0 };
int x;
switch_assert(ext_list);
switch_assert(ext_list);
if ((argc = switch_separate_string(ext_list, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
for (x = 0; x < argc; x++) {
if (argv[x] && ptype) {
/* Map each file extension to this MIME type if not already mapped. Map the MIME type to the first file extension in the list if not already mapped. */
if ((argc = switch_separate_string(ext_list, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
int is_mapped_type = switch_core_hash_find(runtime.mime_type_exts, ptype) != NULL;
for (x = 0; x < argc; x++) {
if (argv[x] && ptype) {
if (!switch_core_hash_find(runtime.mime_types, ext)) {
switch_core_hash_insert(runtime.mime_types, argv[x], ptype);
}
if (!is_mapped_type) {
switch_core_hash_insert(runtime.mime_type_exts, ptype, switch_core_permanent_strdup(argv[x]));
is_mapped_type = 1;
}
}
status = SWITCH_STATUS_SUCCESS;
}
free(ext_list);
status = SWITCH_STATUS_SUCCESS;
}
free(ext_list);
return status;
}
@ -1719,7 +1730,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
switch_core_set_globals();
switch_core_session_init(runtime.memory_pool);
switch_event_create_plain(&runtime.global_vars, SWITCH_EVENT_CHANNEL_DATA);
switch_core_hash_init(&runtime.mime_types);
switch_core_hash_init_case(&runtime.mime_types, SWITCH_FALSE);
switch_core_hash_init_case(&runtime.mime_type_exts, SWITCH_FALSE);
switch_core_hash_init_case(&runtime.ptimes, SWITCH_FALSE);
load_mime_types();
runtime.flags |= flags;
@ -2748,6 +2760,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
switch_event_destroy(&runtime.global_vars);
switch_core_hash_destroy(&runtime.ptimes);
switch_core_hash_destroy(&runtime.mime_types);
switch_core_hash_destroy(&runtime.mime_type_exts);
if (IP_LIST.hash) {
switch_core_hash_destroy(&IP_LIST.hash);