/// <summary> /// Procesa an arbitrary XMPP Message /// </summary> /// <param name = "node"></param> /// <returns></returns> private AutoResetEvent ProcessXmppMessage(XmppStreamElement node) { if (node != null) { Debug.WriteLine(node.ToString()); if (node.OpensXmppStream) { OnXmppStreamInitializedSubject.OnNext(node.ToString()); } else if (node.ClosesXmppStream) { OnXmppStreamClosedSubject.OnNext(node.ToString()); } else { var message = XmppSerializer.Deserialize(node.Name, node.ToString()); if (message != null) { if (message is Proceed) { return(tlsProceedEvent); } OnMessageReceivedSubject.OnNext(message); } } } return(null); }
/// <summary> /// Sends an XMPP message buffer to the XMPP Server /// </summary> public HttpBindBody SendSync(byte[] buffer) { Debug.WriteLine(Encoding.UTF8.GetString(buffer)); lock (SyncWrites) { HttpWebRequest webRequest = CreateWebRequest(); using (var stream = webRequest.GetRequestStream()) { stream.Write(buffer, 0, buffer.Length); var webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse.StatusCode == HttpStatusCode.OK) { using (var responseStream = webResponse.GetResponseStream()) { using (var responseReader = new StreamReader(responseStream, true)) { var response = responseReader.ReadToEnd(); // TODO: necessary? Debug.WriteLine(response); return(XmppSerializer.Deserialize("body", response) as HttpBindBody); } } } } return(null); } }
public void DeserializeWithMessage() { var xml = @"<stream:stream from=""*****@*****.**"" to=""im.example.com"" version=""1.0"" xml:lang=""en"" xmlns:stream=""http://etherx.jabber.org/streams""> <message xmlns=""jabber:client""> <body>foo</body> </message> </stream:stream>"; var stream = XmppSerializer.Deserialize <Stream>("stream:stream", xml); Assert.IsNotNull(stream); Assert.AreEqual("en", stream.Lang); Assert.AreEqual("1.0", stream.Version); Assert.AreEqual("*****@*****.**", stream.From); Assert.AreEqual("im.example.com", stream.To); Assert.IsNotNull(stream.Items); Assert.AreEqual(1, stream.Items.Count); Assert.IsTrue(stream.Items[0] is Message); var message = stream.Items[0] as Message; Assert.IsTrue(message.Body != null); Assert.AreEqual("foo", message.Body.Value); }
private async void OnMessageReceivedAsync(StreamElement xmlMessage) { Debug.WriteLine($"SERVER <- {xmlMessage}"); if (xmlMessage.OpensXmppStream) { // Stream opened } else if (xmlMessage.ClosesXmppStream) { // Stream closed } else { var message = XmppSerializer.Deserialize(xmlMessage.Name, xmlMessage.ToString()); if (message is InfoQuery || message is Message || message is Presence) { await this.OnStanzaAsync(message).ConfigureAwait(false); } else { await this.OnStreamFragmentAsync(message).ConfigureAwait(false); } } }
public void DeserializeWithBindFeature() { var xml = @"<stream:features xmlns:stream=""http://etherx.jabber.org/streams""> <bind xmlns=""urn:ietf:params:xml:ns:xmpp-bind""/> </stream:features>"; var features = XmppSerializer.Deserialize <StreamFeatures>("stream:features", xml); Assert.IsNotNull(features); Assert.IsNotNull(features.Bind); }
public void DeserializeWithStartTlsFeature() { var xml = @"<stream:features> <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'> <required/> </starttls> </stream:features>"; var features = XmppSerializer.Deserialize <StreamFeatures>("stream:features", xml); Assert.IsNotNull(features); Assert.IsNotNull(features.StartTls); Assert.IsNotNull(features.StartTls.Required); }
public void DeserializeRosterRequest() { var xml = @"<iq from='[email protected]/balcony' id='bv1bs71f' type='get' xmlns=""jabber:client""> <query xmlns='jabber:iq:roster'/> </iq>"; var infoQuery = XmppSerializer.Deserialize <InfoQuery>("iq", xml); Assert.IsNotNull(infoQuery); Assert.AreEqual("[email protected]/balcony", infoQuery.From); Assert.AreEqual(InfoQueryType.Get, infoQuery.Type); Assert.AreNotEqual(null, infoQuery.Roster); }
public void DeserializeWithCompressFeature() { var xml = @"<stream:features> <compression xmlns='http://jabber.org/features/compress'> <method>zlib</method> <method>lzw</method> </compression> </stream:features>"; var features = XmppSerializer.Deserialize <StreamFeatures>("stream:features", xml); Assert.IsNotNull(features); Assert.IsNotNull(features.Compression); Assert.AreEqual(2, features.Compression.Methods.Count); Assert.AreEqual("zlib", features.Compression.Methods[0]); Assert.AreEqual("lzw", features.Compression.Methods[1]); }