diff options
author | Marvin W <git@larma.de> | 2019-12-22 04:10:53 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2019-12-23 16:58:53 +0100 |
commit | a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d (patch) | |
tree | cbb079649066c2001b6d6881137108e70eed9d3f /main/src/ui/add_conversation | |
parent | 3218dc0211ac717230fe03fad82681a626d968b5 (diff) | |
download | dino-a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d.tar.gz dino-a0a956ee0878d24bd06be7f5d75dc4ccd4e7901d.zip |
Properly check Jids everywhere
Diffstat (limited to 'main/src/ui/add_conversation')
5 files changed, 97 insertions, 68 deletions
diff --git a/main/src/ui/add_conversation/add_conference_dialog.vala b/main/src/ui/add_conversation/add_conference_dialog.vala index ecafc9cc..a03f3db6 100644 --- a/main/src/ui/add_conversation/add_conference_dialog.vala +++ b/main/src/ui/add_conversation/add_conference_dialog.vala @@ -159,7 +159,7 @@ public class AddConferenceDialog : Gtk.Dialog { } private void set_ok_sensitive_from_details() { - ok_button.sensitive = select_fragment.done; + ok_button.sensitive = details_fragment.done; } private void on_next_button_clicked() { diff --git a/main/src/ui/add_conversation/add_contact_dialog.vala b/main/src/ui/add_conversation/add_contact_dialog.vala index 33f6fa72..7e9b5185 100644 --- a/main/src/ui/add_conversation/add_contact_dialog.vala +++ b/main/src/ui/add_conversation/add_contact_dialog.vala @@ -39,17 +39,24 @@ protected class AddContactDialog : Gtk.Dialog { private void on_ok_button_clicked() { string? alias = alias_entry.text == "" ? null : alias_entry.text; - Jid jid = new Jid(jid_entry.text); - stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias); - stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); - close(); + try { + Jid jid = new Jid(jid_entry.text); + stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias); + stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); + close(); + } catch (InvalidJidError e) { + warning("Tried to add contact with invalid Jid: %s", e.message); + } } private void on_jid_entry_changed() { - Jid parsed_jid = Jid.parse(jid_entry.text); - bool sensitive = parsed_jid != null && parsed_jid.resourcepart == null && - stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, parsed_jid) == null; - ok_button.set_sensitive(sensitive); + try { + Jid parsed_jid = new Jid(jid_entry.text); + ok_button. sensitive = parsed_jid != null && parsed_jid.resourcepart == null && + stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, parsed_jid) == null; + } catch (InvalidJidError e) { + ok_button.sensitive = false; + } } } diff --git a/main/src/ui/add_conversation/add_groupchat_dialog.vala b/main/src/ui/add_conversation/add_groupchat_dialog.vala index 33a3a455..da6b10b2 100644 --- a/main/src/ui/add_conversation/add_groupchat_dialog.vala +++ b/main/src/ui/add_conversation/add_groupchat_dialog.vala @@ -52,29 +52,41 @@ protected class AddGroupchatDialog : Gtk.Dialog { private bool on_jid_key_release() { check_ok(); if (!alias_entry_changed) { - Jid? parsed_jid = Jid.parse(jid_entry.text); - alias_entry.text = parsed_jid != null && parsed_jid.localpart != null ? parsed_jid.localpart : jid_entry.text; + try { + Jid parsed_jid = new Jid(jid_entry.text); + alias_entry.text = parsed_jid != null && parsed_jid.localpart != null ? parsed_jid.localpart : jid_entry.text; + } catch (InvalidJidError e) { + alias_entry.text = jid_entry.text; + } } return false; } private bool check_ok() { - Jid? parsed_jid = Jid.parse(jid_entry.text); - ok_button.sensitive = parsed_jid != null && parsed_jid.localpart != null && parsed_jid.resourcepart == null; + try { + Jid parsed_jid = new Jid(jid_entry.text); + ok_button.sensitive = parsed_jid != null && parsed_jid.localpart != null && parsed_jid.resourcepart == null; + } catch (InvalidJidError e) { + ok_button.sensitive = false; + } return false; } private void on_ok_button_clicked() { - Conference conference = new Conference(); - conference.jid = Jid.parse(jid_entry.text); - conference.nick = nick_entry.text != "" ? nick_entry.text : null; - conference.name = alias_entry.text; - if (edit_conference == null) { - stream_interactor.get_module(MucManager.IDENTITY).add_bookmark(account_combobox.selected, conference); - } else { - stream_interactor.get_module(MucManager.IDENTITY).replace_bookmark(account_combobox.selected, edit_conference, conference); + try { + Conference conference = new Conference(); + conference.jid = new Jid(jid_entry.text); + conference.nick = nick_entry.text != "" ? nick_entry.text : null; + conference.name = alias_entry.text; + if (edit_conference == null) { + stream_interactor.get_module(MucManager.IDENTITY).add_bookmark(account_combobox.selected, conference); + } else { + stream_interactor.get_module(MucManager.IDENTITY).replace_bookmark(account_combobox.selected, edit_conference, conference); + } + close(); + } catch (InvalidJidError e) { + warning("Ignoring invalid conference Jid: %s", e.message); } - close(); } } diff --git a/main/src/ui/add_conversation/conference_details_fragment.vala b/main/src/ui/add_conversation/conference_details_fragment.vala index 38232633..d0a4c42e 100644 --- a/main/src/ui/add_conversation/conference_details_fragment.vala +++ b/main/src/ui/add_conversation/conference_details_fragment.vala @@ -14,9 +14,12 @@ protected class ConferenceDetailsFragment : Box { public bool done { get { - Jid? parsed_jid = Jid.parse(jid); - return parsed_jid != null && parsed_jid.localpart != null && - parsed_jid.resourcepart == null && nick != ""; + try { + Jid parsed_jid = new Jid(jid); + return parsed_jid.localpart != null && parsed_jid.resourcepart == null && nick != null; + } catch (InvalidJidError e) { + return false; + } } private set {} } @@ -146,43 +149,46 @@ protected class ConferenceDetailsFragment : Box { ok_button.label = _("Joining…"); ok_button.sensitive = false; - Jid parsed_jid = new Jid(jid); - Muc.JoinResult? join_result = yield stream_interactor.get_module(MucManager.IDENTITY).join(account, parsed_jid, nick, password); - - ok_button.label = _("Join"); - ok_button.sensitive = true; - if (join_result == null || join_result.nick != null) { - Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(parsed_jid, account, Conversation.Type.GROUPCHAT); + string label_text = ""; + try { + Jid parsed_jid = new Jid(jid); + Muc.JoinResult? join_result = yield stream_interactor.get_module(MucManager.IDENTITY).join(account, parsed_jid, nick, password); + + ok_button.label = _("Join"); + ok_button.sensitive = true; + if (join_result == null || join_result.nick != null) { + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(parsed_jid, account, Conversation.Type.GROUPCHAT); Application app = GLib.Application.get_default() as Application; - app.controller.select_conversation(conversation); - joined(); - return; - } + app.controller.select_conversation(conversation);joined(); + return; + } - string label_text = ""; - if (join_result.muc_error != null) { - switch (join_result.muc_error) { - case Muc.MucEnterError.PASSWORD_REQUIRED: - label_text = _("Password required to enter room"); - password_text_label.visible = true; - password_stack.visible = true; - break; - case Muc.MucEnterError.BANNED: - label_text = _("Banned from joining or creating conference"); break; - case Muc.MucEnterError.ROOM_DOESNT_EXIST: - label_text = _("Room does not exist"); break; - case Muc.MucEnterError.CREATION_RESTRICTED: - label_text = _("Not allowed to create room"); break; - case Muc.MucEnterError.NOT_IN_MEMBER_LIST: - label_text = _("Members-only room"); break; - case Muc.MucEnterError.USE_RESERVED_ROOMNICK: - case Muc.MucEnterError.NICK_CONFLICT: - label_text = _("Choose a different nick"); break; - case Muc.MucEnterError.OCCUPANT_LIMIT_REACHED: - label_text = _("Too many occupants in room"); break; + if (join_result.muc_error != null) { + switch (join_result.muc_error) { + case Muc.MucEnterError.PASSWORD_REQUIRED: + label_text = _("Password required to enter room"); + password_text_label.visible = true; + password_stack.visible = true; + break; + case Muc.MucEnterError.BANNED: + label_text = _("Banned from joining or creating conference"); break; + case Muc.MucEnterError.ROOM_DOESNT_EXIST: + label_text = _("Room does not exist"); break; + case Muc.MucEnterError.CREATION_RESTRICTED: + label_text = _("Not allowed to create room"); break; + case Muc.MucEnterError.NOT_IN_MEMBER_LIST: + label_text = _("Members-only room"); break; + case Muc.MucEnterError.USE_RESERVED_ROOMNICK: + case Muc.MucEnterError.NICK_CONFLICT: + label_text = _("Choose a different nick"); break; + case Muc.MucEnterError.OCCUPANT_LIMIT_REACHED: + label_text = _("Too many occupants in room"); break; + } + } else if (join_result.stanza_error != null) { + label_text = _("Could not connect to %s").printf((new Jid(jid)).domainpart); } - } else if (join_result.stanza_error != null) { - label_text = _("Could not connect to %s").printf((new Jid(jid)).domainpart); + } catch (InvalidJidError e) { + label_text = _("Invalid address"); } notification_label.label = label_text; notification_revealer.set_reveal_child(true); diff --git a/main/src/ui/add_conversation/select_jid_fragment.vala b/main/src/ui/add_conversation/select_jid_fragment.vala index 09792c75..f0170cfb 100644 --- a/main/src/ui/add_conversation/select_jid_fragment.vala +++ b/main/src/ui/add_conversation/select_jid_fragment.vala @@ -53,13 +53,17 @@ public class SelectJidFragment : Gtk.Box { string[] ? values = str == "" ? null : str.split(" "); filterable_list.set_filter_values(values); - Jid? parsed_jid = Jid.parse(str); - if (parsed_jid != null && parsed_jid.localpart != null) { - foreach (Account account in accounts) { - AddListRow row = new AddListRow(stream_interactor, str, account); - filterable_list.add(row); - added_rows.add(row); + try { + Jid parsed_jid = new Jid(str); + if (parsed_jid != null && parsed_jid.localpart != null) { + foreach (Account account in accounts) { + AddListRow row = new AddListRow(stream_interactor, parsed_jid, account); + filterable_list.add(row); + added_rows.add(row); + } } + } catch (InvalidJidError ignored) { + // Ignore } } @@ -82,11 +86,11 @@ public class SelectJidFragment : Gtk.Box { private class AddListRow : ListRow { - public AddListRow(StreamInteractor stream_interactor, string jid, Account account) { + public AddListRow(StreamInteractor stream_interactor, Jid jid, Account account) { this.account = account; - this.jid = new Jid(jid); + this.jid = jid; - name_label.label = jid; + name_label.label = jid.to_string(); if (stream_interactor.get_accounts().size > 1) { via_label.label = account.bare_jid.to_string(); } else { |