From b148ff8dd9024a87517c30be0aa0a346e7c16ef2 Mon Sep 17 00:00:00 2001 From: lumi Date: Sun, 19 Feb 2017 15:25:18 +0100 Subject: [PATCH] Client can now connect --- src/client.rs | 11 +++++++++-- src/transport.rs | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/client.rs b/src/client.rs index 7a26ca6..de3b84f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,9 @@ use jid::Jid; -use transport::SslTransport; +use transport::{Transport, SslTransport}; use error::Error; +use ns; + +use xml::writer::XmlEvent; pub struct ClientBuilder { jid: Jid, @@ -29,7 +32,11 @@ impl ClientBuilder { pub fn connect(self) -> Result { let host = &self.host.unwrap_or(self.jid.domain.clone()); - let transport = SslTransport::connect(host, self.port)?; + let mut transport = SslTransport::connect(host, self.port)?; + transport.write_event(XmlEvent::start_element("stream:stream") + .attr("to", &self.jid.domain) + .default_ns(ns::CLIENT) + .ns("stream", ns::STREAM))?; Ok(Client { jid: self.jid, transport: transport diff --git a/src/transport.rs b/src/transport.rs index f016412..cd7aa3e 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -3,7 +3,7 @@ use std::io::prelude::*; use std::net::TcpStream; use xml::reader::{EventReader, XmlEvent as XmlReaderEvent}; -use xml::writer::{EventWriter, XmlEvent as XmlWriterEvent}; +use xml::writer::{EventWriter, XmlEvent as XmlWriterEvent, EmitterConfig}; use std::sync::{Arc, Mutex}; @@ -67,7 +67,12 @@ impl SslTransport { let ssl_stream = Arc::new(Mutex::new(ssl_connector.connect(host, stream)?)); let locked_io = LockedIO::from(ssl_stream.clone()); let reader = EventReader::new(locked_io.clone()); - let writer = EventWriter::new(locked_io); + let writer = EventWriter::new_with_config(locked_io, EmitterConfig { + line_separator: "".into(), + perform_indent: false, + normalize_empty_elements: false, + .. Default::default() + }); Ok(SslTransport { inner: ssl_stream, reader: reader,