public void ComplexGenerationExample() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book xml:lang='en'/>"); XmlElement book = doc.DocumentElement; foreach (XmlAttribute attr in book.Attributes) { System.Console.WriteLine(attr.Name); } XmlElement root = doc.DocumentElement; DiscoInfo info = new DiscoInfo(doc); info.AddFeature("http://jabber.org/protocol/muc"); info.AddFeature("http://jabber.org/protocol/disco#info"); info.AddFeature("http://jabber.org/protocol/disco#items"); info.AddIdentity("client", "pc", "Psi 0.9.1", "en"); info.AddIdentity("client", "pc", "\u03a8 0.9.1", "el"); Data x = info.CreateExtension(); x.FormType = "urn:xmpp:dataforms:softwareinfo"; x.AddField("ip_version").Vals = new string[] { "ipv4", "ipv6" }; x.AddField("os").Val = "Mac"; x.AddField("os_version").Val = "10.5.1"; x.AddField("software").Val = "Psi"; x.AddField("software_version").Val = "0.11"; DiscoNode dn = new DiscoNode(new JID(null, "placeholder", null), null); dn.AddInfo(info); CapsManager cm = new CapsManager(dn); Assert.AreEqual("8lu+88MRxmKM7yO3MEzY7YmTsWs=", cm.Ver); }
internal Disco() { disco_info = new DiscoInfo (XmppGlobal.InternalClient.Document); AddIdentity ("client", "pc", "XmppApplication"); AddFeature ("http://jabber.org/protocol/disco#info"); XmppGlobal.InternalClient.OnIQ += new jabber.client.IQHandler (GotIQ); }
private string BuildCapsVersion(DiscoInfo di) { /* * 1. Initialize an empty string S. * 2. Sort the service discovery identities by category and then by type (if it exists), formatted as 'category' '/' 'type'. * 3. For each identity, append the 'category/type' to S, followed by the '<' character. * 4. Sort the supported features. * 5. For each feature, append the feature to S, followed by the '<' character. * 6. Compute ver by hashing S using the SHA-1 algorithm as specified in RFC 3174 [17] (with binary output) and * encoding the hash using Base64 as specified in Section 4 of RFC 4648 [18] * (note: the Base64 output MUST NOT include whitespace and MUST set padding bits to zero). [19] */ var features = new ArrayList(); var identities = new ArrayList(); foreach (DiscoIdentity did in di.GetIdentities()) { identities.Add(did.Type == null ? did.Category : did.Category + "/" + did.Type); } foreach (DiscoFeature df in di.GetFeatures()) { features.Add(df.Var); } identities.Sort(); features.Sort(); var S = new StringBuilder(); foreach (string s in identities) { S.Append(s + "<"); } foreach (string s in features) { S.Append(s + "<"); } byte[] sha1 = Hash.Sha1HashBytes(S.ToString()); #if CF return(Convert.ToBase64String(sha1, 0, sha1.Length)); #else return(Convert.ToBase64String(sha1)); #endif }
private IQ CreateIqRequest() { IQ iq = new IQ(doc); iq.To = TO_JID; iq.From = FROM_JID; iq.Type = IQType.get; iq.ID = TEST_ID; DiscoInfo info = new DiscoInfo(doc); info.SetAttribute("xmlns", URI.DISCO_INFO); iq.Query = info; return(iq); }
private IQ CreateDiscoInfoResponse(string id) { IQ returnIq = new IQ(doc); returnIq.SetAttribute("id", id); returnIq.SetAttribute("from", jid); returnIq.SetAttribute("type", "result"); DiscoInfo info = new DiscoInfo(doc); info.AddIdentity("server", "im", "jabber2 4.2.16.6", null); info.AddFeature(URI.DISCO_ITEMS); info.AddFeature(URI.DISCO_INFO); returnIq.Query = info; return(returnIq); }
/// <summary> /// Determines whether or not this is a capabilities request. /// Answers true for a bare no-node disco request, as well as /// for requests to the correct hash. /// </summary> /// <param name="iq">XML to look through for capabilities.</param> /// <returns>True if this is a capabilities request.</returns> public bool IsCaps(IQ iq) { if (iq.Type != IQType.get) return false; DiscoInfo info = iq.Query as DiscoInfo; if (info == null) return false; string node = info.Node; if (node == null) return true; if (node == NodeVer) return true; return false; }
public MucRoomMember(MucRoom room, Jid memberJid, Jid realJid, XmppStream stream, XmppHandlerContext context) { if (room == null) { throw new ArgumentNullException("room"); } if (memberJid == null) { throw new ArgumentNullException("memberJid"); } if (realJid == null) { throw new ArgumentNullException("realJid"); } if (context == null) { throw new ArgumentNullException("sender"); } this.room = room; this.stream = stream; this.context = context; this.sender = context.Sender; //Register disconect context.SessionManager.SessionUnavailable += SessionManager_SessionUnavailable; ParentService = room; RealJid = realJid; Jid = memberJid; Name = memberJid.Resource; presenceType = PresenceType.unavailable; //Create handler lock (Handlers) { Handlers.Add(new MucRoomMemberStanzaHandler(this)); Handlers.Add(new MucRoomMemberDiscoHandler(Jid, RealJid)); } DiscoInfo.AddIdentity(new DiscoIdentity("text", Name, "member")); DiscoInfo.AddFeature(new DiscoFeature(Core.protocol.Uri.DISCO_INFO)); DiscoInfo.AddFeature(new DiscoFeature(Core.protocol.Uri.DISCO_ITEMS)); }
private void jc_OnIQ(object sender, IQ iq) { if (!IsCaps(iq)) { return; } DiscoInfo info = iq.Query as DiscoInfo; if (info == null) { return; } IQ resp = iq.GetResponse(m_stream.Document); info = (DiscoInfo)resp.Query; FillInInfo(info); Write(resp); }
// We got back our disco#info query result private void GotInfoQuery(object sender, IQ iq, object state) { // If the user clicked stop, ignore this result if (was_stopped) { return; } try { if (iq.Type == IQType.result) { DiscoInfo info = (DiscoInfo)iq.Query; // If there is an <identity> node, display the data if (info.GetIdentities().Length > 0) { DiscoIdentity i = info.GetIdentities()[0]; IdentityNameLabel.Text = i.Named.Trim(); IdentityAddressLabel.Text = iq.From.ToString(); IdentityCategoryTypeLabel.Text = string.Format("{0} - {1}", i.Category.Trim(), i.Type.Trim()); Label4.Visible = true; } // Create the actions menu button PopulateActions(iq); // Track how many responses we have gotten back TurnOffSpinner(); } else if (iq.Type == IQType.error) { GotErrorBack(iq); } } catch (Exception) { GotErrorBack(iq); MessageBox.Show(string.Format("Had a problem with Info response: {0}", iq.OuterXml)); } }
public void TestCaps() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); pres.From = baz; CapsManager cm = new CapsManager(); pp.CapsManager = cm; cm.FileName = "caps.xml"; cm.Node = "http://cursive.net/clients/PresenceManagerTest"; cm.AddFeature(URI.DISCO_INFO); cm.AddFeature(URI.DELAY); cm.AddIdentity("client", "pc", null, "Presence Manager Test"); DiscoInfo info = new DiscoInfo(doc); cm.FillInInfo(info); cm[cm.Ver] = info; pres.AddChild(cm.GetCaps(pres.OwnerDocument)); pp.AddPresence(pres); JID dij = pp.GetFeatureJID(bare, URI.DISCO_INFO); Assert.AreEqual(baz, dij); dij = pp.GetFeatureJID(bare, URI.DISCO_ITEMS); Assert.IsNull(dij); dij = pp.GetFeatureJID(baz, URI.DISCO_INFO); Assert.AreEqual(baz, dij); StringSet fs = pp.GetFeatures(bare); Assert.IsTrue(fs[URI.DISCO_INFO]); Assert.IsFalse(fs[URI.DISCO_ITEMS]); }
private StringSet GetFeatures(CapsManager caps, Presence p) { if (p == null) { return(null); } Caps c = p.GetChildElement <Caps>(); if (c == null) { return(null); } DiscoInfo di = caps[c.Version]; if (di == null) { return(null); } return(di.FeatureSet); }
private void OnDiscoInfoResult(object sender, IQ iq, object data) { // <iq from='proxy.cachet.myjabber.net' to='[email protected]/Exodus' type='result' id='jcl_19'> // <query xmlns='http://jabber.org/protocol/disco#info'> // <identity category='proxy' name='SOCKS5 Bytestreams Service' type='bytestreams'/> // <feature var='http://jabber.org/protocol/bytestreams'/> // <feature var='http://jabber.org/protocol/disco#info'/> // </query> // </iq> if (iq.Type == IqType.result) { if (iq.Query is DiscoInfo) { DiscoInfo di = iq.Query as DiscoInfo; if (di.HasFeature(agsXMPP.Uri.MUC)) { Jid jid = iq.From; listView1.Groups.Add(jid.ToString(), jid.ToString()); discoManager.DiscoverItems(jid, new IqCB(OnDiscoRoomlist), null); } } } }
public override void Configure(IDictionary <string, string> properties) { DiscoInfo.AddIdentity(new DiscoIdentity("server", Name, "im")); Handlers.Add(new ClientNamespaceHandler()); Handlers.Add(new AuthDigestMD5Handler()); Handlers.Add(new AuthTMTokenHandler()); Handlers.Add(new BindSessionHandler()); Handlers.Add(new RosterHandler()); Handlers.Add(new VCardHandler()); Handlers.Add(new VerTimePingHandler()); Handlers.Add(new PrivateHandler()); Handlers.Add(new PresenceHandler()); Handlers.Add(new MessageHandler()); Handlers.Add(new MessageArchiveHandler()); Handlers.Add(new LastHandler()); Handlers.Add(new RegisterHandler()); Handlers.Add(new TransferHandler()); Handlers.Add(new CommandHandler()); Handlers.Add(new OfflineProvider(Jid)); Handlers.Add(new DiscoHandler(Jid)); messageAnnounceHandler = new MessageAnnounceHandler(); }
private void xmppDiscoServerInformation(object sender, agsXMPP.protocol.client.IQ iq, object data) { if (iq.Type == agsXMPP.protocol.client.IqType.result) { if (iq.Query != null && iq.Query is DiscoInfo) { DiscoInfo di = iq.Query as DiscoInfo; List <string> features = new List <string>(); if (di.GetFeatures() != null) { DiscoFeature[] fs = di.GetFeatures(); foreach (DiscoFeature f in fs) { if (!features.Contains(f.Var)) { features.Add(f.Var); } } } if (features.Contains("http://jabber.org/protocol/pubsub")) { if (features.Contains("http://jabber.org/protocol/pubsub#publish")) { _pepCapable = true; Jabber._presence.setMood(Jabber._presence.mood.type, Jabber._presence.mood.text); Jabber._presence.setActivity(Jabber._presence.activity.type, Jabber._presence.activity.text); Jabber._presence.setLocation(Jabber._presence.location); Jabber._presence.clearTune(); } } } } if (Jabber.xmpp.IqGrabber != null && iq.Id != null) { Jabber.xmpp.IqGrabber.Remove(iq.Id); } }
/// <summary> /// Builds and sets the caps ver attribute from a DiscoInfo object /// </summary> /// <param name="di"></param> public void SetVersion(DiscoInfo di) { Hash = "sha-1"; Version = BuildCapsVersion(di); }
private IQ CreateDiscoInfoResponse(string id) { IQ returnIq = new IQ(doc); returnIq.SetAttribute("id", id); returnIq.SetAttribute("from", jid); returnIq.SetAttribute("type", "result"); DiscoInfo info = new DiscoInfo(doc); info.AddIdentity("server", "im", "jabber2 4.2.16.6", null); info.AddFeature(URI.DISCO_ITEMS); info.AddFeature(URI.DISCO_INFO); returnIq.Query = info; return returnIq; }
/// <summary> /// Take the info for this entity, and fill it in to the given DiscoInfo protocol element. /// Node, identities, and features get filled in. /// </summary> /// <param name="info">The empty info element to fill in.</param> public void FillInInfo(DiscoInfo info) { foreach (Ident id in Identities) info.AddIdentity(id.Category, id.Type, id.Name, id.Lang); foreach (string uri in Features) info.AddFeature(uri); }
/*[Obsolete("This property is deprecated with version 1.4 of XEP-0115. You shouldn't use this propety anymore.")] * public string[] Extensions * { * get * { * var ext = this.GetAttribute("ext"); * if (ext != null) * { * var ret = ext.Split(' '); * return ret; * } * else * { * return null; * } * } * set * { * if (value != null) * { * string temp = null; * for (var i = 0; i < value.Length; i++) * { * temp += value[i]; * if (i < value.Length - 1) * temp += " "; * } * this.SetAttribute("ext", temp); * } * } * }*/ /// <summary> /// Builds and sets the caps ver attribute from a DiscoInfo object /// </summary> /// <param name="di"></param> public void SetVersion(DiscoInfo di) { this.Version = this.BuildCapsVersion(di); }
/// <summary> /// Pulls all of the data out of the given protocol response. /// </summary> /// <param name="info">If null, just calls callbacks</param> public void AddInfo(DiscoInfo info) { m_info = info; if (info == null) { AddIdentities(null); AddFeatures((StringSet)null); return; } Extensions = info.GetExtensions(); AddIdentities(info.GetIdentities()); AddFeatures(info.FeatureSet); }
private void xmppOnIq(object sender, IQ iq) { if (iq.Type == IqType.get) { if (iq.Query != null) { if (iq.Query is DiscoInfo) { iq.SwitchDirection(); iq.Type = IqType.result; DiscoInfo di = getDiscoInfo(); iq.Query = di; Jabber.xmpp.Send(iq); } else if (iq.Query is DiscoItems) { iq.SwitchDirection(); iq.Type = IqType.error; iq.Error = new Error(ErrorType.cancel, ErrorCondition.FeatureNotImplemented); Jabber.xmpp.Send(iq); } else if (iq.Query is agsXMPP.protocol.iq.version.Version) { iq.SwitchDirection(); iq.Type = IqType.result; agsXMPP.protocol.iq.version.Version version = iq.Query as agsXMPP.protocol.iq.version.Version; version.Name = Assembly.GetExecutingAssembly().GetName().Name; version.Ver = Assembly.GetExecutingAssembly().GetName().Version.ToString(); version.Os = Environment.OSVersion.ToString(); Jabber.xmpp.Send(iq); } else if (iq.Query is agsXMPP.protocol.iq.last.Last) { iq.SwitchDirection(); iq.Type = IqType.result; agsXMPP.protocol.iq.last.Last last = iq.Query as agsXMPP.protocol.iq.last.Last; last.Seconds = new TimeSpan(Jabber._presence.getLastActivityTicks()).Seconds; Jabber.xmpp.Send(iq); } else if (iq.Query is agsXMPP.protocol.iq.time.Time) { iq.SwitchDirection(); iq.Type = IqType.result; agsXMPP.protocol.iq.time.Time time = iq.Query as agsXMPP.protocol.iq.time.Time; time.Display = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); time.Tz = TimeZone.CurrentTimeZone.StandardName; time.Utc = agsXMPP.util.Time.ISO_8601Date(DateTime.Now); Jabber.xmpp.Send(iq); } else if (iq.Query is agsXMPP.protocol.extensions.ping.Ping) { iq.SwitchDirection(); iq.Type = IqType.result; agsXMPP.protocol.extensions.ping.Ping ping = iq.Query as agsXMPP.protocol.extensions.ping.Ping; Jabber.xmpp.Send(iq); } else if (iq.Query is agsXMPP.protocol.iq.avatar.Avatar) { iq.SwitchDirection(); iq.Type = IqType.result; agsXMPP.protocol.iq.avatar.Avatar avatar = iq.Query as agsXMPP.protocol.iq.avatar.Avatar; //avatar.Data = null; if (Jabber._identity.photo != null && Jabber._identity.photoFormat != null) { MemoryStream ms = new MemoryStream(); Jabber._identity.photo.Save(ms, Jabber._identity.photoFormat); avatar.Data = ms.ToArray(); avatar.MimeType = "image/" + Jabber._identity.photoFormat.ToString(); ms.Close(); ms.Dispose(); } Jabber.xmpp.Send(iq); } else if (iq.Query is agsXMPP.protocol.iq.vcard.Vcard) { iq.SwitchDirection(); iq.Type = IqType.result; iq.Query = Jabber._identity.toVcard(); Jabber.xmpp.Send(iq); } } } }
private IQ CreateIqRequest() { IQ iq = new IQ(doc); iq.To = TO_JID; iq.From = FROM_JID; iq.Type = IQType.get; iq.ID = TEST_ID; DiscoInfo info = new DiscoInfo(doc); info.SetAttribute("xmlns", URI.DISCO_INFO); iq.Query = info; return iq; }
/// <summary> /// Builds and sets the caps ver attribute from a DiscoInfo object /// </summary> /// <param name="di"> </param> public void SetVersion(DiscoInfo di) { Version = BuildCapsVersion(di); }
public TestService() { Name = "Multi User Chat"; DiscoInfo.AddIdentity(new DiscoIdentity("muc", Name, "im")); }
public XmppServiceBase() { Handlers = new List <IXmppHandler>(); Registered = false; DiscoInfo = new DiscoInfo(); }