diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-06-25 21:17:32 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-06-25 21:47:19 +0200 |
commit | 1d8fa7e99dc1304ece611bff99d12f52981ab1f9 (patch) | |
tree | 91e3790c1ad84b5413238c74b2c09b080234a893 /src/main/java/de/pixart/messenger/persistance | |
parent | 73c8feea13a526259ee5bb58e639e31ad781fd79 (diff) |
Revert "Networkstack - let OS decide IPv4 or IPv6 (#267)"
This reverts commit e6a15597904019f68c02e6fd8f61fb6de0b13324.
If there is IPv6 available but the server doesn't listen to it, the connection will not be established
Diffstat (limited to 'src/main/java/de/pixart/messenger/persistance')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 243db470a..ba0f7927d 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -55,6 +55,7 @@ import de.pixart.messenger.entities.ServiceDiscoveryResult; import de.pixart.messenger.services.ShortcutService; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.FtsUtils; +import de.pixart.messenger.utils.Resolver; import de.pixart.messenger.xmpp.InvalidJid; import de.pixart.messenger.xmpp.mam.MamReference; import rocks.xmpp.addr.Jid; @@ -62,7 +63,7 @@ import rocks.xmpp.addr.Jid; public class DatabaseBackend extends SQLiteOpenHelper { public static final String DATABASE_NAME = "history"; - public static final int DATABASE_VERSION = 47; // = Conversations DATABASE_VERSION + 3 + public static final int DATABASE_VERSION = 48; // = Conversations DATABASE_VERSION + 4 private static DatabaseBackend instance = null; private static String CREATE_CONTATCS_STATEMENT = "create table " @@ -150,6 +151,17 @@ public class DatabaseBackend extends SQLiteOpenHelper { + ") ON CONFLICT IGNORE" + ");"; + private static String RESOLVER_RESULTS_TABLENAME = "resolver_results"; + private static String CREATE_RESOLVER_RESULTS_TABLE = "create table " + RESOLVER_RESULTS_TABLENAME + "(" + + Resolver.Result.DOMAIN + " TEXT," + + Resolver.Result.HOSTNAME + " TEXT," + + Resolver.Result.IP + " BLOB," + + Resolver.Result.PRIORITY + " NUMBER," + + Resolver.Result.DIRECT_TLS + " NUMBER," + + Resolver.Result.AUTHENTICATED + " NUMBER," + + Resolver.Result.PORT + " NUMBER," + + "UNIQUE(" + Resolver.Result.DOMAIN + ") ON CONFLICT REPLACE" + + ");"; private static String CREATE_MESSAGE_TIME_INDEX = "create INDEX message_time_index ON " + Message.TABLENAME + "(" + Message.TIME_SENT + ")"; private static String CREATE_MESSAGE_CONVERSATION_INDEX = "create INDEX message_conversation_index ON " + Message.TABLENAME + "(" + Message.CONVERSATION + ")"; private static String CREATE_MESSAGE_DELETED_INDEX = "create index message_deleted_index ON " + Message.TABLENAME + "(" + Message.DELETED + ")"; @@ -247,6 +259,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL(CREATE_SIGNED_PREKEYS_STATEMENT); db.execSQL(CREATE_IDENTITIES_STATEMENT); db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT); + db.execSQL(CREATE_RESOLVER_RESULTS_TABLE); db.execSQL(CREATE_MESSAGE_INDEX_TABLE); db.execSQL(CREATE_MESSAGE_INSERT_TRIGGER); db.execSQL(CREATE_MESSAGE_UPDATE_TRIGGER); @@ -516,6 +529,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.MARKABLE + " NUMBER DEFAULT 0"); } + if (oldVersion < 40 && newVersion >= 40) { + db.execSQL(CREATE_RESOLVER_RESULTS_TABLE); + } + if (oldVersion < 42 && newVersion >= 42) { db.execSQL(CREATE_MESSAGE_INDEX_TABLE); db.execSQL(CREATE_MESSAGE_INSERT_TRIGGER); @@ -544,7 +561,14 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.TRUSTED); // TODO - just to make old databases importable, column isn't needed at all } } - db.execSQL("DROP TABLE resolver_results"); + + if (oldVersion < 48 && newVersion >= 48) { + try { + db.execSQL(CREATE_RESOLVER_RESULTS_TABLE); + } catch (Exception e) { + //ignore + } + } } private boolean isColumnExisting(SQLiteDatabase db, String TableName, String ColumnName) { @@ -681,6 +705,34 @@ public class DatabaseBackend extends SQLiteOpenHelper { return result; } + public void saveResolverResult(String domain, Resolver.Result result) { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues contentValues = result.toContentValues(); + contentValues.put(Resolver.Result.DOMAIN, domain); + db.insert(RESOLVER_RESULTS_TABLENAME, null, contentValues); + } + + public synchronized Resolver.Result findResolverResult(String domain) { + SQLiteDatabase db = this.getReadableDatabase(); + String where = Resolver.Result.DOMAIN + "=?"; + String[] whereArgs = {domain}; + final Cursor cursor = db.query(RESOLVER_RESULTS_TABLENAME, null, where, whereArgs, null, null, null); + Resolver.Result result = null; + if (cursor != null) { + try { + if (cursor.moveToFirst()) { + result = Resolver.Result.fromCursor(cursor); + } + } catch (Exception e) { + Log.d(Config.LOGTAG, "unable to find cached resolver result in database " + e.getMessage()); + return null; + } finally { + cursor.close(); + } + } + return result; + } + public void insertPresenceTemplate(PresenceTemplate template) { SQLiteDatabase db = this.getWritableDatabase(); String whereToDelete = PresenceTemplate.MESSAGE + "=?"; |