From 87ef75d941fa9cb126c2534c16146f3aa2012e6e Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Tue, 28 Jan 2020 22:16:29 +0100 Subject: [PATCH] many: fix build, warnings Signed-off-by: Maciek Borzecki --- src/mconnect/application.vala | 11 +++++--- src/mconnect/device-proxy.vala | 15 +++-------- src/mconnect/device.vala | 6 ++--- src/mconnect/devicechannel.vala | 7 +++--- src/mconnect/devicemanager-proxy.vala | 19 ++++++++------ src/mconnect/discovery.vala | 2 +- src/mconnect/logging.vala | 2 +- src/mconnect/mpris-proxies.vala | 12 ++++----- src/mconnect/mpris.vala | 9 ++++--- .../packethandlerinterface-proxy.vala | 6 ++--- src/mconnect/share-proxy.vala | 12 ++++----- src/mconnect/share.vala | 10 +++++--- src/mconnect/telephony-proxy.vala | 4 +-- src/mconnect/transfer-download.vala | 25 +++++++++++-------- src/mconnect/transfer-manager-proxy.vala | 6 ++--- src/mconnect/transfer-manager.vala | 3 ++- src/mconnect/transfer-proxy.vala | 8 +++--- src/mconnect/transfer-upload.vala | 12 ++++++--- src/mconnect/utils.vala | 7 +++--- src/mconnectctl/device-manager-iface.vala | 6 ++--- src/mconnectctl/share-iface.vala | 8 +++--- src/mconnectctl/telephony-iface.vala | 4 +-- test/mconn-crypt-vala-test.vala | 5 ++-- 23 files changed, 105 insertions(+), 94 deletions(-) diff --git a/src/mconnect/application.vala b/src/mconnect/application.vala index f14f48f..3159532 100644 --- a/src/mconnect/application.vala +++ b/src/mconnect/application.vala @@ -53,12 +53,15 @@ namespace Mconn { base.startup (); + if (log_debug_verbose == true) { + Logging.enable_vdebug (); + // enable debug logging when verbose is enabled + log_debug = true; + } + if (log_debug == true) Environment.set_variable ("G_MESSAGES_DEBUG", "all", false); - if (log_debug_verbose == true) - Logging.enable_vdebug (); - core = Core.instance (); if (core == null) error ("cannot initialize core"); @@ -112,4 +115,4 @@ namespace Mconn { debug ("dbus unregister, path %s", object_path); } } -} \ No newline at end of file +} diff --git a/src/mconnect/device-proxy.vala b/src/mconnect/device-proxy.vala index 6aa7eb4..83b970a 100644 --- a/src/mconnect/device-proxy.vala +++ b/src/mconnect/device-proxy.vala @@ -30,7 +30,6 @@ class DeviceDBusProxy : Object { } private set { } - default = ""; } public string name { get { @@ -38,7 +37,6 @@ class DeviceDBusProxy : Object { } private set { } - default = ""; } public string device_type { get { @@ -46,7 +44,6 @@ class DeviceDBusProxy : Object { } private set { } - default = ""; } public uint protocol_version { get { @@ -54,7 +51,6 @@ class DeviceDBusProxy : Object { } private set { } - default = 5; } public string address { get; private set; default = ""; @@ -66,7 +62,6 @@ class DeviceDBusProxy : Object { } private set { } - default = false; } public bool allowed { get { @@ -74,7 +69,6 @@ class DeviceDBusProxy : Object { } private set { } - default = false; } public bool is_active { get { @@ -82,10 +76,9 @@ class DeviceDBusProxy : Object { } private set { } - default = false; } public bool is_connected { - get; private set; default = false; + get; private set; } public string[] incoming_capabilities { @@ -268,7 +261,7 @@ class DeviceDBusProxy : Object { [DBus (visible = false)] public void bus_register_handler (DBusConnection conn, string cap, - PacketHandlerInterfaceProxy handler) { + PacketHandlerInterfaceProxy handler) throws Error { handler.bus_register (conn, this.object_path); this.handlers.@set (cap, handler); @@ -276,7 +269,7 @@ class DeviceDBusProxy : Object { [DBus (visible = false)] public void bus_unregister_handler (DBusConnection conn, - string cap) { + string cap) throws Error { PacketHandlerInterfaceProxy handler; this.handlers.@unset (cap, out handler); @@ -284,4 +277,4 @@ class DeviceDBusProxy : Object { handler.bus_unregister (conn); } } -} \ No newline at end of file +} diff --git a/src/mconnect/device.vala b/src/mconnect/device.vala index 18e01ef..4fb696a 100644 --- a/src/mconnect/device.vala +++ b/src/mconnect/device.vala @@ -193,7 +193,7 @@ class Device : Object { dev.host = host; return dev; - } catch (KeyFileError e) { + } catch (Error e) { warning ("failed to load device data from cache: %s", e.message); return null; } @@ -617,7 +617,7 @@ class Device : Object { public void send (Packet pkt) { // TODO: queue messages if (this._channel != null) { - _channel.send (pkt); + _channel.send.begin (pkt); } } -} \ No newline at end of file +} diff --git a/src/mconnect/devicechannel.vala b/src/mconnect/devicechannel.vala index 11d2ab6..f85ceef 100644 --- a/src/mconnect/devicechannel.vala +++ b/src/mconnect/devicechannel.vala @@ -150,10 +150,11 @@ class DeviceChannel : Object { var cert = Core.instance ().certificate; // wrap with TLS - var tls_conn = Utils.make_tls_connection (this._sock_conn, + TlsConnection tls_conn; + try { + tls_conn = Utils.make_tls_connection (this._sock_conn, cert, expected_peer); - try { info ("attempt TLS handshake"); var res = yield tls_conn.handshake_async (); @@ -298,4 +299,4 @@ class DeviceChannel : Object { this.packet_received (pkt); } } -} \ No newline at end of file +} diff --git a/src/mconnect/devicemanager-proxy.vala b/src/mconnect/devicemanager-proxy.vala index 56e0f77..16a016f 100644 --- a/src/mconnect/devicemanager-proxy.vala +++ b/src/mconnect/devicemanager-proxy.vala @@ -25,8 +25,7 @@ class DeviceManagerDBusProxy : Object { owned get { return Core.instance ().certificate.certificate_pem; } - private set { - } + private set {} } public signal void device_added (string path); @@ -52,7 +51,7 @@ class DeviceManagerDBusProxy : Object { } [DBus (visible = false)] - public void publish () throws IOError { + public void publish () throws Error { assert (this.bus != null); this.bus.register_object (DBUS_PATH, this); @@ -64,7 +63,7 @@ class DeviceManagerDBusProxy : Object { * * Allow given device */ - public void allow_device (string path) { + public void allow_device (string path) throws Error { debug ("allow device %s", path); var dev_proxy = this.devices.@get (path); @@ -83,7 +82,7 @@ class DeviceManagerDBusProxy : Object { * * Disallow given device */ - public void disallow_device (string path) { + public void disallow_device (string path) throws Error { debug ("disallow device %s", path); var dev_proxy = this.devices.@get (path); @@ -101,7 +100,7 @@ class DeviceManagerDBusProxy : Object { * * Returns a list of DBus paths of all known devices */ - public ObjectPath[] list_devices () { + public ObjectPath[] list_devices () throws Error { ObjectPath[] devices = {}; foreach (var path in this.devices.keys) { @@ -155,7 +154,11 @@ class DeviceManagerDBusProxy : Object { capability, iface); if (h != null) { - h.bus_register (this.bus, dp.object_path); + try { + h.bus_register (this.bus, dp.object_path); + } catch (Error e) { + warning ("cannot register handler at path %s: %s", dp.object_path, e.message); + } } } @@ -172,4 +175,4 @@ class DeviceManagerDBusProxy : Object { return path; } -} \ No newline at end of file +} diff --git a/src/mconnect/discovery.vala b/src/mconnect/discovery.vala index f45d0a0..b2bdabf 100644 --- a/src/mconnect/discovery.vala +++ b/src/mconnect/discovery.vala @@ -93,4 +93,4 @@ class Discovery : GLib.Object { device_found (dev); } -} \ No newline at end of file +} diff --git a/src/mconnect/logging.vala b/src/mconnect/logging.vala index 26988da..601a215 100644 --- a/src/mconnect/logging.vala +++ b/src/mconnect/logging.vala @@ -41,4 +41,4 @@ void vdebug (string format, ...) { var l = va_list (); logv (null, LogLevelFlags.LEVEL_DEBUG, format, l); } -} \ No newline at end of file +} diff --git a/src/mconnect/mpris-proxies.vala b/src/mconnect/mpris-proxies.vala index 8670d63..9a2436a 100644 --- a/src/mconnect/mpris-proxies.vala +++ b/src/mconnect/mpris-proxies.vala @@ -19,7 +19,7 @@ [DBus (name = "org.freedesktop.DBus")] public interface DBusProxy : Object { - public abstract string[] list_names () throws IOError; + public abstract string[] list_names () throws Error; public signal void name_owner_changed (string name, string old_owner, string new_owner); } @@ -33,10 +33,10 @@ public interface DBusPropertiesProxy : Object { [DBus (name = "org.mpris.MediaPlayer2.Player")] public interface MprisPlayerProxy : Object { - public abstract void next () throws IOError; - public abstract void previous () throws IOError; - public abstract void play_pause () throws IOError; - public abstract void seek (int64 Offset) throws IOError; + public abstract void next () throws Error; + public abstract void previous () throws Error; + public abstract void play_pause () throws Error; + public abstract void seek (int64 Offset) throws Error; public abstract string playback_status { owned get; @@ -76,4 +76,4 @@ public interface MprisProxy : Object { public abstract string identity { owned get; } -} \ No newline at end of file +} diff --git a/src/mconnect/mpris.vala b/src/mconnect/mpris.vala index 3f4bce5..c64e8c1 100644 --- a/src/mconnect/mpris.vala +++ b/src/mconnect/mpris.vala @@ -173,13 +173,14 @@ class MprisHandler : Object, PacketHandlerInterface { prop.can_seek = mpris_player.can_seek; update_status (make_player_prop_packet (player_id, prop)); } - } catch (IOError e) { + } catch (Error e) { warning ("dbus communication failed: %s", e.message); return; } } private static void get_metadata_string (HashTable metadata, string meta_what, out string where) { + where = ""; if (metadata.contains (meta_what) && metadata.get (meta_what).is_of_type (VariantType.STRING)) { where = metadata.get (meta_what).get_string (); @@ -369,7 +370,7 @@ class MprisHandler : Object, PacketHandlerInterface { add_player (bus_name); } } - } catch (IOError e) { + } catch (Error e) { warning ("failed to get mpris player list: %s", e.message); } } @@ -396,7 +397,7 @@ class MprisHandler : Object, PacketHandlerInterface { bus_name, "/org/mpris/MediaPlayer2"); player_list.insert (mpris.identity, bus_name); - } catch (IOError e) { + } catch (Error e) { warning ("failed to connect to mpris player: %s", e.message); } } @@ -414,4 +415,4 @@ class MprisHandler : Object, PacketHandlerInterface { player_list.remove (key); } } -} \ No newline at end of file +} diff --git a/src/mconnect/packethandlerinterface-proxy.vala b/src/mconnect/packethandlerinterface-proxy.vala index dabb458..71bf911 100644 --- a/src/mconnect/packethandlerinterface-proxy.vala +++ b/src/mconnect/packethandlerinterface-proxy.vala @@ -20,6 +20,6 @@ * PacketHandlerInterfaceProxy: interface of DBus exported packet handler */ interface PacketHandlerInterfaceProxy : Object { - public abstract void bus_register (DBusConnection conn, string path) throws IOError; - public abstract void bus_unregister (DBusConnection conn) throws IOError; -} \ No newline at end of file + public abstract void bus_register (DBusConnection conn, string path) throws Error; + public abstract void bus_unregister (DBusConnection conn) throws Error; +} diff --git a/src/mconnect/share-proxy.vala b/src/mconnect/share-proxy.vala index a278e28..c84c7c3 100644 --- a/src/mconnect/share-proxy.vala +++ b/src/mconnect/share-proxy.vala @@ -29,25 +29,25 @@ class ShareHandlerProxy : Object, PacketHandlerInterfaceProxy { } [DBus (visible = false)] - public void bus_register (DBusConnection conn, string path) throws IOError { + public void bus_register (DBusConnection conn, string path) throws Error { conn.register_object (path, this); } [DBus (visible = false)] - public void bus_unregister (DBusConnection conn) throws IOError { + public void bus_unregister (DBusConnection conn) throws Error { // conn.unregister_object(this); } - public void share_file (string path) throws IOError { + public void share_file (string path) throws Error { this.share_handler.share_file (this.device, path); } - public void share_url (string url) throws IOError { + public void share_url (string url) throws Error { debug ("share url %s", url); this.share_handler.share_url (this.device, url); } - public void share_text (string text) throws IOError { + public void share_text (string text) throws Error { this.share_handler.share_text (this.device, text); } -} \ No newline at end of file +} diff --git a/src/mconnect/share.vala b/src/mconnect/share.vala index af9f6c4..059c5b9 100644 --- a/src/mconnect/share.vala +++ b/src/mconnect/share.vala @@ -105,7 +105,11 @@ class ShareHandler : Object, PacketHandlerInterface { debug ("got URL: %s, launching...", url); Utils.show_own_notification ("Launching shared URL", dev.device_name); - AppInfo.launch_default_for_uri (url, null); + try { + AppInfo.launch_default_for_uri (url, null); + } catch (Error e) { + warning ("cannot launch application: %s", e.message); + } } } @@ -161,7 +165,7 @@ class ShareHandler : Object, PacketHandlerInterface { dev.send (make_share_packet ("text", text)); } - public void share_file (Device dev, string path) { + public void share_file (Device dev, string path) throws Error { debug ("share file %s to device %s", path, dev.to_string ()); var file = File.new_for_path (path); @@ -206,4 +210,4 @@ class ShareHandler : Object, PacketHandlerInterface { t.start_async.begin (); dev.send (make_file_share_packet (file.get_basename (), size, port)); } -} \ No newline at end of file +} diff --git a/src/mconnect/telephony-proxy.vala b/src/mconnect/telephony-proxy.vala index a1da4c3..165eb2d 100644 --- a/src/mconnect/telephony-proxy.vala +++ b/src/mconnect/telephony-proxy.vala @@ -38,7 +38,7 @@ class TelephonyHandlerProxy : Object, PacketHandlerInterfaceProxy { // conn.unregister_object(this); } - public void send_sms (string number, string message) { + public void send_sms (string number, string message) throws Error { this.telephony.send_sms (this.device, number, message); } -} \ No newline at end of file +} diff --git a/src/mconnect/transfer-download.vala b/src/mconnect/transfer-download.vala index 061f3ac..b82b9ed 100644 --- a/src/mconnect/transfer-download.vala +++ b/src/mconnect/transfer-download.vala @@ -69,13 +69,13 @@ class DownloadTransfer : TransferInterface, Object { Utils.socket_set_keepalive (sock); // enable TLS - this.tls_conn = Utils.make_tls_connection (this.conn, - Core.instance ().certificate, - this.device.certificate, - Utils.TlsConnectionMode.CLIENT); try { + this.tls_conn = Utils.make_tls_connection (this.conn, + Core.instance ().certificate, + this.device.certificate, + Utils.TlsConnectionMode.CLIENT); debug ("attempt TLS handshake"); - var tls_res = yield this.tls_conn.handshake_async (); + yield this.tls_conn.handshake_async (); debug ("TLS handshake complete"); } catch (Error e) { @@ -124,7 +124,7 @@ class DownloadTransfer : TransferInterface, Object { if (this.foutstream != null) { try { this.foutstream.close (); - } catch (IOError e) { + } catch (Error e) { warning ("failed to close file output: %s", e.message); } @@ -133,7 +133,7 @@ class DownloadTransfer : TransferInterface, Object { if (this.tls_conn != null) { try { this.tls_conn.close (); - } catch (IOError e) { + } catch (Error e) { warning ("failed to close TLS connection: %s", e.message); } @@ -141,7 +141,7 @@ class DownloadTransfer : TransferInterface, Object { if (this.conn != null) { try { this.conn.close (); - } catch (IOError e) { + } catch (Error e) { warning ("failed to close connection: %s", e.message); } @@ -155,8 +155,11 @@ class DownloadTransfer : TransferInterface, Object { } private void cleanup_error (string reason) { - - this.file.@delete (); + try { + this.file.@delete (); + } catch (Error e) { + warning ("cannot remove file: %s", e.message); + } this.cleanup (); @@ -184,4 +187,4 @@ class DownloadTransfer : TransferInterface, Object { debug ("cancel called"); this.cancellable.cancel (); } -} \ No newline at end of file +} diff --git a/src/mconnect/transfer-manager-proxy.vala b/src/mconnect/transfer-manager-proxy.vala index 579a229..a2d9113 100644 --- a/src/mconnect/transfer-manager-proxy.vala +++ b/src/mconnect/transfer-manager-proxy.vala @@ -20,8 +20,6 @@ using Gee; [DBus (name = "org.mconnect.TransferManager")] class TransferManagerDBusProxy : Object { - - private TransferManager manager; private DBusConnection bus; private int job_idx = 0; @@ -49,7 +47,7 @@ class TransferManagerDBusProxy : Object { * * Returns a list of DBus paths of all known transfer jobs */ - public ObjectPath[] list_jobs () { + public ObjectPath[] list_jobs () throws Error { ObjectPath[] jobs = {}; foreach (var path in this.jobs.keys) { @@ -108,4 +106,4 @@ class TransferManagerDBusProxy : Object { public signal void transfer_failed (string path, string reason); public signal void transfer_started (string path); -} \ No newline at end of file +} diff --git a/src/mconnect/transfer-manager.vala b/src/mconnect/transfer-manager.vala index 675a223..61c9521 100644 --- a/src/mconnect/transfer-manager.vala +++ b/src/mconnect/transfer-manager.vala @@ -32,6 +32,7 @@ class TransferManager : Object { } public SocketService ? make_listener (out uint16 listen_port) { + listen_port = 0; var ss = new SocketService (); for (var port = PORT_MIN; port <= PORT_MAX; port++) { var added = false; @@ -52,4 +53,4 @@ class TransferManager : Object { warning ("could not find a free port to listen on"); return null; } -} \ No newline at end of file +} diff --git a/src/mconnect/transfer-proxy.vala b/src/mconnect/transfer-proxy.vala index 1fdce0e..7c641b5 100644 --- a/src/mconnect/transfer-proxy.vala +++ b/src/mconnect/transfer-proxy.vala @@ -34,21 +34,21 @@ class TransferDBusProxy : Object { } [DBus (visible = false)] - public void bus_register (DBusConnection conn) { + public void bus_register (DBusConnection conn) throws Error { debug ("register transfer at path %s", this.object_path.to_string ()); this.register_id = conn.register_object (this.object_path, this); } [DBus (visible = false)] - public void bus_unregister (DBusConnection conn) { + public void bus_unregister (DBusConnection conn) throws Error { if (this.register_id != 0) { debug ("unregister transfer at path %s", this.object_path.to_string ()); conn.unregister_object (this.register_id); } } - public void cancel () { + public void cancel () throws Error { debug ("cancelling job"); this.transfer.cancel (); } -} \ No newline at end of file +} diff --git a/src/mconnect/transfer-upload.vala b/src/mconnect/transfer-upload.vala index 1cc23c8..4867ce9 100644 --- a/src/mconnect/transfer-upload.vala +++ b/src/mconnect/transfer-upload.vala @@ -71,7 +71,13 @@ class UploadTransfer : TransferInterface, Object { } private async void handle_client (SocketConnection conn) { - var isa = conn.get_remote_address () as InetSocketAddress; + InetSocketAddress isa; + try { + isa = conn.get_remote_address () as InetSocketAddress; + } catch (Error e) { + warning ("cannot obtain remote address: %s", e.message); + return; + } debug ("client connected: %s:%u", isa.address.to_string (), isa.port); @@ -87,7 +93,7 @@ class UploadTransfer : TransferInterface, Object { Utils.TlsConnectionMode.SERVER); try { debug ("attempt TLS handshake"); - var tls_res = yield this.tls_conn.handshake_async (); + yield this.tls_conn.handshake_async (); debug ("TLS handshake complete"); } catch (Error e) { @@ -183,4 +189,4 @@ class UploadTransfer : TransferInterface, Object { debug ("cancel called"); this.cancellable.cancel (); } -} \ No newline at end of file +} diff --git a/src/mconnect/utils.vala b/src/mconnect/utils.vala index ec4bea9..1d7f5cb 100644 --- a/src/mconnect/utils.vala +++ b/src/mconnect/utils.vala @@ -70,7 +70,6 @@ namespace Utils { option = 3; Posix.setsockopt (sock.fd, 6, 6, &option, (Posix.socklen_t) sizeof (int)); #endif - int option = 10; Posix.setsockopt (sock.fd, IPProto.TCP, Posix.TCP_KEEPIDLE, @@ -109,7 +108,7 @@ namespace Utils { TlsConnection make_tls_connection (SocketConnection sock_conn, TlsCertificate self_cert, TlsCertificate ? expected_peer = null, - TlsConnectionMode mode = TlsConnectionMode.SERVER) { + TlsConnectionMode mode = TlsConnectionMode.SERVER) throws Error { TlsConnection tls_conn; if (mode == TlsConnectionMode.SERVER) { @@ -183,7 +182,7 @@ namespace Utils { return matches; } catch (RegexError e) { warning ("failed to compile regex: %s", e.message); - return null; + return {}; } } @@ -198,4 +197,4 @@ namespace Utils { critical ("failed to show notification: %s", e.message); } } -} \ No newline at end of file +} diff --git a/src/mconnectctl/device-manager-iface.vala b/src/mconnectctl/device-manager-iface.vala index 0cf9d04..f388073 100644 --- a/src/mconnectctl/device-manager-iface.vala +++ b/src/mconnectctl/device-manager-iface.vala @@ -22,7 +22,7 @@ namespace Mconnect { public const string OBJECT_PATH = "/org/mconnect/manager"; - public abstract ObjectPath[] ListDevices () throws IOError; - public abstract void AllowDevice (string path) throws IOError; + public abstract ObjectPath[] ListDevices () throws Error; + public abstract void AllowDevice (string path) throws Error; } -} \ No newline at end of file +} diff --git a/src/mconnectctl/share-iface.vala b/src/mconnectctl/share-iface.vala index 59aaf07..5f5f31a 100644 --- a/src/mconnectctl/share-iface.vala +++ b/src/mconnectctl/share-iface.vala @@ -21,8 +21,8 @@ namespace Mconnect { [DBus (name = "org.mconnect.Device.Share")] public interface ShareIface : Object { - public abstract void share_url (string url) throws IOError; - public abstract void share_text (string text) throws IOError; - public abstract void share_file (string path) throws IOError; + public abstract void share_url (string url) throws Error; + public abstract void share_text (string text) throws Error; + public abstract void share_file (string path) throws Error; } -} \ No newline at end of file +} diff --git a/src/mconnectctl/telephony-iface.vala b/src/mconnectctl/telephony-iface.vala index 1b20705..995b727 100644 --- a/src/mconnectctl/telephony-iface.vala +++ b/src/mconnectctl/telephony-iface.vala @@ -22,6 +22,6 @@ namespace Mconnect { public interface TelephonyIface : Object { public abstract void send_sms (string number, - string message) throws IOError; + string message) throws Error; } -} \ No newline at end of file +} diff --git a/test/mconn-crypt-vala-test.vala b/test/mconn-crypt-vala-test.vala index 8cf9b7b..86db378 100644 --- a/test/mconn-crypt-vala-test.vala +++ b/test/mconn-crypt-vala-test.vala @@ -31,8 +31,7 @@ void test_generate_load () { } try { - var cert = new TlsCertificate.from_files (cert_path, - key_path); + new TlsCertificate.from_files (cert_path, key_path); } catch (Error e) { warning ("load from files failed: %s", e.message); Test.fail (); @@ -129,4 +128,4 @@ public static void main (string[] args) { Test.add_func ("/mconn-crypt-vala/verify-cn", test_custom_cn); Test.add_func ("/mconn-crypt-vala/fingerprint", test_fingerprint); Test.run (); -} \ No newline at end of file +}