[asterisk-commits] qwell: branch 1.6.0 r106440 - in /branches/1.6.0: ./ main/file.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Mar 6 16:15:04 CST 2008
Author: qwell
Date: Thu Mar 6 16:15:03 2008
New Revision: 106440
URL: http://svn.digium.com/view/asterisk?view=rev&rev=106440
Log:
Merged revisions 106439 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r106439 | qwell | 2008-03-06 16:11:30 -0600 (Thu, 06 Mar 2008) | 8 lines
Fix file playback in many cases.
(closes issue #12115)
Reported by: pj
Patches:
v2-fileexists.patch uploaded by dimas (license 88) (with modifications by me)
Tested by: dimas, qwell, russell
........
Modified:
branches/1.6.0/ (props changed)
branches/1.6.0/main/file.c
Propchange: branches/1.6.0/
------------------------------------------------------------------------------
--- trunk-merged (original)
+++ trunk-merged Thu Mar 6 16:15:03 2008
@@ -1,1 +1,1 @@
-/trunk:1-105595,105675,105677,105733-105734,105773,105785,105804,105840-105841,105864,105899,105933,106036,106040,106139,106186,106238-106239,106329,106346,106399
+/trunk:1-105595,105675,105677,105733-105734,105773,105785,105804,105840-105841,105864,105899,105933,106036,106040,106139,106186,106238-106239,106329,106346,106399,106439
Modified: branches/1.6.0/main/file.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/file.c?view=diff&rev=106440&r1=106439&r2=106440
==============================================================================
--- branches/1.6.0/main/file.c (original)
+++ branches/1.6.0/main/file.c Thu Mar 6 16:15:03 2008
@@ -455,6 +455,37 @@
return res;
}
+static int is_absolute_path(const char *filename)
+{
+ return filename[0] == '/';
+}
+
+static int fileexists_test(const char *filename, const char *fmt, const char *lang,
+ char *buf, int buflen)
+{
+ if (buf == NULL) {
+ return -1;
+ }
+
+ if (ast_language_is_prefix) { /* new layout */
+ if (lang) {
+ snprintf(buf, buflen, "%s/%s", lang, filename);
+ } else {
+ snprintf(buf, buflen, "%s", filename);
+ }
+ } else { /* old layout */
+ strcpy(buf, filename); /* first copy the full string */
+ if (lang) {
+ /* insert the language and suffix if needed */
+ const char *c = strrchr(filename, '/');
+ int offset = c ? c - filename + 1 : 0; /* points right after the last '/' */
+ snprintf(buf + offset, buflen - offset, "%s/%s", lang, filename + offset);
+ }
+ }
+
+ return ast_filehelper(buf, NULL, fmt, ACTION_EXISTS);
+}
+
/*!
* \brief helper routine to locate a file with a given format
* and language preference.
@@ -470,57 +501,56 @@
char *buf, int buflen)
{
int res = -1;
- int langlen; /* length of language string */
- const char *c = strrchr(filename, '/');
- int offset = c ? c - filename + 1 : 0; /* points right after the last '/' */
-
- if (preflang == NULL) {
- preflang = "";
- }
- langlen = strlen(preflang);
-
- if (buflen < langlen + strlen(filename) + 4) {
- ast_log(LOG_WARNING, "buffer too small, allocating larger buffer\n");
- buf = alloca(langlen + strlen(filename) + 4); /* room for everything */
- }
+ char *lang = NULL;
if (buf == NULL) {
- return 0;
- }
-
- for (;;) {
- if (ast_language_is_prefix) { /* new layout */
- if (langlen) {
- strcpy(buf, preflang);
- buf[langlen] = '/';
- strcpy(buf + langlen + 1, filename);
- } else {
- strcpy(buf, "en/"); /* English - fallback if no file found in preferred language */
- strcpy(buf + 3, filename);
+ return -1;
+ }
+
+ if (is_absolute_path(filename)) {
+ ast_copy_string(buf, filename, buflen);
+ return ast_filehelper(buf, NULL, fmt, ACTION_EXISTS);
+ }
+
+ /* We try languages in the following order:
+ * preflang (may include dialect)
+ * lang (preflang without dialect - if any)
+ * <none>
+ * default (unless the same as preflang or lang without dialect)
+ */
+
+ /* Try preferred language */
+ if (!ast_strlen_zero(preflang)) {
+ /* try the preflang exactly as it was requested */
+ if ((res = fileexists_test(filename, fmt, preflang, buf, buflen)) > 0) {
+ return res;
+ } else {
+ /* try without a dialect */
+ char *postfix = NULL;
+ postfix = lang = ast_strdupa(preflang);
+
+ strsep(&postfix, "_");
+ if (postfix) {
+ if ((res = fileexists_test(filename, fmt, lang, buf, buflen)) > 0) {
+ return res;
+ }
}
- } else { /* old layout */
- strcpy(buf, filename); /* first copy the full string */
- if (langlen) {
- /* insert the language and suffix if needed */
- strcpy(buf + offset, preflang);
- sprintf(buf + offset + langlen, "/%s", filename + offset);
- }
- }
- res = ast_filehelper(buf, NULL, fmt, ACTION_EXISTS);
- if (res > 0) { /* found format */
- break;
- }
- if (langlen == 0) { /* no more formats */
- break;
- }
- if (preflang[langlen] == '_') { /* we are on the local suffix */
- langlen = 0; /* try again with no language */
- } else {
- langlen = (c = strchr(preflang, '_')) ? c - preflang : 0;
- }
- }
-
- return res;
+ }
+ }
+
+ /* Try without any language */
+ if ((res = fileexists_test(filename, fmt, NULL, buf, buflen)) > 0) {
+ return res;
+ }
+
+ /* Finally try the default language unless it was already tried before */
+ if ((ast_strlen_zero(preflang) || strcmp(preflang, DEFAULT_LANGUAGE)) && (ast_strlen_zero(lang) || strcmp(lang, DEFAULT_LANGUAGE))) {
+ if ((res = fileexists_test(filename, fmt, DEFAULT_LANGUAGE, buf, buflen)) > 0) {
+ return res;
+ }
+ }
+
+ return 0;
}
struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
More information about the asterisk-commits
mailing list