From: Allan Nathanson <42244061+Allan-N@users.noreply.github.com> Date: Tue, 18 Mar 2025 23:54:48 +0000 (-0400) Subject: file.c: missing "custom" sound files should not generate warning logs X-Git-Tag: 21.9.0-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ba4e702cd103ad0d5339d9d494484f60bfe15b3;p=thirdparty%2Fasterisk.git file.c: missing "custom" sound files should not generate warning logs With `sounds_search_custom_dir = yes` we first look to see if a sound file is present in the "custom" sound directory before looking in the standard sound directories. We should not be issuing a WARNING log message if a sound cannot be found in the "custom" directory. Resolves: https://github.com/asterisk/asterisk/issues/1170 (cherry picked from commit f24729a48d9a63b5fa4b2966b92551c16900f1a8) --- diff --git a/main/file.c b/main/file.c index 0f29ca82db..039e33b19a 100644 --- a/main/file.c +++ b/main/file.c @@ -787,13 +787,8 @@ static int fileexists_core(const char *filename, const char *fmt, const char *pr return 0; } -struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang) -{ - return ast_openstream_full(chan, filename, preflang, 0); -} - -struct ast_filestream *ast_openstream_full(struct ast_channel *chan, - const char *filename, const char *preflang, int asis) +static struct ast_filestream *openstream_internal(struct ast_channel *chan, + const char *filename, const char *preflang, int asis, int quiet) { /* * Use fileexists_core() to find a file in a compatible @@ -822,7 +817,9 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, if (!fileexists_core(filename, NULL, preflang, buf, buflen, file_fmt_cap) || !ast_format_cap_has_type(file_fmt_cap, AST_MEDIA_TYPE_AUDIO)) { - ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename); + if (!quiet) { + ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename); + } ao2_ref(file_fmt_cap, -1); return NULL; } @@ -845,6 +842,17 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, return NULL; } +struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang) +{ + return openstream_internal(chan, filename, preflang, 0, 0); +} + +struct ast_filestream *ast_openstream_full(struct ast_channel *chan, + const char *filename, const char *preflang, int asis) +{ + return openstream_internal(chan, filename, preflang, asis, 0); +} + struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang) { @@ -1307,7 +1315,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, if (ast_opt_sounds_search_custom && !is_absolute_path(filename)) { memset(custom_filename, 0, sizeof(custom_filename)); snprintf(custom_filename, sizeof(custom_filename), "custom/%s", filename); - fs = ast_openstream(chan, custom_filename, preflang); + fs = openstream_internal(chan, filename, preflang, 0, 1); /* open stream, do not warn for missing files */ if (fs) { tmp_filename = custom_filename; ast_debug(3, "Found file %s in custom directory\n", filename);