/// <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, XMPPProtocol.Protocol.client.IQ iq) { if (iq == null) { return; } string id = iq.Id; if (id == null) { return; } TrackerData td; lock (m_grabbing) { td = (TrackerData)m_grabbing[id]; if (td == null) { return; } m_grabbing.Remove(id); } td.cb(this, iq, td.data); }
/// <summary> /// Sends an Iq synchronous and return the response or null on timeout /// </summary> /// <param name="iq">The IQ to send</param> /// <param name="timeout"></param> /// <returns>The response IQ or null on timeout</returns> public IQ SendIq(XMPPProtocol.Protocol.client.IQ iq, int timeout) { synchronousResponse = null; AutoResetEvent are = new AutoResetEvent(false); SendIq(iq, new IqCB(SynchronousIqResult), are); if (!are.WaitOne(timeout, true)) { // Timed out lock (m_grabbing) { if (m_grabbing.ContainsKey(iq.Id)) { m_grabbing.Remove(iq.Id); } } return(null); } return(synchronousResponse); }
/// <summary> /// Sends an Iq synchronous and return the response or null on timeout /// </summary> /// <param name="iq">The IQ to send</param> /// <param name="timeout"></param> /// <returns>The response IQ or null on timeout</returns> public IQ SendIq(XMPPProtocol.Protocol.client.IQ iq, int timeout) { synchronousResponse = null; AutoResetEvent are = new AutoResetEvent(false); SendIq(iq, new IqCB(SynchronousIqResult), are); if (!are.WaitOne(timeout, true)) { // Timed out lock (m_grabbing) { if (m_grabbing.ContainsKey(iq.Id)) m_grabbing.Remove(iq.Id); } return null; } return synchronousResponse; }
/// <summary> /// Send an IQ Request and store the object with callback in the Hashtable /// </summary> /// <param name="iq">The iq to send</param> /// <param name="cb">the callback function which gets raised for the response</param> /// <param name="cbArg">additional object for arguments</param> public void SendIq(IQ iq, IqCB cb, object cbArg) { // check if the callback is null, in case of wrong usage of this class if (cb != null) { TrackerData td = new TrackerData(); td.cb = cb; td.data = cbArg; m_grabbing[iq.Id] = td; } m_connection.Send(iq); }
/// <summary> /// Send an IQ Request and store the object with callback in the Hashtable /// </summary> /// <param name="iq">The iq to send</param> /// <param name="cb">the callback function which gets raised for the response</param> public void SendIq(IQ iq, IqCB cb) { SendIq(iq, cb, null); }
private void SessionResult(object sender, IQ iq, object data) { if (iq.Type == IqType.result) { m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.SessionStarted); m_XmppClient.RaiseOnLogin(); } else if (iq.Type == IqType.error) { } }
private void BindResult(object sender, IQ iq, object data) { // 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, new IqCB(SessionResult), null); } else if (iq.Type == IqType.error) { // TODO, handle bind errors } }
private void OnRosterIQ(IQ iq) { // if type == result then it must be the "FullRoster" we requested // in this case we raise OnRosterStart and OnRosterEnd // // if type == set its a new added r updated rosteritem. Here we dont raise // OnRosterStart and OnRosterEnd if (iq.Type == IqType.result && OnRosterStart != null) OnRosterStart(this); Roster r = iq.Query as Roster; if (r != null) { foreach (RosterItem i in r.GetRoster()) { if (OnRosterItem != null) OnRosterItem(this, i); } } if (iq.Type == IqType.result && OnRosterEnd != null) OnRosterEnd(this); if (m_AutoPresence && iq.Type == IqType.result) SendMyPresence(); }
private void OnRegisterResult(object sender, IQ iq, object data) { /* Example 6. Host Informs Entity of Failed Registration (Username Conflict) <iq type='error' id='reg2'> <query xmlns='jabber:iq:register'> <username>bill</username> <password>m1cro$oft</password> <email>[email protected]</email> </query> <error code='409' type='cancel'> <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> </error> </iq> Example 7. Host Informs Entity of Failed Registration (Some Required Information Not Provided) <iq type='error' id='reg2'> <query xmlns='jabber:iq:register'> <username>bill</username> <password>Calliope</password> </query> <error code='406' type='modify'> <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> </error> </iq> */ if (iq.Type == IqType.result) { DoChangeXmppConnectionState(XmppConnectionState.Registered); if (OnRegistered != null) OnRegistered(this); if (this.StreamVersion != null && this.StreamVersion.StartsWith("1.")) { // init sasl login InitSaslHandler(); m_SaslHandler.OnStreamElement(this, data as Node); } else { // old jabber style login RequestLoginInfo(); } } else if (iq.Type == IqType.error) { if (OnRegisterError != null) OnRegisterError(this, iq); } }
private void OnGetAuthInfo(object sender, IQ iq, object data) { // We get smth like this and should add password (digest) and ressource // Recv:<iq type="result" id="MX_7"><query xmlns="jabber:iq:auth"><username>gnauck</username><password/><digest/><resource/></query></iq> // Send:<iq type='set' id='mx_login'> // <query xmlns='jabber:iq:auth'><username>gnauck</username><digest>27c05d464e3f908db3b2ca1729674bfddb28daf2</digest><resource>Office</resource></query> // </iq> // Recv:<iq id="mx_login" type="result"/> iq.GenerateId(); iq.SwitchDirection(); iq.Type = IqType.set; Auth auth = (Auth) iq.Query; auth.Resource = this.m_Resource; auth.SetAuth(this.m_Username, this.m_Password, this.StreamId); IqGrabber.SendIq(iq, new IqCB(OnAuthenticate), null); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="iq"></param> /// <param name="data">contains the new password</param> private void OnChangePasswordResult(object sender, IQ iq, object data) { if (iq.Type == IqType.result) { if(OnPasswordChanged!=null) OnPasswordChanged(this); // Set the new password in the Password property on sucess m_Password = (string) data; } else if (iq.Type == IqType.error) { /* The server or service SHOULD NOT return the original XML sent in IQ error stanzas related to password changes. Example 12. Host Informs Client of Failed Password Change (Bad Request) <iq type='error' from='somehost' to='user@host/resource' id='change1'> <error code='400' type='modify'> <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> </error> </iq> Example 13. Host Informs Client of Failed Password Change (Not Authorized) <iq type='error' from='somehost' to='user@host/resource' id='change1'> <error code='401' type='cancel'> <not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> </error> </iq> Example 14. Server Informs Client of Failed Password Change (Not Allowed) <iq type='error' from='somehost' to='user@host/resource' id='change1'> <error code='405' type='cancel'> <not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> </error> </iq> */ if(OnRegisterError!=null) OnRegisterError(this, iq); } }
private void OnAuthenticate(object sender, IQ iq, object data) { if (iq.Type == IqType.result) { m_Authenticated = true; RaiseOnLogin(); } else if(iq.Type == IqType.error) { /* * <iq xmlns="jabber:client" id="XMPPProtocol_2" type="error"> * <query xmlns="jabber:iq:auth"> * <username>test</username> * <digest sid="842070264">dc7e472abb95b65c2b75129ade607170be478b16</digest> * <resource>MiniClient</resource> * </query> * <error code="401">Unauthorized</error> * </iq> * */ if (OnAuthError!=null) OnAuthError(this, iq); } }
private void OnAgents(object sender, IQ iq, object data) { if (OnAgentStart != null) OnAgentStart(this); Agents agents = iq.Query as Agents; if (agents != null) { foreach (Agent a in agents.GetAgents()) { if (OnAgentItem != null) OnAgentItem(this, a); } } if (OnAgentEnd != null) OnAgentEnd(this); }
private void ProcessDiscoInfo(IQ iq) { IQ diiq = new IQ(); diiq.To = iq.From; diiq.Id = iq.Id; diiq.Type = IqType.result; diiq.Query = xmppConnection.DiscoInfo; xmppConnection.Send(diiq); }
private void OnIq(object sender, IQ iq) { // DiscoInfo if (m_AutoAnswerDiscoInfoRequests && iq.Query is DiscoInfo && iq.Type == IqType.get) ProcessDiscoInfo(iq); }
/// <summary> /// Sends an Iq synchronous and return the response or null on timeout. /// Timeout time used is <see cref="SynchronousTimeout"/> /// </summary> /// <param name="iq">The IQ to send</param> /// <returns>The response IQ or null on timeout</returns> public IQ SendIq(IQ iq) { return SendIq(iq, m_SynchronousTimeout); }
/// <summary> /// Callback for synchronous iq grabbing /// </summary> /// <param name="sender"></param> /// <param name="iq"></param> /// <param name="data"></param> private void SynchronousIqResult(object sender, IQ iq, object data) { synchronousResponse = iq; AutoResetEvent are = data as AutoResetEvent; are.Set(); }
private void OnRegistrationFieldsResult(object sender, IQ iq, object data) { if (iq.Type != IqType.error) { if (iq.Query != null && iq.Query.GetType() == typeof(Register)) { RegisterEventArgs args = new RegisterEventArgs(iq.Query as Register); if (OnRegisterInformation != null) OnRegisterInformation(this, args); DoChangeXmppConnectionState(XmppConnectionState.Registering); IQ regIq = new IQ(IqType.set); regIq.GenerateId(); regIq.To = new Jid(base.Server); //RegisterIq regIq = new RegisterIq(IqType.set, new Jid(base.Server)); if (args.Auto) { Register reg = new Register(this.m_Username, this.m_Password); regIq.Query = reg; } else { regIq.Query = args.Register; } IqGrabber.SendIq(regIq, new IqCB(OnRegisterResult), data); } } else { if (OnRegisterError != null) OnRegisterError(this, iq); } }