diff options
author | Marvin W <git@larma.de> | 2017-04-18 17:53:25 +0200 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-04-18 20:20:41 +0200 |
commit | f95b4f4e0949eefaed871c267626e3ff84ce5ca6 (patch) | |
tree | e60469776bcf062d2db15e9968bf6dbd37fa1630 /xmpp-vala | |
parent | 765c2605cd0abf2b4431051142f09e2676584222 (diff) | |
download | dino-f95b4f4e0949eefaed871c267626e3ff84ce5ca6.tar.gz dino-f95b4f4e0949eefaed871c267626e3ff84ce5ca6.zip |
xmpp-vala/core+libdino: concurrency + nullity improvements
Diffstat (limited to 'xmpp-vala')
-rw-r--r-- | xmpp-vala/src/core/stanza_attribute.vala | 51 | ||||
-rw-r--r-- | xmpp-vala/src/core/stanza_node.vala | 168 | ||||
-rw-r--r-- | xmpp-vala/src/core/stanza_reader.vala | 15 | ||||
-rw-r--r-- | xmpp-vala/src/core/xmpp_stream.vala | 49 | ||||
-rw-r--r-- | xmpp-vala/src/module/util.vala | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0045_muc/module.vala | 6 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0048_bookmarks/module.vala | 2 |
7 files changed, 164 insertions, 129 deletions
diff --git a/xmpp-vala/src/core/stanza_attribute.vala b/xmpp-vala/src/core/stanza_attribute.vala index e6887f33..26e63f80 100644 --- a/xmpp-vala/src/core/stanza_attribute.vala +++ b/xmpp-vala/src/core/stanza_attribute.vala @@ -1,7 +1,18 @@ namespace Xmpp.Core { + public class StanzaAttribute : StanzaEntry { - public StanzaAttribute() {} + internal const string ATTRIBUTE_STRING_FORMAT = "{%s}:%s='%s'"; + internal const string ATTRIBUTE_STRING_NO_NS_FORMAT = "%s='%s'"; + internal const string ATTRIBUTE_STRING_ANSI_FORMAT = ANSI_COLOR_GRAY+"{%s}:"+ANSI_COLOR_END+"%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END; + internal const string ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT = "%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END; + internal const string ATTRIBUTE_XML_FORMAT = "%s:%s='%s'"; + internal const string ATTRIBUTE_XML_NO_NS_FORMAT = "%s='%s'"; + internal const string ATTRIBUTE_XML_ANSI_FORMAT = "%s:%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END; + internal const string ATTRIBUTE_XML_ANSI_NO_NS_FORMAT = "%s="+ANSI_COLOR_GREEN+"'%s'"+ANSI_COLOR_END; + + internal StanzaAttribute() { + } public StanzaAttribute.build(string ns_uri, string name, string val) { this.ns_uri = ns_uri; @@ -9,29 +20,47 @@ public class StanzaAttribute : StanzaEntry { this.val = val; } - public string to_string() { - if (ns_uri == null) { - return @"$name='$val'"; + internal string printf(string fmt, bool no_ns = false, string? ns_name = null) { + if (no_ns) { + return fmt.printf(name, (!)val); } else { - return @"{$ns_uri}:$name='$val'"; + if (ns_name == null) { + return fmt.printf((!)ns_uri, name, (!)val); + } else { + return fmt.printf((!)ns_name, name, (!)val); + } } } + public string to_string() { + return printf(ATTRIBUTE_STRING_FORMAT); + } + public string to_ansi_string(bool hide_ns = false) { - if (ns_uri == null || hide_ns) { - return @"$name=$ANSI_COLOR_GREEN'$val'$ANSI_COLOR_END"; + if (hide_ns) { + return printf(ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT, true); } else { - return @"$ANSI_COLOR_GRAY{$ns_uri}:$ANSI_COLOR_END$name=$ANSI_COLOR_GREEN'$val'$ANSI_COLOR_END"; + return printf(ATTRIBUTE_STRING_ANSI_FORMAT); } } - public string to_xml(NamespaceState? state_) throws XmlError { + public string to_xml(NamespaceState? state_ = null) throws XmlError { NamespaceState state = state_ ?? new NamespaceState(); if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) { - return @"$name='$val'"; + return printf(ATTRIBUTE_XML_NO_NS_FORMAT, true); } else { - return "%s:%s='%s'".printf (state.find_name (ns_uri), name, val); + return printf(ATTRIBUTE_XML_FORMAT, false, state.find_name((!)ns_uri)); + } + } + + public string to_ansi_xml(NamespaceState? state_ = null) throws XmlError { + NamespaceState state = state_ ?? new NamespaceState(); + 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)); } } } + } diff --git a/xmpp-vala/src/core/stanza_node.vala b/xmpp-vala/src/core/stanza_node.vala index d9398a39..fd44c925 100644 --- a/xmpp-vala/src/core/stanza_node.vala +++ b/xmpp-vala/src/core/stanza_node.vala @@ -12,12 +12,17 @@ public abstract class StanzaEntry { public string name; public string? val; - public string encoded_val { + public string? encoded_val { owned get { - return val != null ? val.replace("&", "&").replace("\"", """).replace("'", "'").replace("<", "<").replace(">", ">") : null; + if (val == null) return null; + return ((!)val).replace("&", "&").replace("\"", """).replace("'", "'").replace("<", "<").replace(">", ">"); } set { - string tmp = value.replace(">", ">").replace("<", "<").replace("'","'").replace(""","\""); + if (value == null) { + val = null; + return; + } + string tmp = ((!)value).replace(">", ">").replace("<", "<").replace("'","'").replace(""","\""); while (tmp.contains("&#")) { int start = tmp.index_of("&#"); int end = tmp.index_of(";", start); @@ -39,26 +44,20 @@ public abstract class StanzaEntry { } } -public class NoStanza : StanzaEntry { - public NoStanza(string? name) { - this.name = name; - } -} - public class StanzaNode : StanzaEntry { public ArrayList<StanzaNode> sub_nodes = new ArrayList<StanzaNode>(); public ArrayList<StanzaAttribute> attributes = new ArrayList<StanzaAttribute>(); public bool has_nodes = false; public bool pseudo = false; - public StanzaNode() { + internal StanzaNode() { } public StanzaNode.build(string name, string ns_uri = "jabber:client", ArrayList<StanzaNode>? nodes = null, ArrayList<StanzaAttribute>? attrs = null) { this.ns_uri = ns_uri; this.name = name; - if (nodes != null) this.sub_nodes.add_all(nodes); - if (attrs != null) this.attributes.add_all(attrs); + if (nodes != null) this.sub_nodes.add_all((!)nodes); + if (attrs != null) this.attributes.add_all((!)attrs); } public StanzaNode.text(string text) { @@ -72,7 +71,8 @@ public class StanzaNode : StanzaEntry { } public StanzaNode add_self_xmlns() { - return put_attribute("xmlns", ns_uri); + if (ns_uri == null) return this; + return put_attribute("xmlns", (!)ns_uri); } public unowned string? get_attribute(string name, string? ns_uri = null) { @@ -88,7 +88,7 @@ public class StanzaNode : StanzaEntry { } } foreach (var attr in attributes) { - if (attr.ns_uri == _ns_uri && attr.name == _name) return attr.val; + if (attr.ns_uri == (!)_ns_uri && attr.name == _name) return attr.val; } return null; } @@ -96,19 +96,19 @@ public class StanzaNode : StanzaEntry { public int get_attribute_int(string name, int def = -1, string? ns_uri = null) { string? res = get_attribute(name, ns_uri); if (res == null) return def; - return int.parse(res); + return int.parse((!)res); } public uint get_attribute_uint(string name, uint def = 0, string? ns_uri = null) { string? res = get_attribute(name, ns_uri); if (res == null) return def; - return (uint) long.parse(res); + return (uint) long.parse((!)res); } public bool get_attribute_bool(string name, bool def = false, string? ns_uri = null) { string? res = get_attribute(name, ns_uri); if (res == null) return def; - return res.down() == "true" || res == "1"; + return ((!)res).down() == "true" || res == "1"; } public StanzaAttribute? get_attribute_raw(string name, string? ns_uri = null) { @@ -137,34 +137,26 @@ public class StanzaNode : StanzaEntry { return ret; } - public StanzaEntry get(...) { - va_list l = va_list(); - StanzaEntry? res = get_deep_attribute_(va_list.copy(l)); - if (res != null) return res; - res = get_deep_subnode_(va_list.copy(l)); - if (res != null) return res; - return new NoStanza("-"); - } - public unowned string? get_deep_attribute(...) { va_list l = va_list(); - var res = get_deep_attribute_(va_list.copy(l)); + StanzaAttribute? res = get_deep_attribute_(va_list.copy(l)); if (res == null) return null; - return res.val; + return ((!)res).val; } public StanzaAttribute? get_deep_attribute_(va_list l) { - StanzaNode? node = this; + StanzaNode node = this; string? attribute_name = l.arg(); if (attribute_name == null) return null; while (true) { string? s = l.arg(); if (s == null) break; - node = node.get_subnode(attribute_name); - if (node == null) return null; + StanzaNode? node_tmp = node.get_subnode((!)attribute_name); + if (node_tmp == null) return null; + node = (!)node_tmp; attribute_name = s; } - return node.get_attribute_raw(attribute_name); + return node.get_attribute_raw((!)attribute_name); } public StanzaNode? get_subnode(string name, string? ns_uri = null, bool recurse = false) { @@ -217,35 +209,35 @@ public class StanzaNode : StanzaEntry { } public StanzaNode? get_deep_subnode_(va_list l) { - StanzaNode? node = this; + StanzaNode node = this; while (true) { string? s = l.arg(); if (s == null) break; - node = node.get_subnode(s); - if (node == null) return null; + StanzaNode? node_tmp = node.get_subnode((!)s); + if (node_tmp == null) return null; + node = (!)node_tmp; } return node; } public ArrayList<StanzaNode> get_deep_subnodes(...) { va_list l = va_list(); - var res = get_deep_subnodes_(va_list.copy(l)); - if (res != null) return res; - return new ArrayList<StanzaNode>(); + return get_deep_subnodes_(va_list.copy(l)); } public ArrayList<StanzaNode> get_deep_subnodes_(va_list l) { - StanzaNode? node = this; + StanzaNode node = this; string? subnode_name = l.arg(); if (subnode_name == null) return new ArrayList<StanzaNode>(); while (true) { string? s = l.arg(); if (s == null) break; - node = node.get_subnode(subnode_name); - if (node == null) return new ArrayList<StanzaNode>(); + StanzaNode? node_tmp = node.get_subnode((!)subnode_name); + if (node_tmp == null) return new ArrayList<StanzaNode>(); + node = (!)node_tmp; subnode_name = s; } - return node.get_subnodes(subnode_name); + return node.get_subnodes((!)subnode_name); } public ArrayList<StanzaNode> get_all_subnodes() { @@ -255,7 +247,7 @@ public class StanzaNode : StanzaEntry { public ArrayList<StanzaNode> get_deep_all_subnodes(...) { va_list l = va_list(); StanzaNode? node = get_deep_subnode_(va_list.copy(l)); - if (node != null) return node.get_all_subnodes(); + if (node != null) return ((!)node).get_all_subnodes(); return new ArrayList<StanzaNode>(); } @@ -272,14 +264,16 @@ public class StanzaNode : StanzaEntry { public unowned string? get_deep_string_content(...) { va_list l = va_list(); StanzaNode? node = get_deep_subnode_(va_list.copy(l)); - if (node != null) return node.get_string_content(); + if (node != null) return ((!)node).get_string_content(); return null; } public StanzaNode put_attribute(string name, string val, string? ns_uri = null) { - if (name == "xmlns") ns_uri = XMLNS_URI; - if (ns_uri == null) ns_uri = this.ns_uri; - attributes.add(new StanzaAttribute.build(ns_uri, name, val)); + string? _ns_uri = ns_uri; + if (name == "xmlns") _ns_uri = XMLNS_URI; + if (_ns_uri == null) _ns_uri = this.ns_uri; + if (_ns_uri == null) return this; + attributes.add(new StanzaAttribute.build((!)_ns_uri, name, val)); return this; } @@ -302,75 +296,79 @@ public class StanzaNode : StanzaEntry { return this; } - public string to_string(int i = 0) { + private const string TAG_START_BEGIN_FORMAT = "%s<{%s}:%s"; + private const string TAG_START_EMPTY_END = " />\n"; + private const string TAG_START_CONTENT_END = ">\n"; + private const string TAG_END_FORMAT = "%s</{%s}:%s>\n"; + private const string TAG_ANSI_START_BEGIN_FORMAT = "%s"+ANSI_COLOR_YELLOW+"<"+ANSI_COLOR_GRAY+"{%s}:"+ANSI_COLOR_YELLOW+"%s"+ANSI_COLOR_END; + private const string TAG_ANSI_START_BEGIN_NO_NS_FORMAT = "%s"+ANSI_COLOR_YELLOW+"<%s"+ANSI_COLOR_END; + private const string TAG_ANSI_START_EMPTY_END = ANSI_COLOR_YELLOW+" />"+ANSI_COLOR_END+"\n"; + private const string TAG_ANSI_START_CONTENT_END = ANSI_COLOR_YELLOW+">"+ANSI_COLOR_END+"\n"; + private const string TAG_ANSI_END_FORMAT = "%s"+ANSI_COLOR_YELLOW+"</"+ANSI_COLOR_GRAY+"{%s}:"+ANSI_COLOR_YELLOW+"%s>"+ANSI_COLOR_END+"\n"; + private const string TAG_ANSI_END_NO_NS_FORMAT = "%s"+ANSI_COLOR_YELLOW+"</%s>"+ANSI_COLOR_END+"\n"; + + internal string printf(int i, string fmt_start_begin, string start_empty_end, string start_content_end, string fmt_end, string fmt_attr, bool no_ns = false) { string indent = string.nfill (i * 2, ' '); if (name == "#text") { - return @"$indent$val\n"; + return indent + ((!)val).replace("\n", indent + "\n") + "\n"; } var sb = new StringBuilder(); - sb.append(@"$indent<{$ns_uri}:$name"); + if (no_ns) { + sb.append_printf(fmt_start_begin, indent, name); + } else { + sb.append_printf(fmt_start_begin, indent, (!)ns_uri, name); + } foreach (StanzaAttribute attr in attributes) { - sb.append_printf(" %s", attr.to_string()); + sb.append_printf(" %s", attr.printf(fmt_attr, no_ns)); } if (!has_nodes && sub_nodes.size == 0) { - sb.append(" />\n"); + sb.append(start_empty_end); } else { - sb.append(">\n"); + sb.append(start_content_end); if (sub_nodes.size != 0) { foreach (StanzaNode subnode in sub_nodes) { - sb.append(subnode.to_string(i+1)); + sb.append(subnode.printf(i+1, fmt_start_begin, start_empty_end, start_content_end, fmt_end, fmt_attr, no_ns)); + } + if (no_ns) { + sb.append_printf(fmt_end, indent, name); + } else { + sb.append_printf(fmt_end, indent, (!)ns_uri, name); } - sb.append(@"$indent</{$ns_uri}:$name>\n"); } } return sb.str; } + public string to_string(int i = 0) { + return printf(i, TAG_START_BEGIN_FORMAT, TAG_START_EMPTY_END, TAG_START_CONTENT_END, TAG_END_FORMAT, StanzaAttribute.ATTRIBUTE_STRING_FORMAT); + } + public string to_ansi_string(bool hide_ns = false, int i = 0) { - string indent = string.nfill (i * 2, ' '); - if (name == "#text") { - return @"$indent$val\n"; - } - var sb = new StringBuilder(); - sb.append(@"$indent$ANSI_COLOR_YELLOW<"); - if (!hide_ns) sb.append(@"$ANSI_COLOR_GRAY{$ns_uri}:$ANSI_COLOR_YELLOW"); - sb.append(@"$name$ANSI_COLOR_END"); - foreach (StanzaAttribute attr in attributes) { - sb.append_printf(" %s", attr.to_ansi_string(hide_ns)); - } - if (!has_nodes && sub_nodes.size == 0) { - sb.append(@" $ANSI_COLOR_YELLOW/>$ANSI_COLOR_END\n"); + if (hide_ns) { + return printf(i, TAG_ANSI_START_BEGIN_NO_NS_FORMAT, TAG_ANSI_START_EMPTY_END, TAG_ANSI_START_CONTENT_END, TAG_ANSI_END_NO_NS_FORMAT, StanzaAttribute.ATTRIBUTE_STRING_ANSI_NO_NS_FORMAT, true); } else { - sb.append(@"$ANSI_COLOR_YELLOW>$ANSI_COLOR_END\n"); - if (sub_nodes.size != 0) { - foreach (StanzaNode subnode in sub_nodes) { - sb.append(subnode.to_ansi_string(hide_ns, i + 1)); - } - sb.append(@"$indent$ANSI_COLOR_YELLOW</"); - if (!hide_ns) sb.append(@"$ANSI_COLOR_GRAY{$ns_uri}:$ANSI_COLOR_YELLOW"); - sb.append(@"$name>$ANSI_COLOR_END\n"); - } + return printf(i, TAG_ANSI_START_BEGIN_FORMAT, TAG_ANSI_START_EMPTY_END, TAG_ANSI_START_CONTENT_END, TAG_ANSI_END_FORMAT, StanzaAttribute.ATTRIBUTE_STRING_ANSI_FORMAT); } - return sb.str; } public string to_xml(NamespaceState? state = null) throws XmlError { NamespaceState my_state = state ?? new NamespaceState.for_stanza(); - if (name == "#text") return @"$encoded_val"; + if (name == "#text") return val == null ? "" : (!)encoded_val; foreach (var xmlns in get_attributes_by_ns_uri (XMLNS_URI)) { + if (xmlns.val == null) continue; if (xmlns.name == "xmlns") { - my_state = new NamespaceState.with_current(my_state, xmlns.val); + my_state = new NamespaceState.with_current(my_state, (!)xmlns.val); } else { - my_state = new NamespaceState.with_assoc(my_state, xmlns.val, xmlns.name); + my_state = new NamespaceState.with_assoc(my_state, (!)xmlns.val, xmlns.name); } } var sb = new StringBuilder(); if (ns_uri == my_state.current_ns_uri) { - sb.append(@"<$name"); + sb.append_printf("<%s", name); } else { - sb.append_printf("<%s:%s", my_state.find_name (ns_uri), name); + sb.append_printf("<%s:%s", my_state.find_name ((!)ns_uri), name); } - var attr_ns_state = new NamespaceState.with_current(my_state, ns_uri); + var attr_ns_state = new NamespaceState.with_current(my_state, (!)ns_uri); foreach (StanzaAttribute attr in attributes) { sb.append_printf(" %s", attr.to_xml(attr_ns_state)); } @@ -385,7 +383,7 @@ public class StanzaNode : StanzaEntry { if (ns_uri == my_state.current_ns_uri) { sb.append(@"</$name>"); } else { - sb.append_printf("</%s:%s>", my_state.find_name (ns_uri), name); + sb.append_printf("</%s:%s>", my_state.find_name ((!)ns_uri), name); } } } diff --git a/xmpp-vala/src/core/stanza_reader.vala b/xmpp-vala/src/core/stanza_reader.vala index 0a90f855..f1ce5c19 100644 --- a/xmpp-vala/src/core/stanza_reader.vala +++ b/xmpp-vala/src/core/stanza_reader.vala @@ -44,9 +44,10 @@ public class StanzaReader { private void update_buffer() throws XmlError { try { + InputStream? input = this.input; if (input == null) throw new XmlError.EOF("No input stream specified and end of buffer reached."); if (cancellable.is_cancelled()) throw new XmlError.EOF("Input stream is canceled."); - buffer_fill = (int) input.read(buffer, cancellable); + buffer_fill = (int) ((!)input).read(buffer, cancellable); if (buffer_fill == 0) throw new XmlError.EOF("End of input stream reached."); buffer_pos = 0; } catch (GLib.IOError e) { @@ -140,21 +141,21 @@ public class StanzaReader { private void handle_stanza_ns(StanzaNode res) throws XmlError { foreach (StanzaAttribute attr in res.attributes) { - if (attr.name == "xmlns") { + if (attr.name == "xmlns" && attr.val != null) { attr.ns_uri = XMLNS_URI; - ns_state.set_current(attr.val); - } else if (attr.name.contains(":")) { + ns_state.set_current((!)attr.val); + } else if (attr.name.contains(":") && attr.val != null) { var split = attr.name.split(":"); if (split[0] == "xmlns") { attr.ns_uri = XMLNS_URI; attr.name = split[1]; - ns_state.add_assoc(attr.val, attr.name); + ns_state.add_assoc((!)attr.val, attr.name); } } } handle_entry_ns(res); foreach (StanzaAttribute attr in res.attributes) { - handle_entry_ns(attr, res.ns_uri); + handle_entry_ns(attr, res.ns_uri ?? ns_state.current_ns_uri); } } @@ -229,7 +230,7 @@ public class StanzaReader { skip_single(); if (desc.contains(":")) { var split = desc.split(":"); - assert(split[0] == ns_state.find_name(res.ns_uri)); + assert(split[0] == ns_state.find_name((!)res.ns_uri)); assert(split[1] == res.name); } else { assert(ns_state.current_ns_uri == res.ns_uri); diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 684c7ed0..682639a8 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -65,7 +65,7 @@ public class XmppLog { } if (inner == null) return true; foreach (StanzaNode snode in node.get_all_subnodes()) { - if (inner.matches(snode)) return true; + if (((!)inner).matches(snode)) return true; } return false; } @@ -78,10 +78,10 @@ public class XmppLog { private ArrayList<NodeLogDesc> descs = new ArrayList<NodeLogDesc>(); public XmppLog(string? ident = null, string? desc = null) { - this.ident = ident; - this.desc = desc; + this.ident = ident ?? ""; + this.desc = desc ?? ""; this.use_ansi = is_atty(stderr.fileno()); - while (this.desc != null && this.desc.contains(";")) { + while (this.desc.contains(";")) { string opt = this.desc.substring(0, this.desc.index_of(";")); this.desc = this.desc.substring(opt.length + 1); switch (opt) { @@ -91,7 +91,7 @@ public class XmppLog { case "show-ns": hide_ns = false; break; } } - if (desc != null) { + if (desc != "") { foreach (string d in this.desc.split("|")) { descs.add(new NodeLogDesc(d)); } @@ -99,7 +99,7 @@ public class XmppLog { } public virtual bool should_log_node(StanzaNode node) { - if (ident == null || desc == null) return false; + if (ident == "" || desc == "") return false; if (desc == "all") return true; foreach (var desc in descs) { if (desc.matches(node)) return true; @@ -108,7 +108,7 @@ public class XmppLog { } public virtual bool should_log_str(string str) { - if (ident == null || desc == null) return false; + if (ident == "" || desc == "") return false; if (desc == "all") return true; foreach (var desc in descs) { if (desc.name == "#text") return true; @@ -158,12 +158,12 @@ public class XmppStream { public signal void stream_negotiated(XmppStream stream); public void connect(string? remote_name = null) throws IOStreamError { - if (remote_name != null) this.remote_name = remote_name; + if (remote_name != null) this.remote_name = (!)remote_name; SocketClient client = new SocketClient(); try { SocketConnection? stream = client.connect(new NetworkService("xmpp-client", "tcp", this.remote_name)); if (stream == null) throw new IOStreamError.CONNECT("client.connect() returned null"); - reset_stream(stream); + reset_stream((!)stream); } catch (Error e) { stderr.printf("CONNECTION LOST?\n"); throw new IOStreamError.CONNECT(e.message); @@ -172,11 +172,14 @@ public class XmppStream { } public void disconnect() throws IOStreamError { - if (writer == null) throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open"); + StanzaWriter? writer = this.writer; + StanzaReader? reader = this.reader; + IOStream? stream = this.stream; + if (writer == null || reader == null || stream == null) throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open"); log.str("OUT", "</stream:stream>"); - writer.write.begin("</stream:stream>"); - reader.cancel(); - stream.close_async.begin(); + ((!)writer).write.begin("</stream:stream>"); + ((!)reader).cancel(); + ((!)stream).close_async.begin(); } public void reset_stream(IOStream stream) { @@ -195,9 +198,10 @@ public class XmppStream { } public StanzaNode read() throws IOStreamError { + StanzaReader? reader = this.reader; if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open"); try { - StanzaNode node = reader.read_node(); + StanzaNode node = ((!)reader).read_node(); log.node("IN", node); return node; } catch (XmlError e) { @@ -206,10 +210,11 @@ public class XmppStream { } public void write(StanzaNode node) throws IOStreamError { + StanzaWriter? writer = this.writer; if (writer == null) throw new IOStreamError.WRITE("trying to write, but no stream open"); try { log.node("OUT", node); - writer.write_node(node); + ((!)writer).write_node(node); } catch (XmlError e) { throw new IOStreamError.WRITE(e.message); } @@ -230,7 +235,7 @@ public class XmppStream { public T? get_flag<T>(FlagIdentity<T>? identity) { if (identity == null) return null; foreach (var flag in flags) { - if (identity.matches(flag)) return identity.cast(flag); + if (((!)identity).matches(flag)) return ((!)identity).cast(flag); } return null; } @@ -254,7 +259,7 @@ public class XmppStream { public T? get_module<T>(ModuleIdentity<T>? identity) { if (identity == null) return null; foreach (var module in modules) { - if (identity.matches(module)) return identity.cast(module); + if (((!)identity).matches(module)) return ((!)identity).cast(module); } return null; } @@ -315,10 +320,10 @@ public class XmppStream { bool mandatory_outstanding = false; bool negotiation_active = false; foreach (XmppStreamModule module in modules) { - XmppStreamNegotiationModule negotiation_module = module as XmppStreamNegotiationModule; + XmppStreamNegotiationModule? negotiation_module = module as XmppStreamNegotiationModule; if (negotiation_module != null) { - if (negotiation_module.negotiation_active(this)) negotiation_active = true; - if (negotiation_module.mandatory_outstanding(this)) mandatory_outstanding = true; + if (((!)negotiation_module).negotiation_active(this)) negotiation_active = true; + if (((!)negotiation_module).mandatory_outstanding(this)) mandatory_outstanding = true; } } if (!negotiation_active) { @@ -341,8 +346,10 @@ public class XmppStream { } private StanzaNode read_root() throws IOStreamError { + StanzaReader? reader = this.reader; + if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open"); try { - StanzaNode node = reader.read_root_node(); + StanzaNode node = ((!)reader).read_root_node(); log.node("IN ROOT", node); return node; } catch (XmlError e) { diff --git a/xmpp-vala/src/module/util.vala b/xmpp-vala/src/module/util.vala index 9096ea32..a0621225 100644 --- a/xmpp-vala/src/module/util.vala +++ b/xmpp-vala/src/module/util.vala @@ -1,5 +1,5 @@ namespace Xmpp { - public string? get_bare_jid(string jid) { + public string get_bare_jid(string jid) { return jid.split("/")[0]; } diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index 714bb2ca..badb7d60 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -167,16 +167,16 @@ public class Module : XmppStreamModule { flag.finish_muc_enter(bare_jid, get_resource_part(presence.from)); } } - string? affiliation = x_node["item", "affiliation"].val; + string? affiliation = x_node.get_deep_attribute("item", "affiliation"); if (affiliation != null) { received_occupant_affiliation(stream, presence.from, affiliation); } - string? jid = x_node["item", "jid"].val; + string? jid = x_node.get_deep_attribute("item", "jid"); if (jid != null) { flag.set_real_jid(presence.from, jid); received_occupant_jid(stream, presence.from, jid); } - string? role = x_node["item", "role"].val; + string? role = x_node.get_deep_attribute("item", "role"); if (role != null) { received_occupant_role(stream, presence.from, role); } diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala index 5170c80a..0e0d9489 100644 --- a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala +++ b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala @@ -77,7 +77,7 @@ public class Module : XmppStreamModule { public override void detach(XmppStream stream) { } public static void require(XmppStream stream) { - if (stream.get_module(IDENTITY) == null) stderr.printf(""); + if (stream.get_module(IDENTITY) == null) stream.add_module(new Module()); } public override string get_ns() { return NS_URI; } |