| 1 |
public class Xmpp.DirectTlsXmppStream : TlsXmppStream { |
| 2 |
|
| 3 |
const string[] ADVERTISED_PROTOCOLS = {"xmpp-client", null}; |
| 4 |
|
| 5 |
string host; |
| 6 |
uint16 port; |
| 7 |
TlsXmppStream.OnInvalidCertWrapper on_invalid_cert; |
| 8 |
|
| 9 |
public DirectTlsXmppStream(Jid remote_name, string host, uint16 port, TlsXmppStream.OnInvalidCertWrapper on_invalid_cert) { |
| 10 |
base(remote_name); |
| 11 |
this.host = host; |
| 12 |
this.port = port; |
| 13 |
this.on_invalid_cert = on_invalid_cert; |
| 14 |
} |
| 15 |
|
| 16 |
public override async void connect() throws IOError { |
| 17 |
SocketClient client = new SocketClient(); |
| 18 |
try { |
| 19 |
debug("Connecting to %s:%i (tls)", host, port); |
| 20 |
IOStream? io_stream = yield client.connect_to_host_async(host, port, cancellable); |
| 21 |
TlsConnection tls_connection = TlsClientConnection.new(io_stream, new NetworkAddress(remote_name.to_string(), port)); |
| 22 |
#if GLIB_2_60 |
| 23 |
tls_connection.set_advertised_protocols(ADVERTISED_PROTOCOLS); |
| 24 |
#endif |
| 25 |
tls_connection.accept_certificate.connect(on_invalid_certificate); |
| 26 |
tls_connection.accept_certificate.connect((cert, flags) => on_invalid_cert.func(cert, flags)); |
| 27 |
reset_stream(tls_connection); |
| 28 |
|
| 29 |
yield setup(); |
| 30 |
|
| 31 |
attach_negotation_modules(); |
| 32 |
} catch (IOError e) { |
| 33 |
throw e; |
| 34 |
} catch (Error e) { |
| 35 |
throw new IOError.CONNECTION_REFUSED("Failed connecting to %s:%i (tls): %s", host, port, e.message); |
| 36 |
} |
| 37 |
} |
| 38 |
} |