Example #1
0
        /// <summary>
        /// An IQ Element is received. Now check if its one we are looking for and
        /// raise the event in this case.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnIq(object sender, IQEventArgs e)
        {
            // the tracker handles on iq responses, which are either result or error
            if (e.IQ.Type != IqType.error && e.IQ.Type != IqType.result)
            {
                return;
            }

            string id = e.IQ.Id;

            if (id == null)
            {
                return;
            }

            IqHandler td;

            lock (m_grabbing)
            {
                td = (IqHandler)m_grabbing[id];

                if (td == null)
                {
                    return;
                }
                m_grabbing.Remove(id);
            }

            td(this, e);
        }
Example #2
0
 private void OnIq(object sender, IQEventArgs e)
 {
     // DiscoInfo
     if (m_AutoAnswerDiscoInfoRequests && e.IQ.Query is DiscoInfo && e.IQ.Type == IqType.get)
     {
         e.Handled = true;
         ProcessDiscoInfo(e.IQ);
     }
 }
Example #3
0
 private void SessionResult(object sender, IQEventArgs e)
 {
     if (e.IQ.Type == IqType.result)
     {
         m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.SessionStarted);
         m_XmppClient.RaiseOnLogin();
         e.Handled = true;
     }
     else if (e.IQ.Type == IqType.error)
     {
     }
 }
Example #4
0
        private void BindResult(object sender, IQEventArgs e)
        {
            var iq = e.IQ;

            // Once the server has generated a resource identifier for the client or accepted the resource
            // identifier provided by the client, it MUST return an IQ stanza of type "result"
            // to the client, which MUST include a <jid/> child element that specifies the full JID for
            // the connected resource as determined by the server:

            // Server informs client of successful resource binding:
            // <iq type='result' id='bind_2'>
            //  <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
            //    <jid>[email protected]/someresource</jid>
            //  </bind>
            // </iq>
            if (iq.Type == IqType.result)
            {
                // i assume the server could assign another resource here to the client
                // so grep the resource assigned by the server now
                Element bind = iq.SelectSingleElement(typeof(Bind));
                if (bind != null)
                {
                    Jid jid = ((Bind)bind).Jid;
                    m_XmppClient.Resource = jid.Resource;
                    m_XmppClient.Username = jid.User;
                }

                m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binded);
                m_XmppClient.m_Binded = true;

                m_XmppClient.DoRaiseEventBinded();

                // success, so start the session now
                m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.StartSession);
                SessionIq sIq = new SessionIq(IqType.set, new Jid(m_XmppClient.Server));
                m_XmppClient.IqGrabber.SendIq(sIq, SessionResult);
                e.Handled = true;
            }
            else if (iq.Type == IqType.error)
            {
                // TODO, handle bind errors
                m_XmppClient.DoRaiseEventBindError(iq);
            }
        }