Merge pull request #4212 from BaronGreenback/BaseControlHandlerFix
Null Pointer fix: BaseControlHandler.cs
This commit is contained in:
commit
d9e7f1f75f
|
@ -235,13 +235,13 @@ namespace Emby.Dlna.Server
|
||||||
.Append(SecurityElement.Escape(service.ServiceId ?? string.Empty))
|
.Append(SecurityElement.Escape(service.ServiceId ?? string.Empty))
|
||||||
.Append("</serviceId>");
|
.Append("</serviceId>");
|
||||||
builder.Append("<SCPDURL>")
|
builder.Append("<SCPDURL>")
|
||||||
.Append(BuildUrl(service.ScpdUrl, true))
|
.Append(BuildUrl(service.ScpdUrl))
|
||||||
.Append("</SCPDURL>");
|
.Append("</SCPDURL>");
|
||||||
builder.Append("<controlURL>")
|
builder.Append("<controlURL>")
|
||||||
.Append(BuildUrl(service.ControlUrl, true))
|
.Append(BuildUrl(service.ControlUrl))
|
||||||
.Append("</controlURL>");
|
.Append("</controlURL>");
|
||||||
builder.Append("<eventSubURL>")
|
builder.Append("<eventSubURL>")
|
||||||
.Append(BuildUrl(service.EventSubUrl, true))
|
.Append(BuildUrl(service.EventSubUrl))
|
||||||
.Append("</eventSubURL>");
|
.Append("</eventSubURL>");
|
||||||
|
|
||||||
builder.Append("</service>");
|
builder.Append("</service>");
|
||||||
|
@ -250,13 +250,7 @@ namespace Emby.Dlna.Server
|
||||||
builder.Append("</serviceList>");
|
builder.Append("</serviceList>");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private string BuildUrl(string url)
|
||||||
/// Builds a valid url for inclusion in the xml.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url">Url to include.</param>
|
|
||||||
/// <param name="absoluteUrl">Optional. When set to true, the absolute url is always used.</param>
|
|
||||||
/// <returns>The url to use for the element.</returns>
|
|
||||||
private string BuildUrl(string url, bool absoluteUrl = false)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(url))
|
if (string.IsNullOrEmpty(url))
|
||||||
{
|
{
|
||||||
|
@ -267,7 +261,7 @@ namespace Emby.Dlna.Server
|
||||||
|
|
||||||
url = "/dlna/" + _serverUdn + "/" + url;
|
url = "/dlna/" + _serverUdn + "/" + url;
|
||||||
|
|
||||||
if (EnableAbsoluteUrls || absoluteUrl)
|
if (EnableAbsoluteUrls)
|
||||||
{
|
{
|
||||||
url = _serverAddress.TrimEnd('/') + url;
|
url = _serverAddress.TrimEnd('/') + url;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,12 +150,12 @@ namespace Emby.Dlna.Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ControlRequestInfo();
|
throw new EndOfStreamException("Stream ended but no body tag found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ControlRequestInfo> ParseBodyTagAsync(XmlReader reader)
|
private async Task<ControlRequestInfo> ParseBodyTagAsync(XmlReader reader)
|
||||||
{
|
{
|
||||||
var result = new ControlRequestInfo();
|
string namespaceURI = null, localName = null;
|
||||||
|
|
||||||
await reader.MoveToContentAsync().ConfigureAwait(false);
|
await reader.MoveToContentAsync().ConfigureAwait(false);
|
||||||
await reader.ReadAsync().ConfigureAwait(false);
|
await reader.ReadAsync().ConfigureAwait(false);
|
||||||
|
@ -165,11 +165,12 @@ namespace Emby.Dlna.Service
|
||||||
{
|
{
|
||||||
if (reader.NodeType == XmlNodeType.Element)
|
if (reader.NodeType == XmlNodeType.Element)
|
||||||
{
|
{
|
||||||
result.LocalName = reader.LocalName;
|
localName = reader.LocalName;
|
||||||
result.NamespaceURI = reader.NamespaceURI;
|
namespaceURI = reader.NamespaceURI;
|
||||||
|
|
||||||
if (!reader.IsEmptyElement)
|
if (!reader.IsEmptyElement)
|
||||||
{
|
{
|
||||||
|
var result = new ControlRequestInfo(localName, namespaceURI);
|
||||||
using (var subReader = reader.ReadSubtree())
|
using (var subReader = reader.ReadSubtree())
|
||||||
{
|
{
|
||||||
await ParseFirstBodyChildAsync(subReader, result.Headers).ConfigureAwait(false);
|
await ParseFirstBodyChildAsync(subReader, result.Headers).ConfigureAwait(false);
|
||||||
|
@ -187,7 +188,12 @@ namespace Emby.Dlna.Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
if (localName != null && namespaceURI != null)
|
||||||
|
{
|
||||||
|
return new ControlRequestInfo(localName, namespaceURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new EndOfStreamException("Stream ended but no control found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ParseFirstBodyChildAsync(XmlReader reader, IDictionary<string, string> headers)
|
private async Task ParseFirstBodyChildAsync(XmlReader reader, IDictionary<string, string> headers)
|
||||||
|
@ -234,11 +240,18 @@ namespace Emby.Dlna.Service
|
||||||
|
|
||||||
private class ControlRequestInfo
|
private class ControlRequestInfo
|
||||||
{
|
{
|
||||||
|
public ControlRequestInfo(string localName, string namespaceUri)
|
||||||
|
{
|
||||||
|
LocalName = localName;
|
||||||
|
NamespaceURI = namespaceUri;
|
||||||
|
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
public string LocalName { get; set; }
|
public string LocalName { get; set; }
|
||||||
|
|
||||||
public string NamespaceURI { get; set; }
|
public string NamespaceURI { get; set; }
|
||||||
|
|
||||||
public Dictionary<string, string> Headers { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
public Dictionary<string, string> Headers { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user