Esempio n. 1
0
        private void LogResponse(ControlResponse response)
        {
            if (!DlnaServerManager.Configuration.EnableDebugLog)
            {
                return;
            }

            Logger.LogInformation("Control response. Headers: {Headers:l}\n{Xml}", response.Headers, WebUtility.HtmlDecode(response.Xml));
        }
Esempio n. 2
0
        private async Task <ControlResponse> ProcessControlRequestInternalAsync(ControlRequest request)
        {
            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);
            var requestInfo = await ParseRequestAsync(reader).ConfigureAwait(false);

            Logger.LogDebug("Received control request {Name}", requestInfo.LocalName);

            var settings = new XmlWriterSettings
            {
                Encoding        = Encoding.UTF8,
                CloseOutput     = false,
                CheckCharacters = false
            };

            var builder = new Utf8StringWriter();

            using var writer = XmlWriter.Create(builder, settings);
            writer.WriteStartDocument(true);
            writer.WriteStartElement("s", "Envelope", NsSoapEnv);
            writer.WriteAttributeString(string.Empty, "encodingStyle", NsSoapEnv, "http://schemas.xmlsoap.org/soap/encoding/");
            writer.WriteStartElement("s", "Body", NsSoapEnv);
            writer.WriteStartElement("u", requestInfo.LocalName + "Response", requestInfo.NamespaceUri);
            WriteResult(requestInfo.LocalName, requestInfo.Headers, writer);
            writer.WriteFullEndElement();
            writer.WriteFullEndElement();
            writer.WriteFullEndElement();
            writer.WriteEndDocument();
            writer.Flush();

            var xml = builder.ToString().Replace("xmlns:m=", "xmlns:u=", StringComparison.Ordinal);

            var controlResponse = new ControlResponse(xml);

            controlResponse.Headers.Add("EXT", string.Empty);

            return(controlResponse);
        }