jellyfin/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2014-02-26 21:31:47 +00:00
using System;
2014-03-25 05:25:03 +00:00
using System.Collections.Generic;
using System.IO;
2014-02-26 21:31:47 +00:00
using System.Text;
2014-03-25 05:25:03 +00:00
namespace MediaBrowser.Dlna.Ssdp
2014-02-26 21:31:47 +00:00
{
public class SsdpHelper
{
/// <summary>
/// Parses the socket response into a location Uri for the DeviceDescription.xml.
/// </summary>
/// <param name="data">The data.</param>
/// <returns></returns>
2014-03-25 05:25:03 +00:00
public static Dictionary<string,string> ParseSsdpResponse(byte[] data)
2014-02-26 21:31:47 +00:00
{
2014-03-25 05:25:03 +00:00
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
2014-02-26 21:31:47 +00:00
2014-03-25 05:25:03 +00:00
using (var reader = new StreamReader(new MemoryStream(data), Encoding.ASCII))
{
for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
{
line = line.Trim();
if (string.IsNullOrEmpty(line))
{
break;
}
var parts = line.Split(new[] { ':' }, 2);
2014-02-26 21:31:47 +00:00
2014-03-25 05:25:03 +00:00
if (parts.Length == 2)
{
headers[parts[0]] = parts[1].Trim();
}
}
}
return headers;
2014-02-26 21:31:47 +00:00
}
}
}