From d5ea5172a754848c10d061a4a9dd777f63ba71c1 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 11 Mar 2017 01:29:38 +0100 Subject: Add OMEMO via Plugin --- plugins/omemo/src/database.vala | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 plugins/omemo/src/database.vala (limited to 'plugins/omemo/src/database.vala') diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala new file mode 100644 index 00000000..1216ca84 --- /dev/null +++ b/plugins/omemo/src/database.vala @@ -0,0 +1,80 @@ +using Gee; +using Sqlite; +using Qlite; + +using Dino.Entities; + +namespace Dino.Omemo { + +public class Database : Qlite.Database { + private const int VERSION = 0; + + public class IdentityTable : Table { + public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; + public Column account_id = new Column.Integer("account_id") { unique = true, not_null = true }; + public Column device_id = new Column.Integer("device_id") { not_null = true }; + public Column identity_key_private_base64 = new Column.Text("identity_key_private_base64") { not_null = true }; + public Column identity_key_public_base64 = new Column.Text("identity_key_public_base64") { not_null = true }; + + protected IdentityTable(Database db) { + base(db, "identity"); + init({id, account_id, device_id, identity_key_private_base64, identity_key_public_base64}); + } + } + + public class SignedPreKeyTable : Table { + public Column identity_id = new Column.Integer("identity_id") { not_null = true }; + public Column signed_pre_key_id = new Column.Integer("signed_pre_key_id") { not_null = true }; + public Column record_base64 = new Column.Text("record_base64") { not_null = true }; + + protected SignedPreKeyTable(Database db) { + base(db, "signed_pre_key"); + init({identity_id, signed_pre_key_id, record_base64}); + unique({identity_id, signed_pre_key_id}); + } + } + + public class PreKeyTable : Table { + public Column identity_id = new Column.Integer("identity_id") { not_null = true }; + public Column pre_key_id = new Column.Integer("pre_key_id") { not_null = true }; + public Column record_base64 = new Column.Text("record_base64") { not_null = true }; + + protected PreKeyTable(Database db) { + base(db, "pre_key"); + init({identity_id, pre_key_id, record_base64}); + unique({identity_id, pre_key_id}); + } + } + + public class SessionTable : Table { + public Column identity_id = new Column.Integer("identity_id") { not_null = true }; + public Column address_name = new Column.Text("name") { not_null = true }; + public Column device_id = new Column.Integer("device_id") { not_null = true }; + public Column record_base64 = new Column.Text("record_base64") { not_null = true }; + + protected SessionTable(Database db) { + base(db, "session"); + init({identity_id, address_name, device_id, record_base64}); + unique({identity_id, address_name, device_id}); + } + } + public IdentityTable identity { get; private set; } + public SignedPreKeyTable signed_pre_key { get; private set; } + public PreKeyTable pre_key { get; private set; } + public SessionTable session { get; private set; } + + public Database(string fileName) { + base(fileName, VERSION); + identity = new IdentityTable(this); + signed_pre_key = new SignedPreKeyTable(this); + pre_key = new PreKeyTable(this); + session = new SessionTable(this); + init({identity, signed_pre_key, pre_key, session}); + } + + public override void migrate(long oldVersion) { + // new table columns are added, outdated columns are still present + } +} + +} \ No newline at end of file -- cgit v1.2.3-70-g09d2