aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_voicemail.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-05 01:34:34 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-05 01:34:34 +0000
commit7865b11fb6fce9e3c1ef6fcc96dd1fb676c75016 (patch)
tree217f5ce520831ea1d2be39195555bfae7d36ca4a /apps/app_voicemail.c
parent7c295196556a30173fef15bd9796020c2394a81f (diff)
Merged revisions 48251 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2 ........ r48251 | tilghman | 2006-12-04 19:26:08 -0600 (Mon, 04 Dec 2006) | 6 lines If the recording in the database is too large, it will fail to retrieve with an mmap error. Not too sure why this doesn't happen when we put it in the database, also, but since that doesn't seem to be broken, I'm not going to fix it (at least until someone reports it). Solution is to ask for the file in smaller chunks. (Bug 8385) ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@48252 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_voicemail.c')
-rw-r--r--apps/app_voicemail.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 336c63ac4..b9c478e8d 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -142,6 +142,7 @@ static struct vmstate *vmstates = NULL;
/* Don't modify these here; set your umask at runtime instead */
#define VOICEMAIL_DIR_MODE 0777
#define VOICEMAIL_FILE_MODE 0666
+#define CHUNKSIZE 65536
#define VOICEMAIL_CONFIG "voicemail.conf"
#define ASTERISK_USERNAME "asterisk"
@@ -1088,6 +1089,7 @@ static int retrieve_file(char *dir, int msgnum)
goto yuck;
}
if (!strcasecmp(coltitle, "recording")) {
+ off_t offset;
res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize2);
fdlen = colsize2;
if (fd > -1) {
@@ -1098,24 +1100,26 @@ static int retrieve_file(char *dir, int msgnum)
fd = -1;
continue;
}
- if (fd > -1) {
- if ((fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == -1) {
+ /* Read out in small chunks */
+ for (offset = 0; offset < colsize2; offset += CHUNKSIZE) {
+ /* +1 because SQLGetData likes null-terminating binary data */
+ if ((fdm = mmap(NULL, CHUNKSIZE + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == (void *)-1) {
ast_log(LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
ast_odbc_release_obj(obj);
goto yuck;
+ } else {
+ res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE + 1, NULL);
+ munmap(fdm, 0);
+ if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+ ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
+ unlink(full_fn);
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ goto yuck;
+ }
}
}
- }
- if (fdm) {
- memset(fdm, 0, fdlen);
- res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize2);
- if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
- SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- ast_odbc_release_obj(obj);
- goto yuck;
- }
+ truncate(full_fn, fdlen);
}
} else {
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
@@ -1136,8 +1140,6 @@ static int retrieve_file(char *dir, int msgnum)
yuck:
if (f)
fclose(f);
- if (fdm)
- munmap(fdm, fdlen);
if (fd > -1)
close(fd);
return x - 1;