2014-04-10 17:06:54 +02:00
|
|
|
|
using MediaBrowser.Dlna.Common;
|
|
|
|
|
using MediaBrowser.Model.Dlna;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Security;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Dlna.Server
|
|
|
|
|
{
|
|
|
|
|
public class DescriptionXmlBuilder
|
|
|
|
|
{
|
|
|
|
|
private readonly DeviceProfile _profile;
|
|
|
|
|
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
private readonly string _serverUdn;
|
2014-05-16 19:11:07 +02:00
|
|
|
|
private readonly string _serverAddress;
|
2014-04-10 17:06:54 +02:00
|
|
|
|
|
2014-05-16 19:11:07 +02:00
|
|
|
|
public DescriptionXmlBuilder(DeviceProfile profile, string serverUdn, string serverAddress)
|
2014-04-10 17:06:54 +02:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(serverUdn))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("serverUdn");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_profile = profile;
|
|
|
|
|
_serverUdn = serverUdn;
|
2014-05-16 19:11:07 +02:00
|
|
|
|
_serverAddress = serverAddress;
|
2014-04-10 17:06:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetXml()
|
|
|
|
|
{
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append("<?xml version=\"1.0\"?>");
|
2014-04-24 16:11:05 +02:00
|
|
|
|
|
|
|
|
|
builder.Append("<root xmlns=\"urn:schemas-upnp-org:device-1-0\" xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\"");
|
|
|
|
|
foreach (var att in _profile.XmlRootAttributes)
|
|
|
|
|
{
|
|
|
|
|
builder.AppendFormat(" {0}=\"{1}\"", att.Name, att.Value);
|
|
|
|
|
}
|
|
|
|
|
builder.Append(">");
|
2014-04-10 17:06:54 +02:00
|
|
|
|
|
|
|
|
|
builder.Append("<specVersion>");
|
|
|
|
|
builder.Append("<major>1</major>");
|
|
|
|
|
builder.Append("<minor>0</minor>");
|
|
|
|
|
builder.Append("</specVersion>");
|
|
|
|
|
|
|
|
|
|
AppendDeviceInfo(builder);
|
|
|
|
|
|
|
|
|
|
builder.Append("</root>");
|
|
|
|
|
|
|
|
|
|
return builder.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AppendDeviceInfo(StringBuilder builder)
|
|
|
|
|
{
|
2014-04-15 09:27:20 +02:00
|
|
|
|
builder.Append("<device>");
|
2014-04-10 17:06:54 +02:00
|
|
|
|
AppendDeviceProperties(builder);
|
|
|
|
|
|
|
|
|
|
AppendIconList(builder);
|
|
|
|
|
AppendServiceList(builder);
|
2014-04-15 09:27:20 +02:00
|
|
|
|
builder.Append("</device>");
|
2014-04-10 17:06:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AppendDeviceProperties(StringBuilder builder)
|
|
|
|
|
{
|
2014-04-18 19:16:25 +02:00
|
|
|
|
builder.Append("<UDN>uuid:" + SecurityElement.Escape(_serverUdn) + "</UDN>");
|
2014-04-10 17:06:54 +02:00
|
|
|
|
builder.Append("<dlna:X_DLNACAP>" + SecurityElement.Escape(_profile.XDlnaCap ?? string.Empty) + "</dlna:X_DLNACAP>");
|
2014-04-21 18:02:30 +02:00
|
|
|
|
|
2014-05-16 19:11:07 +02:00
|
|
|
|
builder.Append("<dlna:X_DLNADOC xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">M-DMS-1.50</dlna:X_DLNADOC>");
|
2014-05-24 03:16:53 +02:00
|
|
|
|
builder.Append("<dlna:X_DLNADOC xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">" + SecurityElement.Escape(_profile.XDlnaDoc ?? string.Empty) + "</dlna:X_DLNADOC>");
|
2014-04-15 05:54:52 +02:00
|
|
|
|
|
2014-04-10 17:06:54 +02:00
|
|
|
|
builder.Append("<friendlyName>" + SecurityElement.Escape(_profile.FriendlyName ?? string.Empty) + "</friendlyName>");
|
|
|
|
|
builder.Append("<deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>");
|
|
|
|
|
builder.Append("<manufacturer>" + SecurityElement.Escape(_profile.Manufacturer ?? string.Empty) + "</manufacturer>");
|
|
|
|
|
builder.Append("<manufacturerURL>" + SecurityElement.Escape(_profile.ManufacturerUrl ?? string.Empty) + "</manufacturerURL>");
|
|
|
|
|
builder.Append("<modelName>" + SecurityElement.Escape(_profile.ModelName ?? string.Empty) + "</modelName>");
|
|
|
|
|
builder.Append("<modelDescription>" + SecurityElement.Escape(_profile.ModelDescription ?? string.Empty) + "</modelDescription>");
|
|
|
|
|
builder.Append("<modelNumber>" + SecurityElement.Escape(_profile.ModelNumber ?? string.Empty) + "</modelNumber>");
|
|
|
|
|
builder.Append("<modelURL>" + SecurityElement.Escape(_profile.ModelUrl ?? string.Empty) + "</modelURL>");
|
|
|
|
|
builder.Append("<serialNumber>" + SecurityElement.Escape(_profile.SerialNumber ?? string.Empty) + "</serialNumber>");
|
|
|
|
|
|
2014-05-16 19:11:07 +02:00
|
|
|
|
//builder.Append("<URLBase>" + SecurityElement.Escape(_serverAddress) + "</URLBase>");
|
|
|
|
|
|
2014-04-21 03:36:12 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(_profile.SonyAggregationFlags))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<av:aggregationFlags xmlns:av=\"urn:schemas-sony-com:av\">" + SecurityElement.Escape(_profile.SonyAggregationFlags) + "</av:aggregationFlags>");
|
|
|
|
|
}
|
2014-04-10 17:06:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AppendIconList(StringBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<iconList>");
|
|
|
|
|
|
|
|
|
|
foreach (var icon in GetIcons())
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<icon>");
|
|
|
|
|
|
|
|
|
|
builder.Append("<mimetype>" + SecurityElement.Escape(icon.MimeType ?? string.Empty) + "</mimetype>");
|
|
|
|
|
builder.Append("<width>" + SecurityElement.Escape(icon.Width.ToString(_usCulture)) + "</width>");
|
|
|
|
|
builder.Append("<height>" + SecurityElement.Escape(icon.Height.ToString(_usCulture)) + "</height>");
|
|
|
|
|
builder.Append("<depth>" + SecurityElement.Escape(icon.Depth ?? string.Empty) + "</depth>");
|
|
|
|
|
builder.Append("<url>" + SecurityElement.Escape(icon.Url ?? string.Empty) + "</url>");
|
|
|
|
|
|
|
|
|
|
builder.Append("</icon>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.Append("</iconList>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AppendServiceList(StringBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<serviceList>");
|
|
|
|
|
|
|
|
|
|
foreach (var service in GetServices())
|
|
|
|
|
{
|
2014-04-15 05:54:52 +02:00
|
|
|
|
builder.Append("<service>");
|
2014-04-10 17:06:54 +02:00
|
|
|
|
|
|
|
|
|
builder.Append("<serviceType>" + SecurityElement.Escape(service.ServiceType ?? string.Empty) + "</serviceType>");
|
|
|
|
|
builder.Append("<serviceId>" + SecurityElement.Escape(service.ServiceId ?? string.Empty) + "</serviceId>");
|
|
|
|
|
builder.Append("<SCPDURL>" + SecurityElement.Escape(service.ScpdUrl ?? string.Empty) + "</SCPDURL>");
|
|
|
|
|
builder.Append("<controlURL>" + SecurityElement.Escape(service.ControlUrl ?? string.Empty) + "</controlURL>");
|
|
|
|
|
builder.Append("<eventSubURL>" + SecurityElement.Escape(service.EventSubUrl ?? string.Empty) + "</eventSubURL>");
|
|
|
|
|
|
2014-04-15 05:54:52 +02:00
|
|
|
|
builder.Append("</service>");
|
2014-04-10 17:06:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.Append("</serviceList>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<DeviceIcon> GetIcons()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<DeviceIcon>();
|
|
|
|
|
|
2014-07-30 05:31:35 +02:00
|
|
|
|
list.Add(new DeviceIcon
|
|
|
|
|
{
|
|
|
|
|
MimeType = "image/png",
|
|
|
|
|
Depth = "24",
|
|
|
|
|
Width = 240,
|
|
|
|
|
Height = 240,
|
2015-01-17 20:30:23 +01:00
|
|
|
|
Url = "/dlna/icons/logo240.png"
|
2014-07-30 05:31:35 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new DeviceIcon
|
|
|
|
|
{
|
|
|
|
|
MimeType = "image/jpeg",
|
|
|
|
|
Depth = "24",
|
|
|
|
|
Width = 240,
|
|
|
|
|
Height = 240,
|
2015-01-17 20:30:23 +01:00
|
|
|
|
Url = "/dlna/icons/logo240.jpg"
|
2014-07-30 05:31:35 +02:00
|
|
|
|
});
|
|
|
|
|
|
2014-04-10 17:06:54 +02:00
|
|
|
|
list.Add(new DeviceIcon
|
|
|
|
|
{
|
2014-04-16 07:08:12 +02:00
|
|
|
|
MimeType = "image/png",
|
2014-04-10 17:06:54 +02:00
|
|
|
|
Depth = "24",
|
2014-04-16 07:08:12 +02:00
|
|
|
|
Width = 120,
|
|
|
|
|
Height = 120,
|
2015-01-17 20:30:23 +01:00
|
|
|
|
Url = "/dlna/icons/logo120.png"
|
2014-04-10 17:06:54 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new DeviceIcon
|
|
|
|
|
{
|
|
|
|
|
MimeType = "image/jpeg",
|
|
|
|
|
Depth = "24",
|
|
|
|
|
Width = 120,
|
|
|
|
|
Height = 120,
|
2015-01-17 20:30:23 +01:00
|
|
|
|
Url = "/dlna/icons/logo120.jpg"
|
2014-04-10 17:06:54 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new DeviceIcon
|
|
|
|
|
{
|
|
|
|
|
MimeType = "image/png",
|
|
|
|
|
Depth = "24",
|
|
|
|
|
Width = 48,
|
|
|
|
|
Height = 48,
|
2015-01-17 20:30:23 +01:00
|
|
|
|
Url = "/dlna/icons/logo48.png"
|
2014-04-10 17:06:54 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new DeviceIcon
|
|
|
|
|
{
|
2014-04-16 07:08:12 +02:00
|
|
|
|
MimeType = "image/jpeg",
|
2014-04-10 17:06:54 +02:00
|
|
|
|
Depth = "24",
|
2014-04-16 07:08:12 +02:00
|
|
|
|
Width = 48,
|
|
|
|
|
Height = 48,
|
2015-01-17 20:30:23 +01:00
|
|
|
|
Url = "/dlna/icons/logo48.jpg"
|
2014-04-10 17:06:54 +02:00
|
|
|
|
});
|
2014-04-20 07:21:08 +02:00
|
|
|
|
|
2014-04-10 17:06:54 +02:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<DeviceService> GetServices()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<DeviceService>();
|
|
|
|
|
|
|
|
|
|
list.Add(new DeviceService
|
|
|
|
|
{
|
|
|
|
|
ServiceType = "urn:schemas-upnp-org:service:ContentDirectory:1",
|
|
|
|
|
ServiceId = "urn:upnp-org:serviceId:ContentDirectory",
|
2015-01-17 20:30:23 +01:00
|
|
|
|
ScpdUrl = "/dlna/contentdirectory/contentdirectory.xml",
|
|
|
|
|
ControlUrl = "/dlna/contentdirectory/" + _serverUdn + "/control",
|
|
|
|
|
EventSubUrl = "/dlna/contentdirectory/" + _serverUdn + "/events"
|
2014-04-10 17:06:54 +02:00
|
|
|
|
});
|
|
|
|
|
|
2014-05-21 02:56:24 +02:00
|
|
|
|
list.Add(new DeviceService
|
|
|
|
|
{
|
|
|
|
|
ServiceType = "urn:schemas-upnp-org:service:ConnectionManager:1",
|
|
|
|
|
ServiceId = "urn:upnp-org:serviceId:ConnectionManager",
|
2015-01-17 20:30:23 +01:00
|
|
|
|
ScpdUrl = "/dlna/connectionmanager/connectionmanager.xml",
|
|
|
|
|
ControlUrl = "/dlna/connectionmanager/" + _serverUdn + "/control",
|
|
|
|
|
EventSubUrl = "/dlna/connectionmanager/" + _serverUdn + "/events"
|
2014-05-21 02:56:24 +02:00
|
|
|
|
});
|
|
|
|
|
|
2014-04-10 17:06:54 +02:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return GetXml();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|