aboutsummaryrefslogtreecommitdiff
path: root/Plugins.Essentials/src/FileProcessArgs.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-01-08 14:44:01 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2023-01-08 14:44:01 -0500
commitbe6dc557a3b819248b014992eb96c1cb21f8112b (patch)
tree5361530552856ba8154bfcfbfac8377549117c9e /Plugins.Essentials/src/FileProcessArgs.cs
parent072a1294646542a73007784d08a35ffcad557b1b (diff)
Initial commit
Diffstat (limited to 'Plugins.Essentials/src/FileProcessArgs.cs')
-rw-r--r--Plugins.Essentials/src/FileProcessArgs.cs169
1 files changed, 169 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// Server routine to follow after processing selector
+ /// </summary>
+ public enum FpRoutine
+ {
+ /// <summary>
+ /// There was an error during processing and the server should immediatly respond with a <see cref="HttpStatusCode.InternalServerError"/> error code
+ /// </summary>
+ Error,
+ /// <summary>
+ /// The server should continue the file read operation with the current information
+ /// </summary>
+ Continue,
+ /// <summary>
+ /// The server should redirect the conneciton to an alternate location
+ /// </summary>
+ Redirect,
+ /// <summary>
+ /// The server should immediatly respond with a <see cref="HttpStatusCode.Forbidden"/> error code
+ /// </summary>
+ Deny,
+ /// <summary>
+ /// The server should fulfill the reqeest by sending the contents of an alternate file location (if it exists) with the existing connection
+ /// </summary>
+ ServeOther,
+ /// <summary>
+ /// The server should immediatly respond with a <see cref="HttpStatusCode.NotFound"/> error code
+ /// </summary>
+ NotFound,
+ /// <summary>
+ /// Serves another file location that must be a trusted fully qualified location
+ /// </summary>
+ ServeOtherFQ,
+ /// <summary>
+ /// The connection does not require a file to be processed
+ /// </summary>
+ VirtualSkip,
+ }
+
+ /// <summary>
+ /// Specifies operations the file processor will follow during request handling
+ /// </summary>
+ public readonly struct FileProcessArgs : IEquatable<FileProcessArgs>
+ {
+ /// <summary>
+ /// Signals the file processor should complete with a <see cref="FpRoutine.Deny"/> routine
+ /// </summary>
+ public static readonly FileProcessArgs Deny = new (FpRoutine.Deny);
+ /// <summary>
+ /// Signals the file processor should continue with intended/normal processing of the request
+ /// </summary>
+ public static readonly FileProcessArgs Continue = new (FpRoutine.Continue);
+ /// <summary>
+ /// Signals the file processor should complete with a <see cref="FpRoutine.Error"/> routine
+ /// </summary>
+ public static readonly FileProcessArgs Error = new (FpRoutine.Error);
+ /// <summary>
+ /// Signals the file processor should complete with a <see cref="FpRoutine.NotFound"/> routine
+ /// </summary>
+ public static readonly FileProcessArgs NotFound = new (FpRoutine.NotFound);
+ /// <summary>
+ /// Signals the file processor should not process the connection
+ /// </summary>
+ public static readonly FileProcessArgs VirtualSkip = new (FpRoutine.VirtualSkip);
+ /// <summary>
+ /// The routine the file processor should execute
+ /// </summary>
+ public readonly FpRoutine Routine { get; init; }
+ /// <summary>
+ /// An optional alternate path for the given routine
+ /// </summary>
+ public readonly string Alternate { get; init; }
+
+ /// <summary>
+ /// Initializes a new <see cref="FileProcessArgs"/> with the specified routine
+ /// and empty <see cref="Alternate"/> path
+ /// </summary>
+ /// <param name="routine">The file processing routine to execute</param>
+ public FileProcessArgs(FpRoutine routine)
+ {
+ this.Routine = routine;
+ this.Alternate = string.Empty;
+ }
+ /// <summary>
+ /// Initializes a new <see cref="FileProcessArgs"/> with the specified routine
+ /// and alternate path
+ /// </summary>
+ /// <param name="routine"></param>
+ /// <param name="alternatePath"></param>
+ public FileProcessArgs(FpRoutine routine, string alternatePath)
+ {
+ this.Routine = routine;
+ this.Alternate = alternatePath;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="arg1"></param>
+ /// <param name="arg2"></param>
+ /// <returns></returns>
+ public static bool operator == (FileProcessArgs arg1, FileProcessArgs arg2)
+ {
+ return arg1.Equals(arg2);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="arg1"></param>
+ /// <param name="arg2"></param>
+ /// <returns></returns>
+ public static bool operator != (FileProcessArgs arg1, FileProcessArgs arg2)
+ {
+ return !arg1.Equals(arg2);
+ }
+ ///<inheritdoc/>
+ 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));
+ }
+ ///<inheritdoc/>
+ public override bool Equals(object obj)
+ {
+ return obj is FileProcessArgs args && Equals(args);
+ }
+ /// <summary>
+ /// <inheritdoc/>
+ /// </summary>
+ /// <returns></returns>
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+ }
+} \ No newline at end of file