2016-10-30 00:22:20 +02:00
|
|
|
|
using MediaBrowser.Controller.Dlna;
|
|
|
|
|
using System;
|
2016-11-04 09:31:05 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
2016-10-30 00:22:20 +02:00
|
|
|
|
using System.Xml;
|
2016-11-04 09:31:05 +01:00
|
|
|
|
using Emby.Dlna.Didl;
|
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 ControlErrorHandler
|
|
|
|
|
{
|
|
|
|
|
private const string NS_SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/";
|
2019-01-08 00:27:46 +01:00
|
|
|
|
|
2016-10-30 00:22:20 +02:00
|
|
|
|
public ControlResponse GetResponse(Exception ex)
|
|
|
|
|
{
|
2016-11-04 09:31:05 +01:00
|
|
|
|
var settings = new XmlWriterSettings
|
|
|
|
|
{
|
|
|
|
|
Encoding = Encoding.UTF8,
|
|
|
|
|
CloseOutput = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(builder, settings))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteStartDocument(true);
|
|
|
|
|
|
|
|
|
|
writer.WriteStartElement("SOAP-ENV", "Envelope", NS_SOAPENV);
|
|
|
|
|
writer.WriteAttributeString(string.Empty, "encodingStyle", NS_SOAPENV, "http://schemas.xmlsoap.org/soap/encoding/");
|
|
|
|
|
|
|
|
|
|
writer.WriteStartElement("SOAP-ENV", "Body", NS_SOAPENV);
|
|
|
|
|
writer.WriteStartElement("SOAP-ENV", "Fault", NS_SOAPENV);
|
|
|
|
|
|
|
|
|
|
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>");
|
2016-11-06 18:30:44 +01:00
|
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 09:31:05 +01:00
|
|
|
|
|
2016-11-06 18:30:44 +01:00
|
|
|
|
writer.WriteFullEndElement();
|
|
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 09:31:05 +01:00
|
|
|
|
|
2016-11-06 18:30:44 +01:00
|
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 09:31:05 +01:00
|
|
|
|
writer.WriteEndDocument();
|
|
|
|
|
}
|
2016-10-30 00:22:20 +02:00
|
|
|
|
|
|
|
|
|
return new ControlResponse
|
|
|
|
|
{
|
2016-11-04 09:31:05 +01:00
|
|
|
|
Xml = builder.ToString(),
|
2016-10-30 00:22:20 +02:00
|
|
|
|
IsSuccessful = false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|