Client can now connect

This commit is contained in:
lumi 2017-02-19 15:25:18 +01:00
parent 82a26d7d08
commit b148ff8dd9
2 changed files with 16 additions and 4 deletions

View file

@ -1,6 +1,9 @@
use jid::Jid; use jid::Jid;
use transport::SslTransport; use transport::{Transport, SslTransport};
use error::Error; use error::Error;
use ns;
use xml::writer::XmlEvent;
pub struct ClientBuilder { pub struct ClientBuilder {
jid: Jid, jid: Jid,
@ -29,7 +32,11 @@ impl ClientBuilder {
pub fn connect(self) -> Result<Client, Error> { pub fn connect(self) -> Result<Client, Error> {
let host = &self.host.unwrap_or(self.jid.domain.clone()); 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 { Ok(Client {
jid: self.jid, jid: self.jid,
transport: transport transport: transport

View file

@ -3,7 +3,7 @@ use std::io::prelude::*;
use std::net::TcpStream; use std::net::TcpStream;
use xml::reader::{EventReader, XmlEvent as XmlReaderEvent}; 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}; use std::sync::{Arc, Mutex};
@ -67,7 +67,12 @@ impl SslTransport {
let ssl_stream = Arc::new(Mutex::new(ssl_connector.connect(host, stream)?)); let ssl_stream = Arc::new(Mutex::new(ssl_connector.connect(host, stream)?));
let locked_io = LockedIO::from(ssl_stream.clone()); let locked_io = LockedIO::from(ssl_stream.clone());
let reader = EventReader::new(locked_io.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 { Ok(SslTransport {
inner: ssl_stream, inner: ssl_stream,
reader: reader, reader: reader,