diff options
author | Jenkins2 <jenkins2@gerrit.asterisk.org> | 2018-05-03 10:50:51 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2018-05-03 10:50:51 -0500 |
commit | 0565a6c909dff12f02838e23e3984463cbd7da70 (patch) | |
tree | 3f28d4ba1756834371e6aadb497978577ef4a591 /main/file.c | |
parent | e538fc8e86bece8b562cc678ab2c4bcf3978d8e6 (diff) | |
parent | 0827d5cc53c2609231c4ef9bc92f321f258c4af2 (diff) |
Merge "Add the ability to read the media file type from HTTP header for playback"
Diffstat (limited to 'main/file.c')
-rw-r--r-- | main/file.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/main/file.c b/main/file.c index 8dded8123..3ee58b168 100644 --- a/main/file.c +++ b/main/file.c @@ -333,20 +333,21 @@ static char *build_filename(const char *filename, const char *ext) /* compare type against the list 'exts' */ /* XXX need a better algorithm */ -static int exts_compare(const char *exts, const char *type) +static int type_in_list(const char *list, const char *type, int (*cmp)(const char *s1, const char *s2)) { - char tmp[256]; - char *stringp = tmp, *ext; + char *stringp = ast_strdupa(list), *item; - ast_copy_string(tmp, exts, sizeof(tmp)); - while ((ext = strsep(&stringp, "|"))) { - if (!strcmp(ext, type)) + while ((item = strsep(&stringp, "|"))) { + if (!cmp(item, type)) { return 1; + } } return 0; } +#define exts_compare(list, type) (type_in_list((list), (type), strcmp)) + /*! * \internal * \brief Close the file stream by canceling any pending read / write callbacks @@ -1926,6 +1927,27 @@ struct ast_format *ast_get_format_for_file_ext(const char *file_ext) return NULL; } +int ast_get_extension_for_mime_type(const char *mime_type, char *buffer, size_t capacity) +{ + struct ast_format_def *f; + SCOPED_RDLOCK(lock, &formats.lock); + + ast_assert(buffer && capacity); + + AST_RWLIST_TRAVERSE(&formats, f, list) { + if (type_in_list(f->mime_types, mime_type, strcasecmp)) { + size_t item_len = strcspn(f->exts, "|"); + size_t bytes_written = snprintf(buffer, capacity, ".%.*s", (int) item_len, f->exts); + if (bytes_written < capacity) { + /* Only return success if we didn't truncate */ + return 1; + } + } + } + + return 0; +} + static struct ast_cli_entry cli_file[] = { AST_CLI_DEFINE(handle_cli_core_show_file_formats, "Displays file formats") }; |