diff options
Diffstat (limited to 'Jellyfin.Server/SocketSharp')
| -rw-r--r-- | Jellyfin.Server/SocketSharp/HttpFile.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/RequestMono.cs | 61 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/SharpWebSocket.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs | 45 | ||||
| -rw-r--r-- | Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs | 2 |
6 files changed, 61 insertions, 53 deletions
diff --git a/Jellyfin.Server/SocketSharp/HttpFile.cs b/Jellyfin.Server/SocketSharp/HttpFile.cs index 77ce03510..89c75e536 100644 --- a/Jellyfin.Server/SocketSharp/HttpFile.cs +++ b/Jellyfin.Server/SocketSharp/HttpFile.cs @@ -1,7 +1,7 @@ using System.IO; using MediaBrowser.Model.Services; -namespace Jellyfin.SocketSharp +namespace Jellyfin.Server.SocketSharp { public class HttpFile : IHttpFile { diff --git a/Jellyfin.Server/SocketSharp/RequestMono.cs b/Jellyfin.Server/SocketSharp/RequestMono.cs index f09197fb3..a8ba4cdb5 100644 --- a/Jellyfin.Server/SocketSharp/RequestMono.cs +++ b/Jellyfin.Server/SocketSharp/RequestMono.cs @@ -7,11 +7,11 @@ using System.Text; using System.Threading.Tasks; using MediaBrowser.Model.Services; -namespace Jellyfin.SocketSharp +namespace Jellyfin.Server.SocketSharp { public partial class WebSocketSharpRequest : IHttpRequest { - static internal string GetParameter(string header, string attr) + internal static string GetParameter(string header, string attr) { int ap = header.IndexOf(attr); if (ap == -1) @@ -40,7 +40,7 @@ namespace Jellyfin.SocketSharp return header.Substring(ap + 1, end - ap - 1); } - async Task LoadMultiPart(WebROCollection form) + private async Task LoadMultiPart(WebROCollection form) { string boundary = GetParameter(ContentType, "; boundary="); if (boundary == null) @@ -50,8 +50,8 @@ namespace Jellyfin.SocketSharp using (var requestStream = InputStream) { - //DB: 30/01/11 - Hack to get around non-seekable stream and received HTTP request - //Not ending with \r\n? + // DB: 30/01/11 - Hack to get around non-seekable stream and received HTTP request + // Not ending with \r\n? var ms = new MemoryStream(32 * 1024); await requestStream.CopyToAsync(ms).ConfigureAwait(false); @@ -62,9 +62,9 @@ namespace Jellyfin.SocketSharp input.Position = 0; // Uncomment to debug - //var content = new StreamReader(ms).ReadToEnd(); - //Console.WriteLine(boundary + "::" + content); - //input.Position = 0; + // var content = new StreamReader(ms).ReadToEnd(); + // Console.WriteLine(boundary + "::" + content); + // input.Position = 0; var multi_part = new HttpMultipart(input, boundary, ContentEncoding); @@ -111,7 +111,7 @@ namespace Jellyfin.SocketSharp // Setting this before calling the validator prevents // possible endless recursion checked_form = true; - ValidateNameValueCollection ("Form", query_string_nvc, RequestValidationSource.Form); + ValidateNameValueCollection("Form", query_string_nvc, RequestValidationSource.Form); } else #endif if (validate_form && !checked_form) @@ -130,7 +130,7 @@ namespace Jellyfin.SocketSharp protected bool validate_cookies, validate_query_string, validate_form; protected bool checked_cookies, checked_query_string, checked_form; - static void ThrowValidationException(string name, string key, string value) + private static void ThrowValidationException(string name, string key, string value) { string v = "\"" + value + "\""; if (v.Length > 20) @@ -144,7 +144,7 @@ namespace Jellyfin.SocketSharp throw new Exception(msg); } - static void ValidateNameValueCollection(string name, QueryParamCollection coll) + private static void ValidateNameValueCollection(string name, QueryParamCollection coll) { if (coll == null) { @@ -209,7 +209,7 @@ namespace Jellyfin.SocketSharp validate_form = true; } - bool IsContentType(string ct, bool starts_with) + private bool IsContentType(string ct, bool starts_with) { if (ct == null || ContentType == null) { @@ -224,7 +224,7 @@ namespace Jellyfin.SocketSharp return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase); } - async Task LoadWwwForm(WebROCollection form) + private async Task LoadWwwForm(WebROCollection form) { using (var input = InputStream) { @@ -280,7 +280,7 @@ namespace Jellyfin.SocketSharp } } - static void AddRawKeyValue(WebROCollection form, StringBuilder key, StringBuilder value) + private static void AddRawKeyValue(WebROCollection form, StringBuilder key, StringBuilder value) { form.Add(WebUtility.UrlDecode(key.ToString()), WebUtility.UrlDecode(value.ToString())); @@ -288,9 +288,9 @@ namespace Jellyfin.SocketSharp value.Length = 0; } - Dictionary<string, HttpPostedFile> files; + private Dictionary<string, HttpPostedFile> files; - class WebROCollection : QueryParamCollection + private class WebROCollection : QueryParamCollection { public override string ToString() { @@ -317,16 +317,16 @@ namespace Jellyfin.SocketSharp public sealed class HttpPostedFile { - string name; - string content_type; - Stream stream; + private string name; + private string content_type; + private Stream stream; - class ReadSubStream : Stream + private class ReadSubStream : Stream { - Stream s; - long offset; - long end; - long position; + private Stream s; + private long offset; + private long end; + private long position; public ReadSubStream(Stream s, long offset, long length) { @@ -429,7 +429,7 @@ namespace Jellyfin.SocketSharp real = position + d; break; default: - throw new ArgumentException(); + throw new ArgumentException(nameof(origin)); } long virt = real - offset; @@ -491,7 +491,7 @@ namespace Jellyfin.SocketSharp public Stream InputStream => stream; } - class Helpers + private class Helpers { public static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture; } @@ -614,7 +614,7 @@ namespace Jellyfin.SocketSharp private static string GetContentDispositionAttribute(string l, string name) { - int idx = l.IndexOf(name + "=\""); + int idx = l.IndexOf(name + "=\"", StringComparison.Ordinal); if (idx < 0) { return null; @@ -637,7 +637,7 @@ namespace Jellyfin.SocketSharp private string GetContentDispositionAttributeWithEncoding(string l, string name) { - int idx = l.IndexOf(name + "=\""); + int idx = l.IndexOf(name + "=\"", StringComparison.Ordinal); if (idx < 0) { return null; @@ -669,11 +669,12 @@ namespace Jellyfin.SocketSharp { try { - string line = ReadLine(); - while (line == string.Empty) + string line; + do { line = ReadLine(); } + while (line.Length == 0); if (line[0] != '-' || line[1] != '-') { diff --git a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs index d0dcd86eb..f371cb25a 100644 --- a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs +++ b/Jellyfin.Server/SocketSharp/SharpWebSocket.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Emby.Server.Implementations.Net; using Microsoft.Extensions.Logging; -namespace Jellyfin.SocketSharp +namespace Jellyfin.Server.SocketSharp { public class SharpWebSocket : IWebSocket { diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs index c7f9f01b5..a44343ab2 100644 --- a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs +++ b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs @@ -15,7 +15,7 @@ using MediaBrowser.Model.System; using Microsoft.Extensions.Logging; using SocketHttpListener.Net; -namespace Jellyfin.SocketSharp +namespace Jellyfin.Server.SocketSharp { public class WebSocketSharpListener : IHttpListener { diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs index 2e8dd9185..ebeb18ea0 100644 --- a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs +++ b/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs @@ -11,7 +11,7 @@ using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest; using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse; using IResponse = MediaBrowser.Model.Services.IResponse; -namespace Jellyfin.SocketSharp +namespace Jellyfin.Server.SocketSharp { public partial class WebSocketSharpRequest : IHttpRequest { @@ -80,15 +80,13 @@ namespace Jellyfin.SocketSharp private string remoteIp; public string RemoteIp => remoteIp ?? - (remoteIp = (CheckBadChars(XForwardedFor)) ?? - (NormalizeIp(CheckBadChars(XRealIp)) ?? + (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 }; - // // CheckBadChars - throws on invalid chars to be not found in header name/value - // internal static string CheckBadChars(string name) { if (name == null || name.Length == 0) @@ -97,11 +95,11 @@ namespace Jellyfin.SocketSharp } // VALUE check - //Trim spaces from both ends + // Trim spaces from both ends name = name.Trim(HttpTrimCharacters); - //First, check for correctly formed multi-line value - //Second, check for absenece of CTL characters + // First, check for correctly formed multi-line value + // Second, check for absenece of CTL characters int crlf = 0; for (int i = 0; i < name.Length; ++i) { @@ -198,9 +196,12 @@ namespace Jellyfin.SocketSharp public static string GetResponseContentType(IRequest httpReq) { var specifiedContentType = GetQueryStringContentType(httpReq); - if (!string.IsNullOrEmpty(specifiedContentType)) return specifiedContentType; + if (!string.IsNullOrEmpty(specifiedContentType)) + { + return specifiedContentType; + } - var serverDefaultContentType = "application/json"; + const string serverDefaultContentType = "application/json"; var acceptContentTypes = httpReq.AcceptTypes; string defaultContentType = null; @@ -210,7 +211,7 @@ namespace Jellyfin.SocketSharp } var acceptsAnything = false; - var hasDefaultContentType = !string.IsNullOrEmpty(defaultContentType); + var hasDefaultContentType = defaultContentType != null; if (acceptContentTypes != null) { foreach (var acceptsType in acceptContentTypes) @@ -237,7 +238,7 @@ namespace Jellyfin.SocketSharp return Soap11; } - //We could also send a '406 Not Acceptable', but this is allowed also + // We could also send a '406 Not Acceptable', but this is allowed also return serverDefaultContentType; } @@ -252,7 +253,10 @@ namespace Jellyfin.SocketSharp foreach (var contentType in contentTypes) { - if (IsContentType(request, contentType)) return true; + if (IsContentType(request, contentType)) + { + return true; + } } return false; @@ -274,10 +278,12 @@ namespace Jellyfin.SocketSharp { return null; } + if (pi[0] == '/') { pi = pi.Substring(1); } + format = LeftPart(pi, '/'); if (format.Length > formatMaxLength) { @@ -285,7 +291,7 @@ namespace Jellyfin.SocketSharp } } - format = LeftPart(format, '.').ToLowerInvariant(); + format = LeftPart(format, '.'); if (format.Contains("json", StringComparison.OrdinalIgnoreCase)) { return "application/json"; @@ -305,7 +311,7 @@ namespace Jellyfin.SocketSharp return null; } - var pos = strVal.IndexOf(needle); + var pos = strVal.IndexOf(needle, StringComparison.Ordinal); return pos == -1 ? strVal : strVal.Substring(0, pos); } @@ -349,7 +355,7 @@ namespace Jellyfin.SocketSharp return pathInfo; } - //Wildcard mode relies on this to work out the handlerPath + // Wildcard mode relies on this to work out the handlerPath pathInfo = ResolvePathInfoFromMappedPath(fullPath, appPath); if (!string.IsNullOrEmpty(pathInfo)) { @@ -391,6 +397,7 @@ namespace Jellyfin.SocketSharp } } } + if (!pathRootFound) { return null; @@ -501,10 +508,10 @@ namespace Jellyfin.SocketSharp public static string NormalizePathInfo(string pathInfo, string handlerPath) { - if (handlerPath != null && pathInfo.TrimStart('/').StartsWith( - handlerPath, StringComparison.OrdinalIgnoreCase)) + var trimmed = pathInfo.TrimStart('/'); + if (handlerPath != null && trimmed.StartsWith(handlerPath, StringComparison.OrdinalIgnoreCase)) { - return pathInfo.TrimStart('/').Substring(handlerPath.Length); + return trimmed.Substring(handlerPath.Length); } return pathInfo; diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs index 21bfac55d..cabc96b23 100644 --- a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs +++ b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs @@ -14,7 +14,7 @@ using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse; using IRequest = MediaBrowser.Model.Services.IRequest; -namespace Jellyfin.SocketSharp +namespace Jellyfin.Server.SocketSharp { public class WebSocketSharpResponse : IHttpResponse { |
