[asterisk-commits] twilson: branch twilson/sqlite_astdb r323322 - /team/twilson/sqlite_astdb/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 13 22:43:00 CDT 2011


Author: twilson
Date: Mon Jun 13 22:42:58 2011
New Revision: 323322

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=323322
Log:
Add code to avoid potential infinite loop in BDB for conversion

Modified:
    team/twilson/sqlite_astdb/main/db.c

Modified: team/twilson/sqlite_astdb/main/db.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/sqlite_astdb/main/db.c?view=diff&rev=323322&r1=323321&r2=323322
==============================================================================
--- team/twilson/sqlite_astdb/main/db.c (original)
+++ team/twilson/sqlite_astdb/main/db.c Mon Jun 13 22:42:58 2011
@@ -175,16 +175,25 @@
 static int convert_bdb_to_sqlite3(const char *sql3_dbname)
 {
 	DB *bdb;
-	DBT key = { 0, }, value = { 0, };
-	int res;
+	DBT key = { 0, }, value = { 0, }, last_key = { 0, };
+	int res, last = 0;
+	char last_key_s[MAX_DB_FIELD];
 
 	if (!(bdb = dbopen(ast_config_AST_DB, O_RDONLY, AST_FILE_MODE, DB_BTREE, NULL))) {
 		ast_log(LOG_WARNING, "Unable to open Asterisk database '%s': %s\n", ast_config_AST_DB, strerror(errno));
 		return -1;
 	}
 
+	if (bdb->seq(bdb, &last_key, &value, R_LAST)) {
+		/* Empty database */
+		return 0;
+	}
+
+	memcpy(last_key_s, last_key.data, MIN(last_key.size - 1, sizeof(last_key_s)));
+	last_key_s[last_key.size - 1] = '\0';
 	for (res = bdb->seq(bdb, &key, &value, R_FIRST);
 			!res; res = bdb->seq(bdb, &key, &value, R_NEXT)) {
+		last = !strcmp(key.data, last_key_s);
 		db_put_raw((const char *) key.data, key.size, (const char *) value.data, value.size);
 	}
 




More information about the asterisk-commits mailing list