/// <summary> /// Empaqquete un DIscoInfo /// </summary> /// <param name="info">DicoInfo</param> /// <returns>Ampaquetage</returns> public static string DiscoInfoToVersion(DiscoInfo info) { StringBuilder builder = new StringBuilder(256); DiscoIdentity[] identities = info.GetIdentities(); string[] ids = new string[identities.Length]; for (int i = 0; i < identities.Length; i++) { ids[i] = string.Format("{0}/{1}", identities[i].Category, identities[i].Type); } Array.Sort(ids); foreach (string id in ids) { builder.AppendFormat("{0}<", id); } DiscoFeature[] features = info.GetFeatures(); string[] feas = new string[features.Length]; for (int i = 0; i < features.Length; i++) { feas[i] = features[i].Var; } Array.Sort(feas); foreach (string fea in feas) { builder.AppendFormat("{0}<", fea); } SHA1Managed sha1 = new SHA1Managed(); byte[] hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(builder.ToString())); return(Convert.ToBase64String(hash)); }
// 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)); } }
/// <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 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] */ ArrayList features = new ArrayList(); ArrayList 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(); StringBuilder S = new StringBuilder(); foreach (string s in identities) { S.Append(s + "<"); } foreach (string s in features) { S.Append(s + "<"); } byte[] sha1 = Util.Hash.Sha1HashBytes(S.ToString()); #if CF return(Convert.ToBase64String(sha1, 0, sha1.Length)); #else return(Convert.ToBase64String(sha1)); #endif }
/// <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); }