(config-blacklist config)
read))))
(let* ((line (read-line in-port))
- (selector-raw (string-trim-both line))
- (selector (if (= (string-length selector-raw) 0)
- "/"
- selector-raw)))
+ (selector (string-trim-both line)))
(condition-case
(begin
(with-output-to-port out-port
;;; Selector retrieval
(define (serve-selector raw-selector config)
- (let* ((selector-list (string-split raw-selector "\t"))
+ (let* ((selector-list (string-split raw-selector "\t" #t))
(selector (car selector-list))
(arguments (cdr selector-list)))
- (if (string-contains selector "|")
- (let ((l (string-split selector "|" #t)))
- (serve-script (car l) (cdr l) config))
- (case (infer-selector-type selector)
- ((1) (serve-directory-file selector config))
- ((7) (let ((l (string-split selector "?" #t)))
- (serve-script (car l) arguments config)))
- ((0) (serve-text-file selector config))
- ((h) (serve-url selector config))
- (else (serve-binary-file selector config))))))
+ (cond
+ ((string-contains selector "|")
+ (let ((l (string-split selector "|" #t)))
+ (serve-script (car l) (cdr l) config)))
+ ((legal-filename? (directory-index-filename selector config) config)
+ (serve-directory-file selector config))
+ (else
+ (case (infer-selector-type selector)
+ ((1) (error "Invalid directory selector."))
+ ((7) (let ((l (string-split selector "?" #t)))
+ (serve-script (car l) arguments config)))
+ ((0) (serve-text-file selector config))
+ ((h) (serve-url selector config))
+ (else (serve-binary-file selector config)))))))
(define (legal-filename? filename config)
(and (string-prefix? (config-root-dir config)
(string-suffix? ".scm" filename)
(file-executable? filename)))
+(define (directory-index-filename selector config)
+ (make-pathname (list (config-root-dir config)
+ selector)
+ gopher-index-filename))
+
(define (serve-directory-file selector config)
- (let ((filename (make-pathname (list (config-root-dir config) selector)
- gopher-index-filename)))
+ (let ((filename (directory-index-filename selector config)))
(if (legal-filename? filename config)
(begin
(with-input-from-file filename
(define (with-selector-dir selector config thunk)
(with-current-working-directory
- (make-pathname (config-root-dir config)
- (pathname-directory selector)) thunk))
+ (make-pathname (config-root-dir config) selector)
+ thunk))
;;; Main