diff options
-rw-r--r-- | lib/Net.Compression/VNLib.Net.Compression/CompressorManager.cs | 2 | ||||
-rw-r--r-- | lib/Net.Compression/vnlib_compress/Taskfile.yaml | 27 | ||||
-rw-r--r-- | lib/Net.Compression/vnlib_compress/package.json | 10 | ||||
-rw-r--r-- | lib/Net.Http/src/Core/Request/HttpRequest.cs | 2 | ||||
-rw-r--r-- | lib/Net.Rest.Client/src/Construction/Extensions.cs | 39 | ||||
-rw-r--r-- | lib/Plugins.Essentials/src/Accounts/AccountUtils.cs | 6 | ||||
-rw-r--r-- | lib/Plugins.Essentials/src/Sessions/SessionBase.cs | 5 | ||||
-rw-r--r-- | lib/Utils/src/IO/IStreamBufferFactory.cs | 4 | ||||
-rw-r--r-- | lib/Utils/src/IO/IsolatedStorageDirectory.cs | 4 | ||||
-rw-r--r-- | lib/Utils/src/IO/VnStreamReader.cs | 70 |
10 files changed, 124 insertions, 45 deletions
diff --git a/lib/Net.Compression/VNLib.Net.Compression/CompressorManager.cs b/lib/Net.Compression/VNLib.Net.Compression/CompressorManager.cs index bcc85c9..2407ba0 100644 --- a/lib/Net.Compression/VNLib.Net.Compression/CompressorManager.cs +++ b/lib/Net.Compression/VNLib.Net.Compression/CompressorManager.cs @@ -64,7 +64,7 @@ namespace VNLib.Net.Compression /// <param name="config">The json configuration element</param> public void OnLoad(ILogProvider? log, JsonElement? config) { - _compLevel = CompressionLevel.Optimal; + _compLevel = CompressionLevel.Fastest; string libPath = NATIVE_LIB_NAME; if(config.HasValue) diff --git a/lib/Net.Compression/vnlib_compress/Taskfile.yaml b/lib/Net.Compression/vnlib_compress/Taskfile.yaml new file mode 100644 index 0000000..51aaf79 --- /dev/null +++ b/lib/Net.Compression/vnlib_compress/Taskfile.yaml @@ -0,0 +1,27 @@ +# https://taskfile.dev + +#Called by the vnbuild system to produce builds for my website +#https://www.vaughnnugent.com/resources/software + +#This taskfile is specific to this project, since it must be compiled on the target platform +#this simply packs the source code into a tgz file for download + +version: '3' + +tasks: + + #when build succeeds, archive the output into a tgz + postbuild_success: + cmds: + - cmd: powershell mkdir -Force './bin' + #copy source code to target + - powershell -Command "Get-ChildItem -Include *.c,*.h,*.txt -Path * | Resolve-Path -Relative | tar --files-from - -czf 'bin/src.tgz'" + + postbuild_failed: + cmds: [] + +#Remove the output dirs on clean + clean: + ignore_error: true + cmds: + - cmd: powershell Remove-Item -Recurse './bin' diff --git a/lib/Net.Compression/vnlib_compress/package.json b/lib/Net.Compression/vnlib_compress/package.json new file mode 100644 index 0000000..6373511 --- /dev/null +++ b/lib/Net.Compression/vnlib_compress/package.json @@ -0,0 +1,10 @@ +{ + "name": "vnlib_compress", + "version": "0.1.0", + "author": "Vaughn Nugent", + "description": "A CMake cross platform native data compression library, provides brotli and zlib compressors in a single stream api", + "copyright": "Copyright \u00A9 2023 Vaughn Nugent", + "company": "Vaughn Nugent", + "repository": "https://github.com/VnUgE/VNLib.Core/tree/main/lib/Net.Compression/vnlib_compress", + "output_dir": "bin" +}
\ No newline at end of file diff --git a/lib/Net.Http/src/Core/Request/HttpRequest.cs b/lib/Net.Http/src/Core/Request/HttpRequest.cs index 2cc99bd..ddf592e 100644 --- a/lib/Net.Http/src/Core/Request/HttpRequest.cs +++ b/lib/Net.Http/src/Core/Request/HttpRequest.cs @@ -80,7 +80,7 @@ namespace VNLib.Net.Http.Core //Create new collection for headers Headers = new(); //Create new collection for request cookies - Cookies = new(); + Cookies = new(StringComparer.OrdinalIgnoreCase); //New list for accept Accept = new(); AcceptLanguage = new(); diff --git a/lib/Net.Rest.Client/src/Construction/Extensions.cs b/lib/Net.Rest.Client/src/Construction/Extensions.cs index bbc8b1d..ca0873b 100644 --- a/lib/Net.Rest.Client/src/Construction/Extensions.cs +++ b/lib/Net.Rest.Client/src/Construction/Extensions.cs @@ -76,6 +76,45 @@ namespace VNLib.Net.Rest.Client.Construction } /// <summary> + /// Executes a request against the site by sending the request model parameter. An <see cref="IRestEndpointAdapter{TModel}"/> must be + /// defined to handle requests of the given model type. + /// </summary> + /// <typeparam name="TModel"></typeparam> + /// <typeparam name="TJson">The response entity type</typeparam> + /// <param name="site"></param> + /// <param name="entity">The request entity model to send to the server</param> + /// <param name="cancellation">A token to cancel the operation</param> + /// <returns>A task that resolves the response message with json resonse support</returns> + public static async Task<RestResponse<TJson>> ExecuteAsync<TModel, TJson>(this IRestSiteAdapter site, TModel entity, CancellationToken cancellation = default) + { + //Get the adapter for the model + IRestEndpointAdapter<TModel> adapter = site.GetAdapter<TModel>(); + + //Get new request on adapter + RestRequest request = adapter.GetRequest(entity); + + //Wait to exec operations if needed + await site.WaitAsync(cancellation); + + RestResponse<TJson> response; + + //Get rest client + using (ClientContract contract = site.GetClient()) + { + //Exec response + response = await contract.Resource.ExecuteAsync<TJson>(request, cancellation); + } + + //Site handler should not cause an exception + site.OnResponse(response); + + //invoke response handlers + adapter.OnResponse(entity, response); + + return response; + } + + /// <summary> /// Executes a request using a model that defines its own endpoint information, on the current site and returns the response /// </summary> /// <typeparam name="TModel">The request model type</typeparam> diff --git a/lib/Plugins.Essentials/src/Accounts/AccountUtils.cs b/lib/Plugins.Essentials/src/Accounts/AccountUtils.cs index 137fa4a..1b30934 100644 --- a/lib/Plugins.Essentials/src/Accounts/AccountUtils.cs +++ b/lib/Plugins.Essentials/src/Accounts/AccountUtils.cs @@ -468,12 +468,12 @@ namespace VNLib.Plugins.Essentials.Accounts #endregion - #region Privilage Extensions + #region Privilege Extensions /// <summary> - /// Compares the users privilage level against the specified level + /// Compares the users privilege level against the specified level /// </summary> /// <param name="session"></param> - /// <param name="level">64bit privilage level to compare</param> + /// <param name="level">64bit privilege level to compare</param> /// <returns>true if the current user has at least the specified level or higher</returns> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasLevel(this in SessionInfo session, byte level) => (session.Privilages & LEVEL_MSK) >= (((ulong)level << LEVEL_MSK_OFFSET) & LEVEL_MSK); diff --git a/lib/Plugins.Essentials/src/Sessions/SessionBase.cs b/lib/Plugins.Essentials/src/Sessions/SessionBase.cs index 100818b..33a0dbd 100644 --- a/lib/Plugins.Essentials/src/Sessions/SessionBase.cs +++ b/lib/Plugins.Essentials/src/Sessions/SessionBase.cs @@ -95,8 +95,11 @@ namespace VNLib.Plugins.Essentials.Sessions ///<inheritdoc/> public virtual SessionType SessionType { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get => Enum.Parse<SessionType>(this[SESSION_TYPE_ENTRY]); - protected set => this[SESSION_TYPE_ENTRY] = ((byte)value).ToString(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected set => this[SESSION_TYPE_ENTRY] = value.ToString(); } ///<inheritdoc/> diff --git a/lib/Utils/src/IO/IStreamBufferFactory.cs b/lib/Utils/src/IO/IStreamBufferFactory.cs index f8cfe2d..5aab76b 100644 --- a/lib/Utils/src/IO/IStreamBufferFactory.cs +++ b/lib/Utils/src/IO/IStreamBufferFactory.cs @@ -3,9 +3,9 @@ * * Library: VNLib * Package: VNLib.Utils -* File: VnStreamReader.cs +* File: IStreamBufferFactory.cs * -* VnStreamReader.cs is part of VNLib.Utils which is part of the larger +* IStreamBufferFactory.cs is part of VNLib.Utils which is part of the larger * VNLib collection of libraries and utilities. * * VNLib.Utils is free software: you can redistribute it and/or modify diff --git a/lib/Utils/src/IO/IsolatedStorageDirectory.cs b/lib/Utils/src/IO/IsolatedStorageDirectory.cs index 65460ff..c06018e 100644 --- a/lib/Utils/src/IO/IsolatedStorageDirectory.cs +++ b/lib/Utils/src/IO/IsolatedStorageDirectory.cs @@ -126,9 +126,13 @@ namespace VNLib.Utils.IO Storage.DeleteDirectory(this.DirectoryPath); } + ///<inheritdoc/> public override long AvailableFreeSpace => Storage.AvailableFreeSpace; + ///<inheritdoc/> public override long Quota => Storage.Quota; + ///<inheritdoc/> public override long UsedSize => Storage.UsedSize; + ///<inheritdoc/> public override bool IncreaseQuotaTo(long newQuotaSize) => Storage.IncreaseQuotaTo(newQuotaSize); /// <summary> diff --git a/lib/Utils/src/IO/VnStreamReader.cs b/lib/Utils/src/IO/VnStreamReader.cs index a03a1de..22df5c7 100644 --- a/lib/Utils/src/IO/VnStreamReader.cs +++ b/lib/Utils/src/IO/VnStreamReader.cs @@ -107,28 +107,12 @@ namespace VNLib.Utils.IO ///<inheritdoc/> public override async Task<string?> ReadLineAsync() { + string? result = null; + //If buffered data is available, check for line termination - if (Available > 0) + if (Available > 0 && GetStringFromBuffer(ref result)) { - //Get current buffer window - Memory<byte> buffered = _buffer.AccumulatedBuffer; - - //search for line termination in current buffer - int term = buffered.IndexOf(LineTermination); - - //Termination found in buffer window - if (term > -1) - { - //Capture the line from the begining of the window to the termination - Memory<byte> line = buffered[..term]; - - //Shift the window to the end of the line (excluding the termination) - _buffer.AdvanceStart(term + LineTermination.Length); - - //Decode the line to a string - return Encoding.GetString(line.Span); - } - //Termination not found + return result; } //Compact the buffer window and see if space is avialble to buffer more data @@ -143,24 +127,11 @@ namespace VNLib.Utils.IO //No string found return null; } - - //Get current buffer window - Memory<byte> buffered = _buffer.AccumulatedBuffer; - - //search for line termination in current buffer - int term = buffered.IndexOf(LineTermination); - - //Termination found in buffer window - if (term > -1) + + //Termination not found + if (GetStringFromBuffer(ref result)) { - //Capture the line from the begining of the window to the termination - Memory<byte> line = buffered[..term]; - - //Shift the window to the end of the line (excluding the termination) - _buffer.AdvanceStart(term + LineTermination.Length); - - //Decode the line to a string - return Encoding.GetString(line.Span); + return result; } } //Termination not found within the entire buffer, so buffer space has been exhausted @@ -170,6 +141,31 @@ namespace VNLib.Utils.IO throw new OutOfMemoryException("A line termination was not found within the buffer"); #pragma warning restore CA2201 // Do not raise reserved exception types } + + private bool GetStringFromBuffer(ref string? result) + { + //Get current buffer window + Memory<byte> buffered = _buffer.AccumulatedBuffer; + + //search for line termination in current buffer + int term = buffered.IndexOf(LineTermination); + + //Termination found in buffer window + if (term > -1) + { + //Capture the line from the begining of the window to the termination + Memory<byte> line = buffered[..term]; + + //Shift the window to the end of the line (excluding the termination) + _buffer.AdvanceStart(term + LineTermination.Length); + + //Decode the line to a string + result = Encoding.GetString(line.Span); + return true; + } + + return false; + } ///<inheritdoc/> public override int Read(char[] buffer, int index, int count) => Read(buffer.AsSpan(index, count)); |