The Free Software Media System - Server Backend & API
made dlna logging optional
Luke Pulverenti30496c11687e
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.csindex ca9214b548..ac9a51ea1a 100644--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs@@ -259,7 +259,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManagerthrow new HttpException(string.Format("Connection to {0} timed out", options.Url)) { IsTimedOut = true };}- _logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url);+ if (options.LogRequest)+ {+ _logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url);+ }try{@@ -456,7 +459,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManageroptions.Progress.Report(0);- _logger.Info("HttpClientManager.GetTempFileResponse url: {0}", options.Url);+ if (options.LogRequest)+ {+ _logger.Info("HttpClientManager.GetTempFileResponse url: {0}", options.Url);+ }try{diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.csindex 659d230cff..da0449ae79 100644--- a/MediaBrowser.Common/Net/HttpRequestOptions.cs+++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs@@ -72,6 +72,8 @@ namespace MediaBrowser.Common.Netpublic bool BufferContent { get; set; }+ public bool LogRequest { get; set; }+public HttpRequestCachePolicy CachePolicy { get; set; }private string GetHeaderValue(string name)@@ -94,6 +96,8 @@ namespace MediaBrowser.Common.NetCachePolicy = HttpRequestCachePolicy.None;RequestHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);++ LogRequest = true;}}diff --git a/MediaBrowser.Dlna/PlayTo/Device.cs b/MediaBrowser.Dlna/PlayTo/Device.csindex 802fdc31d2..4120c1a7f3 100644--- a/MediaBrowser.Dlna/PlayTo/Device.cs+++ b/MediaBrowser.Dlna/PlayTo/Device.cs@@ -1,4 +1,5 @@using MediaBrowser.Common.Net;+using MediaBrowser.Controller.Configuration;using MediaBrowser.Model.Logging;using System;using System.Collections.Generic;@@ -9,7 +10,7 @@ using System.Xml.Linq;namespace MediaBrowser.Dlna.PlayTo{- public sealed class Device : IDisposable+ public class Device : IDisposable{const string ServiceAvtransportId = "urn:upnp-org:serviceId:AVTransport";const string ServiceRenderingId = "urn:upnp-org:serviceId:RenderingControl";@@ -119,12 +120,14 @@ namespace MediaBrowser.Dlna.PlayToprivate readonly IHttpClient _httpClient;private readonly ILogger _logger;+ private readonly IServerConfigurationManager _config;- public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logger)+ public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logger, IServerConfigurationManager config){Properties = deviceProperties;_httpClient = httpClient;_logger = logger;+ _config = config;}private int GetPlaybackTimerIntervalMs()@@ -217,7 +220,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, value))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, value)).ConfigureAwait(false);Volume = value;return true;@@ -236,7 +239,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, String.Format("{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, String.Format("{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME")).ConfigureAwait(false);return value;@@ -266,7 +269,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, url, dictionary), header)+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, url, dictionary), header).ConfigureAwait(false);@@ -311,7 +314,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, value, dictionary), header)+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, value, dictionary), header).ConfigureAwait(false);await Task.Delay(100).ConfigureAwait(false);@@ -332,7 +335,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, 1))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, 1)).ConfigureAwait(false);_lapsCount = GetLapsCount();@@ -347,7 +350,7 @@ namespace MediaBrowser.Dlna.PlayTovar service = Properties.Services.FirstOrDefault(s => s.ServiceId == ServiceAvtransportId);- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, 1))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, 1)).ConfigureAwait(false);await Task.Delay(50).ConfigureAwait(false);return true;@@ -361,7 +364,7 @@ namespace MediaBrowser.Dlna.PlayTovar service = Properties.Services.FirstOrDefault(s => s.ServiceId == ServiceAvtransportId);- var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, 0))+ var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType, 0)).ConfigureAwait(false);await Task.Delay(50).ConfigureAwait(false);@@ -440,7 +443,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).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)).ConfigureAwait(false);if (result == null || result.Document == null)@@ -471,7 +474,7 @@ namespace MediaBrowser.Dlna.PlayToif (service == null)return;- var result = await new SsdpHttpClient(_httpClient).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)).ConfigureAwait(false);if (result == null || result.Document == null)@@ -501,7 +504,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).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)).ConfigureAwait(false);if (result == null || result.Document == null)@@ -542,7 +545,7 @@ namespace MediaBrowser.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- var result = await new SsdpHttpClient(_httpClient).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)).ConfigureAwait(false);if (result == null || result.Document == null)@@ -603,7 +606,7 @@ namespace MediaBrowser.Dlna.PlayToif (!url.StartsWith("/"))url = "/" + url;- var httpClient = new SsdpHttpClient(_httpClient);+ var httpClient = new SsdpHttpClient(_httpClient, _config);var document = await httpClient.GetDataAsync(new Uri(Properties.BaseUrl + url));AvCommands = TransportCommands.Create(document);@@ -621,7 +624,7 @@ namespace MediaBrowser.Dlna.PlayToif (!url.StartsWith("/"))url = "/" + url;- var httpClient = new SsdpHttpClient(_httpClient);+ var httpClient = new SsdpHttpClient(_httpClient, _config);var document = await httpClient.GetDataAsync(new Uri(Properties.BaseUrl + url));RendererCommands = TransportCommands.Create(document);@@ -639,9 +642,9 @@ namespace MediaBrowser.Dlna.PlayToset;}- public static async Task<Device> CreateuPnpDeviceAsync(Uri url, IHttpClient httpClient, ILogger logger)+ public static async Task<Device> CreateuPnpDeviceAsync(Uri url, IHttpClient httpClient, IServerConfigurationManager config, ILogger logger){- var ssdpHttpClient = new SsdpHttpClient(httpClient);+ var ssdpHttpClient = new SsdpHttpClient(httpClient, config);var document = await ssdpHttpClient.GetDataAsync(url).ConfigureAwait(false);@@ -719,7 +722,7 @@ namespace MediaBrowser.Dlna.PlayToif (isRenderer){- var device = new Device(deviceProperties, httpClient, logger);+ var device = new Device(deviceProperties, httpClient, logger, config);await device.GetRenderingProtocolAsync().ConfigureAwait(false);await device.GetAVProtocolAsync().ConfigureAwait(false);diff --git a/MediaBrowser.Dlna/PlayTo/PlayToManager.cs b/MediaBrowser.Dlna/PlayTo/PlayToManager.csindex eca3033a81..d1fdc9626d 100644--- a/MediaBrowser.Dlna/PlayTo/PlayToManager.cs+++ b/MediaBrowser.Dlna/PlayTo/PlayToManager.cs@@ -31,8 +31,9 @@ namespace MediaBrowser.Dlna.PlayToprivate readonly INetworkManager _networkManager;private readonly IUserManager _userManager;private readonly IDlnaManager _dlnaManager;+ private readonly IServerConfigurationManager _config;- public PlayToManager(ILogger logger,IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager)+ public PlayToManager(ILogger logger, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager){_locations = new ConcurrentDictionary<string, DateTime>();_tokenSource = new CancellationTokenSource();@@ -45,6 +46,7 @@ namespace MediaBrowser.Dlna.PlayTo_networkManager = networkManager;_userManager = userManager;_dlnaManager = dlnaManager;+ _config = config;}public async void Start()@@ -212,7 +214,7 @@ namespace MediaBrowser.Dlna.PlayToif (!IsUriValid(uri))return;- var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _logger).ConfigureAwait(false);+ var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _config, _logger).ConfigureAwait(false);if (device != null && device.RendererCommands != null && !_sessionManager.Sessions.Any(s => string.Equals(s.DeviceId, device.Properties.UUID) && s.IsActive)){@@ -229,7 +231,7 @@ namespace MediaBrowser.Dlna.PlayTo}controller.Init(device);-+_logger.Info("DLNA Session created for {0} - {1}", device.Properties.Name, device.Properties.ModelName);}}diff --git a/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs b/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.csindex bb03caf8e9..7a4928e5ca 100644--- a/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs+++ b/MediaBrowser.Dlna/PlayTo/SsdpHttpClient.cs@@ -1,4 +1,5 @@using MediaBrowser.Common.Net;+using MediaBrowser.Controller.Configuration;using System;using System.IO;using System.Net;@@ -16,10 +17,12 @@ namespace MediaBrowser.Dlna.PlayToprivate static readonly CookieContainer Container = new CookieContainer();private readonly IHttpClient _httpClient;+ private readonly IServerConfigurationManager _config;- public SsdpHttpClient(IHttpClient httpClient)+ public SsdpHttpClient(IHttpClient httpClient, IServerConfigurationManager config){_httpClient = httpClient;+ _config = config;}public async Task<XDocument> SendCommandAsync(string baseUrl, DeviceService service, string command, string postData, string header = null)@@ -45,7 +48,8 @@ namespace MediaBrowser.Dlna.PlayTovar options = new HttpRequestOptions{Url = url.ToString(),- UserAgent = USERAGENT+ UserAgent = USERAGENT,+ LogRequest = _config.Configuration.DlnaOptions.EnablePlayToDebugLogging};options.RequestHeaders["HOST"] = ip + ":" + port;@@ -83,7 +87,8 @@ namespace MediaBrowser.Dlna.PlayTovar options = new HttpRequestOptions{Url = url.ToString(),- UserAgent = USERAGENT+ UserAgent = USERAGENT,+ LogRequest = _config.Configuration.DlnaOptions.EnablePlayToDebugLogging};options.RequestHeaders["FriendlyName.DLNA.ORG"] = FriendlyName;@@ -106,7 +111,8 @@ namespace MediaBrowser.Dlna.PlayTovar options = new HttpRequestOptions{Url = url.ToString(),- UserAgent = USERAGENT+ UserAgent = USERAGENT,+ LogRequest = _config.Configuration.DlnaOptions.EnablePlayToDebugLogging};options.RequestHeaders["SOAPAction"] = soapAction;diff --git a/MediaBrowser.Model/Configuration/DlnaOptions.cs b/MediaBrowser.Model/Configuration/DlnaOptions.csindex e6c24fdfb6..67145e6644 100644--- a/MediaBrowser.Model/Configuration/DlnaOptions.cs+++ b/MediaBrowser.Model/Configuration/DlnaOptions.cs@@ -4,5 +4,6 @@ namespace MediaBrowser.Model.Configurationpublic class DlnaOptions{public bool EnablePlayTo { get; set; }+ public bool EnablePlayToDebugLogging { get; set; }}}