don't use display version of jids
This commit is contained in:
parent
6cb2b0b5d1
commit
d3dfecae8a
|
@ -52,7 +52,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
private static DatabaseBackend instance = null;
|
||||
|
||||
private static final String DATABASE_NAME = "history";
|
||||
private static final int DATABASE_VERSION = 27;
|
||||
private static final int DATABASE_VERSION = 28;
|
||||
|
||||
private static String CREATE_CONTATCS_STATEMENT = "create table "
|
||||
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
|
||||
|
@ -250,6 +250,90 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
db.execSQL("update " + Account.TABLENAME + " set " + Account.ROSTERVERSION + " = NULL");
|
||||
}
|
||||
if (oldVersion < 14 && newVersion >= 14) {
|
||||
canonicalizeJids(db);
|
||||
}
|
||||
if (oldVersion < 15 && newVersion >= 15) {
|
||||
recreateAxolotlDb(db);
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
|
||||
+ Message.FINGERPRINT + " TEXT");
|
||||
} else if (oldVersion < 22 && newVersion >= 22) {
|
||||
db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.CERTIFICATE);
|
||||
}
|
||||
if (oldVersion < 16 && newVersion >= 16) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
|
||||
+ Message.CARBON + " INTEGER");
|
||||
}
|
||||
if (oldVersion < 19 && newVersion >= 19) {
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.DISPLAY_NAME + " TEXT");
|
||||
}
|
||||
if (oldVersion < 20 && newVersion >= 20) {
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.HOSTNAME + " TEXT");
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.PORT + " NUMBER DEFAULT 5222");
|
||||
}
|
||||
if (oldVersion < 26 && newVersion >= 26) {
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS + " TEXT");
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS_MESSAGE + " TEXT");
|
||||
}
|
||||
/* Any migrations that alter the Account table need to happen BEFORE this migration, as it
|
||||
* depends on account de-serialization.
|
||||
*/
|
||||
if (oldVersion < 17 && newVersion >= 17) {
|
||||
List<Account> accounts = getAccounts(db);
|
||||
for (Account account : accounts) {
|
||||
String ownDeviceIdString = account.getKey(SQLiteAxolotlStore.JSONKEY_REGISTRATION_ID);
|
||||
if (ownDeviceIdString == null) {
|
||||
continue;
|
||||
}
|
||||
int ownDeviceId = Integer.valueOf(ownDeviceIdString);
|
||||
AxolotlAddress ownAddress = new AxolotlAddress(account.getJid().toBareJid().toString(), ownDeviceId);
|
||||
deleteSession(db, account, ownAddress);
|
||||
IdentityKeyPair identityKeyPair = loadOwnIdentityKeyPair(db, account);
|
||||
if (identityKeyPair != null) {
|
||||
setIdentityKeyTrust(db, account, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), XmppAxolotlSession.Trust.TRUSTED);
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not load own identity key pair");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldVersion < 18 && newVersion >= 18) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ + " NUMBER DEFAULT 1");
|
||||
}
|
||||
|
||||
if (oldVersion < 21 && newVersion >= 21) {
|
||||
List<Account> accounts = getAccounts(db);
|
||||
for (Account account : accounts) {
|
||||
account.unsetPgpSignature();
|
||||
db.update(Account.TABLENAME, account.getContentValues(), Account.UUID
|
||||
+ "=?", new String[]{account.getUuid()});
|
||||
}
|
||||
}
|
||||
|
||||
if (oldVersion < 23 && newVersion >= 23) {
|
||||
db.execSQL(CREATE_DISCOVERY_RESULTS_STATEMENT);
|
||||
}
|
||||
|
||||
if (oldVersion < 24 && newVersion >= 24) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT");
|
||||
}
|
||||
|
||||
if (oldVersion < 25 && newVersion >= 25) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.OOB + " INTEGER");
|
||||
}
|
||||
|
||||
if (oldVersion < 26 && newVersion >= 26) {
|
||||
db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT);
|
||||
}
|
||||
|
||||
if (oldVersion < 27 && newVersion >= 27) {
|
||||
db.execSQL("DELETE FROM "+ServiceDiscoveryResult.TABLENAME);
|
||||
}
|
||||
|
||||
if (oldVersion < 28 && newVersion >= 28) {
|
||||
canonicalizeJids(db);
|
||||
}
|
||||
}
|
||||
|
||||
private void canonicalizeJids(SQLiteDatabase db) {
|
||||
// migrate db to new, canonicalized JID domainpart representation
|
||||
|
||||
// Conversation table
|
||||
|
@ -331,82 +415,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
}
|
||||
cursor.close();
|
||||
}
|
||||
if (oldVersion < 15 && newVersion >= 15) {
|
||||
recreateAxolotlDb(db);
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
|
||||
+ Message.FINGERPRINT + " TEXT");
|
||||
} else if (oldVersion < 22 && newVersion >= 22) {
|
||||
db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.CERTIFICATE);
|
||||
}
|
||||
if (oldVersion < 16 && newVersion >= 16) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
|
||||
+ Message.CARBON + " INTEGER");
|
||||
}
|
||||
if (oldVersion < 19 && newVersion >= 19) {
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.DISPLAY_NAME + " TEXT");
|
||||
}
|
||||
if (oldVersion < 20 && newVersion >= 20) {
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.HOSTNAME + " TEXT");
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.PORT + " NUMBER DEFAULT 5222");
|
||||
}
|
||||
if (oldVersion < 26 && newVersion >= 26) {
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS + " TEXT");
|
||||
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS_MESSAGE + " TEXT");
|
||||
}
|
||||
/* Any migrations that alter the Account table need to happen BEFORE this migration, as it
|
||||
* depends on account de-serialization.
|
||||
*/
|
||||
if (oldVersion < 17 && newVersion >= 17) {
|
||||
List<Account> accounts = getAccounts(db);
|
||||
for (Account account : accounts) {
|
||||
String ownDeviceIdString = account.getKey(SQLiteAxolotlStore.JSONKEY_REGISTRATION_ID);
|
||||
if (ownDeviceIdString == null) {
|
||||
continue;
|
||||
}
|
||||
int ownDeviceId = Integer.valueOf(ownDeviceIdString);
|
||||
AxolotlAddress ownAddress = new AxolotlAddress(account.getJid().toBareJid().toString(), ownDeviceId);
|
||||
deleteSession(db, account, ownAddress);
|
||||
IdentityKeyPair identityKeyPair = loadOwnIdentityKeyPair(db, account);
|
||||
if (identityKeyPair != null) {
|
||||
setIdentityKeyTrust(db, account, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), XmppAxolotlSession.Trust.TRUSTED);
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not load own identity key pair");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldVersion < 18 && newVersion >= 18) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ + " NUMBER DEFAULT 1");
|
||||
}
|
||||
|
||||
if (oldVersion < 21 && newVersion >= 21) {
|
||||
List<Account> accounts = getAccounts(db);
|
||||
for (Account account : accounts) {
|
||||
account.unsetPgpSignature();
|
||||
db.update(Account.TABLENAME, account.getContentValues(), Account.UUID
|
||||
+ "=?", new String[]{account.getUuid()});
|
||||
}
|
||||
}
|
||||
|
||||
if (oldVersion < 23 && newVersion >= 23) {
|
||||
db.execSQL(CREATE_DISCOVERY_RESULTS_STATEMENT);
|
||||
}
|
||||
|
||||
if (oldVersion < 24 && newVersion >= 24) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT");
|
||||
}
|
||||
|
||||
if (oldVersion < 25 && newVersion >= 25) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.OOB + " INTEGER");
|
||||
}
|
||||
|
||||
if (oldVersion < 26 && newVersion >= 26) {
|
||||
db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT);
|
||||
}
|
||||
|
||||
if (oldVersion < 27 && newVersion >= 27) {
|
||||
db.execSQL("DELETE FROM "+ServiceDiscoveryResult.TABLENAME);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized DatabaseBackend getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
|
|
|
@ -21,10 +21,6 @@ public final class Jid {
|
|||
private final String domainpart;
|
||||
private final String resourcepart;
|
||||
|
||||
// It's much more efficient to store the ful JID as well as the parts instead of figuring them
|
||||
// all out every time (since some characters are displayed but aren't used for comparisons).
|
||||
private final String displayjid;
|
||||
|
||||
public String getLocalpart() {
|
||||
return localpart;
|
||||
}
|
||||
|
@ -73,7 +69,6 @@ public final class Jid {
|
|||
|
||||
Jid fromCache = Jid.cache.get(jid);
|
||||
if (fromCache != null) {
|
||||
displayjid = fromCache.displayjid;
|
||||
localpart = fromCache.localpart;
|
||||
domainpart = fromCache.domainpart;
|
||||
resourcepart = fromCache.resourcepart;
|
||||
|
@ -94,8 +89,6 @@ public final class Jid {
|
|||
throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
|
||||
}
|
||||
|
||||
String finaljid;
|
||||
|
||||
final int domainpartStart;
|
||||
final int atLoc = jid.indexOf("@");
|
||||
final int slashLoc = jid.indexOf("/");
|
||||
|
@ -103,7 +96,6 @@ public final class Jid {
|
|||
// or there are one or more "@" signs but they're all in the resourcepart (eg. "example.net/@/rp@"):
|
||||
if (atCount == 0 || (atCount > 0 && slashLoc != -1 && atLoc > slashLoc)) {
|
||||
localpart = "";
|
||||
finaljid = "";
|
||||
domainpartStart = 0;
|
||||
} else {
|
||||
final String lp = jid.substring(0, atLoc);
|
||||
|
@ -116,7 +108,6 @@ public final class Jid {
|
|||
throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
|
||||
}
|
||||
domainpartStart = atLoc + 1;
|
||||
finaljid = lp + "@";
|
||||
}
|
||||
|
||||
final String dp;
|
||||
|
@ -135,7 +126,6 @@ public final class Jid {
|
|||
} catch (final StringprepException e) {
|
||||
throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
|
||||
}
|
||||
finaljid = finaljid + dp + "/" + rp;
|
||||
} else {
|
||||
resourcepart = "";
|
||||
try{
|
||||
|
@ -143,7 +133,6 @@ public final class Jid {
|
|||
} catch (final StringprepException e) {
|
||||
throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
|
||||
}
|
||||
finaljid = finaljid + dp;
|
||||
}
|
||||
|
||||
// Remove trailing "." before storing the domain part.
|
||||
|
@ -167,8 +156,6 @@ public final class Jid {
|
|||
}
|
||||
|
||||
Jid.cache.put(jid, this);
|
||||
|
||||
this.displayjid = finaljid;
|
||||
}
|
||||
|
||||
public Jid toBareJid() {
|
||||
|
@ -191,7 +178,16 @@ public final class Jid {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return displayjid;
|
||||
String out;
|
||||
if (hasLocalpart()) {
|
||||
out = localpart + '@' + domainpart;
|
||||
} else {
|
||||
out = domainpart;
|
||||
}
|
||||
if (!resourcepart.isEmpty()) {
|
||||
out += '/'+resourcepart;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue