aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-10-28 23:48:07 +0200
committerfiaxh <git@mx.ax.lt>2017-10-31 15:41:45 +0100
commitb9df78e4494879752e9e68dcc5d54e03fffe9467 (patch)
treed1c74fde4aedea42773bc411c557f2184003defa /plugins/omemo
parentd9b91206c0291fa8aa58df572292784a4f8ff878 (diff)
downloaddino-b9df78e4494879752e9e68dcc5d54e03fffe9467.tar.gz
dino-b9df78e4494879752e9e68dcc5d54e03fffe9467.zip
Move DatabaseError handling into Qlite
Diffstat (limited to 'plugins/omemo')
-rw-r--r--plugins/omemo/src/account_settings_widget.vala20
-rw-r--r--plugins/omemo/src/database.vala10
-rw-r--r--plugins/omemo/src/manager.vala39
-rw-r--r--plugins/omemo/src/plugin.vala42
-rw-r--r--plugins/omemo/src/pre_key_store.vala28
-rw-r--r--plugins/omemo/src/session_store.vala32
-rw-r--r--plugins/omemo/src/signed_pre_key_store.vala29
7 files changed, 76 insertions, 124 deletions
diff --git a/plugins/omemo/src/account_settings_widget.vala b/plugins/omemo/src/account_settings_widget.vala
index da3f6ca2..cec0eecd 100644
--- a/plugins/omemo/src/account_settings_widget.vala
+++ b/plugins/omemo/src/account_settings_widget.vala
@@ -36,17 +36,13 @@ public class AccountSettingWidget : Plugins.AccountSettingsWidget, Box {
public void set_account(Account account) {
this.account = account;
btn.visible = false;
- try {
- Qlite.Row? row = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id).inner;
- if (row == null) {
- fingerprint.set_markup("%s\n<span font='8'>%s</span>".printf(_("Own fingerprint"), _("Will be generated on first connect")));
- } else {
- string res = fingerprint_markup(fingerprint_from_base64(((!)row)[plugin.db.identity.identity_key_public_base64]));
- fingerprint.set_markup("%s\n<span font_family='monospace' font='8'>%s</span>".printf(_("Own fingerprint"), res));
- btn.visible = true;
- }
- } catch (Qlite.DatabaseError e) {
- fingerprint.set_markup("%s\n<span font='8'>%s</span>".printf(_("Own fingerprint"), _("Database error")));
+ Qlite.Row? row = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id).inner;
+ if (row == null) {
+ fingerprint.set_markup("%s\n<span font='8'>%s</span>".printf(_("Own fingerprint"), _("Will be generated on first connect")));
+ } else {
+ string res = fingerprint_markup(fingerprint_from_base64(((!)row)[plugin.db.identity.identity_key_public_base64]));
+ fingerprint.set_markup("%s\n<span font_family='monospace' font='8'>%s</span>".printf(_("Own fingerprint"), res));
+ btn.visible = true;
}
}
@@ -54,4 +50,4 @@ public class AccountSettingWidget : Plugins.AccountSettingsWidget, Box {
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala
index aa52daf0..52a1b15d 100644
--- a/plugins/omemo/src/database.vala
+++ b/plugins/omemo/src/database.vala
@@ -23,11 +23,11 @@ public class Database : Qlite.Database {
index("identity_meta_list_idx", {address_name});
}
- public QueryBuilder with_address(string address_name) throws DatabaseError {
+ public QueryBuilder with_address(string address_name) {
return select().with(this.address_name, "=", address_name);
}
- public void insert_device_list(string address_name, ArrayList<int32> devices) throws DatabaseError {
+ public void insert_device_list(string address_name, ArrayList<int32> devices) {
update().with(this.address_name, "=", address_name).set(now_active, false).perform();
foreach (int32 device_id in devices) {
upsert()
@@ -39,7 +39,7 @@ public class Database : Qlite.Database {
}
}
- public int64 insert_device_bundle(string address_name, int device_id, Bundle bundle) throws DatabaseError {
+ public int64 insert_device_bundle(string address_name, int device_id, Bundle bundle) {
if (bundle == null || bundle.identity_key == null) return -1;
return upsert()
.value(this.address_name, address_name, true)
@@ -108,7 +108,7 @@ public class Database : Qlite.Database {
public PreKeyTable pre_key { get; private set; }
public SessionTable session { get; private set; }
- public Database(string fileName) throws DatabaseError {
+ public Database(string fileName) {
base(fileName, VERSION);
identity_meta = new IdentityMetaTable(this);
identity = new IdentityTable(this);
@@ -124,4 +124,4 @@ public class Database : Qlite.Database {
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala
index 9b6f3681..5a7cb9ef 100644
--- a/plugins/omemo/src/manager.vala
+++ b/plugins/omemo/src/manager.vala
@@ -196,39 +196,24 @@ public class Manager : StreamInteractionModule, Object {
if (module == null) {
return;
}
- try {
- ArrayList<int32> device_list = module.get_device_list(jid);
- db.identity_meta.insert_device_list(jid, device_list);
- int inc = 0;
- foreach (Row row in db.identity_meta.with_address(jid).with_null(db.identity_meta.identity_key_public_base64)) {
- module.fetch_bundle(stream, row[db.identity_meta.address_name], row[db.identity_meta.device_id]);
- inc++;
- }
- if (inc > 0) {
- if (Plugin.DEBUG) print(@"OMEMO: new bundles $inc/$(device_list.size) for $jid\n");
- }
- } catch (DatabaseError e) {
- // Ignore
- print(@"OMEMO: failed to use database: $(e.message)\n");
+ ArrayList<int32> device_list = module.get_device_list(jid);
+ db.identity_meta.insert_device_list(jid, device_list);
+ int inc = 0;
+ foreach (Row row in db.identity_meta.with_address(jid).with_null(db.identity_meta.identity_key_public_base64)) {
+ module.fetch_bundle(stream, row[db.identity_meta.address_name], row[db.identity_meta.device_id]);
+ inc++;
+ }
+ if (inc > 0) {
+ if (Plugin.DEBUG) print(@"OMEMO: new bundles $inc/$(device_list.size) for $jid\n");
}
}
public void on_bundle_fetched(Account account, string jid, int32 device_id, Bundle bundle) {
- try {
- db.identity_meta.insert_device_bundle(jid, device_id, bundle);
- } catch (DatabaseError e) {
- // Ignore
- print(@"OMEMO: failed to use database: $(e.message)\n");
- }
+ db.identity_meta.insert_device_bundle(jid, device_id, bundle);
}
private void on_store_created(Account account, Store store) {
- Qlite.Row? row = null;
- try {
- row = db.identity.row_with(db.identity.account_id, account.id).inner;
- } catch (Error e) {
- // Ignore error
- }
+ Qlite.Row? row = db.identity.row_with(db.identity.account_id, account.id).inner;
int identity_id = -1;
if (row == null) {
@@ -280,4 +265,4 @@ public class Manager : StreamInteractionModule, Object {
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/omemo/src/plugin.vala b/plugins/omemo/src/plugin.vala
index 18661403..b9ce500d 100644
--- a/plugins/omemo/src/plugin.vala
+++ b/plugins/omemo/src/plugin.vala
@@ -30,31 +30,27 @@ public class Plugin : RootInterface, Object {
public ContactDetailsProvider contact_details_provider;
public void registered(Dino.Application app) {
- try {
- ensure_context();
- this.app = app;
- this.db = new Database(Path.build_filename(Application.get_storage_dir(), "omemo.db"));
- this.list_entry = new EncryptionListEntry(this);
- this.settings_entry = new AccountSettingsEntry(this);
- this.contact_details_provider = new ContactDetailsProvider(this);
- this.app.plugin_registry.register_encryption_list_entry(list_entry);
- this.app.plugin_registry.register_account_settings_entry(settings_entry);
- this.app.plugin_registry.register_contact_details_entry(contact_details_provider);
- this.app.stream_interactor.module_manager.initialize_account_modules.connect((account, list) => {
- list.add(new StreamModule());
- });
- Manager.start(this.app.stream_interactor, db);
+ ensure_context();
+ this.app = app;
+ this.db = new Database(Path.build_filename(Application.get_storage_dir(), "omemo.db"));
+ this.list_entry = new EncryptionListEntry(this);
+ this.settings_entry = new AccountSettingsEntry(this);
+ this.contact_details_provider = new ContactDetailsProvider(this);
+ this.app.plugin_registry.register_encryption_list_entry(list_entry);
+ this.app.plugin_registry.register_account_settings_entry(settings_entry);
+ this.app.plugin_registry.register_contact_details_entry(contact_details_provider);
+ this.app.stream_interactor.module_manager.initialize_account_modules.connect((account, list) => {
+ list.add(new StreamModule());
+ });
+ Manager.start(this.app.stream_interactor, db);
- string locales_dir;
- if (app.search_path_generator != null) {
- locales_dir = ((!)app.search_path_generator).get_locale_path(GETTEXT_PACKAGE, LOCALE_INSTALL_DIR);
- } else {
- locales_dir = LOCALE_INSTALL_DIR;
- }
- internationalize(GETTEXT_PACKAGE, locales_dir);
- } catch (Error e) {
- print(@"Error initializing OMEMO: $(e.message)\n");
+ string locales_dir;
+ if (app.search_path_generator != null) {
+ locales_dir = ((!)app.search_path_generator).get_locale_path(GETTEXT_PACKAGE, LOCALE_INSTALL_DIR);
+ } else {
+ locales_dir = LOCALE_INSTALL_DIR;
}
+ internationalize(GETTEXT_PACKAGE, locales_dir);
}
public void shutdown() {
diff --git a/plugins/omemo/src/pre_key_store.vala b/plugins/omemo/src/pre_key_store.vala
index 0fd78ffc..93ec2dfe 100644
--- a/plugins/omemo/src/pre_key_store.vala
+++ b/plugins/omemo/src/pre_key_store.vala
@@ -27,27 +27,19 @@ private class BackedPreKeyStore : SimplePreKeyStore {
}
public void on_pre_key_stored(PreKeyStore.Key key) {
- try {
- db.pre_key.insert().or("REPLACE")
- .value(db.pre_key.identity_id, identity_id)
- .value(db.pre_key.pre_key_id, (int) key.key_id)
- .value(db.pre_key.record_base64, Base64.encode(key.record))
- .perform();
- } catch (Error e) {
- print(@"OMEMO: Error while updating pre key store: $(e.message)\n");
- }
+ db.pre_key.insert().or("REPLACE")
+ .value(db.pre_key.identity_id, identity_id)
+ .value(db.pre_key.pre_key_id, (int) key.key_id)
+ .value(db.pre_key.record_base64, Base64.encode(key.record))
+ .perform();
}
public void on_pre_key_deleted(PreKeyStore.Key key) {
- try {
- db.pre_key.delete()
- .with(db.pre_key.identity_id, "=", identity_id)
- .with(db.pre_key.pre_key_id, "=", (int) key.key_id)
- .perform();
- } catch (Error e) {
- print(@"OMEMO: Error while updating pre key store: $(e.message)\n");
- }
+ db.pre_key.delete()
+ .with(db.pre_key.identity_id, "=", identity_id)
+ .with(db.pre_key.pre_key_id, "=", (int) key.key_id)
+ .perform();
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/omemo/src/session_store.vala b/plugins/omemo/src/session_store.vala
index 333fdc08..25b4d719 100644
--- a/plugins/omemo/src/session_store.vala
+++ b/plugins/omemo/src/session_store.vala
@@ -29,29 +29,21 @@ private class BackedSessionStore : SimpleSessionStore {
}
public void on_session_stored(SessionStore.Session session) {
- try {
- db.session.insert().or("REPLACE")
- .value(db.session.identity_id, identity_id)
- .value(db.session.address_name, session.name)
- .value(db.session.device_id, session.device_id)
- .value(db.session.record_base64, Base64.encode(session.record))
- .perform();
- } catch (Error e) {
- print(@"OMEMO: Error while updating session store: $(e.message)\n");
- }
+ db.session.insert().or("REPLACE")
+ .value(db.session.identity_id, identity_id)
+ .value(db.session.address_name, session.name)
+ .value(db.session.device_id, session.device_id)
+ .value(db.session.record_base64, Base64.encode(session.record))
+ .perform();
}
public void on_session_deleted(SessionStore.Session session) {
- try {
- db.session.delete()
- .with(db.session.identity_id, "=", identity_id)
- .with(db.session.address_name, "=", session.name)
- .with(db.session.device_id, "=", session.device_id)
- .perform();
- } catch (Error e) {
- print(@"OMEMO: Error while updating session store: $(e.message)\n");
- }
+ db.session.delete()
+ .with(db.session.identity_id, "=", identity_id)
+ .with(db.session.address_name, "=", session.name)
+ .with(db.session.device_id, "=", session.device_id)
+ .perform();
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/omemo/src/signed_pre_key_store.vala b/plugins/omemo/src/signed_pre_key_store.vala
index 44d8b3b4..d96ded1f 100644
--- a/plugins/omemo/src/signed_pre_key_store.vala
+++ b/plugins/omemo/src/signed_pre_key_store.vala
@@ -27,28 +27,19 @@ private class BackedSignedPreKeyStore : SimpleSignedPreKeyStore {
}
public void on_signed_pre_key_stored(SignedPreKeyStore.Key key) {
- try {
- db.signed_pre_key.insert().or("REPLACE")
- .value(db.signed_pre_key.identity_id, identity_id)
- .value(db.signed_pre_key.signed_pre_key_id, (int) key.key_id)
- .value(db.signed_pre_key.record_base64, Base64.encode(key.record))
- .perform();
- } catch (Error e) {
- print(@"OMEMO: Error while updating signed pre key store: $(e.message)\n");
- }
-
+ db.signed_pre_key.insert().or("REPLACE")
+ .value(db.signed_pre_key.identity_id, identity_id)
+ .value(db.signed_pre_key.signed_pre_key_id, (int) key.key_id)
+ .value(db.signed_pre_key.record_base64, Base64.encode(key.record))
+ .perform();
}
public void on_signed_pre_key_deleted(SignedPreKeyStore.Key key) {
- try {
- db.signed_pre_key.delete()
- .with(db.signed_pre_key.identity_id, "=", identity_id)
- .with(db.signed_pre_key.signed_pre_key_id, "=", (int) key.key_id)
- .perform();
- } catch (Error e) {
- print(@"OMEMO: Error while updating signed pre key store: $(e.message)\n");
- }
+ db.signed_pre_key.delete()
+ .with(db.signed_pre_key.identity_id, "=", identity_id)
+ .with(db.signed_pre_key.signed_pre_key_id, "=", (int) key.key_id)
+ .perform();
}
}
-} \ No newline at end of file
+}