From 293e1b299445e73f9149b6e6950dcefdd3c9c299 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sun, 13 Mar 2022 11:40:09 -0300 Subject: add VALID-HOSTNAME-P Initial intended application is checking data source IDEN1. This could be done as a one-liner with a more complex regex, but that seems harder to debug. Signed-off-by: David Bremner --- src/util.lisp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util.lisp') diff --git a/src/util.lisp b/src/util.lisp index 63ca21a..d1658d3 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -399,6 +399,17 @@ expansion as a starting point for your own DEFPACKAGE form for your consfig." (with-standard-io-syntax (write object :stream fifo) (terpri fifo) (finish-output fifo))) +(defun valid-hostname-p (string) + "Test whether STRING looks like a valid hostname, as defined by RFCs 952 and +1123." + (and + (<= (length string) 253) + (let ((parts (split-string string :separator "."))) + (every (lambda (part) + (and (<= (length part) 63) + (re:scan "^[a-zA-Z0-9][a-zA-Z0-9-]*$" part))) + parts)))) + ;;;; Progress & debug printing -- cgit v1.2.3