diff options
author | Marvin W <git@larma.de> | 2021-03-21 12:41:06 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2021-03-21 12:41:06 +0100 |
commit | 5bd719a919eea613bd800bfca994156a4e9bb968 (patch) | |
tree | 6dedef83bc0a171e8ade9d95b939921f4afbe3c8 /xmpp-vala/src/module/xep/0176_jingle_ice_udp/candidate.vala | |
parent | 2b90fcc39a1079346d6c5e2bfff8987104da737a (diff) | |
download | dino-5bd719a919eea613bd800bfca994156a4e9bb968.tar.gz dino-5bd719a919eea613bd800bfca994156a4e9bb968.zip |
Add ICE-UDP Jingle transport (XEP-0176) to xmpp-vala
Co-authored-by: fiaxh <git@lightrise.org>
Diffstat (limited to 'xmpp-vala/src/module/xep/0176_jingle_ice_udp/candidate.vala')
-rw-r--r-- | xmpp-vala/src/module/xep/0176_jingle_ice_udp/candidate.vala | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/xmpp-vala/src/module/xep/0176_jingle_ice_udp/candidate.vala b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/candidate.vala new file mode 100644 index 00000000..a2988d90 --- /dev/null +++ b/xmpp-vala/src/module/xep/0176_jingle_ice_udp/candidate.vala @@ -0,0 +1,93 @@ +using Gee; +using Xmpp.Xep; +using Xmpp; + +public class Xmpp.Xep.JingleIceUdp.Candidate { + public uint8 component; + public uint8 foundation; + public uint8 generation; + public string id; + public string ip; + public uint8 network; + public uint16 port; + public uint32 priority; + public string protocol; + public string? rel_addr; + public uint16 rel_port; + public Type type_; + + public static Candidate parse(StanzaNode node) throws Jingle.IqError { + Candidate candidate = new Candidate(); + candidate.component = (uint8) node.get_attribute_uint("component"); + candidate.foundation = (uint8) node.get_attribute_uint("foundation"); + candidate.generation = (uint8) node.get_attribute_uint("generation"); + candidate.id = node.get_attribute("id"); + candidate.ip = node.get_attribute("ip"); + candidate.network = (uint8) node.get_attribute_uint("network"); + candidate.port = (uint16) node.get_attribute_uint("port"); + candidate.priority = (uint32) node.get_attribute_uint("priority"); + candidate.protocol = node.get_attribute("protocol"); + candidate.rel_addr = node.get_attribute("rel-addr"); + candidate.rel_port = (uint16) node.get_attribute_uint("rel-port"); + candidate.type_ = Type.parse(node.get_attribute("type")); + return candidate; + } + + public enum Type { + HOST, PRFLX, RELAY, SRFLX; + public static Type parse(string str) throws Jingle.IqError { + switch (str) { + case "host": return HOST; + case "prflx": return PRFLX; + case "relay": return RELAY; + case "srflx": return SRFLX; + default: throw new Jingle.IqError.BAD_REQUEST("Illegal ICE-UDP candidate type"); + } + } + public string to_string() { + switch (this) { + case HOST: return "host"; + case PRFLX: return "prflx"; + case RELAY: return "relay"; + case SRFLX: return "srflx"; + default: assert_not_reached(); + } + } + } + + public StanzaNode to_xml() { + StanzaNode node = new StanzaNode.build("candidate", NS_URI) + .put_attribute("component", component.to_string()) + .put_attribute("foundation", foundation.to_string()) + .put_attribute("generation", generation.to_string()) + .put_attribute("id", id) + .put_attribute("ip", ip) + .put_attribute("network", network.to_string()) + .put_attribute("port", port.to_string()) + .put_attribute("priority", priority.to_string()) + .put_attribute("protocol", protocol) + .put_attribute("type", type_.to_string()); + if (rel_addr != null) node.put_attribute("rel-addr", rel_addr); + if (rel_port != 0) node.put_attribute("rel-port", rel_port.to_string()); + return node; + } + + public bool equals(Candidate c) { + return equals_func(this, c); + } + + public static bool equals_func(Candidate c1, Candidate c2) { + return c1.component == c2.component && + c1.foundation == c2.foundation && + c1.generation == c2.generation && + c1.id == c2.id && + c1.ip == c2.ip && + c1.network == c2.network && + c1.port == c2.port && + c1.priority == c2.priority && + c1.protocol == c2.protocol && + c1.rel_addr == c2.rel_addr && + c1.rel_port == c2.rel_port && + c1.type_ == c2.type_; + } +}
\ No newline at end of file |