Beispiel #1
0
        public static SLPMessage Parse(byte[] data)
        {
            int lineLen = MSNHttpUtility.IndexOf(data, "\r\n");

            if (lineLen < 0)
            {
                return(null);
            }

            try
            {
                byte[] lineData = new byte[lineLen];
                Buffer.BlockCopy(data, 0, lineData, 0, lineLen);
                string line = Encoding.UTF8.GetString(lineData);

                if (!line.Contains("MSNSLP"))
                {
                    return(null);
                }

                if (line.StartsWith("MSNSLP/1.0"))
                {
                    return(new SLPStatusMessage(data));
                }
                else
                {
                    return(new SLPRequestMessage(data));
                }
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Parses an MSNSLP message and stores the values in the object's fields.
        /// </summary>
        /// <param name="data">The messagedata to parse</param>
        public override void ParseBytes(byte[] data)
        {
            int lineLen = MSNHttpUtility.IndexOf(data, "\r\n");

            byte[] lineData = new byte[lineLen];
            Buffer.BlockCopy(data, 0, lineData, 0, lineLen);
            StartLine = Encoding.GetString(lineData).Trim();

            byte[] header = new byte[data.Length - lineLen - 2];
            Buffer.BlockCopy(data, lineLen + 2, header, 0, header.Length);

            mimeHeaders.Clear();
            int mimeEnd = mimeHeaders.Parse(header);

            byte[] body = new byte[header.Length - mimeEnd];
            Buffer.BlockCopy(header, mimeEnd, body, 0, body.Length);

            mimeBodies.Clear();
            mimeBodies.Parse(body);
        }