2002-02-23 09:42:50 -05:00
|
|
|
;;; http server in the Scheme Shell -*- Scheme -*-
|
2002-08-27 05:03:22 -04:00
|
|
|
|
|
|
|
;;; This file is part of the Scheme Untergrund Networking package.
|
|
|
|
|
|
|
|
;;; Copyright (c) 2002 by Mike Sperber.
|
|
|
|
;;; For copyright information, see the file COPYING which comes with
|
|
|
|
;;; the distribution.
|
2002-02-23 09:42:50 -05:00
|
|
|
|
|
|
|
;;; This package manages options to the http server as an abstract
|
|
|
|
;;; data type.
|
|
|
|
|
|
|
|
(define-record-type httpd-options :httpd-options
|
|
|
|
(really-make-httpd-options port
|
|
|
|
root-directory
|
|
|
|
fqdn
|
|
|
|
reported-port
|
2002-09-22 11:41:41 -04:00
|
|
|
request-handler
|
2002-02-23 09:42:50 -05:00
|
|
|
server-admin
|
2002-03-25 06:35:05 -05:00
|
|
|
simultaneous-requests
|
2003-01-30 11:09:20 -05:00
|
|
|
log-file
|
2002-08-22 12:10:08 -04:00
|
|
|
syslog?
|
|
|
|
resolve-ips?)
|
2002-02-23 09:42:50 -05:00
|
|
|
httpd-options?
|
|
|
|
(port httpd-options-port
|
|
|
|
set-httpd-options-port!)
|
|
|
|
(root-directory httpd-options-root-directory
|
|
|
|
set-httpd-options-root-directory!)
|
|
|
|
(fqdn httpd-options-fqdn
|
|
|
|
set-httpd-options-fqdn!)
|
|
|
|
(reported-port httpd-options-reported-port
|
|
|
|
set-httpd-options-reported-port!)
|
2002-09-22 11:41:41 -04:00
|
|
|
(request-handler httpd-options-request-handler
|
|
|
|
set-httpd-options-request-handler!)
|
2002-02-23 09:42:50 -05:00
|
|
|
(server-admin httpd-options-server-admin
|
|
|
|
set-httpd-options-server-admin!)
|
|
|
|
(simultaneous-requests httpd-options-simultaneous-requests
|
2002-03-25 06:35:05 -05:00
|
|
|
set-httpd-options-simultaneous-requests!)
|
2003-01-30 11:09:20 -05:00
|
|
|
(log-file httpd-options-log-file set-httpd-options-log-file!)
|
2002-08-22 12:10:08 -04:00
|
|
|
(syslog? httpd-options-syslog? set-httpd-options-syslog?!)
|
|
|
|
(resolve-ips? httpd-options-resolve-ips? set-httpd-options-resolve-ips?!))
|
2002-02-23 09:42:50 -05:00
|
|
|
|
2002-03-25 06:35:05 -05:00
|
|
|
; default httpd-options generation
|
2002-08-26 09:10:57 -04:00
|
|
|
(define (make-default-httpd-options)
|
2002-02-23 09:42:50 -05:00
|
|
|
(really-make-httpd-options 80 ; port
|
|
|
|
"/" ; root-directory
|
|
|
|
#f ; fqdn
|
|
|
|
#f ; reported-port
|
2002-09-22 11:41:41 -04:00
|
|
|
#f ; request-handler
|
2002-04-03 13:02:58 -05:00
|
|
|
#f ; server-admin
|
2002-03-25 06:35:05 -05:00
|
|
|
#f ; simultaneous-requests
|
2002-08-26 05:46:11 -04:00
|
|
|
#f
|
2003-01-30 11:09:20 -05:00
|
|
|
; string: filename of log-file (directory must exist)
|
2002-08-26 05:46:11 -04:00
|
|
|
; output-port: log to this port (e.g. (current-error-port))
|
|
|
|
; #f: no logging
|
2002-08-22 12:10:08 -04:00
|
|
|
#t ; Do syslogging?
|
2003-01-30 11:09:20 -05:00
|
|
|
#t)) ; Write host names instead of IPs in log-files?
|
2002-03-25 06:35:05 -05:00
|
|
|
|
|
|
|
; creates a copy of a given httpd-option
|
2002-02-23 09:42:50 -05:00
|
|
|
|
|
|
|
(define (copy-httpd-options options)
|
2002-08-26 09:10:57 -04:00
|
|
|
(let ((new-options (make-default-httpd-options)))
|
2002-02-23 09:42:50 -05:00
|
|
|
(set-httpd-options-port! new-options
|
|
|
|
(httpd-options-port options))
|
|
|
|
(set-httpd-options-root-directory! new-options
|
|
|
|
(httpd-options-root-directory options))
|
|
|
|
(set-httpd-options-fqdn! new-options
|
|
|
|
(httpd-options-fqdn options))
|
|
|
|
(set-httpd-options-reported-port! new-options
|
|
|
|
(httpd-options-reported-port options))
|
2002-09-22 11:41:41 -04:00
|
|
|
(set-httpd-options-request-handler! new-options
|
|
|
|
(httpd-options-request-handler options))
|
2002-02-23 09:42:50 -05:00
|
|
|
(set-httpd-options-server-admin! new-options
|
|
|
|
(httpd-options-server-admin options))
|
|
|
|
(set-httpd-options-simultaneous-requests!
|
|
|
|
new-options
|
|
|
|
(httpd-options-simultaneous-requests options))
|
2003-01-30 11:09:20 -05:00
|
|
|
(set-httpd-options-log-file! new-options (httpd-options-log-file options))
|
2002-03-25 06:35:05 -05:00
|
|
|
(set-httpd-options-syslog?! new-options (httpd-options-syslog? options))
|
2002-08-22 12:10:08 -04:00
|
|
|
(set-httpd-options-resolve-ips?! new-options (httpd-options-resolve-ips? options))
|
2002-02-23 09:42:50 -05:00
|
|
|
new-options))
|
|
|
|
|
2002-03-25 06:35:05 -05:00
|
|
|
; (make-httpd-options-transformer set-option!) -> lambda (new-value [httpd-option])
|
|
|
|
; creates a transformer for httpd-options
|
|
|
|
; the returned procedure is called with the new value for the option
|
|
|
|
; and optionally with the httpd-option to change
|
2002-02-23 09:42:50 -05:00
|
|
|
(define (make-httpd-options-transformer set-option!)
|
|
|
|
(lambda (new-value . stuff)
|
|
|
|
(let ((new-options (if (not (null? stuff))
|
|
|
|
(copy-httpd-options (car stuff))
|
2002-08-26 09:10:57 -04:00
|
|
|
(make-default-httpd-options))))
|
2002-02-23 09:42:50 -05:00
|
|
|
(set-option! new-options new-value)
|
|
|
|
new-options)))
|
|
|
|
|
2002-03-25 06:35:05 -05:00
|
|
|
; several transformers for port, root-directory, etc.
|
2002-02-23 09:42:50 -05:00
|
|
|
(define with-port
|
|
|
|
(make-httpd-options-transformer set-httpd-options-port!))
|
|
|
|
(define with-root-directory
|
|
|
|
(make-httpd-options-transformer set-httpd-options-root-directory!))
|
|
|
|
(define with-fqdn
|
|
|
|
(make-httpd-options-transformer set-httpd-options-fqdn!))
|
|
|
|
(define with-reported-port
|
|
|
|
(make-httpd-options-transformer set-httpd-options-reported-port!))
|
2002-09-22 11:41:41 -04:00
|
|
|
(define with-request-handler
|
|
|
|
(make-httpd-options-transformer set-httpd-options-request-handler!))
|
2002-02-23 09:42:50 -05:00
|
|
|
(define with-server-admin
|
|
|
|
(make-httpd-options-transformer set-httpd-options-server-admin!))
|
|
|
|
(define with-simultaneous-requests
|
|
|
|
(make-httpd-options-transformer set-httpd-options-simultaneous-requests!))
|
2003-01-30 11:09:20 -05:00
|
|
|
(define with-log-file
|
|
|
|
(make-httpd-options-transformer set-httpd-options-log-file!))
|
2002-03-25 06:35:05 -05:00
|
|
|
(define with-syslog?
|
|
|
|
(make-httpd-options-transformer set-httpd-options-syslog?!))
|
2002-08-22 12:10:08 -04:00
|
|
|
(define with-resolve-ips?
|
|
|
|
(make-httpd-options-transformer set-httpd-options-resolve-ips?!))
|
2002-03-25 06:35:05 -05:00
|
|
|
|
2002-08-26 09:10:57 -04:00
|
|
|
(define (make-httpd-options . stuff)
|
|
|
|
(let loop ((options (make-default-httpd-options))
|
|
|
|
(stuff stuff))
|
|
|
|
(if (null? stuff)
|
|
|
|
options
|
|
|
|
(let* ((transformer (car stuff))
|
|
|
|
(value (cadr stuff)))
|
|
|
|
(loop (transformer value options)
|
|
|
|
(cddr stuff))))))
|