jellyfin/MediaBrowser.Dlna/Ssdp/SsdpHelper.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2015-04-29 11:48:34 -07:00
using MediaBrowser.Controller.Dlna;
using System;
2014-03-24 22:25:03 -07:00
using System.Collections.Generic;
using System.IO;
2014-02-26 14:31:47 -07:00
using System.Text;
2014-03-24 22:25:03 -07:00
namespace MediaBrowser.Dlna.Ssdp
2014-02-26 14:31:47 -07:00
{
public class SsdpHelper
{
public static SsdpMessageEventArgs ParseSsdpResponse(byte[] data)
2014-02-26 14:31:47 -07:00
{
2014-04-26 20:42:05 -07:00
using (var ms = new MemoryStream(data))
2014-03-24 22:25:03 -07:00
{
2014-04-26 20:42:05 -07:00
using (var reader = new StreamReader(ms, Encoding.ASCII))
2014-03-24 22:25:03 -07:00
{
2014-04-26 20:42:05 -07: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-24 22:25:03 -07:00
{
2014-04-26 20:42:05 -07: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-24 22:25:03 -07:00
}
2014-02-26 14:31:47 -07:00
2014-04-26 20:42:05 -07:00
return new SsdpMessageEventArgs
2014-03-24 22:25:03 -07:00
{
2014-04-26 20:42:05 -07:00
Method = method,
2015-04-29 11:48:34 -07:00
Headers = headers,
Message = data
2014-04-26 20:42:05 -07:00
};
2014-03-24 22:25:03 -07:00
}
}
2014-02-26 14:31:47 -07:00
}
}
}