diff options
| author | frosty <frostinator33@airmail.cc> | 2026-10-26 10:21:57 -0400 |
|---|---|---|
| committer | frosty <frostinator33@airmail.cc> | 2026-10-26 10:21:57 -0400 |
| commit | 74aecd8b0986d07b50b7ce310d64e645b8b54e38 (patch) | |
| tree | 560e6434f183eb54cd779936f3a4c9575146a066 /xmpp-vala/src | |
| parent | 3d7e90d401da02d430a87db0ec7e1db3a6f1a68f (diff) | |
| parent | 4436001bb361ad4f9e4e05819214ecf0ea77c063 (diff) | |
Merge 'upstream/master'
Diffstat (limited to 'xmpp-vala/src')
51 files changed, 394 insertions, 327 deletions
diff --git a/xmpp-vala/src/core/direct_tls_xmpp_stream.vala b/xmpp-vala/src/core/direct_tls_xmpp_stream.vala index 2f159ab6..55488eb5 100644 --- a/xmpp-vala/src/core/direct_tls_xmpp_stream.vala +++ b/xmpp-vala/src/core/direct_tls_xmpp_stream.vala @@ -19,9 +19,7 @@ public class Xmpp.DirectTlsXmppStream : TlsXmppStream { debug("Connecting to %s:%i (tls)", host, port); IOStream? io_stream = yield client.connect_to_host_async(host, port, cancellable); TlsConnection tls_connection = TlsClientConnection.new(io_stream, new NetworkAddress(remote_name.to_string(), port)); -#if GLIB_2_60 tls_connection.set_advertised_protocols(ADVERTISED_PROTOCOLS); -#endif tls_connection.accept_certificate.connect(on_invalid_certificate); tls_connection.accept_certificate.connect((cert, flags) => on_invalid_cert.func(cert, flags)); reset_stream(tls_connection); diff --git a/xmpp-vala/src/core/module_flag.vala b/xmpp-vala/src/core/module_flag.vala index 76ae4dc1..95547852 100644 --- a/xmpp-vala/src/core/module_flag.vala +++ b/xmpp-vala/src/core/module_flag.vala @@ -10,12 +10,7 @@ namespace Xmpp { } public T? cast(XmppStreamFlag flag) { -#if VALA_0_56_11 - // We can't typecheck due to compiler bug - return (T) module; -#else return flag.get_type().is_a(typeof(T)) ? (T?) flag : null; -#endif } public bool matches(XmppStreamFlag module) { @@ -39,12 +34,7 @@ namespace Xmpp { } public T? cast(XmppStreamModule module) { -#if VALA_0_56_11 - // We can't typecheck due to compiler bug - return (T) module; -#else return module.get_type().is_a(typeof(T)) ? (T?) module : null; -#endif } public bool matches(XmppStreamModule module) { diff --git a/xmpp-vala/src/core/stanza_attribute.vala b/xmpp-vala/src/core/stanza_attribute.vala index 6c6ac579..ba1616a5 100644 --- a/xmpp-vala/src/core/stanza_attribute.vala +++ b/xmpp-vala/src/core/stanza_attribute.vala @@ -56,7 +56,13 @@ public class StanzaAttribute : StanzaEntry { if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) { return printf(ATTRIBUTE_XML_NO_NS_FORMAT, true); } else { - return printf(ATTRIBUTE_XML_FORMAT, false, state.find_name((!)ns_uri)); + string ns_name = "_"; + try { + ns_name = state.find_name((!)ns_uri); + } catch (IOError e) { + warning("Error finding name: %s", e.message); + } + return printf(ATTRIBUTE_XML_FORMAT, false, ns_name); } } @@ -65,7 +71,13 @@ public class StanzaAttribute : StanzaEntry { if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) { return printf(ATTRIBUTE_XML_ANSI_NO_NS_FORMAT, true); } else { - return printf(ATTRIBUTE_XML_ANSI_FORMAT, false, state.find_name((!)ns_uri)); + string ns_name = "_"; + try { + ns_name = state.find_name((!)ns_uri); + } catch (IOError e) { + warning("Error finding name: %s", e.message); + } + return printf(ATTRIBUTE_XML_ANSI_FORMAT, false, ns_name); } } } diff --git a/xmpp-vala/src/core/stanza_node.vala b/xmpp-vala/src/core/stanza_node.vala index f44657f1..56f857d4 100644 --- a/xmpp-vala/src/core/stanza_node.vala +++ b/xmpp-vala/src/core/stanza_node.vala @@ -18,54 +18,62 @@ public abstract class StanzaEntry { public string? encoded_val { owned get { if (val == null) return null; - return ENCODABLE_VALUE_CHARS.replace_eval(val, -1, 0, 0, (match_info, result_builder) => { - int start; - match_info.fetch_pos(0, out start, null); - unowned string src = match_info.get_string(); - switch (src[start]) { - case '&': result_builder.append("&"); break; - case '"': result_builder.append("""); break; - case '\'': result_builder.append("'"); break; - case '<': result_builder.append("<"); break; - case '>': result_builder.append(">"); break; - default: error("Unreachable"); break; - } - return false; - }); + try { + return ENCODABLE_VALUE_CHARS.replace_eval(val, -1, 0, 0, (match_info, result_builder) => { + int start; + match_info.fetch_pos(0, out start, null); + unowned string src = match_info.get_string(); + switch (src[start]) { + case '&': result_builder.append("&"); break; + case '"': result_builder.append("""); break; + case '\'': result_builder.append("'"); break; + case '<': result_builder.append("<"); break; + case '>': result_builder.append(">"); break; + default: error("Unreachable"); + } + return false; + }); + } catch (RegexError e) { + error("Error encoding entities in string \"%s\": %s", val, e.message); + } } set { if (value == null) { val = null; return; } - val = DECODABLE_VALUE_SEQUENCES.replace_eval(value, -1, 0, 0, (match_info, result_builder) => { - int start, end; - match_info.fetch_pos(0, out start, out end); - unowned string src = match_info.get_string(); - switch (src[start+1]) { - case 'g': result_builder.append_c('>'); break; - case 'l': result_builder.append_c('<'); break; - case 'q': result_builder.append_c('"'); break; - case 'a': - switch (src[start+2]) { - case 'p': result_builder.append_c('\''); break; - case 'm': result_builder.append_c('&'); break; - default: critical("Invalid encoding: %s in %s", match_info.fetch(0), src); break; - } - break; - case '#': - unichar num = -1; - if (src[start+2] == 'x') { - src.substring(start+3, start-end-3).scanf("%x", &num); - } else { - num = int.parse(src.substring(start+2, start-end-2)); - } - result_builder.append_unichar(num); - break; - default: critical("Invalid encoding: %s in %s", match_info.fetch(0), src); break; - } - return false; - }); + try { + val = DECODABLE_VALUE_SEQUENCES.replace_eval(value, -1, 0, 0, (match_info, result_builder) => { + int start, end; + match_info.fetch_pos(0, out start, out end); + unowned string src = match_info.get_string(); + switch (src[start + 1]) { + case 'g': result_builder.append_c('>'); break; + case 'l': result_builder.append_c('<'); break; + case 'q': result_builder.append_c('"'); break; + case 'a': + switch (src[start + 2]) { + case 'p': result_builder.append_c('\''); break; + case 'm': result_builder.append_c('&'); break; + default: critical("Invalid encoding: %s in %s", match_info.fetch(0), src); break; + } + break; + case '#': + unichar num = -1; + if (src[start + 2] == 'x') { + src.substring(start + 3, start - end - 3).scanf("%x", &num); + } else { + num = int.parse(src.substring(start + 2, start - end - 2)); + } + result_builder.append_unichar(num); + break; + default: critical("Invalid encoding: %s in %s", match_info.fetch(0), src); break; + } + return false; + }); + } catch (RegexError e) { + error("Error decoding entities in string \"%s\": %s", value, e.message); + } } } diff --git a/xmpp-vala/src/core/stanza_reader.vala b/xmpp-vala/src/core/stanza_reader.vala index ff512497..4828600d 100644 --- a/xmpp-vala/src/core/stanza_reader.vala +++ b/xmpp-vala/src/core/stanza_reader.vala @@ -38,8 +38,15 @@ public class StanzaReader { if (cancellable != null && cancellable.is_cancelled()) throw new IOError.CANCELLED("Input stream is canceled."); try { buffer_fill = (int) yield ((!)input).read_async(buffer, GLib.Priority.DEFAULT, cancellable); - } catch (TlsError.EOF e) { - throw new IOError.CLOSED("End of TLS stream reached"); + } catch (Error e) { + if (e is IOError) { + throw (IOError) e; + } else if (e is TlsError.EOF) { + // The error can be TlsError.EOF instead of IOError.CLOSED, fixing that + throw new IOError.CLOSED("End of TLS stream reached"); + } else { + throw new IOError.FAILED("Unknown error: %s", e.message); + } } if (buffer_fill == 0) throw new IOError.CLOSED("End of input stream reached."); buffer_pos = 0; diff --git a/xmpp-vala/src/core/stream_connect.vala b/xmpp-vala/src/core/stream_connect.vala index 7e3843fa..a496fc3c 100644 --- a/xmpp-vala/src/core/stream_connect.vala +++ b/xmpp-vala/src/core/stream_connect.vala @@ -15,7 +15,7 @@ namespace Xmpp { public async XmppStreamResult establish_stream(Jid bare_jid, Gee.List<XmppStreamModule> modules, string? log_options, owned TlsXmppStream.OnInvalidCert on_invalid_cert) { Jid remote = bare_jid.domain_jid; - TlsXmppStream.OnInvalidCertWrapper on_invalid_cert_wrapper = new TlsXmppStream.OnInvalidCertWrapper(on_invalid_cert); + TlsXmppStream.OnInvalidCertWrapper on_invalid_cert_wrapper = new TlsXmppStream.OnInvalidCertWrapper((owned) on_invalid_cert); //Lookup xmpp-client and xmpps-client SRV records GLib.List<SrvTargetInfo>? targets = new GLib.List<SrvTargetInfo>(); @@ -72,7 +72,13 @@ namespace Xmpp { connection_timeout_id = Timeout.add_seconds(30, () => { warning("Connection attempt timed out"); - stream.disconnect(); + stream.disconnect.begin((_, res) => { + try { + stream.disconnect.end(res); + } catch (IOError e) { + debug("Error while disconnecting: %s", e.message); + } + }); connection_timeout_id = 0; return Source.REMOVE; }); diff --git a/xmpp-vala/src/file_content_type.vala b/xmpp-vala/src/file_content_type.vala index 3656435e..bae493f6 100644 --- a/xmpp-vala/src/file_content_type.vala +++ b/xmpp-vala/src/file_content_type.vala @@ -14,8 +14,12 @@ namespace Xmpp { } public FileContentType.from_file(File file) { - FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); - this.from_file_info(file_info); + try { + FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); + this.from_file_info(file_info); + } catch (Error e) { + warning("Failed reading file content type: %s", e.message); + } } public string? get_mime_type() { diff --git a/xmpp-vala/src/module/bookmarks_provider.vala b/xmpp-vala/src/module/bookmarks_provider.vala index 6ddcc5af..458ff183 100644 --- a/xmpp-vala/src/module/bookmarks_provider.vala +++ b/xmpp-vala/src/module/bookmarks_provider.vala @@ -8,10 +8,10 @@ public interface BookmarksProvider : Object { public signal void conference_changed(XmppStream stream, Conference conferences); public signal void received_conferences(XmppStream stream, Set<Conference> conferences); - public async abstract async Set<Conference>? get_conferences(XmppStream stream); - public async abstract void add_conference(XmppStream stream, Conference conference); - public async abstract void remove_conference(XmppStream stream, Conference conference); - public async abstract void replace_conference(XmppStream stream, Jid muc_jid, Conference modified_conference); + public async abstract async Set<Conference>? get_conferences(XmppStream stream) throws IOError; + public async abstract void add_conference(XmppStream stream, Conference conference) throws IOError; + public async abstract void remove_conference(XmppStream stream, Conference conference) throws IOError; + public async abstract void replace_conference(XmppStream stream, Jid muc_jid, Conference modified_conference) throws IOError; } } diff --git a/xmpp-vala/src/module/iq/module.vala b/xmpp-vala/src/module/iq/module.vala index bb9260c9..c87db897 100644 --- a/xmpp-vala/src/module/iq/module.vala +++ b/xmpp-vala/src/module/iq/module.vala @@ -17,22 +17,39 @@ namespace Xmpp.Iq { preprocess_outgoing_iq_set_get(stream, iq); Iq.Stanza? return_stanza = null; + IOError? return_error = null; + bool yielded = false; responseListeners[iq.id] = new ResponseListener((_, result_iq) => { return_stanza = result_iq; - if (cancellable == null || !cancellable.is_cancelled()) { - Idle.add(send_iq_async.callback); + if (yielded) send_iq_async.callback(); + }); + stream.write_async.begin(iq.stanza, io_priority, cancellable, (_, res) => { + try { + stream.write_async.end(res); + } catch (IOError e) { + return_error = e; } }); - stream.write_async(iq.stanza, io_priority, cancellable); ulong cancelled_handler_id = 0; if (cancellable != null) { - cancelled_handler_id = cancellable.cancelled.connect(() => Idle.add(send_iq_async.callback)); + cancelled_handler_id = cancellable.connect(() => { + if (yielded) send_iq_async.callback(); + }); + } + if ((cancellable == null || !cancellable.is_cancelled()) && return_error == null) { + yielded = true; + yield; + yielded = false; } - yield; if (cancellable != null) { - cancellable.disconnect(cancelled_handler_id); - cancellable.set_error_if_cancelled(); + if (cancellable.is_cancelled()) { + cancellable.set_error_if_cancelled(); + } else { + cancellable.disconnect(cancelled_handler_id); + } } + responseListeners.unset(iq.id); + if (return_error != null) throw return_error; return return_stanza; } diff --git a/xmpp-vala/src/module/sasl.vala b/xmpp-vala/src/module/sasl.vala index 035cc723..f0c2d6ed 100644 --- a/xmpp-vala/src/module/sasl.vala +++ b/xmpp-vala/src/module/sasl.vala @@ -73,10 +73,14 @@ namespace Xmpp.Sasl { } else if (node.name == "challenge" && stream.has_flag(Flag.IDENTITY)) { Flag flag = stream.get_flag(Flag.IDENTITY); if (flag.mechanism == Mechanism.SCRAM_SHA_1) { - var challenge_response = compute_challenge_response(node.get_string_content(), flag.password, flag.client_nonce, flag.name); - flag.server_signature = challenge_response.expected_server_signature; - stream.write(new StanzaNode.build("response", NS_URI).add_self_xmlns() - .put_node(new StanzaNode.text(Base64.encode((uchar[]) (challenge_response.response).to_utf8())))); + try { + var challenge_response = compute_challenge_response(node.get_string_content(), flag.password, flag.client_nonce, flag.name); + flag.server_signature = challenge_response.expected_server_signature; + stream.write(new StanzaNode.build("response", NS_URI).add_self_xmlns() + .put_node(new StanzaNode.text(Base64.encode((uchar[]) (challenge_response.response).to_utf8())))); + } catch (Error e) { + warning("Failed processing challenge: %s", e.message); + } } } } @@ -165,7 +169,7 @@ namespace Xmpp.Sasl { public string response { get; set; } } - public static ChallengeResponse compute_challenge_response(string challenge, string password, string client_nonce, string name) { + public static ChallengeResponse compute_challenge_response(string challenge, string password, string client_nonce, string name) throws Error { string challenge_base64 = (string) Base64.decode(challenge); string? server_nonce = null; uint8[] salt = null; diff --git a/xmpp-vala/src/module/session.vala b/xmpp-vala/src/module/session.vala index b1436d1e..fa947624 100644 --- a/xmpp-vala/src/module/session.vala +++ b/xmpp-vala/src/module/session.vala @@ -28,9 +28,13 @@ public class Module : XmppStreamNegotiationModule { stream.add_flag(new Flag()); Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("session", NS_URI).add_self_xmlns()) { to=stream.remote_name }; - Iq.Stanza result_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); - if (!result_iq.is_error()) { - stream.get_flag(Flag.IDENTITY).finished = true; + try { + Iq.Stanza result_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + if (!result_iq.is_error()) { + stream.get_flag(Flag.IDENTITY).finished = true; + } + } catch (IOError e) { + warning("Error establishing legacy session: %s", e.message); } } } diff --git a/xmpp-vala/src/module/xep/0004_data_forms.vala b/xmpp-vala/src/module/xep/0004_data_forms.vala index 6b5624da..6c16a53d 100644 --- a/xmpp-vala/src/module/xep/0004_data_forms.vala +++ b/xmpp-vala/src/module/xep/0004_data_forms.vala @@ -18,6 +18,7 @@ public class DataForm { } public enum Type { + UNKNOWN, BOOLEAN, FIXED, HIDDEN, @@ -44,7 +45,7 @@ public class DataForm { get { return node.get_attribute("label", NS_URI); } set { node.set_attribute("label", value); } } - public virtual Type? type_ { get; internal set; default=null; } + public virtual Type type_ { get; internal set; default=Type.UNKNOWN; } public string? var { get { return node.get_attribute("var", NS_URI); } set { node.set_attribute("var", value); } @@ -82,11 +83,6 @@ public class DataForm { value_node.put_node(new StanzaNode.text(val)); } - internal void add_value_string(string val) { - StanzaNode node = new StanzaNode.build("value"); - node.put_node(new StanzaNode.text(val)); - } - internal Gee.List<Option>? get_options() { Gee.List<Option> ret = new ArrayList<Option>(); Gee.List<StanzaNode> option_nodes = node.get_subnodes("option", NS_URI); diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala index 537e460b..20666820 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala @@ -45,7 +45,7 @@ public class Module : XmppStreamModule, Iq.Handler { return yield this.cache.get_entity_identities(jid); } - public async InfoResult? request_info(XmppStream stream, Jid jid) { + public async InfoResult? request_info(XmppStream stream, Jid jid) throws IOError { var future = active_info_requests[jid]; if (future == null) { var promise = new Promise<InfoResult?>(); @@ -53,10 +53,14 @@ public class Module : XmppStreamModule, Iq.Handler { active_info_requests[jid] = future; Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_INFO).add_self_xmlns()) { to=jid }; - Iq.Stanza iq_response = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); - InfoResult? result = InfoResult.create_from_iq(iq_response); + try { + Iq.Stanza iq_response = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + InfoResult? result = InfoResult.create_from_iq(iq_response); - promise.set_value(result); + promise.set_value(result); + } catch (IOError e) { + promise.set_exception(e); + } active_info_requests.unset(jid); } @@ -64,12 +68,17 @@ public class Module : XmppStreamModule, Iq.Handler { InfoResult? res = yield future.wait_async(); return res; } catch (FutureError error) { + if (error is FutureError.EXCEPTION) { + if (future.exception is IOError) { + throw (IOError) future.exception; + } + } warning("Future error when waiting for info request result: %s", error.message); return null; } } - public async ItemsResult? request_items(XmppStream stream, Jid jid) { + public async ItemsResult? request_items(XmppStream stream, Jid jid) throws IOError { StanzaNode query_node = new StanzaNode.build("query", NS_URI_ITEMS).add_self_xmlns(); Iq.Stanza iq = new Iq.Stanza.get(query_node) { to=jid }; diff --git a/xmpp-vala/src/module/xep/0045_muc/flag.vala b/xmpp-vala/src/module/xep/0045_muc/flag.vala index d0d2c359..a72965b3 100644 --- a/xmpp-vala/src/module/xep/0045_muc/flag.vala +++ b/xmpp-vala/src/module/xep/0045_muc/flag.vala @@ -5,9 +5,6 @@ namespace Xmpp.Xep.Muc { public class Flag : XmppStreamFlag { public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "muc"); - private HashMap<Jid, Gee.List<Feature>> room_features = new HashMap<Jid, Gee.List<Feature>>(Jid.hash_bare_func, Jid.equals_bare_func); - private HashMap<Jid, string> room_names = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func); - private HashMap<Jid, string> enter_ids = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func); public HashMap<Jid, Promise<JoinResult?>> enter_futures = new HashMap<Jid, Promise<JoinResult?>>(Jid.hash_func, Jid.equals_func); private HashMap<Jid, string> own_nicks = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func); @@ -18,12 +15,6 @@ public class Flag : XmppStreamFlag { private HashMap<Jid, HashMap<Jid, Affiliation>> affiliations = new HashMap<Jid, HashMap<Jid, Affiliation>>(Jid.hash_bare_func, Jid.equals_bare_func); private HashMap<Jid, Role> occupant_role = new HashMap<Jid, Role>(Jid.hash_func, Jid.equals_func); - public string? get_room_name(Jid muc_jid) { return room_names.has_key(muc_jid.bare_jid) ? room_names[muc_jid.bare_jid] : null; } - - public bool has_room_feature(Jid muc_jid, Feature feature) { - return room_features.has_key(muc_jid.bare_jid) && room_features[muc_jid.bare_jid].contains(feature); - } - public Jid? get_real_jid(Jid full_jid) { return occupant_real_jids[full_jid]; } public Jid? get_occupant_jid(Jid real_jid, Jid room) { @@ -77,14 +68,6 @@ public class Flag : XmppStreamFlag { public string? get_muc_subject(Jid muc_jid) { return subjects[muc_jid.bare_jid]; } - internal void set_room_name(Jid muc_jid, string name) { - room_names[muc_jid.bare_jid] = name; - } - - internal void set_room_features(Jid muc_jid, Gee.List<Feature> features) { - room_features[muc_jid.bare_jid] = features; - } - internal void set_real_jid(Jid full_jid, Jid real_jid) { occupant_real_jids[full_jid] = real_jid; } internal void set_offline_member(Jid muc_jid, Jid real_jid, Affiliation affiliation) { diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index ad929b00..e4c066f0 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -8,6 +8,12 @@ private const string NS_URI_OWNER = NS_URI + "#owner"; public const string NS_URI_USER = NS_URI + "#user"; private const string NS_URI_REQUEST = NS_URI + "#request"; +public const string FEATURE_STABLE_ID = "http://jabber.org/protocol/muc#stable_id"; +public const string FEATURE_MEMBERS_ONLY = "muc_membersonly"; +public const string FEATURE_MODERATED = "muc_moderated"; +public const string FEATURE_NON_ANONYMOUS = "muc_nonanonymous"; +public const string FEATURE_PASSWORD_PROTECTED = "muc_passwordprotected"; + public enum MucEnterError { PASSWORD_REQUIRED, BANNED, @@ -34,26 +40,6 @@ public enum Role { VISITOR } -public enum Feature { - REGISTER, - ROOMCONFIG, - ROOMINFO, - HIDDEN, - MEMBERS_ONLY, - MODERATED, - NON_ANONYMOUS, - OPEN, - PASSWORD_PROTECTED, - PERSISTENT, - PUBLIC, - ROOMS, - SEMI_ANONYMOUS, - STABLE_ID, - TEMPORARY, - UNMODERATED, - UNSECURED -} - public static void add_muc_pm_message_stanza_x_node(MessageStanza message_stanza) { StanzaNode x_node = new StanzaNode.build("x", "http://jabber.org/protocol/muc#user").add_self_xmlns(); message_stanza.stanza.put_node(x_node); @@ -74,6 +60,7 @@ public class Module : XmppStreamModule { public signal void subject_set(XmppStream stream, string? subject, Jid jid); public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason); public signal void voice_request_received(XmppStream stream, Jid room_jid, Jid from_jid, string nick); + public signal void room_info_changed(XmppStream stream, Jid muc_jid); public signal void room_info_updated(XmppStream stream, Jid muc_jid); public signal void self_removed_from_room(XmppStream stream, Jid jid, StatusCode code); @@ -228,7 +215,7 @@ public class Module : XmppStreamModule { stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq); } - public async void change_affiliation(XmppStream stream, Jid muc_jid, Jid? user_jid, string? nick, string new_affiliation) { + public async void change_affiliation(XmppStream stream, Jid muc_jid, Jid? user_jid, string? nick, string new_affiliation) throws IOError { StanzaNode item_node = new StanzaNode.build("item", NS_URI_ADMIN) .put_attribute("affiliation", new_affiliation, NS_URI_ADMIN); if (user_jid != null) { @@ -242,7 +229,7 @@ public class Module : XmppStreamModule { yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); } - public async DataForms.DataForm? get_config_form(XmppStream stream, Jid jid) { + public async DataForms.DataForm? get_config_form(XmppStream stream, Jid jid) throws IOError { Iq.Stanza get_iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid }; Iq.Stanza result_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, get_iq); @@ -254,7 +241,7 @@ public class Module : XmppStreamModule { return null; } - public async void set_config_form(XmppStream stream, Jid jid, DataForms.DataForm data_form) { + public async void set_config_form(XmppStream stream, Jid jid, DataForms.DataForm data_form) throws IOError { StanzaNode stanza_node = new StanzaNode.build("query", NS_URI_OWNER); stanza_node.add_self_xmlns().put_node(data_form.get_submit_node()); Iq.Stanza set_iq = new Iq.Stanza.set(stanza_node) { to=jid }; @@ -299,7 +286,7 @@ public class Module : XmppStreamModule { if (status_codes.contains(StatusCode.CONFIG_CHANGE_NON_PRIVACY) || status_codes.contains(StatusCode.NON_ANONYMOUS) || status_codes.contains(StatusCode.SEMI_ANONYMOUS)) { - query_room_info.begin(stream, message.from.bare_jid); + room_info_changed(stream, message.from.bare_jid); } } } @@ -358,9 +345,6 @@ public class Module : XmppStreamModule { if (status_codes.contains(StatusCode.SELF_PRESENCE)) { Jid bare_jid = presence.from.bare_jid; if (flag.get_enter_id(bare_jid) != null) { - - query_room_info.begin(stream, bare_jid); - flag.finish_muc_enter(bare_jid); var join_result = new JoinResult() { nick=presence.from.resourcepart, newly_created=status_codes.contains(StatusCode.NEW_ROOM_CREATED) }; flag.enter_futures[bare_jid].set_value(join_result); @@ -430,52 +414,13 @@ public class Module : XmppStreamModule { } } - private async void query_room_info(XmppStream stream, Jid jid) { - ServiceDiscovery.InfoResult? info_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, jid); - if (info_result == null) return; - - Gee.List<Feature> features = new ArrayList<Feature>(); - - foreach (ServiceDiscovery.Identity identity in info_result.identities) { - if (identity.category == "conference" && identity.name != null) { - stream.get_flag(Flag.IDENTITY).set_room_name(jid, identity.name); - } - } - - foreach (string feature in info_result.features) { - Feature? parsed = null; - switch (feature) { - case "http://jabber.org/protocol/muc#register": parsed = Feature.REGISTER; break; - case "http://jabber.org/protocol/muc#roomconfig": parsed = Feature.ROOMCONFIG; break; - case "http://jabber.org/protocol/muc#roominfo": parsed = Feature.ROOMINFO; break; - case "http://jabber.org/protocol/muc#stable_id": parsed = Feature.STABLE_ID; break; - case "muc_hidden": parsed = Feature.HIDDEN; break; - case "muc_membersonly": parsed = Feature.MEMBERS_ONLY; break; - case "muc_moderated": parsed = Feature.MODERATED; break; - case "muc_nonanonymous": parsed = Feature.NON_ANONYMOUS; break; - case "muc_open": parsed = Feature.OPEN; break; - case "muc_passwordprotected": parsed = Feature.PASSWORD_PROTECTED; break; - case "muc_persistent": parsed = Feature.PERSISTENT; break; - case "muc_public": parsed = Feature.PUBLIC; break; - case "muc_rooms": parsed = Feature.ROOMS; break; - case "muc_semianonymous": parsed = Feature.SEMI_ANONYMOUS; break; - case "muc_temporary": parsed = Feature.TEMPORARY; break; - case "muc_unmoderated": parsed = Feature.UNMODERATED; break; - case "muc_unsecured": parsed = Feature.UNSECURED; break; - } - if (parsed != null) features.add(parsed); - } - stream.get_flag(Flag.IDENTITY).set_room_features(jid, features); - room_info_updated(stream, jid); - } - public async void fetch_affiliations(XmppStream stream, Jid muc_jid) { query_affiliation.begin(stream, muc_jid, "member"); query_affiliation.begin(stream, muc_jid, "admin"); yield query_affiliation(stream, muc_jid, "owner"); } - private async Gee.List<Jid>? query_affiliation(XmppStream stream, Jid jid, string affiliation) { + private async Gee.List<Jid>? query_affiliation(XmppStream stream, Jid jid, string affiliation) throws IOError { Iq.Stanza iq = new Iq.Stanza.get( new StanzaNode.build("query", NS_URI_ADMIN) .add_self_xmlns() @@ -593,14 +538,18 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> { if (item_nodes.size > 0) { var affiliations = new HashMap<Jid, Affiliation>(); foreach (StanzaNode item_node in item_nodes) { - string jid_str = item_node.get_attribute("jid", Muc.NS_URI_USER); - Jid real_jid = Jid.from_string(jid_str); - string affiliation_str = item_node.get_attribute("affiliation", Muc.NS_URI_USER); - Muc.Affiliation affiliation = Muc.Module.parse_affiliation(affiliation_str); + try { + string jid_str = item_node.get_attribute("jid", Muc.NS_URI_USER); + Jid real_jid = Jid.from_string(jid_str); + string affiliation_str = item_node.get_attribute("affiliation", Muc.NS_URI_USER); + Muc.Affiliation affiliation = Muc.Module.parse_affiliation(affiliation_str); - affiliations[real_jid] = affiliation; + affiliations[real_jid] = affiliation; - stream.get_flag(Flag.IDENTITY).set_offline_member(message.from, real_jid, affiliation); + stream.get_flag(Flag.IDENTITY).set_offline_member(message.from, real_jid, affiliation); + } catch (InvalidJidError e) { + warning("Received invalid affiliation update: %s", e.message); + } } string? mav_since = MucAffiliationsVersioning.get_mav_since(x_node); diff --git a/xmpp-vala/src/module/xep/0047_in_band_bytestreams.vala b/xmpp-vala/src/module/xep/0047_in_band_bytestreams.vala index 1e423b49..74034a8a 100644 --- a/xmpp-vala/src/module/xep/0047_in_band_bytestreams.vala +++ b/xmpp-vala/src/module/xep/0047_in_band_bytestreams.vala @@ -177,7 +177,7 @@ public class Connection : IOStream { if (read_callback != null) { Idle.add((owned) read_callback, read_callback_priority); read_callback = null; - if (read_callback_cancellable != null) { + if (read_callback_cancellable != null && !read_callback_cancellable.is_cancelled()) { read_callback_cancellable.disconnect(read_callback_cancellable_id); } read_callback_cancellable = null; @@ -187,7 +187,7 @@ public class Connection : IOStream { if (write_callback != null) { Idle.add((owned) write_callback, write_callback_priority); write_callback = null; - if (write_callback_cancellable != null) { + if (write_callback_cancellable != null && !write_callback_cancellable.is_cancelled()) { write_callback_cancellable.disconnect(write_callback_cancellable_id); } write_callback_cancellable = null; diff --git a/xmpp-vala/src/module/xep/0048_bookmarks.vala b/xmpp-vala/src/module/xep/0048_bookmarks.vala index 46814e4a..dc009a1e 100644 --- a/xmpp-vala/src/module/xep/0048_bookmarks.vala +++ b/xmpp-vala/src/module/xep/0048_bookmarks.vala @@ -6,7 +6,7 @@ private const string NS_URI = "storage:bookmarks"; public class Module : BookmarksProvider, XmppStreamModule { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0048_bookmarks_module"); - public async Set<Conference>? get_conferences(XmppStream stream) { + public async Set<Conference>? get_conferences(XmppStream stream) throws IOError { StanzaNode get_node = new StanzaNode.build("storage", NS_URI).add_self_xmlns(); StanzaNode? result_node = yield stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node); if (result_node == null) return null; @@ -20,7 +20,7 @@ public class Module : BookmarksProvider, XmppStreamModule { return ret; } - private async void set_conferences(XmppStream stream, Set<Conference> conferences) { + private async void set_conferences(XmppStream stream, Set<Conference> conferences) throws IOError { StanzaNode storage_node = (new StanzaNode.build("storage", NS_URI)).add_self_xmlns(); foreach (Conference conference in conferences) { Bookmarks1Conference? bookmarks1conference = conference as Bookmarks1Conference; @@ -45,13 +45,13 @@ public class Module : BookmarksProvider, XmppStreamModule { stream.get_module(Module.IDENTITY).received_conferences(stream, conferences); } - public async void add_conference(XmppStream stream, Conference conference) { + public async void add_conference(XmppStream stream, Conference conference) throws IOError { Set<Conference>? conferences = yield get_conferences(stream); conferences.add(conference); yield set_conferences(stream, conferences); } - public async void replace_conference(XmppStream stream, Jid muc_jid, Conference modified_conference) { + public async void replace_conference(XmppStream stream, Jid muc_jid, Conference modified_conference) throws IOError { Set<Conference>? conferences = yield get_conferences(stream); foreach (Conference conference in conferences) { if (conference.jid.equals(muc_jid)) { @@ -64,7 +64,7 @@ public class Module : BookmarksProvider, XmppStreamModule { yield set_conferences(stream, conferences); } - public async void remove_conference(XmppStream stream, Conference conference_remove) { + public async void remove_conference(XmppStream stream, Conference conference_remove) throws IOError { Set<Conference>? conferences = yield get_conferences(stream); conferences.remove(conference_remove); yield set_conferences(stream, conferences); diff --git a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala index 81ccde9b..a6501505 100644 --- a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala +++ b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala @@ -6,13 +6,13 @@ namespace Xmpp.Xep.PrivateXmlStorage { public class Module : XmppStreamModule { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0049_private_xml_storage"); - public async void store(XmppStream stream, StanzaNode node) { + public async void store(XmppStream stream, StanzaNode node) throws IOError { StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node); Iq.Stanza iq = new Iq.Stanza.set(queryNode); yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); } - public async StanzaNode? retrieve(XmppStream stream, StanzaNode node) { + public async StanzaNode? retrieve(XmppStream stream, StanzaNode node) throws IOError { StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node); Iq.Stanza iq = new Iq.Stanza.get(queryNode); Iq.Stanza iq_result = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); diff --git a/xmpp-vala/src/module/xep/0054_vcard/module.vala b/xmpp-vala/src/module/xep/0054_vcard/module.vala index 4df1d9a5..4c02a2d1 100644 --- a/xmpp-vala/src/module/xep/0054_vcard/module.vala +++ b/xmpp-vala/src/module/xep/0054_vcard/module.vala @@ -2,7 +2,7 @@ namespace Xmpp.Xep.VCard { private const string NS_URI = "vcard-temp"; private const string NS_URI_UPDATE = NS_URI + ":x:update"; -public async Bytes? fetch_image(XmppStream stream, Jid jid, string hash) { +public async Bytes? fetch_image(XmppStream stream, Jid jid, string hash) throws IOError { Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("vCard", NS_URI).add_self_xmlns()) { to=jid }; Iq.Stanza iq_res = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala index c9af4263..88b9cd31 100644 --- a/xmpp-vala/src/module/xep/0060_pubsub.vala +++ b/xmpp-vala/src/module/xep/0060_pubsub.vala @@ -41,7 +41,7 @@ namespace Xmpp.Xep.Pubsub { retract_listeners.unset(node); } - public async Gee.List<StanzaNode>? request_all(XmppStream stream, Jid? jid, string node) { // TODO multiple nodes gehen auch + public async Gee.List<StanzaNode>? request_all(XmppStream stream, Jid? jid, string node) throws IOError { // TODO multiple nodes gehen auch Iq.Stanza request_iq = new Iq.Stanza.get(new StanzaNode.build("pubsub", NS_URI).add_self_xmlns().put_node(new StanzaNode.build("items", NS_URI).put_attribute("node", node))); if (jid != null) request_iq.to = jid; @@ -72,7 +72,7 @@ namespace Xmpp.Xep.Pubsub { XmppStream stream, Jid? jid, string node_id, string? item_id, StanzaNode content, PublishOptions? publish_options = null, bool try_reconfiguring = true - ) { + ) throws IOError { StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI).add_self_xmlns(); StanzaNode publish_node = new StanzaNode.build("publish", NS_URI).put_attribute("node", node_id); pubsub_node.put_node(publish_node); @@ -142,7 +142,7 @@ namespace Xmpp.Xep.Pubsub { stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null); } - public async DataForms.DataForm? request_node_config(XmppStream stream, Jid? jid, string node_id) { + public async DataForms.DataForm? request_node_config(XmppStream stream, Jid? jid, string node_id) throws IOError { StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI_OWNER).add_self_xmlns(); StanzaNode publish_node = new StanzaNode.build("configure", NS_URI_OWNER).put_attribute("node", node_id); pubsub_node.put_node(publish_node); @@ -154,7 +154,7 @@ namespace Xmpp.Xep.Pubsub { return DataForms.DataForm.create_from_node(data_form_node); } - public async bool submit_node_config(XmppStream stream, DataForms.DataForm data_form, string node_id) { + public async bool submit_node_config(XmppStream stream, DataForms.DataForm data_form, string node_id) throws IOError { StanzaNode submit_node = data_form.get_submit_node(); StanzaNode pubsub_node = new StanzaNode.build("pubsub", Pubsub.NS_URI_OWNER).add_self_xmlns(); @@ -222,7 +222,7 @@ namespace Xmpp.Xep.Pubsub { } } - private async bool change_node_config(XmppStream stream, Jid jid, string node, PublishOptions publish_options) { + private async bool change_node_config(XmppStream stream, Jid jid, string node, PublishOptions publish_options) throws IOError { DataForms.DataForm? data_form = yield stream.get_module(Pubsub.Module.IDENTITY).request_node_config(stream, jid, node); if (data_form == null) return false; diff --git a/xmpp-vala/src/module/xep/0065_socks5_bytestreams.vala b/xmpp-vala/src/module/xep/0065_socks5_bytestreams.vala index 97674f3f..4bb46837 100644 --- a/xmpp-vala/src/module/xep/0065_socks5_bytestreams.vala +++ b/xmpp-vala/src/module/xep/0065_socks5_bytestreams.vala @@ -25,6 +25,10 @@ public class Module : XmppStreamModule, Iq.Handler { private GetLocalIpAddresses? get_local_ip_addresses_impl = null; + public Module.with_local_ip_address_handler(owned GetLocalIpAddresses get_local_ip_addresses) { + set_local_ip_address_handler((owned) get_local_ip_addresses); + } + public override void attach(XmppStream stream) { stream.add_flag(new Flag()); query_availability.begin(stream); @@ -46,7 +50,7 @@ public class Module : XmppStreamModule, Iq.Handler { return get_local_ip_addresses_impl(); } - private async void query_availability(XmppStream stream) { + private async void query_availability(XmppStream stream) throws IOError { ServiceDiscovery.ItemsResult? items_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_items(stream, stream.remote_name); if (items_result == null) return; diff --git a/xmpp-vala/src/module/xep/0077_in_band_registration.vala b/xmpp-vala/src/module/xep/0077_in_band_registration.vala index 12ed2f1c..0d2dae40 100644 --- a/xmpp-vala/src/module/xep/0077_in_band_registration.vala +++ b/xmpp-vala/src/module/xep/0077_in_band_registration.vala @@ -7,7 +7,7 @@ public const string NS_URI = "jabber:iq:register"; public class Module : XmppStreamNegotiationModule { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0077_in_band_registration"); - public async Form? get_from_server(XmppStream stream, Jid jid) { + public async Form? get_from_server(XmppStream stream, Jid jid) throws IOError { StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); Iq.Stanza request_form_iq = new Iq.Stanza.get(query_node) { to=jid }; request_form_iq.to = jid; @@ -16,7 +16,7 @@ public class Module : XmppStreamNegotiationModule { return new Form.from_node(stream, iq_result); } - public async string? submit_to_server(XmppStream stream, Jid jid, Form form) { + public async string? submit_to_server(XmppStream stream, Jid jid, Form form) throws IOError { StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); query_node.put_node(form.get_submit_node()); Iq.Stanza iq = new Iq.Stanza.set(query_node) { to=jid }; @@ -30,7 +30,7 @@ public class Module : XmppStreamNegotiationModule { return null; } - public async ErrorStanza? change_password(XmppStream stream, Jid bare_jid, string new_pw) { + public async ErrorStanza? change_password(XmppStream stream, Jid bare_jid, string new_pw) throws IOError { StanzaNode pw_change_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); StanzaNode username_node = new StanzaNode.build("username", NS_URI); StanzaNode pw_node = new StanzaNode.build("password", NS_URI); diff --git a/xmpp-vala/src/module/xep/0082_date_time_profiles.vala b/xmpp-vala/src/module/xep/0082_date_time_profiles.vala index 3237208e..8cd3cfb1 100644 --- a/xmpp-vala/src/module/xep/0082_date_time_profiles.vala +++ b/xmpp-vala/src/module/xep/0082_date_time_profiles.vala @@ -15,8 +15,8 @@ public TimeZone? parse_tzd(string tzd) { } else { return null; } - int h_offset = unprefixed.substring(0, 2).to_int(); - int m_offset = unprefixed.substring(3, 2).to_int(); + int h_offset = int.parse(unprefixed.substring(0, 2)); + int m_offset = int.parse(unprefixed.substring(3, 2)); int offset = h_offset * 60 * 60 + m_offset * 60; if (tzd.has_prefix("-")) { offset = -offset; diff --git a/xmpp-vala/src/module/xep/0084_user_avatars.vala b/xmpp-vala/src/module/xep/0084_user_avatars.vala index 680c8e78..4e96dd8f 100644 --- a/xmpp-vala/src/module/xep/0084_user_avatars.vala +++ b/xmpp-vala/src/module/xep/0084_user_avatars.vala @@ -20,12 +20,15 @@ namespace Xmpp.Xep.UserAvatars { stream.get_module(Pubsub.Module.IDENTITY).publish.begin(stream, null, NS_URI_METADATA, sha1, metadata_node); } - public void unset_avatar(XmppStream stream) { - StanzaNode metadata_node = new StanzaNode.build("metadata", NS_URI_METADATA).add_self_xmlns(); - stream.get_module(Pubsub.Module.IDENTITY).delete_node(stream, null, NS_URI_METADATA); + public void unset_avatar(XmppStream stream, string? hash = null) { + var pubsub_module = stream.get_module(Pubsub.Module.IDENTITY); + pubsub_module.delete_node(stream, null, NS_URI_METADATA); + if (hash != null) { + pubsub_module.retract_item.begin(stream, null, NS_URI_DATA, hash, (_, res) => pubsub_module.retract_item.end(res)); + } } - public async Bytes? fetch_image(XmppStream stream, Jid jid, string hash) { + public async Bytes? fetch_image(XmppStream stream, Jid jid, string hash) throws IOError { Gee.List<StanzaNode>? items = yield stream.get_module(Pubsub.Module.IDENTITY).request_all(stream, jid, NS_URI_DATA); if (items == null || items.size == 0 || items[0].sub_nodes.size == 0) return null; diff --git a/xmpp-vala/src/module/xep/0115_entity_capabilities.vala b/xmpp-vala/src/module/xep/0115_entity_capabilities.vala index 8e15e0c2..e39dcbbd 100644 --- a/xmpp-vala/src/module/xep/0115_entity_capabilities.vala +++ b/xmpp-vala/src/module/xep/0115_entity_capabilities.vala @@ -35,11 +35,6 @@ namespace Xmpp.Xep.EntityCapabilities { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0115_entity_capabilities"); private string own_ver_hash; - private Storage storage; - - public Module(Storage storage) { - this.storage = storage; - } private string get_own_hash(XmppStream stream) { if (own_ver_hash == null) { diff --git a/xmpp-vala/src/module/xep/0166_jingle/component.vala b/xmpp-vala/src/module/xep/0166_jingle/component.vala index e30175d5..f08ffbce 100644 --- a/xmpp-vala/src/module/xep/0166_jingle/component.vala +++ b/xmpp-vala/src/module/xep/0166_jingle/component.vala @@ -41,7 +41,11 @@ namespace Xmpp.Xep.Jingle { assert(!this.stream.ready); promise.set_value(stream); if (terminated != null) { - yield stream.close_async(); + try { + yield stream.close_async(); + } catch (IOError e) { + warning("Failed closing stream provided for terminated connection: %s", e.message); + } } } @@ -53,7 +57,11 @@ namespace Xmpp.Xep.Jingle { if (terminated == null) { terminated = (reason_name ?? "") + " - " + (reason_text ?? "") + @"we terminated? $we_terminated"; if (stream.ready) { - yield stream.value.close_async(); + try { + yield stream.value.close_async(); + } catch (IOError e) { + warning("Failed closing stream when terminating connection: %s", e.message); + } } else { promise.set_exception(new IOError.FAILED("Jingle connection failed")); } diff --git a/xmpp-vala/src/module/xep/0166_jingle/content.vala b/xmpp-vala/src/module/xep/0166_jingle/content.vala index f6af1b17..07cadc36 100644 --- a/xmpp-vala/src/module/xep/0166_jingle/content.vala +++ b/xmpp-vala/src/module/xep/0166_jingle/content.vala @@ -67,7 +67,7 @@ public class Xmpp.Xep.Jingle.Content : Object { ContentType content_type, ContentParameters content_params, Transport transport, TransportParameters? transport_params, SecurityPrecondition? security_precondition, SecurityParameters? security_params, - Jid local_full_jid, Jid peer_full_jid) throws Error { + Jid local_full_jid, Jid peer_full_jid) { this.content_name = content_name; this.senders = senders; this.role = Role.RESPONDER; @@ -142,7 +142,7 @@ public class Xmpp.Xep.Jingle.Content : Object { this.content_params.accept(stream, session, this); } - internal void handle_accept(XmppStream stream, ContentNode content_node) { + internal void handle_accept(XmppStream stream, ContentNode content_node) throws IqError { this.transport_params.handle_transport_accept(content_node.transport); this.transport_params.create_transport_connection(stream, this); this.content_params.handle_accept(stream, this.session, this, content_node.description); @@ -157,7 +157,13 @@ public class Xmpp.Xep.Jingle.Content : Object { return; } tried_transport_methods.add(new_transport.ns_uri); - transport_params = new_transport.create_transport_parameters(stream, transport_params.components, local_full_jid, peer_full_jid); + try { + transport_params = new_transport.create_transport_parameters(stream, transport_params.components, local_full_jid, peer_full_jid); + } catch (Error e) { + session.terminate(ReasonElement.FAILED_TRANSPORT, null, e.message); + // TODO should we only terminate this content or really the whole session? + return; + } set_transport_params(transport_params); session.send_transport_replace(this, transport_params); state = State.REPLACING_TRANSPORT; diff --git a/xmpp-vala/src/module/xep/0166_jingle/jingle_flag.vala b/xmpp-vala/src/module/xep/0166_jingle/jingle_flag.vala index 9f0acd27..f451f4c9 100644 --- a/xmpp-vala/src/module/xep/0166_jingle/jingle_flag.vala +++ b/xmpp-vala/src/module/xep/0166_jingle/jingle_flag.vala @@ -24,7 +24,12 @@ public class Xmpp.Xep.Jingle.Flag : XmppStreamFlag { public async Session? get_session(string sid) { if (promises.has_key(sid)) { - return yield promises[sid].future.wait_async(); + try { + return yield promises[sid].future.wait_async(); + } catch (FutureError e) { + warning("Failed waiting for session: %s", e.message); + return null; + } } return sessions[sid]; } diff --git a/xmpp-vala/src/module/xep/0166_jingle/session.vala b/xmpp-vala/src/module/xep/0166_jingle/session.vala index 22e8e978..aa8d6656 100644 --- a/xmpp-vala/src/module/xep/0166_jingle/session.vala +++ b/xmpp-vala/src/module/xep/0166_jingle/session.vala @@ -222,7 +222,12 @@ public class Xmpp.Xep.Jingle.Session : Object { .put_node(content.transport_params.to_transport_stanza_node("content-add"))); Iq.Stanza iq = new Iq.Stanza.set(content_add_node) { to=peer_full_jid }; - yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + try { + yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + } catch (IOError e) { + warning("Error adding content: %s", e.message); + // FIXME: Probably need to clean up some state + } } private void handle_content_accept(ContentNode content_node) throws IqError { diff --git a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala index 490cc125..53057d9e 100644 --- a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala +++ b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala @@ -39,7 +39,11 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T remote_pwd = node.get_attribute("pwd"); remote_ufrag = node.get_attribute("ufrag"); foreach (StanzaNode candidateNode in node.get_subnodes("candidate")) { - remote_candidates.add(Candidate.parse(candidateNode)); + try { + remote_candidates.add(Candidate.parse(candidateNode)); + } catch (Jingle.IqError e) { + warning("Ignoring invalid candidate %s: %s", candidateNode.to_string(), e.message); + } } StanzaNode? fingerprint_node = node.get_subnode("fingerprint", DTLS_NS_URI); diff --git a/xmpp-vala/src/module/xep/0177_jingle_raw_udp.vala b/xmpp-vala/src/module/xep/0177_jingle_raw_udp.vala index 200cdfa9..b59c1b06 100644 --- a/xmpp-vala/src/module/xep/0177_jingle_raw_udp.vala +++ b/xmpp-vala/src/module/xep/0177_jingle_raw_udp.vala @@ -13,6 +13,10 @@ namespace Xmpp.Xep.JingleRawUdp { private GetLocalIpAddresses? get_local_ip_addresses_impl = null; + public Module.with_local_ip_address_handler(owned GetLocalIpAddresses get_local_ip_addresses) { + set_local_ip_address_handler((owned) get_local_ip_addresses); + } + public override void attach(XmppStream stream) { stream.get_module(Jingle.Module.IDENTITY).register_transport(this); stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); diff --git a/xmpp-vala/src/module/xep/0191_blocking_command.vala b/xmpp-vala/src/module/xep/0191_blocking_command.vala index 9e5ede78..c037c480 100644 --- a/xmpp-vala/src/module/xep/0191_blocking_command.vala +++ b/xmpp-vala/src/module/xep/0191_blocking_command.vala @@ -88,11 +88,15 @@ public class Module : XmppStreamModule, Iq.Handler { bool has_feature = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).has_entity_feature(stream, stream.remote_name, NS_URI); if (has_feature) { stream.add_flag(new Flag()); - stream.get_flag(Flag.IDENTITY).blocklist = yield get_blocklist(stream); + try { + stream.get_flag(Flag.IDENTITY).blocklist = yield get_blocklist(stream); + } catch (IOError e) { + warning("Failed to retrieve blocklist: %s", e.message); + } } } - private async Gee.List<string> get_blocklist(XmppStream stream) { + private async Gee.List<string> get_blocklist(XmppStream stream) throws IOError { StanzaNode blocklist_node = new StanzaNode.build("blocklist", NS_URI).add_self_xmlns(); Iq.Stanza iq = new Iq.Stanza.get(blocklist_node); diff --git a/xmpp-vala/src/module/xep/0199_ping.vala b/xmpp-vala/src/module/xep/0199_ping.vala index 18fa538c..7bc234bc 100644 --- a/xmpp-vala/src/module/xep/0199_ping.vala +++ b/xmpp-vala/src/module/xep/0199_ping.vala @@ -6,7 +6,7 @@ namespace Xmpp.Xep.Ping { public class Module : XmppStreamModule, Iq.Handler { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0199_ping"); - public async Iq.Stanza send_ping(XmppStream stream, Jid jid) { + public async Iq.Stanza send_ping(XmppStream stream, Jid jid) throws IOError { StanzaNode ping_node = new StanzaNode.build("ping", NS_URI).add_self_xmlns(); Iq.Stanza iq = new Iq.Stanza.get(ping_node) { to=jid }; return yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq, Priority.HIGH); diff --git a/xmpp-vala/src/module/xep/0215_external_service_discovery.vala b/xmpp-vala/src/module/xep/0215_external_service_discovery.vala index 5bad71cd..67f67c05 100644 --- a/xmpp-vala/src/module/xep/0215_external_service_discovery.vala +++ b/xmpp-vala/src/module/xep/0215_external_service_discovery.vala @@ -4,7 +4,7 @@ namespace Xmpp.Xep.ExternalServiceDiscovery { private const string NS_URI = "urn:xmpp:extdisco:2"; - public static async Gee.List<Service> request_services(XmppStream stream) { + public static async Gee.List<Service> request_services(XmppStream stream) throws IOError { Iq.Stanza request_iq = new Iq.Stanza.get((new StanzaNode.build("services", NS_URI)).add_self_xmlns()) { to=stream.remote_name }; Iq.Stanza response_iq = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, request_iq); diff --git a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala index f85049ac..43edefad 100644 --- a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala +++ b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala @@ -42,7 +42,7 @@ public class Module : Jingle.ContentType, XmppStreamModule { return yield stream.get_module(Jingle.Module.IDENTITY).is_available(stream, required_transport_type, required_components, full_jid); } - public async void offer_file_stream(XmppStream stream, Jid receiver_full_jid, InputStream input_stream, string basename, int64 size, string? precondition_name = null, Object? precondition_options = null) throws Jingle.Error { + public async void offer_file_stream(XmppStream stream, Jid receiver_full_jid, InputStream input_stream, string basename, int64 size, string? precondition_name = null, Object? precondition_options = null) throws Jingle.Error, Jingle.IqError { StanzaNode file_node; StanzaNode description = new StanzaNode.build("description", NS_URI) .add_self_xmlns() diff --git a/xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala b/xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala index 852cc7eb..7f44bda2 100644 --- a/xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala +++ b/xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala @@ -328,9 +328,13 @@ class LocalListener { } } catch (Error e) { warning("Jingle SOCKS5 bytestream establish error cid %s: %s", cid, e.message); - // Send a "general SOCKS server failure" (0x01) - yield conn.output_stream.write_all_async({0x05, 0x01}, GLib.Priority.DEFAULT, null, out written); - yield conn.output_stream.close_async(); + try { + // Send a "general SOCKS server failure" (0x01) + yield conn.output_stream.write_all_async({0x05, 0x01}, GLib.Priority.DEFAULT, null, out written); + yield conn.output_stream.close_async(); + } catch (Error sub) { + // Ignoring + } } } diff --git a/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala b/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala index 09eaf711..09134a61 100644 --- a/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala +++ b/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala @@ -65,10 +65,6 @@ class Parameters : Jingle.TransportParameters, Object { return new Parameters(Jingle.Role.RESPONDER, peer_full_jid, sid, block_size); } - public string transport_ns_uri() { - return NS_URI; - } - public void set_content(Jingle.Content content) { } diff --git a/xmpp-vala/src/module/xep/0272_muji.vala b/xmpp-vala/src/module/xep/0272_muji.vala index 8226da10..b287295c 100644 --- a/xmpp-vala/src/module/xep/0272_muji.vala +++ b/xmpp-vala/src/module/xep/0272_muji.vala @@ -56,9 +56,13 @@ namespace Xmpp.Xep.Muji { muji_node.put_node(content_node); } - Presence.Stanza presence_stanza = new Presence.Stanza() { to=muc_jid.with_resource(group_call.our_nick) }; - presence_stanza.stanza.put_node(muji_node); - stream.get_module(Presence.Module.IDENTITY).send_presence(stream, presence_stanza); + try { + Presence.Stanza presence_stanza = new Presence.Stanza() { to=muc_jid.with_resource(group_call.our_nick) }; + presence_stanza.stanza.put_node(muji_node); + stream.get_module(Presence.Module.IDENTITY).send_presence(stream, presence_stanza); + } catch (InvalidJidError e) { + error("Group call participant jid was invalid: %s", e.message); + } return group_call; } @@ -86,7 +90,12 @@ namespace Xmpp.Xep.Muji { GroupCall group_call = stream.get_flag(Flag.IDENTITY).calls[muc_jid]; group_call.waiting_for_finish_prepares[promise] = preparing_peers; - return yield promise.future.wait_async(); + try { + return yield promise.future.wait_async(); + } catch (FutureError e) { + warning("Failed waiting for preparing peers: %s", e.message); + return new ArrayList<Presence.Stanza>(); + } } private async void compute_payload_intersection(XmppStream stream, GroupCall group_call, string media) { diff --git a/xmpp-vala/src/module/xep/0280_message_carbons.vala b/xmpp-vala/src/module/xep/0280_message_carbons.vala index b396ee54..f8008bfe 100644 --- a/xmpp-vala/src/module/xep/0280_message_carbons.vala +++ b/xmpp-vala/src/module/xep/0280_message_carbons.vala @@ -10,13 +10,21 @@ public class Module : XmppStreamModule { public async void enable(XmppStream stream) { if (stream.get_flag(Flag.IDENTITY) == null) { Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns()); - yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + try { + yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + } catch (IOError e) { + warning("Failed enabling carbons: %s", e.message); + } } } public async void disable(XmppStream stream) { Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("disable", NS_URI).add_self_xmlns()); - yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + try { + yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + } catch (IOError e) { + warning("Failed enabling carbons: %s", e.message); + } } public override void attach(XmppStream stream) { diff --git a/xmpp-vala/src/module/xep/0313_2_message_archive_management.vala b/xmpp-vala/src/module/xep/0313_2_message_archive_management.vala index 298a1c61..17b93d55 100644 --- a/xmpp-vala/src/module/xep/0313_2_message_archive_management.vala +++ b/xmpp-vala/src/module/xep/0313_2_message_archive_management.vala @@ -61,7 +61,7 @@ namespace Xmpp.MessageArchiveManagement.V2 { return MessageArchiveManagement.create_base_query(stream, mam_params.query_id, fields); } - public async QueryResult query_archive(XmppStream stream, MamQueryParams mam_params, Cancellable? cancellable = null) { + public async QueryResult query_archive(XmppStream stream, MamQueryParams mam_params, Cancellable? cancellable = null) throws IOError { var query_node = create_base_query(stream, mam_params); if (!mam_params.use_ns2_extended) { query_node.put_node(ResultSetManagement.create_set_rsm_node_before(mam_params.end_id)); @@ -70,7 +70,7 @@ namespace Xmpp.MessageArchiveManagement.V2 { return yield MessageArchiveManagement.query_archive(stream, mam_params.mam_server, query_node, cancellable); } - public async QueryResult page_through_results(XmppStream stream, MamQueryParams mam_params, QueryResult prev_result, Cancellable? cancellable = null) { + public async QueryResult page_through_results(XmppStream stream, MamQueryParams mam_params, QueryResult prev_result, Cancellable? cancellable = null) throws IOError { var query_node = create_base_query(stream, mam_params); query_node.put_node(ResultSetManagement.create_set_rsm_node_before(prev_result.first)); diff --git a/xmpp-vala/src/module/xep/0313_message_archive_management.vala b/xmpp-vala/src/module/xep/0313_message_archive_management.vala index a9149d4e..f054a047 100644 --- a/xmpp-vala/src/module/xep/0313_message_archive_management.vala +++ b/xmpp-vala/src/module/xep/0313_message_archive_management.vala @@ -57,7 +57,7 @@ public class Module : XmppStreamModule { return query_node; } - internal async QueryResult query_archive(XmppStream stream, Jid? mam_server, StanzaNode query_node, Cancellable? cancellable = null) { + internal async QueryResult query_archive(XmppStream stream, Jid? mam_server, StanzaNode query_node, Cancellable? cancellable = null) throws IOError { var res = new QueryResult(); Flag flag = Flag.get_flag(stream); diff --git a/xmpp-vala/src/module/xep/0363_http_file_upload.vala b/xmpp-vala/src/module/xep/0363_http_file_upload.vala index cba422ba..bd82109b 100644 --- a/xmpp-vala/src/module/xep/0363_http_file_upload.vala +++ b/xmpp-vala/src/module/xep/0363_http_file_upload.vala @@ -117,24 +117,28 @@ public class Module : XmppStreamModule { public override string get_id() { return IDENTITY.id; } private async void query_availability(XmppStream stream) { - ServiceDiscovery.InfoResult? info_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, stream.remote_name); - bool available = check_ns_in_info(stream, stream.remote_name, info_result); - if (!available) { - ServiceDiscovery.ItemsResult? items_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_items(stream, stream.remote_name); - if (items_result == null) return; + try { + ServiceDiscovery.InfoResult? info_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, stream.remote_name); + bool available = check_ns_in_info(stream, stream.remote_name, info_result); + if (!available) { + ServiceDiscovery.ItemsResult? items_result = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_items(stream, stream.remote_name); + if (items_result == null) return; - for (int i = 0; i < 2; i++) { - foreach (Xep.ServiceDiscovery.Item item in items_result.items) { + for (int i = 0; i < 2; i++) { + foreach (Xep.ServiceDiscovery.Item item in items_result.items) { - // First try the promising items and only afterwards all the others - bool promising_upload_item = item.jid.to_string().has_prefix("upload"); - if ((i == 0 && !promising_upload_item) || (i == 1) && promising_upload_item) continue; + // First try the promising items and only afterwards all the others + bool promising_upload_item = item.jid.to_string().has_prefix("upload"); + if ((i == 0 && !promising_upload_item) || (i == 1) && promising_upload_item) continue; - ServiceDiscovery.InfoResult? info_result2 = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, item.jid); - bool available2 = check_ns_in_info(stream, item.jid, info_result2); - if (available2) return; + ServiceDiscovery.InfoResult? info_result2 = yield stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, item.jid); + bool available2 = check_ns_in_info(stream, item.jid, info_result2); + if (available2) return; + } } } + } catch (IOError e) { + warning("Error querying file upload availability: %s", e.message); } } diff --git a/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala b/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala index 1c6afb30..54d00482 100644 --- a/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala +++ b/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala @@ -43,19 +43,27 @@ namespace Xmpp.Xep.ExtensibleSaslProfile { stream.expect_further_negotiation_stanzas = true; var authorisation_identifier = node.get_subnode("authorization-identifier", NS_URI); - string jid_string = authorisation_identifier.get_string_content(); - Jid jid = Jid.from_string(jid_string); + string jid_string = authorisation_identifier != null ? authorisation_identifier.get_string_content() : ""; + try { + Jid jid = Jid.from_string(jid_string); - foreach (var inline_provider in inline_activation_providers.values) { - inline_provider.on_bound(stream, jid, node); + foreach (var inline_provider in inline_activation_providers.values) { + inline_provider.on_bound(stream, jid, node); + } + } catch (InvalidJidError e) { + warning("Server provided invalid authorization-identifier \"%s\": %s", jid_string, e.message); } } else if (node.name == "challenge" && stream.has_flag(Flag.IDENTITY)) { Flag flag = stream.get_flag(Flag.IDENTITY); if (flag.mechanism == Mechanism.SCRAM_SHA_1) { - var challenge_response = compute_challenge_response(node.get_string_content(), flag.password, flag.client_nonce, flag.name); - flag.server_signature = challenge_response.expected_server_signature; - stream.write(new StanzaNode.build("response", NS_URI).add_self_xmlns() - .put_node(new StanzaNode.text(Base64.encode((uchar[]) (challenge_response.response).to_utf8())))); + try { + var challenge_response = compute_challenge_response(node.get_string_content(), flag.password, flag.client_nonce, flag.name); + flag.server_signature = challenge_response.expected_server_signature; + stream.write(new StanzaNode.build("response", NS_URI).add_self_xmlns() + .put_node(new StanzaNode.text(Base64.encode((uchar[]) (challenge_response.response).to_utf8())))); + } catch (Error e) { + warning("Error computing challenge response: %s", e.message); + } } } else if (node.name == "failure") { stream.remove_flag(stream.get_flag(Flag.IDENTITY)); diff --git a/xmpp-vala/src/module/xep/0392_consistent_color/hsluv.vala b/xmpp-vala/src/module/xep/0392_consistent_color/hsluv.vala index b45d84de..9efe0970 100644 --- a/xmpp-vala/src/module/xep/0392_consistent_color/hsluv.vala +++ b/xmpp-vala/src/module/xep/0392_consistent_color/hsluv.vala @@ -1,4 +1,4 @@ -namespace Hsluv { +namespace Xmpp.Xep.ConsistentColor.Hsluv { private const double[] M0 = { 3.240969941904521, -1.537383177570093, -0.498610760293 }; private const double[] M1 = { -0.96924363628087, 1.87596750150772, 0.041555057407175 }; @@ -8,10 +8,6 @@ private const double[] MInv0 = { 0.41239079926595, 0.35758433938387, 0.180480788 private const double[] MInv1 = { 0.21263900587151, 0.71516867876775, 0.072192315360733 }; private const double[] MInv2 = { 0.019330818715591, 0.11919477979462, 0.95053215224966 }; -private double RefX = 0.95045592705167; -private double RefY = 1.0; -private double RefZ = 1.089057750759878; - private double RefU = 0.19783000664283; private double RefV = 0.46831999493879; @@ -129,22 +125,19 @@ private double to_linear(double c) { } private int[] rgb_prepare(double[] tuple) { - for (int i = 0; i < tuple.length; ++i) { - tuple[i] = round(tuple[i], 3); - } - - for (int i = 0; i < tuple.length; ++i) { - double ch = tuple[i]; - - if (ch < -0.0001 || ch > 1.0001) { - return null; //throw new Error("Illegal rgb value: " + ch); - } - } - var results = new int[tuple.length]; for (int i = 0; i < tuple.length; ++i) { - results[i] = (int) Math.round(tuple[i] * 255); + double ch = round(tuple[i], 3); + if (ch < -0.0001) { + warning("RGB value underflow: %f", tuple[i]); + results[i] = 0; + } else if (ch > 1.0001) { + warning("RGB value overflow: %f", tuple[i]); + results[i] = 255; + } else { + results[i] = (int) Math.round(ch * 255); + } } return results; @@ -174,17 +167,17 @@ internal double[] rgb_to_xyz(double[] tuple) { private double y_to_l(double Y) { if (Y <= Epsilon) { - return (Y / RefY) * Kappa; + return Y * Kappa; } else { - return 116 * Math.pow(Y / RefY, 1.0 / 3.0) - 16; + return 116 * Math.pow(Y, 1.0 / 3.0) - 16; } } private double l_to_y(double L) { if (L <= 8) { - return RefY * L / Kappa; + return L / Kappa; } else { - return RefY * Math.pow((L + 16) / 116, 3); + return Math.pow((L + 16) / 116, 3); } } @@ -340,9 +333,9 @@ internal string rgb_to_hex(double[] tuple) { internal double[] hex_to_tgb(string hex) { return new double[] { - hex.substring(1, 2).to_long(null, 16) / 255.0, - hex.substring(3, 2).to_long(null, 16) / 255.0, - hex.substring(5, 2).to_long(null, 16) / 255.0 + long.parse(hex.substring(1, 2), 16) / 255.0, + long.parse(hex.substring(3, 2), 16) / 255.0, + long.parse(hex.substring(5, 2), 16) / 255.0 }; } @@ -356,37 +349,37 @@ internal double[] rgb_to_lch(double[] tuple) { // Rgb <--> Hsluv(p) -internal double[] hsluv_to_rgb(double[] tuple) { +public double[] hsluv_to_rgb(double[] tuple) { return lch_to_rgb(hsluv_to_lch(tuple)); } -internal double[] rgb_to_hsluv(double[] tuple) { +public double[] rgb_to_hsluv(double[] tuple) { return lch_to_hsluv(rgb_to_lch(tuple)); } -internal double[] hpluv_to_rgb(double[] tuple) { +public double[] hpluv_to_rgb(double[] tuple) { return lch_to_rgb(hpluv_to_lch(tuple)); } -internal double[] rgb_to_hpluv(double[] tuple) { +public double[] rgb_to_hpluv(double[] tuple) { return lch_to_hpluv(rgb_to_lch(tuple)); } // Hex -internal string hsluv_to_hex(double[] tuple) { +public string hsluv_to_hex(double[] tuple) { return rgb_to_hex(hsluv_to_rgb(tuple)); } -internal string hpluv_to_hex(double[] tuple) { +public string hpluv_to_hex(double[] tuple) { return rgb_to_hex(hpluv_to_rgb(tuple)); } -internal double[] hex_to_hsluv(string s) { +public double[] hex_to_hsluv(string s) { return rgb_to_hsluv(hex_to_tgb(s)); } -internal double[] hex_to_hpluv(string s) { +public double[] hex_to_hpluv(string s) { return rgb_to_hpluv(hex_to_tgb(s)); } diff --git a/xmpp-vala/src/module/xep/0402_bookmarks2.vala b/xmpp-vala/src/module/xep/0402_bookmarks2.vala index 938af0e9..3a7e5211 100644 --- a/xmpp-vala/src/module/xep/0402_bookmarks2.vala +++ b/xmpp-vala/src/module/xep/0402_bookmarks2.vala @@ -8,7 +8,7 @@ public const string NS_URI_COMPAT = NS_URI + "#compat"; public class Module : BookmarksProvider, XmppStreamModule { public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0402_bookmarks2"); - public async Set<Conference>? get_conferences(XmppStream stream) { + public async Set<Conference>? get_conferences(XmppStream stream) throws IOError { HashMap<Jid, Conference>? hm = null; Flag? flag = stream.get_flag(Flag.IDENTITY); @@ -35,7 +35,7 @@ public class Module : BookmarksProvider, XmppStreamModule { return ret; } - public async void add_conference(XmppStream stream, Conference conference) { + public async void add_conference(XmppStream stream, Conference conference) throws IOError { StanzaNode conference_node = new StanzaNode.build("conference", NS_URI).add_self_xmlns() .put_attribute("autojoin", conference.autojoin.to_string()); if (conference.name != null) { @@ -56,7 +56,7 @@ public class Module : BookmarksProvider, XmppStreamModule { yield stream.get_module(Pubsub.Module.IDENTITY).publish(stream, stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid, NS_URI, conference.jid.to_string(), conference_node, publish_options); } - public async void replace_conference(XmppStream stream, Jid muc_jid, Conference modified_conference) { + public async void replace_conference(XmppStream stream, Jid muc_jid, Conference modified_conference) throws IOError { yield add_conference(stream, modified_conference); } diff --git a/xmpp-vala/src/module/xep/0410_muc_self_ping.vala b/xmpp-vala/src/module/xep/0410_muc_self_ping.vala index 84772333..6511789e 100644 --- a/xmpp-vala/src/module/xep/0410_muc_self_ping.vala +++ b/xmpp-vala/src/module/xep/0410_muc_self_ping.vala @@ -1,16 +1,20 @@ namespace Xmpp.Xep.MucSelfPing { public static async bool is_joined(XmppStream stream, Jid jid) { - Iq.Stanza iq_result = yield stream.get_module(Xmpp.Xep.Ping.Module.IDENTITY).send_ping(stream, jid); + try { + Iq.Stanza iq_result = yield stream.get_module(Xmpp.Xep.Ping.Module.IDENTITY).send_ping(stream, jid); - if (!iq_result.is_error()) { - return true; - } else { - var error_stanza = iq_result.get_error(); - if (error_stanza.condition in new string[] {ErrorStanza.CONDITION_SERVICE_UNAVAILABLE, ErrorStanza.CONDITION_FEATURE_NOT_IMPLEMENTED}) { - // the client is joined, but the pinged client does not implement XMPP Ping + if (!iq_result.is_error()) { return true; + } else { + var error_stanza = iq_result.get_error(); + if (error_stanza.condition in new string[] {ErrorStanza.CONDITION_SERVICE_UNAVAILABLE, ErrorStanza.CONDITION_FEATURE_NOT_IMPLEMENTED}) { + // the client is joined, but the pinged client does not implement XMPP Ping + return true; + } } + } catch (IOError e) { + // Ignoring, same as if ping failed } return false; } diff --git a/xmpp-vala/src/module/xep/0425_message_moderation.vala b/xmpp-vala/src/module/xep/0425_message_moderation.vala index 80fab905..934e5ff3 100644 --- a/xmpp-vala/src/module/xep/0425_message_moderation.vala +++ b/xmpp-vala/src/module/xep/0425_message_moderation.vala @@ -7,13 +7,17 @@ namespace Xmpp.Xep.MessageModeration { * @return whether the moderation was successful */ public static async bool moderate(XmppStream stream, Jid muc_jid, string message_id) { - StanzaNode moderate_node = new StanzaNode.build("moderate", NS_URI) - .add_self_xmlns() - .put_attribute("id", message_id) - .put_node(new StanzaNode.build("retract", Xep.MessageRetraction.NS_URI).add_self_xmlns()); - Iq.Stanza iq = new Iq.Stanza.set(moderate_node) { to = muc_jid }; + try { + StanzaNode moderate_node = new StanzaNode.build("moderate", NS_URI) + .add_self_xmlns() + .put_attribute("id", message_id) + .put_node(new StanzaNode.build("retract", Xep.MessageRetraction.NS_URI).add_self_xmlns()); + Iq.Stanza iq = new Iq.Stanza.set(moderate_node) { to = muc_jid }; - Iq.Stanza result_stanza = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); - return !result_stanza.is_error(); + Iq.Stanza result_stanza = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, iq); + return !result_stanza.is_error(); + } catch (IOError e) { + return false; + } } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/xep/0447_stateless_file_sharing.vala b/xmpp-vala/src/module/xep/0447_stateless_file_sharing.vala index 86da6a3a..7e9b12ba 100644 --- a/xmpp-vala/src/module/xep/0447_stateless_file_sharing.vala +++ b/xmpp-vala/src/module/xep/0447_stateless_file_sharing.vala @@ -5,7 +5,7 @@ namespace Xmpp.Xep.StatelessFileSharing { public const string NS_URI = "urn:xmpp:sfs:0"; - public static Gee.List<FileShare> get_file_shares(MessageStanza message) { + public static Gee.List<FileShare>? get_file_shares(MessageStanza message) { var ret = new ArrayList<FileShare>(); foreach (StanzaNode file_sharing_node in message.stanza.get_subnodes("file-sharing", NS_URI)) { var metadata = Xep.FileMetadataElement.get_file_metadata(file_sharing_node); diff --git a/xmpp-vala/src/module/xep/0461_replies.vala b/xmpp-vala/src/module/xep/0461_replies.vala index af84aa3d..23849d69 100644 --- a/xmpp-vala/src/module/xep/0461_replies.vala +++ b/xmpp-vala/src/module/xep/0461_replies.vala @@ -36,6 +36,5 @@ namespace Xmpp.Xep.Replies { } catch (InvalidJidError e) { return null; } - return null; } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/xep/0490_message_displayed_synchronization.vala b/xmpp-vala/src/module/xep/0490_message_displayed_synchronization.vala index 38437735..b129c571 100644 --- a/xmpp-vala/src/module/xep/0490_message_displayed_synchronization.vala +++ b/xmpp-vala/src/module/xep/0490_message_displayed_synchronization.vala @@ -10,15 +10,19 @@ namespace Xmpp.Xep.MessageDisplayedSynchronization { private void handle_displayed_node_item(XmppStream stream, string? id, StanzaNode? item) { if (id == null || item == null) return; - Jid conversation_jid = Jid.from_string(id); - StanzaNode? stanza_id_node = item.get_subnode("stanza-id", UniqueStableStanzaIDs.NS_URI); - if (stanza_id_node == null || stanza_id_node.get_attribute("by") == null || stanza_id_node.get_attribute("id") == null) return; - Jid stanza_id_by_jid = Jid.from_string(stanza_id_node.get_attribute("by")); - string stanza_id = stanza_id_node.get_attribute("id"); - if (stream.has_flag(Flag.IDENTITY)) { - stream.get_flag(Flag.IDENTITY).learn_mds(conversation_jid, stanza_id_by_jid, stanza_id); + try { + Jid conversation_jid = Jid.from_string(id); + StanzaNode? stanza_id_node = item.get_subnode("stanza-id", UniqueStableStanzaIDs.NS_URI); + if (stanza_id_node == null || stanza_id_node.get_attribute("by") == null || stanza_id_node.get_attribute("id") == null) return; + Jid stanza_id_by_jid = Jid.from_string(stanza_id_node.get_attribute("by")); + string stanza_id = stanza_id_node.get_attribute("id"); + if (stream.has_flag(Flag.IDENTITY)) { + stream.get_flag(Flag.IDENTITY).learn_mds(conversation_jid, stanza_id_by_jid, stanza_id); + } + on_message_displayed(conversation_jid, stanza_id_by_jid, stanza_id); + } catch (InvalidJidError e) { + warning("Received mds item with invalid jid, ignoring: %s", e.message); } - on_message_displayed(conversation_jid, stanza_id_by_jid, stanza_id); } private void on_pubsub_item(XmppStream stream, Jid jid, string id, StanzaNode? item) { @@ -32,9 +36,13 @@ namespace Xmpp.Xep.MessageDisplayedSynchronization { private void on_initial_presence_sent(XmppStream stream) { var pubsub = stream.get_module(Pubsub.Module.IDENTITY); pubsub.request_all.begin(stream, null, NS_URI, (_, res) => { - Gee.List<StanzaNode>? items = pubsub.request_all.end(res); - foreach (StanzaNode node_item in items) { - handle_displayed_node_item(stream, node_item.get_attribute("id"), node_item.get_subnode("displayed", NS_URI)); + try { + Gee.List<StanzaNode>? items = pubsub.request_all.end(res); + foreach (StanzaNode node_item in items) { + handle_displayed_node_item(stream, node_item.get_attribute("id"), node_item.get_subnode("displayed", NS_URI)); + } + } catch (IOError e) { + warning("Failed requesting initial mds set: %s", e.message); } }); } @@ -50,7 +58,12 @@ namespace Xmpp.Xep.MessageDisplayedSynchronization { .set_max_items("max") .set_send_last_published_item("never") .set_access_model("whitelist"); - return yield pubsub.publish(stream, stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid, NS_URI, conversation_jid.to_string(), node, options); + try { + return yield pubsub.publish(stream, stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid, NS_URI, conversation_jid.to_string(), node, options); + } catch (IOError e) { + warning("Failed publishing mds item: %s", e.message); + return false; + } } public override void attach(XmppStream stream) { diff --git a/xmpp-vala/src/weak_map.vala b/xmpp-vala/src/weak_map.vala index a7f4bc44..4c0d4504 100644 --- a/xmpp-vala/src/weak_map.vala +++ b/xmpp-vala/src/weak_map.vala @@ -39,7 +39,7 @@ public class WeakMap<K, V> : Gee.AbstractMap<K, V> { notify_map.clear(); } - public override V @get(K key) { + public override V? @get(K key) { if (!hash_map.has_key(key)) return null; var v = hash_map[key]; |
