update submodules to open linphone.db

This commit is contained in:
Benjamin Reis 2017-10-27 16:03:11 +02:00
parent 15e1cb667f
commit d0d6d86537
5 changed files with 9 additions and 134 deletions

View file

@ -326,129 +326,6 @@ static int check_should_migrate_images(void *data, int argc, char **argv, char *
return 0;
}
- (BOOL)migrateChatDBIfNeeded:(LinphoneCore *)lc {
sqlite3 *newDb;
char *errMsg;
NSError *error;
NSString *oldDbPath = [LinphoneManager documentFile:kLinphoneOldChatDBFilename];
NSString *newDbPath = [LinphoneManager documentFile:kLinphoneInternalChatDBFilename];
BOOL shouldMigrate = [[NSFileManager defaultManager] fileExistsAtPath:oldDbPath];
BOOL shouldMigrateImages = FALSE;
const char *identity = NULL;
BOOL migrated = FALSE;
char *attach_stmt = NULL;
LinphoneProxyConfig *default_proxy = linphone_core_get_default_proxy_config(lc);
if (sqlite3_open([newDbPath UTF8String], &newDb) != SQLITE_OK) {
LOGE(@"Can't open \"%@\" sqlite3 database.", newDbPath);
return FALSE;
}
const char *check_appdata =
"SELECT url,message FROM history WHERE url LIKE 'assets-library%' OR message LIKE 'assets-library%' LIMIT 1;";
// will set "needToMigrateImages to TRUE if a result comes by
sqlite3_exec(newDb, check_appdata, check_should_migrate_images, &shouldMigrateImages, NULL);
if (!shouldMigrate && !shouldMigrateImages) {
sqlite3_close(newDb);
return FALSE;
}
LOGI(@"Starting migration procedure");
if (shouldMigrate) {
// attach old database to the new one:
attach_stmt = sqlite3_mprintf("ATTACH DATABASE %Q AS oldchats", [oldDbPath UTF8String]);
if (sqlite3_exec(newDb, attach_stmt, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"Can't attach old chat table, error[%s] ", errMsg);
sqlite3_free(errMsg);
goto exit_dbmigration;
}
// migrate old chats to the new db. The iOS stores timestamp in UTC already, so we can directly put it in the
// 'utc' field and set 'time' to -1
const char *migration_statement =
"INSERT INTO history (localContact,remoteContact,direction,message,utc,read,status,time) "
"SELECT localContact,remoteContact,direction,message,time,read,state,'-1' FROM oldchats.chat";
if (sqlite3_exec(newDb, migration_statement, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"DB migration failed, error[%s] ", errMsg);
sqlite3_free(errMsg);
goto exit_dbmigration;
}
// invert direction of old messages, because iOS was storing the direction flag incorrectly
const char *invert_direction = "UPDATE history SET direction = NOT direction";
if (sqlite3_exec(newDb, invert_direction, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"Inverting direction failed, error[%s]", errMsg);
sqlite3_free(errMsg);
goto exit_dbmigration;
}
// replace empty from: or to: by the current identity.
if (default_proxy) {
identity = linphone_proxy_config_get_identity(default_proxy);
}
if (!identity) {
identity = "sip:unknown@sip.linphone.org";
}
char *from_conversion =
sqlite3_mprintf("UPDATE history SET localContact = %Q WHERE localContact = ''", identity);
if (sqlite3_exec(newDb, from_conversion, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"FROM conversion failed, error[%s] ", errMsg);
sqlite3_free(errMsg);
}
sqlite3_free(from_conversion);
char *to_conversion =
sqlite3_mprintf("UPDATE history SET remoteContact = %Q WHERE remoteContact = ''", identity);
if (sqlite3_exec(newDb, to_conversion, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"DB migration failed, error[%s] ", errMsg);
sqlite3_free(errMsg);
}
sqlite3_free(to_conversion);
}
// local image paths were stored in the 'message' field historically. They were
// very temporarily stored in the 'url' field, and now we migrated them to a JSON-
// encoded field. These are the migration steps to migrate them.
// move already stored images from the messages to the appdata JSON field
const char *assetslib_migration = "UPDATE history SET appdata='{\"localimage\":\"'||message||'\"}' , message='' "
"WHERE message LIKE 'assets-library%'";
if (sqlite3_exec(newDb, assetslib_migration, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"Assets-history migration for MESSAGE failed, error[%s] ", errMsg);
sqlite3_free(errMsg);
}
// move already stored images from the url to the appdata JSON field
const char *assetslib_migration_fromurl =
"UPDATE history SET appdata='{\"localimage\":\"'||url||'\"}' , url='' WHERE url LIKE 'assets-library%'";
if (sqlite3_exec(newDb, assetslib_migration_fromurl, NULL, NULL, &errMsg) != SQLITE_OK) {
LOGE(@"Assets-history migration for URL failed, error[%s] ", errMsg);
sqlite3_free(errMsg);
}
// We will lose received messages with remote url, they will be displayed in plain. We can't do much for them..
migrated = TRUE;
exit_dbmigration:
if (attach_stmt)
sqlite3_free(attach_stmt);
sqlite3_close(newDb);
// in any case, we should remove the old chat db
if (shouldMigrate && ![[NSFileManager defaultManager] removeItemAtPath:oldDbPath error:&error]) {
LOGE(@"Could not remove old chat DB: %@", error);
}
LOGI(@"Message storage migration finished: success = %@", migrated ? @"TRUE" : @"FALSE");
return migrated;
}
- (void)migrateFromUserPrefs {
static NSString *migration_flag = @"userpref_migration_done";
@ -490,14 +367,6 @@ exit_dbmigration:
}
- (void)migrationLinphoneSettings {
// we need to proceed to the migration *after* the chat database was opened, so that we know it is in consistent
// state
NSString *chatDBFileName = [LinphoneManager documentFile:kLinphoneInternalChatDBFilename];
if ([self migrateChatDBIfNeeded:theLinphoneCore]) {
// if a migration was performed, we should reinitialize the chat database
linphone_core_set_chat_database_path(theLinphoneCore, [chatDBFileName UTF8String]);
}
/* AVPF migration */
if ([self lpConfigBoolForKey:@"avpf_migration_done"] == FALSE) {
const MSList *proxies = linphone_core_get_proxy_config_list(theLinphoneCore);

View file

@ -1631,6 +1631,7 @@
63FB30341A680E73008CA393 /* UIRoundedImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIRoundedImageView.m; sourceTree = "<group>"; };
70E542F213E147E3002BA2C0 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
70E542F413E147EB002BA2C0 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
8C1A1F7C1FA331D40064BE00 /* libsoci_sqlite3.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsoci_sqlite3.a; path = "liblinphone-sdk/apple-darwin/lib/libsoci_sqlite3.a"; sourceTree = "<group>"; };
8C1B67051E671826001EA2FE /* AudioHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioHelper.m; sourceTree = "<group>"; };
8C1B67081E6718BC001EA2FE /* AudioHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AudioHelper.h; path = Utils/AudioHelper.h; sourceTree = "<group>"; };
8C1C42E61E43408E00FE9A91 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AboutView.strings; sourceTree = "<group>"; };
@ -1718,6 +1719,8 @@
8CB2B8F61F86229B0015CEE2 /* chat_secure.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = chat_secure.png; sourceTree = "<group>"; };
8CB2B8F71F86229C0015CEE2 /* next_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = next_disabled.png; sourceTree = "<group>"; };
8CB2B8F81F86229D0015CEE2 /* next_disabled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "next_disabled@2x.png"; sourceTree = "<group>"; };
8CD0B3BE1FA22CBA008FEB16 /* libsoci_core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsoci_core.a; path = "liblinphone-sdk/apple-darwin/lib/libsoci_core.a"; sourceTree = "<group>"; };
8CD0B3C81FA2357B008FEB16 /* libsqlite3.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsqlite3.a; path = "liblinphone-sdk/apple-darwin/lib/libsqlite3.a"; sourceTree = "<group>"; };
8CDC618C1F84D89B0087CF7F /* check_selected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = check_selected.png; path = "../../../ressources 27.07.17/check_selected.png"; sourceTree = "<group>"; };
8CDC61961F84D9270087CF7F /* check_selected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "check_selected@2x.png"; path = "../../../ressources 27.07.17/check_selected@2x.png"; sourceTree = "<group>"; };
8CE24F491F8234A20077AC0A /* next_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = next_default.png; sourceTree = "<group>"; };
@ -2288,6 +2291,9 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
8C1A1F7C1FA331D40064BE00 /* libsoci_sqlite3.a */,
8CD0B3C81FA2357B008FEB16 /* libsqlite3.a */,
8CD0B3BE1FA22CBA008FEB16 /* libsoci_core.a */,
8C3EAA191EB8D9C300B732B6 /* linphonetester.framework */,
8C5BCEC61EB3859200A9AAEF /* bctoolbox-tester.framework */,
8C3EA9EF1EB8A78C00B732B6 /* msx264.framework */,

@ -1 +1 @@
Subproject commit 99773d23d71b78c75a8b2eb7ec91e7c3a69777f5
Subproject commit ddddd2b3bc66604225c26b6cdecaf3c91680deda

@ -1 +1 @@
Subproject commit 908c7eb8f421601e6eb7b77e1131a35bcbe374fa
Subproject commit 672c6a8ef77ffc0725475a826110d13e22dc909d

@ -1 +1 @@
Subproject commit d15d7dfc52041ee6e983e677735542cbeb63f5a8
Subproject commit a859c185b5345cc4e05a4e7c4c3367cea5241a72