From f519eb8473bf276ef53503a4454afcd28c09fcce Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Dec 2022 15:51:14 -0600 Subject: add option for case sensitive regular expressions --- src/slskd/Core/Options.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 814b9b90..e23fd640 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -381,6 +381,15 @@ namespace slskd [Description("use volatile data storage (all data will be lost at shutdown)")] [RequiresRestart] public bool Volatile { get; init; } = false; + + /// + /// Gets a value indicating whether user-defined regular expressions are case sensitive. + /// + [Argument(default, "case-sensitive-regex")] + [EnvironmentVariable("CASE_SENSITIVE_REGEX")] + [Description("user-defined regular expressions are case sensitive")] + [RequiresRestart] + public bool CaseSensitiveRegEx { get; init; } = false; } /// -- cgit v1.2.3 From 53f13352b0dbc6b5d9ab134b140a9bec6910676a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Dec 2022 15:52:00 -0600 Subject: document new option --- docs/config.md | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/config.md b/docs/config.md index 6a96588d..b1eb177a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -849,18 +849,19 @@ feature: Several additional feature flags are provided to change the application's runtime behavior, which is helpful during development. Available feature flags are: -| Flag | Environment Variable | Description | -| -------------------- | -------------------------- | ---------------------------------------------------------------- | -| `-d\|--debug` | `SLSKD_DEBUG` | Run the application in debug mode. Produces verbose log output. | -| `--experimental` | `SLSKD_EXPERIMENTAL` | Run the application in experimental mode. YMMV. | -| `-n\|--no-logo` | `SLSKD_NO_LOGO` | Don't show the application logo on startup | -| `-x\|--no-start` | `SLSKD_NO_START` | Bootstrap the application, but don't start | -| `--no-connect` | `SLSKD_NO_CONNECT` | Start the application, but don't connect to the server | -| `--no-share-scan` | `SLSKD_NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup | -| `--force-share-scan` | `SLSKD_FORCE_SHARE_SCAN` | Force a scan of shared directories on startup | -| `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup | -| `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework | -| `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) | +| Flag | Environment Variable | Description | +| ------------------------ | ---------------------------- | ---------------------------------------------------------------- | +| `-d\|--debug` | `SLSKD_DEBUG` | Run the application in debug mode. Produces verbose log output. | +| `--experimental` | `SLSKD_EXPERIMENTAL` | Run the application in experimental mode. YMMV. | +| `-n\|--no-logo` | `SLSKD_NO_LOGO` | Don't show the application logo on startup | +| `-x\|--no-start` | `SLSKD_NO_START` | Bootstrap the application, but don't start | +| `--no-connect` | `SLSKD_NO_CONNECT` | Start the application, but don't connect to the server | +| `--no-share-scan` | `SLSKD_NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup | +| `--force-share-scan` | `SLSKD_FORCE_SHARE_SCAN` | Force a scan of shared directories on startup | +| `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup | +| `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework | +| `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) | +| `--case-sensitive-regex` | `SLSKD_CASE_SENSITIVE_REGEX` | User-defined regular expressions are case sensitive | #### **YAML** ```yaml @@ -872,6 +873,8 @@ flags: no_share_scan: false no_version_check: false log_sql: false + volatile: false + case_sensitive_regex: false ``` # Commands -- cgit v1.2.3 From bbe4e17c499414d0ed7bed983075cdfeae1984e3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Dec 2022 15:52:16 -0600 Subject: add static Flags property --- src/slskd/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 0b82e825..04d3b7e4 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -157,6 +157,11 @@ namespace slskd /// public static bool IsRelayAgent { get; private set; } + /// + /// Gets the application flags. + /// + public static Options.FlagsOptions Flags { get; private set; } + /// /// Gets the path where application data is saved. /// @@ -364,6 +369,7 @@ namespace slskd } IsRelayAgent = OptionsAtStartup.Relay.Enabled && OptionsAtStartup.Relay.Mode.ToEnum() == RelayMode.Agent; + Flags = OptionsAtStartup.Flags; ConfigureGlobalLogger(); Log = Serilog.Log.ForContext(typeof(Program)); -- cgit v1.2.3 From 88e83d6b0fdeb1d3a5500ab45795ec3a4a35eb7c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Dec 2022 15:53:06 -0600 Subject: selectively ignore case when compiling search filters --- src/slskd/Application.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 71fb140d..44b7c627 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -118,7 +118,16 @@ namespace slskd PreviousOptions = OptionsMonitor.CurrentValue; - CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled)); + Flags = Program.Flags; + + var regexOptions = RegexOptions.Compiled; + + if (!Flags.CaseSensitiveRegEx) + { + regexOptions |= RegexOptions.IgnoreCase; + } + + CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, regexOptions)); State = state; State.OnChange(state => State_OnChange(state)); @@ -203,6 +212,7 @@ namespace slskd private IMemoryCache Cache { get; set; } = new MemoryCache(new MemoryCacheOptions()); private IEnumerable CompiledSearchResponseFilters { get; set; } private IEnumerable ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty(); + private Options.FlagsOptions Flags { get; set; } public void CollectGarbage() { -- cgit v1.2.3 From 1a5aac776066fb217786a6c0488184e9febe8fa0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Dec 2022 15:53:42 -0600 Subject: selectively ignore case sensitivity for share filters --- src/slskd/Shares/ShareScanner.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs index f5bbcd41..30a67ee6 100644 --- a/src/slskd/Shares/ShareScanner.cs +++ b/src/slskd/Shares/ShareScanner.cs @@ -72,6 +72,8 @@ namespace slskd.Shares { WorkerCount = workerCount; SoulseekFileFactory = soulseekFileFactory ?? new SoulseekFileFactory(); + + Flags = Program.Flags; } /// @@ -86,6 +88,7 @@ namespace slskd.Shares private IManagedState State { get; } = new ManagedState(); private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1); private CancellationTokenSource CancellationTokenSource { get; set; } + private Options.FlagsOptions Flags { get; set; } /// /// Scans the configured shares and fills the cache. @@ -132,8 +135,15 @@ namespace slskd.Shares Log.Information("Shared file cache re-created and ready for scan."); } + var regexOptions = RegexOptions.Compiled; + + if (!Flags.CaseSensitiveRegEx) + { + regexOptions |= RegexOptions.IgnoreCase; + } + var filters = options.Filters - .Select(filter => new Regex(filter, RegexOptions.Compiled)) + .Select(filter => new Regex(filter, regexOptions)) .ToList(); Log.Information("Starting shared file scan"); -- cgit v1.2.3 From 0f1b69a9c82232067afdcea684a2f84deb304110 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Dec 2022 16:03:52 -0600 Subject: add note about insensitive defaults --- docs/config.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/config.md b/docs/config.md index b1eb177a..aed3a424 100644 --- a/docs/config.md +++ b/docs/config.md @@ -143,6 +143,8 @@ Aliases: Share filters can be used to prevent certain types of files from being shared. This option is an array that can take any number of filters. Filters must be a valid regular expression; a few examples are included below and in the example configuration included with the application, but the list is empty by default. +Filter expressions are case insensitive by default. + | Command Line | Environment Variable | Description | | ------------------------- | ----------------------------- | --------------------------------------------------------------------- | | `--share-filter` | `SLSKD_SHARE_FILTER` | A list of regular expressions used to filter files from shares | @@ -683,6 +685,8 @@ A number of filters can be configured to control various aspects of how the appl Share filters can be used to prevent certain types of files from being shared. This option is an array that can take any number of filters. Filters must be a valid regular expression; a few examples are included below and in the example configuration included with the application, but the list is empty by default. +Filter expressions are case insensitive by default. + | Command Line | Environment Variable | Description | | ------------------------- | ----------------------- | --------------------------------------------------------------------- | | `--share-filter` | `SLSKD_SHARE_FILTER` | A list of regular expressions used to filter files from shares | -- cgit v1.2.3