aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-12-09 19:33:24 -0600
committerJP Dillingham <jp@dillingham.me>2025-12-09 19:33:24 -0600
commitb90b5a96654727c7ded4a5b926bc315aa99014ee (patch)
treed1d6fc475b0387e10102ee589ec6c15b754df450 /src
parentc026b58c435372b7042d5a1ddf911dd4429ba993 (diff)
downloadslskd-b90b5a96654727c7ded4a5b926bc315aa99014ee.tar.gz
add support for commaa separated lists of IPs
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Validation/IPAddressAttribute.cs31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/slskd/Common/Validation/IPAddressAttribute.cs b/src/slskd/Common/Validation/IPAddressAttribute.cs
index 6e53df57..17ae5f08 100644
--- a/src/slskd/Common/Validation/IPAddressAttribute.cs
+++ b/src/slskd/Common/Validation/IPAddressAttribute.cs
@@ -25,6 +25,13 @@ namespace slskd.Validation
/// </summary>
public class IPAddressAttribute : ValidationAttribute
{
+ public IPAddressAttribute(bool allowCommaSeparatedValues = false)
+ {
+ AllowCommaSeparatedValues = allowCommaSeparatedValues;
+ }
+
+ private bool AllowCommaSeparatedValues { get; set; }
+
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null)
@@ -36,9 +43,29 @@ namespace slskd.Validation
return fail;
}
- if (!IPAddress.TryParse(valueAsString, out _))
+ if (!valueAsString.Contains(','))
{
- return fail;
+ if (!IPAddress.TryParse(valueAsString, out _))
+ {
+ return fail;
+ }
+ }
+ else
+ {
+ if (!AllowCommaSeparatedValues)
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field accepts a single value only (a comma separated list was specified)");
+ }
+
+ var values = valueAsString.Split(',');
+
+ foreach (var currentValue in values)
+ {
+ if (!IPAddress.TryParse(currentValue, out _))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field contains one or more invalid IPv4 or IPv6 IP addresses.");
+ }
+ }
}
}