From 3a8df2069eba3a5a4174749fc46a6698c1877ec1 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 30 May 2017 22:17:41 +0200 Subject: MUC config form (data forms), MUC room info --- xmpp-vala/src/module/iq/module.vala | 10 +- xmpp-vala/src/module/stanza.vala | 2 +- xmpp-vala/src/module/stanza_error.vala | 2 +- xmpp-vala/src/module/stream_error.vala | 2 +- xmpp-vala/src/module/xep/0004_data_forms.vala | 208 +++++++++++++++++++++ xmpp-vala/src/module/xep/0045_muc/flag.vala | 10 + xmpp-vala/src/module/xep/0045_muc/module.vala | 79 +++++++- .../src/module/xep/0048_bookmarks/module.vala | 6 +- .../module/xep/0085_chat_state_notifications.vala | 2 +- xmpp-vala/src/module/xep/0333_chat_markers.vala | 2 +- 10 files changed, 307 insertions(+), 16 deletions(-) create mode 100644 xmpp-vala/src/module/xep/0004_data_forms.vala (limited to 'xmpp-vala/src/module') diff --git a/xmpp-vala/src/module/iq/module.vala b/xmpp-vala/src/module/iq/module.vala index eed3389d..909ec984 100644 --- a/xmpp-vala/src/module/iq/module.vala +++ b/xmpp-vala/src/module/iq/module.vala @@ -11,15 +11,15 @@ namespace Xmpp.Iq { private HashMap responseListeners = new HashMap(); private HashMap> namespaceRegistrants = new HashMap>(); - [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, Iq.Stanza iq, Object reference); - public void send_iq(XmppStream stream, Iq.Stanza iq, OnResult? listener = null, Object? reference = null) { + [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, Iq.Stanza iq, Object store); + public void send_iq(XmppStream stream, Iq.Stanza iq, OnResult? listener = null, Object? store = null) { try { stream.write(iq.stanza); } catch (IOStreamError e) { print(@"$(e.message)\n"); } if (listener != null) { - responseListeners[iq.id] = new ResponseListener(listener, reference); + responseListeners[iq.id] = new ResponseListener(listener, store); } } @@ -61,9 +61,9 @@ namespace Xmpp.Iq { responseListeners.unset(iq.id); } } else { - ArrayList children = node.get_all_subnodes(); + Gee.List children = node.get_all_subnodes(); if (children.size == 1 && namespaceRegistrants.has_key(children[0].ns_uri)) { - ArrayList handlers = namespaceRegistrants[children[0].ns_uri]; + Gee.List handlers = namespaceRegistrants[children[0].ns_uri]; foreach (Handler handler in handlers) { if (iq.type_ == Iq.Stanza.TYPE_GET) { handler.on_iq_get(stream, iq); diff --git a/xmpp-vala/src/module/stanza.vala b/xmpp-vala/src/module/stanza.vala index 85cbadb7..2bf3e29b 100644 --- a/xmpp-vala/src/module/stanza.vala +++ b/xmpp-vala/src/module/stanza.vala @@ -2,7 +2,7 @@ using Xmpp.Core; namespace Xmpp { - public class Stanza { + public class Stanza : Object { public const string ATTRIBUTE_FROM = "from"; public const string ATTRIBUTE_ID = "id"; diff --git a/xmpp-vala/src/module/stanza_error.vala b/xmpp-vala/src/module/stanza_error.vala index be4633e9..b34caeb0 100644 --- a/xmpp-vala/src/module/stanza_error.vala +++ b/xmpp-vala/src/module/stanza_error.vala @@ -40,7 +40,7 @@ namespace Xmpp { public string condition { get { - ArrayList subnodes = error_node.sub_nodes; + Gee.List subnodes = error_node.sub_nodes; foreach (StanzaNode subnode in subnodes) { // TODO get subnode by ns if (subnode.ns_uri == "urn:ietf:params:xml:ns:xmpp-stanzas") { return subnode.name; diff --git a/xmpp-vala/src/module/stream_error.vala b/xmpp-vala/src/module/stream_error.vala index bd292d2b..fa54d06f 100644 --- a/xmpp-vala/src/module/stream_error.vala +++ b/xmpp-vala/src/module/stream_error.vala @@ -32,7 +32,7 @@ namespace Xmpp.StreamError { private Flag generate_error_flag(StanzaNode node) { string? subnode_name = null; - ArrayList subnodes = node.sub_nodes; + Gee.List subnodes = node.sub_nodes; foreach (StanzaNode subnode in subnodes) { // TODO get subnode by ns if (subnode.ns_uri == "urn:ietf:params:xml:ns:xmpp-streams" && subnode.name != "text") { subnode_name = subnode.name; diff --git a/xmpp-vala/src/module/xep/0004_data_forms.vala b/xmpp-vala/src/module/xep/0004_data_forms.vala new file mode 100644 index 00000000..add2fa9a --- /dev/null +++ b/xmpp-vala/src/module/xep/0004_data_forms.vala @@ -0,0 +1,208 @@ +using Gee; + +using Xmpp.Core; + +namespace Xmpp.Xep.DataForms { + +public const string NS_URI = "jabber:x:data"; + +public class DataForm { + + public StanzaNode stanza_node { get; set; } + public Gee.List fields = new ArrayList(); + + public XmppStream stream; + public OnResult on_result; + public Object? store; + + public void cancel() { + StanzaNode stanza_node = new StanzaNode.build("x", NS_URI); + stanza_node.add_self_xmlns().set_attribute("type", "cancel"); + on_result(stream, stanza_node, store); + } + + public void submit() { + stanza_node.set_attribute("type", "submit"); + on_result(stream, stanza_node, store); + } + + public enum Type { + BOOLEAN, + FIXED, + HIDDEN, + JID_MULTI, + LIST_SINGLE, + LIST_MULTI, + TEXT_PRIVATE, + TEXT_SINGLE, + } + + public class Option { + public string label { get; set; } + public string value { get; set; } + + public Option(string label, string value) { + this.label = label; + this.value = value; + } + } + + public abstract class Field { + public string label { + get { return node.get_attribute("label", NS_URI); } + set { node.set_attribute("label", value); } + } + public StanzaNode node { get; set; } + public abstract Type type_ { get; internal set; } + public string var { + get { return node.get_attribute("var", NS_URI); } + set { node.set_attribute("var", value); } + } + + public Field(StanzaNode node) { + this.node = node; + } + + internal Gee.List get_values() { + Gee.List ret = new ArrayList(); + Gee.List value_nodes = node.get_subnodes("value", NS_URI); + foreach (StanzaNode node in value_nodes) { + ret.add(node.get_string_content()); + } + return ret; + } + + internal string get_value_string() { + Gee.List values = get_values(); + return values.size > 0 ? values[0] : ""; + } + + internal void set_value_string(string val) { + StanzaNode? value_node = node.get_subnode("value", NS_URI); + if (value_node == null) { + value_node = new StanzaNode.build("value", NS_URI); + node.put_node(value_node); + } + value_node.sub_nodes.clear(); + 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