From 595eb2739742b30be21197a3c059eccb08e9926b Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 30 Jun 2022 11:05:41 +0530 Subject: bin: Introduce listen specification for web service. The new listen specification unifies unix sockets, IP addresses and ports, all into one string. * bin/tissue (address->socket-address): Delete function. (listen->socket-address): New function. (tissue-run-web): Use listen->socket-address instead of address->socket-address. Specify default listen instead of default address and port. --- bin/tissue | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'bin') diff --git a/bin/tissue b/bin/tissue index fb1656e..bf69100 100755 --- a/bin/tissue +++ b/bin/tissue @@ -190,22 +190,30 @@ Export the repository as a website to OUTPUT-DIRECTORY. (tissue-configuration-web-css (load-config)) (tissue-configuration-web-files (load-config))))))) -(define (address->socket-address address port) - "Convert ADDRESS and PORT to a socket address." +(define (listen->socket-address listen) + "Convert LISTEN specification to a socket address." (cond + ;; Unix socket + ((string-prefix? "unix:" listen) + (make-socket-address AF_UNIX + (string-remove-prefix "unix:" listen))) ;; IPv4 - ((string-contains address ".") - (make-socket-address AF_INET - (inet-pton AF_INET address) - port)) + ((guard (_ (else #f)) + (inet-pton AF_INET + (substring listen 0 (string-index-right listen #\:)))) + => (lambda (ip) + (make-socket-address + AF_INET ip (string->number + (substring listen (1+ (string-index-right listen #\:))))))) ;; IPv6 - ((string-contains address ":") - (make-socket-address AF_INET6 - (inet-pton AF_INET6 address) - port)) - ;; Unix socket (else - (make-socket-address AF_UNIX address)))) + (make-socket-address AF_INET6 + (inet-pton AF_INET6 + (string-trim-both + (substring listen 0 (string-index-right listen #\:)) + (char-set #\[ #\]))) + (string->number + (substring listen (1+ (string-index-right listen #\:)))))))) (define tissue-run-web (match-lambda* @@ -227,9 +235,8 @@ Run a web search service reading configuration from CONFIG-FILE. (append (call-with-input-file config-file read) result)) - ;; Default address and port - '((address . "127.0.0.1") - (port . 8080))))) + ;; Default listen + '((listen . "127.0.0.1:8080"))))) (let ((listen-repl (assq-ref args 'listen-repl))) (when listen-repl (spawn-server (cond @@ -243,8 +250,7 @@ Run a web search service reading configuration from CONFIG-FILE. "REPL server listening on ~a~%" listen-repl) (make-unix-domain-server-socket #:path listen-repl)))))) - (start-web-server (address->socket-address (assq-ref args 'address) - (assq-ref args 'port)) + (start-web-server (listen->socket-address (assq-ref args 'listen)) %xapian-index (tissue-configuration-web-css (load-config))))))) -- cgit v1.2.3