Example #1
0
        /// <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));
        }
Example #2
0
 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);
     }
 }
Example #3
0
        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
        }