[asterisk-commits] ivaxer: branch ivaxer/ast_storage r275550 - /team/ivaxer/ast_storage/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 11 18:38:25 CDT 2010


Author: ivaxer
Date: Sun Jul 11 18:38:22 2010
New Revision: 275550

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=275550
Log:
implemented downloading process in the get() function of the odbc storage backend

Modified:
    team/ivaxer/ast_storage/res/res_storage_odbc.c

Modified: team/ivaxer/ast_storage/res/res_storage_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/res/res_storage_odbc.c?view=diff&rev=275550&r1=275549&r2=275550
==============================================================================
--- team/ivaxer/ast_storage/res/res_storage_odbc.c (original)
+++ team/ivaxer/ast_storage/res/res_storage_odbc.c Sun Jul 11 18:38:22 2010
@@ -250,13 +250,55 @@
 			goto error;
 		}
 		if(!strcasecmp(coltitle, "recording")) {
+			size_t ndata;
+			off_t offset;
+			void *fdm;
+			int chunksize = 0x4000000; /* Try 64MB chunks initially */
+
 			fd = mkstemp(tmpfile_fmt);
 			if (fd == -1) {
 				ast_log(LOG_WARNING, "Could not create temp file");
 				goto error;
 			}
 
-			/* TODO: Downloading */
+			ast_copy_string(fi->localfile, tmpfile_fmt, sizeof(fi->localfile));
+
+			ret = SQLGetData(stmt, colid, SQL_BINARY, NULL, 0, (SQLLEN *)&ndata);
+
+			lseek(fd, ndata - 1, SEEK_SET);
+			if (write(fd, "", 1) != 1) {
+				close(fd);
+				fd = -1;
+				ast_log(LOG_WARNING, "Unable to write '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+				goto error;
+			}
+
+			for (offset = 0; offset < ndata; offset += chunksize) {
+				if ((fdm = mmap(NULL, chunksize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == MAP_FAILED) {
+					chunksize >>= 1;
+					offset -= chunksize;
+
+					if (chunksize < 2048) {
+						ast_log(LOG_WARNING, "Could not mmap the output file: [%d] %s\n", errno, strerror(errno));
+						goto error;
+					}
+
+					continue;
+				} else {
+					ret = SQLGetData(stmt, colid, SQL_BINARY, fdm, chunksize, NULL);
+					munmap(fdm, chunksize);
+					if (!SQL_SUCCEEDED(ret)) {
+						ast_log(LOG_WARNING, "SQL Get Data error!\n");
+						goto error;
+					}
+				}
+			}
+
+			fsync(fd);
+
+			if (truncate(fi->localfile, ndata) < 0) {
+				ast_log(LOG_WARNING, "Unable to truncate '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+			}
 
 			ast_copy_string(fi->localfile, tmpfile_fmt, sizeof(fi->localfile));
 		}




More information about the asterisk-commits mailing list