aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2019-12-22 04:10:53 +0100
committerMarvin W <git@larma.de>2019-12-23 16:58:53 +0100
commita0a956ee0878d24bd06be7f5d75dc4ccd4e7901d (patch)
treecbb079649066c2001b6d6881137108e70eed9d3f /libdino/src/entity
parent3218dc0211ac717230fe03fad82681a626d968b5 (diff)
downloaddino-a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d.tar.gz
dino-a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d.zip
Properly check Jids everywhere
Diffstat (limited to 'libdino/src/entity')
-rw-r--r--libdino/src/entity/account.vala30
-rw-r--r--libdino/src/entity/conversation.vala2
-rw-r--r--libdino/src/entity/file_transfer.vala2
-rw-r--r--libdino/src/entity/message.vala2
4 files changed, 24 insertions, 12 deletions
diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala
index f7257b5a..3eb75505 100644
--- a/libdino/src/entity/account.vala
+++ b/libdino/src/entity/account.vala
@@ -6,10 +6,11 @@ namespace Dino.Entities {
public class Account : Object {
public int id { get; set; }
- public string localpart { get { return bare_jid.localpart; } }
- public string domainpart { get { return bare_jid.domainpart; } }
- public string resourcepart { get; set; }
- public Jid bare_jid { get; private set; }
+ public string localpart { get { return full_jid.localpart; } }
+ public string domainpart { get { return full_jid.domainpart; } }
+ public string resourcepart { get { return full_jid.resourcepart;} }
+ public Jid bare_jid { owned get { return full_jid.bare_jid; } }
+ public Jid full_jid { get; private set; }
public string? password { get; set; }
public string display_name {
owned get { return alias ?? bare_jid.to_string(); }
@@ -23,17 +24,28 @@ public class Account : Object {
public Account(Jid bare_jid, string? resourcepart, string? password, string? alias) {
this.id = -1;
- this.resourcepart = resourcepart ?? "dino." + Random.next_int().to_string("%x");
- this.bare_jid = bare_jid;
+ if (resourcepart != null) {
+ try {
+ this.full_jid = bare_jid.with_resource(resourcepart);
+ } catch (InvalidJidError e) {
+ warning("Tried to create account with invalid resource (%s), defaulting to auto generated", e.message);
+ }
+ }
+ if (this.full_jid == null) {
+ try {
+ this.full_jid = bare_jid.with_resource("dino." + Random.next_int().to_string("%x"));
+ } catch (InvalidJidError e) {
+ error("Auto-generated resource was invalid (%s)", e.message);
+ }
+ }
this.password = password;
this.alias = alias;
}
- public Account.from_row(Database db, Qlite.Row row) {
+ public Account.from_row(Database db, Qlite.Row row) throws InvalidJidError {
this.db = db;
id = row[db.account.id];
- resourcepart = row[db.account.resourcepart];
- bare_jid = new Jid(row[db.account.bare_jid]);
+ full_jid = new Jid(row[db.account.bare_jid]).with_resource(row[db.account.resourcepart]);
password = row[db.account.password];
alias = row[db.account.alias];
enabled = row[db.account.enabled];
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index 53c59bd2..d0ba4920 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -47,7 +47,7 @@ public class Conversation : Object {
this.type_ = type;
}
- public Conversation.from_row(Database db, Qlite.Row row) {
+ public Conversation.from_row(Database db, Qlite.Row row) throws InvalidJidError {
this.db = db;
id = row[db.conversation.id];
diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala
index 9c0099d0..a8e386bf 100644
--- a/libdino/src/entity/file_transfer.vala
+++ b/libdino/src/entity/file_transfer.vala
@@ -63,7 +63,7 @@ public class FileTransfer : Object {
private Database? db;
private string storage_dir;
- public FileTransfer.from_row(Database db, Qlite.Row row, string storage_dir) {
+ public FileTransfer.from_row(Database db, Qlite.Row row, string storage_dir) throws InvalidJidError {
this.db = db;
this.storage_dir = storage_dir;
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index 4b16d12c..d5697c72 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -60,7 +60,7 @@ public class Message : Object {
this.body = body;
}
- public Message.from_row(Database db, Qlite.Row row) {
+ public Message.from_row(Database db, Qlite.Row row) throws InvalidJidError {
this.db = db;
id = row[db.message.id];