private void ProcessBind(Iq iq) { var bind = iq.Query as Bind; string res = bind.Resource; if (!String.IsNullOrEmpty(res)) { var jid = new Jid(User, XmppDomain, res); Jid = jid; var resIq = new BindIq { Id = iq.Id, Type = IqType.Result, Bind = { Jid = jid } }; Send(resIq); Resource = res; IsBinded = true; // connection is bindet now. Add it to our global list of connection. Global.ServerConnections.Add(this); } else { // return error } }
private void ProcessIq(Iq iq) { if (iq.Query is Roster) { ProcessRosterIq(iq); } else if (iq.Query is Bind) { ProcessBind(iq); } //else if (iq.Query is Session) // ProcessSession(iq); else if (iq.To != null && !iq.To.Equals(XmppDomain, new FullJidComparer())) { RouteIq(iq); } //if (iq.Query is Bind) // ProcessBind(iq); //else if (iq.To != null && !iq.To.Equals(XmppDomain, new FullJidComparer())) // RouteIq(iq); else { // something we don't understand or do not support, reply with error Send( new Matrix.Xmpp.Client.Iq() { Type = IqType.Error, Id = iq.Id, Error = new Matrix.Xmpp.Client.Error(Matrix.Xmpp.Base.ErrorCondition.FeatureNotImplemented) }); } }
private void ProcessRosterIq(Iq iq) { if (iq.Type == IqType.Get) { // Send the roster // we send a dummy roster here, you should retrieve it from a // database or some kind of directory (LDAP, AD etc...) iq.SwitchDirection(); iq.Type = IqType.Result; for (int i = 1; i < 11; i++) { // don't add yourself to the contact list (aka roster) if (Jid.User.EndsWith(i.ToString())) { continue; } var ri = new RosterItem { Jid = new Jid("user" + i + "@" + XmppDomain), Name = "User " + i, Subscription = Subscription.Both }; ri.AddGroup("Group 1"); iq.Query.Add(ri); } Send(iq); } else if (iq.Type == IqType.Set) { // TODO, handle roster add, remove and update here. } }
private void ProcessSession(Iq iq) { /* * <iq type="set" id="aabca" > * <session xmlns="urn:ietf:params:xml:ns:xmpp-session"/> * </iq> */ if (iq.Type == IqType.Set) { Send(new SessionIq { Id = iq.Id, Type = IqType.Result }); } }
private void ProcessBind(Iq iq) { var bind = iq.Query as Bind; string res = bind.Resource; if (!String.IsNullOrEmpty(res)) { var jid = new Jid(User, XmppDomain, res); _Jid = jid; var resIq = new BindIq { Id = iq.Id, Type = IqType.Result, Bind = { Jid = jid } }; Send(resIq); Resource = res; IsBinded = true; // connection is bindet now. Add it to our global list of connection. if (!Global.ServerConnections.ContainsKey(this._Jid)) { Global.ServerConnections[this._Jid] = this; m_server.OnConnect(this._Jid); } //else // Global.ServerConnections.Add(this._Jid, this); // Wait until we receive the HANDSHAKE message //if (m_server != null) //{ // m_server.OnConnect(m_clientJid); //} } else { // return error } }
private void ProcessRosterIq(Iq iq) { if (iq.Type == IqType.Get) { // Send the roster // All logged in items for EMRALD are in a roster given for all clients - this may change later iq.SwitchDirection(); iq.Type = IqType.Result; //The roster will always include all the connections this may change in the future foreach (var con in Global.ServerConnections) { var ri = new Matrix.Xmpp.Roster.RosterItem { Jid = con.Key, Name = con.Value.User, Subscription = Matrix.Xmpp.Roster.Subscription.Both }; ri.AddGroup("EMRALD"); ri.AddGroup(con.Value.Resource); iq.Query.Add(ri); } Send(iq); } else //if (iq.Type == IqType.Set) { //For EMRALD items are added to a master roster for everyone to access so no need to set roster items - this may change later // TODO, send an error here for //if(iq.Query.FirstElement is RosterItem) //{ // var item = iq.Query.FirstElement as RosterItem; // _roster.Add(item); //} } }
private void ProcessIq(Iq iq) { if (iq.Query is Roster) { ProcessRosterIq(iq); } else if (iq.Query is Bind) { ProcessBind(iq); } else if (iq.Query is Session) { ProcessSession(iq); } else if (iq.To != null && !iq.To.Equals(XmppDomain, new FullJidComparer())) { RouteIq(iq); } else { // TODO } }
private void ProcessRosterIq(Iq iq) { if (iq.Type == IqType.Get) { // Send the roster // we send a dummy roster here, you should retrieve it from a // database or some kind of directory (LDAP, AD etc...) iq.SwitchDirection(); iq.Type = IqType.Result; String[] contact = new string[3]; contact[0] = "krishna"; contact[1] = "madu"; contact[2] = "madu2"; for (int i = 0; i < contact.Length; i++) { // don't add yourself to the contact list (aka roster) if (contact[i].Equals(Jid.User)) { continue; } var ri = new RosterItem { Jid = new Jid(contact[i] + "@" + XmppDomain), Name = contact[i], Subscription = Subscription.Both }; ri.AddGroup("Group 1"); iq.Query.Add(ri); } Send(iq); } else if (iq.Type == IqType.Set) { // TODO, handle roster add, remove and update here. } }
private void RouteIq(Iq iq) { // route the iq here var to = iq.To; // check if the destination of this message is available XmppServerConnection con; if (Global.ServerConnections.TryGetValue(to, out con)) { // found connection, stamp packet with from and route it. iq.From = _Jid; con.Send(iq); } else { // connection not found. Return the message to the sender and stamp it with error iq.Type = IqType.Error; iq.To = _Jid; iq.From = to; iq.Add(new Matrix.Xmpp.Client.Error(Matrix.Xmpp.Base.ErrorCondition.ServiceUnavailable)); Send(iq); } }
private void RouteIq(Iq iq) { // route the iq here var to = iq.To; // check if the destination of this message is available var con = Global.ServerConnections.FirstOrDefault(c => c.Jid.Equals(to, new BareJidComparer())); if (con != null) { // found connection, stamp packet with from and route it. iq.From = Jid; con.Send(iq); } else { // connection not found. Return the message to the sender and stamp it with error iq.Type = IqType.Error; iq.To = Jid; iq.From = to; iq.Add(new Matrix.Xmpp.Client.Error(Matrix.Xmpp.Base.ErrorCondition.ServiceUnavailable)); Send(iq); } }