2020-01-22 21:00:07 +01:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2016-10-30 00:22:20 +02:00
|
|
|
using System.Collections.Generic;
|
2020-07-19 21:31:14 +02:00
|
|
|
using System.Security;
|
2016-10-30 00:22:20 +02:00
|
|
|
using System.Text;
|
2019-01-13 20:16:19 +01:00
|
|
|
using Emby.Dlna.Common;
|
2016-10-30 00:22:20 +02:00
|
|
|
|
2016-10-30 00:34:54 +02:00
|
|
|
namespace Emby.Dlna.Service
|
2016-10-30 00:22:20 +02:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-01-06 21:50:43 +01:00
|
|
|
private static void AppendActionList(StringBuilder builder, IEnumerable<ServiceAction> actions)
|
2016-10-30 00:22:20 +02:00
|
|
|
{
|
|
|
|
builder.Append("<actionList>");
|
|
|
|
|
|
|
|
foreach (var item in actions)
|
|
|
|
{
|
|
|
|
builder.Append("<action>");
|
|
|
|
|
2020-07-19 21:31:14 +02:00
|
|
|
builder.Append("<name>")
|
2021-12-15 18:25:36 +01:00
|
|
|
.Append(SecurityElement.Escape(item.Name))
|
2020-07-19 21:31:14 +02:00
|
|
|
.Append("</name>");
|
2016-10-30 00:22:20 +02:00
|
|
|
|
|
|
|
builder.Append("<argumentList>");
|
|
|
|
|
|
|
|
foreach (var argument in item.ArgumentList)
|
|
|
|
{
|
|
|
|
builder.Append("<argument>");
|
|
|
|
|
2020-07-19 21:31:14 +02:00
|
|
|
builder.Append("<name>")
|
2021-12-15 18:25:36 +01:00
|
|
|
.Append(SecurityElement.Escape(argument.Name))
|
2020-07-19 21:31:14 +02:00
|
|
|
.Append("</name>");
|
|
|
|
builder.Append("<direction>")
|
2021-12-15 18:25:36 +01:00
|
|
|
.Append(SecurityElement.Escape(argument.Direction))
|
2020-07-19 21:31:14 +02:00
|
|
|
.Append("</direction>");
|
|
|
|
builder.Append("<relatedStateVariable>")
|
2021-12-15 18:25:36 +01:00
|
|
|
.Append(SecurityElement.Escape(argument.RelatedStateVariable))
|
2020-07-19 21:31:14 +02:00
|
|
|
.Append("</relatedStateVariable>");
|
2016-10-30 00:22:20 +02:00
|
|
|
|
|
|
|
builder.Append("</argument>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</argumentList>");
|
|
|
|
|
|
|
|
builder.Append("</action>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</actionList>");
|
|
|
|
}
|
|
|
|
|
2019-01-06 21:50:43 +01:00
|
|
|
private static void AppendServiceStateTable(StringBuilder builder, IEnumerable<StateVariable> stateVariables)
|
2016-10-30 00:22:20 +02:00
|
|
|
{
|
|
|
|
builder.Append("<serviceStateTable>");
|
|
|
|
|
|
|
|
foreach (var item in stateVariables)
|
|
|
|
{
|
|
|
|
var sendEvents = item.SendsEvents ? "yes" : "no";
|
|
|
|
|
2020-07-19 21:31:14 +02:00
|
|
|
builder.Append("<stateVariable sendEvents=\"")
|
|
|
|
.Append(sendEvents)
|
|
|
|
.Append("\">");
|
2016-10-30 00:22:20 +02:00
|
|
|
|
2020-07-19 21:31:14 +02:00
|
|
|
builder.Append("<name>")
|
2021-12-15 18:25:36 +01:00
|
|
|
.Append(SecurityElement.Escape(item.Name))
|
2020-07-19 21:31:14 +02:00
|
|
|
.Append("</name>");
|
|
|
|
builder.Append("<dataType>")
|
2021-12-15 18:25:36 +01:00
|
|
|
.Append(SecurityElement.Escape(item.DataType))
|
2020-07-19 21:31:14 +02:00
|
|
|
.Append("</dataType>");
|
2016-10-30 00:22:20 +02:00
|
|
|
|
2020-08-20 21:04:57 +02:00
|
|
|
if (item.AllowedValues.Count > 0)
|
2016-10-30 00:22:20 +02:00
|
|
|
{
|
|
|
|
builder.Append("<allowedValueList>");
|
|
|
|
foreach (var allowedValue in item.AllowedValues)
|
|
|
|
{
|
2020-07-19 21:31:14 +02:00
|
|
|
builder.Append("<allowedValue>")
|
|
|
|
.Append(SecurityElement.Escape(allowedValue))
|
|
|
|
.Append("</allowedValue>");
|
2016-10-30 00:22:20 +02:00
|
|
|
}
|
2020-06-15 23:43:52 +02:00
|
|
|
|
2016-10-30 00:22:20 +02:00
|
|
|
builder.Append("</allowedValueList>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</stateVariable>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</serviceStateTable>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|