blob: d196e98518c0ee8d8cc949b4427d52359a4d1391 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
using MediaBrowser.Controller.Dlna;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace MediaBrowser.Dlna.Ssdp
{
public class SsdpHelper
{
public static SsdpMessageEventArgs ParseSsdpResponse(byte[] data)
{
using (var ms = new MemoryStream(data))
{
using (var reader = new StreamReader(ms, Encoding.ASCII))
{
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())
{
line = line.Trim();
if (string.IsNullOrEmpty(line))
{
break;
}
var parts = line.Split(new[] { ':' }, 2);
if (parts.Length >= 2)
{
headers[parts[0]] = parts[1].Trim();
}
}
return new SsdpMessageEventArgs
{
Method = method,
Headers = headers,
Message = data
};
}
}
}
}
}
|