(let* ((selector-list (string-split raw-selector "\t"))
(selector (car selector-list))
(arguments (cdr selector-list)))
- (case (infer-selector-type selector)
- ((1) (if (string-contains selector ":")
- (let ((l (string-split selector ":")))
- (serve-directory-script (car l) (cdr l)
- config))
- (serve-directory-file selector config)))
- ((7) (let ((l (string-split selector "?")))
- (serve-directory-script (car l) arguments config)))
- ((0) (serve-text-file selector config))
- ((h) (serve-url selector config))
- (else (serve-binary-file selector config)))))
+ (if (string-contains selector ":")
+ (let ((l (string-split selector ":")))
+ (serve-script (car l) (cdr l) config))
+ (case (infer-selector-type selector)
+ ((1) (serve-directory-file selector config))
+ ((7) (let ((l (string-split selector "?")))
+ (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 (serve-directory-script selector arguments config)
- (let ((filename (make-pathname (config-root-dir config) selector)))
- (if (legal-script-filename? filename config)
- (let* ((sexp (with-input-from-file filename read))
- (selector-dir (pathname-directory selector)))
- (serve-records (with-selector-dir
- selector config
- (lambda ()
- (apply (eval sexp) arguments)))
- selector-dir config)
- (print ".\r"))
- (error "No legal index script not found." filename))))
-
(define (serve-directory-file selector config)
(let ((filename (make-pathname (list (config-root-dir config) selector)
gopher-index-filename)))
"<a href=\"" url "\">" url "</a>\n"
"</body></html>")))
+(define (serve-script selector arguments config)
+ (let ((filename (make-pathname (config-root-dir config) selector)))
+ (if (legal-script-filename? filename config)
+ (let* ((sexp (with-input-from-file filename read))
+ (script-result (with-selector-dir
+ selector config
+ (lambda ()
+ (apply (eval sexp) arguments)))))
+ (when (pair? script-result)
+ (serve-records script-result
+ (pathname-directory selector) config)
+ (print ".\r")))
+ (error "No legal index script not found." filename))))
+
;;; Index rendering
(let ((string (read-string #f in-port)))
(if (and (not (eof-object? string))
(> (string-length string) 0))
- (serve-info-records (string-chomp string "\n"))))))))
+ (serve-info-records (string-chomp string "\n")))
+ (close-input-port in-port)
+ (close-output-port out-port))))))
(define (serve-expression expression dir-selector config)
(with-selector-dir