(define burrower-footer
(conc "\n"
"--------------------------------------------------\n"
- "This gopher hole was dug using Burrower v" burrower-version "\n"
+ "This gopher hole was dug using Burrower v" burrower-version ".\n"
"Powered by Chicken Scheme!"))
;;; Server loop
(define-record config root-dir host port display-footer)
(define (run-server config)
+ (set-buffering-mode! (current-output-port) #:line)
(print "Gopher server listening on port " (config-port config) " ...")
(let ((listener (tcp-listen (config-port config))))
(let server-loop ()
((or (= (string-length l) 0) (string-suffix? "/" l)) 1)
((has-suffix? l ".txt" ".org" ".md") 0)
((has-suffix? l ".png" ".jpg" ".gif" ".bmp" ".tif" ".tga") 'I)
- ((has-suffix? l "?.scm") 7)
+ ((has-suffix? l "?.scm" "%3f.scm") 7)
((has-prefix? l "url:" "/url:") 'h)
(else 9))))
(regular-file? filename)))
(define (serve-directory selector config)
- (let ((filename (make-pathname (list (config-root-dir config) selector
- gopher-index-filename))))
+ (let ((filename (make-pathname (list (config-root-dir config) selector)
+ gopher-index-filename)))
(if (legal-filename? filename config)
(begin
(with-input-from-file filename
(serve-info-records (read-line)))
(loop (peek-char)))))))
(if (config-display-footer config)
- (serve-info-records burrower-footer)))
+ (serve-info-records burrower-footer))
+ (print ".\r"))
(error "Index file not found."))))
(define (serve-text-file selector config)
(let ((filename (make-pathname (config-root-dir config) selector)))
(if (legal-filename? filename config)
- (with-input-from-file filename
- (lambda ()
- (for-each
- (lambda (line)
- (print line "\r"))
- (read-lines))))
+ (begin
+ (with-input-from-file filename
+ (lambda ()
+ (for-each
+ (lambda (line)
+ (print line "\r"))
+ (read-lines))))
+ (print ".\r"))
(error "File not found." filename))))
(define (serve-binary-file selector config)
(error "File not found." filename))))
(define (serve-query selector arguments config)
- (let ((filename (make-pathname (config-root-dir config) selector)))
+ (let ((filename (make-pathname (config-root-dir config)
+ (string-translate* selector '(("%3f" . "?"))))))
(if (and (legal-filename? filename config)
(= (length arguments) 1))
(with-input-from-file filename
(define (serve-url selector config)
(let ((url (substring selector 4)))
(print
- "If you are seeing this page, your gopher browser does not\r\n"
- "properly support URL directory entries or cannot follow such\r\n"
- "links. To view the link you requested, use a web browser to\r\n"
- "open the follwing url:\r\n"
- "\r\n"
- url "\r\n")))
+ "<html><head><title>Redirection</title>"
+ "<meta http-equiv=\"refresh\" content=\"10; URL='" url "'\" />"
+ "</head><body>"
+ "<p>If you are seeing this page, your gopher browser does not "
+ "properly support URL directory entries or cannot follow such "
+ "links.</p>"
+ "<p>If you are viewing this page using a web browser, you should "
+ "be redirected shortly. Otherwise, you can manually open the "
+ "the follwing url:\n"
+ "\n"
+ "<a href=\"" url "\">" url "</a>\n"
+ "</body></html>")))
;;; Index rendering
(config-port-set! config (string->number (caddr args))))
(run-server config)))))))
-(main)
+;; (main)
-;; (define (test)
-;; (run-server (make-config "gopher-root" "localhost" 70 #t)))
+(define (test)
+ (run-server (make-config "gopher-root" "localhost" 70 #t)))
;; (test)