[asterisk-commits] ivaxer: branch ivaxer/ast_storage r279385 - in /team/ivaxer/ast_storage: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 25 09:30:05 CDT 2010


Author: ivaxer
Date: Sun Jul 25 09:30:01 2010
New Revision: 279385

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=279385
Log:
metadata handling
- extended fileobject structure
- fixed get/put functions

Modified:
    team/ivaxer/ast_storage/include/asterisk/storage.h
    team/ivaxer/ast_storage/main/storage.c
    team/ivaxer/ast_storage/res/res_storage_odbc.c

Modified: team/ivaxer/ast_storage/include/asterisk/storage.h
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/include/asterisk/storage.h?view=diff&rev=279385&r1=279384&r2=279385
==============================================================================
--- team/ivaxer/ast_storage/include/asterisk/storage.h (original)
+++ team/ivaxer/ast_storage/include/asterisk/storage.h Sun Jul 25 09:30:01 2010
@@ -41,6 +41,7 @@
 struct ast_storage_fileobject {
 	char objectname[256];
 	char pathname[256];
+	struct ast_storage_fileinst *metadata;
 	AST_RWLIST_HEAD(, ast_storage_fileinst) files;
 	AST_RWLIST_ENTRY(ast_storage_fileobject) list;
 };

Modified: team/ivaxer/ast_storage/main/storage.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/main/storage.c?view=diff&rev=279385&r1=279384&r2=279385
==============================================================================
--- team/ivaxer/ast_storage/main/storage.c (original)
+++ team/ivaxer/ast_storage/main/storage.c Sun Jul 25 09:30:01 2010
@@ -212,6 +212,10 @@
 
 	if (!fo) {
 		return;
+	}
+
+	if (fo->metadata) {
+		ast_storage_fileinst_release(fo->metadata);
 	}
 
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&fo->files, inst, list) {

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=279385&r1=279384&r2=279385
==============================================================================
--- team/ivaxer/ast_storage/res/res_storage_odbc.c (original)
+++ team/ivaxer/ast_storage/res/res_storage_odbc.c Sun Jul 25 09:30:01 2010
@@ -79,8 +79,11 @@
 	char *objectname;
 	char *ext;
 	void *data;
+	void *metadata;
 	SQLLEN data_len;
 	SQLLEN data_ind;
+	SQLLEN metadata_len;
+	SQLLEN metadata_ind;
 };
 
 static const struct ast_storage_be odbc_se;
@@ -348,8 +351,11 @@
 
 	SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->pathname), 0, (void *)qdata->pathname, 0, NULL);
 	SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->objectname), 0, (void *)qdata->objectname, 0, NULL);
-	if (qdata->ext)
+	if (qdata->ext) {
 		SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->ext), 0, (void *)qdata->ext, 0, NULL);
+	}
+
+	SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 3, 0, (void *)"txt", 0, NULL);
 
 	return stmt;
 }
@@ -385,7 +391,7 @@
 	pathname = ost->pathname;
 
 	if (exts) {
-		snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE pathname=? AND filename=? AND extension=?", ost->tablename);
+		snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE pathname=? AND filename=? AND (extension=? OR extension=?)", ost->tablename);
 	}
 	else {
 		snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE pathname=? AND filename=?", ost->tablename);
@@ -418,6 +424,11 @@
 			ast_copy_string(fo->pathname, pathname, sizeof(fo->pathname));
 		}
 
+		if (!strcasecmp(fi->ext, "txt")) {
+			fo->metadata = fi;
+			continue;
+		}
+
 		AST_RWLIST_WRLOCK(&fo->files);
 		AST_RWLIST_INSERT_TAIL(&fo->files, fi, list);
 		AST_RWLIST_UNLOCK(&fo->files);
@@ -448,9 +459,13 @@
 	}
 
 	SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->pathname), 0, (void *)qdata->pathname, 0, NULL);
+	SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->pathname), 0, (void *)qdata->pathname, 0, NULL);
 	SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->objectname), 0, (void *)qdata->objectname, 0, NULL);
+	SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->objectname), 0, (void *)qdata->objectname, 0, NULL);
 	SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->ext), 0, (void *)qdata->ext, 0, NULL);
+	SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 3, 0, (void *)"txt", 0, NULL);
 	SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, qdata->data_len, 0, (void *)qdata->data, 0, &qdata->data_ind);
+	SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, qdata->metadata_len, 0, (void *)qdata->metadata, 0, &qdata->metadata_ind);
 
 	ret = SQLExecDirect(stmt, (unsigned char *)qdata->sql, SQL_NTS);
 	if(!SQL_SUCCEEDED(ret)) {
@@ -462,15 +477,40 @@
 	return stmt;
 }
 
+static int open_fileinst(struct ast_storage_fileinst *fi, int *fd, int *fdlen, void **fdm) {
+	int local_fd, local_fdlen;
+	void *local_fdm;
+
+	local_fd = open(fi->localfile, O_RDONLY);
+	if (local_fd == -1) {
+		ast_log(LOG_WARNING, "Unable to open file '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+		return -1;
+	}
+
+	local_fdlen = lseek(local_fd, 0, SEEK_END);
+
+	local_fdm = mmap(NULL, local_fdlen, PROT_READ, MAP_SHARED, local_fd, 0);
+	if (local_fdm == MAP_FAILED) {
+		ast_log(LOG_WARNING, "Unable to map file '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+		return -1;
+	}
+
+	*fdm = local_fdm;
+	*fdlen = local_fdlen;
+	*fd = local_fd;
+
+	return 0;
+}
+
 static int se_put(struct ast_storage *st, struct ast_storage_fileobject *fo, const char *exts)
 {
-	SQLHSTMT stmt;
+	SQLHSTMT stmt = NULL;
 	struct odbc_storage_pvt *ost = (struct odbc_storage_pvt *) st->storage_pvt;
-	struct ast_storage_fileinst *fi;
+	struct ast_storage_fileinst *fi, *mfi;
 	char sql[128], ext[16];
 	struct put_query_data qdata;
-	int fd, fdlen;
-	void *fdm;
+	int fd, fdlen, mfd, mfdlen;
+	void *fdm, *mfdm;
 	int putret = -1;
 
 
@@ -496,26 +536,28 @@
 	}
 	AST_RWLIST_UNLOCK(&fo->files);
 
+	mfi = fo->metadata;
+
 	if(!fi) {
 		ast_log(LOG_WARNING, "Unable to find file instance for put()\n");
 		return -1;
 	}
 
-	fd = open(fi->localfile, O_RDONLY);
-	if (fd == -1) {
-		ast_log(LOG_WARNING, "Unable to open file '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+	if(!mfi) {
+		ast_log(LOG_WARNING, "put() failed: metadata fileinst not found\n");
 		return -1;
 	}
 
-	fdlen = lseek(fd, 0, SEEK_END);
-
-	fdm = mmap(NULL, fdlen, PROT_READ, MAP_SHARED, fd, 0);
-	if (fdm == MAP_FAILED) {
-		ast_log(LOG_WARNING, "Unable to map file '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+	fdm = mfdm = NULL;
+
+	if (open_fileinst(fi, &fd, &fdlen, &fdm) == -1) {
 		return -1;
 	}
-
-	snprintf(sql, sizeof(sql), "INSERT INTO %s (pathname,filename,extension,recording) VALUES (?,?,?,?)", ost->tablename);
+	if (open_fileinst(mfi, &mfd, &mfdlen, &mfdm) == -1) {
+		goto error;
+	}
+
+	snprintf(sql, sizeof(sql), "INSERT INTO %s (pathname,filename,extension,recording) VALUES (?,?,?,?), (?,?,?,?)", ost->tablename);
 
 	qdata.sql = sql;
 	qdata.pathname = fo->pathname;
@@ -523,6 +565,8 @@
 	qdata.ext = fi->ext;
 	qdata.data = fdm;
 	qdata.data_len = qdata.data_ind = fdlen;
+	qdata.metadata = mfdm;
+	qdata.metadata_len = qdata.metadata_ind = mfdlen;
 
 	stmt = ast_odbc_direct_execute(ost->conn, execute_put_query, (void *) &qdata);
 	if(!stmt) {
@@ -532,10 +576,20 @@
 
 	putret = 0;
 error:
-	SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-	munmap(fdm, fdlen);
-	close(fd);
-	return 0;
+	if (stmt) {
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+	}
+	if(fdm) {
+		munmap(fdm, fdlen);
+		close(fd);
+	}
+
+	if (mfdm) {
+		munmap(mfdm, mfdlen);
+		close(mfd);
+	}
+
+	return putret;
 }
 
 static int se_del(struct ast_storage *st, struct ast_storage_fileobject *fo)
@@ -666,6 +720,10 @@
 	}
 	AST_RWLIST_UNLOCK(&fo->files);
 
+	if (fo->metadata) {
+		printf("metadata file: %s\n", fo->metadata->localfile);
+	}
+
 	ast_storage_fileobject_release(fo);
 
 	ret = se_release(st);




More information about the asterisk-commits mailing list