aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-02-27 16:53:06 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-02-27 16:53:06 +0000
commitd01b4b865da562c70a693fd42d7ea0dc52543878 (patch)
tree2f2b8def5b794c1246289b3d658858d04a5dbe50
parentdd7d52f2f08c3159711f4c817682b9f739bddd0f (diff)
fallback to standard English prompts properly when using new prompt directory layout
(closes issue #11831) Reported by: IgorG Patches: fallbacken.v1.diff uploaded by IgorG (license 20) (modified by me to improve code and conform rest of function to coding guidelines) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@104593 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/file.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/main/file.c b/main/file.c
index 15cf7fadd..187209dc6 100644
--- a/main/file.c
+++ b/main/file.c
@@ -487,33 +487,37 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm
* which on success is filled with the matching filename.
*/
static int fileexists_core(const char *filename, const char *fmt, const char *preflang,
- char *buf, int buflen)
+ 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)
+ if (preflang == NULL) {
preflang = "";
+ }
langlen = strlen(preflang);
- if (buflen < langlen + strlen(filename) + 2) {
- ast_log(LOG_WARNING, "buffer too small\n");
- buf[0] = '\0'; /* set to empty */
- buf = alloca(langlen + strlen(filename) + 2); /* room for everything */
+ 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 */
}
- if (buf == NULL)
+
+ if (buf == NULL) {
return 0;
- buf[0] = '\0';
+ }
+
for (;;) {
if (ast_language_is_prefix) { /* new layout */
if (langlen) {
strcpy(buf, preflang);
buf[langlen] = '/';
strcpy(buf + langlen + 1, filename);
- } else
- strcpy(buf, filename); /* first copy the full string */
+ } else {
+ strcpy(buf, "en/"); /* English - fallback if no file found in preferred language */
+ strcpy(buf + 3, filename);
+ }
} else { /* old layout */
strcpy(buf, filename); /* first copy the full string */
if (langlen) {
@@ -523,15 +527,19 @@ static int fileexists_core(const char *filename, const char *fmt, const char *pr
}
}
res = ast_filehelper(buf, NULL, fmt, ACTION_EXISTS);
- if (res > 0) /* found format */
+ if (res > 0) { /* found format */
break;
- if (langlen == 0) /* no more formats */
+ }
+ if (langlen == 0) { /* no more formats */
break;
- if (preflang[langlen] == '_') /* we are on the local suffix */
+ }
+ if (preflang[langlen] == '_') { /* we are on the local suffix */
langlen = 0; /* try again with no language */
- else
+ } else {
langlen = (c = strchr(preflang, '_')) ? c - preflang : 0;
+ }
}
+
return res;
}