aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs')
-rw-r--r--MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs101
1 files changed, 81 insertions, 20 deletions
diff --git a/MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs b/MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs
index f4f724d07..e302fe902 100644
--- a/MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs
+++ b/MediaBrowser.Dlna/Server/DescriptionXmlBuilder.cs
@@ -1,8 +1,10 @@
using MediaBrowser.Dlna.Common;
using MediaBrowser.Model.Dlna;
+using MediaBrowser.Model.Extensions;
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
using System.Security;
using System.Text;
@@ -15,17 +17,29 @@ namespace MediaBrowser.Dlna.Server
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly string _serverUdn;
private readonly string _serverAddress;
+ private readonly string _serverName;
- public DescriptionXmlBuilder(DeviceProfile profile, string serverUdn, string serverAddress)
+ public DescriptionXmlBuilder(DeviceProfile profile, string serverUdn, string serverAddress, string serverName)
{
if (string.IsNullOrWhiteSpace(serverUdn))
{
throw new ArgumentNullException("serverUdn");
}
+ if (string.IsNullOrWhiteSpace(serverAddress))
+ {
+ throw new ArgumentNullException("serverAddress");
+ }
+
_profile = profile;
_serverUdn = serverUdn;
_serverAddress = serverAddress;
+ _serverName = serverName;
+ }
+
+ private bool EnableAbsoluteUrls
+ {
+ get { return false; }
}
public string GetXml()
@@ -71,7 +85,7 @@ namespace MediaBrowser.Dlna.Server
builder.Append("<dlna:X_DLNADOC xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">M-DMS-1.50</dlna:X_DLNADOC>");
builder.Append("<dlna:X_DLNADOC xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">" + SecurityElement.Escape(_profile.XDlnaDoc ?? string.Empty) + "</dlna:X_DLNADOC>");
- builder.Append("<friendlyName>" + SecurityElement.Escape(_profile.FriendlyName ?? string.Empty) + "</friendlyName>");
+ builder.Append("<friendlyName>" + SecurityElement.Escape(GetFriendlyName()) + "</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>");
@@ -81,14 +95,30 @@ namespace MediaBrowser.Dlna.Server
builder.Append("<modelURL>" + SecurityElement.Escape(_profile.ModelUrl ?? string.Empty) + "</modelURL>");
builder.Append("<serialNumber>" + SecurityElement.Escape(_profile.SerialNumber ?? string.Empty) + "</serialNumber>");
- //builder.Append("<URLBase>" + SecurityElement.Escape(_serverAddress) + "</URLBase>");
-
+ builder.Append("<presentationURL>" + SecurityElement.Escape(_serverAddress) + "</presentationURL>");
+
+ if (!EnableAbsoluteUrls)
+ {
+ //builder.Append("<URLBase>" + SecurityElement.Escape(_serverAddress) + "</URLBase>");
+ }
+
if (!string.IsNullOrWhiteSpace(_profile.SonyAggregationFlags))
{
builder.Append("<av:aggregationFlags xmlns:av=\"urn:schemas-sony-com:av\">" + SecurityElement.Escape(_profile.SonyAggregationFlags) + "</av:aggregationFlags>");
}
}
+ private string GetFriendlyName()
+ {
+ var characters = _serverName.Where(c => (char.IsLetterOrDigit(c) || c == '-')).ToArray();
+
+ var serverName = new string(characters);
+
+ var name = (_profile.FriendlyName ?? string.Empty).Replace("${HostName}", serverName, StringComparison.OrdinalIgnoreCase);
+
+ return name;
+ }
+
private void AppendIconList(StringBuilder builder)
{
builder.Append("<iconList>");
@@ -101,7 +131,7 @@ namespace MediaBrowser.Dlna.Server
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("<url>" + BuildUrl(icon.Url) + "</url>");
builder.Append("</icon>");
}
@@ -119,9 +149,9 @@ namespace MediaBrowser.Dlna.Server
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>");
+ builder.Append("<SCPDURL>" + BuildUrl(service.ScpdUrl) + "</SCPDURL>");
+ builder.Append("<controlURL>" + BuildUrl(service.ControlUrl) + "</controlURL>");
+ builder.Append("<eventSubURL>" + BuildUrl(service.EventSubUrl) + "</eventSubURL>");
builder.Append("</service>");
}
@@ -129,6 +159,25 @@ namespace MediaBrowser.Dlna.Server
builder.Append("</serviceList>");
}
+ private string BuildUrl(string url)
+ {
+ if (string.IsNullOrWhiteSpace(url))
+ {
+ return string.Empty;
+ }
+
+ url = url.TrimStart('/');
+
+ url = "/dlna/" + _serverUdn + "/" + url;
+
+ if (EnableAbsoluteUrls)
+ {
+ url = _serverAddress.TrimEnd('/') + url;
+ }
+
+ return SecurityElement.Escape(url);
+ }
+
private IEnumerable<DeviceIcon> GetIcons()
{
var list = new List<DeviceIcon>();
@@ -139,7 +188,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24",
Width = 240,
Height = 240,
- Url = "/mediabrowser/dlna/icons/logo240.png"
+ Url = "icons/logo240.png"
});
list.Add(new DeviceIcon
@@ -148,7 +197,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24",
Width = 240,
Height = 240,
- Url = "/mediabrowser/dlna/icons/logo240.jpg"
+ Url = "icons/logo240.jpg"
});
list.Add(new DeviceIcon
@@ -157,7 +206,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24",
Width = 120,
Height = 120,
- Url = "/mediabrowser/dlna/icons/logo120.png"
+ Url = "icons/logo120.png"
});
list.Add(new DeviceIcon
@@ -166,7 +215,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24",
Width = 120,
Height = 120,
- Url = "/mediabrowser/dlna/icons/logo120.jpg"
+ Url = "icons/logo120.jpg"
});
list.Add(new DeviceIcon
@@ -175,7 +224,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24",
Width = 48,
Height = 48,
- Url = "/mediabrowser/dlna/icons/logo48.png"
+ Url = "icons/logo48.png"
});
list.Add(new DeviceIcon
@@ -184,7 +233,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24",
Width = 48,
Height = 48,
- Url = "/mediabrowser/dlna/icons/logo48.jpg"
+ Url = "icons/logo48.jpg"
});
return list;
@@ -198,20 +247,32 @@ namespace MediaBrowser.Dlna.Server
{
ServiceType = "urn:schemas-upnp-org:service:ContentDirectory:1",
ServiceId = "urn:upnp-org:serviceId:ContentDirectory",
- ScpdUrl = "/mediabrowser/dlna/contentdirectory/contentdirectory.xml",
- ControlUrl = "/mediabrowser/dlna/contentdirectory/" + _serverUdn + "/control",
- EventSubUrl = "/mediabrowser/dlna/contentdirectory/" + _serverUdn + "/events"
+ ScpdUrl = "contentdirectory/contentdirectory.xml",
+ ControlUrl = "contentdirectory/control",
+ EventSubUrl = "contentdirectory/events"
});
list.Add(new DeviceService
{
ServiceType = "urn:schemas-upnp-org:service:ConnectionManager:1",
ServiceId = "urn:upnp-org:serviceId:ConnectionManager",
- ScpdUrl = "/mediabrowser/dlna/connectionmanager/connectionmanager.xml",
- ControlUrl = "/mediabrowser/dlna/connectionmanager/" + _serverUdn + "/control",
- EventSubUrl = "/mediabrowser/dlna/connectionmanager/" + _serverUdn + "/events"
+ ScpdUrl = "connectionmanager/connectionmanager.xml",
+ ControlUrl = "connectionmanager/control",
+ EventSubUrl = "connectionmanager/events"
});
+ if (_profile.EnableMSMediaReceiverRegistrar)
+ {
+ list.Add(new DeviceService
+ {
+ ServiceType = "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1",
+ ServiceId = "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar",
+ ScpdUrl = "mediareceiverregistrar/mediareceiverregistrar.xml",
+ ControlUrl = "mediareceiverregistrar/control",
+ EventSubUrl = "mediareceiverregistrar/events"
+ });
+ }
+
return list;
}