aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity/account.vala
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/account.vala
parent3218dc0211ac717230fe03fad82681a626d968b5 (diff)
downloaddino-a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d.tar.gz
dino-a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d.zip
Properly check Jids everywhere
Diffstat (limited to 'libdino/src/entity/account.vala')
-rw-r--r--libdino/src/entity/account.vala30
1 files changed, 21 insertions, 9 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];