public void SerializeWithMessage()
        {
            var exp = @"<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 msg = new Message {
                Id = null, Body = new MessageBody {
                    Value = "foo"
                }
            };
            var stream = new Stream
            {
                From      = "*****@*****.**"
                , To      = "im.example.com"
                , Version = "1.0"
                , Lang    = "en"
            };

            stream.Items.Add(msg);

            var buffer = XmppSerializer.Serialize(stream);
            var xml    = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

            Assert.IsTrue(exp.CultureAwareCompare(xml));
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Sends a new message.
        /// </summary>
        /// <param name = "message">The message to be sent</param>
        public override void Send(object message)
        {
            var body = new HttpBindBody
            {
                Rid = (rid++).ToString(),
                Sid = streamResponse.Sid
            };

            body.Items.Add(message);

            Send(XmppSerializer.Serialize(body));
        }
Exemplo n.º 3
0
        public void SerializeWithBindFeature()
        {
            var exp = @"<stream:features xmlns:stream=""http://etherx.jabber.org/streams"">
                          <bind xmlns=""urn:ietf:params:xml:ns:xmpp-bind""/>
                        </stream:features>";

            var features = new StreamFeatures
            {
                Bind = new Bind()
            };

            var buffer = XmppSerializer.Serialize(features);
            var xml    = XmppEncoding.Utf8.GetString(buffer, 0, buffer.Length);

            Assert.IsTrue(exp.CultureAwareCompare(xml));
        }
Exemplo n.º 4
0
        public override void InitializeXmppStream()
        {
            var message = new HttpBindBody();

            message.Rid  = (rid++).ToString();
            message.To   = ConnectionString.HostName;
            message.Lang = DefaultLanguage;

            if (streamResponse == null)
            {
                message.Content       = ContentType;
                message.From          = UserId.BareIdentifier;
                message.Hold          = 1;
                message.HoldSpecified = true;
                message.Route         = String.Format(RouteFormat, ConnectionString.HostName);
                message.Ver           = BoshVersion;
                message.Wait          = 60;
                message.WaitSpecified = true;
                message.Ack           = "1";
            }
            else
            {
                message.Sid     = streamResponse.Sid;
                message.Restart = true;
            }

            var response = SendSync(XmppSerializer.Serialize(message));

#warning TODO: If no <stream:features/> element is included in the connection manager's session creation response, then the client SHOULD send empty request elements until it receives a response containing a <stream:features/> element.

            if (response != null)
            {
                streamResponse = response;

                ProcessResponse(response);

#warning TODO: Check if the response has an stream-features element
                OnXmppStreamInitializedSubject.OnNext(String.Empty);
            }
            else
            {
#warning TODO: Review how to handle this case
                throw new Exception("");
            }
        }
Exemplo n.º 5
0
        public void SerializeWithStartTlsFeature()
        {
            var exp = @"<stream:features xmlns:stream=""http://etherx.jabber.org/streams"">
                          <starttls xmlns=""urn:ietf:params:xml:ns:xmpp-tls"">
                             <required />
                          </starttls>
                        </stream:features>";

            var features = new StreamFeatures
            {
                StartTls = new StartTls
                {
                    Required            = new Empty()
                    , RequiredSpecified = true
                }
            };

            var buffer = XmppSerializer.Serialize(features);
            var xml    = XmppEncoding.Utf8.GetString(buffer, 0, buffer.Length);

            Assert.IsTrue(exp.CultureAwareCompare(xml));
        }
        public void SerializeRosterRequest()
        {
            var exp = @"<iq from=""[email protected]/balcony""
                            id=""bv1bs71f""
                            type=""get""
                            xmlns=""jabber:client"">
                          <query xmlns=""jabber:iq:roster""/>
                        </iq>";

            var query = new InfoQuery
            {
                From   = "[email protected]/balcony"
                , Id   = "bv1bs71f"
                , Type = InfoQueryType.Get
            };

            query.Roster = new Roster();

            var buffer = XmppSerializer.Serialize(query);
            var xml    = XmppEncoding.Utf8.GetString(buffer, 0, buffer.Length);

            Assert.IsTrue(exp.CultureAwareCompare(xml));
        }
Exemplo n.º 7
0
        public void SerializeWithCompressFeature()
        {
            var exp = @"<stream:features xmlns:stream=""http://etherx.jabber.org/streams"">
                          <compression xmlns=""http://jabber.org/features/compress"">
                            <method>zlib</method>
                            <method>lzw</method>
                          </compression>
                        </stream:features>";

            var features = new StreamFeatures
            {
                Compression = new StreamCompressionFeature
                {
                    Methods = new List <string> {
                        "zlib", "lzw"
                    }
                }
            };

            var buffer = XmppSerializer.Serialize(features);
            var xml    = XmppEncoding.Utf8.GetString(buffer, 0, buffer.Length);

            Assert.IsTrue(exp.CultureAwareCompare(xml));
        }
Exemplo n.º 8
0
 /// <summary>
 ///   Sends a new message.
 /// </summary>
 /// <param name = "message">The message to be sent</param>
 public override void Send(object message)
 {
     Send(XmppSerializer.Serialize(message));
 }
Exemplo n.º 9
0
 private void Send(HttpBindBody message)
 {
     Send(XmppSerializer.Serialize(message));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Sends a new message.
 /// </summary>
 /// <param name="message">The message to be sent</param>
 public async Task SendAsync <T>(T message)
     where T : class
 {
     await this.transport.SendAsync(XmppSerializer.Serialize(message)).ConfigureAwait(false);
 }