Commit 126eed5e authored by Honfika's avatar Honfika

using "var" for non builtin types everywhere, specify type for builtin types everywhere

parent c706c9fa
......@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers
internal static bool DisableQuickEditMode()
{
IntPtr consoleHandle = GetStdHandle(STD_INPUT_HANDLE);
var consoleHandle = GetStdHandle(STD_INPUT_HANDLE);
// get current console mode
uint consoleMode;
......
......@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
if (e.WebSession.Request.HasBody)
{
//Get/Set request body bytes
byte[] bodyBytes = await e.GetRequestBody();
var bodyBytes = await e.GetRequestBody();
await e.SetRequestBody(bodyBytes);
//Get/Set request body as string
......@@ -180,7 +180,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
if (e.WebSession.Response.ContentType != null && e.WebSession.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
byte[] bodyBytes = await e.GetResponseBody();
var bodyBytes = await e.GetResponseBody();
await e.SetResponseBody(bodyBytes);
string body = await e.GetResponseBodyAsString();
......
......@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
{
//expand this to stress test to find
//why in long run proxy becomes unresponsive as per issue #184
var testUrl = "https://google.com";
string testUrl = "https://google.com";
int proxyPort = 8086;
var proxy = new ProxyTestController();
proxy.StartProxy(proxyPort);
......
......@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.UnitTests
for (int i = 0; i < 1000; i++)
{
foreach (var host in hostNames)
foreach (string host in hostNames)
{
tasks.Add(Task.Run(async () =>
{
......
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Titanium.Web.Proxy.Network.WinAuth;
namespace Titanium.Web.Proxy.UnitTests
......@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.UnitTests
[TestMethod]
public void Test_Acquire_Client_Token()
{
var token = WinAuthHandler.GetInitialAuthToken("mylocalserver.com", "NTLM", Guid.NewGuid());
string token = WinAuthHandler.GetInitialAuthToken("mylocalserver.com", "NTLM", Guid.NewGuid());
Assert.IsTrue(token.Length > 1);
}
}
......
......@@ -5,6 +5,8 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">160</s:Int64>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVar</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CN/@EntryIndexedValue">CN</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DN/@EntryIndexedValue">DN</s:String>
......
......@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy
if (acceptableIssuers != null && acceptableIssuers.Length > 0 && localCertificates != null && localCertificates.Count > 0)
{
// Use the first certificate that is from an acceptable issuer.
foreach (X509Certificate certificate in localCertificates)
foreach (var certificate in localCertificates)
{
string issuer = certificate.Issuer;
if (Array.IndexOf(acceptableIssuers, issuer) != -1)
......
......@@ -7,8 +7,8 @@ namespace Titanium.Web.Proxy.Extensions
{
public static void InvokeParallel<T>(this Func<object, T, Task> callback, object sender, T args)
{
Delegate[] invocationList = callback.GetInvocationList();
Task[] handlerTasks = new Task[invocationList.Length];
var invocationList = callback.GetInvocationList();
var handlerTasks = new Task[invocationList.Length];
for (int i = 0; i < invocationList.Length; i++)
{
......@@ -20,8 +20,8 @@ namespace Titanium.Web.Proxy.Extensions
public static async Task InvokeParallelAsync<T>(this Func<object, T, Task> callback, object sender, T args)
{
Delegate[] invocationList = callback.GetInvocationList();
Task[] handlerTasks = new Task[invocationList.Length];
var invocationList = callback.GetInvocationList();
var handlerTasks = new Task[invocationList.Length];
for (int i = 0; i < invocationList.Length; i++)
{
......
......@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <returns></returns>
internal static async Task CopyBytesToStream(this CustomBinaryReader streamReader, Stream stream, long totalBytesToRead)
{
byte[] buffer = streamReader.Buffer;
var buffer = streamReader.Buffer;
long remainingBytes = totalBytesToRead;
while (remainingBytes > 0)
......@@ -72,8 +72,8 @@ namespace Titanium.Web.Proxy.Extensions
{
while (true)
{
var chuchkHead = await clientStreamReader.ReadLineAsync();
var chunkSize = int.Parse(chuchkHead, NumberStyles.HexNumber);
string chuchkHead = await clientStreamReader.ReadLineAsync();
int chunkSize = int.Parse(chuchkHead, NumberStyles.HexNumber);
if (chunkSize != 0)
{
......@@ -148,8 +148,8 @@ namespace Titanium.Web.Proxy.Extensions
{
while (true)
{
var chunkHead = await inStreamReader.ReadLineAsync();
var chunkSize = int.Parse(chunkHead, NumberStyles.HexNumber);
string chunkHead = await inStreamReader.ReadLineAsync();
int chunkSize = int.Parse(chunkHead, NumberStyles.HexNumber);
if (chunkSize != 0)
{
......
......@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Extensions
internal static bool IsConnected(this Socket client)
{
// This is how you can determine whether a socket is still connected.
var blockingState = client.Blocking;
bool blockingState = client.Blocking;
try
{
......
......@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
internal async Task<string> ReadLineAsync()
{
var lastChar = default(byte);
byte lastChar = default(byte);
int bufferDataLength = 0;
......@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Helpers
while (stream.DataAvailable || await stream.FillBufferAsync())
{
var newChar = stream.ReadByteFromBuffer();
byte newChar = stream.ReadByteFromBuffer();
buffer[bufferDataLength] = newChar;
//if new line
......
......@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy.Helpers
var myProfileDirectory =
new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Mozilla\\Firefox\\Profiles\\")
.GetDirectories("*.default");
var myFfPrefFile = myProfileDirectory[0].FullName + "\\prefs.js";
string myFfPrefFile = myProfileDirectory[0].FullName + "\\prefs.js";
if (!File.Exists(myFfPrefFile))
{
return;
......@@ -26,12 +26,12 @@ namespace Titanium.Web.Proxy.Helpers
// We have a pref file so let''s make sure it has the proxy setting
var myReader = new StreamReader(myFfPrefFile);
var myPrefContents = myReader.ReadToEnd();
string myPrefContents = myReader.ReadToEnd();
myReader.Close();
for (int i = 0; i <= 4; i++)
{
var searchStr = $"user_pref(\"network.proxy.type\", {i});";
string searchStr = $"user_pref(\"network.proxy.type\", {i});";
if (myPrefContents.Contains(searchStr))
{
......
......@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Helpers
//extract the encoding by finding the charset
var parameters = contentType.Split(ProxyConstants.SemiColonSplit);
foreach (var parameter in parameters)
foreach (string parameter in parameters)
{
var encodingSplit = parameter.Split(ProxyConstants.EqualSplit, 2);
if (encodingSplit.Length == 2 && encodingSplit[0].Trim().Equals("charset", StringComparison.CurrentCultureIgnoreCase))
......@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
if (hostname.Split(ProxyConstants.DotSplit).Length > 2)
{
int idx = hostname.IndexOf(ProxyConstants.DotSplit);
var rootDomain = hostname.Substring(idx + 1);
string rootDomain = hostname.Substring(idx + 1);
return "*." + rootDomain;
}
......
......@@ -15,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers
internal static int GetProcessIdFromPort(int port, bool ipV6Enabled)
{
var processId = FindProcessIdFromLocalPort(port, IpVersion.Ipv4);
int processId = FindProcessIdFromLocalPort(port, IpVersion.Ipv4);
if (processId > 0 && !ipV6Enabled)
{
......@@ -43,10 +43,10 @@ namespace Titanium.Web.Proxy.Helpers
{
bool isLocalhost = false;
IPHostEntry localhost = Dns.GetHostEntry("127.0.0.1");
var localhost = Dns.GetHostEntry("127.0.0.1");
if (hostName == localhost.HostName)
{
IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
var hostEntry = Dns.GetHostEntry(hostName);
isLocalhost = hostEntry.AddressList.Any(IPAddress.IsLoopback);
}
......
......@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Helpers
{
var overrides = proxyOverride.Split(';');
var overrides2 = new List<string>();
foreach (var overrideHost in overrides)
foreach (string overrideHost in overrides)
{
if (overrideHost == "<-loopback>")
{
......@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Helpers
private static string BypassStringEscape(string rawString)
{
Match match =
var match =
new Regex("^(?<scheme>.*://)?(?<host>[^:]*)(?<port>:[0-9]{1,5})?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant).Match(rawString);
string empty1;
string rawString1;
......@@ -174,7 +174,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
private static HttpSystemProxyValue ParseProxyValue(string value)
{
var tmp = Regex.Replace(value, @"\s+", " ").Trim();
string tmp = Regex.Replace(value, @"\s+", " ").Trim();
int equalsIndex = tmp.IndexOf("=", StringComparison.InvariantCulture);
if (equalsIndex >= 0)
......
......@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy.Helpers
SaveOriginalProxyConfiguration(reg);
PrepareRegistry(reg);
var exisitingContent = reg.GetValue(regProxyServer) as string;
string exisitingContent = reg.GetValue(regProxyServer) as string;
var existingSystemProxyValues = ProxyInfo.GetSystemProxyValues(exisitingContent);
existingSystemProxyValues.RemoveAll(x => (protocolType & x.ProtocolType) != 0);
if ((protocolType & ProxyProtocolType.Http) != 0)
......@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Helpers
if (reg.GetValue(regProxyServer) != null)
{
var exisitingContent = reg.GetValue(regProxyServer) as string;
string exisitingContent = reg.GetValue(regProxyServer) as string;
var existingSystemProxyValues = ProxyInfo.GetSystemProxyValues(exisitingContent);
existingSystemProxyValues.RemoveAll(x => (protocolType & x.ProtocolType) != 0);
......
......@@ -83,12 +83,12 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns>Collection of <see cref="TcpRow"/>.</returns>
internal static TcpTable GetExtendedTcpTable(IpVersion ipVersion)
{
List<TcpRow> tcpRows = new List<TcpRow>();
var tcpRows = new List<TcpRow>();
IntPtr tcpTable = IntPtr.Zero;
var tcpTable = IntPtr.Zero;
int tcpTableLength = 0;
var ipVersionValue = ipVersion == IpVersion.Ipv4 ? NativeMethods.AfInet : NativeMethods.AfInet6;
int ipVersionValue = ipVersion == IpVersion.Ipv4 ? NativeMethods.AfInet : NativeMethods.AfInet6;
if (NativeMethods.GetExtendedTcpTable(tcpTable, ref tcpTableLength, false, ipVersionValue, (int)NativeMethods.TcpTableType.OwnerPidAll, 0) != 0)
{
......@@ -97,9 +97,9 @@ namespace Titanium.Web.Proxy.Helpers
tcpTable = Marshal.AllocHGlobal(tcpTableLength);
if (NativeMethods.GetExtendedTcpTable(tcpTable, ref tcpTableLength, true, ipVersionValue, (int)NativeMethods.TcpTableType.OwnerPidAll, 0) == 0)
{
NativeMethods.TcpTable table = (NativeMethods.TcpTable)Marshal.PtrToStructure(tcpTable, typeof(NativeMethods.TcpTable));
var table = (NativeMethods.TcpTable)Marshal.PtrToStructure(tcpTable, typeof(NativeMethods.TcpTable));
IntPtr rowPtr = (IntPtr)((long)tcpTable + Marshal.SizeOf(table.length));
var rowPtr = (IntPtr)((long)tcpTable + Marshal.SizeOf(table.length));
for (int i = 0; i < table.length; ++i)
{
......@@ -126,10 +126,10 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns><see cref="TcpRow"/>.</returns>
internal static TcpRow GetTcpRowByLocalPort(IpVersion ipVersion, int localPort)
{
IntPtr tcpTable = IntPtr.Zero;
var tcpTable = IntPtr.Zero;
int tcpTableLength = 0;
var ipVersionValue = ipVersion == IpVersion.Ipv4 ? NativeMethods.AfInet : NativeMethods.AfInet6;
int ipVersionValue = ipVersion == IpVersion.Ipv4 ? NativeMethods.AfInet : NativeMethods.AfInet6;
if (NativeMethods.GetExtendedTcpTable(tcpTable, ref tcpTableLength, false, ipVersionValue, (int)NativeMethods.TcpTableType.OwnerPidAll, 0) != 0)
{
......@@ -138,9 +138,9 @@ namespace Titanium.Web.Proxy.Helpers
tcpTable = Marshal.AllocHGlobal(tcpTableLength);
if (NativeMethods.GetExtendedTcpTable(tcpTable, ref tcpTableLength, true, ipVersionValue, (int)NativeMethods.TcpTableType.OwnerPidAll, 0) == 0)
{
NativeMethods.TcpTable table = (NativeMethods.TcpTable)Marshal.PtrToStructure(tcpTable, typeof(NativeMethods.TcpTable));
var table = (NativeMethods.TcpTable)Marshal.PtrToStructure(tcpTable, typeof(NativeMethods.TcpTable));
IntPtr rowPtr = (IntPtr)((long)tcpTable + Marshal.SizeOf(table.length));
var rowPtr = (IntPtr)((long)tcpTable + Marshal.SizeOf(table.length));
for (int i = 0; i < table.length; ++i)
{
......@@ -199,7 +199,7 @@ namespace Titanium.Web.Proxy.Helpers
if (requestHeaders != null)
{
foreach (var header in requestHeaders.Select(t => t.Value.ToString()))
foreach (string header in requestHeaders.Select(t => t.Value.ToString()))
{
sb.Append(header);
sb.Append(ProxyConstants.NewLine);
......@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy.Helpers
try
{
Stream tunnelStream = tcpConnection.Stream;
var tunnelStream = tcpConnection.Stream;
//Now async relay all server=>client & client=>server data
var sendRelay = clientStream.CopyToAsync(sb?.ToString() ?? string.Empty, tunnelStream);
......
......@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Http
requestLines.AppendLine();
var request = requestLines.ToString();
string request = requestLines.ToString();
var requestBytes = Encoding.ASCII.GetBytes(request);
await stream.WriteAsync(requestBytes, 0, requestBytes.Length);
......@@ -129,8 +129,8 @@ namespace Titanium.Web.Proxy.Http
if (Request.ExpectContinue)
{
var httpResult = (await ServerConnection.StreamReader.ReadLineAsync()).Split(ProxyConstants.SpaceSplit, 3);
var responseStatusCode = httpResult[1].Trim();
var responseStatusDescription = httpResult[2].Trim();
string responseStatusCode = httpResult[1].Trim();
string responseStatusDescription = httpResult[2].Trim();
//find if server is willing for expect continue
if (responseStatusCode.Equals("100")
......@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Http
httpResult = (await ServerConnection.StreamReader.ReadLineAsync()).Split(ProxyConstants.SpaceSplit, 3);
}
var httpVersion = httpResult[0];
string httpVersion = httpResult[0];
var version = HttpHeader.Version11;
if (string.Equals(httpVersion, "HTTP/1.0", StringComparison.OrdinalIgnoreCase))
......
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Models;
......@@ -41,12 +41,12 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("host");
bool hasHeader = RequestHeaders.ContainsKey("host");
return hasHeader ? RequestHeaders["host"].Value : null;
}
set
{
var hasHeader = RequestHeaders.ContainsKey("host");
bool hasHeader = RequestHeaders.ContainsKey("host");
if (hasHeader)
{
RequestHeaders["host"].Value = value;
......@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("content-encoding");
bool hasHeader = RequestHeaders.ContainsKey("content-encoding");
if (hasHeader)
{
......@@ -83,7 +83,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("content-length");
bool hasHeader = RequestHeaders.ContainsKey("content-length");
if (hasHeader == false)
{
......@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy.Http
}
set
{
var hasHeader = RequestHeaders.ContainsKey("content-length");
bool hasHeader = RequestHeaders.ContainsKey("content-length");
var header = RequestHeaders["content-length"];
......@@ -137,7 +137,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("content-type");
bool hasHeader = RequestHeaders.ContainsKey("content-type");
if (hasHeader)
{
......@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Http
}
set
{
var hasHeader = RequestHeaders.ContainsKey("content-type");
bool hasHeader = RequestHeaders.ContainsKey("content-type");
if (hasHeader)
{
......@@ -170,7 +170,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("transfer-encoding");
bool hasHeader = RequestHeaders.ContainsKey("transfer-encoding");
if (hasHeader)
{
......@@ -183,7 +183,7 @@ namespace Titanium.Web.Proxy.Http
}
set
{
var hasHeader = RequestHeaders.ContainsKey("transfer-encoding");
bool hasHeader = RequestHeaders.ContainsKey("transfer-encoding");
if (value)
{
......@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("expect");
bool hasHeader = RequestHeaders.ContainsKey("expect");
if (!hasHeader)
return false;
......@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = RequestHeaders.ContainsKey("upgrade");
bool hasHeader = RequestHeaders.ContainsKey("upgrade");
if (hasHeader == false)
{
......
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Models;
......@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = ResponseHeaders.ContainsKey("content-encoding");
bool hasHeader = ResponseHeaders.ContainsKey("content-encoding");
if (!hasHeader)
return null;
......@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = ResponseHeaders.ContainsKey("connection");
bool hasHeader = ResponseHeaders.ContainsKey("connection");
if (hasHeader)
{
......@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = ResponseHeaders.ContainsKey("content-type");
bool hasHeader = ResponseHeaders.ContainsKey("content-type");
if (hasHeader)
{
......@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = ResponseHeaders.ContainsKey("content-length");
bool hasHeader = ResponseHeaders.ContainsKey("content-length");
if (hasHeader == false)
{
......@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Http
}
set
{
var hasHeader = ResponseHeaders.ContainsKey("content-length");
bool hasHeader = ResponseHeaders.ContainsKey("content-length");
if (value >= 0)
{
......@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy.Http
{
get
{
var hasHeader = ResponseHeaders.ContainsKey("transfer-encoding");
bool hasHeader = ResponseHeaders.ContainsKey("transfer-encoding");
if (hasHeader)
{
......@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Http
}
set
{
var hasHeader = ResponseHeaders.ContainsKey("transfer-encoding");
bool hasHeader = ResponseHeaders.ContainsKey("transfer-encoding");
if (value)
{
......
......@@ -249,7 +249,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
try
{
var empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
}
catch (Exception)
......@@ -279,15 +279,15 @@ namespace Titanium.Web.Proxy.Network.Certificate
}
//Subject
var fullSubject = $"CN={sSubjectCN}";
string fullSubject = $"CN={sSubjectCN}";
//Sig Algo
var HashAlgo = "SHA256";
string HashAlgo = "SHA256";
//Grace Days
var GraceDays = -366;
int GraceDays = -366;
//ValiDays
var ValidDays = 1825;
int ValidDays = 1825;
//KeyLength
var keyLength = 2048;
int keyLength = 2048;
var graceTime = DateTime.Now.AddDays(GraceDays);
var now = DateTime.Now;
......
......@@ -132,7 +132,7 @@ namespace Titanium.Web.Proxy.Network
private string GetRootCertificatePath()
{
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
// dynamically loaded assemblies returns string.Empty location
if (assemblyLocation == string.Empty)
......@@ -140,16 +140,16 @@ namespace Titanium.Web.Proxy.Network
assemblyLocation = Assembly.GetEntryAssembly().Location;
}
var path = Path.GetDirectoryName(assemblyLocation);
string path = Path.GetDirectoryName(assemblyLocation);
if (null == path)
throw new NullReferenceException();
var fileName = Path.Combine(path, "rootCert.pfx");
string fileName = Path.Combine(path, "rootCert.pfx");
return fileName;
}
private X509Certificate2 LoadRootCertificate()
{
var fileName = GetRootCertificatePath();
string fileName = GetRootCertificatePath();
if (!File.Exists(fileName))
return null;
try
......@@ -195,7 +195,7 @@ namespace Titanium.Web.Proxy.Network
{
try
{
var fileName = GetRootCertificatePath();
string fileName = GetRootCertificatePath();
File.WriteAllBytes(fileName, RootCertificate.Export(X509ContentType.Pkcs12));
}
catch (Exception e)
......@@ -231,7 +231,7 @@ namespace Titanium.Web.Proxy.Network
return false;
}
var fileName = Path.GetTempFileName();
string fileName = Path.GetTempFileName();
File.WriteAllBytes(fileName, RootCertificate.Export(X509ContentType.Pkcs12));
var info = new ProcessStartInfo
......@@ -340,7 +340,7 @@ namespace Titanium.Web.Proxy.Network
private X509Certificate2Collection FindCertificates(StoreName storeName, StoreLocation storeLocation, string findValue)
{
X509Store x509Store = new X509Store(storeName, storeLocation);
var x509Store = new X509Store(storeName, storeLocation);
try
{
x509Store.Open(OpenFlags.OpenExistingOnly);
......
......@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
using (var reader = new CustomBinaryReader(stream, server.BufferSize))
{
var result = await reader.ReadLineAsync();
string result = await reader.ReadLineAsync();
if (!new[] { "200 OK", "connection established" }.Any(s => result.ContainsIgnoreCase(s)))
{
......
......@@ -11,21 +11,19 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </seealso>
internal class TcpTable : IEnumerable<TcpRow>
{
private readonly IEnumerable<TcpRow> tcpRows;
/// <summary>
/// Initializes a new instance of the <see cref="TcpTable"/> class.
/// </summary>
/// <param name="tcpRows">TcpRow collection to initialize with.</param>
internal TcpTable(IEnumerable<TcpRow> tcpRows)
{
this.tcpRows = tcpRows;
this.TcpRows = tcpRows;
}
/// <summary>
/// Gets the TCP rows.
/// </summary>
internal IEnumerable<TcpRow> TcpRows => tcpRows;
internal IEnumerable<TcpRow> TcpRows { get; }
/// <summary>
/// Returns an enumerator that iterates through the collection.
......@@ -33,7 +31,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <returns>An enumerator that can be used to iterate through the collection.</returns>
public IEnumerator<TcpRow> GetEnumerator()
{
return tcpRows.GetEnumerator();
return TcpRows.GetEnumerator();
}
/// <summary>
......
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
using System;
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
internal class Common
{
#region Private constants
......@@ -177,7 +177,7 @@
{
ulVersion = (int)SecurityBufferType.SECBUFFER_VERSION;
cBuffers = 1;
SecurityBuffer thisSecBuffer = new SecurityBuffer(bufferSize);
var thisSecBuffer = new SecurityBuffer(bufferSize);
pBuffers = Marshal.AllocHGlobal(Marshal.SizeOf(thisSecBuffer));
Marshal.StructureToPtr(thisSecBuffer, pBuffers, false);
}
......@@ -186,7 +186,7 @@
{
ulVersion = (int)SecurityBufferType.SECBUFFER_VERSION;
cBuffers = 1;
SecurityBuffer thisSecBuffer = new SecurityBuffer(secBufferBytes);
var thisSecBuffer = new SecurityBuffer(secBufferBytes);
pBuffers = Marshal.AllocHGlobal(Marshal.SizeOf(thisSecBuffer));
Marshal.StructureToPtr(thisSecBuffer, pBuffers, false);
}
......@@ -197,7 +197,7 @@
{
if (cBuffers == 1)
{
SecurityBuffer thisSecBuffer = (SecurityBuffer)Marshal.PtrToStructure(pBuffers, typeof(SecurityBuffer));
var thisSecBuffer = (SecurityBuffer)Marshal.PtrToStructure(pBuffers, typeof(SecurityBuffer));
thisSecBuffer.Dispose();
}
else
......@@ -211,7 +211,7 @@
//What we need to do here is to grab a hold of the pvBuffer allocate by the individual
//SecBuffer and release it...
int currentOffset = index * Marshal.SizeOf(typeof(Buffer));
IntPtr secBufferpvBuffer = Marshal.ReadIntPtr(pBuffers, currentOffset + Marshal.SizeOf(typeof(int)) + Marshal.SizeOf(typeof(int)));
var secBufferpvBuffer = Marshal.ReadIntPtr(pBuffers, currentOffset + Marshal.SizeOf(typeof(int)) + Marshal.SizeOf(typeof(int)));
Marshal.FreeHGlobal(secBufferpvBuffer);
}
}
......@@ -232,7 +232,7 @@
if (cBuffers == 1)
{
SecurityBuffer thisSecBuffer = (SecurityBuffer)Marshal.PtrToStructure(pBuffers, typeof(SecurityBuffer));
var thisSecBuffer = (SecurityBuffer)Marshal.PtrToStructure(pBuffers, typeof(SecurityBuffer));
if (thisSecBuffer.cbBuffer > 0)
{
......@@ -267,7 +267,7 @@
//byte array...
int currentOffset = index * Marshal.SizeOf(typeof(Buffer));
int bytesToCopy = Marshal.ReadInt32(pBuffers, currentOffset);
IntPtr secBufferpvBuffer = Marshal.ReadIntPtr(pBuffers, currentOffset + Marshal.SizeOf(typeof(int)) + Marshal.SizeOf(typeof(int)));
var secBufferpvBuffer = Marshal.ReadIntPtr(pBuffers, currentOffset + Marshal.SizeOf(typeof(int)) + Marshal.SizeOf(typeof(int)));
Marshal.Copy(secBufferpvBuffer, buffer, bufferIndex, bytesToCopy);
bufferIndex += bytesToCopy;
}
......
......@@ -27,17 +27,17 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
using System;
internal sealed class LittleEndian
{
private LittleEndian()
{
}
unsafe private static byte[] GetUShortBytes(byte*bytes)
private static unsafe byte[] GetUShortBytes(byte*bytes)
{
if (BitConverter.IsLittleEndian)
{
......@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return new[] { bytes[1], bytes[0] };
}
unsafe private static byte[] GetUIntBytes(byte*bytes)
private static unsafe byte[] GetUIntBytes(byte*bytes)
{
if (BitConverter.IsLittleEndian)
{
......@@ -57,7 +57,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return new[] { bytes[3], bytes[2], bytes[1], bytes[0] };
}
unsafe private static byte[] GetULongBytes(byte*bytes)
private static unsafe byte[] GetULongBytes(byte*bytes)
{
if (BitConverter.IsLittleEndian)
{
......@@ -72,52 +72,52 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return new[] { value ? (byte)1 : (byte)0 };
}
unsafe internal static byte[] GetBytes(char value)
internal static unsafe byte[] GetBytes(char value)
{
return GetUShortBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(short value)
internal static unsafe byte[] GetBytes(short value)
{
return GetUShortBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(int value)
internal static unsafe byte[] GetBytes(int value)
{
return GetUIntBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(long value)
internal static unsafe byte[] GetBytes(long value)
{
return GetULongBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(ushort value)
internal static unsafe byte[] GetBytes(ushort value)
{
return GetUShortBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(uint value)
internal static unsafe byte[] GetBytes(uint value)
{
return GetUIntBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(ulong value)
internal static unsafe byte[] GetBytes(ulong value)
{
return GetULongBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(float value)
internal static unsafe byte[] GetBytes(float value)
{
return GetUIntBytes((byte*)&value);
}
unsafe internal static byte[] GetBytes(double value)
internal static unsafe byte[] GetBytes(double value)
{
return GetULongBytes((byte*)&value);
}
unsafe private static void UShortFromBytes(byte*dst, byte[] src, int startIndex)
private static unsafe void UShortFromBytes(byte*dst, byte[] src, int startIndex)
{
if (BitConverter.IsLittleEndian)
{
......@@ -131,7 +131,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
}
}
unsafe private static void UIntFromBytes(byte*dst, byte[] src, int startIndex)
private static unsafe void UIntFromBytes(byte*dst, byte[] src, int startIndex)
{
if (BitConverter.IsLittleEndian)
{
......@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
}
}
unsafe private static void ULongFromBytes(byte*dst, byte[] src, int startIndex)
private static unsafe void ULongFromBytes(byte*dst, byte[] src, int startIndex)
{
if (BitConverter.IsLittleEndian)
{
......@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return value[startIndex] != 0;
}
unsafe internal static char ToChar(byte[] value, int startIndex)
internal static unsafe char ToChar(byte[] value, int startIndex)
{
char ret;
......@@ -177,7 +177,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static short ToInt16(byte[] value, int startIndex)
internal static unsafe short ToInt16(byte[] value, int startIndex)
{
short ret;
......@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static int ToInt32(byte[] value, int startIndex)
internal static unsafe int ToInt32(byte[] value, int startIndex)
{
int ret;
......@@ -195,7 +195,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static long ToInt64(byte[] value, int startIndex)
internal static unsafe long ToInt64(byte[] value, int startIndex)
{
long ret;
......@@ -204,7 +204,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static ushort ToUInt16(byte[] value, int startIndex)
internal static unsafe ushort ToUInt16(byte[] value, int startIndex)
{
ushort ret;
......@@ -213,7 +213,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static uint ToUInt32(byte[] value, int startIndex)
internal static unsafe uint ToUInt32(byte[] value, int startIndex)
{
uint ret;
......@@ -222,7 +222,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static ulong ToUInt64(byte[] value, int startIndex)
internal static unsafe ulong ToUInt64(byte[] value, int startIndex)
{
ulong ret;
......@@ -231,7 +231,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static float ToSingle(byte[] value, int startIndex)
internal static unsafe float ToSingle(byte[] value, int startIndex)
{
float ret;
......@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return ret;
}
unsafe internal static double ToDouble(byte[] value, int startIndex)
internal static unsafe double ToDouble(byte[] value, int startIndex)
{
double ret;
......
......@@ -33,14 +33,14 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
using System;
using System.Text;
internal class Message
{
static private readonly byte[] header = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00 };
private static readonly byte[] header = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00 };
internal Message(byte[] message)
{
......
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
using System;
using System;
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
/// <summary>
/// Status of authenticated session
/// </summary>
......
// http://pinvoke.net/default.aspx/secur32/InitializeSecurityContext.html
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
using System;
using System.Linq;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Principal;
using static Common;
using System.Threading.Tasks;
internal class WinAuthEndPoint
{
......@@ -31,9 +32,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
byte[] token;
//null for initial call
SecurityBufferDesciption serverToken = new SecurityBufferDesciption();
var serverToken = new SecurityBufferDesciption();
SecurityBufferDesciption clientToken = new SecurityBufferDesciption(MaximumTokenSize);
var clientToken = new SecurityBufferDesciption(MaximumTokenSize);
try
{
......@@ -102,9 +103,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
byte[] token;
//user server challenge
SecurityBufferDesciption serverToken = new SecurityBufferDesciption(serverChallenge);
var serverToken = new SecurityBufferDesciption(serverChallenge);
SecurityBufferDesciption clientToken = new SecurityBufferDesciption(MaximumTokenSize);
var clientToken = new SecurityBufferDesciption(MaximumTokenSize);
try
{
......
using Titanium.Web.Proxy.Network.WinAuth.Security;
using System;
using System;
using Titanium.Web.Proxy.Network.WinAuth.Security;
namespace Titanium.Web.Proxy.Network.WinAuth
{
......
......@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy
var header = httpHeaders.FirstOrDefault(t => t.Name == "Proxy-Authorization");
if (header == null)
throw new NullReferenceException();
var headerValue = header.Value.Trim();
string headerValue = header.Value.Trim();
if (!headerValue.StartsWith("basic", StringComparison.CurrentCultureIgnoreCase))
{
//Return not authorized
......@@ -42,7 +42,7 @@ namespace Titanium.Web.Proxy
headerValue = headerValue.Substring(5).Trim();
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(headerValue));
string decoded = Encoding.UTF8.GetString(Convert.FromBase64String(headerValue));
if (decoded.Contains(":") == false)
{
//Return not authorized
......@@ -50,8 +50,8 @@ namespace Titanium.Web.Proxy
return false;
}
var username = decoded.Substring(0, decoded.IndexOf(':'));
var password = decoded.Substring(decoded.IndexOf(':') + 1);
string username = decoded.Substring(0, decoded.IndexOf(':'));
string password = decoded.Substring(decoded.IndexOf(':') + 1);
return await AuthenticateUserFunc(username, password);
}
catch (Exception e)
......
......@@ -562,7 +562,7 @@ namespace Titanium.Web.Proxy
if (!RunTime.IsRunningOnMono)
{
var setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>().Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy);
bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>().Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy);
if (setAsSystemProxy)
{
......
......@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
/// <returns></returns>
private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpClient)
{
var disposed = false;
bool disposed = false;
var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize);
......@@ -48,7 +48,7 @@ namespace Titanium.Web.Proxy
try
{
//read the first line HTTP command
var httpCmd = await clientStreamReader.ReadLineAsync();
string httpCmd = await clientStreamReader.ReadLineAsync();
if (string.IsNullOrEmpty(httpCmd))
{
......@@ -59,7 +59,7 @@ namespace Titanium.Web.Proxy
var httpCmdSplit = httpCmd.Split(ProxyConstants.SpaceSplit, 3);
//Find the request Verb
var httpVerb = httpCmdSplit[0].ToUpper();
string httpVerb = httpCmdSplit[0].ToUpper();
httpRemoteUri = httpVerb == "CONNECT" ? new Uri("http://" + httpCmdSplit[1]) : new Uri(httpCmdSplit[1]);
......@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy
var version = HttpHeader.Version11;
if (httpCmdSplit.Length == 3)
{
var httpVersion = httpCmdSplit[2].Trim();
string httpVersion = httpCmdSplit[2].Trim();
if (string.Equals(httpVersion, "HTTP/1.0", StringComparison.OrdinalIgnoreCase))
{
......@@ -117,7 +117,7 @@ namespace Titanium.Web.Proxy
{
sslStream = new SslStream(clientStream);
var certName = HttpHelper.GetWildCardDomainName(httpRemoteUri.Host);
string certName = HttpHelper.GetWildCardDomainName(httpRemoteUri.Host);
var certificate = endPoint.GenericCertificate ?? CertificateManager.CreateCertificate(certName, false);
......@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy
};
//now read the request line
var httpCmd = await clientStreamReader.ReadLineAsync();
string httpCmd = await clientStreamReader.ReadLineAsync();
//Now create the request
disposed = await HandleHttpSessionRequest(tcpClient, httpCmd, clientStream, clientStreamReader, clientStreamWriter,
......@@ -287,13 +287,13 @@ namespace Titanium.Web.Proxy
//break up the line into three components (method, remote URL & Http Version)
var httpCmdSplit = httpCmd.Split(ProxyConstants.SpaceSplit, 3);
var httpMethod = httpCmdSplit[0];
string httpMethod = httpCmdSplit[0];
//find the request HTTP version
var httpVersion = HttpHeader.Version11;
if (httpCmdSplit.Length == 3)
{
var httpVersionString = httpCmdSplit[2].Trim();
string httpVersionString = httpCmdSplit[2].Trim();
if (string.Equals(httpVersionString, "HTTP/1.0", StringComparison.OrdinalIgnoreCase))
{
......
......@@ -36,7 +36,7 @@ namespace Titanium.Web.Proxy
&& !RunTime.IsRunningOnMono
&& args.WebSession.Response.ResponseStatusCode == "401")
{
var disposed = await Handle401UnAuthorized(args);
bool disposed = await Handle401UnAuthorized(args);
if (disposed)
{
......@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy
{
//clear current response
await args.ClearResponse();
var disposed = await HandleHttpSessionRequestInternal(args.WebSession.ServerConnection, args, false);
bool disposed = await HandleHttpSessionRequestInternal(args.WebSession.ServerConnection, args, false);
return disposed;
}
......@@ -82,8 +82,8 @@ namespace Titanium.Web.Proxy
if (args.WebSession.Response.ResponseBodyRead)
{
var isChunked = args.WebSession.Response.IsChunked;
var contentEncoding = args.WebSession.Response.ContentEncoding;
bool isChunked = args.WebSession.Response.IsChunked;
string contentEncoding = args.WebSession.Response.ContentEncoding;
if (contentEncoding != null)
{
......@@ -198,8 +198,8 @@ namespace Titanium.Web.Proxy
private void FixProxyHeaders(Dictionary<string, HttpHeader> headers)
{
//If proxy-connection close was returned inform to close the connection
var hasProxyHeader = headers.ContainsKey("proxy-connection");
var hasConnectionheader = headers.ContainsKey("connection");
bool hasProxyHeader = headers.ContainsKey("proxy-connection");
bool hasConnectionheader = headers.ContainsKey("connection");
if (hasProxyHeader)
{
......
......@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy
if (authHeader != null)
{
var scheme = authSchemes.FirstOrDefault(x => authHeader.Value.Equals(x, StringComparison.OrdinalIgnoreCase));
string scheme = authSchemes.FirstOrDefault(x => authHeader.Value.Equals(x, StringComparison.OrdinalIgnoreCase));
//clear any existing headers to avoid confusing bad servers
if (args.WebSession.Request.NonUniqueRequestHeaders.ContainsKey("Authorization"))
......@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy
//initial value will match exactly any of the schemes
if (scheme != null)
{
var clientToken = WinAuthHandler.GetInitialAuthToken(args.WebSession.Request.Host, scheme, args.Id);
string clientToken = WinAuthHandler.GetInitialAuthToken(args.WebSession.Request.Host, scheme, args.Id);
var auth = new HttpHeader("Authorization", string.Concat(scheme, clientToken));
......@@ -118,8 +118,8 @@ namespace Titanium.Web.Proxy
scheme = authSchemes.FirstOrDefault(x => authHeader.Value.StartsWith(x, StringComparison.OrdinalIgnoreCase) &&
authHeader.Value.Length > x.Length + 1);
var serverToken = authHeader.Value.Substring(scheme.Length + 1);
var clientToken = WinAuthHandler.GetFinalAuthToken(args.WebSession.Request.Host, serverToken, args.Id);
string serverToken = authHeader.Value.Substring(scheme.Length + 1);
string clientToken = WinAuthHandler.GetFinalAuthToken(args.WebSession.Request.Host, serverToken, args.Id);
//there will be an existing header from initial client request
args.WebSession.Request.RequestHeaders["Authorization"] = new HttpHeader("Authorization", string.Concat(scheme, clientToken));
......@@ -140,7 +140,7 @@ namespace Titanium.Web.Proxy
//request again with updated authorization header
//and server cookies
var disposed = await HandleHttpSessionRequestInternal(args.WebSession.ServerConnection, args, false);
bool disposed = await HandleHttpSessionRequestInternal(args.WebSession.ServerConnection, args, false);
return disposed;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment