diff options
Diffstat (limited to 'Jellyfin.Server')
| -rw-r--r-- | Jellyfin.Server/CoreAppHost.cs | 19 | ||||
| -rw-r--r-- | Jellyfin.Server/Jellyfin.Server.csproj | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/Program.cs | 63 | ||||
| -rw-r--r-- | Jellyfin.Server/Properties/AssemblyInfo.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/HttpFile.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/RequestMono.cs | 95 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/SharpWebSocket.cs | 10 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs | 174 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs | 36 |
10 files changed, 124 insertions, 281 deletions
diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index 64e03f22e..b18562a69 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -16,29 +16,16 @@ namespace Jellyfin.Server { } - public override bool CanSelfRestart - { - get - { - // A restart script must be provided - return StartupOptions.ContainsOption("-restartpath"); - } - } + public override bool CanSelfRestart => StartupOptions.ContainsOption("-restartpath"); protected override void RestartInternal() => Program.Restart(); protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal() - => new [] { typeof(CoreAppHost).Assembly }; + => new[] { typeof(CoreAppHost).Assembly }; protected override void ShutdownInternal() => Program.Shutdown(); - protected override bool SupportsDualModeSockets - { - get - { - return true; - } - } + protected override bool SupportsDualModeSockets => true; protected override IHttpListener CreateHttpListener() => new WebSocketSharpListener( diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj index e7358e6a1..f17e06e69 100644 --- a/Jellyfin.Server/Jellyfin.Server.csproj +++ b/Jellyfin.Server/Jellyfin.Server.csproj @@ -1,4 +1,4 @@ -<Project Sdk="Microsoft.NET.Sdk"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <AssemblyName>jellyfin</AssemblyName> diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index acbe5c714..51ad53749 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -17,8 +17,8 @@ using Emby.Server.Implementations.Networking; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Drawing; -using MediaBrowser.Model.IO; using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.IO; using MediaBrowser.Model.System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -45,7 +45,8 @@ namespace Jellyfin.Server Console.WriteLine(version.ToString()); } - ServerApplicationPaths appPaths = createApplicationPaths(options); + ServerApplicationPaths appPaths = CreateApplicationPaths(options); + // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath); await createLogger(appPaths); @@ -130,7 +131,7 @@ namespace Jellyfin.Server } } - private static ServerApplicationPaths createApplicationPaths(StartupOptions options) + private static ServerApplicationPaths CreateApplicationPaths(StartupOptions options) { string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH"); if (string.IsNullOrEmpty(programDataPath)) @@ -155,12 +156,21 @@ namespace Jellyfin.Server programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); } } + programDataPath = Path.Combine(programDataPath, "jellyfin"); - // Ensure the dir exists - Directory.CreateDirectory(programDataPath); } } + if (string.IsNullOrEmpty(programDataPath)) + { + Console.WriteLine("Cannot continue without path to program data folder (try -programdata)"); + Environment.Exit(1); + } + else + { + Directory.CreateDirectory(programDataPath); + } + string configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR"); if (string.IsNullOrEmpty(configDir)) { @@ -175,6 +185,11 @@ namespace Jellyfin.Server } } + if (configDir != null) + { + Directory.CreateDirectory(configDir); + } + string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); if (string.IsNullOrEmpty(logDir)) { @@ -189,6 +204,11 @@ namespace Jellyfin.Server } } + if (logDir != null) + { + Directory.CreateDirectory(logDir); + } + string appPath = AppContext.BaseDirectory; return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir); @@ -258,7 +278,8 @@ namespace Jellyfin.Server return new NullImageEncoder(); } - private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem() { + private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem() + { switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: @@ -267,22 +288,22 @@ namespace Jellyfin.Server return MediaBrowser.Model.System.OperatingSystem.Windows; case PlatformID.Unix: default: - { - string osDescription = RuntimeInformation.OSDescription; - if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase)) - { - return MediaBrowser.Model.System.OperatingSystem.Linux; - } - else if (osDescription.Contains("darwin", StringComparison.OrdinalIgnoreCase)) - { - return MediaBrowser.Model.System.OperatingSystem.OSX; - } - else if (osDescription.Contains("bsd", StringComparison.OrdinalIgnoreCase)) { - return MediaBrowser.Model.System.OperatingSystem.BSD; + string osDescription = RuntimeInformation.OSDescription; + if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase)) + { + return MediaBrowser.Model.System.OperatingSystem.Linux; + } + else if (osDescription.Contains("darwin", StringComparison.OrdinalIgnoreCase)) + { + return MediaBrowser.Model.System.OperatingSystem.OSX; + } + else if (osDescription.Contains("bsd", StringComparison.OrdinalIgnoreCase)) + { + return MediaBrowser.Model.System.OperatingSystem.BSD; + } + throw new Exception($"Can't resolve OS with description: '{osDescription}'"); } - throw new Exception($"Can't resolve OS with description: '{osDescription}'"); - } } } @@ -320,7 +341,7 @@ namespace Jellyfin.Server } else { - commandLineArgsString = string .Join(" ", + commandLineArgsString = string.Join(" ", Environment.GetCommandLineArgs() .Skip(1) .Select(NormalizeCommandLineArgument) diff --git a/Jellyfin.Server/Properties/AssemblyInfo.cs b/Jellyfin.Server/Properties/AssemblyInfo.cs index 1934b6bc1..2959cdf1f 100644 --- a/Jellyfin.Server/Properties/AssemblyInfo.cs +++ b/Jellyfin.Server/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Reflection; using System.Resources; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Jellyfin.Server")] diff --git a/Jellyfin.Server/SocketSharp/HttpFile.cs b/Jellyfin.Server/SocketSharp/HttpFile.cs index 4a798062d..77ce03510 100644 --- a/Jellyfin.Server/SocketSharp/HttpFile.cs +++ b/Jellyfin.Server/SocketSharp/HttpFile.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using MediaBrowser.Model.Services; namespace Jellyfin.SocketSharp diff --git a/Jellyfin.Server/SocketSharp/RequestMono.cs b/Jellyfin.Server/SocketSharp/RequestMono.cs index 4c3d8d1d5..45cb323d2 100644 --- a/Jellyfin.Server/SocketSharp/RequestMono.cs +++ b/Jellyfin.Server/SocketSharp/RequestMono.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -75,7 +75,7 @@ namespace Jellyfin.SocketSharp // // We use a substream, as in 2.x we will support large uploads streamed to disk, // - HttpPostedFile sub = new HttpPostedFile(e.Filename, e.ContentType, input, e.Start, e.Length); + var sub = new HttpPostedFile(e.Filename, e.ContentType, input, e.Start, e.Length); files[e.Name] = sub; } } @@ -113,21 +113,9 @@ namespace Jellyfin.SocketSharp return form; } - public string Accept - { - get - { - return string.IsNullOrEmpty(request.Headers["Accept"]) ? null : request.Headers["Accept"]; - } - } + public string Accept => string.IsNullOrEmpty(request.Headers["Accept"]) ? null : request.Headers["Accept"]; - public string Authorization - { - get - { - return string.IsNullOrEmpty(request.Headers["Authorization"]) ? null : request.Headers["Authorization"]; - } - } + public string Authorization => string.IsNullOrEmpty(request.Headers["Authorization"]) ? null : request.Headers["Authorization"]; protected bool validate_cookies, validate_query_string, validate_form; protected bool checked_cookies, checked_query_string, checked_form; @@ -160,9 +148,7 @@ namespace Jellyfin.SocketSharp internal static bool IsInvalidString(string val) { - int validationFailureIndex; - - return IsInvalidString(val, out validationFailureIndex); + return IsInvalidString(val, out var validationFailureIndex); } internal static bool IsInvalidString(string val, out int validationFailureIndex) @@ -219,17 +205,17 @@ namespace Jellyfin.SocketSharp async Task LoadWwwForm(WebROCollection form) { - using (Stream input = InputStream) + using (var input = InputStream) { using (var ms = new MemoryStream()) { await input.CopyToAsync(ms).ConfigureAwait(false); ms.Position = 0; - using (StreamReader s = new StreamReader(ms, ContentEncoding)) + using (var s = new StreamReader(ms, ContentEncoding)) { - StringBuilder key = new StringBuilder(); - StringBuilder value = new StringBuilder(); + var key = new StringBuilder(); + var value = new StringBuilder(); int c; while ((c = s.Read()) != -1) @@ -281,7 +267,7 @@ namespace Jellyfin.SocketSharp { public override string ToString() { - StringBuilder result = new StringBuilder(); + var result = new StringBuilder(); foreach (var pair in this) { if (result.Length > 0) @@ -410,30 +396,17 @@ namespace Jellyfin.SocketSharp throw new NotSupportedException(); } - public override bool CanRead - { - get { return true; } - } - public override bool CanSeek - { - get { return true; } - } - public override bool CanWrite - { - get { return false; } - } + public override bool CanRead => true; - public override long Length - { - get { return end - offset; } - } + public override bool CanSeek => true; + + public override bool CanWrite => false; + + public override long Length => end - offset; public override long Position { - get - { - return position - offset; - } + get => position - offset; set { if (value > Length) @@ -451,37 +424,13 @@ namespace Jellyfin.SocketSharp this.stream = new ReadSubStream(base_stream, offset, length); } - public string ContentType - { - get - { - return content_type; - } - } + public string ContentType => content_type; - public int ContentLength - { - get - { - return (int)stream.Length; - } - } + public int ContentLength => (int)stream.Length; - public string FileName - { - get - { - return name; - } - } + public string FileName => name; - public Stream InputStream - { - get - { - return stream; - } - } + public Stream InputStream => stream; } class Helpers @@ -764,7 +713,7 @@ namespace Jellyfin.SocketSharp if (at_eof || ReadBoundary()) return null; - Element elem = new Element(); + var elem = new Element(); string header; while ((header = ReadHeaders()) != null) { diff --git a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs index 7101f83d9..d0dcd86eb 100644 --- a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs +++ b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs @@ -1,7 +1,7 @@ using System; +using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; -using System.Net.WebSockets; using Emby.Server.Implementations.Net; using Microsoft.Extensions.Logging; @@ -85,13 +85,7 @@ namespace Jellyfin.SocketSharp /// Gets or sets the state. /// </summary> /// <value>The state.</value> - public WebSocketState State - { - get - { - return WebSocket.ReadyState; - } - } + public WebSocketState State => WebSocket.ReadyState; /// <summary> /// Sends the async. diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs index 468c4c5ca..89337b6b7 100644 --- a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs +++ b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -using Emby.Server.Implementations.Net; using Emby.Server.Implementations.HttpServer; +using Emby.Server.Implementations.Net; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Cryptography; diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs index 149842bd4..e38468388 100644 --- a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs +++ b/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -39,88 +39,38 @@ namespace Jellyfin.SocketSharp return string.IsNullOrEmpty(endHostUrl) ? null : endHostUrl.TrimEnd('/'); } - public HttpListenerRequest HttpRequest - { - get { return request; } - } + public HttpListenerRequest HttpRequest => request; - public object OriginalRequest - { - get { return request; } - } + public object OriginalRequest => request; - public IResponse Response - { - get { return response; } - } + public IResponse Response => response; - public IHttpResponse HttpResponse - { - get { return response; } - } + public IHttpResponse HttpResponse => response; public string OperationName { get; set; } public object Dto { get; set; } - public string RawUrl - { - get { return request.RawUrl; } - } + public string RawUrl => request.RawUrl; - public string AbsoluteUri - { - get { return request.Url.AbsoluteUri.TrimEnd('/'); } - } + public string AbsoluteUri => request.Url.AbsoluteUri.TrimEnd('/'); - public string UserHostAddress - { - get { return request.UserHostAddress; } - } + public string UserHostAddress => request.UserHostAddress; - public string XForwardedFor - { - get - { - return string.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"]; - } - } + public string XForwardedFor => string.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"]; - public int? XForwardedPort - { - get - { - return string.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"]); - } - } + public int? XForwardedPort => string.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"]); - public string XForwardedProtocol - { - get - { - return string.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"]; - } - } + public string XForwardedProtocol => string.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"]; - public string XRealIp - { - get - { - return string.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"]; - } - } + public string XRealIp => string.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"]; private string remoteIp; - public string RemoteIp - { - get - { - return remoteIp ?? - (remoteIp = (CheckBadChars(XForwardedFor)) ?? - (NormalizeIp(CheckBadChars(XRealIp)) ?? - (request.RemoteEndPoint != null ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null))); - } - } + public string RemoteIp => + remoteIp ?? + (remoteIp = (CheckBadChars(XForwardedFor)) ?? + (NormalizeIp(CheckBadChars(XRealIp)) ?? + (request.RemoteEndPoint != null ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null))); private static readonly char[] HttpTrimCharacters = new char[] { (char)0x09, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20 }; @@ -215,34 +165,20 @@ namespace Jellyfin.SocketSharp return ip; } - public bool IsSecureConnection - { - get { return request.IsSecureConnection || XForwardedProtocol == "https"; } - } + public bool IsSecureConnection => request.IsSecureConnection || XForwardedProtocol == "https"; - public string[] AcceptTypes - { - get { return request.AcceptTypes; } - } + public string[] AcceptTypes => request.AcceptTypes; private Dictionary<string, object> items; - public Dictionary<string, object> Items - { - get { return items ?? (items = new Dictionary<string, object>()); } - } + public Dictionary<string, object> Items => items ?? (items = new Dictionary<string, object>()); private string responseContentType; public string ResponseContentType { - get - { - return responseContentType - ?? (responseContentType = GetResponseContentType(this)); - } - set - { - this.responseContentType = value; - } + get => + responseContentType + ?? (responseContentType = GetResponseContentType(this)); + set => this.responseContentType = value; } public const string FormUrlEncoded = "application/x-www-form-urlencoded"; @@ -425,7 +361,7 @@ namespace Jellyfin.SocketSharp cookies = new Dictionary<string, System.Net.Cookie>(); foreach (var cookie in this.request.Cookies) { - var httpCookie = (System.Net.Cookie) cookie; + var httpCookie = (System.Net.Cookie)cookie; cookies[httpCookie.Name] = new System.Net.Cookie(httpCookie.Name, httpCookie.Value, httpCookie.Path, httpCookie.Domain); } } @@ -434,58 +370,32 @@ namespace Jellyfin.SocketSharp } } - public string UserAgent - { - get { return request.UserAgent; } - } + public string UserAgent => request.UserAgent; - public QueryParamCollection Headers - { - get { return request.Headers; } - } + public QueryParamCollection Headers => request.Headers; private QueryParamCollection queryString; - public QueryParamCollection QueryString - { - get { return queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query)); } - } + public QueryParamCollection QueryString => queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query)); - public bool IsLocal - { - get { return request.IsLocal; } - } + public bool IsLocal => request.IsLocal; private string httpMethod; - public string HttpMethod - { - get - { - return httpMethod - ?? (httpMethod = request.HttpMethod); - } - } + public string HttpMethod => + httpMethod + ?? (httpMethod = request.HttpMethod); - public string Verb - { - get { return HttpMethod; } - } + public string Verb => HttpMethod; - public string ContentType - { - get { return request.ContentType; } - } + public string ContentType => request.ContentType; public Encoding contentEncoding; public Encoding ContentEncoding { - get { return contentEncoding ?? request.ContentEncoding; } - set { contentEncoding = value; } + get => contentEncoding ?? request.ContentEncoding; + set => contentEncoding = value; } - public Uri UrlReferrer - { - get { return request.UrlReferrer; } - } + public Uri UrlReferrer => request.UrlReferrer; public static Encoding GetEncoding(string contentTypeHeader) { @@ -501,15 +411,9 @@ namespace Jellyfin.SocketSharp } } - public Stream InputStream - { - get { return request.InputStream; } - } + public Stream InputStream => request.InputStream; - public long ContentLength - { - get { return request.ContentLength64; } - } + public long ContentLength => request.ContentLength64; private IHttpFile[] httpFiles; public IHttpFile[] Files diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs index c7437c825..21bfac55d 100644 --- a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs +++ b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Net; @@ -31,27 +31,24 @@ namespace Jellyfin.SocketSharp public IRequest Request { get; private set; } public Dictionary<string, object> Items { get; private set; } - public object OriginalResponse - { - get { return _response; } - } + public object OriginalResponse => _response; public int StatusCode { - get { return this._response.StatusCode; } - set { this._response.StatusCode = value; } + get => this._response.StatusCode; + set => this._response.StatusCode = value; } public string StatusDescription { - get { return this._response.StatusDescription; } - set { this._response.StatusDescription = value; } + get => this._response.StatusDescription; + set => this._response.StatusDescription = value; } public string ContentType { - get { return _response.ContentType; } - set { _response.ContentType = value; } + get => _response.ContentType; + set => _response.ContentType = value; } //public ICookies Cookies { get; set; } @@ -67,13 +64,7 @@ namespace Jellyfin.SocketSharp _response.AddHeader(name, value); } - public QueryParamCollection Headers - { - get - { - return _response.Headers; - } - } + public QueryParamCollection Headers => _response.Headers; public string GetHeader(string name) { @@ -85,10 +76,7 @@ namespace Jellyfin.SocketSharp _response.Redirect(url); } - public Stream OutputStream - { - get { return _response.OutputStream; } - } + public Stream OutputStream => _response.OutputStream; public void Close() { @@ -179,8 +167,8 @@ namespace Jellyfin.SocketSharp public bool SendChunked { - get { return _response.SendChunked; } - set { _response.SendChunked = value; } + get => _response.SendChunked; + set => _response.SendChunked = value; } public bool KeepAlive { get; set; } |
