diff --git a/Emby.Common.Implementations/BaseApplicationHost.cs b/Emby.Common.Implementations/BaseApplicationHost.cs index d3d8672bea..dd4be9aae4 100644 --- a/Emby.Common.Implementations/BaseApplicationHost.cs +++ b/Emby.Common.Implementations/BaseApplicationHost.cs @@ -39,10 +39,6 @@ using MediaBrowser.Model.System; using MediaBrowser.Model.Tasks; using MediaBrowser.Model.Threading; -#if NETSTANDARD1_6 -using System.Runtime.Loader; -#endif - namespace Emby.Common.Implementations { /// @@ -306,7 +302,6 @@ namespace Emby.Common.Implementations builder.AppendLine(string.Format("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs()))); -#if NET46 builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion)); builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem)); builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess)); @@ -320,7 +315,6 @@ namespace Emby.Common.Implementations builder.AppendLine("Mono: " + displayName.Invoke(null, null)); } } -#endif builder.AppendLine(string.Format("Processor count: {0}", Environment.ProcessorCount)); builder.AppendLine(string.Format("Program data path: {0}", appPaths.ProgramDataPath)); @@ -336,9 +330,7 @@ namespace Emby.Common.Implementations try { // Increase the max http request limit -#if NET46 ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit); -#endif } catch (Exception ex) { @@ -436,7 +428,6 @@ namespace Emby.Common.Implementations if (assemblyPlugin != null) { -#if NET46 var assembly = plugin.GetType().Assembly; var assemblyName = assembly.GetName(); @@ -447,21 +438,7 @@ namespace Emby.Common.Implementations var assemblyFilePath = Path.Combine(ApplicationPaths.PluginsPath, assemblyFileName); assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId); -#elif NETSTANDARD1_6 - var typeInfo = plugin.GetType().GetTypeInfo(); - var assembly = typeInfo.Assembly; - var assemblyName = assembly.GetName(); - - var attribute = (GuidAttribute)assembly.GetCustomAttribute(typeof(GuidAttribute)); - var assemblyId = new Guid(attribute.Value); - - var assemblyFileName = assemblyName.Name + ".dll"; - var assemblyFilePath = Path.Combine(ApplicationPaths.PluginsPath, assemblyFileName); - - assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId); -#else -return null; -#endif + return null; } var isFirstRun = !File.Exists(plugin.ConfigurationFilePath); @@ -492,17 +469,7 @@ return null; AllConcreteTypes = assemblies .SelectMany(GetTypes) - .Where(t => - { -#if NET46 - return t.IsClass && !t.IsAbstract && !t.IsInterface && !t.IsGenericType; -#endif -#if NETSTANDARD1_6 - var typeInfo = t.GetTypeInfo(); - return typeInfo.IsClass && !typeInfo.IsAbstract && !typeInfo.IsInterface && !typeInfo.IsGenericType; -#endif - return false; - }) + .Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && !t.IsGenericType) .ToArray(); } @@ -717,13 +684,7 @@ return null; { try { -#if NET46 return Assembly.Load(File.ReadAllBytes(file)); -#elif NETSTANDARD1_6 - - return AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file))); -#endif - return null; } catch (Exception ex) { @@ -742,14 +703,7 @@ return null; { var currentType = typeof(T); -#if NET46 return AllConcreteTypes.Where(currentType.IsAssignableFrom); -#elif NETSTANDARD1_6 - var currentTypeInfo = currentType.GetTypeInfo(); - - return AllConcreteTypes.Where(currentTypeInfo.IsAssignableFrom); -#endif - return new List(); } /// diff --git a/Emby.Common.Implementations/Diagnostics/CommonProcess.cs b/Emby.Common.Implementations/Diagnostics/CommonProcess.cs index 462345ced5..f6ca6cf9c8 100644 --- a/Emby.Common.Implementations/Diagnostics/CommonProcess.cs +++ b/Emby.Common.Implementations/Diagnostics/CommonProcess.cs @@ -31,14 +31,12 @@ namespace Emby.Common.Implementations.Diagnostics RedirectStandardOutput = options.RedirectStandardOutput }; -#if NET46 startInfo.ErrorDialog = options.ErrorDialog; if (options.IsHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; } -#endif _process = new Process { diff --git a/Emby.Common.Implementations/Emby.Common.Implementations.csproj b/Emby.Common.Implementations/Emby.Common.Implementations.csproj new file mode 100644 index 0000000000..6e818b163d --- /dev/null +++ b/Emby.Common.Implementations/Emby.Common.Implementations.csproj @@ -0,0 +1,381 @@ + + + + + Debug + AnyCPU + {1E37A338-9F57-4B70-BD6D-BB9C591E319B} + Library + Properties + Emby.Common.Implementations + Emby.Common.Implementations + v4.6.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NLog.4.4.3\lib\net45\NLog.dll + True + + + ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll + True + + + ..\packages\SharpCompress.0.14.0\lib\net45\SharpCompress.dll + True + + + ..\packages\SimpleInjector.4.0.7\lib\net45\SimpleInjector.dll + True + + + + + + + + + + + + + Properties\SharedVersion.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {9142eefa-7570-41e1-bfcc-468bb571af2f} + MediaBrowser.Common + + + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} + MediaBrowser.Model + + + + + + + + \ No newline at end of file diff --git a/Emby.Common.Implementations/Emby.Common.Implementations.xproj b/Emby.Common.Implementations/Emby.Common.Implementations.xproj deleted file mode 100644 index 5bb6e4e589..0000000000 --- a/Emby.Common.Implementations/Emby.Common.Implementations.xproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 5a27010a-09c6-4e86-93ea-437484c10917 - Emby.Common.Implementations - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - - - - - \ No newline at end of file diff --git a/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs index 27fc642f14..89aa787b56 100644 --- a/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -10,7 +10,7 @@ namespace Emby.Common.Implementations.EnvironmentInfo { public class EnvironmentInfo : IEnvironmentInfo { - public MediaBrowser.Model.System.Architecture? CustomArchitecture { get; set; } + public Architecture? CustomArchitecture { get; set; } public MediaBrowser.Model.System.OperatingSystem? CustomOperatingSystem { get; set; } public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem @@ -22,7 +22,6 @@ namespace Emby.Common.Implementations.EnvironmentInfo return CustomOperatingSystem.Value; } -#if NET46 switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: @@ -32,20 +31,7 @@ namespace Emby.Common.Implementations.EnvironmentInfo case PlatformID.Unix: return MediaBrowser.Model.System.OperatingSystem.Linux; } -#elif NETSTANDARD1_6 - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return OperatingSystem.OSX; - } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return OperatingSystem.Windows; - } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return OperatingSystem.Linux; - } -#endif + return MediaBrowser.Model.System.OperatingSystem.Windows; } } @@ -54,12 +40,7 @@ namespace Emby.Common.Implementations.EnvironmentInfo { get { -#if NET46 return Environment.OSVersion.Platform.ToString(); -#elif NETSTANDARD1_6 - return System.Runtime.InteropServices.RuntimeInformation.OSDescription; -#endif - return "Operating System"; } } @@ -67,12 +48,7 @@ namespace Emby.Common.Implementations.EnvironmentInfo { get { -#if NET46 return Environment.OSVersion.Version.ToString() + " " + Environment.OSVersion.ServicePack.ToString(); -#elif NETSTANDARD1_6 - return System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; -#endif - return "1.0"; } } @@ -84,7 +60,7 @@ namespace Emby.Common.Implementations.EnvironmentInfo } } - public MediaBrowser.Model.System.Architecture SystemArchitecture + public Architecture SystemArchitecture { get { @@ -92,22 +68,8 @@ namespace Emby.Common.Implementations.EnvironmentInfo { return CustomArchitecture.Value; } -#if NET46 + return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86; -#elif NETSTANDARD1_6 - switch(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture) - { - case System.Runtime.InteropServices.Architecture.Arm: - return MediaBrowser.Model.System.Architecture.Arm; - case System.Runtime.InteropServices.Architecture.Arm64: - return MediaBrowser.Model.System.Architecture.Arm64; - case System.Runtime.InteropServices.Architecture.X64: - return MediaBrowser.Model.System.Architecture.X64; - case System.Runtime.InteropServices.Architecture.X86: - return MediaBrowser.Model.System.Architecture.X86; - } -#endif - return MediaBrowser.Model.System.Architecture.X64; } } diff --git a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs index eb9bc1bd06..c2a310c0e1 100644 --- a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -66,13 +66,11 @@ namespace Emby.Common.Implementations.HttpClientManager _appPaths = appPaths; _defaultUserAgentFn = defaultUserAgentFn; -#if NET46 // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c ServicePointManager.Expect100Continue = false; // Trakt requests sometimes fail without this ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls; -#endif } /// @@ -129,7 +127,6 @@ namespace Emby.Common.Implementations.HttpClientManager private void AddIpv4Option(HttpWebRequest request, HttpRequestOptions options) { -#if NET46 request.ServicePoint.BindIPEndPointDelegate = (servicePount, remoteEndPoint, retryCount) => { if (remoteEndPoint.AddressFamily == AddressFamily.InterNetwork) @@ -138,7 +135,6 @@ namespace Emby.Common.Implementations.HttpClientManager } throw new InvalidOperationException("no IPv4 address"); }; -#endif } private WebRequest GetRequest(HttpRequestOptions options, string method) @@ -165,7 +161,6 @@ namespace Emby.Common.Implementations.HttpClientManager AddRequestHeaders(httpWebRequest, options); -#if NET46 if (options.EnableHttpCompression) { if (options.DecompressionMethod.HasValue) @@ -183,48 +178,33 @@ namespace Emby.Common.Implementations.HttpClientManager { httpWebRequest.AutomaticDecompression = DecompressionMethods.None; } -#endif } -#if NET46 request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); -#endif if (httpWebRequest != null) { if (options.EnableKeepAlive) { -#if NET46 httpWebRequest.KeepAlive = true; -#endif } } request.Method = method; -#if NET46 request.Timeout = options.TimeoutMs; -#endif if (httpWebRequest != null) { if (!string.IsNullOrEmpty(options.Host)) { -#if NET46 httpWebRequest.Host = options.Host; -#elif NETSTANDARD1_6 - httpWebRequest.Headers["Host"] = options.Host; -#endif } if (!string.IsNullOrEmpty(options.Referer)) { -#if NET46 httpWebRequest.Referer = options.Referer; -#elif NETSTANDARD1_6 - httpWebRequest.Headers["Referer"] = options.Referer; -#endif } } @@ -235,9 +215,7 @@ namespace Emby.Common.Implementations.HttpClientManager { request.Credentials = GetCredential(url, parts[0], parts[1]); // TODO: .net core ?? -#if NET46 request.PreAuthenticate = true; -#endif } } @@ -269,11 +247,7 @@ namespace Emby.Common.Implementations.HttpClientManager } else { -#if NET46 request.Headers.Set(header.Key, header.Value); -#elif NETSTANDARD1_6 - request.Headers[header.Key] = header.Value; -#endif } } @@ -285,11 +259,7 @@ namespace Emby.Common.Implementations.HttpClientManager private void SetUserAgent(HttpWebRequest request, string userAgent) { -#if NET46 request.UserAgent = userAgent; -#elif NETSTANDARD1_6 - request.Headers["User-Agent"] = userAgent; -#endif } /// @@ -465,9 +435,7 @@ namespace Emby.Common.Implementations.HttpClientManager httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded"; -#if NET46 httpWebRequest.ContentLength = bytes.Length; -#endif (await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length); } catch (Exception ex) @@ -950,7 +918,6 @@ namespace Emby.Common.Implementations.HttpClientManager private Task GetResponseAsync(WebRequest request, TimeSpan timeout) { -#if NET46 var taskCompletion = new TaskCompletionSource(); Task asyncTask = Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null); @@ -963,9 +930,6 @@ namespace Emby.Common.Implementations.HttpClientManager asyncTask.ContinueWith(callback.OnError, TaskContinuationOptions.OnlyOnFaulted); return taskCompletion.Task; -#endif - - return request.GetResponseAsync(); } private static void TimeoutCallback(object state, bool timedOut) diff --git a/Emby.Common.Implementations/Net/SocketFactory.cs b/Emby.Common.Implementations/Net/SocketFactory.cs index 39f236afaa..3562a86444 100644 --- a/Emby.Common.Implementations/Net/SocketFactory.cs +++ b/Emby.Common.Implementations/Net/SocketFactory.cs @@ -188,16 +188,7 @@ namespace Emby.Common.Implementations.Net try { -#if NET46 - retVal.ExclusiveAddressUse = false; -#else - // The ExclusiveAddressUse acceptSocket option is a Windows-specific option that, when set to "true," tells Windows not to allow another acceptSocket to use the same local address as this acceptSocket - // See https://github.com/dotnet/corefx/pull/11509 for more details - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) - { - retVal.ExclusiveAddressUse = false; - } -#endif + retVal.ExclusiveAddressUse = false; //retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive); diff --git a/Emby.Common.Implementations/Net/UdpSocket.cs b/Emby.Common.Implementations/Net/UdpSocket.cs index f9181eb6ab..678cf6f035 100644 --- a/Emby.Common.Implementations/Net/UdpSocket.cs +++ b/Emby.Common.Implementations/Net/UdpSocket.cs @@ -116,129 +116,64 @@ namespace Emby.Common.Implementations.Net private set; } - public Task ReceiveAsync(CancellationToken cancellationToken) + private readonly AsyncCallback _defaultAsyncCallback = (i) => { }; + + public IAsyncResult BeginReceive(byte[] buffer, int offset, int count, AsyncCallback callback) { - ThrowIfDisposed(); - var tcs = new TaskCompletionSource(); EndPoint receivedFromEndPoint = new IPEndPoint(IPAddress.Any, 0); - var state = new AsyncReceiveState(_Socket, receivedFromEndPoint); - state.TaskCompletionSource = tcs; - - cancellationToken.Register(() => tcs.TrySetCanceled()); - - _receiveSocketAsyncEventArgs.RemoteEndPoint = receivedFromEndPoint; - _currentReceiveTaskCompletionSource = tcs; - - try - { - var willRaiseEvent = _Socket.ReceiveFromAsync(_receiveSocketAsyncEventArgs); - - if (!willRaiseEvent) - { - _receiveSocketAsyncEventArgs_Completed(this, _receiveSocketAsyncEventArgs); - } - } - catch (Exception ex) - { - tcs.TrySetException(ex); - } - - return tcs.Task; + return _Socket.BeginReceiveFrom(buffer, offset, count, SocketFlags.None, ref receivedFromEndPoint, callback, buffer); } - public Task SendAsync(byte[] buffer, int size, IpEndPointInfo endPoint, CancellationToken cancellationToken) + public SocketReceiveResult EndReceive(IAsyncResult result) { - ThrowIfDisposed(); + IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); + EndPoint remoteEndPoint = (EndPoint)sender; - if (buffer == null) throw new ArgumentNullException("messageData"); - if (endPoint == null) throw new ArgumentNullException("endPoint"); + var receivedBytes = _Socket.EndReceiveFrom(result, ref remoteEndPoint); + var buffer = (byte[]) result.AsyncState; + + return new SocketReceiveResult + { + ReceivedBytes = receivedBytes, + RemoteEndPoint = ToIpEndPointInfo((IPEndPoint)remoteEndPoint), + Buffer = buffer, + LocalIPAddress = LocalIPAddress + }; + } + + public Task ReceiveAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + var result = BeginReceive(buffer, offset, count, _defaultAsyncCallback); + + return Task.Factory.FromAsync(result, EndReceive); + } + + public Task ReceiveAsync(CancellationToken cancellationToken) + { + var buffer = new byte[8192]; + + return ReceiveAsync(buffer, 0, buffer.Length, cancellationToken); + } + + public Task SendToAsync(byte[] buffer, int offset, int size, IpEndPointInfo endPoint, CancellationToken cancellationToken) + { + var result = BeginSendTo(buffer, offset, size, endPoint, _defaultAsyncCallback, null); + + return Task.Factory.FromAsync(result, EndSendTo); + } + + public IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, IpEndPointInfo endPoint, AsyncCallback callback, object state) + { var ipEndPoint = NetworkManager.ToIPEndPoint(endPoint); -#if NETSTANDARD1_6 - - if (size != buffer.Length) - { - byte[] copy = new byte[size]; - Buffer.BlockCopy(buffer, 0, copy, 0, size); - buffer = copy; - } - - cancellationToken.ThrowIfCancellationRequested(); - - _Socket.SendTo(buffer, ipEndPoint); - return Task.FromResult(true); -#else - var taskSource = new TaskCompletionSource(); - - try - { - _Socket.BeginSendTo(buffer, 0, size, SocketFlags.None, ipEndPoint, result => - { - if (cancellationToken.IsCancellationRequested) - { - taskSource.TrySetCanceled(); - return; - } - try - { - _Socket.EndSend(result); - taskSource.TrySetResult(true); - } - catch (Exception ex) - { - taskSource.TrySetException(ex); - } - - }, null); - } - catch (Exception ex) - { - taskSource.TrySetException(ex); - } - - return taskSource.Task; -#endif - //ThrowIfDisposed(); - - //if (buffer == null) throw new ArgumentNullException("messageData"); - //if (endPoint == null) throw new ArgumentNullException("endPoint"); - - //cancellationToken.ThrowIfCancellationRequested(); - - //var tcs = new TaskCompletionSource(); - - //cancellationToken.Register(() => tcs.TrySetCanceled()); - - //_sendSocketAsyncEventArgs.SetBuffer(buffer, 0, size); - //_sendSocketAsyncEventArgs.RemoteEndPoint = NetworkManager.ToIPEndPoint(endPoint); - //_currentSendTaskCompletionSource = tcs; - - //var willRaiseEvent = _Socket.SendAsync(_sendSocketAsyncEventArgs); - - //if (!willRaiseEvent) - //{ - // _sendSocketAsyncEventArgs_Completed(this, _sendSocketAsyncEventArgs); - //} - - //return tcs.Task; + return _Socket.BeginSendTo(buffer, offset, size, SocketFlags.None, ipEndPoint, callback, state); } - public async Task SendWithLockAsync(byte[] buffer, int size, IpEndPointInfo endPoint, CancellationToken cancellationToken) + public int EndSendTo(IAsyncResult result) { - ThrowIfDisposed(); - - //await _sendLock.WaitAsync(cancellationToken).ConfigureAwait(false); - - try - { - await SendAsync(buffer, size, endPoint, cancellationToken).ConfigureAwait(false); - } - finally - { - //_sendLock.Release(); - } + return _Socket.EndSendTo(result); } protected override void Dispose(bool disposing) @@ -274,36 +209,6 @@ namespace Emby.Common.Implementations.Net return NetworkManager.ToIpEndPointInfo(endpoint); } - private void ProcessResponse(IAsyncResult asyncResult) - { -#if NET46 - var state = asyncResult.AsyncState as AsyncReceiveState; - try - { - var bytesRead = state.Socket.EndReceiveFrom(asyncResult, ref state.RemoteEndPoint); - - var ipEndPoint = state.RemoteEndPoint as IPEndPoint; - state.TaskCompletionSource.SetResult( - new SocketReceiveResult - { - Buffer = state.Buffer, - ReceivedBytes = bytesRead, - RemoteEndPoint = ToIpEndPointInfo(ipEndPoint), - LocalIPAddress = LocalIPAddress - } - ); - } - catch (ObjectDisposedException) - { - state.TaskCompletionSource.SetCanceled(); - } - catch (Exception ex) - { - state.TaskCompletionSource.SetException(ex); - } -#endif - } - private class AsyncReceiveState { public AsyncReceiveState(Socket socket, EndPoint remoteEndPoint) diff --git a/Emby.Common.Implementations/Properties/AssemblyInfo.cs b/Emby.Common.Implementations/Properties/AssemblyInfo.cs index 1a5abcb274..787f18997c 100644 --- a/Emby.Common.Implementations/Properties/AssemblyInfo.cs +++ b/Emby.Common.Implementations/Properties/AssemblyInfo.cs @@ -2,18 +2,33 @@ using System.Runtime.CompilerServices; 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("Emby.Common.Implementations")] +[assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Emby.Common.Implementations")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("5a27010a-09c6-4e86-93ea-437484c10917")] +[assembly: Guid("1e37a338-9f57-4b70-bd6d-bb9c591e319b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/Emby.Common.Implementations/Reflection/AssemblyInfo.cs b/Emby.Common.Implementations/Reflection/AssemblyInfo.cs index 7a92f02d6b..87821bf7ab 100644 --- a/Emby.Common.Implementations/Reflection/AssemblyInfo.cs +++ b/Emby.Common.Implementations/Reflection/AssemblyInfo.cs @@ -9,18 +9,12 @@ namespace Emby.Common.Implementations.Reflection { public Stream GetManifestResourceStream(Type type, string resource) { -#if NET46 return type.Assembly.GetManifestResourceStream(resource); -#endif - return type.GetTypeInfo().Assembly.GetManifestResourceStream(resource); } public string[] GetManifestResourceNames(Type type) { -#if NET46 return type.Assembly.GetManifestResourceNames(); -#endif - return type.GetTypeInfo().Assembly.GetManifestResourceNames(); } public Assembly[] GetCurrentAssemblies() diff --git a/Emby.Common.Implementations/Serialization/XmlSerializer.cs b/Emby.Common.Implementations/Serialization/XmlSerializer.cs index 3583f998e5..ad2708387b 100644 --- a/Emby.Common.Implementations/Serialization/XmlSerializer.cs +++ b/Emby.Common.Implementations/Serialization/XmlSerializer.cs @@ -78,18 +78,11 @@ namespace Emby.Common.Implementations.Serialization /// The stream. public void SerializeToStream(object obj, Stream stream) { -#if NET46 - using (var writer = new XmlTextWriter(stream, null)) + using (var writer = new XmlTextWriter(stream, null)) { writer.Formatting = Formatting.Indented; SerializeToWriter(obj, writer); } -#else - using (var writer = XmlWriter.Create(stream)) - { - SerializeToWriter(obj, writer); - } -#endif } /// diff --git a/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs b/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs index 806290cf44..35c266cdb2 100644 --- a/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs +++ b/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs @@ -11,9 +11,7 @@ namespace Emby.Common.Implementations.Xml if (!enableValidation) { -#if NET46 settings.ValidationType = ValidationType.None; -#endif } return settings; diff --git a/Emby.Common.Implementations/packages.config b/Emby.Common.Implementations/packages.config new file mode 100644 index 0000000000..18022eb2e0 --- /dev/null +++ b/Emby.Common.Implementations/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Emby.Common.Implementations/project.json b/Emby.Common.Implementations/project.json deleted file mode 100644 index ff60c740e8..0000000000 --- a/Emby.Common.Implementations/project.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "version": "1.0.0-*", - - "dependencies": { - - }, - - "frameworks": { - "net46": { - "frameworkAssemblies": { - "System.Collections": "4.0.0.0", - "System.IO": "4.0.0.0", - "System.Net": "4.0.0.0", - "System.Net.Http": "4.0.0.0", - "System.Net.Primitives": "4.0.0.0", - "System.Net.Http.WebRequest": "4.0.0.0", - "System.Reflection": "4.0.0.0", - "System.Runtime": "4.0.0.0", - "System.Runtime.Extensions": "4.0.0.0", - "System.Text.Encoding": "4.0.0.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0", - "System.Xml.ReaderWriter": "4.0.0" - }, - "dependencies": { - "SimpleInjector": "3.2.4", - "ServiceStack.Text": "4.5.4", - "NLog": "4.4.0-betaV15", - "sharpcompress": "0.14.0", - "MediaBrowser.Model": { - "target": "project" - }, - "MediaBrowser.Common": { - "target": "project" - } - } - }, - "netstandard1.6": { - "imports": "dnxcore50", - "dependencies": { - "NETStandard.Library": "1.6.1", - "System.IO.FileSystem.DriveInfo": "4.3.0", - "System.Diagnostics.Process": "4.3.0", - "System.Threading.Timer": "4.3.0", - "System.Net.Requests": "4.3.0", - "System.Xml.ReaderWriter": "4.3.0", - "System.Xml.XmlSerializer": "4.3.0", - "System.Net.Http": "4.3.2", - "System.Net.Primitives": "4.3.0", - "System.Net.Sockets": "4.3.0", - "System.Net.NetworkInformation": "4.3.0", - "System.Net.NameResolution": "4.3.0", - "System.Runtime.InteropServices.RuntimeInformation": "4.3.0", - "System.Reflection": "4.3.0", - "System.Reflection.Primitives": "4.3.0", - "System.Runtime.Loader": "4.3.0", - "SimpleInjector": "3.2.4", - "ServiceStack.Text.Core": "1.0.27", - "NLog": "4.4.0-betaV15", - "sharpcompress": "0.14.0", - "System.AppDomain": "2.0.11", - "MediaBrowser.Model": { - "target": "project" - }, - "MediaBrowser.Common": { - "target": "project" - } - } - } - } -} diff --git a/MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs b/Emby.Server.Core/ApplicationPathHelper.cs similarity index 97% rename from MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs rename to Emby.Server.Core/ApplicationPathHelper.cs index 254a782db9..e83d5444aa 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs +++ b/Emby.Server.Core/ApplicationPathHelper.cs @@ -2,7 +2,7 @@ using System.Configuration; using System.IO; -namespace MediaBrowser.Server.Startup.Common +namespace Emby.Server.Core { public static class ApplicationPathHelper { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/ASN1.cs b/Emby.Server.Core/Cryptography/ASN1.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/ASN1.cs rename to Emby.Server.Core/Cryptography/ASN1.cs index a25c270734..f5c826436e 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/ASN1.cs +++ b/Emby.Server.Core/Cryptography/ASN1.cs @@ -34,7 +34,8 @@ using System.Collections; using System.IO; using System.Text; -namespace Emby.Common.Implementations.Security { +namespace Emby.Server.Core.Cryptography +{ // References: // a. ITU ASN.1 standards (free download) diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/ASN1Convert.cs b/Emby.Server.Core/Cryptography/ASN1Convert.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/ASN1Convert.cs rename to Emby.Server.Core/Cryptography/ASN1Convert.cs index 8a2a487c82..851d36dc70 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/ASN1Convert.cs +++ b/Emby.Server.Core/Cryptography/ASN1Convert.cs @@ -34,7 +34,7 @@ using System.Globalization; using System.Security.Cryptography; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { // References: diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/BitConverterLE.cs b/Emby.Server.Core/Cryptography/BitConverterLE.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/BitConverterLE.cs rename to Emby.Server.Core/Cryptography/BitConverterLE.cs index 240c958a3a..34e6bf6dce 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/BitConverterLE.cs +++ b/Emby.Server.Core/Cryptography/BitConverterLE.cs @@ -29,7 +29,7 @@ using System; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { internal sealed class BitConverterLE { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/CertificateGenerator.cs b/Emby.Server.Core/Cryptography/CertificateGenerator.cs similarity index 98% rename from MediaBrowser.Server.Startup.Common/Cryptography/CertificateGenerator.cs rename to Emby.Server.Core/Cryptography/CertificateGenerator.cs index 4f5b3d0042..2600d74702 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/CertificateGenerator.cs +++ b/Emby.Server.Core/Cryptography/CertificateGenerator.cs @@ -3,7 +3,7 @@ using System; using System.Collections; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public class CertificateGenerator { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/CryptoConvert.cs b/Emby.Server.Core/Cryptography/CryptoConvert.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/CryptoConvert.cs rename to Emby.Server.Core/Cryptography/CryptoConvert.cs index c6e466534b..70a91bfff1 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/CryptoConvert.cs +++ b/Emby.Server.Core/Cryptography/CryptoConvert.cs @@ -32,7 +32,7 @@ using System.Globalization; using System.Security.Cryptography; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public sealed class CryptoConvert { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS1.cs b/Emby.Server.Core/Cryptography/PKCS1.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/PKCS1.cs rename to Emby.Server.Core/Cryptography/PKCS1.cs index 85bf9db380..24c0708c54 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS1.cs +++ b/Emby.Server.Core/Cryptography/PKCS1.cs @@ -31,7 +31,7 @@ using System; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { // References: diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS12.cs b/Emby.Server.Core/Cryptography/PKCS12.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/PKCS12.cs rename to Emby.Server.Core/Cryptography/PKCS12.cs index 2205a71604..50f3776d9d 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS12.cs +++ b/Emby.Server.Core/Cryptography/PKCS12.cs @@ -37,7 +37,7 @@ using System.IO; using System.Security.Cryptography; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public class PKCS5 { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS7.cs b/Emby.Server.Core/Cryptography/PKCS7.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/PKCS7.cs rename to Emby.Server.Core/Cryptography/PKCS7.cs index 1b1a3295b4..475854500c 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS7.cs +++ b/Emby.Server.Core/Cryptography/PKCS7.cs @@ -33,7 +33,7 @@ using System; using System.Collections; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public sealed class PKCS7 { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS8.cs b/Emby.Server.Core/Cryptography/PKCS8.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/PKCS8.cs rename to Emby.Server.Core/Cryptography/PKCS8.cs index b58ebdaf99..7e9a272987 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/PKCS8.cs +++ b/Emby.Server.Core/Cryptography/PKCS8.cs @@ -33,7 +33,7 @@ using System; using System.Collections; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public sealed class PKCS8 { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/PfxGenerator.cs b/Emby.Server.Core/Cryptography/PfxGenerator.cs similarity index 97% rename from MediaBrowser.Server.Startup.Common/Cryptography/PfxGenerator.cs rename to Emby.Server.Core/Cryptography/PfxGenerator.cs index 3f9b90ac16..2d1dd649ea 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/PfxGenerator.cs +++ b/Emby.Server.Core/Cryptography/PfxGenerator.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public class PFXGenerator { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X501Name.cs b/Emby.Server.Core/Cryptography/X501Name.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X501Name.cs rename to Emby.Server.Core/Cryptography/X501Name.cs index 93e1a6bef4..3318f95e2b 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X501Name.cs +++ b/Emby.Server.Core/Cryptography/X501Name.cs @@ -31,7 +31,7 @@ using System; using System.Globalization; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { // References: diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X509Builder.cs b/Emby.Server.Core/Cryptography/X509Builder.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X509Builder.cs rename to Emby.Server.Core/Cryptography/X509Builder.cs index e168559591..a2e292350b 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X509Builder.cs +++ b/Emby.Server.Core/Cryptography/X509Builder.cs @@ -33,7 +33,7 @@ using System; using System.Globalization; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { public abstract class X509Builder { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X509Certificate.cs b/Emby.Server.Core/Cryptography/X509Certificate.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X509Certificate.cs rename to Emby.Server.Core/Cryptography/X509Certificate.cs index f49445f0e7..3de58cfeea 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X509Certificate.cs +++ b/Emby.Server.Core/Cryptography/X509Certificate.cs @@ -34,7 +34,7 @@ using System.Security.Cryptography; using System.Security.Permissions; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { // References: diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X509CertificateBuilder.cs b/Emby.Server.Core/Cryptography/X509CertificateBuilder.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X509CertificateBuilder.cs rename to Emby.Server.Core/Cryptography/X509CertificateBuilder.cs index fb6f8ec727..cecff65784 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X509CertificateBuilder.cs +++ b/Emby.Server.Core/Cryptography/X509CertificateBuilder.cs @@ -32,7 +32,7 @@ using System; using System.Security.Cryptography; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { // From RFC3280 /* diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X509CertificateCollection.cs b/Emby.Server.Core/Cryptography/X509CertificateCollection.cs similarity index 98% rename from MediaBrowser.Server.Startup.Common/Cryptography/X509CertificateCollection.cs rename to Emby.Server.Core/Cryptography/X509CertificateCollection.cs index 5d353f9cfd..a129bfc1a1 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X509CertificateCollection.cs +++ b/Emby.Server.Core/Cryptography/X509CertificateCollection.cs @@ -31,7 +31,7 @@ using System; using System.Collections; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { [Serializable] diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X509Extension.cs b/Emby.Server.Core/Cryptography/X509Extension.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X509Extension.cs rename to Emby.Server.Core/Cryptography/X509Extension.cs index e82f52bac7..36b17deba0 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X509Extension.cs +++ b/Emby.Server.Core/Cryptography/X509Extension.cs @@ -31,7 +31,7 @@ using System; using System.Globalization; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { /* * Extension ::= SEQUENCE { diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X509Extensions.cs b/Emby.Server.Core/Cryptography/X509Extensions.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X509Extensions.cs rename to Emby.Server.Core/Cryptography/X509Extensions.cs index c7d5f0046e..018a04d796 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X509Extensions.cs +++ b/Emby.Server.Core/Cryptography/X509Extensions.cs @@ -32,7 +32,7 @@ using System; using System.Collections; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { /* * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension diff --git a/MediaBrowser.Server.Startup.Common/Cryptography/X520Attributes.cs b/Emby.Server.Core/Cryptography/X520Attributes.cs similarity index 99% rename from MediaBrowser.Server.Startup.Common/Cryptography/X520Attributes.cs rename to Emby.Server.Core/Cryptography/X520Attributes.cs index 5062bf80ad..da7fd2b82c 100644 --- a/MediaBrowser.Server.Startup.Common/Cryptography/X520Attributes.cs +++ b/Emby.Server.Core/Cryptography/X520Attributes.cs @@ -30,7 +30,7 @@ using System; using System.Text; -namespace Emby.Common.Implementations.Security +namespace Emby.Server.Core.Cryptography { // References: diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/Emby.Server.Core/Emby.Server.Core.csproj similarity index 53% rename from MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj rename to Emby.Server.Core/Emby.Server.Core.csproj index 5955d4c96c..6c8daf9c95 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/Emby.Server.Core/Emby.Server.Core.csproj @@ -1,17 +1,16 @@  - + Debug AnyCPU - {B90AB8F2-1BFF-4568-A3FD-2A338A435A75} + {776B9F0C-5195-45E3-9A36-1CC1F0D8E0B0} Library Properties - MediaBrowser.Server.Startup.Common - MediaBrowser.Server.Startup.Common - v4.6 + Emby.Server.Core + Emby.Server.Core + v4.6.2 512 - ..\ @@ -25,7 +24,7 @@ true - None + pdbonly true bin\Release\ TRACE @@ -34,13 +33,18 @@ true - - ..\ThirdParty\emby\Emby.Server.Core.dll - ..\packages\Microsoft.IO.RecyclableMemoryStream.1.2.2\lib\net45\Microsoft.IO.RecyclableMemoryStream.dll True + + ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll + True + + + ..\packages\SimpleInjector.4.0.7\lib\net45\SimpleInjector.dll + True + @@ -48,12 +52,14 @@ + Properties\SharedVersion.cs + @@ -73,16 +79,41 @@ + + + + + + + {1e37a338-9f57-4b70-bd6d-bb9c591e319b} + Emby.Common.Implementations + + + {805844ab-e92f-45e6-9d99-4f6d48d129a5} + Emby.Dlna + + + {08fff49b-f175-4807-a2b5-73b0ebd9f716} + Emby.Drawing + + + {89ab4548-770d-41fd-a891-8daff44f452c} + Emby.Photos + {e383961b-9356-4d5d-8233-9a1079d03055} Emby.Server.Implementations + + {4fd51ac5-2c16-4308-a993-c3a84f3b4582} + MediaBrowser.Api + {9142eefa-7570-41e1-bfcc-468bb571af2f} MediaBrowser.Common @@ -91,16 +122,51 @@ {17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2} MediaBrowser.Controller + + {7ef9f3e0-697d-42f3-a08f-19deb5f84392} + MediaBrowser.LocalMetadata + + + {0bd82fa6-eb8a-4452-8af5-74f9c3849451} + MediaBrowser.MediaEncoding + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} MediaBrowser.Model + + {442b5058-dcaf-4263-bb6a-f21e31120a1b} + MediaBrowser.Providers + + + {2e781478-814d-4a48-9d80-bff206441a65} + MediaBrowser.Server.Implementations + + + {5624b7b5-b5a7-41d8-9f10-cc5611109619} + MediaBrowser.WebDashboard + + + {23499896-b135-4527-8574-c26e926ea99e} + MediaBrowser.XbmcMetadata + + + {cb7f2326-6497-4a3d-ba03-48513b17a7be} + Mono.Nat + + + {4a4402d4-e910-443b-b8fc-2c18286a2ca0} + OpenSubtitlesHandler + + + {1d74413b-e7cf-455b-b021-f52bdf881542} + SocketHttpListener + - + \ No newline at end of file diff --git a/Mono.Nat/Mono.Nat.xproj b/Mono.Nat/Mono.Nat.xproj deleted file mode 100644 index 3479a2a677..0000000000 --- a/Mono.Nat/Mono.Nat.xproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 4acab6a2-ac9a-4b50-baec-1fe4a1f3b8bc - Mono.Nat - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - - - - - \ No newline at end of file diff --git a/Mono.Nat/Properties/AssemblyInfo.cs b/Mono.Nat/Properties/AssemblyInfo.cs index 2a4e75c210..18b1838175 100644 --- a/Mono.Nat/Properties/AssemblyInfo.cs +++ b/Mono.Nat/Properties/AssemblyInfo.cs @@ -2,15 +2,33 @@ using System.Runtime.CompilerServices; 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("Mono.Nat")] +[assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Mono.Nat")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cb7f2326-6497-4a3d-ba03-48513b17a7be")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/Mono.Nat/project.json b/Mono.Nat/project.json deleted file mode 100644 index 3c38a62e13..0000000000 --- a/Mono.Nat/project.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "1.0.0-*", - - "dependencies": { - - }, - - "frameworks": { - "net46": { - "frameworkAssemblies": { - "System.Collections": "4.0.0.0", - "System.Net": "4.0.0.0", - "System.Runtime": "4.0.0.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0", - "System.Xml": "4.0.0.0" - }, - "dependencies": { - "MediaBrowser.Common": { - "target": "project" - }, - "MediaBrowser.Model": { - "target": "project" - } - } - }, - "netstandard1.6": { - "imports": "dnxcore50", - "dependencies": { - "NETStandard.Library": "1.6.1", - "MediaBrowser.Common": { - "target": "project" - }, - "MediaBrowser.Model": { - "target": "project" - }, - "System.Net.NetworkInformation": "4.3.0" - } - } - } -} diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs index e9dc4c54f7..91004b76fe 100644 --- a/RSSDP/SsdpCommunicationsServer.cs +++ b/RSSDP/SsdpCommunicationsServer.cs @@ -177,7 +177,7 @@ namespace Rssdp.Infrastructure { try { - await socket.SendWithLockAsync(messageData, messageData.Length, destination, cancellationToken).ConfigureAwait(false); + await socket.SendToAsync(messageData, 0, messageData.Length, destination, cancellationToken).ConfigureAwait(false); } catch (ObjectDisposedException) { @@ -392,11 +392,13 @@ namespace Rssdp.Infrastructure var t = Task.Run(async () => { var cancelled = false; + var receiveBuffer = new byte[8192]; + while (!cancelled) { try { - var result = await socket.ReceiveAsync(CancellationToken.None).ConfigureAwait(false); + var result = await socket.ReceiveAsync(receiveBuffer, 0, receiveBuffer.Length, CancellationToken.None).ConfigureAwait(false); if (result.ReceivedBytes > 0) { diff --git a/SocketHttpListener.Portable/Net/ChunkedInputStream.cs b/SocketHttpListener.Portable/Net/ChunkedInputStream.cs deleted file mode 100644 index 6dfd8d8a1d..0000000000 --- a/SocketHttpListener.Portable/Net/ChunkedInputStream.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System; -using System.IO; -using System.Runtime.InteropServices; -using SocketHttpListener.Primitives; - -namespace SocketHttpListener.Net -{ - class ChunkedInputStream : RequestStream - { - bool disposed; - ChunkStream decoder; - HttpListenerContext context; - bool no_more_data; - - //class ReadBufferState - //{ - // public byte[] Buffer; - // public int Offset; - // public int Count; - // public int InitialCount; - // public HttpStreamAsyncResult Ares; - // public ReadBufferState(byte[] buffer, int offset, int count, - // HttpStreamAsyncResult ares) - // { - // Buffer = buffer; - // Offset = offset; - // Count = count; - // InitialCount = count; - // Ares = ares; - // } - //} - - public ChunkedInputStream(HttpListenerContext context, Stream stream, - byte[] buffer, int offset, int length) - : base(stream, buffer, offset, length) - { - this.context = context; - WebHeaderCollection coll = (WebHeaderCollection)context.Request.Headers; - decoder = new ChunkStream(coll); - } - - //public ChunkStream Decoder - //{ - // get { return decoder; } - // set { decoder = value; } - //} - - //public override int Read([In, Out] byte[] buffer, int offset, int count) - //{ - // IAsyncResult ares = BeginRead(buffer, offset, count, null, null); - // return EndRead(ares); - //} - - //public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, - // AsyncCallback cback, object state) - //{ - // if (disposed) - // throw new ObjectDisposedException(GetType().ToString()); - - // if (buffer == null) - // throw new ArgumentNullException("buffer"); - - // int len = buffer.Length; - // if (offset < 0 || offset > len) - // throw new ArgumentOutOfRangeException("offset exceeds the size of buffer"); - - // if (count < 0 || offset > len - count) - // throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer"); - - // HttpStreamAsyncResult ares = new HttpStreamAsyncResult(); - // ares.Callback = cback; - // ares.State = state; - // if (no_more_data) - // { - // ares.Complete(); - // return ares; - // } - // int nread = decoder.Read(buffer, offset, count); - // offset += nread; - // count -= nread; - // if (count == 0) - // { - // // got all we wanted, no need to bother the decoder yet - // ares.Count = nread; - // ares.Complete(); - // return ares; - // } - // if (!decoder.WantMore) - // { - // no_more_data = nread == 0; - // ares.Count = nread; - // ares.Complete(); - // return ares; - // } - // ares.Buffer = new byte[8192]; - // ares.Offset = 0; - // ares.Count = 8192; - // ReadBufferState rb = new ReadBufferState(buffer, offset, count, ares); - // rb.InitialCount += nread; - // base.BeginRead(ares.Buffer, ares.Offset, ares.Count, OnRead, rb); - // return ares; - //} - - //void OnRead(IAsyncResult base_ares) - //{ - // ReadBufferState rb = (ReadBufferState)base_ares.AsyncState; - // HttpStreamAsyncResult ares = rb.Ares; - // try - // { - // int nread = base.EndRead(base_ares); - // decoder.Write(ares.Buffer, ares.Offset, nread); - // nread = decoder.Read(rb.Buffer, rb.Offset, rb.Count); - // rb.Offset += nread; - // rb.Count -= nread; - // if (rb.Count == 0 || !decoder.WantMore || nread == 0) - // { - // no_more_data = !decoder.WantMore && nread == 0; - // ares.Count = rb.InitialCount - rb.Count; - // ares.Complete(); - // return; - // } - // ares.Offset = 0; - // ares.Count = Math.Min(8192, decoder.ChunkLeft + 6); - // base.BeginRead(ares.Buffer, ares.Offset, ares.Count, OnRead, rb); - // } - // catch (Exception e) - // { - // context.Connection.SendError(e.Message, 400); - // ares.Complete(e); - // } - //} - - //public override int EndRead(IAsyncResult ares) - //{ - // if (disposed) - // throw new ObjectDisposedException(GetType().ToString()); - - // HttpStreamAsyncResult my_ares = ares as HttpStreamAsyncResult; - // if (ares == null) - // throw new ArgumentException("Invalid IAsyncResult", "ares"); - - // if (!ares.IsCompleted) - // ares.AsyncWaitHandle.WaitOne(); - - // if (my_ares.Error != null) - // throw new HttpListenerException(400, "I/O operation aborted: " + my_ares.Error.Message); - - // return my_ares.Count; - //} - - //protected override void Dispose(bool disposing) - //{ - // if (!disposed) - // { - // disposed = true; - // base.Dispose(disposing); - // } - //} - } -} diff --git a/SocketHttpListener.Portable/Net/HttpStreamAsyncResult.cs b/SocketHttpListener.Portable/Net/HttpStreamAsyncResult.cs deleted file mode 100644 index 518c45acba..0000000000 --- a/SocketHttpListener.Portable/Net/HttpStreamAsyncResult.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Threading; - -namespace SocketHttpListener.Net -{ - class HttpStreamAsyncResult : IAsyncResult - { - object locker = new object(); - ManualResetEvent handle; - bool completed; - - internal byte[] Buffer; - internal int Offset; - internal int Count; - internal AsyncCallback Callback; - internal object State; - internal int SynchRead; - internal Exception Error; - - public void Complete(Exception e) - { - Error = e; - Complete(); - } - - public void Complete() - { - lock (locker) - { - if (completed) - return; - - completed = true; - if (handle != null) - handle.Set(); - - if (Callback != null) - Callback.BeginInvoke(this, null, null); - } - } - - public object AsyncState - { - get { return State; } - } - - public WaitHandle AsyncWaitHandle - { - get - { - lock (locker) - { - if (handle == null) - handle = new ManualResetEvent(completed); - } - - return handle; - } - } - - public bool CompletedSynchronously - { - get { return (SynchRead == Count); } - } - - public bool IsCompleted - { - get - { - lock (locker) - { - return completed; - } - } - } - } -} diff --git a/SocketHttpListener.Portable/Net/RequestStream.cs b/SocketHttpListener.Portable/Net/RequestStream.cs deleted file mode 100644 index 58030500d1..0000000000 --- a/SocketHttpListener.Portable/Net/RequestStream.cs +++ /dev/null @@ -1,231 +0,0 @@ -using System; -using System.IO; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; - -namespace SocketHttpListener.Net -{ - class RequestStream : Stream - { - byte[] buffer; - int offset; - int length; - long remaining_body; - bool disposed; - Stream stream; - - internal RequestStream(Stream stream, byte[] buffer, int offset, int length) - : this(stream, buffer, offset, length, -1) - { - } - - internal RequestStream(Stream stream, byte[] buffer, int offset, int length, long contentlength) - { - this.stream = stream; - this.buffer = buffer; - this.offset = offset; - this.length = length; - this.remaining_body = contentlength; - } - - public override bool CanRead - { - get { return true; } - } - - public override bool CanSeek - { - get { return false; } - } - - public override bool CanWrite - { - get { return false; } - } - - public override long Length - { - get { throw new NotSupportedException(); } - } - - public override long Position - { - get { throw new NotSupportedException(); } - set { throw new NotSupportedException(); } - } - - - protected override void Dispose(bool disposing) - { - disposed = true; - } - - public override void Flush() - { - } - - - // Returns 0 if we can keep reading from the base stream, - // > 0 if we read something from the buffer. - // -1 if we had a content length set and we finished reading that many bytes. - int FillFromBuffer(byte[] buffer, int off, int count) - { - if (buffer == null) - throw new ArgumentNullException("buffer"); - if (off < 0) - throw new ArgumentOutOfRangeException("offset", "< 0"); - if (count < 0) - throw new ArgumentOutOfRangeException("count", "< 0"); - int len = buffer.Length; - if (off > len) - throw new ArgumentException("destination offset is beyond array size"); - if (off > len - count) - throw new ArgumentException("Reading would overrun buffer"); - - if (this.remaining_body == 0) - return -1; - - if (this.length == 0) - return 0; - - int size = Math.Min(this.length, count); - if (this.remaining_body > 0) - size = (int)Math.Min(size, this.remaining_body); - - if (this.offset > this.buffer.Length - size) - { - size = Math.Min(size, this.buffer.Length - this.offset); - } - if (size == 0) - return 0; - - Buffer.BlockCopy(this.buffer, this.offset, buffer, off, size); - this.offset += size; - this.length -= size; - if (this.remaining_body > 0) - remaining_body -= size; - return size; - } - - public override int Read([In, Out] byte[] buffer, int offset, int count) - { - if (disposed) - throw new ObjectDisposedException(typeof(RequestStream).ToString()); - - // Call FillFromBuffer to check for buffer boundaries even when remaining_body is 0 - int nread = FillFromBuffer(buffer, offset, count); - if (nread == -1) - { // No more bytes available (Content-Length) - return 0; - } - else if (nread > 0) - { - return nread; - } - - nread = stream.Read(buffer, offset, count); - if (nread > 0 && remaining_body > 0) - remaining_body -= nread; - return nread; - } - - public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - if (disposed) - throw new ObjectDisposedException(typeof(RequestStream).ToString()); - - int nread = FillFromBuffer(buffer, offset, count); - if (nread > 0 || nread == -1) - { - return Math.Max(0, nread); - } - - // Avoid reading past the end of the request to allow - // for HTTP pipelining - if (remaining_body >= 0 && count > remaining_body) - count = (int)Math.Min(Int32.MaxValue, remaining_body); - - nread = await stream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); - if (remaining_body > 0 && nread > 0) - remaining_body -= nread; - return nread; - } - - //public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, - // AsyncCallback cback, object state) - //{ - // if (disposed) - // throw new ObjectDisposedException(typeof(RequestStream).ToString()); - - // int nread = FillFromBuffer(buffer, offset, count); - // if (nread > 0 || nread == -1) - // { - // HttpStreamAsyncResult ares = new HttpStreamAsyncResult(); - // ares.Buffer = buffer; - // ares.Offset = offset; - // ares.Count = count; - // ares.Callback = cback; - // ares.State = state; - // ares.SynchRead = Math.Max(0, nread); - // ares.Complete(); - // return ares; - // } - - // // Avoid reading past the end of the request to allow - // // for HTTP pipelining - // if (remaining_body >= 0 && count > remaining_body) - // count = (int)Math.Min(Int32.MaxValue, remaining_body); - // return stream.BeginRead(buffer, offset, count, cback, state); - //} - - //public override int EndRead(IAsyncResult ares) - //{ - // if (disposed) - // throw new ObjectDisposedException(typeof(RequestStream).ToString()); - - // if (ares == null) - // throw new ArgumentNullException("async_result"); - - // if (ares is HttpStreamAsyncResult) - // { - // HttpStreamAsyncResult r = (HttpStreamAsyncResult)ares; - // if (!ares.IsCompleted) - // ares.AsyncWaitHandle.WaitOne(); - // return r.SynchRead; - // } - - // // Close on exception? - // int nread = stream.EndRead(ares); - // if (remaining_body > 0 && nread > 0) - // remaining_body -= nread; - // return nread; - //} - - public override long Seek(long offset, SeekOrigin origin) - { - throw new NotSupportedException(); - } - - public override void SetLength(long value) - { - throw new NotSupportedException(); - } - - public override void Write(byte[] buffer, int offset, int count) - { - throw new NotSupportedException(); - } - - //public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, - // AsyncCallback cback, object state) - //{ - // throw new NotSupportedException(); - //} - - //public override void EndWrite(IAsyncResult async_result) - //{ - // throw new NotSupportedException(); - //} - } -} diff --git a/SocketHttpListener.Portable/Primitives/HttpListenerException.cs b/SocketHttpListener.Portable/Primitives/HttpListenerException.cs deleted file mode 100644 index 7b383fd230..0000000000 --- a/SocketHttpListener.Portable/Primitives/HttpListenerException.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SocketHttpListener.Primitives -{ - public class HttpListenerException : Exception - { - public HttpListenerException(int statusCode, string message) - : base(message) - { - - } - } -} diff --git a/SocketHttpListener.Portable/Properties/AssemblyInfo.cs b/SocketHttpListener.Portable/Properties/AssemblyInfo.cs deleted file mode 100644 index 8704264603..0000000000 --- a/SocketHttpListener.Portable/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 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("SocketHttpListener.Portable")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SocketHttpListener.Portable")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SocketHttpListener.Portable/SocketHttpListener.Portable.nuget.targets b/SocketHttpListener.Portable/SocketHttpListener.Portable.nuget.targets deleted file mode 100644 index e69ce0e64f..0000000000 --- a/SocketHttpListener.Portable/SocketHttpListener.Portable.nuget.targets +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SocketHttpListener.Portable/packages.config b/SocketHttpListener.Portable/packages.config deleted file mode 100644 index 2aae715b5a..0000000000 --- a/SocketHttpListener.Portable/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/SocketHttpListener.Portable/project.json b/SocketHttpListener.Portable/project.json deleted file mode 100644 index fbbe9eaf32..0000000000 --- a/SocketHttpListener.Portable/project.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "frameworks":{ - "netstandard1.6":{ - "dependencies":{ - "NETStandard.Library":"1.6.0", - } - }, - ".NETPortable,Version=v4.5,Profile=Profile7":{ - "buildOptions": { - "define": [ ] - }, - "frameworkAssemblies":{ - - } - } - } -} \ No newline at end of file diff --git a/SocketHttpListener.Portable/ByteOrder.cs b/SocketHttpListener/ByteOrder.cs similarity index 100% rename from SocketHttpListener.Portable/ByteOrder.cs rename to SocketHttpListener/ByteOrder.cs diff --git a/SocketHttpListener.Portable/CloseEventArgs.cs b/SocketHttpListener/CloseEventArgs.cs similarity index 100% rename from SocketHttpListener.Portable/CloseEventArgs.cs rename to SocketHttpListener/CloseEventArgs.cs diff --git a/SocketHttpListener.Portable/CloseStatusCode.cs b/SocketHttpListener/CloseStatusCode.cs similarity index 100% rename from SocketHttpListener.Portable/CloseStatusCode.cs rename to SocketHttpListener/CloseStatusCode.cs diff --git a/SocketHttpListener.Portable/CompressionMethod.cs b/SocketHttpListener/CompressionMethod.cs similarity index 100% rename from SocketHttpListener.Portable/CompressionMethod.cs rename to SocketHttpListener/CompressionMethod.cs diff --git a/SocketHttpListener.Portable/ErrorEventArgs.cs b/SocketHttpListener/ErrorEventArgs.cs similarity index 100% rename from SocketHttpListener.Portable/ErrorEventArgs.cs rename to SocketHttpListener/ErrorEventArgs.cs diff --git a/SocketHttpListener.Portable/Ext.cs b/SocketHttpListener/Ext.cs similarity index 100% rename from SocketHttpListener.Portable/Ext.cs rename to SocketHttpListener/Ext.cs diff --git a/SocketHttpListener.Portable/Fin.cs b/SocketHttpListener/Fin.cs similarity index 100% rename from SocketHttpListener.Portable/Fin.cs rename to SocketHttpListener/Fin.cs diff --git a/SocketHttpListener.Portable/HttpBase.cs b/SocketHttpListener/HttpBase.cs similarity index 100% rename from SocketHttpListener.Portable/HttpBase.cs rename to SocketHttpListener/HttpBase.cs diff --git a/SocketHttpListener.Portable/HttpResponse.cs b/SocketHttpListener/HttpResponse.cs similarity index 100% rename from SocketHttpListener.Portable/HttpResponse.cs rename to SocketHttpListener/HttpResponse.cs diff --git a/SocketHttpListener.Portable/Mask.cs b/SocketHttpListener/Mask.cs similarity index 100% rename from SocketHttpListener.Portable/Mask.cs rename to SocketHttpListener/Mask.cs diff --git a/SocketHttpListener.Portable/MessageEventArgs.cs b/SocketHttpListener/MessageEventArgs.cs similarity index 100% rename from SocketHttpListener.Portable/MessageEventArgs.cs rename to SocketHttpListener/MessageEventArgs.cs diff --git a/SocketHttpListener.Portable/Net/AuthenticationSchemeSelector.cs b/SocketHttpListener/Net/AuthenticationSchemeSelector.cs similarity index 100% rename from SocketHttpListener.Portable/Net/AuthenticationSchemeSelector.cs rename to SocketHttpListener/Net/AuthenticationSchemeSelector.cs diff --git a/SocketHttpListener.Portable/Net/ChunkStream.cs b/SocketHttpListener/Net/ChunkStream.cs similarity index 50% rename from SocketHttpListener.Portable/Net/ChunkStream.cs rename to SocketHttpListener/Net/ChunkStream.cs index 3f3b4a667a..2de6c2c182 100644 --- a/SocketHttpListener.Portable/Net/ChunkStream.cs +++ b/SocketHttpListener/Net/ChunkStream.cs @@ -8,9 +8,39 @@ using System.Text; namespace SocketHttpListener.Net { - class ChunkStream + // Licensed to the .NET Foundation under one or more agreements. + // See the LICENSE file in the project root for more information. + // + // System.Net.ResponseStream + // + // Author: + // Gonzalo Paniagua Javier (gonzalo@novell.com) + // + // Copyright (c) 2005 Novell, Inc. (http://www.novell.com) + // + // Permission is hereby granted, free of charge, to any person obtaining + // a copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to + // permit persons to whom the Software is furnished to do so, subject to + // the following conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + // + + internal sealed class ChunkStream { - enum State + private enum State { None, PartialSize, @@ -19,14 +49,14 @@ namespace SocketHttpListener.Net Trailer } - class Chunk + private class Chunk { public byte[] Bytes; public int Offset; public Chunk(byte[] chunk) { - this.Bytes = chunk; + Bytes = chunk; } public int Read(byte[] buffer, int offset, int size) @@ -38,33 +68,38 @@ namespace SocketHttpListener.Net } } - internal WebHeaderCollection headers; - int chunkSize; - int chunkRead; - int totalWritten; - State state; - //byte [] waitBuffer; - StringBuilder saved; - bool sawCR; - bool gotit; - int trailerState; - List chunks; + internal WebHeaderCollection _headers; + private int _chunkSize; + private int _chunkRead; + private int _totalWritten; + private State _state; + private StringBuilder _saved; + private bool _sawCR; + private bool _gotit; + private int _trailerState; + private List _chunks; + + public ChunkStream(byte[] buffer, int offset, int size, WebHeaderCollection headers) + : this(headers) + { + Write(buffer, offset, size); + } public ChunkStream(WebHeaderCollection headers) { - this.headers = headers; - saved = new StringBuilder(); - chunks = new List(); - chunkSize = -1; - totalWritten = 0; + _headers = headers; + _saved = new StringBuilder(); + _chunks = new List(); + _chunkSize = -1; + _totalWritten = 0; } public void ResetBuffer() { - chunkSize = -1; - chunkRead = 0; - totalWritten = 0; - chunks.Clear(); + _chunkSize = -1; + _chunkRead = 0; + _totalWritten = 0; + _chunks.Clear(); } public void WriteAndReadBack(byte[] buffer, int offset, int size, ref int read) @@ -79,15 +114,15 @@ namespace SocketHttpListener.Net return ReadFromChunks(buffer, offset, size); } - int ReadFromChunks(byte[] buffer, int offset, int size) + private int ReadFromChunks(byte[] buffer, int offset, int size) { - int count = chunks.Count; + int count = _chunks.Count; int nread = 0; var chunksForRemoving = new List(count); for (int i = 0; i < count; i++) { - Chunk chunk = (Chunk)chunks[i]; + Chunk chunk = _chunks[i]; if (chunk.Offset == chunk.Bytes.Length) { @@ -101,7 +136,7 @@ namespace SocketHttpListener.Net } foreach (var chunk in chunksForRemoving) - chunks.Remove(chunk); + _chunks.Remove(chunk); return nread; } @@ -112,44 +147,44 @@ namespace SocketHttpListener.Net InternalWrite(buffer, ref offset, size); } - void InternalWrite(byte[] buffer, ref int offset, int size) + private void InternalWrite(byte[] buffer, ref int offset, int size) { - if (state == State.None || state == State.PartialSize) + if (_state == State.None || _state == State.PartialSize) { - state = GetChunkSize(buffer, ref offset, size); - if (state == State.PartialSize) + _state = GetChunkSize(buffer, ref offset, size); + if (_state == State.PartialSize) return; - saved.Length = 0; - sawCR = false; - gotit = false; + _saved.Length = 0; + _sawCR = false; + _gotit = false; } - if (state == State.Body && offset < size) + if (_state == State.Body && offset < size) { - state = ReadBody(buffer, ref offset, size); - if (state == State.Body) + _state = ReadBody(buffer, ref offset, size); + if (_state == State.Body) return; } - if (state == State.BodyFinished && offset < size) + if (_state == State.BodyFinished && offset < size) { - state = ReadCRLF(buffer, ref offset, size); - if (state == State.BodyFinished) + _state = ReadCRLF(buffer, ref offset, size); + if (_state == State.BodyFinished) return; - sawCR = false; + _sawCR = false; } - if (state == State.Trailer && offset < size) + if (_state == State.Trailer && offset < size) { - state = ReadTrailer(buffer, ref offset, size); - if (state == State.Trailer) + _state = ReadTrailer(buffer, ref offset, size); + if (_state == State.Trailer) return; - saved.Length = 0; - sawCR = false; - gotit = false; + _saved.Length = 0; + _sawCR = false; + _gotit = false; } if (offset < size) @@ -158,21 +193,21 @@ namespace SocketHttpListener.Net public bool WantMore { - get { return (chunkRead != chunkSize || chunkSize != 0 || state != State.None); } + get { return (_chunkRead != _chunkSize || _chunkSize != 0 || _state != State.None); } } public bool DataAvailable { get { - int count = chunks.Count; + int count = _chunks.Count; for (int i = 0; i < count; i++) { - Chunk ch = (Chunk)chunks[i]; + Chunk ch = _chunks[i]; if (ch == null || ch.Bytes == null) continue; if (ch.Bytes.Length > 0 && ch.Offset < ch.Bytes.Length) - return (state != State.Body); + return (_state != State.Body); } return false; } @@ -180,73 +215,73 @@ namespace SocketHttpListener.Net public int TotalDataSize { - get { return totalWritten; } + get { return _totalWritten; } } public int ChunkLeft { - get { return chunkSize - chunkRead; } + get { return _chunkSize - _chunkRead; } } - State ReadBody(byte[] buffer, ref int offset, int size) + private State ReadBody(byte[] buffer, ref int offset, int size) { - if (chunkSize == 0) + if (_chunkSize == 0) return State.BodyFinished; int diff = size - offset; - if (diff + chunkRead > chunkSize) - diff = chunkSize - chunkRead; + if (diff + _chunkRead > _chunkSize) + diff = _chunkSize - _chunkRead; byte[] chunk = new byte[diff]; Buffer.BlockCopy(buffer, offset, chunk, 0, diff); - chunks.Add(new Chunk(chunk)); + _chunks.Add(new Chunk(chunk)); offset += diff; - chunkRead += diff; - totalWritten += diff; - return (chunkRead == chunkSize) ? State.BodyFinished : State.Body; + _chunkRead += diff; + _totalWritten += diff; + return (_chunkRead == _chunkSize) ? State.BodyFinished : State.Body; } - State GetChunkSize(byte[] buffer, ref int offset, int size) + private State GetChunkSize(byte[] buffer, ref int offset, int size) { - chunkRead = 0; - chunkSize = 0; + _chunkRead = 0; + _chunkSize = 0; char c = '\0'; while (offset < size) { c = (char)buffer[offset++]; if (c == '\r') { - if (sawCR) + if (_sawCR) ThrowProtocolViolation("2 CR found"); - sawCR = true; + _sawCR = true; continue; } - if (sawCR && c == '\n') + if (_sawCR && c == '\n') break; if (c == ' ') - gotit = true; + _gotit = true; - if (!gotit) - saved.Append(c); + if (!_gotit) + _saved.Append(c); - if (saved.Length > 20) + if (_saved.Length > 20) ThrowProtocolViolation("chunk size too long."); } - if (!sawCR || c != '\n') + if (!_sawCR || c != '\n') { if (offset < size) ThrowProtocolViolation("Missing \\n"); try { - if (saved.Length > 0) + if (_saved.Length > 0) { - chunkSize = Int32.Parse(RemoveChunkExtension(saved.ToString()), NumberStyles.HexNumber); + _chunkSize = Int32.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber); } } catch (Exception) @@ -257,26 +292,26 @@ namespace SocketHttpListener.Net return State.PartialSize; } - chunkRead = 0; + _chunkRead = 0; try { - chunkSize = Int32.Parse(RemoveChunkExtension(saved.ToString()), NumberStyles.HexNumber); + _chunkSize = Int32.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber); } catch (Exception) { ThrowProtocolViolation("Cannot parse chunk size."); } - if (chunkSize == 0) + if (_chunkSize == 0) { - trailerState = 2; + _trailerState = 2; return State.Trailer; } return State.Body; } - static string RemoveChunkExtension(string input) + private static string RemoveChunkExtension(string input) { int idx = input.IndexOf(';'); if (idx == -1) @@ -284,30 +319,30 @@ namespace SocketHttpListener.Net return input.Substring(0, idx); } - State ReadCRLF(byte[] buffer, ref int offset, int size) + private State ReadCRLF(byte[] buffer, ref int offset, int size) { - if (!sawCR) + if (!_sawCR) { if ((char)buffer[offset++] != '\r') ThrowProtocolViolation("Expecting \\r"); - sawCR = true; + _sawCR = true; if (offset == size) return State.BodyFinished; } - if (sawCR && (char)buffer[offset++] != '\n') + if (_sawCR && (char)buffer[offset++] != '\n') ThrowProtocolViolation("Expecting \\n"); return State.None; } - State ReadTrailer(byte[] buffer, ref int offset, int size) + private State ReadTrailer(byte[] buffer, ref int offset, int size) { char c = '\0'; // short path - if (trailerState == 2 && (char)buffer[offset] == '\r' && saved.Length == 0) + if (_trailerState == 2 && (char)buffer[offset] == '\r' && _saved.Length == 0) { offset++; if (offset < size && (char)buffer[offset] == '\n') @@ -318,7 +353,7 @@ namespace SocketHttpListener.Net offset--; } - int st = trailerState; + int st = _trailerState; string stString = "\r\n\r"; while (offset < size && st < 4) { @@ -337,34 +372,33 @@ namespace SocketHttpListener.Net if (st > 0) { - saved.Append(stString.Substring(0, saved.Length == 0 ? st - 2 : st)); + _saved.Append(stString.Substring(0, _saved.Length == 0 ? st - 2 : st)); st = 0; - if (saved.Length > 4196) + if (_saved.Length > 4196) ThrowProtocolViolation("Error reading trailer (too long)."); } } if (st < 4) { - trailerState = st; + _trailerState = st; if (offset < size) ThrowProtocolViolation("Error reading trailer."); return State.Trailer; } - StringReader reader = new StringReader(saved.ToString()); + StringReader reader = new StringReader(_saved.ToString()); string line; while ((line = reader.ReadLine()) != null && line != "") - headers.Add(line); + _headers.Add(line); return State.None; } - static void ThrowProtocolViolation(string message) + private static void ThrowProtocolViolation(string message) { - WebException we = new WebException(message, null, WebExceptionStatus.UnknownError, null); - //WebException we = new WebException(message, null, WebExceptionStatus.ServerProtocolViolation, null); + WebException we = new WebException(message, null, WebExceptionStatus.ServerProtocolViolation, null); throw we; } } diff --git a/SocketHttpListener/Net/ChunkedInputStream.cs b/SocketHttpListener/Net/ChunkedInputStream.cs new file mode 100644 index 0000000000..2e0e1964be --- /dev/null +++ b/SocketHttpListener/Net/ChunkedInputStream.cs @@ -0,0 +1,172 @@ +using System; +using System.IO; +using System.Net; +using System.Runtime.InteropServices; +using SocketHttpListener.Primitives; + +namespace SocketHttpListener.Net +{ + // Licensed to the .NET Foundation under one or more agreements. + // See the LICENSE file in the project root for more information. + // + // System.Net.ResponseStream + // + // Author: + // Gonzalo Paniagua Javier (gonzalo@novell.com) + // + // Copyright (c) 2005 Novell, Inc. (http://www.novell.com) + // + // Permission is hereby granted, free of charge, to any person obtaining + // a copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to + // permit persons to whom the Software is furnished to do so, subject to + // the following conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + // + + internal sealed class ChunkedInputStream : HttpRequestStream + { + private ChunkStream _decoder; + private readonly HttpListenerContext _context; + private bool _no_more_data; + + private class ReadBufferState + { + public byte[] Buffer; + public int Offset; + public int Count; + public int InitialCount; + public HttpStreamAsyncResult Ares; + public ReadBufferState(byte[] buffer, int offset, int count, HttpStreamAsyncResult ares) + { + Buffer = buffer; + Offset = offset; + Count = count; + InitialCount = count; + Ares = ares; + } + } + + public ChunkedInputStream(HttpListenerContext context, Stream stream, byte[] buffer, int offset, int length) + : base(stream, buffer, offset, length) + { + _context = context; + WebHeaderCollection coll = (WebHeaderCollection)context.Request.Headers; + _decoder = new ChunkStream(coll); + } + + public ChunkStream Decoder + { + get { return _decoder; } + set { _decoder = value; } + } + + protected override int ReadCore(byte[] buffer, int offset, int count) + { + IAsyncResult ares = BeginReadCore(buffer, offset, count, null, null); + return EndRead(ares); + } + + protected override IAsyncResult BeginReadCore(byte[] buffer, int offset, int size, AsyncCallback cback, object state) + { + HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + ares._callback = cback; + ares._state = state; + if (_no_more_data || size == 0 || _closed) + { + ares.Complete(); + return ares; + } + int nread = _decoder.Read(buffer, offset, size); + offset += nread; + size -= nread; + if (size == 0) + { + // got all we wanted, no need to bother the decoder yet + ares._count = nread; + ares.Complete(); + return ares; + } + if (!_decoder.WantMore) + { + _no_more_data = nread == 0; + ares._count = nread; + ares.Complete(); + return ares; + } + ares._buffer = new byte[8192]; + ares._offset = 0; + ares._count = 8192; + ReadBufferState rb = new ReadBufferState(buffer, offset, size, ares); + rb.InitialCount += nread; + base.BeginReadCore(ares._buffer, ares._offset, ares._count, OnRead, rb); + return ares; + } + + private void OnRead(IAsyncResult base_ares) + { + ReadBufferState rb = (ReadBufferState)base_ares.AsyncState; + HttpStreamAsyncResult ares = rb.Ares; + try + { + int nread = base.EndRead(base_ares); + _decoder.Write(ares._buffer, ares._offset, nread); + nread = _decoder.Read(rb.Buffer, rb.Offset, rb.Count); + rb.Offset += nread; + rb.Count -= nread; + if (rb.Count == 0 || !_decoder.WantMore || nread == 0) + { + _no_more_data = !_decoder.WantMore && nread == 0; + ares._count = rb.InitialCount - rb.Count; + ares.Complete(); + return; + } + ares._offset = 0; + ares._count = Math.Min(8192, _decoder.ChunkLeft + 6); + base.BeginReadCore(ares._buffer, ares._offset, ares._count, OnRead, rb); + } + catch (Exception e) + { + _context.Connection.SendError(e.Message, 400); + ares.Complete(e); + } + } + + public override int EndRead(IAsyncResult asyncResult) + { + if (asyncResult == null) + throw new ArgumentNullException(nameof(asyncResult)); + + HttpStreamAsyncResult ares = asyncResult as HttpStreamAsyncResult; + if (ares == null || !ReferenceEquals(this, ares._parent)) + { + throw new ArgumentException("Invalid async result"); + } + if (ares._endCalled) + { + throw new InvalidOperationException("Invalid end call"); + } + ares._endCalled = true; + + if (!asyncResult.IsCompleted) + asyncResult.AsyncWaitHandle.WaitOne(); + + if (ares._error != null) + throw new HttpListenerException((int)HttpStatusCode.BadRequest, "Bad Request"); + + return ares._count; + } + } +} diff --git a/SocketHttpListener.Portable/Net/CookieHelper.cs b/SocketHttpListener/Net/CookieHelper.cs similarity index 100% rename from SocketHttpListener.Portable/Net/CookieHelper.cs rename to SocketHttpListener/Net/CookieHelper.cs diff --git a/SocketHttpListener.Portable/Net/EndPointListener.cs b/SocketHttpListener/Net/EndPointListener.cs similarity index 100% rename from SocketHttpListener.Portable/Net/EndPointListener.cs rename to SocketHttpListener/Net/EndPointListener.cs diff --git a/SocketHttpListener.Portable/Net/EndPointManager.cs b/SocketHttpListener/Net/EndPointManager.cs similarity index 100% rename from SocketHttpListener.Portable/Net/EndPointManager.cs rename to SocketHttpListener/Net/EndPointManager.cs diff --git a/SocketHttpListener.Portable/Net/HttpConnection.cs b/SocketHttpListener/Net/HttpConnection.cs similarity index 94% rename from SocketHttpListener.Portable/Net/HttpConnection.cs rename to SocketHttpListener/Net/HttpConnection.cs index 65e7470f7e..848b80f99a 100644 --- a/SocketHttpListener.Portable/Net/HttpConnection.cs +++ b/SocketHttpListener/Net/HttpConnection.cs @@ -23,7 +23,7 @@ namespace SocketHttpListener.Net HttpListenerContext context; StringBuilder current_line; ListenerPrefix prefix; - RequestStream i_stream; + HttpRequestStream i_stream; Stream o_stream; bool chunked; int reuses; @@ -186,7 +186,7 @@ namespace SocketHttpListener.Net } } - public RequestStream GetRequestStream(bool chunked, long contentlength) + public HttpRequestStream GetRequestStream(bool chunked, long contentlength) { if (i_stream == null) { @@ -203,7 +203,7 @@ namespace SocketHttpListener.Net } else { - i_stream = new RequestStream(stream, buffer, position, length - position, contentlength); + i_stream = new HttpRequestStream(stream, buffer, position, length - position, contentlength); } } return i_stream; @@ -216,20 +216,9 @@ namespace SocketHttpListener.Net { //context.Response.DetermineIfChunked(); - if (context.Response.SendChunked || isExpect100Continue || context.Request.IsWebSocketRequest || true) - { - var supportsDirectSocketAccess = !context.Response.SendChunked && !isExpect100Continue && !secure; + var supportsDirectSocketAccess = !context.Response.SendChunked && !isExpect100Continue && !secure; - o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding, _fileSystem, sock, supportsDirectSocketAccess, _logger, _environment); - } - else - { - o_stream = stream; - using (var headerStream = ResponseStream.GetHeaders(context.Response, _memoryStreamFactory, false)) - { - headerStream.CopyTo(o_stream); - } - } + o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding, _fileSystem, sock, supportsDirectSocketAccess, _logger, _environment); } return o_stream; } diff --git a/SocketHttpListener.Portable/Net/HttpListener.cs b/SocketHttpListener/Net/HttpListener.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpListener.cs rename to SocketHttpListener/Net/HttpListener.cs diff --git a/SocketHttpListener.Portable/Net/HttpListenerBasicIdentity.cs b/SocketHttpListener/Net/HttpListenerBasicIdentity.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpListenerBasicIdentity.cs rename to SocketHttpListener/Net/HttpListenerBasicIdentity.cs diff --git a/SocketHttpListener.Portable/Net/HttpListenerContext.cs b/SocketHttpListener/Net/HttpListenerContext.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpListenerContext.cs rename to SocketHttpListener/Net/HttpListenerContext.cs diff --git a/SocketHttpListener.Portable/Net/HttpListenerPrefixCollection.cs b/SocketHttpListener/Net/HttpListenerPrefixCollection.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpListenerPrefixCollection.cs rename to SocketHttpListener/Net/HttpListenerPrefixCollection.cs diff --git a/SocketHttpListener.Portable/Net/HttpListenerRequest.cs b/SocketHttpListener/Net/HttpListenerRequest.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpListenerRequest.cs rename to SocketHttpListener/Net/HttpListenerRequest.cs diff --git a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs b/SocketHttpListener/Net/HttpListenerResponse.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpListenerResponse.cs rename to SocketHttpListener/Net/HttpListenerResponse.cs diff --git a/SocketHttpListener/Net/HttpRequestStream.Managed.cs b/SocketHttpListener/Net/HttpRequestStream.Managed.cs new file mode 100644 index 0000000000..cb02a4d5a2 --- /dev/null +++ b/SocketHttpListener/Net/HttpRequestStream.Managed.cs @@ -0,0 +1,196 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.ExceptionServices; +using System.Text; +using System.Threading.Tasks; + +namespace SocketHttpListener.Net +{ + // Licensed to the .NET Foundation under one or more agreements. + // See the LICENSE file in the project root for more information. + // + // System.Net.ResponseStream + // + // Author: + // Gonzalo Paniagua Javier (gonzalo@novell.com) + // + // Copyright (c) 2005 Novell, Inc. (http://www.novell.com) + // + // Permission is hereby granted, free of charge, to any person obtaining + // a copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to + // permit persons to whom the Software is furnished to do so, subject to + // the following conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + // + + internal partial class HttpRequestStream : Stream + { + private byte[] _buffer; + private int _offset; + private int _length; + private long _remainingBody; + protected bool _closed; + private Stream _stream; + + internal HttpRequestStream(Stream stream, byte[] buffer, int offset, int length) + : this(stream, buffer, offset, length, -1) + { + } + + internal HttpRequestStream(Stream stream, byte[] buffer, int offset, int length, long contentlength) + { + _stream = stream; + _buffer = buffer; + _offset = offset; + _length = length; + _remainingBody = contentlength; + } + + // Returns 0 if we can keep reading from the base stream, + // > 0 if we read something from the buffer. + // -1 if we had a content length set and we finished reading that many bytes. + private int FillFromBuffer(byte[] buffer, int offset, int count) + { + if (_remainingBody == 0) + return -1; + + if (_length == 0) + return 0; + + int size = Math.Min(_length, count); + if (_remainingBody > 0) + size = (int)Math.Min(size, _remainingBody); + + if (_offset > _buffer.Length - size) + { + size = Math.Min(size, _buffer.Length - _offset); + } + if (size == 0) + return 0; + + Buffer.BlockCopy(_buffer, _offset, buffer, offset, size); + _offset += size; + _length -= size; + if (_remainingBody > 0) + _remainingBody -= size; + return size; + } + + protected virtual int ReadCore(byte[] buffer, int offset, int size) + { + // Call FillFromBuffer to check for buffer boundaries even when remaining_body is 0 + int nread = FillFromBuffer(buffer, offset, size); + if (nread == -1) + { // No more bytes available (Content-Length) + return 0; + } + else if (nread > 0) + { + return nread; + } + + nread = _stream.Read(buffer, offset, size); + if (nread > 0 && _remainingBody > 0) + _remainingBody -= nread; + return nread; + } + + protected virtual IAsyncResult BeginReadCore(byte[] buffer, int offset, int size, AsyncCallback cback, object state) + { + if (size == 0 || _closed) + { + HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + ares._callback = cback; + ares._state = state; + ares.Complete(); + return ares; + } + + int nread = FillFromBuffer(buffer, offset, size); + if (nread > 0 || nread == -1) + { + HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + ares._buffer = buffer; + ares._offset = offset; + ares._count = size; + ares._callback = cback; + ares._state = state; + ares._synchRead = Math.Max(0, nread); + ares.Complete(); + return ares; + } + + // Avoid reading past the end of the request to allow + // for HTTP pipelining + if (_remainingBody >= 0 && size > _remainingBody) + { + size = (int)Math.Min(int.MaxValue, _remainingBody); + } + + return _stream.BeginRead(buffer, offset, size, cback, state); + } + + public override int EndRead(IAsyncResult asyncResult) + { + if (asyncResult == null) + throw new ArgumentNullException(nameof(asyncResult)); + + var r = asyncResult as HttpStreamAsyncResult; + + if (r != null) + { + if (!ReferenceEquals(this, r._parent)) + { + throw new ArgumentException("Invalid async result"); + } + if (r._endCalled) + { + throw new InvalidOperationException("Invalid end call"); + } + r._endCalled = true; + + if (!asyncResult.IsCompleted) + { + asyncResult.AsyncWaitHandle.WaitOne(); + } + + return r._synchRead; + } + + if (_closed) + return 0; + + int nread = 0; + try + { + nread = _stream.EndRead(asyncResult); + } + catch (IOException e) when (e.InnerException is ArgumentException || e.InnerException is InvalidOperationException) + { + throw e.InnerException; + } + + if (_remainingBody > 0 && nread > 0) + { + _remainingBody -= nread; + } + + return nread; + } + } +} diff --git a/SocketHttpListener/Net/HttpRequestStream.cs b/SocketHttpListener/Net/HttpRequestStream.cs new file mode 100644 index 0000000000..c54da44a17 --- /dev/null +++ b/SocketHttpListener/Net/HttpRequestStream.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SocketHttpListener.Net +{ + // Licensed to the .NET Foundation under one or more agreements. + // See the LICENSE file in the project root for more information. + // + // System.Net.ResponseStream + // + // Author: + // Gonzalo Paniagua Javier (gonzalo@novell.com) + // + // Copyright (c) 2005 Novell, Inc. (http://www.novell.com) + // + // Permission is hereby granted, free of charge, to any person obtaining + // a copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to + // permit persons to whom the Software is furnished to do so, subject to + // the following conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + // + + internal partial class HttpRequestStream : Stream + { + public override bool CanSeek => false; + public override bool CanWrite => false; + public override bool CanRead => true; + + public override int Read(byte[] buffer, int offset, int size) + { + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + if (offset < 0 || offset > buffer.Length) + { + throw new ArgumentOutOfRangeException(nameof(offset)); + } + if (size < 0 || size > buffer.Length - offset) + { + throw new ArgumentOutOfRangeException(nameof(size)); + } + if (size == 0 || _closed) + { + return 0; + } + + return ReadCore(buffer, offset, size); + } + + public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state) + { + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + if (offset < 0 || offset > buffer.Length) + { + throw new ArgumentOutOfRangeException(nameof(offset)); + } + if (size < 0 || size > buffer.Length - offset) + { + throw new ArgumentOutOfRangeException(nameof(size)); + } + + return BeginReadCore(buffer, offset, size, callback, state); + } + + public override void Flush() { } + public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask; + + public override long Length + { + get + { + throw new NotImplementedException(); + } + } + + public override long Position + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return base.BeginWrite(buffer, offset, count, callback, state); + } + + public override void EndWrite(IAsyncResult asyncResult) + { + base.EndWrite(asyncResult); + } + + internal bool Closed => _closed; + + protected override void Dispose(bool disposing) + { + _closed = true; + base.Dispose(disposing); + } + } +} diff --git a/SocketHttpListener.Portable/Net/HttpStatusCode.cs b/SocketHttpListener/Net/HttpStatusCode.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpStatusCode.cs rename to SocketHttpListener/Net/HttpStatusCode.cs diff --git a/SocketHttpListener/Net/HttpStreamAsyncResult.cs b/SocketHttpListener/Net/HttpStreamAsyncResult.cs new file mode 100644 index 0000000000..e7e516c6b4 --- /dev/null +++ b/SocketHttpListener/Net/HttpStreamAsyncResult.cs @@ -0,0 +1,85 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace SocketHttpListener.Net +{ + internal class HttpStreamAsyncResult : IAsyncResult + { + private object _locker = new object(); + private ManualResetEvent _handle; + private bool _completed; + + internal readonly object _parent; + internal byte[] _buffer; + internal int _offset; + internal int _count; + internal AsyncCallback _callback; + internal object _state; + internal int _synchRead; + internal Exception _error; + internal bool _endCalled; + + internal HttpStreamAsyncResult(object parent) + { + _parent = parent; + } + + public void Complete(Exception e) + { + _error = e; + Complete(); + } + + public void Complete() + { + lock (_locker) + { + if (_completed) + return; + + _completed = true; + if (_handle != null) + _handle.Set(); + + if (_callback != null) + Task.Run(() => _callback(this)); + } + } + + public object AsyncState + { + get { return _state; } + } + + public WaitHandle AsyncWaitHandle + { + get + { + lock (_locker) + { + if (_handle == null) + _handle = new ManualResetEvent(_completed); + } + + return _handle; + } + } + + public bool CompletedSynchronously + { + get { return (_synchRead == _count); } + } + + public bool IsCompleted + { + get + { + lock (_locker) + { + return _completed; + } + } + } + } +} diff --git a/SocketHttpListener.Portable/Net/HttpVersion.cs b/SocketHttpListener/Net/HttpVersion.cs similarity index 100% rename from SocketHttpListener.Portable/Net/HttpVersion.cs rename to SocketHttpListener/Net/HttpVersion.cs diff --git a/SocketHttpListener.Portable/Net/ListenerPrefix.cs b/SocketHttpListener/Net/ListenerPrefix.cs similarity index 100% rename from SocketHttpListener.Portable/Net/ListenerPrefix.cs rename to SocketHttpListener/Net/ListenerPrefix.cs diff --git a/SocketHttpListener.Portable/Net/ResponseStream.cs b/SocketHttpListener/Net/ResponseStream.cs similarity index 99% rename from SocketHttpListener.Portable/Net/ResponseStream.cs rename to SocketHttpListener/Net/ResponseStream.cs index b2d0d4e9c2..5949e3817e 100644 --- a/SocketHttpListener.Portable/Net/ResponseStream.cs +++ b/SocketHttpListener/Net/ResponseStream.cs @@ -304,7 +304,7 @@ namespace SocketHttpListener.Net private async Task TransmitFileManaged(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken) { - var allowAsync = _environment.OperatingSystem != OperatingSystem.Windows; + var allowAsync = _environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows; var fileOpenOptions = offset > 0 ? FileOpenOptions.RandomAccess diff --git a/SocketHttpListener.Portable/Net/WebHeaderCollection.cs b/SocketHttpListener/Net/WebHeaderCollection.cs similarity index 100% rename from SocketHttpListener.Portable/Net/WebHeaderCollection.cs rename to SocketHttpListener/Net/WebHeaderCollection.cs diff --git a/SocketHttpListener.Portable/Net/WebSockets/HttpListenerWebSocketContext.cs b/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs similarity index 100% rename from SocketHttpListener.Portable/Net/WebSockets/HttpListenerWebSocketContext.cs rename to SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs diff --git a/SocketHttpListener.Portable/Net/WebSockets/WebSocketContext.cs b/SocketHttpListener/Net/WebSockets/WebSocketContext.cs similarity index 100% rename from SocketHttpListener.Portable/Net/WebSockets/WebSocketContext.cs rename to SocketHttpListener/Net/WebSockets/WebSocketContext.cs diff --git a/SocketHttpListener.Portable/Opcode.cs b/SocketHttpListener/Opcode.cs similarity index 100% rename from SocketHttpListener.Portable/Opcode.cs rename to SocketHttpListener/Opcode.cs diff --git a/SocketHttpListener.Portable/PayloadData.cs b/SocketHttpListener/PayloadData.cs similarity index 100% rename from SocketHttpListener.Portable/PayloadData.cs rename to SocketHttpListener/PayloadData.cs diff --git a/SocketHttpListener.Portable/Primitives/ICertificate.cs b/SocketHttpListener/Primitives/ICertificate.cs similarity index 100% rename from SocketHttpListener.Portable/Primitives/ICertificate.cs rename to SocketHttpListener/Primitives/ICertificate.cs diff --git a/SocketHttpListener.Portable/Primitives/IStreamFactory.cs b/SocketHttpListener/Primitives/IStreamFactory.cs similarity index 100% rename from SocketHttpListener.Portable/Primitives/IStreamFactory.cs rename to SocketHttpListener/Primitives/IStreamFactory.cs diff --git a/SocketHttpListener.Portable/Primitives/ITextEncoding.cs b/SocketHttpListener/Primitives/ITextEncoding.cs similarity index 100% rename from SocketHttpListener.Portable/Primitives/ITextEncoding.cs rename to SocketHttpListener/Primitives/ITextEncoding.cs diff --git a/MediaBrowser.Server.Startup.Common/Properties/AssemblyInfo.cs b/SocketHttpListener/Properties/AssemblyInfo.cs similarity index 69% rename from MediaBrowser.Server.Startup.Common/Properties/AssemblyInfo.cs rename to SocketHttpListener/Properties/AssemblyInfo.cs index c8e0378046..8876cea4fe 100644 --- a/MediaBrowser.Server.Startup.Common/Properties/AssemblyInfo.cs +++ b/SocketHttpListener/Properties/AssemblyInfo.cs @@ -1,15 +1,16 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 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("MediaBrowser.Server.Startup.Common")] +[assembly: AssemblyTitle("SocketHttpListener")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.Server.Startup.Common")] -[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyProduct("SocketHttpListener")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -19,7 +20,7 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("fcc1d690-3a86-4c4b-baef-439c53e1547a")] +[assembly: Guid("1d74413b-e7cf-455b-b021-f52bdf881542")] // Version information for an assembly consists of the following four values: // @@ -27,4 +28,7 @@ using System.Runtime.InteropServices; // Minor Version // Build Number // Revision -// \ No newline at end of file +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] diff --git a/SocketHttpListener.Portable/Rsv.cs b/SocketHttpListener/Rsv.cs similarity index 100% rename from SocketHttpListener.Portable/Rsv.cs rename to SocketHttpListener/Rsv.cs diff --git a/SocketHttpListener.Portable/SocketHttpListener.Portable.csproj b/SocketHttpListener/SocketHttpListener.csproj similarity index 82% rename from SocketHttpListener.Portable/SocketHttpListener.Portable.csproj rename to SocketHttpListener/SocketHttpListener.csproj index ee902462b0..dd2d2cf0fc 100644 --- a/SocketHttpListener.Portable/SocketHttpListener.Portable.csproj +++ b/SocketHttpListener/SocketHttpListener.csproj @@ -2,19 +2,16 @@ - 11.0 Debug AnyCPU - {4F26D5D8-A7B0-42B3-BA42-7CB7D245934E} + {1D74413B-E7CF-455B-B021-F52BDF881542} Library Properties - SocketHttpListener.Portable - SocketHttpListener.Portable - en-US + SocketHttpListener + SocketHttpListener + v4.6.2 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Profile7 - v4.5 + true @@ -34,6 +31,19 @@ 4 + + + + + + + + + + + + Properties\SharedVersion.cs + @@ -58,18 +68,18 @@ + + - - @@ -80,9 +90,6 @@ - - - {9142eefa-7570-41e1-bfcc-468bb571af2f} @@ -93,11 +100,7 @@ MediaBrowser.Model - - - - - +