/*
* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Essentials.ServiceStack
* File: VirtualHostConfiguration.cs
*
* VirtualHostConfiguration.cs is part of VNLib.Plugins.Essentials.ServiceStack which is part of the larger
* VNLib collection of libraries and utilities.
*
* VNLib.Plugins.Essentials.ServiceStack 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 2 of the
* License, or (at your option) any later version.
*
* VNLib.Plugins.Essentials.ServiceStack 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.IO;
using System.Net;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using VNLib.Utils.Logging;
using VNLib.Plugins.Essentials.Middleware;
namespace VNLib.Plugins.Essentials.ServiceStack
{
///
/// A virtual host configuration container
///
public class VirtualHostConfiguration : IHostTransportInfo, IEpProcessingOptions
{
///
/// The directory that this virtual host will serve files from
///
public DirectoryInfo RootDir { get; set; } = null!;
///
/// The hostname, or domain name, that this virtual host will respond to
/// Default: *
///
public string Hostname { get; set; } = "*";
///
/// The transport endpoint that this virtual host will listen on
/// Default: 0.0.0.0:80
///
public IPEndPoint TransportEndpoint { get; set; } = new IPEndPoint(IPAddress.Any, 80);
///
/// An optional certificate to use for TLS connections
///
public X509Certificate? Certificate { get; set; }
///
/// A log provider to use for this virtual host
///
public ILogProvider LogProvider { get; set; } = null!;
///
/// The name of a default file to search for within a directory if no file is specified (index.html).
/// This array should be ordered.
/// Default: empty set
///
public IReadOnlyCollection DefaultFiles { get; set; } = Array.Empty();
///
/// File extensions that are denied from being read from the filesystem
/// Default: empty set
///
public IReadOnlySet ExcludedExtensions { get; set; } = new HashSet();
///
/// File attributes that must be matched for the file to be accessed, defaults to all allowed
/// Default: 0xFFFFFFFF
///
public FileAttributes AllowedAttributes { get; set; } = unchecked((FileAttributes)(0xFFFFFFFF));
///
/// Files that match any attribute flag set will be denied
/// Default:
///
public FileAttributes DissallowedAttributes { get; set; } = FileAttributes.System;
///
/// A table of known downstream servers/ports that can be trusted to proxy connections
/// Default: empty set
///
public IReadOnlySet DownStreamServers { get; set; } = new HashSet();
///
/// A for how long a connection may remain open before all operations are cancelled
/// Default: 60 seconds
///
public TimeSpan ExecutionTimeout { get; set; } = TimeSpan.FromSeconds(60);
///
/// A for how long a connection may remain idle before all operations are cancelled
///
public IVirtualHostHooks EventHooks { get; set; } = null!;
///
/// A set of custom middleware to add to virtual host middleware pipeline
///
public ICollection CustomMiddleware { get; } = new List();
internal VirtualHostConfiguration Clone() => (VirtualHostConfiguration)MemberwiseClone();
}
}