jellyfin/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2015-04-29 18:48:34 +00:00
using MediaBrowser.Controller.Dlna;
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
{
public static SsdpMessageEventArgs ParseSsdpResponse(byte[] data)
2014-02-26 21:31:47 +00:00
{
2014-04-27 03:42:05 +00:00
using (var ms = new MemoryStream(data))
2014-03-25 05:25:03 +00:00
{
2014-04-27 03:42:05 +00:00
using (var reader = new StreamReader(ms, Encoding.ASCII))
2014-03-25 05:25:03 +00:00
{
2014-04-27 03:42:05 +00:00
var proto = (reader.ReadLine() ?? string.Empty).Trim();
var method = proto.Split(new[] { ' ' }, 2)[0];
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
2014-03-25 05:25:03 +00:00
{
2014-04-27 03:42:05 +00:00
line = line.Trim();
if (string.IsNullOrEmpty(line))
{
break;
}
var parts = line.Split(new[] { ':' }, 2);
if (parts.Length >= 2)
{
headers[parts[0]] = parts[1].Trim();
}
2014-03-25 05:25:03 +00:00
}
2014-02-26 21:31:47 +00:00
2014-04-27 03:42:05 +00:00
return new SsdpMessageEventArgs
2014-03-25 05:25:03 +00:00
{
2014-04-27 03:42:05 +00:00
Method = method,
2015-04-29 18:48:34 +00:00
Headers = headers,
Message = data
2014-04-27 03:42:05 +00:00
};
2014-03-25 05:25:03 +00:00
}
}
2014-02-26 21:31:47 +00:00
}
}
}