aboutsummaryrefslogtreecommitdiff
path: root/Emby.Dlna/Service
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2023-11-09 14:45:16 -0500
committerPatrick Barron <barronpm@gmail.com>2023-11-15 20:53:44 -0500
commitf1aba6b95230474d47c580071370c7dbd00eba13 (patch)
tree4fdc0131e7ae17c724e5bcda8d1e8878475a6461 /Emby.Dlna/Service
parent01fd42cf9555d85469c07ce3d0c0e5842359eb2b (diff)
Remove Emby.Dlna
Diffstat (limited to 'Emby.Dlna/Service')
-rw-r--r--Emby.Dlna/Service/BaseControlHandler.cs242
-rw-r--r--Emby.Dlna/Service/BaseService.cs37
-rw-r--r--Emby.Dlna/Service/ControlErrorHandler.cs52
-rw-r--r--Emby.Dlna/Service/ServiceXmlBuilder.cs109
4 files changed, 0 insertions, 440 deletions
diff --git a/Emby.Dlna/Service/BaseControlHandler.cs b/Emby.Dlna/Service/BaseControlHandler.cs
deleted file mode 100644
index bff5307a49..0000000000
--- a/Emby.Dlna/Service/BaseControlHandler.cs
+++ /dev/null
@@ -1,242 +0,0 @@
-#pragma warning disable CS1591
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading.Tasks;
-using System.Xml;
-using Emby.Dlna.Didl;
-using Jellyfin.Extensions;
-using MediaBrowser.Controller.Configuration;
-using Microsoft.Extensions.Logging;
-
-namespace Emby.Dlna.Service
-{
- public abstract class BaseControlHandler
- {
- private const string NsSoapEnv = "http://schemas.xmlsoap.org/soap/envelope/";
-
- protected BaseControlHandler(IServerConfigurationManager config, ILogger logger)
- {
- Config = config;
- Logger = logger;
- }
-
- protected IServerConfigurationManager Config { get; }
-
- protected ILogger Logger { get; }
-
- public async Task<ControlResponse> ProcessControlRequestAsync(ControlRequest request)
- {
- try
- {
- LogRequest(request);
-
- var response = await ProcessControlRequestInternalAsync(request).ConfigureAwait(false);
- LogResponse(response);
- return response;
- }
- catch (Exception ex)
- {
- Logger.LogError(ex, "Error processing control request");
-
- return ControlErrorHandler.GetResponse(ex);
- }
- }
-
- private async Task<ControlResponse> ProcessControlRequestInternalAsync(ControlRequest request)
- {
- ControlRequestInfo requestInfo;
-
- using (var streamReader = new StreamReader(request.InputXml, Encoding.UTF8))
- {
- var readerSettings = new XmlReaderSettings()
- {
- ValidationType = ValidationType.None,
- CheckCharacters = false,
- IgnoreProcessingInstructions = true,
- IgnoreComments = true,
- Async = true
- };
-
- using var reader = XmlReader.Create(streamReader, readerSettings);
- requestInfo = await ParseRequestAsync(reader).ConfigureAwait(false);
- }
-
- Logger.LogDebug("Received control request {LocalName}, params: {@Headers}", requestInfo.LocalName, requestInfo.Headers);
-
- return CreateControlResponse(requestInfo);
- }
-
- private ControlResponse CreateControlResponse(ControlRequestInfo requestInfo)
- {
- var settings = new XmlWriterSettings
- {
- Encoding = Encoding.UTF8,
- CloseOutput = false
- };
-
- StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
-
- using (var writer = XmlWriter.Create(builder, settings))
- {
- writer.WriteStartDocument(true);
-
- writer.WriteStartElement("SOAP-ENV", "Envelope", NsSoapEnv);
- writer.WriteAttributeString(string.Empty, "encodingStyle", NsSoapEnv, "http://schemas.xmlsoap.org/soap/encoding/");
-
- writer.WriteStartElement("SOAP-ENV", "Body", NsSoapEnv);
- writer.WriteStartElement("u", requestInfo.LocalName + "Response", requestInfo.NamespaceURI);
-
- WriteResult(requestInfo.LocalName, requestInfo.Headers, writer);
-
- writer.WriteFullEndElement();
- writer.WriteFullEndElement();
-
- writer.WriteFullEndElement();
- writer.WriteEndDocument();
- }
-
- var xml = builder.ToString().Replace("xmlns:m=", "xmlns:u=", StringComparison.Ordinal);
-
- var controlResponse = new ControlResponse(xml, true);
-
- controlResponse.Headers.Add("EXT", string.Empty);
-
- return controlResponse;
- }
-
- private async Task<ControlRequestInfo> ParseRequestAsync(XmlReader reader)
- {
- await reader.MoveToContentAsync().ConfigureAwait(false);
- await reader.ReadAsync().ConfigureAwait(false);
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- if (string.Equals(reader.LocalName, "Body", StringComparison.Ordinal))
- {
- if (reader.IsEmptyElement)
- {
- await reader.ReadAsync().ConfigureAwait(false);
- continue;
- }
-
- using var subReader = reader.ReadSubtree();
- return await ParseBodyTagAsync(subReader).ConfigureAwait(false);
- }
-
- await reader.SkipAsync().ConfigureAwait(false);
- }
- else
- {
- await reader.ReadAsync().ConfigureAwait(false);
- }
- }
-
- throw new EndOfStreamException("Stream ended but no body tag found.");
- }
-
- private async Task<ControlRequestInfo> ParseBodyTagAsync(XmlReader reader)
- {
- string? namespaceURI = null, localName = null;
-
- await reader.MoveToContentAsync().ConfigureAwait(false);
- await reader.ReadAsync().ConfigureAwait(false);
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- localName = reader.LocalName;
- namespaceURI = reader.NamespaceURI;
-
- if (reader.IsEmptyElement)
- {
- await reader.ReadAsync().ConfigureAwait(false);
- }
- else
- {
- var result = new ControlRequestInfo(localName, namespaceURI);
- using var subReader = reader.ReadSubtree();
- await ParseFirstBodyChildAsync(subReader, result.Headers).ConfigureAwait(false);
- return result;
- }
- }
- else
- {
- await reader.ReadAsync().ConfigureAwait(false);
- }
- }
-
- if (localName is not null && namespaceURI is not 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)
- {
- await reader.MoveToContentAsync().ConfigureAwait(false);
- await reader.ReadAsync().ConfigureAwait(false);
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- // TODO: Should we be doing this here, or should it be handled earlier when decoding the request?
- headers[reader.LocalName.RemoveDiacritics()] = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);
- }
- else
- {
- await reader.ReadAsync().ConfigureAwait(false);
- }
- }
- }
-
- protected abstract void WriteResult(string methodName, IReadOnlyDictionary<string, string> methodParams, XmlWriter xmlWriter);
-
- private void LogRequest(ControlRequest request)
- {
- if (!Config.GetDlnaConfiguration().EnableDebugLog)
- {
- return;
- }
-
- Logger.LogDebug("Control request. Headers: {@Headers}", request.Headers);
- }
-
- private void LogResponse(ControlResponse response)
- {
- if (!Config.GetDlnaConfiguration().EnableDebugLog)
- {
- return;
- }
-
- Logger.LogDebug("Control response. Headers: {@Headers}\n{Xml}", response.Headers, response.Xml);
- }
-
- 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 NamespaceURI { get; set; }
-
- public Dictionary<string, string> Headers { get; }
- }
- }
-}
diff --git a/Emby.Dlna/Service/BaseService.cs b/Emby.Dlna/Service/BaseService.cs
deleted file mode 100644
index 67e7bf6a63..0000000000
--- a/Emby.Dlna/Service/BaseService.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-#nullable disable
-#pragma warning disable CS1591
-
-using System.Net.Http;
-using Emby.Dlna.Eventing;
-using Microsoft.Extensions.Logging;
-
-namespace Emby.Dlna.Service
-{
- public class BaseService : IDlnaEventManager
- {
- protected BaseService(ILogger<BaseService> logger, IHttpClientFactory httpClientFactory)
- {
- Logger = logger;
- EventManager = new DlnaEventManager(logger, httpClientFactory);
- }
-
- protected IDlnaEventManager EventManager { get; }
-
- protected ILogger Logger { get; }
-
- public EventSubscriptionResponse CancelEventSubscription(string subscriptionId)
- {
- return EventManager.CancelEventSubscription(subscriptionId);
- }
-
- public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string notificationType, string requestedTimeoutString, string callbackUrl)
- {
- return EventManager.RenewEventSubscription(subscriptionId, notificationType, requestedTimeoutString, callbackUrl);
- }
-
- public EventSubscriptionResponse CreateEventSubscription(string notificationType, string requestedTimeoutString, string callbackUrl)
- {
- return EventManager.CreateEventSubscription(notificationType, requestedTimeoutString, callbackUrl);
- }
- }
-}
diff --git a/Emby.Dlna/Service/ControlErrorHandler.cs b/Emby.Dlna/Service/ControlErrorHandler.cs
deleted file mode 100644
index 3e2cd6d2e4..0000000000
--- a/Emby.Dlna/Service/ControlErrorHandler.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma warning disable CS1591
-
-using System;
-using System.IO;
-using System.Text;
-using System.Xml;
-using Emby.Dlna.Didl;
-
-namespace Emby.Dlna.Service
-{
- public static class ControlErrorHandler
- {
- private const string NsSoapEnv = "http://schemas.xmlsoap.org/soap/envelope/";
-
- public static ControlResponse GetResponse(Exception ex)
- {
- var settings = new XmlWriterSettings
- {
- Encoding = Encoding.UTF8,
- CloseOutput = false
- };
-
- StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
-
- using (var writer = XmlWriter.Create(builder, settings))
- {
- writer.WriteStartDocument(true);
-
- writer.WriteStartElement("SOAP-ENV", "Envelope", NsSoapEnv);
- writer.WriteAttributeString(string.Empty, "encodingStyle", NsSoapEnv, "http://schemas.xmlsoap.org/soap/encoding/");
-
- writer.WriteStartElement("SOAP-ENV", "Body", NsSoapEnv);
- writer.WriteStartElement("SOAP-ENV", "Fault", NsSoapEnv);
-
- writer.WriteElementString("faultcode", "500");
- writer.WriteElementString("faultstring", ex.Message);
-
- writer.WriteStartElement("detail");
- writer.WriteRaw("<UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>401</errorCode><errorDescription>Invalid Action</errorDescription></UPnPError>");
- writer.WriteFullEndElement();
-
- writer.WriteFullEndElement();
- writer.WriteFullEndElement();
-
- writer.WriteFullEndElement();
- writer.WriteEndDocument();
- }
-
- return new ControlResponse(builder.ToString(), false);
- }
- }
-}
diff --git a/Emby.Dlna/Service/ServiceXmlBuilder.cs b/Emby.Dlna/Service/ServiceXmlBuilder.cs
deleted file mode 100644
index 6e0bc6ad8b..0000000000
--- a/Emby.Dlna/Service/ServiceXmlBuilder.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-#pragma warning disable CS1591
-
-using System.Collections.Generic;
-using System.Security;
-using System.Text;
-using Emby.Dlna.Common;
-
-namespace Emby.Dlna.Service
-{
- public class ServiceXmlBuilder
- {
- public string GetXml(IEnumerable<ServiceAction> actions, IEnumerable<StateVariable> stateVariables)
- {
- var builder = new StringBuilder();
-
- builder.Append("<?xml version=\"1.0\"?>");
- builder.Append("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">");
-
- builder.Append("<specVersion>");
- builder.Append("<major>1</major>");
- builder.Append("<minor>0</minor>");
- builder.Append("</specVersion>");
-
- AppendActionList(builder, actions);
- AppendServiceStateTable(builder, stateVariables);
-
- builder.Append("</scpd>");
-
- return builder.ToString();
- }
-
- private static void AppendActionList(StringBuilder builder, IEnumerable<ServiceAction> actions)
- {
- builder.Append("<actionList>");
-
- foreach (var item in actions)
- {
- builder.Append("<action>");
-
- builder.Append("<name>")
- .Append(SecurityElement.Escape(item.Name))
- .Append("</name>");
-
- builder.Append("<argumentList>");
-
- foreach (var argument in item.ArgumentList)
- {
- builder.Append("<argument>");
-
- builder.Append("<name>")
- .Append(SecurityElement.Escape(argument.Name))
- .Append("</name>");
- builder.Append("<direction>")
- .Append(SecurityElement.Escape(argument.Direction))
- .Append("</direction>");
- builder.Append("<relatedStateVariable>")
- .Append(SecurityElement.Escape(argument.RelatedStateVariable))
- .Append("</relatedStateVariable>");
-
- builder.Append("</argument>");
- }
-
- builder.Append("</argumentList>");
-
- builder.Append("</action>");
- }
-
- builder.Append("</actionList>");
- }
-
- private static void AppendServiceStateTable(StringBuilder builder, IEnumerable<StateVariable> stateVariables)
- {
- builder.Append("<serviceStateTable>");
-
- foreach (var item in stateVariables)
- {
- var sendEvents = item.SendsEvents ? "yes" : "no";
-
- builder.Append("<stateVariable sendEvents=\"")
- .Append(sendEvents)
- .Append("\">");
-
- builder.Append("<name>")
- .Append(SecurityElement.Escape(item.Name))
- .Append("</name>");
- builder.Append("<dataType>")
- .Append(SecurityElement.Escape(item.DataType))
- .Append("</dataType>");
-
- if (item.AllowedValues.Count > 0)
- {
- builder.Append("<allowedValueList>");
- foreach (var allowedValue in item.AllowedValues)
- {
- builder.Append("<allowedValue>")
- .Append(SecurityElement.Escape(allowedValue))
- .Append("</allowedValue>");
- }
-
- builder.Append("</allowedValueList>");
- }
-
- builder.Append("</stateVariable>");
- }
-
- builder.Append("</serviceStateTable>");
- }
- }
-}