Exemplo n.º 1
0
        private void JabberClient_OnSASLEnd(Object sender, jabber.protocol.stream.Features feat)
        {
            lock (StateLock)
            {
                State = BindState.Instance;
            }
            if (feat["bind", URI.BIND] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;

                jabber.protocol.stream.Bind bind = new jabber.protocol.stream.Bind(this.Document);
                if ((Resource != null) && (Resource != ""))
                {
                    bind.Resource = Resource;
                }

                iq.AddChild(bind);
                this.Tracker.BeginIQ(iq, new IqCB(GotResource), feat);
            }
            else if (feat["session", URI.SESSION] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;
                iq.AddChild(new jabber.protocol.stream.Session(this.Document));
                this.Tracker.BeginIQ(iq, new IqCB(GotSession), feat);
            }
            else
            {
                IsAuthenticated = true;
            }
        }
Exemplo n.º 2
0
        private void GotResource(object sender, IQ iq, object state)
        {
            jabber.protocol.stream.Features feat =
                state as jabber.protocol.stream.Features;

            if (iq == null)
            {
                FireOnError(new AuthenticationFailedException("Timeout authenticating"));
                return;
            }
            if (iq.Type != IQType.result)
            {
                Error err = iq.Error;
                if (err == null)
                {
                    FireOnError(new AuthenticationFailedException("Unknown error binding resource"));
                }
                else
                {
                    FireOnError(new AuthenticationFailedException("Error binding resource: " + err.OuterXml));
                }
                return;
            }

            XmlElement bind = iq["bind", URI.BIND];

            if (bind == null)
            {
                FireOnError(new AuthenticationFailedException("No binding returned.  Server implementation error."));
                return;
            }
            XmlElement jid = bind["jid"];

            if (jid == null)
            {
                FireOnError(new AuthenticationFailedException("No jid returned from binding.  Server implementation error."));
                return;
            }
            this[Options.JID] = new JID(jid.InnerText);

            if (feat["session", URI.SESSION] != null)
            {
                IQ iqs = new IQ(this.Document);
                iqs.To   = this.Server;
                iqs.Type = IQType.set;
                iqs.AddChild(new jabber.protocol.stream.Session(this.Document));
                this.Tracker.BeginIQ(iqs, new IqCB(GotSession), feat);
            }
            else
            {
                IsAuthenticated = true;
            }
        }