Fix more warnings

This commit is contained in:
Bond-009 2019-02-08 00:07:57 +01:00
parent f60ad53393
commit 38d9eeffbe
2 changed files with 39 additions and 37 deletions

View File

@ -11,7 +11,7 @@ namespace Jellyfin.SocketSharp
{ {
public partial class WebSocketSharpRequest : IHttpRequest 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); int ap = header.IndexOf(attr);
if (ap == -1) if (ap == -1)
@ -40,7 +40,7 @@ namespace Jellyfin.SocketSharp
return header.Substring(ap + 1, end - ap - 1); return header.Substring(ap + 1, end - ap - 1);
} }
async Task LoadMultiPart(WebROCollection form) private async Task LoadMultiPart(WebROCollection form)
{ {
string boundary = GetParameter(ContentType, "; boundary="); string boundary = GetParameter(ContentType, "; boundary=");
if (boundary == null) if (boundary == null)
@ -130,7 +130,7 @@ namespace Jellyfin.SocketSharp
protected bool validate_cookies, validate_query_string, validate_form; protected bool validate_cookies, validate_query_string, validate_form;
protected bool checked_cookies, checked_query_string, checked_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 + "\""; string v = "\"" + value + "\"";
if (v.Length > 20) if (v.Length > 20)
@ -144,7 +144,7 @@ namespace Jellyfin.SocketSharp
throw new Exception(msg); throw new Exception(msg);
} }
static void ValidateNameValueCollection(string name, QueryParamCollection coll) private static void ValidateNameValueCollection(string name, QueryParamCollection coll)
{ {
if (coll == null) if (coll == null)
{ {
@ -209,7 +209,7 @@ namespace Jellyfin.SocketSharp
validate_form = true; validate_form = true;
} }
bool IsContentType(string ct, bool starts_with) private bool IsContentType(string ct, bool starts_with)
{ {
if (ct == null || ContentType == null) if (ct == null || ContentType == null)
{ {
@ -224,7 +224,7 @@ namespace Jellyfin.SocketSharp
return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase); return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase);
} }
async Task LoadWwwForm(WebROCollection form) private async Task LoadWwwForm(WebROCollection form)
{ {
using (var input = InputStream) 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())); form.Add(WebUtility.UrlDecode(key.ToString()), WebUtility.UrlDecode(value.ToString()));
@ -288,9 +288,9 @@ namespace Jellyfin.SocketSharp
value.Length = 0; value.Length = 0;
} }
Dictionary<string, HttpPostedFile> files; private Dictionary<string, HttpPostedFile> files;
class WebROCollection : QueryParamCollection private class WebROCollection : QueryParamCollection
{ {
public override string ToString() public override string ToString()
{ {
@ -317,16 +317,16 @@ namespace Jellyfin.SocketSharp
public sealed class HttpPostedFile public sealed class HttpPostedFile
{ {
string name; private string name;
string content_type; private string content_type;
Stream stream; private Stream stream;
class ReadSubStream : Stream private class ReadSubStream : Stream
{ {
Stream s; private Stream s;
long offset; private long offset;
long end; private long end;
long position; private long position;
public ReadSubStream(Stream s, long offset, long length) public ReadSubStream(Stream s, long offset, long length)
{ {
@ -429,7 +429,7 @@ namespace Jellyfin.SocketSharp
real = position + d; real = position + d;
break; break;
default: default:
throw new ArgumentException(); throw new ArgumentException(nameof(origin));
} }
long virt = real - offset; long virt = real - offset;
@ -491,7 +491,7 @@ namespace Jellyfin.SocketSharp
public Stream InputStream => stream; public Stream InputStream => stream;
} }
class Helpers private class Helpers
{ {
public static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture; public static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture;
} }
@ -614,7 +614,7 @@ namespace Jellyfin.SocketSharp
private static string GetContentDispositionAttribute(string l, string name) private static string GetContentDispositionAttribute(string l, string name)
{ {
int idx = l.IndexOf(name + "=\""); int idx = l.IndexOf(name + "=\"", StringComparison.Ordinal);
if (idx < 0) if (idx < 0)
{ {
return null; return null;
@ -637,7 +637,7 @@ namespace Jellyfin.SocketSharp
private string GetContentDispositionAttributeWithEncoding(string l, string name) private string GetContentDispositionAttributeWithEncoding(string l, string name)
{ {
int idx = l.IndexOf(name + "=\""); int idx = l.IndexOf(name + "=\"", StringComparison.Ordinal);
if (idx < 0) if (idx < 0)
{ {
return null; return null;
@ -669,11 +669,12 @@ namespace Jellyfin.SocketSharp
{ {
try try
{ {
string line = ReadLine(); string line;
while (line == string.Empty) do
{ {
line = ReadLine(); line = ReadLine();
} }
while (line.Length == 0);
if (line[0] != '-' || line[1] != '-') if (line[0] != '-' || line[1] != '-')
{ {

View File

@ -80,8 +80,8 @@ namespace Jellyfin.SocketSharp
private string remoteIp; private string remoteIp;
public string RemoteIp => public string RemoteIp =>
remoteIp ?? remoteIp ??
(remoteIp = (CheckBadChars(XForwardedFor)) ?? (remoteIp = CheckBadChars(XForwardedFor) ??
(NormalizeIp(CheckBadChars(XRealIp)) ?? NormalizeIp(CheckBadChars(XRealIp) ??
(request.RemoteEndPoint != null ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null))); (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 }; private static readonly char[] HttpTrimCharacters = new char[] { (char)0x09, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20 };
@ -201,7 +201,7 @@ namespace Jellyfin.SocketSharp
return specifiedContentType; return specifiedContentType;
} }
var serverDefaultContentType = "application/json"; const string serverDefaultContentType = "application/json";
var acceptContentTypes = httpReq.AcceptTypes; var acceptContentTypes = httpReq.AcceptTypes;
string defaultContentType = null; string defaultContentType = null;
@ -211,7 +211,7 @@ namespace Jellyfin.SocketSharp
} }
var acceptsAnything = false; var acceptsAnything = false;
var hasDefaultContentType = !string.IsNullOrEmpty(defaultContentType); var hasDefaultContentType = defaultContentType != null;
if (acceptContentTypes != null) if (acceptContentTypes != null)
{ {
foreach (var acceptsType in acceptContentTypes) foreach (var acceptsType in acceptContentTypes)
@ -311,7 +311,7 @@ namespace Jellyfin.SocketSharp
return null; return null;
} }
var pos = strVal.IndexOf(needle); var pos = strVal.IndexOf(needle, StringComparison.Ordinal);
return pos == -1 ? strVal : strVal.Substring(0, pos); return pos == -1 ? strVal : strVal.Substring(0, pos);
} }
@ -397,6 +397,7 @@ namespace Jellyfin.SocketSharp
} }
} }
} }
if (!pathRootFound) if (!pathRootFound)
{ {
return null; return null;
@ -507,10 +508,10 @@ namespace Jellyfin.SocketSharp
public static string NormalizePathInfo(string pathInfo, string handlerPath) public static string NormalizePathInfo(string pathInfo, string handlerPath)
{ {
if (handlerPath != null && pathInfo.TrimStart('/').StartsWith( var trimmed = pathInfo.TrimStart('/');
handlerPath, StringComparison.OrdinalIgnoreCase)) if (handlerPath != null && trimmed.StartsWith(handlerPath, StringComparison.OrdinalIgnoreCase))
{ {
return pathInfo.TrimStart('/').Substring(handlerPath.Length); return trimmed.Substring(handlerPath.Length);
} }
return pathInfo; return pathInfo;