Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the responses to several requests returns erroneous values #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Jellyfin.Plugin.Dlna.Model/IDlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ public interface IDlnaManager
/// <param name="filename">The filename.</param>
/// <returns>DlnaIconResponse.</returns>
Stream? GetIcon(string filename);

/// <summary>
/// Gets the server name.
/// </summary>
/// <returns>string</returns>
string GetServerName();
}
28 changes: 19 additions & 9 deletions src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Mime;
using System.Reflection.PortableExecutable;
using System.Threading.Tasks;
using Jellyfin.Extensions;
using Jellyfin.Plugin.Dlna.Model;
Expand Down Expand Up @@ -199,10 +200,10 @@
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
[Produces(MediaTypeNames.Text.Xml)]
public ActionResult<EventSubscriptionResponse> ProcessMediaReceiverRegistrarEventRequest(string serverId)
public ActionResult ProcessMediaReceiverRegistrarEventRequest(string serverId)
{
return ProcessEventRequest(_mediaReceiverRegistrar);
SetResponse(ProcessEventRequest(_mediaReceiverRegistrar));
return new EmptyResult();
}

/// <summary>
Expand All @@ -218,10 +219,10 @@
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
[Produces(MediaTypeNames.Text.Xml)]
public ActionResult<EventSubscriptionResponse> ProcessContentDirectoryEventRequest(string serverId)
public ActionResult ProcessContentDirectoryEventRequest(string serverId)
{
return ProcessEventRequest(_contentDirectory);
SetResponse(ProcessEventRequest(_contentDirectory));
return new EmptyResult();
}

/// <summary>
Expand All @@ -237,10 +238,10 @@
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
[Produces(MediaTypeNames.Text.Xml)]
public ActionResult<EventSubscriptionResponse> ProcessConnectionManagerEventRequest(string serverId)
public ActionResult ProcessConnectionManagerEventRequest(string serverId)
{
return ProcessEventRequest(_connectionManager);
SetResponse(ProcessEventRequest(_connectionManager));
return new EmptyResult();
}

/// <summary>
Expand Down Expand Up @@ -333,4 +334,13 @@

return dlnaEventManager.CancelEventSubscription(subscriptionId);
}

private void SetResponse(EventSubscriptionResponse eventSubscriptionResponse)
{
var text = eventSubscriptionResponse.ToString();
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
Response.Headers["Server"] = _dlnaManager.GetServerName();
Response.Headers.Append("SID", eventSubscriptionResponse.Headers["SID"]);
Response.Headers["Timeout"] = Request.Headers["Timeout"];
Response.ContentLength = 0;
}
}
5 changes: 5 additions & 0 deletions src/Jellyfin.Plugin.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ private bool IsRegexOrSubstringMatch(string input, string pattern, string fieldn
return profile;
}

public string GetServerName()
{
return _appHost.FriendlyName;
}

private bool IsMatch(IHeaderDictionary headers, DeviceIdentification profileInfo)
{
return profileInfo.Headers.Any(i => IsMatch(headers, i));
Expand Down
11 changes: 11 additions & 0 deletions src/Jellyfin.Plugin.Dlna/EventSubscriptionResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS1591

using System;
using System.Collections.Generic;

namespace Jellyfin.Plugin.Dlna;
Expand All @@ -18,4 +19,14 @@ public EventSubscriptionResponse(string content, string contentType)
public string ContentType { get; set; }

public Dictionary<string, string> Headers { get; }

public override string ToString()
{
if (ContentType.Equals("text/plain", StringComparison.OrdinalIgnoreCase))
{
return Content.Trim() + "\r\n" + string.Join(Environment.NewLine, Headers);
}

return Content;
}
}
Loading