From 7060934792d463840a616499ab869d4285582608 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 6 Feb 2020 15:20:23 +0100 Subject: Fix some warnings in Emby.Server.Implementations --- Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/HttpClientManager') diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index 8a2bc83fb..45fa03cdd 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.HttpClientManager if (!string.IsNullOrWhiteSpace(userInfo)) { _logger.LogWarning("Found userInfo in url: {0} ... url: {1}", userInfo, url); - url = url.Replace(userInfo + '@', string.Empty); + url = url.Replace(userInfo + '@', string.Empty, StringComparison.Ordinal); } var request = new HttpRequestMessage(method, url); -- cgit v1.2.3 From 2be394089ea5b90873931b6c8d95be69b1d9a543 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 2 Apr 2020 17:00:28 +0200 Subject: Enable Microsoft.CodeAnalysis.FxCopAnalyzers for Jellyfin.Common --- .../HttpClientManager/HttpClientManager.cs | 15 ++++------ .../LiveTv/EmbyTV/DirectRecorder.cs | 2 +- .../LiveTv/Listings/SchedulesDirect.cs | 4 +-- .../LiveTv/Listings/XmlTvListingsProvider.cs | 2 +- .../LiveTv/TunerHosts/SharedHttpStream.cs | 2 +- .../Cryptography/CryptoExtensions.cs | 35 ++++++++++++++++++++++ MediaBrowser.Common/Cryptography/Extensions.cs | 35 ---------------------- MediaBrowser.Common/MediaBrowser.Common.csproj | 2 +- MediaBrowser.Common/Net/HttpRequestOptions.cs | 8 ++--- MediaBrowser.Common/Net/HttpResponseInfo.cs | 2 +- 10 files changed, 50 insertions(+), 57 deletions(-) create mode 100644 MediaBrowser.Common/Cryptography/CryptoExtensions.cs delete mode 100644 MediaBrowser.Common/Cryptography/Extensions.cs (limited to 'Emby.Server.Implementations/HttpClientManager') diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index 45fa03cdd..882bfe2f6 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -96,13 +96,13 @@ namespace Emby.Server.Implementations.HttpClientManager switch (options.DecompressionMethod) { - case CompressionMethod.Deflate | CompressionMethod.Gzip: + case CompressionMethods.Deflate | CompressionMethods.Gzip: request.Headers.Add(HeaderNames.AcceptEncoding, new[] { "gzip", "deflate" }); break; - case CompressionMethod.Deflate: + case CompressionMethods.Deflate: request.Headers.Add(HeaderNames.AcceptEncoding, "deflate"); break; - case CompressionMethod.Gzip: + case CompressionMethods.Gzip: request.Headers.Add(HeaderNames.AcceptEncoding, "gzip"); break; default: @@ -239,15 +239,10 @@ namespace Emby.Server.Implementations.HttpClientManager var httpWebRequest = GetRequestMessage(options, httpMethod); - if (options.RequestContentBytes != null - || !string.IsNullOrEmpty(options.RequestContent) + if (!string.IsNullOrEmpty(options.RequestContent) || httpMethod == HttpMethod.Post) { - if (options.RequestContentBytes != null) - { - httpWebRequest.Content = new ByteArrayContent(options.RequestContentBytes); - } - else if (options.RequestContent != null) + if (options.RequestContent != null) { httpWebRequest.Content = new StringContent( options.RequestContent, diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/DirectRecorder.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/DirectRecorder.cs index e2bff97c8..2e13a3bb3 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/DirectRecorder.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/DirectRecorder.cs @@ -72,7 +72,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV UserAgent = "Emby/3.0", // Shouldn't matter but may cause issues - DecompressionMethod = CompressionMethod.None + DecompressionMethod = CompressionMethods.None }; using (var response = await _httpClient.SendAsync(httpRequestOptions, HttpMethod.Get).ConfigureAwait(false)) diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index 00f469d83..89b81fd96 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -635,7 +635,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings ListingsProviderInfo providerInfo) { // Schedules direct requires that the client support compression and will return a 400 response without it - options.DecompressionMethod = CompressionMethod.Deflate; + options.DecompressionMethod = CompressionMethods.Deflate; try { @@ -665,7 +665,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings ListingsProviderInfo providerInfo) { // Schedules direct requires that the client support compression and will return a 400 response without it - options.DecompressionMethod = CompressionMethod.Deflate; + options.DecompressionMethod = CompressionMethods.Deflate; try { diff --git a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 609b397da..07f8539c5 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -83,7 +83,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings { CancellationToken = cancellationToken, Url = path, - DecompressionMethod = CompressionMethod.Gzip, + DecompressionMethod = CompressionMethods.Gzip, }, HttpMethod.Get).ConfigureAwait(false)) using (var stream = res.Content) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs index 9ced65cca..d63588bbd 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs @@ -59,7 +59,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts Url = url, CancellationToken = CancellationToken.None, BufferContent = false, - DecompressionMethod = CompressionMethod.None + DecompressionMethod = CompressionMethods.None }; foreach (var header in mediaSource.RequiredHttpHeaders) diff --git a/MediaBrowser.Common/Cryptography/CryptoExtensions.cs b/MediaBrowser.Common/Cryptography/CryptoExtensions.cs new file mode 100644 index 000000000..157b0ed10 --- /dev/null +++ b/MediaBrowser.Common/Cryptography/CryptoExtensions.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using MediaBrowser.Model.Cryptography; +using static MediaBrowser.Common.Cryptography.Constants; + +namespace MediaBrowser.Common.Cryptography +{ + /// + /// Class containing extension methods for working with Jellyfin cryptography objects. + /// + public static class CryptoExtensions + { + /// + /// Creates a new instance. + /// + /// The instance used. + /// The password that will be hashed. + /// A instance with the hash method, hash, salt and number of iterations. + public static PasswordHash CreatePasswordHash(this ICryptoProvider cryptoProvider, string password) + { + byte[] salt = cryptoProvider.GenerateSalt(); + return new PasswordHash( + cryptoProvider.DefaultHashMethod, + cryptoProvider.ComputeHashWithDefaultMethod( + Encoding.UTF8.GetBytes(password), + salt), + salt, + new Dictionary + { + { "iterations", DefaultIterations.ToString(CultureInfo.InvariantCulture) } + }); + } + } +} diff --git a/MediaBrowser.Common/Cryptography/Extensions.cs b/MediaBrowser.Common/Cryptography/Extensions.cs deleted file mode 100644 index 1e32a6d1a..000000000 --- a/MediaBrowser.Common/Cryptography/Extensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using MediaBrowser.Model.Cryptography; -using static MediaBrowser.Common.Cryptography.Constants; - -namespace MediaBrowser.Common.Cryptography -{ - /// - /// Class containing extension methods for working with Jellyfin cryptography objects. - /// - public static class Extensions - { - /// - /// Creates a new instance. - /// - /// The instance used. - /// The password that will be hashed. - /// A instance with the hash method, hash, salt and number of iterations. - public static PasswordHash CreatePasswordHash(this ICryptoProvider cryptoProvider, string password) - { - byte[] salt = cryptoProvider.GenerateSalt(); - return new PasswordHash( - cryptoProvider.DefaultHashMethod, - cryptoProvider.ComputeHashWithDefaultMethod( - Encoding.UTF8.GetBytes(password), - salt), - salt, - new Dictionary - { - { "iterations", DefaultIterations.ToString(CultureInfo.InvariantCulture) } - }); - } - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 548c214dd..3b0347802 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -30,7 +30,7 @@ - + diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.cs index 51962001e..38274a80e 100644 --- a/MediaBrowser.Common/Net/HttpRequestOptions.cs +++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs @@ -20,7 +20,7 @@ namespace MediaBrowser.Common.Net RequestHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); CacheMode = CacheMode.None; - DecompressionMethod = CompressionMethod.Deflate; + DecompressionMethod = CompressionMethods.Deflate; } /// @@ -29,7 +29,7 @@ namespace MediaBrowser.Common.Net /// The URL. public string Url { get; set; } - public CompressionMethod DecompressionMethod { get; set; } + public CompressionMethods DecompressionMethod { get; set; } /// /// Gets or sets the accept header. @@ -83,8 +83,6 @@ namespace MediaBrowser.Common.Net public string RequestContent { get; set; } - public byte[] RequestContentBytes { get; set; } - public bool BufferContent { get; set; } public bool LogErrorResponseBody { get; set; } @@ -112,7 +110,7 @@ namespace MediaBrowser.Common.Net } [Flags] - public enum CompressionMethod + public enum CompressionMethods { None = 0b00000001, Deflate = 0b00000010, diff --git a/MediaBrowser.Common/Net/HttpResponseInfo.cs b/MediaBrowser.Common/Net/HttpResponseInfo.cs index 56a951ebf..d4fee6c78 100644 --- a/MediaBrowser.Common/Net/HttpResponseInfo.cs +++ b/MediaBrowser.Common/Net/HttpResponseInfo.cs @@ -8,7 +8,7 @@ namespace MediaBrowser.Common.Net /// /// Class HttpResponseInfo. /// - public class HttpResponseInfo : IDisposable + public sealed class HttpResponseInfo : IDisposable { #pragma warning disable CS1591 public HttpResponseInfo() -- cgit v1.2.3