aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/module/xep')
-rw-r--r--xmpp-vala/src/module/xep/0166_jingle/component.vala12
-rw-r--r--xmpp-vala/src/module/xep/0166_jingle/content.vala4
-rw-r--r--xmpp-vala/src/module/xep/0167_jingle_rtp/jingle_rtp_module.vala18
-rw-r--r--xmpp-vala/src/module/xep/0176_jingle_ice_udp/transport_parameters.vala2
-rw-r--r--xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala20
-rw-r--r--xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala118
-rw-r--r--xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala2
7 files changed, 97 insertions, 79 deletions
diff --git a/xmpp-vala/src/module/xep/0166_jingle/component.vala b/xmpp-vala/src/module/xep/0166_jingle/component.vala
index 544bcd69..5d573522 100644
--- a/xmpp-vala/src/module/xep/0166_jingle/component.vala
+++ b/xmpp-vala/src/module/xep/0166_jingle/component.vala
@@ -31,7 +31,11 @@ namespace Xmpp.Xep.Jingle {
protected Gee.Promise<IOStream> promise = new Gee.Promise<IOStream>();
private string? terminated = null;
- public async void init(IOStream stream) {
+ public async void set_stream(IOStream? stream) {
+ if (stream == null) {
+ promise.set_exception(new IOError.FAILED("Jingle connection failed"));
+ return;
+ }
assert(!this.stream.ready);
promise.set_value(stream);
if (terminated != null) {
@@ -39,11 +43,17 @@ namespace Xmpp.Xep.Jingle {
}
}
+ public void set_error(GLib.Error? e) {
+ promise.set_exception(e);
+ }
+
public override async void terminate(bool we_terminated, string? reason_name = null, string? reason_text = null) {
if (terminated == null) {
terminated = (reason_name ?? "") + " - " + (reason_text ?? "") + @"we terminated? $we_terminated";
if (stream.ready) {
yield stream.value.close_async();
+ } 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 befe02f4..41310aeb 100644
--- a/xmpp-vala/src/module/xep/0166_jingle/content.vala
+++ b/xmpp-vala/src/module/xep/0166_jingle/content.vala
@@ -36,7 +36,7 @@ public class Xmpp.Xep.Jingle.Content : Object {
public HashMap<string, ContentEncryption> encryptions = new HashMap<string, ContentEncryption>();
- public Set<string> tried_transport_methods = new HashSet<string>();
+ private Set<string> tried_transport_methods = new HashSet<string>();
public Content.initiate_sent(string content_name, Senders senders,
@@ -109,7 +109,7 @@ public class Xmpp.Xep.Jingle.Content : Object {
transport_params.dispose();
foreach (ComponentConnection connection in component_connections.values) {
- connection.terminate(we_terminated, reason_name, reason_text);
+ connection.terminate.begin(we_terminated, reason_name, reason_text);
}
}
diff --git a/xmpp-vala/src/module/xep/0167_jingle_rtp/jingle_rtp_module.vala b/xmpp-vala/src/module/xep/0167_jingle_rtp/jingle_rtp_module.vala
index 6eb6289b..6b55cbe6 100644
--- a/xmpp-vala/src/module/xep/0167_jingle_rtp/jingle_rtp_module.vala
+++ b/xmpp-vala/src/module/xep/0167_jingle_rtp/jingle_rtp_module.vala
@@ -83,7 +83,7 @@ public abstract class Module : XmppStreamModule {
}
}
- public async Jingle.Content add_outgoing_video_content(XmppStream stream, Jingle.Session session) {
+ public async Jingle.Content add_outgoing_video_content(XmppStream stream, Jingle.Session session) throws Jingle.Error {
Jid my_jid = session.local_full_jid;
Jid receiver_full_jid = session.peer_full_jid;
@@ -168,7 +168,7 @@ public class Crypto {
public string? session_params { get; private set; }
public string tag { get; private set; }
- public uint8[] key_and_salt { owned get {
+ public uint8[]? key_and_salt { owned get {
if (!key_params.has_prefix("inline:")) return null;
int endIndex = key_params.index_of("|");
if (endIndex < 0) endIndex = key_params.length;
@@ -221,30 +221,30 @@ public class Crypto {
case AES_CM_128_HMAC_SHA1_80:
case AES_CM_128_HMAC_SHA1_32:
case F8_128_HMAC_SHA1_80:
- return key_and_salt.length == 30;
+ return key_and_salt != null && key_and_salt.length == 30;
}
return false;
}}
- public uint8[] key { owned get {
- uint8[] key_and_salt = key_and_salt;
+ public uint8[]? key { owned get {
+ uint8[]? key_and_salt = key_and_salt;
switch(crypto_suite) {
case AES_CM_128_HMAC_SHA1_80:
case AES_CM_128_HMAC_SHA1_32:
case F8_128_HMAC_SHA1_80:
- if (key_and_salt.length >= 16) return key_and_salt[0:16];
+ if (key_and_salt != null && key_and_salt.length >= 16) return key_and_salt[0:16];
break;
}
return null;
}}
- public uint8[] salt { owned get {
- uint8[] keyAndSalt = key_and_salt;
+ public uint8[]? salt { owned get {
+ uint8[]? key_and_salt = key_and_salt;
switch(crypto_suite) {
case AES_CM_128_HMAC_SHA1_80:
case AES_CM_128_HMAC_SHA1_32:
case F8_128_HMAC_SHA1_80:
- if (keyAndSalt.length >= 30) return keyAndSalt[16:30];
+ if (key_and_salt != null && key_and_salt.length >= 30) return key_and_salt[16:30];
break;
}
return null;
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 83da296b..07b599ee 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
@@ -152,7 +152,7 @@ public abstract class Xmpp.Xep.JingleIceUdp.IceUdpTransportParameters : Jingle.T
return sb.str;
}
- private uint8[] fingerprint_to_bytes(string? fingerprint_) {
+ private uint8[]? fingerprint_to_bytes(string? fingerprint_) {
if (fingerprint_ == null) return null;
string fingerprint = fingerprint_.replace(":", "").up();
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 07b158bc..4581019f 100644
--- a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala
+++ b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala
@@ -268,13 +268,19 @@ public class FileTransfer : Object {
content.accept();
Jingle.StreamingConnection connection = content.component_connections.values.to_array()[0] as Jingle.StreamingConnection;
- IOStream? io_stream = yield connection.stream.wait_async();
- FileTransferInputStream ft_stream = new FileTransferInputStream(io_stream.input_stream, size);
- io_stream.output_stream.close();
- ft_stream.closed.connect(() => {
- session.terminate(Jingle.ReasonElement.SUCCESS, null, null);
- });
- this.stream = ft_stream;
+ try {
+ IOStream io_stream = yield connection.stream.wait_async();
+ FileTransferInputStream ft_stream = new FileTransferInputStream(io_stream.input_stream, size);
+ io_stream.output_stream.close();
+ ft_stream.closed.connect(() => {
+ session.terminate(Jingle.ReasonElement.SUCCESS, null, null);
+ });
+ this.stream = ft_stream;
+ } catch (FutureError.EXCEPTION e) {
+ warning("Error accepting Jingle file-transfer: %s", connection.stream.exception.message);
+ } catch (FutureError e) {
+ warning("FutureError accepting Jingle file-transfer: %s", e.message);
+ }
}
public void reject(XmppStream stream) {
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 6edebbbc..47c243e8 100644
--- a/xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala
+++ b/xmpp-vala/src/module/xep/0260_jingle_socks5_bytestreams.vala
@@ -28,6 +28,7 @@ public class Module : Jingle.Transport, XmppStreamModule {
public string ns_uri { get { return NS_URI; } }
public Jingle.TransportType type_ { get { return Jingle.TransportType.STREAMING; } }
public int priority { get { return 1; } }
+
private Gee.List<Candidate> get_proxies(XmppStream stream) {
Gee.List<Candidate> result = new ArrayList<Candidate>();
int i = 1 << 15;
@@ -37,6 +38,7 @@ public class Module : Jingle.Transport, XmppStreamModule {
}
return result;
}
+
private Gee.List<Candidate> start_local_listeners(XmppStream stream, Jid local_full_jid, string dstaddr, out LocalListener? local_listener) {
Gee.List<Candidate> result = new ArrayList<Candidate>();
SocketListener listener = new SocketListener();
@@ -62,15 +64,17 @@ public class Module : Jingle.Transport, XmppStreamModule {
}
return result;
}
+
private void select_candidates(XmppStream stream, Jid local_full_jid, string dstaddr, Parameters result) {
result.local_candidates.add_all(get_proxies(stream));
- //result.local_candidates.add_all(start_local_listeners(stream, local_full_jid, dstaddr, out result.listener));
+ result.local_candidates.add_all(start_local_listeners(stream, local_full_jid, dstaddr, out result.listener));
result.local_candidates.sort((c1, c2) => {
if (c1.priority < c2.priority) { return 1; }
if (c1.priority > c2.priority) { return -1; }
return 0;
});
}
+
public Jingle.TransportParameters create_transport_parameters(XmppStream stream, uint8 components, Jid local_full_jid, Jid peer_full_jid) {
assert(components == 1);
Parameters result = new Parameters.create(local_full_jid, peer_full_jid, random_uuid());
@@ -78,6 +82,7 @@ public class Module : Jingle.Transport, XmppStreamModule {
select_candidates(stream, local_full_jid, dstaddr, result);
return result;
}
+
public Jingle.TransportParameters parse_transport_parameters(XmppStream stream, uint8 components, Jid local_full_jid, Jid peer_full_jid, StanzaNode transport) throws Jingle.IqError {
Parameters result = Parameters.parse(local_full_jid, peer_full_jid, transport);
string dstaddr = calculate_dstaddr(result.sid, local_full_jid, peer_full_jid);
@@ -146,6 +151,7 @@ public class Candidate : Socks5Bytestreams.Proxy {
public Candidate.build(string cid, string host, Jid jid, int port, int local_priority, CandidateType type) {
this(cid, host, jid, port, type.type_preference() + local_priority, type);
}
+
public Candidate.proxy(string cid, Socks5Bytestreams.Proxy proxy, int local_priority) {
this.build(cid, proxy.host, proxy.jid, proxy.port, local_priority, CandidateType.PROXY);
}
@@ -170,6 +176,7 @@ public class Candidate : Socks5Bytestreams.Proxy {
return new Candidate(cid, host, jid, port, priority, type);
}
+
public StanzaNode to_xml() {
return new StanzaNode.build("candidate", NS_URI)
.put_attribute("cid", cid)
@@ -210,6 +217,7 @@ class LocalListener {
this.inner = inner;
this.dstaddr = dstaddr;
}
+
public LocalListener.empty() {
this.inner = null;
this.dstaddr = "";
@@ -233,6 +241,7 @@ class LocalListener {
handle_conn.begin(((StringWrapper)cid).str, conn);
}
}
+
async void handle_conn(string cid, SocketConnection conn) {
conn.socket.timeout = NEGOTIATION_TIMEOUT;
size_t read;
@@ -418,39 +427,39 @@ class Parameters : Jingle.TransportParameters, Object {
}
public void handle_transport_info(StanzaNode transport) throws Jingle.IqError {
- StanzaNode? candidate_error = transport.get_subnode("candidate-error", NS_URI);
- StanzaNode? candidate_used = transport.get_subnode("candidate-used", NS_URI);
- StanzaNode? activated = transport.get_subnode("activated", NS_URI);
- StanzaNode? proxy_error = transport.get_subnode("proxy-error", NS_URI);
- int num_children = 0;
- if (candidate_error != null) { num_children += 1; }
- if (candidate_used != null) { num_children += 1; }
- if (activated != null) { num_children += 1; }
- if (proxy_error != null) { num_children += 1; }
- if (num_children == 0) {
- throw new Jingle.IqError.UNSUPPORTED_INFO("unknown transport-info");
- } else if (num_children > 1) {
- throw new Jingle.IqError.BAD_REQUEST("transport-info with more than one child");
- }
- if (candidate_error != null) {
- handle_remote_candidate(null);
- }
- if (candidate_used != null) {
- string? cid = candidate_used.get_attribute("cid");
- if (cid == null) {
- throw new Jingle.IqError.BAD_REQUEST("missing cid");
- }
- handle_remote_candidate(cid);
- }
- if (activated != null) {
- string? cid = activated.get_attribute("cid");
- if (cid == null) {
- throw new Jingle.IqError.BAD_REQUEST("missing cid");
- }
- handle_activated(cid);
+ ArrayList<StanzaNode> socks5_nodes = new ArrayList<StanzaNode>();
+ foreach (StanzaNode node in transport.sub_nodes) {
+ if (node.ns_uri == NS_URI) socks5_nodes.add(node);
}
- if (proxy_error != null) {
- handle_proxy_error();
+ if (socks5_nodes.is_empty) { warning("No socks5 subnodes in transport node"); return; }
+ if (socks5_nodes.size > 1) { warning("Too many socks5 subnodes in transport node"); return; }
+
+ StanzaNode node = socks5_nodes[0];
+
+ switch (node.name) {
+ case "activated":
+ string? cid = node.get_attribute("cid");
+ if (cid == null) {
+ throw new Jingle.IqError.BAD_REQUEST("missing cid");
+ }
+ handle_activated(cid);
+ break;
+ case "candidate-used":
+ string? cid = node.get_attribute("cid");
+ if (cid == null) {
+ throw new Jingle.IqError.BAD_REQUEST("missing cid");
+ }
+ handle_remote_candidate(cid);
+ break;
+ case "candidate-error":
+ handle_remote_candidate(null);
+ break;
+ case "proxy-error":
+ handle_proxy_error();
+ break;
+ default:
+ warning("Unknown transport-info: %s", transport.to_string());
+ break;
}
}
@@ -499,32 +508,22 @@ class Parameters : Jingle.TransportParameters, Object {
return;
}
- Candidate? remote = remote_selected_candidate;
- Candidate? local = local_selected_candidate;
-
- int num_candidates = 0;
- if (remote != null) { num_candidates += 1; }
- if (local != null) { num_candidates += 1; }
-
- if (num_candidates == 0) {
- // Notify Jingle of the failed transport.
- content_set_transport_connection(null);
+ if (remote_selected_candidate == null && local_selected_candidate == null) {
+ content_set_transport_connection_error(new IOError.FAILED("No candidates"));
return;
}
bool remote_wins;
- if (num_candidates == 1) {
- remote_wins = remote != null;
- } else {
- if (local.priority < remote.priority) {
- remote_wins = true;
- } else if (local.priority > remote.priority) {
- remote_wins = false;
- } else {
+ if (remote_selected_candidate != null && local_selected_candidate != null) {
+ if (local_selected_candidate.priority == remote_selected_candidate.priority) {
// equal priority -> XEP-0260 says that the candidate offered
// by the initiator wins, so the one that the remote chose
remote_wins = role == Jingle.Role.INITIATOR;
+ } else {
+ remote_wins = local_selected_candidate.priority < remote_selected_candidate.priority;
}
+ } else {
+ remote_wins = remote_selected_candidate != null;
}
if (!remote_wins) {
@@ -545,8 +544,7 @@ class Parameters : Jingle.TransportParameters, Object {
}
SocketConnection? conn = listener.get_connection(remote_selected_candidate.cid);
if (conn == null) {
- // Remote hasn't actually connected to us?!
- content_set_transport_connection(null);
+ content_set_transport_connection_error(new IOError.FAILED("Remote hasn't actually connected to us?!"));
return;
}
content_set_transport_connection(conn);
@@ -569,7 +567,7 @@ class Parameters : Jingle.TransportParameters, Object {
if (!waiting_for_activation_error) {
content_set_transport_connection(conn);
} else {
- content_set_transport_connection(null);
+ content_set_transport_connection_error(new IOError.FAILED("waiting_for_activation_error"));
}
}
@@ -620,7 +618,7 @@ class Parameters : Jingle.TransportParameters, Object {
.put_attribute("sid", sid)
.put_node(new StanzaNode.build("proxy-error", NS_URI))
);
- content_set_transport_connection(null);
+ content_set_transport_connection_error(new IOError.FAILED("Connect to local candidate error: %s", e.message));
}
}
@@ -745,15 +743,19 @@ class Parameters : Jingle.TransportParameters, Object {
private Jingle.StreamingConnection connection = new Jingle.StreamingConnection();
- private void content_set_transport_connection(IOStream? ios) {
- IOStream? iostream = ios;
+ private void content_set_transport_connection(IOStream ios) {
+ IOStream iostream = ios;
Jingle.Content? strong_content = content;
if (strong_content == null) return;
if (strong_content.security_params != null) {
iostream = strong_content.security_params.wrap_stream(iostream);
}
- connection.init.begin(iostream);
+ connection.set_stream.begin(iostream);
+ }
+
+ private void content_set_transport_connection_error(Error e) {
+ connection.set_error(e);
}
public void create_transport_connection(XmppStream stream, Jingle.Content content) {
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 f7c77544..09eaf711 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
@@ -98,7 +98,7 @@ class Parameters : Jingle.TransportParameters, Object {
if (content.security_params != null) {
iostream = content.security_params.wrap_stream(iostream);
}
- connection.init.begin(iostream);
+ connection.set_stream.begin(iostream);
debug("set transport conn ibb");
content.set_transport_connection(connection, 1);
}