dlna fixes

This commit is contained in:
Luke Pulverenti 2015-01-30 16:14:08 -05:00
parent 6eeb5f25f4
commit 54c5e88b87
5 changed files with 75 additions and 42 deletions

View file

@ -18,25 +18,31 @@ namespace MediaBrowser.Api.Dlna
public string UuId { get; set; } public string UuId { get; set; }
} }
[Route("/Dlna/contentdirectory/contentdirectory.xml", "GET", Summary = "Gets dlna content directory xml")] [Route("/Dlna/{UuId}/contentdirectory/contentdirectory.xml", "GET", Summary = "Gets dlna content directory xml")]
[Route("/Dlna/contentdirectory/contentdirectory", "GET", Summary = "Gets dlna content directory xml")] [Route("/Dlna/{UuId}/contentdirectory/contentdirectory", "GET", Summary = "Gets dlna content directory xml")]
public class GetContentDirectory public class GetContentDirectory
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; }
} }
[Route("/Dlna/connectionmanager/connectionmanager.xml", "GET", Summary = "Gets dlna connection manager xml")] [Route("/Dlna/{UuId}/connectionmanager/connectionmanager.xml", "GET", Summary = "Gets dlna connection manager xml")]
[Route("/Dlna/connectionmanager/connectionmanager", "GET", Summary = "Gets dlna connection manager xml")] [Route("/Dlna/{UuId}/connectionmanager/connectionmanager", "GET", Summary = "Gets dlna connection manager xml")]
public class GetConnnectionManager public class GetConnnectionManager
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; }
} }
[Route("/Dlna/mediareceiverregistrar/mediareceiverregistrar.xml", "GET", Summary = "Gets dlna mediareceiverregistrar xml")] [Route("/Dlna/{UuId}/mediareceiverregistrar/mediareceiverregistrar.xml", "GET", Summary = "Gets dlna mediareceiverregistrar xml")]
[Route("/Dlna/mediareceiverregistrar/mediareceiverregistrar", "GET", Summary = "Gets dlna mediareceiverregistrar xml")] [Route("/Dlna/{UuId}/mediareceiverregistrar/mediareceiverregistrar", "GET", Summary = "Gets dlna mediareceiverregistrar xml")]
public class GetMediaReceiverRegistrar public class GetMediaReceiverRegistrar
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; }
} }
[Route("/Dlna/contentdirectory/{UuId}/control", "POST", Summary = "Processes a control request")] [Route("/Dlna/{UuId}/contentdirectory/control", "POST", Summary = "Processes a control request")]
public class ProcessContentDirectoryControlRequest : IRequiresRequestStream public class ProcessContentDirectoryControlRequest : IRequiresRequestStream
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
@ -45,7 +51,7 @@ namespace MediaBrowser.Api.Dlna
public Stream RequestStream { get; set; } public Stream RequestStream { get; set; }
} }
[Route("/Dlna/connectionmanager/{UuId}/control", "POST", Summary = "Processes a control request")] [Route("/Dlna/{UuId}/connectionmanager/control", "POST", Summary = "Processes a control request")]
public class ProcessConnectionManagerControlRequest : IRequiresRequestStream public class ProcessConnectionManagerControlRequest : IRequiresRequestStream
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
@ -54,7 +60,7 @@ namespace MediaBrowser.Api.Dlna
public Stream RequestStream { get; set; } public Stream RequestStream { get; set; }
} }
[Route("/Dlna/mediareceiverregistrar/{UuId}/control", "POST", Summary = "Processes a control request")] [Route("/Dlna/{UuId}/mediareceiverregistrar/control", "POST", Summary = "Processes a control request")]
public class ProcessMediaReceiverRegistrarControlRequest : IRequiresRequestStream public class ProcessMediaReceiverRegistrarControlRequest : IRequiresRequestStream
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
@ -63,30 +69,34 @@ namespace MediaBrowser.Api.Dlna
public Stream RequestStream { get; set; } public Stream RequestStream { get; set; }
} }
[Route("/Dlna/mediareceiverregistrar/{UuId}/events", Summary = "Processes an event subscription request")] [Route("/Dlna/{UuId}/mediareceiverregistrar/events", Summary = "Processes an event subscription request")]
public class ProcessMediaReceiverRegistrarEventRequest public class ProcessMediaReceiverRegistrarEventRequest
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; } public string UuId { get; set; }
} }
[Route("/Dlna/contentdirectory/{UuId}/events", Summary = "Processes an event subscription request")] [Route("/Dlna/{UuId}/contentdirectory/events", Summary = "Processes an event subscription request")]
public class ProcessContentDirectoryEventRequest public class ProcessContentDirectoryEventRequest
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; } public string UuId { get; set; }
} }
[Route("/Dlna/connectionmanager/{UuId}/events", Summary = "Processes an event subscription request")] [Route("/Dlna/{UuId}/connectionmanager/events", Summary = "Processes an event subscription request")]
public class ProcessConnectionManagerEventRequest public class ProcessConnectionManagerEventRequest
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; } public string UuId { get; set; }
} }
[Route("/Dlna/{UuId}/icons/{Filename}", "GET", Summary = "Gets a server icon")]
[Route("/Dlna/icons/{Filename}", "GET", Summary = "Gets a server icon")] [Route("/Dlna/icons/{Filename}", "GET", Summary = "Gets a server icon")]
public class GetIcon public class GetIcon
{ {
[ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UuId { get; set; }
[ApiMember(Name = "Filename", Description = "The icon filename", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "Filename", Description = "The icon filename", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Filename { get; set; } public string Filename { get; set; }
} }
@ -108,7 +118,9 @@ namespace MediaBrowser.Api.Dlna
public object Get(GetDescriptionXml request) public object Get(GetDescriptionXml request)
{ {
var xml = _dlnaManager.GetServerDescriptionXml(GetRequestHeaders(), request.UuId); var url = Request.AbsoluteUri;
var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase));
var xml = _dlnaManager.GetServerDescriptionXml(GetRequestHeaders(), request.UuId, serverAddress);
return ResultFactory.GetResult(xml, "text/xml"); return ResultFactory.GetResult(xml, "text/xml");
} }

View file

@ -62,8 +62,9 @@ namespace MediaBrowser.Controller.Dlna
/// </summary> /// </summary>
/// <param name="headers">The headers.</param> /// <param name="headers">The headers.</param>
/// <param name="serverUuId">The server uu identifier.</param> /// <param name="serverUuId">The server uu identifier.</param>
/// <param name="serverAddress">The server address.</param>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
string GetServerDescriptionXml(IDictionary<string, string> headers, string serverUuId); string GetServerDescriptionXml(IDictionary<string, string> headers, string serverUuId, string serverAddress);
/// <summary> /// <summary>
/// Gets the icon. /// Gets the icon.

View file

@ -475,12 +475,12 @@ namespace MediaBrowser.Dlna
internal string Path { get; set; } internal string Path { get; set; }
} }
public string GetServerDescriptionXml(IDictionary<string, string> headers, string serverUuId) public string GetServerDescriptionXml(IDictionary<string, string> headers, string serverUuId, string serverAddress)
{ {
var profile = GetProfile(headers) ?? var profile = GetProfile(headers) ??
GetDefaultProfile(); GetDefaultProfile();
return new DescriptionXmlBuilder(profile, serverUuId, "").GetXml(); return new DescriptionXmlBuilder(profile, serverUuId, serverAddress).GetXml();
} }
public ImageStream GetIcon(string filename) public ImageStream GetIcon(string filename)

View file

@ -11,11 +11,11 @@ namespace MediaBrowser.Dlna.MediaReceiverRegistrar
{ {
GetIsValidated(), GetIsValidated(),
GetIsAuthorized(), GetIsAuthorized(),
//GetRegisterDevice(), GetRegisterDevice(),
//GetGetAuthorizationDeniedUpdateID(), GetGetAuthorizationDeniedUpdateID(),
//GetGetAuthorizationGrantedUpdateID(), GetGetAuthorizationGrantedUpdateID(),
//GetGetValidationRevokedUpdateID(), GetGetValidationRevokedUpdateID(),
//GetGetValidationSucceededUpdateID() GetGetValidationSucceededUpdateID()
}; };
return list; return list;

View file

@ -23,6 +23,11 @@ namespace MediaBrowser.Dlna.Server
throw new ArgumentNullException("serverUdn"); throw new ArgumentNullException("serverUdn");
} }
if (string.IsNullOrWhiteSpace(serverAddress))
{
throw new ArgumentNullException("serverAddress");
}
_profile = profile; _profile = profile;
_serverUdn = serverUdn; _serverUdn = serverUdn;
_serverAddress = serverAddress; _serverAddress = serverAddress;
@ -81,8 +86,8 @@ namespace MediaBrowser.Dlna.Server
builder.Append("<modelURL>" + SecurityElement.Escape(_profile.ModelUrl ?? string.Empty) + "</modelURL>"); builder.Append("<modelURL>" + SecurityElement.Escape(_profile.ModelUrl ?? string.Empty) + "</modelURL>");
builder.Append("<serialNumber>" + SecurityElement.Escape(_profile.SerialNumber ?? string.Empty) + "</serialNumber>"); builder.Append("<serialNumber>" + SecurityElement.Escape(_profile.SerialNumber ?? string.Empty) + "</serialNumber>");
//builder.Append("<URLBase>" + SecurityElement.Escape(_serverAddress) + "</URLBase>"); builder.Append("<URLBase>" + SecurityElement.Escape(_serverAddress) + "</URLBase>");
if (!string.IsNullOrWhiteSpace(_profile.SonyAggregationFlags)) if (!string.IsNullOrWhiteSpace(_profile.SonyAggregationFlags))
{ {
builder.Append("<av:aggregationFlags xmlns:av=\"urn:schemas-sony-com:av\">" + SecurityElement.Escape(_profile.SonyAggregationFlags) + "</av:aggregationFlags>"); builder.Append("<av:aggregationFlags xmlns:av=\"urn:schemas-sony-com:av\">" + SecurityElement.Escape(_profile.SonyAggregationFlags) + "</av:aggregationFlags>");
@ -101,7 +106,7 @@ namespace MediaBrowser.Dlna.Server
builder.Append("<width>" + SecurityElement.Escape(icon.Width.ToString(_usCulture)) + "</width>"); builder.Append("<width>" + SecurityElement.Escape(icon.Width.ToString(_usCulture)) + "</width>");
builder.Append("<height>" + SecurityElement.Escape(icon.Height.ToString(_usCulture)) + "</height>"); builder.Append("<height>" + SecurityElement.Escape(icon.Height.ToString(_usCulture)) + "</height>");
builder.Append("<depth>" + SecurityElement.Escape(icon.Depth ?? string.Empty) + "</depth>"); 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>"); builder.Append("</icon>");
} }
@ -119,9 +124,9 @@ namespace MediaBrowser.Dlna.Server
builder.Append("<serviceType>" + SecurityElement.Escape(service.ServiceType ?? string.Empty) + "</serviceType>"); builder.Append("<serviceType>" + SecurityElement.Escape(service.ServiceType ?? string.Empty) + "</serviceType>");
builder.Append("<serviceId>" + SecurityElement.Escape(service.ServiceId ?? string.Empty) + "</serviceId>"); builder.Append("<serviceId>" + SecurityElement.Escape(service.ServiceId ?? string.Empty) + "</serviceId>");
builder.Append("<SCPDURL>" + SecurityElement.Escape(service.ScpdUrl ?? string.Empty) + "</SCPDURL>"); builder.Append("<SCPDURL>" + BuildUrl(service.ScpdUrl) + "</SCPDURL>");
builder.Append("<controlURL>" + SecurityElement.Escape(service.ControlUrl ?? string.Empty) + "</controlURL>"); builder.Append("<controlURL>" + BuildUrl(service.ControlUrl) + "</controlURL>");
builder.Append("<eventSubURL>" + SecurityElement.Escape(service.EventSubUrl ?? string.Empty) + "</eventSubURL>"); builder.Append("<eventSubURL>" + BuildUrl(service.EventSubUrl) + "</eventSubURL>");
builder.Append("</service>"); builder.Append("</service>");
} }
@ -129,6 +134,21 @@ namespace MediaBrowser.Dlna.Server
builder.Append("</serviceList>"); builder.Append("</serviceList>");
} }
private string BuildUrl(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return string.Empty;
}
url = url.TrimStart('/');
url = "/dlna/" + _serverUdn + "/" + url;
//url = _serverAddress.TrimEnd('/') + url;
return SecurityElement.Escape(url);
}
private IEnumerable<DeviceIcon> GetIcons() private IEnumerable<DeviceIcon> GetIcons()
{ {
var list = new List<DeviceIcon>(); var list = new List<DeviceIcon>();
@ -139,7 +159,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24", Depth = "24",
Width = 240, Width = 240,
Height = 240, Height = 240,
Url = "/dlna/icons/logo240.png" Url = "icons/logo240.png"
}); });
list.Add(new DeviceIcon list.Add(new DeviceIcon
@ -148,7 +168,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24", Depth = "24",
Width = 240, Width = 240,
Height = 240, Height = 240,
Url = "/dlna/icons/logo240.jpg" Url = "icons/logo240.jpg"
}); });
list.Add(new DeviceIcon list.Add(new DeviceIcon
@ -157,7 +177,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24", Depth = "24",
Width = 120, Width = 120,
Height = 120, Height = 120,
Url = "/dlna/icons/logo120.png" Url = "icons/logo120.png"
}); });
list.Add(new DeviceIcon list.Add(new DeviceIcon
@ -166,7 +186,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24", Depth = "24",
Width = 120, Width = 120,
Height = 120, Height = 120,
Url = "/dlna/icons/logo120.jpg" Url = "icons/logo120.jpg"
}); });
list.Add(new DeviceIcon list.Add(new DeviceIcon
@ -175,7 +195,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24", Depth = "24",
Width = 48, Width = 48,
Height = 48, Height = 48,
Url = "/dlna/icons/logo48.png" Url = "icons/logo48.png"
}); });
list.Add(new DeviceIcon list.Add(new DeviceIcon
@ -184,7 +204,7 @@ namespace MediaBrowser.Dlna.Server
Depth = "24", Depth = "24",
Width = 48, Width = 48,
Height = 48, Height = 48,
Url = "/dlna/icons/logo48.jpg" Url = "icons/logo48.jpg"
}); });
return list; return list;
@ -198,27 +218,27 @@ namespace MediaBrowser.Dlna.Server
{ {
ServiceType = "urn:schemas-upnp-org:service:ContentDirectory:1", ServiceType = "urn:schemas-upnp-org:service:ContentDirectory:1",
ServiceId = "urn:upnp-org:serviceId:ContentDirectory", ServiceId = "urn:upnp-org:serviceId:ContentDirectory",
ScpdUrl = "/dlna/contentdirectory/contentdirectory.xml", ScpdUrl = "contentdirectory/contentdirectory.xml",
ControlUrl = "/dlna/contentdirectory/" + _serverUdn + "/control", ControlUrl = "contentdirectory/control",
EventSubUrl = "/dlna/contentdirectory/" + _serverUdn + "/events" EventSubUrl = "contentdirectory/events"
}); });
list.Add(new DeviceService list.Add(new DeviceService
{ {
ServiceType = "urn:schemas-upnp-org:service:ConnectionManager:1", ServiceType = "urn:schemas-upnp-org:service:ConnectionManager:1",
ServiceId = "urn:upnp-org:serviceId:ConnectionManager", ServiceId = "urn:upnp-org:serviceId:ConnectionManager",
ScpdUrl = "/dlna/connectionmanager/connectionmanager.xml", ScpdUrl = "connectionmanager/connectionmanager.xml",
ControlUrl = "/dlna/connectionmanager/" + _serverUdn + "/control", ControlUrl = "connectionmanager/control",
EventSubUrl = "/dlna/connectionmanager/" + _serverUdn + "/events" EventSubUrl = "connectionmanager/events"
}); });
list.Add(new DeviceService list.Add(new DeviceService
{ {
ServiceType = "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1", ServiceType = "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1",
ServiceId = "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar", ServiceId = "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar",
ScpdUrl = "/dlna/mediareceiverregistrar/mediareceiverregistrar.xml", ScpdUrl = "mediareceiverregistrar/mediareceiverregistrar.xml",
ControlUrl = "/dlna/mediareceiverregistrar/" + _serverUdn + "/control", ControlUrl = "mediareceiverregistrar/control",
EventSubUrl = "/dlna/mediareceiverregistrar/" + _serverUdn + "/events" EventSubUrl = "mediareceiverregistrar/events"
}); });
return list; return list;