Пример #1
0
        public void Start(XmppConnection connection)
        {
            var auth = new SASLAuth();

            auth.SetAttributeValue("mechanism", SASLMethod);
            auth.SetValue(Initiate());
            connection.Send(auth);
            var authResponse = connection.NextElement();
            var nextResponse = string.Empty;

            Task.Run(() =>
            {
                while ((nextResponse = NextChallenge(authResponse.Value)) != "")
                {
                    if (nextResponse == "error")
                    {
                        OnAuthenticationFailed(connection);
                        return;
                    }
                    var response = new SASLResponse();
                    response.SetValue(nextResponse);
                    connection.Send(response);
                    authResponse = connection.NextElement();
                }
                OnAuthenticated(connection);
            });
        }
Пример #2
0
 public void Start(XmppConnection connection)
 {
     connection.Features = Stanza.Parse <Features>(connection.NextElement());
     if (connection.Features.Bind)
     {
         var bind = new Elements.Bind(connection.Jid.Resource);
         var iq   = new XMPPIq(XMPPIq.IqTypes.set);
         iq.Add(bind);
         connection.Query(iq, (bindResult) =>
         {
             var jid = bindResult.Element(XNamespace.Get(Namespaces.XmppBind) + "bind");
             if (jid == null)
             {
                 return;
             }
             connection.Jid = new JID(jid.Element(XNamespace.Get(Namespaces.XmppBind) + "jid").Value);
             if (connection.Features.Session)
             {
                 var sess   = new XElement(XNamespace.Get(Namespaces.XmppSession) + "session");
                 var sessIq = new XMPPIq(XMPPIq.IqTypes.set);
                 sessIq.Add(sess);
                 connection.Query(sessIq, (sessionResponse) => OnSessionStarted(connection));
             }
             else
             {
                 OnSessionStarted(connection);
             }
         });
         connection.SessionLoop();
     }
 }