protected void StartPlaintextStream(CancellationToken canceltoken) { using (var stream = Connect(EndpointHost, EndpointPort, ProxyHost, ProxyPort)) { using (var xml = new XmlStream(stream)) { using (var xmppstream = xml.WriteStart(new XElement(NamespaceStream + "stream", new XAttribute("to", Domain), new XAttribute(XNamespace.Xml + "lang", "en"), new XAttribute("version", "1.0")))) { xml.ReadStartElement(NamespaceStream + "stream"); xml.Expect((rdr) => rdr.GetAttribute("from") == Domain, (rdr) => String.Format("Expected domain {0}; got domain {1}", Domain, rdr.GetAttribute("from"))); var features = xml.ReadElement(NamespaceStream + "features"); xml.Write(new XElement(NamespaceStartTLS + "starttls")); xml.ReadStartElement(NamespaceStartTLS + "proceed"); xml.Stream.Logged = false; using (var ssl = new SslStream(xml.Stream, true, (sender, cert, chain, errs) => true)) { ssl.AuthenticateAsClient(EndpointHost); using (var sslxml = new XmlStream(ssl)) { StartTLSStream(sslxml, canceltoken); } } } } } }
protected void ProcessInfoQuery(XmlStream xml, InfoQuery iq) { int id = InfoQueryID.NewId(); xml.Write( new XElement(NamespaceClient + "iq", new XAttribute("type", iq.Type), iq.To == null ? null : new XAttribute("to", iq.To), new XAttribute("id", id), iq.Content ) ); RunningQueries[id.ToString()] = iq; }
public DisposableXElement(XmlStream stream, XElement element) { Stream = stream; Stream.Writer.WriteStartElement(element.Name.LocalName, element.Name.NamespaceName); var rdr = element.CreateReader(); rdr.Read(); Stream.Writer.WriteAttributes(rdr, false); foreach (XNode node in element.Nodes()) { Stream.Write(node); } Stream.Writer.WriteWhitespace(""); Stream.Writer.Flush(); }
protected void StartXMPPStream(XmlStream xml, CancellationToken canceltoken) { using (var xmppstream = xml.WriteStart(new XElement(NamespaceStream + "stream", new XAttribute("to", Domain), new XAttribute(XNamespace.Xml + "lang", "en"), new XAttribute("version", "1.0")))) { xml.ReadStartElement(NamespaceStream + "stream"); xml.Expect((rdr) => rdr.GetAttribute("from") == Domain, (rdr) => String.Format("Expected domain {0}; got domain {1}", Domain, rdr.GetAttribute("from"))); var features = xml.ReadElement(NamespaceStream + "features"); ReaderThread = new Thread(new ThreadStart(() => XMPPReader(xml, canceltoken))); ReaderThread.Start(); BeginBind(); while (!canceltoken.IsCancellationRequested) { switch (WaitHandle.WaitAny(new WaitHandle[] { canceltoken.WaitHandle, ReaderFaulted, QueriesQueued, IsReadyForSubscriptions ? SubscriptionsQueued : QueriesQueued, ResponsesQueued, MessagesQueued }, 15000)) { case 0: break; case 1: throw new AggregateException(ReaderException); case 2: ProcessQueuedQueries(xml, canceltoken); break; case 3: goto case 2; case 4: ProcessQueuedResponses(xml, canceltoken); break; case 5: ProcessQueuedMessages(xml, canceltoken); break; case WaitHandle.WaitTimeout: xml.Write(new XText(" ")); break; } } throw new OperationCanceledException(); } }
protected void StartTLSStream(XmlStream xml, CancellationToken canceltoken) { using (var xmppstream = xml.WriteStart(new XElement(NamespaceStream + "stream", new XAttribute("to", Domain), new XAttribute(XNamespace.Xml + "lang", "en"), new XAttribute("version", "1.0")))) { xml.ReadStartElement(NamespaceStream + "stream"); xml.Expect((rdr) => rdr.GetAttribute("from") == Domain, (rdr) => String.Format("Expected domain {0}; got domain {1}", Domain, rdr.GetAttribute("from"))); var features = xml.ReadElement(NamespaceStream + "features"); xml.Write( new XElement(NamespaceSASL + "auth", new XAttribute("mechanism", AuthMechanism), new XAttribute(NamespaceAuth + "service", "chromiumsync"), new XAttribute(NamespaceAuth + "allow-generated-jid", "true"), new XAttribute(NamespaceAuth + "client-uses-full-bind-result", "true"), new XText(Convert.ToBase64String(Encoding.ASCII.GetBytes("\0" + LoginJID + "\0" + AuthCookie))) ) ); xml.ReadStartElement(NamespaceSASL + "success"); xml.Stream.Logged = false; StartXMPPStream(new XmlStream(xml.Stream), canceltoken); } }