From be6dc557a3b819248b014992eb96c1cb21f8112b Mon Sep 17 00:00:00 2001 From: vnugent Date: Sun, 8 Jan 2023 14:44:01 -0500 Subject: Initial commit --- Plugins.Essentials/src/FileProcessArgs.cs | 169 ++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 Plugins.Essentials/src/FileProcessArgs.cs (limited to 'Plugins.Essentials/src/FileProcessArgs.cs') diff --git a/Plugins.Essentials/src/FileProcessArgs.cs b/Plugins.Essentials/src/FileProcessArgs.cs new file mode 100644 index 0000000..dae695b --- /dev/null +++ b/Plugins.Essentials/src/FileProcessArgs.cs @@ -0,0 +1,169 @@ +/* +* Copyright (c) 2022 Vaughn Nugent +* +* Library: VNLib +* Package: VNLib.Plugins.Essentials +* File: FileProcessArgs.cs +* +* FileProcessArgs.cs is part of VNLib.Plugins.Essentials which is part of the larger +* VNLib collection of libraries and utilities. +* +* VNLib.Plugins.Essentials is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* VNLib.Plugins.Essentials is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see https://www.gnu.org/licenses/. +*/ + +using System; +using System.Net; + +namespace VNLib.Plugins.Essentials +{ + /// + /// Server routine to follow after processing selector + /// + public enum FpRoutine + { + /// + /// There was an error during processing and the server should immediatly respond with a error code + /// + Error, + /// + /// The server should continue the file read operation with the current information + /// + Continue, + /// + /// The server should redirect the conneciton to an alternate location + /// + Redirect, + /// + /// The server should immediatly respond with a error code + /// + Deny, + /// + /// The server should fulfill the reqeest by sending the contents of an alternate file location (if it exists) with the existing connection + /// + ServeOther, + /// + /// The server should immediatly respond with a error code + /// + NotFound, + /// + /// Serves another file location that must be a trusted fully qualified location + /// + ServeOtherFQ, + /// + /// The connection does not require a file to be processed + /// + VirtualSkip, + } + + /// + /// Specifies operations the file processor will follow during request handling + /// + public readonly struct FileProcessArgs : IEquatable + { + /// + /// Signals the file processor should complete with a routine + /// + public static readonly FileProcessArgs Deny = new (FpRoutine.Deny); + /// + /// Signals the file processor should continue with intended/normal processing of the request + /// + public static readonly FileProcessArgs Continue = new (FpRoutine.Continue); + /// + /// Signals the file processor should complete with a routine + /// + public static readonly FileProcessArgs Error = new (FpRoutine.Error); + /// + /// Signals the file processor should complete with a routine + /// + public static readonly FileProcessArgs NotFound = new (FpRoutine.NotFound); + /// + /// Signals the file processor should not process the connection + /// + public static readonly FileProcessArgs VirtualSkip = new (FpRoutine.VirtualSkip); + /// + /// The routine the file processor should execute + /// + public readonly FpRoutine Routine { get; init; } + /// + /// An optional alternate path for the given routine + /// + public readonly string Alternate { get; init; } + + /// + /// Initializes a new with the specified routine + /// and empty path + /// + /// The file processing routine to execute + public FileProcessArgs(FpRoutine routine) + { + this.Routine = routine; + this.Alternate = string.Empty; + } + /// + /// Initializes a new with the specified routine + /// and alternate path + /// + /// + /// + public FileProcessArgs(FpRoutine routine, string alternatePath) + { + this.Routine = routine; + this.Alternate = alternatePath; + } + /// + /// + /// + /// + /// + /// + public static bool operator == (FileProcessArgs arg1, FileProcessArgs arg2) + { + return arg1.Equals(arg2); + } + /// + /// + /// + /// + /// + /// + public static bool operator != (FileProcessArgs arg1, FileProcessArgs arg2) + { + return !arg1.Equals(arg2); + } + /// + public bool Equals(FileProcessArgs other) + { + //make sure the routine types match + if (Routine != other.Routine) + { + return false; + } + //Next make sure the hashcodes of the alternate paths match + return (Alternate?.GetHashCode(StringComparison.OrdinalIgnoreCase)) == (other.Alternate?.GetHashCode(StringComparison.OrdinalIgnoreCase)); + } + /// + public override bool Equals(object obj) + { + return obj is FileProcessArgs args && Equals(args); + } + /// + /// + /// + /// + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} \ No newline at end of file -- cgit