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); } }
/// <summary> /// Gets the style string specifying charset, font, etc. This is used in the MIME header send with a switchboard message. /// </summary> /// <returns></returns> internal string GetStyleString() { StringBuilder builder = new StringBuilder(); builder.Append("FN=").Append(MSNHttpUtility.UrlEncode(Font.ToString())); builder.Append("; EF="); if (((int)Decorations & (int)TextDecorations.Italic) > 0) { builder.Append('I'); } if (((int)Decorations & (int)TextDecorations.Bold) > 0) { builder.Append('B'); } if (((int)Decorations & (int)TextDecorations.Underline) > 0) { builder.Append('U'); } if (((int)Decorations & (int)TextDecorations.Strike) > 0) { builder.Append('S'); } builder.Append("; CO="); builder.Append(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:x2}", new object[] { Color.B })); builder.Append(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:x2}", new object[] { Color.G })); builder.Append(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:x2}", new object[] { Color.R })); builder.Append("; CS=").Append(((int)CharSet).ToString(System.Globalization.CultureInfo.InvariantCulture)); if (rightToLeft) { builder.Append("; RL=1"); } builder.Append("; PF=22"); return(builder.ToString()); }
public static string GetDecodeString(string context) { if (context.IndexOf(" ") == -1) { return(MSNHttpUtility.MSNObjectUrlDecode(context)); } return(context); }
/// <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); }
/// <summary> /// Returns the url-encoded xml string. /// </summary> /// <returns></returns> protected virtual string GetEncodedString() { return(MSNHttpUtility.MSNObjectUrlEncode(GetXmlString())); }
/// <summary> /// Returns the "url-encoded xml" string for MSNObjects. /// </summary> /// <param name="context"></param> /// <returns></returns> public static string GetEncodeString(string context) { return(MSNHttpUtility.MSNObjectUrlEncode(context)); }