The Free Software Media System - Server Backend & API
adjust dlna logging
Luke Pulverenti8ae0822e13ff
diff --git a/MediaBrowser.Dlna/PlayTo/Device.cs b/MediaBrowser.Dlna/PlayTo/Device.csindex 00cb34be3e..d0a46e771d 100644--- a/MediaBrowser.Dlna/PlayTo/Device.cs+++ b/MediaBrowser.Dlna/PlayTo/Device.cs@@ -296,7 +296,7 @@ namespace MediaBrowser.Dlna.PlayTo}var post = AvCommands.BuildPost(command, service.ServiceType, url, dictionary);- await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, post, header)+ await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, post, header: header).ConfigureAwait(false);await Task.Delay(50).ConfigureAwait(false);@@ -466,7 +466,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType), false).ConfigureAwait(false);if (result == null || result.Document == null)@@ -499,7 +499,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType), false).ConfigureAwait(false);if (result == null || result.Document == null)@@ -521,7 +521,7 @@ namespace MediaBrowser.Dlna.PlayToif (service == null)return null;- var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType), false).ConfigureAwait(false);if (result == null || result.Document == null)@@ -558,7 +558,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType), false).ConfigureAwait(false);if (result == null || result.Document == null)@@ -589,7 +589,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType), false).ConfigureAwait(false);if (result == null || result.Document == null)diff --git a/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs b/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.csindex f0689751c5..39d3a8d075 100644--- a/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs+++ b/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs@@ -1,7 +1,7 @@-using System;-using MediaBrowser.Common.Net;+using MediaBrowser.Common.Net;using MediaBrowser.Controller.Configuration;using MediaBrowser.Dlna.Common;+using System;using System.Globalization;using System.IO;using System.Text;@@ -28,9 +28,10 @@ namespace MediaBrowser.Dlna.PlayToDeviceService service,string command,string postData,+ bool logRequest = true,string header = null){- var response = await PostSoapDataAsync(NormalizeServiceUrl(baseUrl, service.ControlUrl), "\"" + service.ServiceType + "#" + command + "\"", postData, header)+ var response = await PostSoapDataAsync(NormalizeServiceUrl(baseUrl, service.ControlUrl), "\"" + service.ServiceType + "#" + command + "\"", postData, header, logRequest).ConfigureAwait(false);using (var stream = response.Content)@@ -69,7 +70,6 @@ namespace MediaBrowser.Dlna.PlayTo{Url = url,UserAgent = USERAGENT,- LogRequest = _config.GetDlnaConfiguration().EnableDebugLogging,LogErrorResponseBody = true};@@ -87,7 +87,6 @@ namespace MediaBrowser.Dlna.PlayTo{Url = url,UserAgent = USERAGENT,- LogRequest = _config.GetDlnaConfiguration().EnableDebugLogging,LogErrorResponseBody = true};@@ -105,7 +104,8 @@ namespace MediaBrowser.Dlna.PlayToprivate Task<HttpResponseInfo> PostSoapDataAsync(string url,string soapAction,string postData,- string header = null)+ string header,+ bool logRequest){if (!soapAction.StartsWith("\""))soapAction = "\"" + soapAction + "\"";@@ -114,7 +114,7 @@ namespace MediaBrowser.Dlna.PlayTo{Url = url,UserAgent = USERAGENT,- LogRequest = _config.GetDlnaConfiguration().EnableDebugLogging,+ LogRequest = logRequest || _config.GetDlnaConfiguration().EnableDebugLogging,LogErrorResponseBody = true};diff --git a/MediaBrowser.Dlna/Service/BaseControlHandler.cs b/MediaBrowser.Dlna/Service/BaseControlHandler.csindex a17182a7e0..a65520d65b 100644--- a/MediaBrowser.Dlna/Service/BaseControlHandler.cs+++ b/MediaBrowser.Dlna/Service/BaseControlHandler.cs@@ -27,14 +27,16 @@ namespace MediaBrowser.Dlna.Service{try{- if (Config.GetDlnaConfiguration().EnableDebugLogging)+ var enableDebugLogging = Config.GetDlnaConfiguration().EnableDebugLogging;++ if (enableDebugLogging){LogRequest(request);}var response = ProcessControlRequestInternal(request);- if (Config.GetDlnaConfiguration().EnableDebugLogging)+ if (enableDebugLogging){LogResponse(response);}diff --git a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs b/MediaBrowser.Dlna/Ssdp/SsdpHandler.csindex 5b3746aeb4..e21074bd40 100644--- a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs+++ b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs@@ -212,7 +212,9 @@ namespace MediaBrowser.Dlna.Ssdpprivate void RespondToSearch(EndPoint endpoint, string deviceType){- if (_config.GetDlnaConfiguration().EnableDebugLogging)+ var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLogging;++ if (enableDebugLogging){_logger.Debug("RespondToSearch");}@@ -238,7 +240,7 @@ namespace MediaBrowser.Dlna.SsdpSendDatagram(header, values, endpoint, new IPEndPoint(d.Address, 0), true, 1);//SendDatagram(header, values, endpoint, null, true);- if (_config.GetDlnaConfiguration().EnableDebugLogging)+ if (enableDebugLogging){_logger.Debug("{1} - Responded to a {0} request to {2}", d.Type, endpoint, d.Address.ToString());}@@ -316,7 +318,9 @@ namespace MediaBrowser.Dlna.Ssdpvar received = (byte[])result.AsyncState;- if (_config.GetDlnaConfiguration().EnableDebugLogging)+ var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLogging;++ if (enableDebugLogging){_logger.Debug(Encoding.ASCII.GetString(received));}@@ -324,7 +328,7 @@ namespace MediaBrowser.Dlna.Ssdpvar args = SsdpHelper.ParseSsdpResponse(received);args.EndPoint = endpoint;- if (_config.GetDlnaConfiguration().EnableDebugLogging)+ if (enableDebugLogging){var headerTexts = args.Headers.Select(i => string.Format("{0}={1}", i.Key, i.Value));var headerText = string.Join(",", headerTexts.ToArray());@@ -399,17 +403,19 @@ namespace MediaBrowser.Dlna.Ssdpprivate void NotifyAll(){- if (_config.GetDlnaConfiguration().EnableDebugLogging)+ var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLogging;++ if (enableDebugLogging){_logger.Debug("Sending alive notifications");}foreach (var d in RegisteredDevices){- NotifyDevice(d, "alive", 1);+ NotifyDevice(d, "alive", 1, enableDebugLogging);}}- private void NotifyDevice(UpnpDevice dev, string type, int sendCount)+ private void NotifyDevice(UpnpDevice dev, string type, int sendCount, bool logMessage){const string header = "NOTIFY * HTTP/1.1";@@ -424,7 +430,7 @@ namespace MediaBrowser.Dlna.Ssdpvalues["NT"] = dev.Type;values["USN"] = dev.USN;- if (_config.GetDlnaConfiguration().EnableDebugLogging)+ if (logMessage){_logger.Debug("{0} said {1}", dev.USN, type);}@@ -457,7 +463,7 @@ namespace MediaBrowser.Dlna.Ssdpforeach (var d in dl.ToList()){- NotifyDevice(d, "byebye", 2);+ NotifyDevice(d, "byebye", 2, true);}_logger.Debug("Unregistered mount {0}", uuid);@@ -468,13 +474,15 @@ namespace MediaBrowser.Dlna.Ssdpprivate int _aliveNotifierIntervalMs;private void ReloadAliveNotifier(){- if (!_config.GetDlnaConfiguration().BlastAliveMessages)+ var config = _config.GetDlnaConfiguration();++ if (!config.BlastAliveMessages){DisposeNotificationTimer();return;}- var intervalMs = _config.GetDlnaConfiguration().BlastAliveMessageIntervalSeconds * 1000;+ var intervalMs = config.BlastAliveMessageIntervalSeconds * 1000;if (_notificationTimer == null || _aliveNotifierIntervalMs != intervalMs){