diff options
author | fiaxh <git@mx.ax.lt> | 2017-10-29 15:15:28 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-10-31 15:41:45 +0100 |
commit | 0102abeec1d2055b19dccbb7edc7f06e527642b1 (patch) | |
tree | 4018e82224c19142c4a7a6eced67d9c2550b2dd8 | |
parent | b9df78e4494879752e9e68dcc5d54e03fffe9467 (diff) | |
download | dino-0102abeec1d2055b19dccbb7edc7f06e527642b1.tar.gz dino-0102abeec1d2055b19dccbb7edc7f06e527642b1.zip |
Fix warnings
31 files changed, 160 insertions, 100 deletions
diff --git a/libdino/src/plugin/interfaces.vala b/libdino/src/plugin/interfaces.vala index 655ef13a..852aa596 100644 --- a/libdino/src/plugin/interfaces.vala +++ b/libdino/src/plugin/interfaces.vala @@ -64,7 +64,7 @@ public interface TextCommand : Object { public interface ConversationTitlebarEntry : Object { public abstract string id { get; } public abstract double order { get; } - public abstract ConversationTitlebarWidget get_widget(WidgetType type); + public abstract ConversationTitlebarWidget? get_widget(WidgetType type); } public interface ConversationTitlebarWidget : Object { @@ -94,7 +94,7 @@ public abstract class MetaConversationItem : Object { public abstract bool requires_avatar { get; set; } public abstract bool requires_header { get; set; } - public abstract Object get_widget(WidgetType type); + public abstract Object? get_widget(WidgetType type); } public interface ConversationItemCollection : Object { @@ -110,7 +110,7 @@ public interface MessageDisplayProvider : Object { } public interface FileWidget : Object { - public abstract Object get_widget(WidgetType type); + public abstract Object? get_widget(WidgetType type); } public interface FileDisplayProvider : Object { diff --git a/libdino/src/plugin/loader.vala b/libdino/src/plugin/loader.vala index 43876b92..102bf3f9 100644 --- a/libdino/src/plugin/loader.vala +++ b/libdino/src/plugin/loader.vala @@ -26,7 +26,7 @@ public class Loader : Object { this.search_paths = app.search_path_generator.get_plugin_paths(); } - public void loadAll() { + public void loadAll() throws Error { if (Module.supported() == false) { throw new Error(-1, 0, "Plugins are not supported"); } @@ -95,4 +95,4 @@ public class Loader : Object { } } -}
\ No newline at end of file +} diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index 3f945f4c..60cd335a 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -59,7 +59,6 @@ public class ConnectionManager { private class RecMutexWrap { public RecMutex mutex = RecMutex(); - public void lock() { mutex.lock(); } public void unlock() { mutex.unlock(); } public bool trylock() { return mutex.trylock(); } } diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index aaceede1..6b75b800 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -199,7 +199,9 @@ public class Database : Qlite.Database { roster = new RosterTable(this); settings = new SettingsTable(this); init({ account, jid, message, real_jid, file_transfer, conversation, avatar, entity_feature, roster, settings }); - exec("PRAGMA synchronous=0"); + try { + exec("PRAGMA synchronous=0"); + } catch (Error e) { } } public override void migrate(long oldVersion) { diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index 92ca7506..571bbaab 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -35,9 +35,6 @@ public class FileManager : StreamInteractionModule, Object { } public void send_file(string uri, Conversation conversation) { - File file = File.new_for_path(uri); - FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); - FileTransfer file_transfer = new FileTransfer(); file_transfer.account = conversation.account; file_transfer.counterpart = conversation.counterpart; @@ -46,11 +43,16 @@ public class FileManager : StreamInteractionModule, Object { file_transfer.time = new DateTime.now_utc(); file_transfer.local_time = new DateTime.now_utc(); file_transfer.encryption = Encryption.NONE; - file_transfer.file_name = file_info.get_display_name(); - file_transfer.input_stream = file.read(); - - file_transfer.mime_type = file_info.get_content_type(); - file_transfer.size = (int)file_info.get_size(); + try { + File file = File.new_for_path(uri); + FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); + file_transfer.file_name = file_info.get_display_name(); + file_transfer.mime_type = file_info.get_content_type(); + file_transfer.size = (int)file_info.get_size(); + file_transfer.input_stream = file.read(); + } catch (Error e) { + file_transfer.state = FileTransfer.State.FAILED; + } save_file(file_transfer); file_transfer.persist(db); @@ -90,7 +92,7 @@ public class FileManager : StreamInteractionModule, Object { File file = File.new_for_path(Path.build_filename(get_storage_dir(), file_transfer.path ?? file_transfer.file_name)); try { file_transfer.input_stream = file.read(); - } catch (IOError e) { } + } catch (Error e) { } ret.insert(0, file_transfer); } return ret; @@ -123,27 +125,29 @@ public class FileManager : StreamInteractionModule, Object { } save_file(file_transfer); - File file = File.new_for_path(file_transfer.get_uri()); - FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); - file_transfer.mime_type = file_info.get_content_type(); + try { + File file = File.new_for_path(file_transfer.get_uri()); + FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); + file_transfer.mime_type = file_info.get_content_type(); + } catch (Error e) { } file_transfer.persist(db); received_file(file_transfer); } private void save_file(FileTransfer file_transfer) { - string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name; - File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename)); try { + string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name; + File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename)); OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION); os.splice(file_transfer.input_stream, 0); os.close(); file_transfer.state = FileTransfer.State.COMPLETE; + file_transfer.path = filename; + file_transfer.input_stream = file.read(); } catch (Error e) { file_transfer.state = FileTransfer.State.FAILED; } - file_transfer.path = filename; - file_transfer.input_stream = file.read(); } } diff --git a/main/src/ui/avatar_generator.vala b/main/src/ui/avatar_generator.vala index 7e44f7e2..dce8e3d6 100644 --- a/main/src/ui/avatar_generator.vala +++ b/main/src/ui/avatar_generator.vala @@ -152,16 +152,18 @@ public class AvatarGenerator { Context rectancle_context = new Context(new ImageSurface(Format.ARGB32, width, height)); draw_colored_rectangle(rectancle_context, hex_color, width, height); - Pixbuf icon_pixbuf = IconTheme.get_default().load_icon(icon, ICON_SIZE, IconLookupFlags.FORCE_SIZE); - Surface icon_surface = cairo_surface_create_from_pixbuf(icon_pixbuf, 1, null); - Context context = new Context(icon_surface); - context.set_operator(Operator.IN); - context.set_source_rgba(1, 1, 1, 1); - context.rectangle(0, 0, width, height); - context.fill(); - - rectancle_context.set_source_surface(icon_surface, width / 2 - ICON_SIZE / 2, height / 2 - ICON_SIZE / 2); - rectancle_context.paint(); + try { + Pixbuf icon_pixbuf = IconTheme.get_default().load_icon(icon, ICON_SIZE, IconLookupFlags.FORCE_SIZE); + Surface icon_surface = cairo_surface_create_from_pixbuf(icon_pixbuf, 1, null); + Context context = new Context(icon_surface); + context.set_operator(Operator.IN); + context.set_source_rgba(1, 1, 1, 1); + context.rectangle(0, 0, width, height); + context.fill(); + + rectancle_context.set_source_surface(icon_surface, width / 2 - ICON_SIZE / 2, height / 2 - ICON_SIZE / 2); + rectancle_context.paint(); + } catch (Error e) { warning(@"Icon $icon does not exist"); } return pixbuf_get_from_surface(rectancle_context.get_target(), 0, 0, width, height); } diff --git a/main/src/ui/chat_input/edit_history.vala b/main/src/ui/chat_input/edit_history.vala index 2ac0b88a..82e6cbc5 100644 --- a/main/src/ui/chat_input/edit_history.vala +++ b/main/src/ui/chat_input/edit_history.vala @@ -8,7 +8,6 @@ namespace Dino.Ui.ChatInput { class EditHistory { - private StreamInteractor stream_interactor; private Conversation? conversation; private TextView text_input; @@ -16,7 +15,6 @@ class EditHistory { private HashMap<Conversation, int> indices = new HashMap<Conversation, int>(Conversation.hash_func, Conversation.equals_func); public EditHistory(TextView text_input, GLib.Application application) { - this.stream_interactor = stream_interactor; this.text_input = text_input; text_input.key_press_event.connect(on_text_input_key_press); diff --git a/main/src/ui/conversation_summary/chat_state_populator.vala b/main/src/ui/conversation_summary/chat_state_populator.vala index 06d0cf87..e491fe44 100644 --- a/main/src/ui/conversation_summary/chat_state_populator.vala +++ b/main/src/ui/conversation_summary/chat_state_populator.vala @@ -53,7 +53,6 @@ class ChatStatePopulator : Plugins.ConversationItemPopulator, Object { string? new_text = null; if (state_ != null) { if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING || state_ == Xep.ChatStateNotifications.STATE_PAUSED) { - string display_name = Util.get_display_name(stream_interactor, jid, account); if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING) { new_text = _("is typing..."); } else if (state_ == Xep.ChatStateNotifications.STATE_PAUSED) { @@ -95,7 +94,7 @@ public class MetaChatStateItem : Plugins.MetaConversationItem { this.text = text; } - public override Object get_widget(Plugins.WidgetType widget_type) { + public override Object? get_widget(Plugins.WidgetType widget_type) { label = new Label("") { xalign=0, vexpand=true, visible=true }; label.get_style_context().add_class("dim-label"); update_text(); diff --git a/main/src/ui/conversation_summary/default_message_display.vala b/main/src/ui/conversation_summary/default_message_display.vala index 44040a3b..f843f116 100644 --- a/main/src/ui/conversation_summary/default_message_display.vala +++ b/main/src/ui/conversation_summary/default_message_display.vala @@ -44,7 +44,7 @@ public class MetaMessageItem : Plugins.MetaConversationItem { public override bool requires_avatar { get; set; default=true; } public override bool requires_header { get; set; default=true; } - public override Object get_widget(Plugins.WidgetType widget_type) { + public override Object? get_widget(Plugins.WidgetType widget_type) { MessageTextView text_view = new MessageTextView() { visible = true }; text_view.add_text(message.body); return text_view; diff --git a/main/src/ui/conversation_summary/file_populator.vala b/main/src/ui/conversation_summary/file_populator.vala index 99185f6b..0edad19e 100644 --- a/main/src/ui/conversation_summary/file_populator.vala +++ b/main/src/ui/conversation_summary/file_populator.vala @@ -79,9 +79,14 @@ public class ImageItem : Plugins.MetaConversationItem { }); } - public override Object get_widget(Plugins.WidgetType widget_type) { + public override Object? get_widget(Plugins.WidgetType widget_type) { Image image = new Image() { halign=Align.START, visible = true }; - Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri()); + Gdk.Pixbuf pixbuf; + try { + pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri()); + } catch (Error error) { + return null; + } int max_scaled_height = MAX_HEIGHT * image.scale_factor; if (pixbuf.height > max_scaled_height) { @@ -104,7 +109,6 @@ public class ImageItem : Plugins.MetaConversationItem { Util.force_color(url_label, "#eee"); file_transfer.notify["info"].connect_after(() => { update_info(url_label, file_transfer.info); }); update_info(url_label, file_transfer.info); - Box url_box = builder.get_object("url_box") as Box; Image copy_image = builder.get_object("copy_image") as Image; Util.force_css(copy_image, "*:not(:hover) { color: #eee; }"); diff --git a/main/src/ui/conversation_summary/message_textview.vala b/main/src/ui/conversation_summary/message_textview.vala index f2a4ca22..77b2d707 100644 --- a/main/src/ui/conversation_summary/message_textview.vala +++ b/main/src/ui/conversation_summary/message_textview.vala @@ -51,7 +51,6 @@ public class MessageTextView : TextView { MatchInfo match_info; url_regex.match(text, 0, out match_info); for (; match_info.matches(); match_info.next()) { - string? url = match_info.fetch(0); int start; int end; match_info.fetch_pos(0, out start, out end); diff --git a/main/src/ui/conversation_summary/slashme_message_display.vala b/main/src/ui/conversation_summary/slashme_message_display.vala index cb3d5cd2..92596936 100644 --- a/main/src/ui/conversation_summary/slashme_message_display.vala +++ b/main/src/ui/conversation_summary/slashme_message_display.vala @@ -50,7 +50,7 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem { public override bool requires_avatar { get; set; default=true; } public override bool requires_header { get; set; default=false; } - public override Object get_widget(Plugins.WidgetType widget_type) { + public override Object? get_widget(Plugins.WidgetType widget_type) { text_view = new MessageTextView() { valign=Align.CENTER, vexpand=true, visible = true }; string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account); @@ -67,7 +67,6 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem { } private void update_style() { - string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account); string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.real_jid ?? message.from, Util.is_dark_theme(text_view)); nick_tag.foreground = "#" + color; } diff --git a/main/src/ui/conversation_titlebar/file_entry.vala b/main/src/ui/conversation_titlebar/file_entry.vala index df173192..cb7d0807 100644 --- a/main/src/ui/conversation_titlebar/file_entry.vala +++ b/main/src/ui/conversation_titlebar/file_entry.vala @@ -14,7 +14,7 @@ public class FileEntry : Plugins.ConversationTitlebarEntry, Object { } public double order { get { return 4; } } - public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { + public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { if (type == Plugins.WidgetType.GTK) { return new FileWidget(stream_interactor) { visible=true }; } diff --git a/main/src/ui/conversation_titlebar/menu_entry.vala b/main/src/ui/conversation_titlebar/menu_entry.vala index e6e5e1b4..51b8051c 100644 --- a/main/src/ui/conversation_titlebar/menu_entry.vala +++ b/main/src/ui/conversation_titlebar/menu_entry.vala @@ -14,7 +14,7 @@ class MenuEntry : Plugins.ConversationTitlebarEntry, Object { } public double order { get { return 0; } } - public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { + public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { if (type == Plugins.WidgetType.GTK) { return new MenuWidget(stream_interactor) { visible=true }; } diff --git a/main/src/ui/conversation_titlebar/occupants_entry.vala b/main/src/ui/conversation_titlebar/occupants_entry.vala index 904a832a..d6ce7f68 100644 --- a/main/src/ui/conversation_titlebar/occupants_entry.vala +++ b/main/src/ui/conversation_titlebar/occupants_entry.vala @@ -16,7 +16,7 @@ class OccupantsEntry : Plugins.ConversationTitlebarEntry, Object { } public double order { get { return 3; } } - public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { + public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { if (type == Plugins.WidgetType.GTK) { return new OccupantsWidget(stream_interactor, window) { visible=true }; } diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index cfbec8dc..464f5b0d 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -92,7 +92,9 @@ public class Notifications : Object { } notifications[conversation].set_title(display_name); notifications[conversation].set_body(text); - notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation))); + try { + notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation))); + } catch (Error e) { } window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]); active_notification_ids.add(conversation.id.to_string()); window.urgency_hint = true; @@ -102,7 +104,9 @@ public class Notifications : Object { private void on_received_subscription_request(Jid jid, Account account) { Notification notification = new Notification(_("Subscription request")); notification.set_body(jid.bare_jid.to_string()); - notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account))); + try { + notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account))); + } catch (Error e) { } Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id); notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id); @@ -119,7 +123,7 @@ public class Notifications : Object { return true; } - private Icon get_pixbuf_icon(Gdk.Pixbuf avatar) { + private Icon get_pixbuf_icon(Gdk.Pixbuf avatar) throws Error { uint8[] buffer; avatar.save_to_buffer(out buffer, "png"); return new BytesIcon(new Bytes(buffer)); diff --git a/plugins/gpgme-vala/vapi/gpgme.vapi b/plugins/gpgme-vala/vapi/gpgme.vapi index 51823a15..55031bfa 100644 --- a/plugins/gpgme-vala/vapi/gpgme.vapi +++ b/plugins/gpgme-vala/vapi/gpgme.vapi @@ -466,7 +466,7 @@ namespace GPG { [CCode (cname = "gpgme_data_new_from_file")] public static GPGError.Error new_from_file(out Data d, string filename, int copy = 1); - public static Data create_from_file(string filename, int copy = 1) { + public static Data create_from_file(string filename, int copy = 1) throws GLib.Error { Data data; throw_if_error(new_from_file(out data, filename, copy)); return data; diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala index 9e677a92..53fe3bb0 100644 --- a/plugins/http-files/src/file_provider.vala +++ b/plugins/http-files/src/file_provider.vala @@ -48,8 +48,13 @@ public class FileProvider : Dino.FileProvider, Object { if (name == "Content-Length") content_length = val; }); if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) { - Soup.Request request = session.request (message.body); FileTransfer file_transfer = new FileTransfer(); + try { + Soup.Request request = session.request(message.body); + file_transfer.input_stream = request.send(); + } catch (Error e) { + return; + } file_transfer.account = conversation.account; file_transfer.counterpart = message.counterpart; file_transfer.ourpart = message.ourpart; @@ -57,7 +62,6 @@ public class FileProvider : Dino.FileProvider, Object { file_transfer.time = message.time; file_transfer.local_time = message.local_time; file_transfer.direction = message.direction; - file_transfer.input_stream = request.send(); file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1); file_transfer.mime_type = content_type; file_transfer.size = int.parse(content_length); diff --git a/plugins/http-files/src/upload_stream_module.vala b/plugins/http-files/src/upload_stream_module.vala index ee70e49d..08e6105f 100644 --- a/plugins/http-files/src/upload_stream_module.vala +++ b/plugins/http-files/src/upload_stream_module.vala @@ -21,7 +21,11 @@ public class UploadStreamModule : XmppStreamModule { Array<uint8> data = new Array<uint8>(false, true, 0); size_t len = -1; do { - len = input_stream.read(buf); + try { + len = input_stream.read(buf); + } catch (IOError error) { + error_listener(stream, @"HTTP upload: IOError reading stream: $(error.message)"); + } data.append_vals(buf, (uint) len); } while(len > 0); @@ -41,7 +45,7 @@ public class UploadStreamModule : XmppStreamModule { } }); }, - error_listener); + (stream, error) => error_listener(stream, error)); } private delegate void OnSlotOk(XmppStream stream, string url_get, string url_put); diff --git a/plugins/omemo/src/account_settings_dialog.vala b/plugins/omemo/src/account_settings_dialog.vala index 373d02aa..4a63ef2f 100644 --- a/plugins/omemo/src/account_settings_dialog.vala +++ b/plugins/omemo/src/account_settings_dialog.vala @@ -17,6 +17,7 @@ public class AccountSettingsDialog : Gtk.Dialog { public AccountSettingsDialog(Plugin plugin, Account account) { Object(use_header_bar : 1); this.plugin = plugin; + this.account = account; string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64]; fingerprint = fingerprint_from_base64(own_b64); @@ -50,4 +51,4 @@ public class AccountSettingsDialog : Gtk.Dialog { } -}
\ No newline at end of file +} diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala index 52a1b15d..5c7309f3 100644 --- a/plugins/omemo/src/database.vala +++ b/plugins/omemo/src/database.vala @@ -116,7 +116,9 @@ public class Database : Qlite.Database { pre_key = new PreKeyTable(this); session = new SessionTable(this); init({identity_meta, identity, signed_pre_key, pre_key, session}); - exec("PRAGMA synchronous=0"); + try { + exec("PRAGMA synchronous=0"); + } catch (Error e) { } } public override void migrate(long oldVersion) { diff --git a/plugins/openpgp/src/contact_details_provider.vala b/plugins/openpgp/src/contact_details_provider.vala index 5529549c..b691cc19 100644 --- a/plugins/openpgp/src/contact_details_provider.vala +++ b/plugins/openpgp/src/contact_details_provider.vala @@ -18,8 +18,11 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object { string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); if (key_id != null) { Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true }; - Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id); - if (keys.size > 0) { + Gee.List<GPG.Key>? keys = null; + try { + keys = GPGHelper.get_keylist(key_id); + } catch (Error e) { } + if (keys != null && keys.size > 0) { label.label = markup_colorize_id(keys[0].fpr, true); } else { label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false); diff --git a/plugins/openpgp/src/encryption_list_entry.vala b/plugins/openpgp/src/encryption_list_entry.vala index e0a11865..d2cbd13f 100644 --- a/plugins/openpgp/src/encryption_list_entry.vala +++ b/plugins/openpgp/src/encryption_list_entry.vala @@ -23,7 +23,9 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object { public bool can_encrypt(Entities.Conversation conversation) { if (conversation.type_ == Conversation.Type.CHAT) { string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); - return key_id != null && GPGHelper.get_keylist(key_id).size > 0; + try { + return key_id != null && GPGHelper.get_keylist(key_id).size > 0; + } catch (Error e) { return false; } } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { Gee.List<Jid> muc_jids = new Gee.ArrayList<Jid>(); Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account); diff --git a/plugins/openpgp/src/in_file_processor.vala b/plugins/openpgp/src/in_file_processor.vala index 2a06bbdf..61baa37e 100644 --- a/plugins/openpgp/src/in_file_processor.vala +++ b/plugins/openpgp/src/in_file_processor.vala @@ -8,19 +8,23 @@ public class InFileProcessor : IncommingFileProcessor, Object { } public void process(FileTransfer file_transfer) { - uint8[] buf = new uint8[256]; - Array<uint8> data = new Array<uint8>(false, true, 0); - size_t len = -1; - do { - len = file_transfer.input_stream.read(buf); - data.append_vals(buf, (uint) len); - } while(len > 0); + try { + uint8[] buf = new uint8[256]; + Array<uint8> data = new Array<uint8>(false, true, 0); + size_t len = -1; + do { + len = file_transfer.input_stream.read(buf); + data.append_vals(buf, (uint) len); + } while(len > 0); - uint8[] clear_data = GPGHelper.decrypt_data(data.data); - file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free); - file_transfer.encryption = Encryption.PGP; - if (file_transfer.file_name.has_suffix(".pgp")) { - file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4); + uint8[] clear_data = GPGHelper.decrypt_data(data.data); + file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free); + file_transfer.encryption = Encryption.PGP; + if (file_transfer.file_name.has_suffix(".pgp")) { + file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4); + } + } catch (Error e) { + file_transfer.state = FileTransfer.State.FAILED; } } } diff --git a/plugins/openpgp/src/manager.vala b/plugins/openpgp/src/manager.vala index 74f6027c..3f0fe3dd 100644 --- a/plugins/openpgp/src/manager.vala +++ b/plugins/openpgp/src/manager.vala @@ -30,7 +30,7 @@ public class Manager : StreamInteractionModule, Object { stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(check_encypt); } - public GPG.Key[] get_key_fprs(Conversation conversation) { + public GPG.Key[] get_key_fprs(Conversation conversation) throws Error { Gee.List<string> keys = new Gee.ArrayList<string>(); keys.add(db.get_account_key(conversation.account)); if (conversation.type_ == Conversation.Type.GROUPCHAT) { @@ -70,13 +70,17 @@ public class Manager : StreamInteractionModule, Object { } private void check_encypt(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { - if (message.encryption == Encryption.PGP) { - GPG.Key[] keys = get_key_fprs(conversation); - Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); - if (stream != null) { - bool encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, keys); - if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND; + try { + if (message.encryption == Encryption.PGP) { + GPG.Key[] keys = get_key_fprs(conversation); + Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); + if (stream != null) { + bool encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, keys); + if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND; + } } + } catch (Error e) { + message.marked = Entities.Message.Marked.WONTSEND; } } diff --git a/plugins/openpgp/src/out_file_processor.vala b/plugins/openpgp/src/out_file_processor.vala index 81c53b16..a09e17a6 100644 --- a/plugins/openpgp/src/out_file_processor.vala +++ b/plugins/openpgp/src/out_file_processor.vala @@ -16,11 +16,15 @@ public class OutFileProcessor : OutgoingFileProcessor, Object { public void process(Conversation conversation, FileTransfer file_transfer) { string uri = file_transfer.get_uri(); - GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation); - uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST); - file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free); - file_transfer.encryption = Encryption.PGP; - file_transfer.server_file_name = file_transfer.server_file_name + ".pgp"; + try { + GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation); + uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST); + file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free); + file_transfer.encryption = Encryption.PGP; + file_transfer.server_file_name = file_transfer.server_file_name + ".pgp"; + } catch (Error e) { + file_transfer.state = FileTransfer.State.FAILED; + } } } diff --git a/qlite/src/database.vala b/qlite/src/database.vala index ad8505be..b153be73 100644 --- a/qlite/src/database.vala +++ b/qlite/src/database.vala @@ -129,7 +129,7 @@ public class Database { return statement; } - public void exec(string sql) { + public void exec(string sql) throws Error { ensure_init(); if (db.exec(sql) != OK) { throw new Error(-1, 0, @"SQLite error: $(db.errcode()) - $(db.errmsg())"); diff --git a/qlite/src/table.vala b/qlite/src/table.vala index 0d9fe2f6..00b4ef00 100644 --- a/qlite/src/table.vala +++ b/qlite/src/table.vala @@ -102,14 +102,22 @@ public class Table { } } sql += @"$constraints)"; - db.exec(sql); + try { + db.exec(sql); + } catch (Error e) { + error("Qlite Error: Create table at version"); + } } public void add_columns_for_version(long old_version, long new_version) { ensure_init(); foreach (Column c in columns) { if (c.min_version <= new_version && c.max_version >= new_version && c.min_version > old_version) { - db.exec(@"ALTER TABLE $name ADD COLUMN $c"); + try { + db.exec(@"ALTER TABLE $name ADD COLUMN $c"); + } catch (Error e) { + error("Qlite Error: Add columns for version"); + } } } } @@ -130,16 +138,24 @@ public class Table { } } if (column_deletion_required) { - db.exec(@"ALTER TABLE $name RENAME TO _$(name)_$old_version"); - create_table_at_version(new_version); - db.exec(@"INSERT INTO $name ($column_list) SELECT $column_list FROM _$(name)_$old_version"); - db.exec(@"DROP TABLE _$(name)_$old_version"); + try { + db.exec(@"ALTER TABLE $name RENAME TO _$(name)_$old_version"); + create_table_at_version(new_version); + db.exec(@"INSERT INTO $name ($column_list) SELECT $column_list FROM _$(name)_$old_version"); + db.exec(@"DROP TABLE _$(name)_$old_version"); + } catch (Error e) { + error("Qlite Error: Delete volumns for version change"); + } } } internal void post() { foreach (string stmt in post_statements) { - db.exec(stmt); + try { + db.exec(stmt); + } catch (Error e) { + error("Qlite Error: Post"); + } } } } diff --git a/xmpp-vala/src/core/stanza_reader.vala b/xmpp-vala/src/core/stanza_reader.vala index 0079dc38..f4b900d1 100644 --- a/xmpp-vala/src/core/stanza_reader.vala +++ b/xmpp-vala/src/core/stanza_reader.vala @@ -54,8 +54,6 @@ public class StanzaReader { buffer_pos = 0; } catch (GLib.IOError e) { throw new XmlError.IO_ERROR("IOError in GLib: %s".printf(e.message)); - } catch (GLib.TlsError e) { - throw new XmlError.IO_ERROR("TlsError in GLib: %s".printf(e.message)); } } diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 9d700b4d..0a1f4120 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -360,8 +360,12 @@ public class StartTlsConnectionProvider : ConnectionProvider { } public override IOStream? connect(XmppStream stream) { - SocketClient client = new SocketClient(); - return client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); + try { + SocketClient client = new SocketClient(); + return client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); + } catch (Error e) { + return null; + } } public override string get_id() { return "start_tls"; } diff --git a/xmpp-vala/src/module/xep/0368_srv_records_tls.vala b/xmpp-vala/src/module/xep/0368_srv_records_tls.vala index 154e8a4f..4c24c63e 100644 --- a/xmpp-vala/src/module/xep/0368_srv_records_tls.vala +++ b/xmpp-vala/src/module/xep/0368_srv_records_tls.vala @@ -37,10 +37,14 @@ public class TlsConnectionProvider : ConnectionProvider { public override IOStream? connect(XmppStream stream) { SocketClient client = new SocketClient(); - IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); - io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port())); - stream.add_flag(new Tls.Flag() { finished=true }); - return io_stream; + try { + IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); + io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port())); + stream.add_flag(new Tls.Flag() { finished=true }); + return io_stream; + } catch (Error e) { + return null; + } } public override string get_id() { return "start_tls"; } |