aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0166_jingle/content_node.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-05-11 12:57:02 +0200
committerfiaxh <git@lightrise.org>2021-05-11 12:57:02 +0200
commitd71604913dd5b3372a823320db83c37c845fac5c (patch)
tree2ffbff97a02c81d48d8aef4a4b7ee870507236e9 /xmpp-vala/src/module/xep/0166_jingle/content_node.vala
parente92ed27317ae398c867c946cf7206b1f0b32f3b4 (diff)
parent90f9ecf62b2ebfef14de2874e7942552409632bf (diff)
downloaddino-d71604913dd5b3372a823320db83c37c845fac5c.tar.gz
dino-d71604913dd5b3372a823320db83c37c845fac5c.zip
Merge remote-tracking branch 'origin/feature/calls'
Diffstat (limited to 'xmpp-vala/src/module/xep/0166_jingle/content_node.vala')
-rw-r--r--xmpp-vala/src/module/xep/0166_jingle/content_node.vala112
1 files changed, 112 insertions, 0 deletions
diff --git a/xmpp-vala/src/module/xep/0166_jingle/content_node.vala b/xmpp-vala/src/module/xep/0166_jingle/content_node.vala
new file mode 100644
index 00000000..7d8d56c8
--- /dev/null
+++ b/xmpp-vala/src/module/xep/0166_jingle/content_node.vala
@@ -0,0 +1,112 @@
+using Gee;
+using Xmpp.Xep;
+using Xmpp;
+
+namespace Xmpp.Xep.Jingle {
+
+ class ContentNode {
+ public Role creator;
+ public string name;
+ public Senders senders;
+ public StanzaNode? description;
+ public StanzaNode? transport;
+ public StanzaNode? security;
+ }
+
+ [Version(deprecated = true)]
+ ContentNode get_single_content_node(StanzaNode jingle) throws IqError {
+ Gee.List<StanzaNode> contents = jingle.get_subnodes("content");
+ if (contents.size == 0) {
+ throw new IqError.BAD_REQUEST("missing content node");
+ }
+ if (contents.size > 1) {
+ throw new IqError.NOT_IMPLEMENTED("can't process multiple content nodes");
+ }
+ StanzaNode content = contents[0];
+ string? creator_str = content.get_attribute("creator");
+ // Vala can't typecheck the ternary operator here.
+ Role? creator = null;
+ if (creator_str != null) {
+ creator = Role.parse(creator_str);
+ } else {
+ // TODO(hrxi): now, is the creator attribute optional or not (XEP-0166
+ // Jingle)?
+ creator = Role.INITIATOR;
+ }
+
+ string? name = content.get_attribute("name");
+
+ Senders senders = Senders.parse(content.get_attribute("senders"));
+
+ StanzaNode? description = get_single_node_anyns(content, "description");
+ StanzaNode? transport = get_single_node_anyns(content, "transport");
+ StanzaNode? security = get_single_node_anyns(content, "security");
+ if (name == null || creator == null) {
+ throw new IqError.BAD_REQUEST("missing name or creator");
+ }
+
+ return new ContentNode() {
+ creator=creator,
+ name=name,
+ senders=senders,
+ description=description,
+ transport=transport,
+ security=security
+ };
+ }
+
+ Gee.List<ContentNode> get_content_nodes(StanzaNode jingle) throws IqError {
+ Gee.List<StanzaNode> contents = jingle.get_subnodes("content");
+ if (contents.size == 0) {
+ throw new IqError.BAD_REQUEST("missing content node");
+ }
+ Gee.List<ContentNode> list = new ArrayList<ContentNode>();
+ foreach (StanzaNode content in contents) {
+ string? creator_str = content.get_attribute("creator");
+ // Vala can't typecheck the ternary operator here.
+ Role? creator = null;
+ if (creator_str != null) {
+ creator = Role.parse(creator_str);
+ } else {
+ // TODO(hrxi): now, is the creator attribute optional or not (XEP-0166
+ // Jingle)?
+ creator = Role.INITIATOR;
+ }
+
+ string? name = content.get_attribute("name");
+ Senders senders = Senders.parse(content.get_attribute("senders"));
+ StanzaNode? description = get_single_node_anyns(content, "description");
+ StanzaNode? transport = get_single_node_anyns(content, "transport");
+ StanzaNode? security = get_single_node_anyns(content, "security");
+ if (name == null || creator == null) {
+ throw new IqError.BAD_REQUEST("missing name or creator");
+ }
+ list.add(new ContentNode() {
+ creator=creator,
+ name=name,
+ senders=senders,
+ description=description,
+ transport=transport,
+ security=security
+ });
+ }
+ return list;
+ }
+
+ StanzaNode? get_single_node_anyns(StanzaNode parent, string? node_name = null) throws IqError {
+ StanzaNode? result = null;
+ foreach (StanzaNode child in parent.get_all_subnodes()) {
+ if (node_name == null || child.name == node_name) {
+ if (result != null) {
+ if (node_name != null) {
+ throw new IqError.BAD_REQUEST(@"multiple $(node_name) nodes");
+ } else {
+ throw new IqError.BAD_REQUEST(@"expected single subnode");
+ }
+ }
+ result = child;
+ }
+ }
+ return result;
+ }
+} \ No newline at end of file