/// <summary> /// Adds the given contact to the roster /// </summary> /// <param name = "jid">Contact JID</param> /// <param name = "name">Contact name</param> public XmppRoster AddContact(string jid, string name) { var query = new RosterQuery(); var iq = new IQ(); iq.ID = XmppIdentifierGenerator.Generate(); iq.Type = IQType.Set; iq.From = connection.UserId; var item = new RosterItem(); item.Subscription = RosterSubscriptionType.None; item.Jid = jid; item.Name = name; query.Items.Add(item); iq.Items.Add(query); pendingMessages.Add(iq.ID); connection.Send(iq); return(this); }
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); }); }
public void HandleError(XMPPIq element) { if (element.IqType == XMPPIq.IqTypes.get || element.IqType == XMPPIq.IqTypes.set) { Connection.Send(element.Error()); } }
public override bool Handle(XmppConnection sender, XMPPIq element) { if (Stanza.Parse <DiscoItems>(element.Elements().FirstOrDefault()) != null) { sender.Send(element.Reply()); return(true); } return(false); }
public void Join(BookmarkedConference room) { var mucPresence = new XMPPPresence(connection.Capabilities) { To = new JID(string.Format("{0}/{1}", room.JID.BareJid, room.Nick)) }; mucPresence.Add(new XElement(XNamespace.Get(Namespaces.MUC) + "x")); connection.Send(mucPresence); }
public override bool Handle(XmppConnection connection, XMPPIq element) { var info = Stanza.Parse <DiscoInfo>(element.Elements().FirstOrDefault()); if (info != null) { if (info.Node == string.Empty || info.Node == string.Format("{0}#{1}", _capabilities.Node, _capabilities.OurHash)) { info.Identity = _capabilities.Identity; info.Features = _capabilities.Features; info.Node = _capabilities.Node; var reply = element.Reply(); reply.RemoveNodes(); reply.Add(info); connection.Send(reply); return(true); } } return(false); }
public override bool Handle(XmppConnection sender, XMPPIq element) { var type = element.Attribute("type"); if (type == null) { return(false); } if (type.Equals("get")) { var query = element.Element("query"); if (query != null) { var ns = query.Attribute("xmlns"); var num = Array.IndexOf(Features, ns); switch (num) { case 0: var from = new JID(element.Attribute("from").Value); _fields = _regHandler.GetCredentials(from); var reply = element.Reply(); var instr = new Stanza("instructions") { Value = _regHandler.GetInstructions() }; query.Add(instr); foreach (string field in _fields.Keys) { var f = new Stanza(field) { Value = _fields[field] }; query.Add(f); } sender.Send(reply); return(true); } } } if (type.Equals("set")) { var query = element.Element("query"); if (query != null) { var ns = query.Attribute("xmlns"); var num = Array.IndexOf(Features, ns); switch (num) { case 0: var queryFields = FilterFields((Stanza)query, _fields); var from = new JID(element.Attribute("from").Value); var requestResult = queryFields.ContainsKey("remove") ? _regHandler.OnRegistrationRemove(from) : _regHandler.OnRegistrationRequest(from, queryFields); if (requestResult) { var reply = element.Reply(); sender.Send(reply); var subscribe = new XMPPPresence(); subscribe.SetAttributeValue("to", from.BareJid); subscribe.SetAttributeValue("from", sender.Jid.BareJid); if (queryFields.ContainsKey("remove")) { subscribe.SetAttributeValue("type", "unsubscribed"); sender.Send(subscribe); subscribe.SetAttributeValue("type", "unsubscribe"); sender.Send(subscribe); } else { subscribe.SetAttributeValue("type", "subscribe"); sender.Send(subscribe); } } else { sender.Send(element.Error()); } return(true); } } } return(false); }
/// <summary> /// Sends a XMPP message to the server /// </summary> /// <param name = "message">The message to be sent</param> internal void Send(object message) { connection.Send(message); }