aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
authorcrobibero <cody@robibe.ro>2020-07-21 08:03:09 -0600
committercrobibero <cody@robibe.ro>2020-07-21 08:03:09 -0600
commitb040d89e5cda3d49ecb45e5441053dc61872f272 (patch)
tree81455a2f97d10c06c20a491a5c46e75fbac1fb47 /MediaBrowser.Common
parent0740ec611211cb121a2ea4f97ab43b92d6411d4d (diff)
parent5b57c81ee14ce585161b9ac331e6e3528826b815 (diff)
Merge remote-tracking branch 'upstream/api-migration' into api-image-service
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs56
-rw-r--r--MediaBrowser.Common/Json/JsonDefaults.cs1
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj4
-rw-r--r--MediaBrowser.Common/Net/INetworkManager.cs49
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs10
-rw-r--r--MediaBrowser.Common/Plugins/IPlugin.cs5
-rw-r--r--MediaBrowser.Common/Updates/IInstallationManager.cs9
7 files changed, 128 insertions, 6 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs b/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs
new file mode 100644
index 000000000..d18fd95d5
--- /dev/null
+++ b/MediaBrowser.Common/Json/Converters/JsonInt64Converter.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Buffers;
+using System.Buffers.Text;
+using System.Globalization;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace MediaBrowser.Common.Json.Converters
+{
+ /// <summary>
+ /// Long to String JSON converter.
+ /// Javascript does not support 64-bit integers.
+ /// </summary>
+ public class JsonInt64Converter : JsonConverter<long>
+ {
+ /// <summary>
+ /// Read JSON string as int64.
+ /// </summary>
+ /// <param name="reader"><see cref="Utf8JsonReader"/>.</param>
+ /// <param name="type">Type.</param>
+ /// <param name="options">Options.</param>
+ /// <returns>Parsed value.</returns>
+ public override long Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
+ {
+ if (reader.TokenType == JsonTokenType.String)
+ {
+ // try to parse number directly from bytes
+ var span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
+ if (Utf8Parser.TryParse(span, out long number, out var bytesConsumed) && span.Length == bytesConsumed)
+ {
+ return number;
+ }
+
+ // try to parse from a string if the above failed, this covers cases with other escaped/UTF characters
+ if (long.TryParse(reader.GetString(), out number))
+ {
+ return number;
+ }
+ }
+
+ // fallback to default handling
+ return reader.GetInt64();
+ }
+
+ /// <summary>
+ /// Write long to JSON string.
+ /// </summary>
+ /// <param name="writer"><see cref="Utf8JsonWriter"/>.</param>
+ /// <param name="value">Value to write.</param>
+ /// <param name="options">Options.</param>
+ public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.ToString(NumberFormatInfo.InvariantInfo));
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs
index ec3c45476..13f2f060b 100644
--- a/MediaBrowser.Common/Json/JsonDefaults.cs
+++ b/MediaBrowser.Common/Json/JsonDefaults.cs
@@ -31,6 +31,7 @@ namespace MediaBrowser.Common.Json
options.Converters.Add(new JsonInt32Converter());
options.Converters.Add(new JsonStringEnumConverter());
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
+ options.Converters.Add(new JsonInt64Converter());
return options;
}
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index c9ca153c7..7380f39fd 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -17,8 +17,8 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.5" />
- <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.6" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
</ItemGroup>
diff --git a/MediaBrowser.Common/Net/INetworkManager.cs b/MediaBrowser.Common/Net/INetworkManager.cs
index 3ba75abd8..a0330afef 100644
--- a/MediaBrowser.Common/Net/INetworkManager.cs
+++ b/MediaBrowser.Common/Net/INetworkManager.cs
@@ -11,14 +11,21 @@ namespace MediaBrowser.Common.Net
{
event EventHandler NetworkChanged;
+ /// <summary>
+ /// Gets or sets a function to return the list of user defined LAN addresses.
+ /// </summary>
Func<string[]> LocalSubnetsFn { get; set; }
/// <summary>
- /// Gets a random port number that is currently available.
+ /// Gets a random port TCP number that is currently available.
/// </summary>
/// <returns>System.Int32.</returns>
int GetRandomUnusedTcpPort();
+ /// <summary>
+ /// Gets a random port UDP number that is currently available.
+ /// </summary>
+ /// <returns>System.Int32.</returns>
int GetRandomUnusedUdpPort();
/// <summary>
@@ -35,18 +42,56 @@ namespace MediaBrowser.Common.Net
bool IsInPrivateAddressSpace(string endpoint);
/// <summary>
+ /// Determines whether [is in private address space 10.x.x.x] [the specified endpoint] and exists in the subnets returned by GetSubnets().
+ /// </summary>
+ /// <param name="endpoint">The endpoint.</param>
+ /// <returns><c>true</c> if [is in private address space 10.x.x.x] [the specified endpoint]; otherwise, <c>false</c>.</returns>
+ bool IsInPrivateAddressSpaceAndLocalSubnet(string endpoint);
+
+ /// <summary>
/// Determines whether [is in local network] [the specified endpoint].
/// </summary>
/// <param name="endpoint">The endpoint.</param>
/// <returns><c>true</c> if [is in local network] [the specified endpoint]; otherwise, <c>false</c>.</returns>
bool IsInLocalNetwork(string endpoint);
- IPAddress[] GetLocalIpAddresses(bool ignoreVirtualInterface);
+ /// <summary>
+ /// Investigates an caches a list of interface addresses, excluding local link and LAN excluded addresses.
+ /// </summary>
+ /// <returns>The list of ipaddresses.</returns>
+ IPAddress[] GetLocalIpAddresses();
+ /// <summary>
+ /// Checks if the given address falls within the ranges given in [subnets]. The addresses in subnets can be hosts or subnets in the CIDR format.
+ /// </summary>
+ /// <param name="addressString">The address to check.</param>
+ /// <param name="subnets">If true, check against addresses in the LAN settings surrounded by brackets ([]).</param>
+ /// <returns><c>true</c>if the address is in at least one of the given subnets, <c>false</c> otherwise.</returns>
bool IsAddressInSubnets(string addressString, string[] subnets);
+ /// <summary>
+ /// Returns true if address is in the LAN list in the config file.
+ /// </summary>
+ /// <param name="address">The address to check.</param>
+ /// <param name="excludeInterfaces">If true, check against addresses in the LAN settings which have [] arroud and return true if it matches the address give in address.</param>
+ /// <param name="excludeRFC">If true, returns false if address is in the 127.x.x.x or 169.128.x.x range.</param>
+ /// <returns><c>false</c>if the address isn't in the LAN list, <c>true</c> if the address has been defined as a LAN address.</returns>
+ bool IsAddressInSubnets(IPAddress address, bool excludeInterfaces, bool excludeRFC);
+
+ /// <summary>
+ /// Checks if address is in the LAN list in the config file.
+ /// </summary>
+ /// <param name="address1">Source address to check.</param>
+ /// <param name="address2">Destination address to check against.</param>
+ /// <param name="subnetMask">Destination subnet to check against.</param>
+ /// <returns><c>true/false</c>depending on whether address1 is in the same subnet as IPAddress2 with subnetMask.</returns>
bool IsInSameSubnet(IPAddress address1, IPAddress address2, IPAddress subnetMask);
+ /// <summary>
+ /// Returns the subnet mask of an interface with the given address.
+ /// </summary>
+ /// <param name="address">The address to check.</param>
+ /// <returns>Returns the subnet mask of an interface with the given address, or null if an interface match cannot be found.</returns>
IPAddress GetLocalIpSubnetMask(IPAddress address);
}
}
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index 9e4a360c3..f10a1918f 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -2,6 +2,7 @@
using System;
using System.IO;
+using System.Reflection;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
@@ -50,6 +51,12 @@ namespace MediaBrowser.Common.Plugins
public string DataFolderPath { get; private set; }
/// <summary>
+ /// Gets a value indicating whether the plugin can be uninstalled.
+ /// </summary>
+ public bool CanUninstall => !Path.GetDirectoryName(AssemblyFilePath)
+ .Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.InvariantCulture);
+
+ /// <summary>
/// Gets the plugin info.
/// </summary>
/// <returns>PluginInfo.</returns>
@@ -60,7 +67,8 @@ namespace MediaBrowser.Common.Plugins
Name = Name,
Version = Version.ToString(),
Description = Description,
- Id = Id.ToString()
+ Id = Id.ToString(),
+ CanUninstall = CanUninstall
};
return info;
diff --git a/MediaBrowser.Common/Plugins/IPlugin.cs b/MediaBrowser.Common/Plugins/IPlugin.cs
index d34820961..7bd37d210 100644
--- a/MediaBrowser.Common/Plugins/IPlugin.cs
+++ b/MediaBrowser.Common/Plugins/IPlugin.cs
@@ -41,6 +41,11 @@ namespace MediaBrowser.Common.Plugins
string AssemblyFilePath { get; }
/// <summary>
+ /// Gets a value indicating whether the plugin can be uninstalled.
+ /// </summary>
+ bool CanUninstall { get; }
+
+ /// <summary>
/// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed.
/// </summary>
/// <value>The data folder path.</value>
diff --git a/MediaBrowser.Common/Updates/IInstallationManager.cs b/MediaBrowser.Common/Updates/IInstallationManager.cs
index 965ffe0ec..4b4030bc2 100644
--- a/MediaBrowser.Common/Updates/IInstallationManager.cs
+++ b/MediaBrowser.Common/Updates/IInstallationManager.cs
@@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Plugins;
-using MediaBrowser.Model.Events;
using MediaBrowser.Model.Updates;
namespace MediaBrowser.Common.Updates
@@ -41,6 +40,14 @@ namespace MediaBrowser.Common.Updates
IEnumerable<InstallationInfo> CompletedInstallations { get; }
/// <summary>
+ /// Parses a plugin manifest at the supplied URL.
+ /// </summary>
+ /// <param name="manifest">The URL to query.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task{IReadOnlyList{PackageInfo}}.</returns>
+ Task<IReadOnlyList<PackageInfo>> GetPackages(string manifest, CancellationToken cancellationToken = default);
+
+ /// <summary>
/// Gets all available packages.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>