< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.PreStartupRoutines.MigrateNetworkConfiguration
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 63
Coverable lines: 63
Total lines: 209
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/62) Branch coverage: 0% (0/10) Total lines: 20511/13/2026 - 12:19:51 AM Line coverage: 0% (0/63) Branch coverage: 0% (0/10) Total lines: 209 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/62) Branch coverage: 0% (0/10) Total lines: 20511/13/2026 - 12:19:51 AM Line coverage: 0% (0/63) Branch coverage: 0% (0/10) Total lines: 209

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
PerformAsync(...)0%2040%
.ctor()100%210%
get_BaseUrl()100%210%
set_BaseUrl(...)0%4260%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs

#LineLine coverage
 1#pragma warning disable CS0618 // obsolete
 2
 3using System;
 4using System.IO;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using System.Xml;
 8using System.Xml.Serialization;
 9using Emby.Server.Implementations;
 10using MediaBrowser.Common.Net;
 11using Microsoft.Extensions.Logging;
 12
 13namespace Jellyfin.Server.Migrations.PreStartupRoutines;
 14
 15/// <inheritdoc />
 16[JellyfinMigration("2025-04-20T01:00:00", nameof(MigrateNetworkConfiguration), "4FB5C950-1991-11EE-9B4B-0800200C9A66", S
 17public class MigrateNetworkConfiguration : IAsyncMigrationRoutine
 18{
 19    private readonly ServerApplicationPaths _applicationPaths;
 20    private readonly ILogger<MigrateNetworkConfiguration> _logger;
 21
 22    /// <summary>
 23    /// Initializes a new instance of the <see cref="MigrateNetworkConfiguration"/> class.
 24    /// </summary>
 25    /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
 26    /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
 27    public MigrateNetworkConfiguration(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
 28    {
 029        _applicationPaths = applicationPaths;
 030        _logger = loggerFactory.CreateLogger<MigrateNetworkConfiguration>();
 031    }
 32
 33    /// <inheritdoc />
 34    public Task PerformAsync(CancellationToken cancellationToken)
 35    {
 036        string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "network.xml");
 037        var oldNetworkConfigSerializer = new XmlSerializer(typeof(OldNetworkConfiguration), new XmlRootAttribute("Networ
 038        OldNetworkConfiguration? oldNetworkConfiguration = null;
 39
 40        try
 41        {
 042            using var xmlReader = XmlReader.Create(path);
 043            oldNetworkConfiguration = (OldNetworkConfiguration?)oldNetworkConfigSerializer.Deserialize(xmlReader);
 044        }
 045        catch (InvalidOperationException ex)
 46        {
 047            _logger.LogError(ex, "Migrate NetworkConfiguration deserialize Invalid Operation error");
 048        }
 049        catch (Exception ex)
 50        {
 051            _logger.LogError(ex, "Migrate NetworkConfiguration deserialize error");
 052        }
 53
 054        if (oldNetworkConfiguration is null)
 55        {
 056            return Task.CompletedTask;
 57        }
 58
 59        // Migrate network config values to new config schema
 060        var networkConfiguration = new NetworkConfiguration
 061        {
 062            AutoDiscovery = oldNetworkConfiguration.AutoDiscovery,
 063            BaseUrl = oldNetworkConfiguration.BaseUrl,
 064            CertificatePassword = oldNetworkConfiguration.CertificatePassword,
 065            CertificatePath = oldNetworkConfiguration.CertificatePath,
 066            EnableHttps = oldNetworkConfiguration.EnableHttps,
 067            EnableIPv4 = oldNetworkConfiguration.EnableIPV4,
 068            EnableIPv6 = oldNetworkConfiguration.EnableIPV6,
 069            EnablePublishedServerUriByRequest = oldNetworkConfiguration.EnablePublishedServerUriByRequest,
 070            EnableRemoteAccess = oldNetworkConfiguration.EnableRemoteAccess,
 071            EnableUPnP = oldNetworkConfiguration.EnableUPnP,
 072            IgnoreVirtualInterfaces = oldNetworkConfiguration.IgnoreVirtualInterfaces,
 073            InternalHttpPort = oldNetworkConfiguration.HttpServerPortNumber,
 074            InternalHttpsPort = oldNetworkConfiguration.HttpsPortNumber,
 075            IsRemoteIPFilterBlacklist = oldNetworkConfiguration.IsRemoteIPFilterBlacklist,
 076            KnownProxies = oldNetworkConfiguration.KnownProxies,
 077            LocalNetworkAddresses = oldNetworkConfiguration.LocalNetworkAddresses,
 078            LocalNetworkSubnets = oldNetworkConfiguration.LocalNetworkSubnets,
 079            PublicHttpPort = oldNetworkConfiguration.PublicPort,
 080            PublicHttpsPort = oldNetworkConfiguration.PublicHttpsPort,
 081            PublishedServerUriBySubnet = oldNetworkConfiguration.PublishedServerUriBySubnet,
 082            RemoteIPFilter = oldNetworkConfiguration.RemoteIPFilter,
 083            RequireHttps = oldNetworkConfiguration.RequireHttps
 084        };
 85
 86        // Migrate old virtual interface name schema
 087        var oldVirtualInterfaceNames = oldNetworkConfiguration.VirtualInterfaceNames;
 088        if (oldVirtualInterfaceNames.Equals("vEthernet*", StringComparison.OrdinalIgnoreCase))
 89        {
 090            networkConfiguration.VirtualInterfaceNames = new string[] { "veth" };
 91        }
 92        else
 93        {
 094            networkConfiguration.VirtualInterfaceNames = oldVirtualInterfaceNames.Replace("*", string.Empty, StringCompa
 95        }
 96
 097        var networkConfigSerializer = new XmlSerializer(typeof(NetworkConfiguration));
 098        var xmlWriterSettings = new XmlWriterSettings { Indent = true };
 099        using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
 0100        networkConfigSerializer.Serialize(xmlWriter, networkConfiguration);
 101
 0102        return Task.CompletedTask;
 0103    }
 104
 105#pragma warning disable
 106    public sealed class OldNetworkConfiguration
 107    {
 108        public const int DefaultHttpPort = 8096;
 109
 110        public const int DefaultHttpsPort = 8920;
 111
 0112        private string _baseUrl = string.Empty;
 113
 114        public bool RequireHttps { get; set; }
 115
 116        public string CertificatePath { get; set; } = string.Empty;
 117
 118        public string CertificatePassword { get; set; } = string.Empty;
 119
 120        public string BaseUrl
 121        {
 0122            get => _baseUrl;
 123            set
 124            {
 125                // Normalize the start of the string
 0126                if (string.IsNullOrWhiteSpace(value))
 127                {
 128                    // If baseUrl is empty, set an empty prefix string
 0129                    _baseUrl = string.Empty;
 0130                    return;
 131                }
 132
 0133                if (value[0] != '/')
 134                {
 135                    // If baseUrl was not configured with a leading slash, append one for consistency
 0136                    value = "/" + value;
 137                }
 138
 139                // Normalize the end of the string
 0140                if (value[^1] == '/')
 141                {
 142                    // If baseUrl was configured with a trailing slash, remove it for consistency
 0143                    value = value.Remove(value.Length - 1);
 144                }
 145
 0146                _baseUrl = value;
 0147            }
 148        }
 149
 150        public int PublicHttpsPort { get; set; } = DefaultHttpsPort;
 151
 152        public int HttpServerPortNumber { get; set; } = DefaultHttpPort;
 153
 154        public int HttpsPortNumber { get; set; } = DefaultHttpsPort;
 155
 156        public bool EnableHttps { get; set; }
 157
 158        public int PublicPort { get; set; } = DefaultHttpPort;
 159
 160        public bool UPnPCreateHttpPortMap { get; set; }
 161
 162        public string UDPPortRange { get; set; } = string.Empty;
 163
 164        public bool EnableIPV6 { get; set; }
 165
 166        public bool EnableIPV4 { get; set; } = true;
 167
 168        public bool EnableSSDPTracing { get; set; }
 169
 170        public string SSDPTracingFilter { get; set; } = string.Empty;
 171
 172        public int UDPSendCount { get; set; } = 2;
 173
 174        public int UDPSendDelay { get; set; } = 100;
 175
 176        public bool IgnoreVirtualInterfaces { get; set; } = true;
 177
 178        public string VirtualInterfaceNames { get; set; } = "vEthernet*";
 179
 180        public int GatewayMonitorPeriod { get; set; } = 60;
 181
 182        public bool EnableMultiSocketBinding { get; } = true;
 183
 184        public bool TrustAllIP6Interfaces { get; set; }
 185
 186        public string HDHomerunPortRange { get; set; } = string.Empty;
 187
 188        public string[] PublishedServerUriBySubnet { get; set; } = Array.Empty<string>();
 189
 190        public bool AutoDiscoveryTracing { get; set; }
 191
 192        public bool AutoDiscovery { get; set; } = true;
 193
 194        public string[] RemoteIPFilter { get; set; } = Array.Empty<string>();
 195
 196        public bool IsRemoteIPFilterBlacklist { get; set; }
 197
 198        public bool EnableUPnP { get; set; }
 199
 200        public bool EnableRemoteAccess { get; set; } = true;
 201
 202        public string[] LocalNetworkSubnets { get; set; } = Array.Empty<string>();
 203
 204        public string[] LocalNetworkAddresses { get; set; } = Array.Empty<string>();
 205        public string[] KnownProxies { get; set; } = Array.Empty<string>();
 206
 207        public bool EnablePublishedServerUriByRequest { get; set; } = false;
 208    }
 209}