Author SHA1 Message Date
vibr bccf27785d rename READ-AND-DISCARD-TRAILER to DISCARD-TRAILER for naming consistency 2005-04-20 11:40:23 +00:00
vibr d06479ee4b adapt httpd-handler-lib-interface and httpd-handler structure to
implementation of chunked transfer coding in handler-lib
2005-04-16 20:49:29 +00:00
vibr 15049e1c58 implementing chunked transfer coding:
*new proc  READ-MESSAGE-BODY: a high-level interface for reading in
message bodies (should be used by all handlers)
*new proc READ-ORDINARY-BODY: reads in message bodies with no transfer
coding applied
*new proc READ-CHUNKED-BODY: reads in message bodies in chunked
transfer coding
*new proc GET-CHUNK-SIZE: reads in and parses the size of the next
chunk in a chunked message body
*helper procs READ-AND-DISCARD-TRAILER and DISCARD-LINE-TERMINATOR
*minor changes to GET-NUMERIC-FIELD-VALUE (cosmetic)
2005-04-16 20:45:33 +00:00
vibr 555d52806d modify seval-handler:
*don't use concept of reader-writer-body (which is broken), use
writer-body instead -> seval-handler now works correctly
*use new interface READ-MESSAGE-BODY from handler-lib for reading in the
message body
*rename READ-REQUEST-SEXP to PARSE-REQUEST-SEXP
*catch errors thrown by READ in PARSE-REQUEST-SEXP to answer 400
instead of 500 for requests whose message body doesn't contain a valid
s-expression
2005-04-16 20:33:35 +00:00
vibr 36db985453 in PARSE-HTTP-REQUEST: catch errors thrown by READ-RFC822-HEADERS and
answer 400 instead of 500 for requests with bad headers
2005-04-16 20:22:41 +00:00
vibr 0554b2d494 move copyright declarations to COPYING 2005-04-16 20:19:32 +00:00
vibr 630c77d83f syntax of comma separated list which is the field value of the
Transfer-Encoding header: needs a single SP less
2005-04-15 15:50:30 +00:00
vibr d174ad3954 add a copy of the regexp definitions HEX and ESCAPED from structure
url to resolve mutual dependency
2005-04-15 15:34:48 +00:00
vibr 184c284c4a move these procs from lib/sunet-utilities to httpd/handler-lib:
GET-SOCKET-HOST-STRING
GET-NUMERIC-FIELD-VALUE
GET-BODY-LENGTH-FROM-CONTENT-LENGTH
CHUNKED-TRANSFER-CODING?
reason: they are httpd-specific in using httpd's data types
2005-04-15 15:23:32 +00:00
vibr d915722a9b implementing chunked transfer coding:
* new predicate CHUNKED-TRANSFER-CODING?
 tests wether a request's entity body is sent in chunked
 transfer-encoding
2005-04-15 12:31:43 +00:00
vibr 4c1e1a16a8 trivia: towards a more modern HTML: closing slash within empty HTML
elements
*new: EMIT-EMPTY-TAG
*use EMIT-EMPTY-TAG instead of EMIT-TAG where appropriate
2005-04-14 21:15:21 +00:00
vibr e8dc69b745 we must send a "Connection: close" header as long as we don't support
persistent connections
2005-04-14 19:17:16 +00:00
vibr db826a9c1f add comment explaining why the concept of http-reader-writer-body
(which is used by the seval-handler only) doesn't work
2005-04-14 15:18:54 +00:00
vibr 8e7e071db2 fix MAKE-CLF (which prepended superfluous slash to requested resource) 2005-04-14 14:42:03 +00:00
vibr 9d3ddd79b9 *delete GET-SOCKET-HOSTNAME-AND-PORTNUMBER (was buggy anyway)
*rewrite GET-SOCKET-HOST-STRING
2005-04-14 14:06:00 +00:00
vibr 8974332da1 Location header must be an absolute URL:
*adapt file-dir-handler's 301 response
*new procs GET-SOCKET-HOSTNAME-AND-PORTNUMBER, GET-SOCKET-HOST-STRING
2005-04-14 11:38:37 +00:00
vibr 96b485294f *new predicate ABSOLUTE-URL?
*remove URI-HAS-PROTOCOL?
2005-04-14 11:32:38 +00:00
vibr f605367c1a answer 400 (Bad Request) for 1.1-Requests which don't include a Host
header:
*new proc CHECK-HOST-HEADER
2005-04-13 20:53:53 +00:00
vibr 453a7cdde6 correct call of http-error in MAKE-HOST-NAME-HANDLER 2005-04-13 20:48:57 +00:00
vibr 97f730075d trivia: formatting of error responses 2005-04-13 20:46:40 +00:00
vibr 40d7c923a2 answer 505 (Version not supported) for requests with major version >
implemented version:
*new proc CHECK-MAJOR-HTTP-VERSION
*new case in MAKE-ERROR-RESPONSE
2005-04-13 19:35:22 +00:00
vibr fe6b3fffac change URL-Parser's interface: parser now preserves info whether
Request-URI's path ends with a slash.
(See http://httpd.apache.org/docs-2.0/misc/rewriteguide.html ->
"Trailing slash problem" for reasons).
2005-04-13 10:32:29 +00:00
vibr 9118345aaa typos 2005-04-13 10:25:14 +00:00
vibr 33b3eb8df7 better documentation of HTTP-URL->URL-STRING and HTTP-URL-PATH->PATH-STRING 2005-04-10 15:30:32 +00:00
vibr d209db26d8 document new URL parser 2005-04-10 15:17:50 +00:00
vibr 0c7c957f2b add comment 2005-04-10 15:15:55 +00:00
vibr a44c53bc67 typos + emphasis 2005-04-10 13:14:02 +00:00
vibr e9bc839cd5 finally adapt documentation to new uri lib procs 2005-04-10 13:03:33 +00:00
vibr 90fc61473e add comment on assumptions about entity in request to seval-handler 2005-04-06 22:49:50 +00:00
vibr c9c45eae6e better comment 2005-04-06 22:47:14 +00:00
vibr 9342e0e593 *replace call of PARSE-REQUEST-URI (relict of old URL parser)
with call of URL-STRING->HTTP-URL
2005-04-06 22:45:48 +00:00
vibr 2dcdd41ed9 *reinsert lost line
*replace calls of UNESCAPE-URI (relict of old URL parser) with UNESCAPE
*simplify URI-HAS-PROTOCOL?
2005-04-06 22:43:53 +00:00
vibr 512ccfaed3 removal of old URL parser relicts:
*replace calls of UNESCAPE-URI with UNESCAPE
*remove imports of uri package where no longer needed
2005-04-06 22:41:10 +00:00
vibr ed53670895 *add comment explaining why we don't need to support "*" and authority
Request-URIS
*comment on when unescaping is done
*don't unescape query when building a http-url record
*don't escape query when unparsing a http-url record.
*remove PARSED-URI->HTTP-URL, integrate its code into
URL-STRING->HTTP-URL
*add dummy encoder ESCAPE-NOT-UNRESERVED-CHARS
2005-04-06 22:31:33 +00:00
vibr 745a123735 adapt code to remove calls of URI-PATH->URI (relict of old URL parser) 2005-04-06 12:32:17 +00:00
vibr 61a63b4d4b adapt URI-HAS-PROTOCOL? to new URL parser 2005-04-06 11:59:05 +00:00
vibr 0de6fe79b4 replace calls of HTTP-URL->STRING (relict of old URL parser)
with calls of HTTP-URL->URL-STRING
2005-04-06 11:44:28 +00:00
vibr 17a46a7e71 rename URI-STRING->HTTP-URL to URL-STRING->HTTP-URL 2005-04-06 11:35:37 +00:00
vibr 5836ae567b export HTTP-URL-PATH->PATH-STRING in url-interface 2005-04-05 18:45:53 +00:00
vibr 9399bf9397 remove MY-REPORTED-PORT (relict of old URL parser) 2005-04-05 18:45:02 +00:00
vibr da10de6309 add function HTTP-URL-PATH->PATH-STRING (unparses path in http-url record into string) 2005-04-05 18:43:23 +00:00
vibr e5c8cae17f rename HTTP-URL->URI-STRING to HTTP-URL->URL-STRING 2005-04-05 10:59:13 +00:00
vibr 1e93a6cb9f rename PARSE-URI to PARSE-URL 2005-04-05 10:50:12 +00:00
vibr c3b855ae22 minor changes:
*HTTP1.1 (this is wishful thinking)
*we don't have a general URI parser, just a URL parser
*typos
*alles irdische hat einen namen
2005-04-04 21:23:16 +00:00
vibr 3548b25c26 rename HTTP-URL-SEARCH to HTTP-URL-QUERY (adaption to restructured
http-url type in url.scm)
2005-04-04 21:13:35 +00:00
vibr d0c64d371a further restrict url-interface 2005-04-04 21:10:05 +00:00
vibr 46645ccd58 *remove definition of PARSE-REQUEST-URI (relict of Olin's old URL parser)
*use URI-STRING->HTTP-URL instead
2005-04-04 21:07:55 +00:00
vibr d864e4da80 correct reference in comment 2005-04-04 20:57:36 +00:00
vibr cf747a97b4 *add solution for mistake in RFC 2616 (where query part of
Request-URIs is only allowed for absoluteURIs)
*rename PARSE-HTTP-URL to URI-STRING->HTTP-URL
2005-04-04 15:35:50 +00:00
vibr ba78eba433 *add comment on another mistake in RFC 2616 (query part of
Request-URIs only allowed for absoluteURIs)
*add copy of Appendix A of RFC 2396 for convenience
2005-04-04 13:36:54 +00:00
vibr 69948e9561 adapt definitions of interfaces and structures to new URI
parsing framework
2004-10-18 18:33:19 +00:00
vibr ed1e4428c5 *move general procedures ESCAPE, UNESCAPE and their helper procs from
url.scm to uri.scm
-->Parser/Unparser for HTTP 1.1 URIs is now complete and resides in
url.scm; Encoder/Decoder applicable to URIs in general resides in uri.scm.
(All has been rewritten from scratch, next to nothing of Olin's code
is left).
<--
2004-10-18 18:23:03 +00:00
vibr 584bfa2cdb *work around scsh bug (?) in definition of charset UNRESERVED
*new procs for encoding URIs:
-general proc ESCAPE taking an RegExp representing forbidden chars as argument
-specialized procs ESCAPE-SEGMENT, ESCAPE-QUERY
*new helper proc ASCII->ESCAPED
*use ESCAPE-SEGMENT and ESCAPE-URI in HTTP-URL->URI-STRING
2004-10-18 17:35:40 +00:00
vibr c48446ba7f *remove ESCAPE-URI (didn't reliably differentiate between different portions of
a URI)
*move INT->HEXCHAR to url.scm
2004-10-18 16:37:32 +00:00
vibr 44a8ef28be *new procedure UNESCAPE (unescape URI-components using RegExps)
*move HEXCHAR->INT from uri.scm to here
*use UNESCAPE in PARSED-URI->HTTP-URL
2004-10-14 17:18:24 +00:00
vibr 9e71b351d4 *remove UNESCAPE-URI, HEX-DIGIT?
*move HEXCHAR->INT to url.scm
2004-10-14 17:14:44 +00:00
vibr 932f03a638 *fix two typos in RegExps
*better comments for PARSE-URI, SPLIT-PATH
*make SPLIT-PATH really accept PARSE-URI's return values
*restructure record-type HTTP-URL
*new procedure PARSED-URI->HTTP-URL
*rewrite PARSE-HTTP-URL to use PARSE-URI and PARSED-URI->HTTP-URL
*remove out-dated comments
*remove out-dated procedure PARSE-HTTP-URL-STRING
*remove DEFAULT-HTTP-SERVER (relict of server record-type)
*rewrite HTTP-URL->STRING
*rename HTTP-URL->STRING to HTTP-URL->URI-STRING
2004-10-11 17:01:32 +00:00
vibr fe08e779f0 remove record-type server and associated procedures
(being a relict of parsing of general URIs)
2004-10-11 09:05:24 +00:00
vibr 41d3e29766 *add comment on how ambiguous definition of Request_URIs in RFC 2616
is 'solved' by uri-parser

*add comment on record-type server and associated procedures
2004-10-11 08:54:41 +00:00
vibr 8de8e01f0d adapt documentation to reflect removal of old uri-parser and addition
of new one
2004-10-10 18:30:45 +00:00
vibr a1e79c4fc7 parse HTTP 1.1 URIs:
* add RegExps
* add proc PARSE-URI
* add proc SPLIT-ABS-PATH
2004-10-06 19:10:49 +00:00
vibr d9950a9b0b remove PARSE-URI from exports of module uri 2004-10-06 19:08:19 +00:00
vibr 2cb8502f9e remove uri-parser PARSE-URI
(completely out-of-date, has never seen RFC 2396)
2004-10-06 13:33:45 +00:00
vibr 649f374e8b add comment on uri-parser 2004-10-06 13:29:06 +00:00
vibr 53e3e9672f adapt to RFC terminology:
rename PARSE-HTTP-SERVERS-URL-FRAGMENT to PARSE-REQUEST-URI
rename variable uri-string to request-uri
2004-10-05 10:24:29 +00:00
vibr cd22ab11d4 Corrected bug: SEVAL now generates a response-body even if the request's body isn't
form-url encoded or doesn't contain a program
2004-08-15 12:44:55 +00:00
vibr 38f2594ba5 emit less newlines 2004-08-15 12:40:06 +00:00
vibr 35565068fb char-set:blank = LWS from RFC 2616 (after folding) 2004-08-15 12:02:36 +00:00
vibr ffac0ebcac simplified get-numeric-field-value (now uses string-trim-both),
adapted packages.scm
2004-08-15 11:49:15 +00:00
vibr 8bf71fc3a5 get-numeric-field-value: correct error message 2004-08-15 11:06:39 +00:00
vibr 44100cbf5e Added type NO-BODY for responses which must not contain a message-body
(201, 304, 404). Added export of type-predicate no-body?.  Adapted
SEND-HTTP-RESPONSE to check for no-body responses. Extended
MAKE-ERROR-RESPONSE to make responses 201, 304, 404.
2004-08-15 11:03:28 +00:00
vibr 0bb601a0e0 make server-generated webpages XHTML 1.0 Strict: emit prolog
(not tested)
2004-08-14 22:08:07 +00:00
vibr 549594bef4 with-tag* outputs no newlines 2004-08-14 22:05:06 +00:00
vibr ef48e4e5ae make-host-name-handler now uses get-header from sunet-utilities.scm 2004-08-14 22:03:19 +00:00
vibr 8cf841bad3 rename get-content-length to get-body-length-from-content-length
move get-body-length-from-content-length and get-numeric-field-value
from seval.scm to sunet-utilities.scm

adapt packages.scm
2004-08-14 21:58:11 +00:00
vibr f8559581d2 GET-NUMERIC-FIELD-VALUE now uses GET-HEADER from utilities.scm
and returns #f if GET-HEADER does so

adapted GET-CONTENT-LENGHT
2004-08-14 21:18:12 +00:00
vibr aea0e950ba removed definition of GET-HEADER which conflicted with definition of
GET-HEADER in utilities.scm and wasn't exported anyway
2004-08-14 20:54:57 +00:00
vibr ffbe3b21cd factor out parsing of content-length header value -> GET-CONTENT-LENGTH
generalize parsing of content-length header value to parse all header field
values of the form 1*DIGIT -> GET-NUMERIC-FIELD-VALUE

check for valid content-length header in SEVAL before answering 200

TODO: SEVAL is still buggy for request with invalid _body_
2004-08-14 19:07:23 +00:00
vibr 9fcfcf36f0 add comments explaining why seval-handler is buggy 2004-08-14 15:47:29 +00:00
vibr 06ec0f0293 server-generated webpages -> XHTML 1.0 Strict:
add XML namespace declaration to html element
2004-08-13 15:49:19 +00:00
vibr 6969b80206 - move XHTML stuff from responses.scm to htmlout.scm
- new function EMIT-PROLOG
- define XML namespace declaration
- adapt macro %hack-attr-elt: special treatment of xmlnsdecl-attr
(this is not nice, but the only alternative was hard-coding the XML
namespace declaration into the various handlers)
- element names -> lower case
2004-08-13 15:46:53 +00:00
vibr 96f0ae41d5 -move XHTML stuff from responses.scm to htmlout.scm
-don't use WRITE-STRING with \n (\n within strings is not in R5RS),
instead use FORMAT with ~%
-use EMIT-PROLOG and EMIT-TAG from htmlout.scm
2004-08-13 15:37:31 +00:00
vibr c089e26e96 move XHTML stuff from responses.scm to htmlout.scm, adapt
packages.scm
2004-08-13 15:34:00 +00:00
vibr a9ae5061d0 make server generated html pages XHTML 1.0 Strict:
element names -> lower case
2004-08-13 15:26:50 +00:00
vibr 4d7f10960c fix typo 2004-08-11 19:38:16 +00:00
vibr 7bdd94cdb5 "moved-temp" -> "temp-redirect"
(HTTP/1.1: use 307 instead of 302 for unambiguity)
2004-08-11 19:06:05 +00:00
vibr 7b6f5675af allow header in 405 answers 2004-08-11 14:53:11 +00:00
vibr 880a05229c -adapt calls of make-error-response
-allow header in 405 answers
-answer 501, not 405, for unimplemented/unrecognized methods
2004-08-11 14:51:51 +00:00
vibr 5f64e72cd0 make-error-response:
more meaningful error description: show parsed uri
2004-08-11 14:48:11 +00:00
vibr 3abe557a86 make-error-response in response.scm uses http-url->string 2004-08-11 14:45:32 +00:00
vibr 8b09f2b338 -adapt calls of make-error-response
-answer 501, not 405, for unimplemented/unrecognized methods
2004-08-11 12:28:46 +00:00
vibr 1c4445933d adapt docu of make-error-response to its reworked interface 2004-08-11 10:43:26 +00:00
vibr f22f43ccd1 make-error-response:
use stuff in req where req isn't #f
2004-08-11 10:17:14 +00:00
vibr 2ee378aea9 add comments:
-make clear difference between http-error and
fatal-syntax-error
-refer to make-error-response for args of http-error
2004-08-11 09:20:31 +00:00
vibr a3dd880c7a +catch calls of make-error-response with too few arguments 2004-08-10 14:26:50 +00:00
vibr 4b37826de8 +comment/question 2004-08-10 14:25:55 +00:00
vibr 1bdac52ad6 adapt calls of make-error-response: remove tautologous description of errors 2004-07-30 22:26:50 +00:00
vibr 7c7be57a22 changes to make-error-response:
(1)no special treatment of first "optional" argument
- rationale: a different number of args is required depending on the
specific error code

(2)use close-html to write out all _effectively_ optional args

(3)generated html-pages are valid XHTML 1.0 Strict

(4)require header Allow for 405 errors

(5)more exact descriptions of errors in generated html-pages

TODO: handle calls of make-error-response with too little args
2004-07-30 22:25:03 +00:00
vibr 63e4761c58 adapt calls of make-error-response:
no URI header field in 1.1
2004-07-29 16:09:31 +00:00
vibr 5e14a326b9 adapt make-error-response:
- no URI header field in 1.1
- new 30x status codes in 1.1
2004-07-29 16:08:30 +00:00
vibr 1b4bdb59c6 updated status codes 2004-07-16 15:09:55 +00:00
vibr f96d93b355 re-commit revision 1.22, this time to branch http-1-1 2004-05-27 14:47:46 +00:00
vibr e4a887d491 Revert last commit. 2004-05-24 15:54:58 +00:00
vibr a2a656ad99 1.0->1.1: updated status codes 2004-05-24 15:42:13 +00:00
mainzelm ae913b3b90 + Some changes from start-web-server
+ Add CGI support
2004-05-24 12:00:34 +00:00
mainzelm 1374c26247 Some changes from start-web-server 2004-05-24 11:59:56 +00:00
vibr 1bd77d4b10 added comments 2004-05-17 16:42:45 +00:00
vibr 96216b243d answer HTTP/1.0 for requests with unknown HTTP-version 2004-05-17 16:39:17 +00:00
mainzelm 7090147e49 Set default port to 8080 2004-05-17 08:35:47 +00:00
mainzelm 3311f6af34 Moved startup scripts to web-server directory 2004-05-17 08:34:07 +00:00
mainzelm b7e37f8767 + Add sample links for rman and info gateways.
+ Mention required startup scripts.
2004-05-17 08:15:47 +00:00
interp aeed1acfc2 Mention SUrflets as in README. 2004-05-13 21:27:55 +00:00
interp 9d67969c09 Adjust section about installing SSAX to package proposal
Minor reformatting / typos removed
2004-05-13 21:27:26 +00:00
mainzelm b568965f6e Fix computation of default directories 2004-05-13 08:34:03 +00:00
mainzelm c7693e9bc7 Correct description of extended-web-server 2004-05-13 08:31:13 +00:00
interp a838425ca3 Show update message if entered energy is out of range. 2004-05-12 20:20:52 +00:00
interp 5e12e7ec0e In MAIN: use args parameter instead of command-line for directory;
allows to start from within scsh manually
2004-05-12 19:59:43 +00:00
interp 84e22f065e html is part of CVS tree. Thus, ignore index.html and man* files in html directory instead. 2004-05-12 19:57:17 +00:00
interp 59e79fa839 Ignore html and pdf directory 2004-05-12 19:51:32 +00:00
interp b4c3ad937e In MAIN: get directory from args parameter, not from command-line;
allows to start from within scsh manually
2004-05-12 19:44:06 +00:00
interp 246c2b46ad In MAIN: get directory from args parameter, not command-line;
allows to start main from within scsh manually
Add comments how to use rman-handler and info-handler
2004-05-12 19:43:13 +00:00
interp 7a04cf81d5 Omit warning message if INFOPATH is not set. 2004-05-12 19:28:17 +00:00
interp e13ad264bc Omit warning message if MANPATH is not set. 2004-05-12 19:28:04 +00:00
mainzelm fe45fdc230 Mention and explain sample web servers. 2004-05-12 07:49:50 +00:00
mainzelm fe9e6fe3b9 Include INSTALL in the tarball. 2004-05-12 07:29:45 +00:00
mainzelm 1a2218b89f Move default location of httpd.log file to /tmp 2004-05-11 12:10:13 +00:00
eknauel 704ffae307 Use args-fold (SRFI-37) for parsing command-line arguments 2004-05-11 12:04:10 +00:00
eknauel 7db04b74e2 kill junk char 2004-05-11 12:03:30 +00:00
mainzelm e4cf4931a3 Don't put the Makefile into the tarball, it contains only the dist target. 2004-05-05 16:47:17 +00:00
mainzelm 93256f3b71 Require SSAX 4.9 to use SUnet. 2004-05-05 16:45:39 +00:00
mainzelm f105fec02e Don't put install-lib files into the tarball. 2004-05-05 16:44:02 +00:00
mainzelm 079d184b57 Fix path to the manual. 2004-05-05 16:22:26 +00:00
mainzelm d662676607 Minor updates. 2004-05-05 16:17:09 +00:00
mainzelm 0d574180af Use the SSAX package by Michel Schinz. 2004-05-05 16:16:26 +00:00
mainzelm 2edc598503 Updates for the installation with the install-lib. 2004-04-15 18:41:58 +00:00
mainzelm addba89427 First steps towards 2.1 release. 2004-03-31 20:32:10 +00:00
mainzelm e0a76f5094 Bump version number, adjust date. 2004-03-31 20:00:32 +00:00
mainzelm 6a19726813 Add install-lib-version 2004-03-29 11:05:18 +00:00
sperber 0db253e1a1 Add hack for the benefits of ftpds on AFS directories, to enable
anonymous-upload directories:

We don't list a directory unless the Unix permissions would allow us
to.
2004-03-26 13:46:56 +00:00
mainzelm cca616721a Fixed some inconsistencies in the documentation of the DNS library. 2004-03-24 20:55:29 +00:00
mainzelm 6cf0413f98 Export a whole bunch of procedures from the low-level interface of the
DNS library.
2004-03-24 20:53:19 +00:00
mainzelm 222f5c5052 Return 'unsupported-message-type if message type is unknown, return
'unsupported-message-class if message class is unknown.

This makes it possible to parse replies that contain IP6 addresses in
the additional section.
2004-03-24 20:52:12 +00:00
mainzelm a65a5c5f86 Fixed severe bug in WITH-LOCK. Noted by Taylor Campbell 2004-03-16 07:30:14 +00:00
mainzelm f328c0537f In copy-ascii-port->port, get length of line only after checking for EOF. 2004-02-17 16:07:22 +00:00
interp 73f55ffb1b Add tags target that got lost on the way 2004-02-17 15:07:36 +00:00
mainzelm a65dbd70e4 On restart, set the file port to unbuffered mode before seeking to
work around scsh limitiation.
2004-02-10 12:27:57 +00:00
eknauel b7314f87f1 + Use SRFI-37 (arg-fold) for parsing command-line-arguments 2004-02-09 08:09:35 +00:00
mainzelm 2b27ee6569 Use location of script to find web-server root 2004-02-03 14:11:26 +00:00
mainzelm 0a7ada489d + Install example scripts
+ Use library search path to find SUnet in example scripts
+ Add option to install without SSAX
2004-02-03 13:51:51 +00:00
interp 1fe7ec1e6f Moving SUrflets webserver to top level,
adjusting startup scripts and documentation accordingly.
Replaced index.html (small & no content) by index2.html.
2004-02-02 17:49:37 +00:00
mainzelm ed74e197ee The annotation of an address is not put into the URL so URI escaping
it is superfluous and wrong.
2004-02-02 17:37:01 +00:00
mainzelm bf44e9d93d Add generation of load.scm 2004-02-02 10:49:10 +00:00
mainzelm 7668a290dc Use Michel's install-lib for installation of SUnet 2004-02-02 10:26:26 +00:00
mainzelm b65323b81b URI escape address annotations 2004-02-02 10:24:05 +00:00
mainzelm ff5bca073d Added a missing port argument. 2004-02-02 10:22:21 +00:00
mainzelm 2066f225bf Fixed parsing of comments in resolv.conf 2004-02-02 10:21:20 +00:00
mainzelm cf8911921d Fixed bug in send-receive-message-tcp where a WITH-HANDLER was called
with erroneous arguments.
2004-01-27 16:29:42 +00:00
interp 5ece0109b1 another todo task (tell about cygwin) 2004-01-22 00:48:11 +00:00
interp 15b5138bd0 Some more sections (session-data, part of mysxml) 2004-01-18 03:32:08 +00:00
interp 63d708b219 Move SUrflet howto into main documentation.
Merge 2 decls.tex together.
Drawback: can't use url package anymore.
2004-01-17 01:35:16 +00:00
interp 25e03fe5e4 More example files for the surflet howto. 2004-01-15 03:47:39 +00:00
interp 721fee4e07 More howto. Draft like version. 2004-01-15 03:46:27 +00:00
mainzelm f231780bf0 Fixed typo (uri-path->uri instead of uri-path-list->path) noted by Jorgen Schaefer <forcer@forcix.cx> 2004-01-13 14:53:00 +00:00
mainzelm 3027a81a75 Document URI-ESCAPED-CHARS as defined in RFC 2396. 2003-12-18 12:54:46 +00:00
interp 05a17e07d7 Use own decls.tex for HowTo. Might merge with doc/decls.tex in the future. 2003-11-21 19:10:12 +00:00
interp 8baad2666f Initial version of How To Use SUrflets.
Needs still some additions.
2003-11-21 19:09:36 +00:00
interp 52e0a557e2 Some example files mentioned in the howto. 2003-11-21 19:09:12 +00:00
interp 07ef3aa5c2 SSAX (and we) need this patch to work. 2003-11-21 19:05:54 +00:00
interp 25fa9fbca5 Make it a bit more portable.
Change default port from webcache to http-alt.
2003-11-21 19:05:02 +00:00
interp 73dfefd439 Exclude some LaTeX files 2003-11-21 19:03:54 +00:00
interp c2109e2e67 Adjust MAKE-RESUME-URL and
DEFAULT-MAKE-SESSION-TIMEOUT-TEXT to surflets that are
in subdirectories.
2003-11-18 20:25:59 +00:00
mainzelm 217596b510 Return text/css for files with .css extension. 2003-10-24 08:16:07 +00:00
mainzelm a5d9b210f0 Fixed wrong parentheses in FTP-APPEND 2003-10-21 05:44:56 +00:00
cresh 6f52781aa6 * added dns-check-nameservers
* fixed alists in send-receive-message-tcp
* fixed and added documentation
2003-08-19 14:36:08 +00:00
interp c42a467ce5 Sorry for the messed up previous commits. Here are the collected messages:
Insert forgotten point to argument list of MAKE-SELECT, making the last
arguments optional. This was the reason for a "bug" in admin-surflet.scm.

Remove bug from MAKE-SELECT;
  MAKE-SELECT used the wrong argument name in calls to
  make-multiple-select or make-single-select, respectively.
2003-08-01 18:00:51 +00:00
interp 0ffbe611dc Sorry for the messed up previous commits. Here are the collected messages:
* Use "Internal Error" instead of "Bad Gateway" as the surflet handler is not a
gateway.
* Thus, rename BAD-GATEWAY-ERROR-RESPONSE to BAD-SURFLET-ERROR-RESPONSE.
Move SESSION-ADJUST-TIMEOUT from SEND/SUSPEND to RESUME-URL where it belongs to.
Let SET-SESSION-DATA! raise an error, if the instance isn't alive anymore (instead of returning #t or #f).
Add small comment to RESET-SESSION-TABLE!
Remove unused variable in DELETE-CONTINUATION!
Remove superfluous FILE-NAME-NON-DIRECTORY from RESUME-URL, as RESUME-URL-IDS uses this anyway.
Small change in error message in MAKE-HTTP-RESPONSE.
2003-08-01 17:59:27 +00:00
interp 64ef783d8d cat ~/diff-sunet/$num/log 2003-08-01 17:41:11 +00:00
interp 92dc531fa2 cat ~/diff-sunet/$num/log 2003-08-01 17:41:06 +00:00
interp d134f033d6 cat ~/diff-sunet/$num/log 2003-08-01 17:41:02 +00:00
interp c0773d8e55 cat ~/diff-sunet/$num/log 2003-08-01 17:40:58 +00:00
interp 5214f767d7 cat ~/diff-sunet/$num/log 2003-08-01 17:40:49 +00:00
interp 4673e0012f cat ~/diff-sunet/$num/log 2003-08-01 17:40:44 +00:00
interp 6f27658c68 cat ~/diff-sunet/4/log 2003-08-01 17:36:18 +00:00
interp f106614a75 cat ~/diff-sunet/3/log 2003-08-01 17:33:21 +00:00
interp d26c61799b Rename callback-functor to callback-function. 2003-08-01 15:02:43 +00:00
mainzelm 0656c89fca + Moved WITH-DATA-CONNECTION closer to call to LS to avoid stray connections in case of an error
+ Call surrounding exception handler in WITH-DATA-CONNECTION

+ Add arguments to two calls of escape proecures
2003-07-28 07:50:16 +00:00
interp d7fb759988 Assure at least one digit for each ID in regexp for cont-URL. 2003-07-24 09:18:53 +00:00
interp 32a2473d2d Remove wrong multiple value return from RESUME-URL-SURFLET-NAME 2003-07-24 09:17:05 +00:00
interp afe38a4147 Add task callback-functor. 2003-07-23 14:07:22 +00:00
interp 0f91f5f1c4 Remove done tasks. 2003-07-23 14:06:33 +00:00
interp d34380c1fa what we have to do 2003-07-23 14:05:29 +00:00
interp 2cc9c209f0 Drop WITH-REAL-INPUT-FIELD. Use INPUT-FIELD-REAL-INPUT-FIELD instead (and instead of CADR). 2003-07-23 13:45:34 +00:00
interp 4ec94f293e Remove superfluous reset in RESUME-URL. 2003-07-21 07:13:50 +00:00
interp 2e3b217145 Remove accidently commited code. 2003-07-18 16:10:57 +00:00
interp 2067f77670 Remove surflet-path bug in SURFLET-HANDLER.
The surflet-path could be given either explicitly or by options-structure.
This introduced an unexpected behavior: the explicitly given surflet-path
argument was completely ignored when options were given.
Now we accept only one argument to SURFLET-HANDLER that must be an option,
like HTTPD does it.
2003-07-18 15:06:53 +00:00
interp 0a510b7c76 Rename SELECT-MULTIPLE-TRANSFORMER to MULTIPLE-SELECT-TRANSFORMER to make things clearer. 2003-07-15 14:39:55 +00:00
interp 3d5a92eb44 Renamen MAKE-ADDRESS-CONSTRUCTOR to MAKE-ADDRESS-RECORD to make things clearer. 2003-07-15 14:06:17 +00:00
interp 0cfc9491d9 Use 'hidden' as internal type of hidden-fields. 2003-07-15 14:05:22 +00:00
interp 2ff183fa28 Move definition of deprecated MAKE-ANNOTATED-SELECT behind the definition of MAKE-SELECT. 2003-07-14 17:33:37 +00:00
interp b532f8a991 Minor change in FIND-IMAGE-BUTTON-COORDINATE. 2003-07-14 09:10:36 +00:00
interp 44268c5c4a Remove double definition of MAKE-IMAGE-BUTTON 2003-07-14 08:57:10 +00:00
interp e634526856 Some minor changes:
+ Detach TEXTAREA input field from simple input fields
  (concerning its setter) and remove WRAP? parameter from
  make-simple-default-setter
+ Rename TOLERATE-OLD-SELECT-OPTIONS to SIMPLE-OPTIONS
+ Deprecate MAKE-ANNOTATED-SELECT; it's not useful anymore
+ Merge MAKE-SELECT and REALLY-MAKE-SELECT to one function MAKE-SELECT
2003-07-13 20:08:28 +00:00
interp 4ff633e5db Add test.scm SUrflet to list of selectable SUrflets. 2003-07-13 16:21:53 +00:00
interp 347094a62f Minor change in RAW-INPUT-FIELD-VALUE 2003-07-13 14:36:41 +00:00
interp cad4fe21cf Minor change in args of MAKE-INPUT-FIELD-SETTER! 2003-07-13 14:35:33 +00:00
interp 4caaa001c7 Don't unwrap and rewrap real-input-field in input-field-rule. 2003-07-13 10:22:21 +00:00
interp 7e76eac6c8 * New packages SURFLETS/INTERNAL-INPUT-FIELDS provides bindings used to
define INPUT-FIELD-RULE in surflet-input-fields.scm.
* Change imports of SURFLETS/SURFLET-SXML (don't need pre-post-order
anymore).
2003-07-11 11:38:28 +00:00
interp 7a7fd39f0c Use SXML->LOW-LEVEL-SXML provided by SURFLETS/SXML instead of using PRE-POST-ORDER directly. 2003-07-11 11:34:38 +00:00
cresh e71a3581af fixed bugs related to invalid nameservers:
* added new error signal no-nameserver-given
* modified send-receive-message-* functions:
	- better error handling
	- timeout/maxtries functionality
	- try to contact all nameservers,
	  before error is signaled
2003-07-09 20:45:20 +00:00
interp f972598f59 Remove module typed-optionals. We don't need it anymore.
Rename function TYPED-OPTONALS to OPTIONALS-FIRST and move its definition
  to the only module that uses it: sxml.scm
Use LET-OPTIONALS instead of OPTIONALS, as it does the job, too, and
  it ensures that the meaning of an argument depends only on its
  position and not on the amount of arguments in front of it.
  This commit removes a pitfall in calls to MAKE-TEXTAREA.
Nearly every example SUrflet continues to work unchanged, except of one
  line in admin-surflets.scm, thus updating it.
2003-07-09 17:18:57 +00:00
interp e43b8bb2fc Rewritten OPTIONALS macro with SYNTAX-RULES. 2003-07-08 23:07:37 +00:00
interp 3384fdd920 Always add COLS and ROWS attributes to TEXTAREA to suffice HTML 4.01 2003-07-08 22:50:21 +00:00
interp c78145dee2 small row line up 2003-07-08 21:23:27 +00:00
interp c1d14a06a0 Change names in surflet-input-fields.scm, so that they are both short and
descriptive and not misleading.

If you have written SUrflets that use the input field feature, you must
rename your input field commands to get them work with this change.
Contact me, if you want to have a small script that does this for you.
2003-07-08 21:22:06 +00:00
interp e66223b666 remove superfluous bracket pair introduced by previous commit 2003-07-06 09:00:36 +00:00
interp 477544caaa Merge a LET in upper LET* 2003-07-06 08:58:39 +00:00
interp 39f7addaf9 Factor out SURFLET-RESPONSE object 2003-07-05 18:13:32 +00:00
interp 592baf7c6a minor change in comment layout. 2003-07-04 16:18:19 +00:00
interp d5b14d4ffc Let it be a bit more valid as HTML 4.01 Transitional.
Among other things, add HEAD tag, give charset information, add TITLE
tag and let it start with the "<!DOCTYPE ...>" declaration.
2003-07-04 14:46:31 +00:00
cresh dbd13f24ab Minor changes in parse-resolv.conf. 2003-06-30 10:57:26 +00:00
mainzelm 886b8f7dd1 Made uri-escaped-chars the complement of alphanum | mark. 2003-06-25 07:49:54 +00:00
interp 7d188b8269 slight modifications 2003-06-22 16:23:16 +00:00
interp dca13aabde slight adaptation, mainly renaming 2003-06-21 15:27:20 +00:00
tjaden 64a8793a37 Added tentative support for ftp RESTART command. 2003-06-14 12:59:02 +00:00
tjaden d236b8990f Fixed a bug preventing httpd from serving files with a recognised
content-encoding.
2003-06-14 12:55:47 +00:00
interp 575dd18f03 Check for correct content-type in GET-BINDINGS. Raise an error if it is not correct. 2003-06-03 07:36:48 +00:00
interp d36409fddc remove debug output 2003-05-23 09:14:58 +00:00
interp f3b7c3a396 Signal an error if image button coordinates cannot be translated into
numbers.
2003-05-23 08:05:03 +00:00
interp a81dfb6ab1 remove debug output 2003-05-22 13:56:57 +00:00
interp 08012edab4 mention code source 2003-05-22 13:55:03 +00:00
interp 6c99e3a707 Remove image button bug (thanks to Eric Knauel for reporting this): Image
buttons return the coordinates where the user clicked à la
imgbtn321.x=13&imgbtn321.y=12. Thus, we cannot search for the
input-field-name of the image button. To remove this bug, we introduce
following changes:

surflet-input-fields.scm:

+ make-image-button returns a multi-input-field that searches for its
  coordinates in the bindings, returning a pair (x y) of it (numbers).
+ Adapt select-input-fields to interface changes of multi-input-fields:
  transformers get also their input-fields.

returned-via.scm:
Don't simply check for the input field name in the binding. Use
input-field-value to check for existance of the input field in the
bindings

input-fields.scm:
multi-input-fields get also their input-field as argument

web-server/root/surflets/byte-input.scm:
Adapt to interface change of multi-input-fields: transformers get also
their input-field

web-server/root/surflets/test.scm:
Check the image-button feature  correctly.
2003-05-22 13:32:49 +00:00
interp 69ea6ae13f Use do-html-string-sending in do-html-sending 2003-05-13 14:02:24 +00:00
interp bd6a537197 + ADD-SEL-IF-OPTION!
+ DELETE-SEL-IF-OPTION!
2003-05-10 12:10:32 +00:00
interp 6bea1e6a0c Adapt to change in sunet/doc/latex/decls.tex and mention out of date status. 2003-05-10 11:59:13 +00:00
interp 27fbf65f2b minor change: changing attribute order in textarea input field 2003-05-04 14:07:11 +00:00
interp 219bcaa4fe Add optional args to MAKE-TEXTAREA-INPUT-FIELD: ROWS COLS READONLY 2003-05-04 14:05:40 +00:00
interp 63afb5d073 Map SXML->LOW-LEVEL-SXML to Oleg's PRE-POST-ORDER 2003-05-04 14:04:54 +00:00
sperber b95d65509e - include Scheme-eval handler in start-web-server
- don't ship start-extended-web-server
- tailor demo web page for start-web-server rather than
  start-extended-web-server
2003-04-23 07:29:37 +00:00
mainzelm 3733c09a42 Fixed a typo and made http://www.scsh.net/resources/sunet.html the SUnet URL 2003-04-22 14:06:50 +00:00
sperber c2ec249d20 Mention scsh mailing list. 2003-04-22 14:01:50 +00:00
sperber fe30fb1fe5 Put web-server/ into distro. 2003-04-22 13:57:19 +00:00
sperber 003f803357 This was really obsolete long ago by start-{extended-}web-server. 2003-04-22 13:52:37 +00:00
sperber 61e6e303f7 Say "start-extended-web-server" instead of "start-web-server" in
usage.
2003-04-22 13:51:04 +00:00
sperber baa9486488 Make MAKE-ERROR-RESPONSE work for "method not allowed" responses. 2003-04-22 13:49:49 +00:00
mainzelm f385c76f6a After allocation the socket, become user nobody if current user is root 2003-04-22 13:14:50 +00:00
sperber 998182b5cb Output to ../html. 2003-04-22 12:56:48 +00:00
sperber 2004aaa05a Add RELEASE to the distro. 2003-04-22 12:56:09 +00:00
sperber 90293f6582 *** empty log message *** 2003-04-22 12:55:56 +00:00
sperber bd22ae282b Working dist target. 2003-04-22 12:47:27 +00:00
sperber 0bbb13664e Long obsolete. 2003-04-22 12:45:30 +00:00
sperber 27b2ae5a4f "January" -> "April" (referring to the release date) 2003-04-22 12:44:55 +00:00
interp 60a11e664d removed obsolete block of comments 2003-04-17 09:23:09 +00:00
interp 5a8d56672d Use some of the new input field features 2003-04-16 17:11:47 +00:00
interp ee5e3cd6ec In make-resume-url: use argument session-id
(not instance-session-id) to create resume-url.
2003-04-16 16:04:11 +00:00
interp 20821bdfb5 Adapt to recent change of session-interface in surflet-handler 2003-04-16 16:03:06 +00:00
interp 5b2e2ddd6a Ship out only session-id/continuation-id
and not the session/continuation itself
2003-04-16 16:02:37 +00:00
interp 91c0997dd7 Add some distance between radio button and radio text 2003-04-16 16:01:38 +00:00
interp 61c5cf4246 Add CALLBACK-FUNCTOR that allows the call back arbitrary functions
(in conjunction with make-annotated-callback)
2003-04-16 16:01:01 +00:00
interp a9f5c6ffa7 test.scm now shows examples for all surflets-input-fields. 2003-04-16 12:32:24 +00:00
interp aa6e6aabfc ! Redesign of input-fields.
+ Split input-fields into two structures:
  + surflets/my-input-fields allows you to create your own input-fields.
    (complete with structure surflets/input-field-value)
  + surflets/surflet-input-fields are the proposals for input-fields
    from SUrflets. They support annotated input-fields where
    appropriate (select, radio, checkbox, hidden) and changing of attributes,
    e.g. default values. See test.scm for examples.
  The interface of the structure SURFLETS has only changed slightly
  concerning the input fields
  (make-higher-input-field --> make-multi-input-field should be the
  main change)
+ Adapt examples to new input-field interface
+ Note new structures in documentation.
2003-04-16 12:30:57 +00:00
interp 6d64530779 SXML-ATTRIBUTE-ATTRIBUTES returns a list instead of #f 2003-04-16 12:20:57 +00:00
interp e3652a93b2 Add identity function 2003-04-16 12:20:12 +00:00
interp eb5f44b932 Add nbps-rule that inserts a &nbsp; 2003-04-16 12:19:44 +00:00
interp 107cb30eb2 factor out generating of 'unique' numbers 2003-04-15 13:55:00 +00:00
interp 2ab93f703b Add SXML-ATTRIBUTE-ATTRIBUTES function that discards the initial '@ 2003-04-15 09:33:32 +00:00
interp f8d7dfbeda remove extraneous right paranthesis 2003-04-14 10:04:23 +00:00
interp ea6e3e6c7d adapt to new surflets/callbacks structure 2003-04-14 09:10:54 +00:00
interp 97c0da8c71 Make url-rul *preorder*.
This removes a bug that escaped the HTML string twice (e.g. '<' or '&').
2003-04-14 08:40:45 +00:00
interp c48f952cc5 + Add annotated callbacks.
Callbacks may now be annotated with arbitrary arguments with which the
function will be called. See surflets/test.scm for a (non-didactic) example.

* The extended callbacks justify an extra structure for callbacks:
surflets/callbacks

- make-callback was moved from surflets/utilities to surflets/callbacks
2003-04-14 08:30:27 +00:00
interp c3e7abbdeb ignore some more files (that I use for debugging) 2003-04-14 08:11:10 +00:00
interp cdbed4fa49 Addresses may now be annotated with arbitrary values (including, but not
limited to strings).
For this purpose, the ADDRESS object uses an internal storage that is freed
as soon the ADDRESS object is freed.
admin-surflets.scm shows an example.
2003-04-13 21:31:41 +00:00
interp e9d126847d replace links to add-html.scm by links to add-raw.scm 2003-04-13 20:27:03 +00:00
interp 5581383962 Add surflet-path to options (needed by admin-surflets.scm) 2003-04-13 20:24:56 +00:00
interp 6f46e17b11 ignore TODO file 2003-04-13 18:28:37 +00:00
interp 4b08eac262 use with-lock instead of obtain-lock/release-lock 2003-04-13 18:27:43 +00:00
interp 956fd7bbf1 Add non-thunk version to with-lock.
Note: To follow naming conventions of scsh, the old with-lock is
renamed to with-lock*. The syntactic sugar version is with-lock now.
2003-04-13 17:36:39 +00:00
interp d0782f63a2 Factor out with-locks from surflet-handler 2003-04-13 17:23:11 +00:00
mainzelm 213090a51d + use search-trees for timeout-queue
+ export session-adjust-timeout! for admin-surflet.scm
2003-04-01 13:17:45 +00:00
mainzelm 61c3a4c216 Introduced field lifetime to session 2003-03-31 10:56:28 +00:00
sperber 1c6bfbc4ea Clear the THE-SESSION-REPLIES after writing a reply. 2003-03-21 10:42:37 +00:00
sperber 9194257f8e Increase *WINDOW-SIZE* from 4096 to 8192.
This improves speed on AIX by a factor of about 20.
2003-03-19 13:02:44 +00:00
mainzelm 33f1a2f063 Two small fixes related to options. 2003-03-17 19:29:45 +00:00
mainzelm b74ca11656 + Make text displayed on session timeout an option to the handler.
+ Fixed various options related bugs.
2003-03-17 12:31:49 +00:00
mainzelm b93e275415 Replaced implementation of surveillance thread: We have now only one
thread which checks every second for sessions to be deleted.
2003-03-17 12:09:26 +00:00
mainzelm 3de0a9c480 Added options for surflet-handler. 2003-03-17 10:17:55 +00:00
mainzelm 573e980f33 Added a rule to generate comments for *COMMENT* tags. 2003-03-14 12:58:12 +00:00
interp 3511a9bffc Add forgotten structure for surflets/my-sessions 2003-03-13 18:32:43 +00:00
interp dcce51cc3f Let URL-RULE use SURFLET-SXML->LOW-LEVEL-SXML instead of writing own string list 2003-03-13 12:07:29 +00:00
interp 39066ac109 Mention session-data in basic user's structures 2003-03-13 11:53:09 +00:00
interp fe70289bc6 Factor out SESSION-DATA and make it available in SURFLETS 2003-03-13 11:52:37 +00:00
interp 88e255d5de + Restructuring: Now, we have a three (four) layer concept:
Basic User, Advanced User, Administrative User
+ see file SURFLETS-STRUCTURES.TXT for details
+ Adapt example surflets to new structures. Only surflets that use extended
  features should need adaptations.
2003-03-13 11:36:49 +00:00
interp df8ea46a27 Add SEND-HTML-STRING, ../SUSPEND, ../FINISH 2003-03-13 11:33:33 +00:00
interp b1e0c7df54 Add GET-SESSION 2003-03-13 11:32:59 +00:00
interp 1caff62db0 minor change in comment 2003-03-13 11:32:38 +00:00
interp e151572459 Add sxml->string/internal 2003-03-13 11:32:16 +00:00
interp d1c7b4e9d3 remove forgotten generate-unique-name 2003-03-10 17:11:41 +00:00
interp ec341accf9 Add SESSION-ALIVE? 2003-03-10 16:37:22 +00:00
interp 3fc36e865e + Splitting file surflets.scm into several packages
- Removing surflets.scm
+ The surflets package remains and collects the most usual used packages
  It does not export any more the outdaters, the access to IDs
    (like session-id), callbacks, form-query-list.
      (and maybe some other stuff I've forgot to mention here, see list
below).

The new packages are (not included in surflets are marked (*)):
+ surflets/addresses: MAKE-ADDRESS, MAKE-ANNOTATED-ADDRESS
+ surflets/bindings: GET-BINDINGS, EXTRACT-BINDINGS and stuff
+ surflets/ids (*): MY-SESSION-ID, .., INSTANCE-SESSION-ID
+ surflets/input-fields: MAKE-INPUT-FIELD, MAKE-NUMBER-INPUT-FIELD...
+ surflets/outdaters(*): MAKE-OUTDATER, OUTDATER?...
+ surflets/returned-via: RETURNED-VIA, CASE-RETURNED-VIA
+ surflets/send-html: SEND-HTML/SUSPEND...
+ surflets/surflet-sxml: URL-RULE,..., SURLFET-SXML-RULES, ...
+ surflets/sxml: SXML->STRING, DEFAULT-RULE,...
+ surflets/typed-optionals(*): TYPED-OPTIONALS, OPTIONALS
+ surflets/utilities(*): MAKE-CALLBACK, FORM-QUERY-LIST,
                         GENERATE-UNIQUE-NAME...
2003-03-10 16:29:32 +00:00
interp 87a4165f94 check existence of sessions in some locking areas 2003-03-10 13:10:29 +00:00
interp 64371c9941 Use the time-to-live argument in really-session-adjust-timeout! 2003-03-10 13:01:45 +00:00
interp 909ed39ce2 Add optional arguments to ADJUST-TIMEOUT! and SESSION-ADJUST-TIMEOUT!
This argument defaults to OPTIONS-SESSION-LIFETIME and represents
the life-time in seconds for the session.
2003-03-10 12:57:44 +00:00
mainzelm 5c03d2e24e URL -> url 2003-03-10 09:23:41 +00:00
interp 3b51f7b82b + export conversion rules from surflets:
default-rules (default, text, attribute, plain-html and url)
  surflet-form-rules (input-field and surflet-form)
+ according to mainzelm: lowercase URL tag to url in surflet-xml
2003-03-09 20:15:08 +00:00
interp 31f0044e2c rename FORM-QUERY of surflets to FORM-QUERY-LIST
to avoid name puzzlement with the simple-surflet-api that already
exports this name (and we cannot change this, as this is adapted to PLT)
2003-03-09 19:57:56 +00:00
interp 4af92bc379 factor out creating of input page 2003-03-09 19:57:09 +00:00
interp b12070e349 Add MY-SESSION-ID, MY-CONTINUATION-ID and MY-IDS to surflets, that return the respective IDs out from an request object. There are restrictions on their use. 2003-03-09 19:44:09 +00:00
interp e64b57f540 Correct some error from last commit:
* COMPOUND-INTERFACE needs its arguments to be defined already
* add bang to some other ADJUST-TIMEOUTs
2003-03-09 19:18:35 +00:00
interp 4748a882c3 Add a bang to SET-OPTIONS-SESSION-LIFETIME, SET-OPTIONS-CACHE-SURFLETS? and ADJUST-TIMEOUT 2003-03-09 18:49:09 +00:00
interp 536fe1394c no changes (internal restructuring using COMPOUND-INTERFACE) 2003-03-09 18:37:38 +00:00
interp 3f1542466c Rename misleading {SET,GET}-SURFLET-DATA to {SET,GET}-SESSION-DATA, as the data is specific to a session and not to a surflet. 2003-03-09 18:03:15 +00:00
interp cacf6aeaa8 downcase! even more identifiers 2003-03-07 18:45:12 +00:00
interp 78a1d2e633 + (foreach downcase! identifiers)
+ fold FORMATED-REPLY into SURFLET-XML->HTML
+ rename REAL-FORMATED-REPLY to FORMATED-REPLY
+ use global value INPUT-FIELD-TRIGGER instead of symbol 'input-field
+ The SURFLET-FORM tag creates a REFORMATted list instead of HTML
Note: There were no changes to the interface.
2003-03-07 18:34:04 +00:00
mainzelm 2e5f385410 Fixed two bugs in case-returned-via. 2003-03-07 13:08:36 +00:00
mainzelm e12ba6a042 => for case-returned-via 2003-03-03 20:38:17 +00:00
interp f4baad5ab1 changed let&if to cond&=> in GET-SURFLET-RT-STRUCTURE 2003-03-03 10:29:18 +00:00
interp bd613946d0 + CASE-RETURNED-VIA from mainzelm added
+ RETURNED-VIA alias for RETURNED-VIA? added
2003-03-03 10:27:49 +00:00
interp 98f0da38c6 Add MAKE-ANNOTATED-ADDRESS that creates string-annotated return-addresses 2003-02-28 08:22:29 +00:00
sperber b2884b22e2 Don't close the data connection upon errors. 2003-02-27 13:33:15 +00:00
sperber 118bc545b1 Make sure we close the data connection upon an error. 2003-02-27 10:53:24 +00:00
sperber 3405ab31ed "occured" -> "occurred" 2003-02-27 09:02:10 +00:00
sperber ee5aba4cf5 Fix reply generation for data transfer errors and aborts. 2003-02-27 09:01:45 +00:00
mainzelm 7f81f8bed9 + Use a port buffer of 4096 bytes for the socket's output port.
+ Comment why we cannot do the same for input.
2003-02-26 18:03:40 +00:00
mainzelm e3d252c370 Use a port buffer of 4096 bytes when reading the CGI script's output
and copy 4094 bytes at once from this buffer to output port.
2003-02-26 18:02:14 +00:00
mainzelm 4923286d96 Let FORM-QUERY return '() if the query string is #f. 2003-02-26 15:55:22 +00:00
interp d5dcbace37 Log a single dash (`-') if referer or user-agent header is missing/unknown 2003-02-25 17:36:36 +00:00
interp 862dd31c88 Correct self links & restructure a bit. 2003-02-21 09:50:49 +00:00
interp 9a6b262637 Correct self links. 2003-02-21 09:49:35 +00:00
mainzelm ef3a8af150 Added httpd-options-post-bind-thunk. 2003-02-20 17:52:27 +00:00
mainzelm 1b0b3f5690 Directory handlers now have a default option. 2003-02-20 16:37:11 +00:00
mainzelm bc6324e252 Generate a pair of status and text if the CGI script failed to provide
the "Status" header.
2003-02-20 08:57:59 +00:00
interp e6e4ea0f1a use INPUT-FIELD-VALUE for check-box 2003-02-19 18:48:24 +00:00
interp ca7e42cfa0 use scheme-with-scsh where appropriate. 2003-02-19 18:47:04 +00:00
interp 945b4a2ade failsafe if "which" is not executable. 2003-02-19 18:45:57 +00:00
interp 2d7a37f060 unify dispatcher: RETURNED-VIA? accepts now input-fields as well as return-addresses. 2003-02-19 18:42:45 +00:00
interp bd26da7497 remove debug output 2003-02-19 18:34:48 +00:00
interp bf070b1036 use 'convert' to create PNG profiling chart. 2003-02-19 18:26:10 +00:00
mainzelm 2ff86dd73b Adaption to parameter change in socket-address->fqdn. 2003-02-19 17:40:48 +00:00
mainzelm 8111eddf82 Fix broken call to map in lookup-optional-args. 2003-02-19 17:37:35 +00:00
interp da98c4b78c factor out GET-HEADER 2003-02-19 17:05:16 +00:00
mainzelm a1f3d72ce8 Fixed \defun for pop3-quit. 2003-02-19 09:43:46 +00:00
interp 71650fbb41 catch every condition only for load-config et al.; otherwise catch only errors. 2003-02-19 09:43:29 +00:00
sperber c48ab741a7 Call scsh with "+lpsd -ll" instead of "-lm." 2003-02-17 15:46:45 +00:00
interp a767f7b84b Correct self-links. 2003-02-17 10:10:26 +00:00
interp 21f62d5d8e + REQUEST object extended for SUrflets by INPUT-PORT
+ SURFLET-REQUESTs used in SUrflets
+ Use MAKE-INPUT-RESPONSE to generate SUrflet responses
2003-02-17 10:09:24 +00:00
interp bf937b2e74 WITH-LOGFILE was renamed to WITH-LOG-FILE 2003-02-17 09:52:21 +00:00
interp ade0a8391f + remove standard options from file handlers
+ remove superfluous comment
2003-02-17 09:08:27 +00:00
interp 0823675325 ignore .idx files 2003-02-17 09:05:15 +00:00
sperber 001c86f6d2 Fix condition handling in HANDLE-COMMAND. 2003-02-14 15:58:17 +00:00
mainzelm 4c2a10f0ff Removed section "Host Names" 2003-02-10 13:14:06 +00:00
mainzelm 0b8c33af3f Removed fqdn? and unqualified-hostname 2003-02-10 13:13:26 +00:00
mainzelm 35efb036af name -> IP-string 2003-02-10 12:46:21 +00:00
mainzelm e75388ad14 Adapted documentation for ips. 2003-02-10 12:38:40 +00:00
mainzelm 45223c1d81 Created structure ips for ip-string related procedures. 2003-02-10 12:30:43 +00:00
sperber 0e7152b68b Finally fix MAKE-HOST-NAME-HANDLER to the point where it works and has
been tested.
2003-02-10 12:02:11 +00:00
mainzelm 183cf60bb7 Make resolve.conf-parse-error a condition. 2003-02-10 10:48:46 +00:00
mainzelm ceb481fc10 Ignore *.png 2003-02-10 10:46:53 +00:00
mainzelm 1503017988 Removed system-fqdn from sunet-utilities and internet-address->fqdn from dns. 2003-02-10 10:44:59 +00:00
mainzelm 090a91be0e + More on introduction
+ Removed many \oops
2003-02-10 09:56:21 +00:00
mainzelm 2bb48917a2 Minor changes. 2003-02-10 08:10:17 +00:00
mainzelm e2697605f6 + rr-X -> resource-record-X
+ removed separate cache mapping IPs to FQDNs
2003-02-10 08:04:17 +00:00
mainzelm a4f7e6f337 Most of Mike's corrections. 2003-02-07 17:21:23 +00:00
sperber 44322977fc Add HTTPD-INPUT-RESPONSE response values. 2003-02-06 15:05:15 +00:00
mainzelm f99dbe3b99 Imported css.t2p from tex2page 4q7d 2003-01-31 13:00:27 +00:00
sperber 1824b062d3 Remove abstract. 2003-01-30 16:11:21 +00:00
sperber d027d399c3 Minor grammar fixes. 2003-01-30 16:10:40 +00:00
sperber 1b45498af9 Document MAKE-FTPD-OPTIONS. 2003-01-30 16:10:08 +00:00
sperber 26d0fe6f43 Better chapter title. 2003-01-30 16:09:46 +00:00
sperber fe25e5a307 In web server, rename LOGFILE -> LOG-FILE. 2003-01-30 16:09:20 +00:00
sperber 6e5f9ed278 - Make the handlers in HTTPD-FILE-DIRECTORY-HANDLERS do something
sensible without a set of icons.
- Make the options arguments to the handlers in
  HTTPD-FILE-DIRECTORY-HANDLERS optional.
2003-01-29 10:08:25 +00:00
sperber 730053c6bc Remove duplicate OPEN clause for LET-OPT. 2003-01-29 09:56:36 +00:00
sperber f373a87413 Rename ...-ICON-FILE-NAME -> ...-ICON-URL. 2003-01-29 09:16:56 +00:00
sperber 301d6ff4c3 Get rid of HTTPD-OPTIONS-ICON-NAME which I'd forgotten about. 2003-01-29 07:54:44 +00:00
interp 8895e3b32a Adapt to recent interface changes of HTTPD and its file handlers.
Particularly, the SUrflet server can now serve the source of SUrflets
via '/source/add-raw.scm'
2003-01-28 21:58:33 +00:00
interp 367caeb01d Emit HTML tags, too. 2003-01-28 21:52:28 +00:00
interp 6804ad4712 * Redirect output from interactive Scheme Program to OPORT (to browser).
* Add definition for GET-HEADER (does every package need its own definition?)
2003-01-28 21:29:23 +00:00
interp 416d914a3f Add missing argument to call to nroff-n-decode in man 2003-01-28 21:15:50 +00:00
interp 8e07bc1b07 Remove export of disappeared OPTIONS-SURFLET-PREFIX 2003-01-28 20:44:48 +00:00
mainzelm 615886e492 Provide default values if the CGI script fails to provide status or
content-type.
2003-01-28 15:20:36 +00:00
sperber 022ea25ba6 Rework once again how content types, content encodings, icons etc. are
handled in the file/directory request handlers:

- HTTPD-FILE-DIRECTORY-HANDLERS now has its own options argument
- the ICON-NAME HTTPD option is gone (effectively moved to the above)
- determination of content type/encoding is now configurable
2003-01-28 15:16:20 +00:00
sperber eb20aec688 Clean up logging in ftpd:
- hold relevant data in new SERVER-STATE fluid
- specify log destination as a port, not a file
2003-01-28 10:49:45 +00:00
sperber a44ab62741 Fresh start. 2003-01-28 09:46:44 +00:00
sperber 91443675da Long obsolete. 2003-01-28 09:20:54 +00:00
interp e32b78badb Add comments about thread safety. 2003-01-25 16:33:50 +00:00
interp f2872877ad Minor change in comments. 2003-01-25 16:30:09 +00:00
interp e3f216aee7 {S,s}urflet-->SUrflet in strings 2003-01-25 16:28:16 +00:00
interp afada4efb2 Look for RESUME-URL-IDS only in the file-name, not in the path. 2003-01-25 16:22:37 +00:00
interp e934340fb5 uncurry LOAD-SURFLET in GET-SURFLET-RT-STRUCTURE 2003-01-25 16:17:33 +00:00
interp 26fa1ca033 correct bogus call to MAKE-DEFAULT-options 2003-01-25 16:13:42 +00:00
interp 9aea76ee83 remove RETURN-CONTINUATION from INSTANCE; it's not used anyway 2003-01-25 16:11:30 +00:00
interp 100ffcc010 remove SURFLET-PREFIX; it's not used anyway 2003-01-25 16:10:19 +00:00
interp 3d3655960b + Outhouse some components of surflet-handler.
+ Textual restructuring of surflet-handler.
+ Comments added.
2003-01-25 16:09:03 +00:00
interp 7747dd4ac6 Use SEND-ERROR instead of MAKE-ERROR-RESPONSE. 2003-01-25 13:42:50 +00:00
interp fe10f7b609 Use SEND-ERROR instead of MAKE-ERROR-RESPONSE 2003-01-25 13:40:34 +00:00
interp 220ac99930 Add SURFLET-RESPONSE->STRING for debug purpose. 2003-01-25 13:30:45 +00:00
interp c7bdc50564 Ignore sunet-manual directory 2003-01-25 13:27:40 +00:00
interp e99acd10ee Use SEND-ERROR instead of MAKE-ERROR-RESPONSE 2003-01-25 13:24:22 +00:00
interp ac28d0c6a2 Remove a bug: wrong parameter to SHOW-SESSIONS after e.g. killing a
session
2003-01-25 13:21:36 +00:00
interp 0bee80fadf Remove bug from POST forms: Let GET-HEADER return only the header
value.
2003-01-25 12:19:54 +00:00
interp 1f10457d52 Adapt to recent changes in surflet-handler 2003-01-24 16:05:39 +00:00
interp 3f3bf045de Add SEND-ERROR, that sends an error. 2003-01-24 16:02:29 +00:00
interp 7055289412 Add comment to MAKE-REDIRECT-RESPONSE. 2003-01-24 15:34:37 +00:00
interp 1dcee71722 Use ASSQ instead of ASSOC in GET-HEADER 2003-01-24 15:29:30 +00:00
interp 90df993fe2 remove double entries; minor name change 2003-01-24 15:28:25 +00:00
interp 6358463b5a + Change interface of SEND/SUSPEND, SEND/FINISH, SEND:
They expect SURFLET-RESPONSE objects now (not HTTP-RESPONSE).
+  SEND-HTML/SUSPEND, SEND-HTML/FINISH, SEND-HTML respect this.
2003-01-24 15:23:51 +00:00
interp 0ce0da0a1f Sync with tex2page target dir of docu. 2003-01-24 13:56:49 +00:00
sperber 9893716650 Actually use READ-LINE parameter in MAKE-READ-RFC822-HEADERS.
(Noticed by bernauer.)
2003-01-24 09:51:17 +00:00
sperber 5f4c1b510b Rename TIME->HTTP-DATE-STRING to RFC822-TIME->STRING.
(Missed by sperber, noticed by bernauer.)
2003-01-24 09:48:37 +00:00
mainzelm 3469f8f4d6 Makefile from scsh. 2003-01-23 16:13:36 +00:00
sperber 0820296df0 Dr.S^2 2003-01-23 15:08:31 +00:00
sperber a8ae20a309 scsh 0.6.3 -> 0.6.4. 2003-01-23 10:06:54 +00:00
sperber baf79101d8 Add some introductory remarks. 2003-01-23 10:06:24 +00:00
sperber eac111bf66 Minor fixes. 2003-01-23 09:39:29 +00:00
sperber 958c87d923 Added missing \var. 2003-01-23 09:39:04 +00:00
sperber a75990e8c2 Reasonable complete and up-to-date docs. 2003-01-23 09:38:44 +00:00
sperber b239184a38 - removed some leftover debugging output
- simplified exception handling (and probably fixed some bugs)
- banners are now lists of lines
- rewrote bogus reply output code
2003-01-23 09:38:20 +00:00
mainzelm 08bf247510 More low-level procedures. 2003-01-22 14:13:40 +00:00
167 changed files with 22093 additions and 2283 deletions
+31
View File
@@ -0,0 +1,31 @@
# CVS default ignores begin
tags
TAGS
.make.state
.nse_depinfo
*~
\#*
.#*
,*
_$*
*$
*.old
*.bak
*.BAK
*.orig
*.rej
.del-*
*.a
*.olb
*.o
*.obj
*.so
*.exe
*.Z
*.elc
*.ln
core
# CVS default ignores end
test-packages.scm
test
SSAX
+30
View File
@@ -0,0 +1,30 @@
Copyright (c) 1994 by Brian D. Carlstrom and Olin Shivers.
Copyright (c) 1995-1996 by Olin Shivers.
Copyright (c) 1996-2001 by Mike Sperber.
Copyright (c) 1999-2001 by Martin Gasbichler.
Copyright (c) 1998-2001 by Eric Marsden.
Copyright (c) 2001-2003 by Andreas Bernauer.
Copyright (c) 2004-2005 by Viola Brunner.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+43
View File
@@ -0,0 +1,43 @@
These are generic installation instructions for scsh packages.
Prerequisites
=============
The scsh installation library is required to install this package.
This library *must* be present on your system before the current
package can be installed. It can be obtained from the following Web
page:
http://lamp.epfl.ch/~schinz/scsh_packages/
The installation library comes with its own documentation which
explains in detail how to install and use scsh packages. It is
recommended that you read it before installing your first scsh
package. What follows is a very brief summary of this documentation,
intended to get you started quickly.
Installation
============
Installation of a scsh package is performed by launching the
"scsh-install-pkg" script, which is part of the scsh installation
library. This script must be launched from within the directory which
resulted from the expansion of the current package's archive, i.e. the
one containing the file you are reading now.
A list of all the arguments accepted by the "scsh-install-pkg" script
can be obtained by launching it with the "--help" option. One of these
arguments, "--prefix", is mandatory and specifies the location where
installation should be performed. Ideally, you should use the same
prefix to install all scsh packages, as this makes them easier to
manage and use.
For example, to install the current package in
"/usr/local/share/scsh-modules", you should type the following:
scsh-install-pkg --prefix=/usr/local/share/scsh-modules
Provided that no errors are encountered during installation, a
message will be printed at the end explaining how to use the newly
installed package.
+52
View File
@@ -0,0 +1,52 @@
SHELL = /bin/sh
version_id = 2.1
distname = sunet-$(version_id)
distdir = /tmp
DISTFILES = COPYING README RELEASE INSTALL pkg-def.scm \
scheme/packages.scm \
start-web-server start-extended-web-server start-surflet-server \
scheme/httpd/*.scm scheme/httpd/surflets/*.scm \
scheme/ftpd/*.scm scheme/lib/*.scm \
doc/pdf/sunet.pdf doc/html \
doc/latex/*.tex doc/latex/*.sty doc/latex/*.t2p doc/latex/*.hdir \
web-server
sunet-$(version_id).tar.gz:
.PHONY: dist
dist:
cd doc/latex && $(MAKE) html
cd doc/latex && $(MAKE) man.pdf
cd web-server/root/htdocs
mkdir -p doc/pdf
cp doc/latex/man.pdf doc/pdf/sunet.pdf
mv doc/html/man.html doc/html/index.html
distname=$(distname) && \
distfile=$(distdir)/$$distname.tar.gz && \
if [ -d $(distdir) ] && \
[ -w $$distfile -o -w $(distdir) ]; then \
rm -f $$distname && \
ln -s . $$distname && \
files='' && \
for i in $(DISTFILES); do \
if [ "$$i" != "c/sysdep.h" ]; then \
files="$$files $$distname/$$i"; \
fi \
done && \
tar --exclude .cvsignore --exclude CVS -cf - $$files | \
gzip --best >$$distfile && \
rm $$distname; \
else \
echo "Can't write $$distfile" >&2; \
exit 1; \
fi
.PHONY: tags
tags:
find . -name "*.scm" | etags -
+116
View File
@@ -0,0 +1,116 @@
This is the Scheme Untergrund Networking Package.
The Scheme Untergrund Networking Package (SUnet, for short) is a
collection of applications and libraries for Internet hacking in
Scheme. It contains over 15000 lines of high-quality Scheme code that
runs under Scsh, the Scheme shell. SUnet makes extensive use of
Scsh's facilities for multi-threaded systems programming und Unix.
SUnet includes the following components:
* The SUnet Web server
This is a highly configurable HTTP 1.1 server in Scheme.
The server is accompanied by some libraries which may also
be used separately:
* an URL parser and unparser
* a library for writing CGI scripts in Scheme
* server extensions for interfacing to CGI scripts
* server extensions for uploading Scheme code
* a simple structured HTML output library
The server also ships with a sophisticated interface for writing
server-side Web applications called "SUrflets".
* The SUnet ftp server
This is a complete anonymous ftp server in Scheme.
* ftp client library
This library allows you to access ftp servers programmatically.
* Netrc library
This library parses authentication information contained in ~/.netrc.
* SMTP client library
This library allows you to forge mail from the comfort of your own
Scheme process.
* POP3 client library
This library allows you to access your POP3 mailbox from inside Scsh.
* RFC822 header library
This library parses email-style headers.
* Daytime and Time protocol client libraries
These libraries lets you find out what time it is without paying for a
Rolex.
* DNS client library
This is a complete, multithreaded DNS library.
* An ls clone
This library displays Unix-style directory listings without running ls.
Download
========
The SUnet code is available from
http://www.scsh.net/sunet/
To run the code, you need version 0.6.4 or later of Scsh, available from
http://www.scsh.net/
Installation
============
Starting with version 2.1 SUnet conforms to the packaging proposal for
scsh by Michel Schinz. Please see:
<http://lamp.epfl.ch/~schinz/scsh_packages/>
In short, this means that you can install SUnet by unpacking the SUnet
tarball and issuing the following command in the created directory:
scsh-install-pkg --prefix /path/to/your/package/root
See the file INSTALL for the generic installation instructions for
scsh packages.
You need to install version 4.9 of the SSAX package to use SUnet. SSAX
is available from <http://lamp.epfl.ch/~schinz/scsh_packages/>.
Sample Web Server
=================
The installation procedure also installs three scripts to run the
SUnet httpd in the directory
/path/to/your/package/root/0.6/sunet/web-server/
The three scripts are:
start-web-server for running a simple web server on port 8080
start-extended-web-server for running a web server with rman and info gateway
start-surflet-server for running a web server with SUrflets enabled
Pass the --help option to learn how to configure the scripts.
These scripts should provide a pretty good starting point to set up
your own server or serve your own SUrfelts.
Support
=======
Please direct questions, comments, answers about SUnet to the regular
scsh mailing list at
scsh@zurich.ai.mit.edu
Relax, hack, and enjoy!
Michael Sperber
Martin Gasbichler
Eric Marsden
Andreas Bernauer
+30
View File
@@ -0,0 +1,30 @@
Scheme Untergrund Networking Library Release Notes
==================================================
We are pleased to release SUnet version 2.1.
SUnet runs under scsh 0.6.4. It is possible, but unlikely that it
runs under earlier versions of scsh. We recommend using version 0.6.6
for simple installation using the new packaging proposal. See file
INSTALL for more details.
The major addition of this release are SUrflets by Andreas
Bernauer. SUrflets are server-side scripts for the web-server written
in Scheme. Based on the idea of Christian Queinnec, SUrflets employ
first-class continuations to overcome the lack of state in the HTTP
protocol and thereby ease the writing of web applications
dramatically. SUrflets represent XHTML using Oleg Kiselyov's SSAX
package, which makes it possible to build on the full power of
s-expressions for generating XHTML.
This release also fixes a number of bugs in various parts of the
library.
Relay, hack, and enjoy!
Dr. S.
Dr. S.
Martin Gasbichler
Eric Marsden
Andreas Bernauer
+1
View File
@@ -0,0 +1 @@
pdf
+1
View File
@@ -0,0 +1 @@
index.html man--h.idx man--h.ilg man--h.ind man.hlog man-Z-A.scm man-Z-H-10.html man-Z-H-11.html man-Z-H-12.html man-Z-H-13.html man-Z-H-14.html man-Z-H-15.html man-Z-H-16.html man-Z-H-17.html man-Z-H-1.html man-Z-H-2.html man-Z-H-3.html man-Z-H-4.html man-Z-H-5.html man-Z-H-6.html man-Z-H-7.html man-Z-H-8.html man-Z-H-9.html man-Z-L.scm man-Z-S.css
+8
View File
@@ -0,0 +1,8 @@
*.aux
*.toc
*.dvi
*.ps
*.pdf
*.log
*.png
*.idx
+1
View File
@@ -0,0 +1 @@
../../web-server/root/htdocs/sunet-manual
+37
View File
@@ -0,0 +1,37 @@
.SUFFIXES: .idx .ind .tex .dvi .ps .pdf $(.SUFFIXES)
TEX= cgi-script.tex ftp.tex pdfcond.tex smtp.tex ftpd.tex pop3.tex \
uri.tex decls.tex httpd.tex netrc.tex rfc822.tex url.tex dns.tex \
intro.tex nettime.tex skeleton.tex
TEX2PAGE=tex2page
man.dvi: $(TEX) man.ind
man.ind: man.idx
man.pdf: $(TEX) man.ind
.dvi.ps:
dvips -j0 -o $@ $<
.tex.dvi:
latex $< && latex $<
rm $*.log
.tex.pdf:
pdflatex $< && thumbpdf $@ && pdflatex $<
rm $*.log
.idx.ind:
makeindex $<
clean:
-rm -f *.log *.png man.out man.dvi man.ps man.pdf thumb*.png
rm -rf ../../web-server/root/htdocs/sunet-manual
INSTALL_DATA= install -c -m 644
tar:
tar cf - *.tex sty | gzip > man.tar.gz
html: $(TEX)
$(TEX2PAGE) man && $(TEX2PAGE) man
+24
View File
@@ -0,0 +1,24 @@
\chapter{Writing CGI Scripts in Scheme}\label{cha:cgi-scripts}
%
The \ex{cgi-scripts} structure provides functionality useful for
writing CGI scripts in Scheme.
\defun{cgi-form-query}{}{data-alist}
\begin{desc}
CGI scripts receive their parameters in various ways, depending on
how they were called (e.g.\ by \ex{GET} method).
This procedure translates the delivered form data into an alist of
decoded strings, using the environment variables set by the server
(\ex{REQUEST\_METHOD}, \ex{QUERY\_STRING} (for a \ex{GET} request),
\ex{CONTENT\_LENGTH} (for a \ex{POST} request)). So a query string
like \codex{button=on\&\ob{}reply=Oh,\ob{}\%20yes} becomes an alist
\codex{(("button" . "on") ("reply" . "Oh, yes"))}
\ex{Cgi-form-query} only works for \ex{GET} and \ex{POST} methods.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+296
View File
@@ -0,0 +1,296 @@
% code.sty: -*- latex -*-
% Latex macros for a "weak" verbatim mode.
% -- like verbatim, except \, {, and } have their usual meanings.
% Environments: code, tightcode, codeaux, codebox, centercode
% Commands: \dcd, \cddollar, \cdmath, \cd, \codeallowbreaks, \codeskip, \^
% Already defined in LaTeX, but of some relevance: \#, \$, \%, \&, \_, \{, \}
% Changelog at the end of the file.
% These commands give you an environment, code, that is like verbatim
% except that you can still insert commands in the middle of the environment:
% \begin{code}
% for(x=1; x<loop_bound; x++)
% y += x^3; /* {\em Add in {\tt x} cubed} */
% \end{code}
%
% All characters are ordinary except \{}. To get \{} in your text,
% you use the commands \\, \{, and \}.
% These macros mess with the definition of the special chars (e.g., ^_~%).
% The characters \{} are left alone, so you can still have embedded commands:
% \begin{code} f(a,b,\ldots,y,z) \end{code}
% However, if your embedded commands use the formerly-special chars, as in
% \begin{code} x := x+1 /* \mbox{\em This is $y^3$} */ \end{code}
% then you lose. The $ and ^ chars are scanned in as non-specials,
% so they don't work. If the chars are scanned *outside* the code env,
% then you have no problem:
% \def\ycube{$y^3$}
% \begin{code} x := x+1 /* {\em This is \ycube} */ \end{code}
% If you must put special chars inside the code env, you do it by
% prefixing them with the special \dcd ("decode") command, that
% reverts the chars to back to special status:
% \begin{code} x := x+1 /* {\dcd\em This is $y^3$} */ \end{code}
% \dcd's scope is bounded by its enclosing braces. It is only defined within
% the code env. You can also turn on just $ with the \cddollar command;
% you can turn on just $^_ with the \cdmath command. See below.
%
% Alternatively, just use \(...\) for $...$, \sp for ^, and \sb for _.
% WARNING:
% Like \verb, you cannot put a \cd{...} inside an argument to a macro
% or a command. If you try, for example,
% \mbox{\cd{$x^y$}}
% you will lose. That is because the text "\cd{$x^y$}" gets read in
% as \mbox's argument before the \cd executes. But the \cd has to
% have a chance to run before LaTeX ever reads the $x^y$ so it can
% turn off the specialness of $ and ^. So, \cd has to appear at
% top level, not inside an argument. Similarly, you can't have
% a \cd or a \code inside a macro (Although you could use \gdef to
% define a macro *inside* a \cd, which you could then use outside.
% Don't worry about this if you don't understand it.)
% BUG: In the codebox env, the effect of a \dcd, \cddollar, or \cdmath
% command is reset at the end of each line. This can be hacked by
% messing with the \halign's preamble, if you feel up to it.
% Useage note: the initial newline after the \begin{code} or
% \begin{codebox} is eaten, but the last newline is not.
% So,
% \begin{code}
% foo
% bar
% \end{code}
% leaves one more blank line after bar than does
% \begin{code}
% foo
% bar\end{code}
% Moral: get in the habit of terminating code envs without a newline
% (as in the second example).
%
% All this stuff tweaks the meaning of space, tab, and newline.
%===============================================================================
% \cd@obeyspaces
% Turns all spaces into non-breakable spaces.
% Note: this is like \@vobeyspaces except without spurious space in defn.
% @xobeysp is basically a space; it's defined in latex.tex.
%
{\catcode`\ =\active\gdef\cd@obeyspaces{\catcode`\ =\active\let =\@xobeysp}}
% \cd@obeytabs
% Turns all tabs into 8 non-breakable spaces (which is bogus).
%
{\catcode`\^^I=\active %
\gdef\cd@obeytabs{\catcode`\^^I=\active\let^^I=\cd@tab}}
\def\cd@tab{\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp}
% \cd@obeylines
% Turns all cr's into linebreaks. Pagebreaks are not permitted between lines.
% This is copied from lplain.tex's \obeylines, with the cr def'n changed.
%
{\catcode`\^^M=\active % these lines must end with %
\gdef\cd@obeylines{\catcode`\^^M=\active\let^^M=\cd@cr}}
% What ^M turns into. This def'n keeps blank lines from being compressed out.
\def\cd@cr{\par\penalty10000\leavevmode} % TeX magicness
%\def\cd@cr{\par\penalty10000\mbox{}} % LaTeX
% \codeallowbreaks
% Same as \cd@obeylines, except pagebreaks are allowed.
% Put this command inside a code env to allow pagebreaks.
{\catcode`\^^M=\active % these lines must end with %
\gdef\codeallowbreaks{\catcode`\^^M\active\let^^M\cd@crbr}}
%\def\cd@crbr{\leavevmode\endgraf} % What ^M turns into.
\def\cd@crbr{\par\leavevmode} % What ^M turns into.
% \cd@obeycrsp
% Turns cr's into non-breakable spaces. Used by \cd.
{\catcode`\^^M=\active % these lines must end with %
\gdef\cd@obeycrsp{\catcode`\^^M=\active\let^^M=\@xobeysp}}
% =============================================================================
% Set up code environment, in which most of the common special characters
% appearing in code are treated verbatim, namely: $&#^_~%
% \ { } are still enabled so that macros can be called in this
% environment. Use \\, \{, and \} to use these characters verbatim
% in this environment.
%
% Inside a group, you can make
% all the hacked chars special with the \dcd command
% $ special with the \cddollar command
% $^_ special with the \cdmath command.
% If you have a bunch of math $..$'s in your code env, then a global \cddollar
% or \cdmath at the beginning of the env can save a lot of trouble.
% When chars are special (e.g., after a \dcd), you can still get #$%&_{} with
% \#, \$, \%, \&, \_, \{, and \} -- this is standard LaTeX.
% Additionally, \\ gives \ inside the code env, and when \cdmath
% makes ^ special, it also defines \^ to give ^.
%The hacked characters can be made special again
% within a group by using the \dcd command.
% Note: this environment allows no breaking of lines whatsoever; not
% at spaces or hypens. To arrange for a break use the standard \- command,
% or a \discretionary{}{}{} which breaks, but inserts nothing. This is useful,
% for example for allowing hypenated identifiers to be broken, e.g.
% \def\={\discretionary{}{}{}} %optional break
% FOO-\=BAR.
\def\setupcode{\parsep=0pt\parindent=0pt%
\normalfont\ttfamily\frenchspacing\catcode``=13\@noligs%
\def\\{\char`\\}%
\let\dcd=\cd@dcd\let\cddollar=\cd@dollarspecial\let\cdmath=\cd@mathspecial%
\@makeother\$\@makeother\&\@makeother\#%
\@makeother\^\@makeother\_\@makeother\~%
\@makeother\%\cd@obeytabs\cd@obeyspaces}
% other: $&#^_~%
% left special: \{}
% unnecessary: @`'"
%% codebox, centercode
%%=============================================================================
%% The codebox env makes a box exactly as wide as it needs to be
%% (i.e., as wide as the longest line of code is). This is useful
%% if you want to center a chunk of code, or flush it right, or
%% something like that. The optional argument to the environment,
%% [t], [c], or [b], specifies how to vertically align the codebox,
%% just as with arrays or other boxes. Default is [c].
%% Must be a newline immediately after "\begin{codebox}[t]"!
{\catcode`\^^M=\active % these lines must end with %
\gdef\cd@obeycr{\catcode`\^^M=\active\let^^M=\cr}}
% If there is a [<letter>] option, then the following newline will
% be read *after* ^M is bound to \cr, so we're cool. If there isn't
% an option given (i.e., default to [c]), then the @\ifnextchar will
% gobble up the newline as it gobbles whitespace. So we insert the
% \cr explicitly. Isn't TeX fun?
\def\codebox{\leavevmode\@ifnextchar[{\@codebox}{\@codebox[c]\cr}} %]
\def\@codebox[#1]%
{\hbox\bgroup$\if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi\bgroup%
\tabskip\z@\setupcode\cd@obeycr% just before cd@obey
\halign\bgroup##\hfil\span}
\def\endcodebox{\crcr\egroup\egroup\m@th$\egroup}
% Center the box on the page:
\newenvironment{centercode}%
{\begin{center}\begin{codebox}[c]}%
{\end{codebox}\end{center}}
%% code, codeaux, tightcode
%%=============================================================================
%% Code environment as described above. Lines are kept on one page.
%% This actually works by setting a huge penalty for breaking
%% between lines of code. Code is indented same as other displayed paras.
%% Note: to increase left margin, use \begin{codeaux}{\leftmargin=1in}.
% To allow pagebreaks, say \codeallowbreaks immediately inside the env.
% You can allow breaks at specific lines with a \pagebreak form.
%% N.B.: The \global\@ignoretrue command must be performed just inside
%% the *last* \end{...} before the following text. If not, you will
%% get an extra space on the following line. Blech.
%% This environment takes two arguments.
%% The second, required argument is the \list parameters to override the
%% \@listi... defaults.
%% - Usefully set by clients: \topsep \leftmargin
%% - Possible, but less useful: \partopsep
%% The first, optional argument is the extra \parskip glue that you get around
%% \list environments. It defaults to the value of \parskip.
\def\codeaux{\@ifnextchar[{\@codeaux}{\@codeaux[\parskip]}} %]
\def\@codeaux[#1]#2{%
\bgroup\parskip#1%
\begin{list}{}%
{\parsep\z@\rightskip\z@\listparindent\z@\itemindent\z@#2}%
\item[]\setupcode\cd@obeylines}%
\def\endcodeaux{\end{list}\leavevmode\egroup\ignorespaces\global\@ignoretrue}
%% Code env is codeaux with the default margin and spacing \list params:
\def\code{\codeaux{}} \let\endcode=\endcodeaux
%% Like code, but with no extra vertical space above and below.
\def\tightcode{\codeaux[=0pt]{\topsep\z@}}%
\let\endtightcode\endcodeaux
% {\vspace{-1\parskip}\begin{codeaux}{\partopsep\z@\topsep\z@}}%
% {\end{codeaux}\vspace{-1\parskip}}
% Reasonable separation between lines of code
\newcommand{\codeskip}{\penalty0\vspace{2ex}}
% \cd is used to build a code environment in the middle of text.
% Note: only difference from display code is that cr's are taken
% as unbreakable spaces instead of linebreaks.
\def\cd{\leavevmode\begingroup\ifmmode\let\startcode=\startmcode\else%
\let\startcode\starttcode\fi%
\setupcode\cd@obeycrsp\startcode}
\def\starttcode#1{#1\endgroup}
\def\startmcode#1{\hbox{#1}\endgroup}
% Restore $&#^_~% to their normal catcodes
% Define \^ to give the ^ char.
% \dcd points to this guy inside a code env.
\def\cd@dcd{\catcode`\$=3\catcode`\&=4\catcode`\#=6\catcode`\^=7%
\catcode`\_=8\catcode`\~=13\catcode`\%=14\def\^{\char`\^}}
% Selectively enable $, and $^_ as special.
% \cd@mathspecial also defines \^ give the ^ char.
% \cddollar and \cdmath point to these guys inside a code env.
\def\cd@dollarspecial{\catcode`\$=3}
\def\cd@mathspecial{\catcode`\$=3\catcode`\^=7\catcode`\_=8%
\def\^{\char`\^}}
% Change log:
% Started off as some macros found in C. Rich's library.
% Olin 1/90:
% Removed \makeatletter, \makeatother's -- they shouldn't be there,
% because style option files are read with makeatletter. The terminal
% makeatother screwed things up for the following style options.
% Olin 3/91:
% Rewritten.
% - Changed things so blank lines don't get compressed out (the \leavevmove
% in \cd@cr and \cd@crwb).
% - Changed names to somewhat less horrible choices.
% - Added lots of doc, so casual hackers can more easily mess with all this.
% - Removed `'"@ from the set of hacked chars, since they are already
% non-special.
% - Removed the bigcode env, which effect can be had with the \codeallowbreaks
% command.
% - Removed the \@noligs command, since it's already defined in latex.tex.
% - Win big with the new \dcd, \cddollar, and \cdmath commands.
% - Now, *only* the chars \{} are special inside the code env. If you need
% more, use the \dcd command inside a group.
% - \cd now works inside math mode. (But if you use it in a superscript,
% it still comes out full size. You must explicitly put a \scriptsize\tt
% inside the \cd: $x^{\cd{\scriptsize\tt...}}$. A \leavevmode was added
% so that if you begin a paragraph with a \cd{...}, TeX realises you
% are starting a paragraph.
% - Added the codebox env. Tricky bit involving the first line hacked
% with help from David Long.
% Olin 8/94
% Changed the font commands for LaTeX2e.
+114
View File
@@ -0,0 +1,114 @@
% css.t2p
% Dorai Sitaram
% 19 Jan 2001
% A basic style for HTML documents generated
% with tex2page.
\ifx\shipout\UNDEFINED
\cssblock
body {
color: black;
/* background-color: #e5e5e5;*/
background-color: #ffffff;
/*background-color: beige;*/
margin-top: 2em;
margin-left: 8%;
margin-right: 8%;
}
h1,h2,h3,h4,h5,h6 {
margin-top: .5em;
}
.partheading {
font-size: 100%;
}
.chapterheading {
font-size: 100%;
}
pre {
margin-left: 2em;
}
ol {
list-style-type: decimal;
}
ol ol {
list-style-type: lower-alpha;
}
ol ol ol {
list-style-type: lower-roman;
}
ol ol ol ol {
list-style-type: upper-alpha;
}
.scheme {
color: brown;
}
.scheme .keyword {
color: #990000;
font-weight: bold;
}
.scheme .builtin {
color: #990000;
}
.scheme .variable {
color: navy;
}
.scheme .global {
color: purple;
}
.scheme .selfeval {
color: green;
}
.scheme .comment {
color: teal;
}
.schemeresponse {
color: green;
}
.navigation {
color: red;
text-align: right;
font-style: italic;
}
.disable {
/* color: #e5e5e5; */
color: gray;
}
.smallcaps {
font-size: 75%;
}
.smallprint {
color: gray;
font-size: 75%;
text-align: right;
}
.smallprint hr {
text-align: left;
width: 40%;
}
\endcssblock
\fi
% ex:ft=css
+6
View File
@@ -0,0 +1,6 @@
% Loads cmtt fonts in on \tt. -*- latex -*-
% I prefer these to the Courier fonts that latex gives you w/postscript styles.
% Courier is too spidery and too wide -- it's hard to get 80 chars on a line.
% -Olin
\renewcommand{\ttdefault}{cmtt}
+338
View File
@@ -0,0 +1,338 @@
\makeatletter
\def\ie{\mbox{\emph{i.e.}}} % \mbox keeps the last period from
\def\Ie{\mbox{\emph{I.e.}}} % looking like an end-of-sentence.
\def\eg{\mbox{\emph{e.g.}}}
\def\Eg{\mbox{\emph{E.g.}}}
\def\etc{{\em etc.}}
\def\Lisp{\textsc{Lisp}}
\def\CommonLisp{\textsc{Common Lisp}}
\def\Ascii{\textsc{Ascii}}
\def\Ansi{\textsc{Ansi}}
\def\Unix{{Unix}} % Not smallcaps, according to Bart.
\def\Scheme{{Scheme}}
\def\scm{{Scheme 48}}
\def\RnRS{R5RS}
\def\Posix{\textsc{Posix}}
\def\sharpf{\textnormal{\texttt{\#f}}}
\def\sharpt{\textnormal{\texttt{\#t}}}
\newcommand{\synteq}{\textnormal{::=}}
\def\maketildeother{\catcode`\~=12}
\def\maketildeactive{\catcode`\~=13}
\def\~{\char`\~}
\newcommand{\evalsto}{\ensuremath{\Rightarrow}}
% One-line code examples
%\newcommand{\codex}[1]% One line, centred. Tight spacing.
% {$$\abovedisplayskip=.75ex plus 1ex minus .5ex%
% \belowdisplayskip=\abovedisplayskip%
% \abovedisplayshortskip=0ex plus .5ex%
% \belowdisplayshortskip=\abovedisplayshortskip%
% \hbox{\ttt #1}$$}
%\newcommand{\codex}[1]{\begin{tightinset}\ex{#1}\end{tightinset}\ignorespaces}
\newcommand{\codex}[1]{\begin{leftinset}\ex{#1}\end{leftinset}\ignorespaces}
\def\widecode{\codeaux{\leftmargin=0pt\topsep=0pt}}
\def\endwidecode{\endcodeaux}
% For multiletter vars in math mode:
\newcommand{\var}[1]{\mbox{\frenchspacing\it{#1}}}
\newcommand{\vari}[2]{\ensuremath{\mbox{\it{#1}}_{#2}}}
%% What you frequently want when you say \tt:
\def\ttchars{\catcode``=13\@noligs\frenchspacing}
\def\ttt{\normalfont\ttfamily\ttchars}
% Works in math mode; all special chars remain special; cheaper than \cd.
% Will not be correct size in super and subscripts, though.
\newcommand{\ex}[1]{{\normalfont\texttt{\ttchars #1}}}
\newenvironment{inset}
{\bgroup\parskip=1ex plus 1ex\begin{list}{}%
{\topsep=0pt\rightmargin\leftmargin}%
\item[]}%
{\end{list}\leavevmode\egroup\global\@ignoretrue}
\newenvironment{leftinset}
{\bgroup\parskip=1ex plus 1ex\begin{list}{}%
{\topsep=0pt}%
\item[]}%
{\end{list}\leavevmode\egroup\global\@ignoretrue}
\newenvironment{tightinset}
{\bgroup\parskip=0pt\begin{list}{}%
{\topsep=0pt\rightmargin\leftmargin}%
\item[]}%
{\end{list}\leavevmode\egroup\global\@ignoretrue}
\newenvironment{tightleftinset}
{\bgroup\parskip=0pt\begin{list}{}%
{\topsep=0pt}%
\item[]}%
{\end{list}\leavevmode\egroup\global\@ignoretrue}
\long\def\remark#1{\bgroup\small\begin{quote}\textsl{Remark: } #1\end{quote}\egroup}
\newenvironment{remarkenv}{\bgroup\small\begin{quote}\textsl{Remark: }}%
{\end{quote}\egroup}
\newcommand{\oops}[1]{\bgroup\small\begin{quote}\textsl{Oops: } #1\end{quote}\egroup}
\newcommand{\note}[1]{\{Note #1\}}
\newcommand{\itum}[1]{\item{\bf #1}\\*}
% For use in code. The \llap magicness makes the lambda exactly as wide as
% the other chars in \tt; the \hskip shifts it right a bit so it doesn't
% crowd the left paren -- which is necessary if \tt is cmtt.
% Note that (\l{x y} (+ x y)) uses the same number of columns in TeX form
% as it produces when typeset. This makes it easy to line up the columns
% in your input. \l is bound to some useless command in LaTeX, so we have to
% define it w/renewcommand.
\let\oldl\l %Save the old \l on \oldl
\renewcommand{\l}[1]{\ \llap{$\lambda$\hskip-.05em}\ (#1)}
% This one is for the rare (lambda x ...) case -- it doesn't have the
% column-invariant property. Oh, well.
\newcommand{\lx}[1]{\ \llap{$\lambda$\hskip-.05em}\ {#1}}
% For subcaptions
\newcommand{\subcaption}[1]
{\unskip\vspace{-2mm}\begin{center}\unskip\em#1\end{center}}
%%% T release notes stuff
\newlength{\notewidth}
\setlength{\notewidth}{\textwidth}
\addtolength{\notewidth}{-1.25in}
%\newcommand{\remark} [1]
% {\par\vspace{\parskip}
% \parbox[t]{.75in}{\sc Remark:}
% \parbox[t]{\notewidth}{\em #1}
% \vspace{\parskip}
% }
\newenvironment{optiontable}%
{\begin{tightinset}\renewcommand{\arraystretch}{1.5}%
\begin{tabular}{@{}>{\ttt}ll@{}}}%
{\end{tabular}\end{tightinset}}%
\newenvironment{desctable}[1]%
{\begin{inset}\renewcommand{\arraystretch}{1.5}%
\begin{tabular}{lp{#1}}}%
{\end{tabular}\end{inset}}
\def\*{{\ttt *}}
% Names of things
\newcommand{\keyword} [1]{\index{#1}{\normalfont\textsf{#1}}}
% \ex{#1} and also generates an index entry.
\newcommand{\exi}[1]{\index{#1@\texttt{#1}}\ex{#1}}
\newcommand{\indextt}[1]{\index{#1@\texttt{#1}}}
\newcommand{\evalto}{$\Longrightarrow$\ }
\renewcommand{\star}{$^*$\/}
\newcommand{\+}{$^+$}
% Semantic domains, used to indicate the type of a value
\newcommand{\sem}{\normalfont\itshape} %semantic font
\newcommand{\semvar}[1]{\textit{#1}} %semantic font
\newcommand{\synvar}[1]{\textrm{\textit{$\left<\right.$#1$\left.\right>$}}} %syntactic font
\newcommand{\type}{\sem}
\newcommand{\zeroormore}[1]{{\sem #1$_1$ \ldots #1$_n$}}
\newcommand{\oneormore}[1]{{\sem #1$_1$ #1$_2$ \ldots #1$_n$}}
\newcommand{\proc} {{\sem procedure}}
\newcommand{\boolean} {{\sem boolean}}
\newcommand{\true} {{\sem true}}
\newcommand{\false} {{\sem false}}
\newcommand{\num} {{\sem number}}
\newcommand{\fixnum} {{\sem fixnum}}
\newcommand{\integer} {{\sem integer}}
\newcommand{\real} {{\sem real}}
\newcommand{\character} {{\sem character}}
\newcommand{\str} {{\sem string}}
\newcommand{\sym} {{\sem symbol}}
\newcommand{\location} {{\sem location}}
\newcommand{\object} {{\sem object}}
\newcommand{\error} {{\sem error}}
\newcommand{\syntaxerror} {{\sem syntax error}}
\newcommand{\readerror} {{\sem read error}}
\newcommand{\undefined} {{\sem undefined}}
\newcommand{\noreturn} {{\sem no return value}}
\newcommand{\port} {{\sem port}}
% semantic variables
\newcommand{\identifier} {{\sem identifier}}
\newcommand{\identifiers} {\zeroormore{\<ident>}}
\newcommand{\expr} {{\sem expression}}
\newcommand{\body} {{\sem body}}
\newcommand{\valueofbody} {{\sem value~of~body}}
\newcommand{\emptylist} {{\sem empty~list}}
\newcommand{\car} {\keyword{car}}
\newcommand{\cdr} {\keyword{cdr}}
\newcommand{\TMPDIR}{\texttt{\$TMPDIR}}
% generally useful things
% For line-breaking \tt stuff.
\renewcommand{\=}{\discretionary{-}{}{-}}
\newcommand{\ob}{\discretionary{}{}{}} % Optional break.
\newcommand{\indx}[1]{#1 \index{ #1 }}
%\newcommand{\gloss}[1]{#1 \glossary{ #1 }}
% This lossage produces #2 if #1 is zero length, otw #3.
% We use it to conditionally add a space between the procedure and
% the args in procedure prototypes, but only if there are any args--
% we want to produce "(read)", not "(read )".
\newlength{\voidlen}
\newcommand{\testvoid}[3]{\settowidth\voidlen{#1}\ifdim\voidlen>0in{#3}\else{#2}\fi}
% Typeset a definition prototype line, e.g.:
% (cons <arg1> <arg2>) -> pair procedure
%
% Five args are: proc-name args ret-value(s) type index-entry
\newcommand{\dfnix}[5]
{\hbox to \linewidth{\ttchars%
{\ttt(#1\testvoid{#2}{}{\ }{\sem{#2}}\testvoid{#2}{}{\/})\hskip 1em minus
0.5em$\longrightarrow$\hskip 1em minus 0.5em{\sem{#3}}\hfill\quad\textnormal{#4}}}\index{#5}}
\newcommand{\dfnx}[4] {\dfnix{#1}{#2}{#3}{#4}{#1@\texttt{#1}}}
\newcommand{\dfn} {\par\medskip\dfnx} % Takes 4 args, actually.
\newcommand{\dfni} {\par\medskip\dfnix} % Takes 5 args, actually.
\newcommand{\defvar} {\par\medskip\defvarx} % Takes 4 args, actually.
\newcommand{\defvarx}[2]%
{\index{#1}
\hbox to \linewidth{\ttchars{{\ttt{#1}} \hfill #2}}}%
% Typeset the protocol line, then do the following descriptive text indented.
% If you want to group two procs together, do the first one with a \dfn,
% then the second one, and the documentation, with a \defndescx.
% This one doesn't put whitespace above. Use it immediately after a \dfn
% to group two prototype lines together.
\newenvironment{dfndescx}[4]%
{\dfnx{#1}{#2}{#3}{#4}\begin{desc}}{\end{desc}}
\newenvironment{dfndesc}[4] % This one puts whitespace above.
{\par\medskip\begin{dfndescx}{#1}{#2}{#3}{#4}}
{\end{dfndescx}}
\newenvironment{desc}%
{\nopagebreak[2]%
\smallskip
\bgroup\begin{list}{}{\topsep=0pt\parskip=0pt}\item[]}
{\end{list}\leavevmode\egroup\global\@ignoretrue}
\def\defun#1#2#3{\dfn{#1}{#2}{#3}{procedure}} % preskip
\newcommand{\defunx}[3]{\dfnx{#1}{#2}{#3}{procedure}} % no skip
\newenvironment{defundescx}[3]%
{\begin{dfndescx}{#1}{#2}{#3}{procedure}}
{\end{dfndescx}}
\newenvironment{defundesc}[3]%
{\begin{dfndesc}{#1}{#2}{#3}{procedure}}
{\end{dfndesc}}
\newenvironment{column}{\begin{tabular}[t]{@{}l@{}}}{\end{tabular}}
\newenvironment{exampletable}%
{\begin{leftinset}%
\newcommand{\header}[1]{\multicolumn{2}{@{}l@{}}{##1}\\}%
\newcommand{\splitline}[2]%
{\multicolumn{2}{@{}l@{}}{##1}\\\multicolumn{2}{@{}l@{}}{\qquad\evalto\quad{##2}}}
\begin{tabular}{@{}l@{\quad\evalto\quad}l@{}}}%
{\end{tabular}\end{leftinset}}
% Put on blank lines in a code env to allow a pagebreak.
\newcommand{\cb}{\pagebreak[0]}
\newenvironment{boxedcode}
{\begin{inset}\tabular{|l|}\hline}
{\\ \hline \end{tabular}\end{inset}}
% A ragged-right decl that doesn't redefine \\ -- for use in tables.
\newcommand{\raggedrightparbox}{\let\temp=\\\raggedright\let\\=\temp}
\newenvironment{boxedfigure}[1]%
{\begin{figure}[#1]\begin{boxedminipage}{\linewidth}\vskip 1.5ex}
{\end{boxedminipage}\end{figure}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%for surflet howto
\def\surflet{SUrflet\xspace}
\def\surflets{SUrflets\xspace}
\def\scsh{scsh\xspace}
\def\sunet{SUnet\xspace}
%From surflet/decls.tex
{\theoremstyle{break}
\theoremheaderfont{\normalfont\bfseries\em}
\newtheorem{proglist}{Listing}[section]}
\setlength{\theorempreskipamount}{1.5ex plus0.2ex minus0.2ex}
\setlength{\theorempostskipamount}{2ex plus0.5ex minus0.2ex}
% These environments differ from the other definition by the
% positioning of \normalem
\newenvironment{listing}
{\ULforem\begin{proglist}\begin{alltt}\small\normalem}
{\end{alltt}\end{proglist}}
\newenvironment{reflisting}[1]
{\ULforem\begin{proglist}[\refinlisting{#1}]\begin{alltt}\small\normalem}
{\end{alltt}\end{proglist}}
\newcommand{\contatlisting}[1]{%
{\normalfont\textit{$<$continued in listing~\ref{#1}\/$>$}}}
\newcommand{\contfromlisting}[1]{%
{\normalfont\textit{$<$continued from listing~\ref{#1}\/$>$}}}
\newcommand{\refinlisting}[1]{%
{\normalfont\textit{referenced in listing~\ref{#1}}}}
\newcommand{\seelisting}[1]{%
{\normalfont{\textit{$<$see listing~\ref{#1}\/$>$}}}}
\newfloat{program}{t}{lop}
\floatname{program}{Programm}
\newenvironment{floatprog}[2]
{\begin{program}[ht] \caption{#1} \label{#2} \begin{alltt}}
{\end{alltt} \end{program}%
% Force output of even long floating figs
\afterpage{\clearpage}}
% Use url-package to get function names line-breaked at - / +
% by infos in /usr/share/texmf/tex/latex/misc/url.sty
%%\newcommand\breakfuntt{\begingroup \urlstyle{tt}%
%%\@ifundefined{selectfont}{\def\UrlFont{\tt}}{\def\UrlFont{\ttfamily}}%
%%\def\UrlBreaks{\do\-\do\/\do\+}\def\UrlNoBreaks{\do\!}\Url
%%}
\newcommand{\name}[1]{\texttt{#1}}
%\newcommand{\object}[1]{\breakfuntt{#1}}
\newcommand{\file}[1]{\textttt{#1}}
\newcommand{\codemph}[1]{\emph{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatother
+482
View File
@@ -0,0 +1,482 @@
\chapter{DNS Client Library}\label{cha:dns}
%
\begin{description}
\item[Used files:] dns.scm
\item[Name of the package:] dns
\end{description}
%
\section{Overview}
The \ex{dns} structure contains a library for querying DNS servers.
The library contains sophisticated replacements for scsh's interface
to the \ex{gethostbyname} and \ex{gethostbyaddr} and many extensions
to these functions.
The main features of the libraray include:
\begin{itemize}
\item Complete implementation of the DNS protocol
\item Concurrent contacting of multiple DNS servers without blocking
the scsh process
\item Internal caching of DNS responses
\item Parsing of \texttt{resolv.conf}, including \texttt{search}
entries to generate FQDNs from unqualified host names
\item Rich condition hierarchie
\end{itemize}
\section{Conditions}
The library defines a set of conditions raised by the procedures of
the library. The supertype of these conditions is \exi{dns-error}.
\defun{dns-error?}{thing}{\boolean}
\begin{desc}
The predicate for \ex{dns-error} conditions.
\end{desc}
\defun{dns-error->string} {dns-error-condition} {\str}
\begin{desc}
Returns a string with the description of the condition.
\end{desc}
\defvar{parse-error}{condition}
\defvarx{unexpected-eof-from-server}{condition}
\defvarx{bad-address}{condition}
\defvarx{no-nameservers}{condition}
\defvarx{bad-nameserver}{condition}
\defvarx{not-a-hostname}{condition}
\defvarx{not-a-ip} {condition}
\begin{desc}
\end{desc}
\defvar {dns-format-error} {condition}
\defvarx {dns-server-failure} {condition}
\defvarx {dns-name-error} {condition}
\defvarx {dns-not-implemented} {condition}
\defvarx {dns-refused} {condition}
\begin{desc}
These conditons correspond to errors returned by the DNS server.
They are all subtypes of the \exi{dns-server-error} condition which
in turn is a subtype of \ex{dns-error}.
\end{desc}
\defun{dns-server-error?}{thing}{\boolean}
\begin{desc}
The predicate for \ex{dns-server-error} conditions.
\end{desc}
\defun{parse-error?}{thing} {\boolean}
\defunx{unexpected-eof-from-server?}{thing} {\boolean}
\defunx{bad-address?}{thing} {\boolean}
\defunx{no-nameservers?}{thing} {\boolean}
\defunx{bad-nameserver?}{thing} {\boolean}
\defunx{not-a-hostname?}{thing} {\boolean}
\defunx{not-a-ip?}{thing} {\boolean}
\defunx{dns-format-error?} {thing} {\boolean}
\defunx{dns-server-failure?} {thing} {\boolean}
\defunx{dns-name-error?} {thing} {\boolean}
\defunx{dns-not-implemented?} {thing} {\boolean}
\defunx{dns-refused?} {thing} {\boolean}
\begin{desc}
The type predicates for the conditions above.
\end{desc}
\section{High-level Interface}
\def\ipaddr{IP-address\xspace}
\def\ipstring{IP-string\xspace}
\def\fqdn{FQDN\xspace}
The library uses an internal store to cache data obtained from DNS
servers. All procedures take a boolean flag \var{use-cache?} that
indicates whether the cache should be used or not. \var{use-cache?}
defaults to true.
\defun{dns-clear-cache!}{}{\undefined}
\begin{desc}
This procedure erases all information stored in the internal cache.
\end{desc}
The library is further capable of parsing the contents of
\texttt{/etc/resolv.conf} (see Section~\ref{sec:dns-rc}). The
nameservers listed there are the default value for the optional
argument \var{nameserver list} which many procedures of the library
accept. \var{Nameserver} is either a \ipaddr or a dotted IP string.
\defun{dns-lookup-name}{\fqdn [nameserver list][use-cache?]}{\ipaddr}
\begin{desc}
Given the FQDN of a host, \ex{dns-lookup-ip} returns the IP address.
The optional argument specifes the name servers to query, it defaults
to the ones found in \texttt{/etc/resolv.conf}.
\end{desc}
\defun{dns-lookup-ip}{\ipstring/\ipaddr [nameserver list][use-cache?]}{\fqdn}
\begin{desc}
Looks up the FQDN for the given IP address. The optional argument
specifes the name servers to query, it defaults to the ones found in
\texttt{/etc/resolv.conf}.
\end{desc}
\defun{dns-lookup-nameserver}{\ipstring/\ipaddr [nameserver list][use-cache?]}{\ipaddr list}
\begin{desc}
Looks up an authoritative name server for a hostname, returns a list
of name servers.
\end{desc}
\defun{dns-lookup-mail-exchanger}{\ipstring/\ipaddr [nameserver list][use-cache?]}{\fqdn list}
\begin{desc}
Looks up mail-exchangers for a hostname und returns them in a list
sorted by preference.
\end{desc}
\defun{socket-address->fqdn}{socket-address [nameserver list][use-cache?]}{\fqdn}
\begin{desc}
Returns the FQDN for of the address bound to argument. The argument
\var{cache?} indicates whether the internal cache may be queried to
obtain the information.
\end{desc}
\defun{maybe-dns-lookup-name}{\fqdn [nameserver list][use-cache?]}{\ipaddr or \sharpf}
\defunx{maybe-dns-lookup-ip}{\ipstring/\ipaddr [nameserver list][use-cache?]}{\fqdn{} or \sharpf}
\begin{desc}
These procedures provide the same functionality as
\ex{dns-lookup-name} and \ex{dns-lookup-ip} but return \sharpf{} in
case of an \ex{dns-error}.
\end{desc}
\defun{host-fqdn} {name/socket-address [nameserver list][use-cache?]}{\fqdn}
\defunx{system-fqdn}{[nameserver list][use-cache?]}{\fqdn}
\begin{desc}
\ex{host-fqdn} returns the fully qualified domain name (FQDN) for
its argument which can be either a unqualified host name or a socket
address. The procedure \ex{system-fqdn} returns the FQDN of the
local host. These procedures use a list of domain names obtained
from \texttt{/etc/resolv.conf} to the generate FQDNs and try to
resolve these FQDNs.
\end{desc}
\defun{dns-check-nameservers} {[nameserver list]} {\undefined}
\begin{desc}
\ex{dns-check-namservers} checks if the given nameservers are reachable.
If no argument is given, the nameservers in \texttt{/etc/resolv.conf}
are checked. Information about the status of the nameservers is printed
to the current output port.
\end{desc}
\section{Low-level Interface}
This section describes a set of data structures and procedures which
directly correspond to the data flow of the DNS protocol. The central
entity is a \var{message}, the abstraction of the packet sent to the
server or received from the server (The DNS protocol uses the same
data format for both directions). A \var{dns-message} encapsulates the
query message sent to the server, the response message received from
the server, and some additional information the library gathered while
generating the \var{dns-message}.
\defunx{dns-get-information}{message protocol answer-okay? [nameserver
list][use-cache?]}{dns-message}
\begin{desc}
Most general way to submit a DNS query. The message is sent to the
name servers via \var{protocol} which can be either
\ex{(network-procotcol tcp)} or {(network-protocol udp)}, both
members of of the enumerated type \ex{network-protocol}. After
receiving the reply, \ex{dns-get-information} applies the predicate
\var{answer-okay?} to the message. If it returns \sharpf{} and the
answer is not authoritative additional name servers sent with the
reply are checked until an authoritative answer is found. If the
predicate returns \sharpf{} but the answer is authoritative a
\var{bad-address} condition is signalled.
\end{desc}
\dfn{network-protocol}{protocol-name}{network-protocol}{syntax}
\defunx{network-protocol?}{thing}{\boolean}
\begin{desc}
Constructor and predicate for the enumerated type
\ex{network-protocol} with the possible protocol names \ex{tcp} and
\ex{udp}.
\end{desc}
\defun{dns-lookup}{\ipstring/\ipaddr type [nameserver list][use-cache?]}{dns-message}
\begin{desc}
Convenient shortcut to submit a DNS query. The return value
is a \ex{dns-message} structure:
\end{desc}
\defun{dns-message?}{thing}{\boolean}
\defunx{dns-message-query}{dns-message}{message}
\defunx{dns-message-reply}{dns-message}{message}
\defunx{dns-message-cache?}{dns-message}{\boolean}
\defunx{dns-message-protocol}{dns-message}{protocol}
\defunx{dns-message-tried-nameservers}{dns-message}{}
\begin{desc}
A \var{dns-message} records the query sent to the server and the
reply from the server. It also contains information whether the
library took the reply from the cache, which protocol was used and
to which nameservers the query was sent.
\end{desc}
\defun{pretty-print-dns-message}{dns-message [output-port]}{\undefined}
\begin{desc}
Pretty prints a DNS message to \var{out-port} which defaults to the
current output port.
\end{desc}
\defun{message?}{thing}{\boolean}{}
\defunx{message-header}{message}{header}
\defunx{message-questions}{message}{question list}
\defunx{message-answers}{message}{resource-record list}
\defunx{message-nameservers}{message}{resource-record list}
\defunx{message-additionals}{message}{resource-record list}
\defunx{message-source}{message}{char list}
\begin{desc}
A \ex{message} represents the data sent to the DNS server or
received from the DNS server. The DNS protocol uses the same message
format for queries and replies. In queries only the header and the
questions is present, a reply may contain answers, name servers and
and additional informations as resource records. \ex{Message-source}
returns the actual data sent over the network.
\end{desc}
\defun{make-query-message header}{header question [questions]}{message}
\begin{desc}
The procedure generates a message the supplied questions,
\var{header}, and the standard message values for queries.
\end{desc}
\defun{make-simple-query-message}{name type class}{message}
\begin{desc}
This simplified constructor generates a message with one question
which is built from the parameters, and the standard header flags
for queries and the standard message values for queries.
\end{desc}
\defun{header?}{thing}{\boolean}
\defunx{header-id}{header}{number}
\defunx{header-flags}{header}{flags}
\defunx{header-question-count}{header}{number}
\defunx{header-answer-count}{header}{number}
\defunx{header-nameserver-count}{header}{number}
\defunx{header-additional-count}{header}{number}
\begin{desc}
Every DNS message contains a header which stores information about
the data present in the message and contains flags for the query.
\end{desc}
\defun{flags?}{thing}{\boolean}
\defunx{flags-query-type}{flags}{'query or 'response}
\defunx{flags-opcode}{flags}{number}
\defunx{flags-authoritative?}{flags}{\boolean}
\defunx{flags-truncated?}{flags}{\boolean}
\defunx{flags-recursion-desired?}{flags}{\boolean}
\defunx{flags-recursion-available?}{flags}{\boolean}
\defunx{flags-zero}{flags}{0}
\defunx{flags-response-code}{flags}{number}
\begin{desc}
Flags occur within the header of a DNS message. The boolean value
returned from \ex{flags-authoritative} indicates whether the message
was sent from a authoritative server, \ex{flags-truncated?} should
always be \sharpf as the library automatically uses the TCP protocol
is the UDP message size is not sufficied.
\end{desc}
\defun{question?}{thing}{\boolean}
\defunx{question-name}{question}{\str}
\defunx{question-type}{question}{message-type}
\defunx{question-class}{question}{message-class}
\begin{desc}
A question sent to the DNS server.
\end{desc}
The type and class of the question and answer are elements of
enumerated types:
\dfn{message-class}{class-name}{message-class}{syntax}
\defunx{message-class?}{thing}{\boolean}
\defunx{message-class-name}{message-class}{symbol}
\defunx{message-class-number}{message-class}{number}
\begin{desc}
\ex{message-class} constructs a member of the enumerated type,
\ex{message-class?} is the type predicate, \ex{message-class-name}
returns the symbol and \ex{message-class-number} the number used for
the class in the DNS protocol.
\end{desc}
The possible names for the classes are:
\begin{description}
\item[\ex{in}] The Internet
\item[\ex{cs}] obsolete
\item[\ex{ch}] the CHAOS class
\item[\ex{hs}] Hesoid
\end{description}
\dfn{message-type}{type-name}{message-type}{syntax}
\defunx{message-type?}{thing}{\boolean}
\defunx{message-type-name}{message-type}{symbol}
\defunx{message-type-number}{message-type}{number}
\begin{desc}
\ex{message-type} constructs a member of the enumeration from name
\synvar{type-name} listed in Table~\ref{tab:message-types}.
\ex{message-type?} is the type predicate, \ex{message-type-name}
returns the name, and \ex{message-type-number} the number used for
the class the DNS protocol.
\end{desc}
\begin{table}[htb]
\centering
\begin{tabular}{|l|l|}
\hline
\ex{a}& a host address\\\hline
\ex{ns}&an authoritative name server\\\hline
\ex{md}&(obsolete)\\\hline
\ex{mf}&(obsolete)\\\hline
\ex{cname}&the canonical name for an alias\\\hline
\ex{soa}& marks the start of a zone of authority\\\hline
\ex{mb}&(experimental)\\\hline
\ex{mg}&(experimental)\\\hline
\ex{mr}&(experimental)\\\hline
\ex{null}& (experimental)\\\hline
\ex{wks}& a well known service description\\\hline
\ex{ptr}& a domain name pointer\\\hline
\ex{hinfo}& host information\\\hline
\ex{minfo}& (experimental)\\\hline
\ex{mx}& mail exchange\\\hline
\ex{txt}& text strings\\\hline
\end{tabular}
\caption{Message types}
\label{tab:message-types}
\end{table}
\defun{resource-record?}{thing}{\boolean}
\defunx{resource-record-name}{resource-record}{\str}
\defunx{resource-record-type}{resource-record}{message-type}
\defunx{resource-record-class}{resource-record}{message-class}
\defunx{resource-record-ttl}{resource-record}{number}
\defunx{resource-record-data}{resource-record}{resource-record-data-\dots}
\begin{desc}
A resource record as returned from the DNS server. The actual data
of the record is stored in the \texttt{resource-record-data} field.
It is one of the record types for resource record data described
below.
\end{desc}
\defun{resource-record-data-a?}{thing}{\boolean}
\defunx{resource-record-data-a-ip}{resource-record-data-a}{\ipaddr}
\begin{desc}
An address resource record which holds an internet address.
\end{desc}
\defun{resource-record-data-ns?}{thing}{\boolean}
\defunx{resource-record-data-ns-name}{resource-record-data-ns}{\fqdn}
\begin{desc}
A name server resource record containing the FQDN of the name server.
\end{desc}
\defun{resource-record-data-cname?}{thing}{\boolean}
\defunx{resource-record-data-cname-name}{resource-record-data-cname}{\fqdn}
\begin{desc}
A canonical name resource record which contains the canonical or
primary name of the owner.
\end{desc}
\defun{resource-record-data-mx?}{thing}{\boolean}
\defunx{resource-record-data-mx-preference}{resource-record-data-mx}{number}
\defunx{resource-record-data-mx-exchanger}{resource-record-data-mx}{\fqdn}
\begin{desc}
A mail exchange resource record with the preference and the FQDN of
a host willing to act as a mail exchange.
\end{desc}
\defun{resource-record-data-ptr?}{thing}{\boolean}
\defunx{resource-record-data-ptr-name}{resource-record-data-ptr}{\str}
\begin{desc}
A pointer resource record which points to some other domain name.
\end{desc}
\defun{resource-record-data-soa?}{thing}{\boolean}
\defunx{resource-record-data-soa-mname}{resource-record-data-soa}{\fqdn}
\defunx{resource-record-data-soa-rname}{resource-record-data-soa}{\fqdn}
\defunx{resource-record-data-soa-serial}{resource-record-data-soa}{number}
\defunx{resource-record-data-soa-refresh}{resource-record-data-soa}{number}
\defunx{resource-record-data-soa-retry}{resource-record-data-soa}{number}
\defunx{resource-record-data-soa-expire}{resource-record-data-soa}{number}
\defunx{resource-record-data-soa-minimum}{resource-record-data-soa}{number}
\begin{desc}
A start of a zone of authority resource record.
\end{desc}
The protocol specifies other possible values for the \texttt{resource-record-data}
field but we where no able to find test cases for them.
\defun{cache?}{thing}{\boolean}
\defunx{cache-answer}{cache}{dns-message}
\defunx{cache-ttl}{cache}{number}
\defunx{cache-time}{cache}{number}
\begin{desc}
A cache data structure corresponds to a saved answer to a previous
query. \ex{cache-answer} returns the saved message, \ex{cache-ttl}
returns the time when the cache entry expires and \ex{cache-time}
returns the time the entry was created.
\end{desc}
\section{Parsing \texttt{/etc/resolv.conf}}
\label{sec:dns-rc}
\defvar{resolv.conf-parse-error} {condition}
\defun{resolv.conf-parse-error?}{thing}{\boolean}
\begin{desc}
The code signals the condition \var{resolv.conf-parse-error} if a
parse error occurs while scanning \texttt{/etc/resolv.conf}. It is a
subtype of the \var{dns-error} condition.
\ex{resolv.conf-parse-error?} is the type predicate for this
condition.
\end{desc}
\defun{resolv.conf}{}{{symbol$\rightarrow$string} alist}
\begin{desc}
Returns the contents of \texttt{/etc/resolv.conv} as an alist with
the possible keys \texttt{nameserver}, \texttt{domain},
\texttt{search}, \texttt{sortlist} and \texttt{options}.
Note that the library caches the contents of
\texttt{/etc/resolv.conv} and \ex{resolv.conf} only really opens the
file if its modification time is more recent than the modification
time of the cache.
\end{desc}
\defun{parse-resolv.conf!}{}{\undefined}
\begin{desc}
Parses the contents of \texttt{/etc/resolv.conv} and updates the
internal cache of the library.
\end{desc}
\defun{dns-find-nameserver-list}{}{\fqdn list}
\begin{desc}
Returns a list of name servers from \texttt{/etc/resolv.conf}
\end{desc}
\defun{dns-find-nameserver}{}{\fqdn}
\begin{desc}
Returns the first name servers found in \texttt{/etc/resolv.conf}.
\ex{dns-find-nameserver} raises \ex{no-nameservers} if
\texttt{/etc/resolv.conf} does not contain a \texttt{nameserver}
entry.
\end{desc}
\defun{domains-for-search}{}{\str{} list}
\begin{desc}
Parses \texttt{/etc/resolv.conf} and extracts the domains specified
by the \texttt{search} keyword.
\end{desc}
\section{IP Addresses as Dotted Strings}
%
\begin{description}
\item[Used files:] ip.scm
\item[Name of the package:] ips
\end{description}
%
The structure \ex{ips} provides a small set of procedures for turning
the human-readable form of IP addresses (``dotted strings'') into 32
bits numbers.
\defun{address32->ip-string}{\ipaddr}{ip-string}
\defun{ip-string->address32}{ip-string}{\ipaddr}
\defun{ip-string?}{string}{\boolean}
\begin{desc}
Tests whether \var{string} is a valid dotted string for an IP
address.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+163
View File
@@ -0,0 +1,163 @@
\chapter{FTP Client}\label{cha:ftp}
The \ex{ftp} structure lets you transfer files between networked
machines from the Scheme Shell, using the File Transfer Protocol as
described in RFC~959.
Some of the procedures in this module extract useful information from
the server's reply, such as the size of a file, or the name of the
directory we have moved to. These procedures return the extracted
information, or, if the server's response doesn't match the expected
code from the server, a catchable \ex{ftp-error} is raised.
\defun{ftp-connect}{host login password passive? [log-port]}{connection}
\begin{desc}
Open a command connection with the remote machine \var{host} and
login on that server with \var{login} and \var{password}.
\var{Login} and \var{password} can be \sharpf, in which case the
information is extracted from the user's \ex{.netrc} file if necessary.
If \var{log-port} is specified, it must be an output port: this
starts logging the conversation with the server to that port. Note
that the log contains passwords in clear text.
\end{desc}
\dfn{ftp-type}{\synvar{name}}{ftp-type}{syntax}
\defunx{set-ftp-type!}{connection ftp-type}{undefined}
\begin{desc}
This change the transfer mode for future file transfers. The
transfer mode is specfified by \var{ftp-type} which can be created
with the \ex{ftp-type} macro. \synvar{Name} must be either
\ex{binary} for binary data or \ex{ascii} for text.
\end{desc}
\defun{ftp-rename}{connection old new}{undefined}
\begin{desc}
This changes the name of \var{old} on the remote host to \var{new}
(assuming sufficient permissions). \var{Old} and \var{new} are
strings.
\end{desc}
\defun{ftp-delete}{connection file}{undefined}
\begin{desc}
This deletes \var{file} from the remote host (assuming the user has
appropriate permissions).
\end{desc}
\defun{ftp-cd}{connection dir}{undefined}
\begin{desc}
This changes the current directory on the server.
\end{desc}
\defun{ftp-cdup}{connection}{undefined}
\begin{desc}
This move to the parent directory on the server.
\end{desc}
\defun{ftp-pwd}{connection}{string}
\begin{desc}
Return the current directory on the remote host, as a string.
\end{desc}
\defun{ftp-ls}{connection [dir]}{list}
\begin{desc}
This returns a list of filenames on the remote host, either from the
current directory (if \var{dir} is not specified), or from the
directory specified by \var{dir}.
\end{desc}
\defun{ftp-dir}{connection [dir]}{status}
\begin{desc}
This returns a list of long-form file name entries on the remote
host, either from the current directory (if \var{dir} is not
specified), or from the directory specified by \var{dir}. (Note
that the format for the long-form entries is not specified by the
FTP standard.)
\end{desc}
\defun{ftp-get}{connection remote-file proc}{undefined}
\begin{desc}
This downloads \var{remote-file} from the FTP server.
\ex{Ftp-get} establishes a data conneciton to the server, attaches
an input port to the data connection, and calls \var{proc} on that
port.
\end{desc}
\defun{ftp-put}{connection remote-file proc}{undefined}
\begin{desc}
This uploads \var{remote-file} to the FTP server. \ex{Ftp-put}
establishes a data conneciton to the server, attaches an output port
to the data connection, and calls \var{proc} on that port.
\end{desc}
\defun{ftp-append}{connection remote-file proc}{undefined}
\begin{desc}
This appends data to \var{remote-file} on the FTP server.
\ex{Ftp-append} establishes a data conneciton to the server,
attaches an output port to the data connection, and calls \var{proc}
on that port.
\end{desc}
\defun{ftp-rmdir}{connection dir}{undefined}
\begin{desc}
This removes the directory \var{dir} from the remote host (assuming
sufficient permissions).
\end{desc}
\defun{ftp-mkdir}{connection dir}{undefined}
\begin{desc}
This create a new directory named \var{dir} on the remote host
(assuming sufficient permissions).
\end{desc}
\defun{ftp-modification-time}{connection file}{date}
\begin{desc}
This requests the time of the last modification of \var{file} on the
remote host, and on success return a Scsh date record. (This command
is not part of RFC~959 and is not implemented by all servers, but is
useful for mirroring.)
\end{desc}
\defun{ftp-size}{connection file}{integer}
\begin{desc}
This returns the size of \var{file} in bytes. (This command is not
part of RFC~959 and is not implemented by all servers.)
\end{desc}
\defun{ftp-quit}{connection}{undefined}
\begin{desc}
This closes the connection to the remote host. The \var{connection}
object is useless after a quit command.
\end{desc}
\defun{ftp-quot}{connection command}{status}
\begin{desc}
This sends a \var{command} verbatim to the remote server and wait
for a response. The response text is returned verbatim.
\end{desc}
\defun{ftp-error?}{thing}{boolean}
\begin{desc}
This returns \sharpt{} if \var{thing} is a \ex{ftp-error} object,
otherwise \sharpf.
\end{desc}
\defun{copy-port->port-binary}{input-port oputput-port}{undefined}
\defunx{copy-port->port-ascii}{input-port oputput-port}{undefined}
\defunx{copy-ascii-port->port}{input-port oputput-port}{undefined}
\begin{desc}
These procedures are useful for downloading and uploading data to an
FTP connection via \ex{ftp-get}, \ex{ftp-get}, and \ex{ftp-append}.
They all copy data from one port to another.
\ex{Copy-port->port-binary} copies verbatim, while the other two
perform CR/LF conversion for ASCII data transfers.
\ex{Copy-port->port-ascii} adds CR/LFs at line endings on output,
whereas \ex{Copy-ascii-port->port} removes CR/LFs at line endings
end replaces them by ordinary LFs.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+115
View File
@@ -0,0 +1,115 @@
\chapter{FTP Server}\label{cha:ftpd}
The \ex{ftpd} structure contains a complete anonymous ftp server.
\defun{ftpd}{options}{\noreturn}
\defunx{ftp-inetd}{options}{\noreturn}
\begin{desc}
\ex{Ftpd} starts the server, using \var{anonymous-home} as the
root directory of the server.
\ex{ftpd-inetd} is the version to be used from \ex{inetd}.
\ex{Ftpd-inetd} handles the connection through the current standard
output and input ports.
\end{desc}
%
The \var{options} argument can be constructed through a number of
procedures with names of the form \texttt{with-\ldots}. Each of these
procedures either creates a fresh options value or adds a
configuration parameter to an old options argument. The configuration
parameter value is always the first argument, the (old) options value
the optional second one. Here they are:
\defun{with-port}{port [options]}{options}
\begin{desc}
This specifies the port on which the server listens. Defaults to 21.
\end{desc}
\defun{with-anonymous-home}{string [options]}{options}
\begin{desc}
This specifies the home directory for anonymous logins. Defaults to
\verb|"~ftp"|.
\end{desc}
\defun{with-banner}{list [options]}{options}
\begin{desc}
This specifies an alternative greeting banner for those members of
the Untergrund who prefer to remain covert. The banner is
represented as a list of strings, one for each line of output.
\end{desc}
\defun{with-log-port}{output-port [options]}{options}
\begin{desc}
If this is non-\sharpf, ex{ftpd} outputs a log entry for each file
sent or retrieved on \var{output-port}. Defaults to \sharpf.
\end{desc}
\defun{with-dns-lookup?}{boolean [options]}{options}
\begin{desc}
If \var{dns-lookup?} is \sharpt, the log file will contain the host
names instead of their IP addresses. If \var{dns-lookup?} is \sharpf,
the log will only contain IP addresses. Defaults to \sharpf.
\end{desc}
%
The \ex{make-ftpd-options} eases the construction of the options
argument:
%
\defun{make-ftpd-options}{transformer value \ldots}{options}
\begin{desc}
This constructs an options value from an argument list of parameter
transformers and parameter values. The arguments come in pairs,
each an option transformer from the list above, and a value for that
parameter. \ex{Make-ftpd-options} returns the resulting options value.
\end{desc}
The log format of \ex{ftpd} is the same as the one of
\ex{wuftpd}. The entries look like this:
%
\begin{verbatim}
Fri Apr 19 17:08:14 2002 4 134.2.2.171 56881 /files.lst b _ i a nop@ssword ftp 0 *
\end{verbatim}
%
These are the fields:
\begin{enumerate}
\item Current date and time. This field contains
spaces and is 24 characters long.
\item Transfer time in seconds.
\item Remote host IP (wu-ftpd puts the name here).
\item File size in bytes
\item Name of file (spaces are converted to underscores)
\item Transfer type: \underline{a}scii or \underline{b}inary (image type).
\item Special action flags. As \ex{ftpd} does not support any special
action, it always has \ex{\_} here.
\item File was sent to user (\underline{o}utgoing) or received from user
(\underline{i}ncoming)
\item \underline{A}nonymous access
\item Anonymous ftp password.
\item Service name---always \ex{ftp}.
\item Authentication mode (always ``none'' = `\ex{0}').
\item Authenticated user ID (always ``not available'' = `\ex{*}')
\end{enumerate}
The server also writes log information to the syslog facility.
The following syslog levels occur in the output:
\begin{description}
\item[\ex{notice}]
\begin{itemize}
\item messages concerning \emph{connections} (establishing connection,
connection refused, closing connection due to timeout, etc.)
\item the execution of the \ex{STOR} command\\
Its success (\ie
somebody is putting something on your server via ftp, also known as
\ex{PUT}) is also logged at \ex{notice}.
\item internal errors
\item Unix errors
\item reaching of actually unreachable case branches
\end{itemize}
\item[\ex{info}] Messages concerning all other commands,
including the \ex{RETR} command.
\item[\ex{debug}] all other messages, including debug messages
\end{description}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+16
View File
@@ -0,0 +1,16 @@
% headings.tex -*- latex -*-
% Quieter headings that the ones used in article.sty.
% This is not a style option. Don't say [headings].
% Instead, say \input{headings} after the \documentstyle.
% -Olin 7/91
\makeatletter
\def\section{\@startsection {section}{1}{\z@}{-3.5ex plus -1ex minus
-.2ex}{2.3ex plus .2ex}{\large\normalfont\bfseries}}
\def\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus
-.2ex}{1.5ex plus .2ex}{\normalsize\normalfont\bfseries}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus
-1ex minus -.2ex}{1.5ex plus .2ex}{\normalsize\normalfont\bfseries}}
\makeatother
+703
View File
@@ -0,0 +1,703 @@
\chapter{HTTP server}\label{cha:httpd}
%
The SUnet HTTP Server is a complete industrial-strength implementation
of the HTTP 1.0 protocol. It is highly configurable and allows the writing
of dynamic web pages that run inside the server without going through
complicated and slow protocols like CGI or Fast/CGI.
\section{Starting and configuring the server}
All procedures described in this section are exported by the
\texttt{httpd} structure.
The Web server is started by calling the \ex{httpd} procedure, which takes
one argument, an options value:
\defun{httpd}{options}{\noreturn}
\begin{desc}
This procedure starts the server. The \var{options} argument
specifies various configuration parameters, explained below.
The server's basic loop is to wait on the port for a connection from
an HTTP client. When it receives a connection, it reads in and
parses the request into a special request data structure. Then the
server forks a thread which binds the current I/O ports to the
connection socket, and then hands off to the top-level
request handler (which must be specified in the options). The
request handler is responsible for actually serving
the request---it can be any arbitrary computation. Its output goes
directly back to the HTTP client that sent the request.
Before calling the request handler to service the request, the HTTP
server installs an error handler that fields any uncaught error,
sends an error reply to the client, and aborts the request
transaction. Hence any error caused by a request handler will be
handled in a reasonable and robust fashion.
\end{desc}
%
The \var{options} argument can be constructed through a number of procedures
with names of the form \texttt{with-\ldots}. Each of these procedures
either creates a fresh options value or adds a configuration parameter
to an old options argument. The configuration parameter value is
always the first argument, the (old) options value the optional second
one. Here they are:
\defun{with-port}{port [options]}{options}
\begin{desc}
This specifies the port on which the server listens. Defaults to 80.
\end{desc}
\defun{with-root-directory}{root-directory [options]}{options}
\begin{desc}
This specifies the current directory of the server. Note that this
is \emph{not} the document root directory. Defaults to \texttt{/}.
\end{desc}
\defun{with-fqdn}{fqdn [options]}{options}
\begin{desc}
This specifies the fully-qualified domain name the server uses in
automatically generated replies, or \ex{\#f} if the server should
query DNS for the fully-qualified domain name.. Defaults to \ex{\#f}.
\end{desc}
\defun{with-reported-port}{reported-port [options]}{options}
\begin{desc}
This specifies the port number the server uses in automatically
generated replies or \ex{\#f} if the reported port is the same as
the port the server is listening on. (This is useful if you're
running the server through an accelerating proxy.) Defaults to
\ex{\#f}.
\end{desc}
\defun{with-server-admin}{mail-address [options]}{options}
\begin{desc}
This specifies the email address of the server administrator the
server uses in automatically generated replies. Defaults to \ex{\#f}.
\end{desc}
\defun{with-request-handler}{request-handler [options]}{options}
\begin{desc}
This specifies the request handler of the server to which the server
delegates the actual work. More on that subject below in
Section~\ref{httpd:request-handlers}. This parameter must be specified.
\end{desc}
\defun{with-simultaneous-requests}{requests [options]}{options}
\begin{desc}
This specifies a limit on the number of simultaneous requests the
server servers. If that limit is exceeded during operation, the
server will hold off on new requests until the number of
simultaneous requests has sunk below the limit again. If this
parameter is \ex{\#f}, no limit is imposed. Defaults to \ex{\#f}.
\end{desc}
\defun{with-log-file}{log-file [options]}{options}
\begin{desc}
This specifies the name of a log file for the server where it writes
Common Log Format logging information. It can also be a port in
which case the information is logged to that port, or \ex{\#f} for
no logging. Defaults to \ex{\#f}.
To allow rotation of log files, the server re-opens the log file
whenever it receives a \texttt{USR1} signal.
\end{desc}
\defun{with-syslog?}{syslog? [options]}{options}
\begin{desc}
This specifies whether the server will log information about
incoming to the Unix syslog facility. Defaults to \ex{\#t}.
\end{desc}
\defun{with-resolve-ip?}{resolve-ip? [options]}{options}
\begin{desc}
This specifies whether the server writes the domain names rather
than numerical IPs to the output log it produces. Defaults to
\ex{\#t}.
\end{desc}
To avoid paranthitis, the \ex{make-httpd-options} procedure eases the
construction of the options argument:
\defun{make-httpd-options}{transformer value \ldots}{options}
\begin{desc}
This constructs an options value from an argument list of parameter
transformers and parameter values. The arguments come in pairs,
each an option transformer from the list above, and a value for that
parameter. \ex{Make-httpd-options} returns the resulting options value.
\end{desc}
For example,
\begin{alltt}
(httpd (make-httpd-options
with-request-handler (rooted-file-handler "/usr/local/etc/httpd")
with-root-directory "/usr/local/etc/httpd"))
\end{alltt}
%
starts the server on port 80 with
\ex{/usr/local/etc/httpd} as its root directory and
lets it serve any file out from this directory.
% #### note about rooted-file-handler
\section{Requests}
\label{httpd:requests}
Request handlers operate on \textit{requests} which contain the
information needed to generate a page. The relevant procedures to
dissect requests are defined in the \texttt{httpd-requests} structure:
\defun{request?}{value}{boolean}
\defunx{request-method}{request}{string}
\defunx{request-uri}{request}{string}
\defunx{request-url}{request}{url}
\defunx{request-version}{request}{pair}
\defunx{request-headers}{request}{list}
\defunx{request-socket}{request}{socket}
\begin{desc}
The procedure inspect request values. \ex{Request?} is a predicate
for requests. \ex{Request-method} extracts the method of the HTTP
request; it's a string such as \verb|"GET"|, \verb|"PUT"|.
\ex{Request-uri} returns the escaped URI string as read from request
line. \ex{Request-url} returns an HTTP URL value (see the
description of the \ex{url} structure in \ref{cha:url}).
\ex{Request-version} returns \verb|(major . minor)| integer pair
representing the version specified in the HTTP request.
\ex{Request-headers} returns an association lists of header field
names and their values, each represented by a list of strings, one
for each line. \ex{Request-socket} returns the the socket connected
to the client.\footnote{Request handlers should not perform I/O on the
request record's socket. Request handlers are frequently called
recursively, and doing I/O directly to the socket might bypass a
filtering or other processing step interposed on the current I/O ports
by some superior request handler.}
\end{desc}
\section{Responses}
\label{sec:http-responses}
A path handler must return a \textit{response} value representing the
content to be sent to the client. The machinery presented here for
constructing responses lives in the \ex{httpd-responses} structure.
\defun{make-response}{status-code maybe-message seconds mime extras
body}{response}
\begin{desc}
This procedure constructs a response value. \var{Status-code} is an
HTTP status code (more on that below). \var{Maybe-message} is a a
message elaborating on the circumstances of the status code; it can
also be \sharpf{} meaning that the server should send a default
message associated with the status code. \var{Seconds} natural
number indicating the time the content was created, typically the
value of \verb|(time)|. \var{Mime} is a string indicating the MIME
type of the response (such as \verb|"text/html"| or
\verb|"application/octet-stream"|). \var{Extras} is an association
list with extra headers to be added to the response; its elements
are pairs, each of which consists of a symbol representing the field
name and a string representing the field value. \var{Body}
represents the body of the response; more on that below.
\end{desc}
\defun{make-redirect-response}{location}{response}
\begin{desc}
This is a helper procedure for constructing HTTP redirections. The
server will serve the new file indicated by \var{location}.
\var{Location} must be URI-encoded and begin with a slash.
\end{desc}
\defun{make-error-response}{status-code request extra \ldots}{response}
\begin{desc}
This is a helper procedure for constructing error responses.
\ex{Make-error-response} returns a response value the body of which
is a web page explaining the error at hand.
\var{status-code} is the status code of the response (see below).
\var{request}
is the request that led to the error. \var{extra} are the further
arguments required for this specific \var{status-code} and
optionally further information-bits (preferably strings in HTML) to
be added to the web page that's generated.
\end{desc}
\begin{table}[htb]
\centering
\begin{tabular}{|l|l|l|}
\hline
continue & 100 & Continue\\\hline
switch-protocol & 101 & Switching Protocol\\\hline
ok & 200 & OK\\\hline
created & 201 & Created\\\hline
accepted & 202 & Accepted\\\hline
non-author-info & 203 & Non-Authoritative Information\\\hline
no-content & 204 & No Content\\\hline
reset-content & 205 & Reset Content\\\hline
partial-content & 206 & Partial Content\\\hline
mult-choice & 300 & Multiple Choices\\\hline
moved-perm & 301 & Moved Permanently\\\hline
found & 302 & Found\\\hline
see-other & 303 & See other\\\hline
not-mod & 304 & Not Modified\\\hline
use-proxy & 305 & Use Proxy\\\hline
temp-redirect & 307 & Temporary Redirect\\\hline
bad-request & 400 & Bad Request\\\hline
unauthorized & 401 & Unauthorized\\\hline
payment-req & 402 & Payment Required\\\hline
forbidden & 403 & Forbidden\\\hline
not-found & 404 & Not Found\\\hline
method-not-allowed & 405 & Method Not Allowed\\\hline
not-acceptable & 406 & Not Acceptable\\\hline
proxy-auth-required &407 & Proxy Authentication Required\\\hline
timeout & 408 & Request Timeout\\\hline
conflict & 409 & Conflict\\\hline
gone & 410 & Gone\\\hline
length-required & 411 & Length Required\\\hline
precon-failed & 412 & Precondition Failed\\\hline
req-ent-too-large & 413 & Request Entity Too Large\\\hline
req-uri-too-large & 414 & Request URI Too Large\\\hline
unsupp-media-type & 415 & Unsupported Media Type\\\hline
req-range-not-sat & 416 & Requested Range Not Satisfiable\\\hline
expectation-failed & 417 & Expectation Failed\\\hline
internal-error & 500 & Internal Server Error\\\hline
not-implemented & 501 & Not Implemented\\\hline
bad-gateway & 502 & Bad Gateway\\\hline
service-unavailable &503 & Service Unavailable\\\hline
gateway-timeout & 504 & Gateway Timeout\\\hline
version-not-supp & 505 & HTTP Version Not Supported\\\hline
\end{tabular}
\caption{HTTP status codes}
\label{tab:status-code-names}
\end{table}
\dfn{status-code}{\synvar{name}}{status-code}{syntax}
\defunx{name->status-code}{symbol}{status-code}
\defunx{status-code-number}{status-code}{integer}
\defunx{status-code-message}{status-code}{string}
\begin{desc}
The \ex{status-code} syntax returns a status code where
\synvar{name} is the name from Table~\ref{tab:status-code-names}.
\ex{Name->status-code} also returns a status code for a name
represented as a symbol. For a given status code,
\ex{status-code-number} extracts its number, and
\ex{status-code-message} extracts its associated default message.
\end{desc}
\section{Response Bodies}
\label{httpd:response-bodies}
A \textit{response body} represents the body of an HTTP response.
There are several types of response bodies, depending on the
requirements on content generation.
\defun{make-writer-body}{proc}{body}
\begin{desc}
This constructs a response body from a \textit{writer}---a procedure
that prints the page contents to a port. The \var{proc} argument
must be a procedure accepting an output port (to which \var{proc}
prints the body) and the options value passed to the \ex{httpd}
invocation.
\end{desc}
\defun{make-reader-writer-body}{proc}{body}
\begin{desc}
This constructs a response body from a \textit{reader/writer}---a
procedure that prints the page contents to a port, possibly after
reading input from the socket of the HTTP connection. The
\var{proc} argument must be a procedure accepting three arguments:
an input port (associated with the HTTP connection socket), an
output port (to which \var{proc} prints the body), and the options
value passed to the \ex{httpd} invocation.
\end{desc}
\section{Request Handlers}
\label{httpd:request-handlers}
A request handler generates the actual content for a request; request
handlers form a simple algebra and may be combined and composed in
various ways.
A request handler is a procedure of two arguments like this:
\defun{request-handler}{path req}{response}
\begin{desc}
\var{Req} is a request. The \semvar{path} argument is the URL's
path, parsed and split at slashes into a string list. For example,
if the Web client dereferences URL
%
\begin{verbatim}
http://clark.lcs.mit.edu:8001/h/shivers/code/web.tar.gz
\end{verbatim}
then the server would pass the following path to the top-level
handler:
%
\begin{verbatim}
("h" "shivers" "code" "web.tar.gz")
\end{verbatim}
%
The \var{path} argument's pre-parsed representation as a string
list makes it easy for the request handler to implement recursive
operations dispatch on URL paths.
The request handler must return an HTTP response.
\end{desc}
\subsection{Basic Request Handlers}
The web server comes with a useful toolbox of basic request handlers
that can be used and built upon. The following procedures are
exported by the \ex{httpd\=basic\=handlers} structure:
\defvar{null-request-handler}{request-handler}
\begin{desc}
This request handler always generates a \ex{not-found} error
response, no matter what the request is.
\end{desc}
\defun{make-predicate-handler}{predicate handler
default-handler}{request-handler}
\begin{desc}
The request handler returned by this procedure first calls
\var{predicate} on its path and request; it then acts like
\var{handler} if the predicate returned a true vale, and like
\var{default-handler} if the predicate returned \sharpf.
\end{desc}
\defun{make-host-name-handler}{hostname handler default-handler}{request-handler}
\begin{desc}
The request handler returned by this procedure compares the host
name specified in the request with \var{hostname}: if they match, it
acts like \var{handler}, otherwise, it acts like
\var{default-handler}.
\end{desc}
\defun{make-path-predicate-handler}{predicate handler
default-handler}{request-handler}
\begin{desc}
The request handler returned by this procedure first calls
\var{predicate} on its path; it then acts like \var{handler} if the
predicate returned a true vale, and like \var{default-handler} if
the predicate returned \sharpf.
\end{desc}
\defun{make-path-prefix-handler}{path-prefix handler default-handler}{request-handler}
\begin{desc}
This constructs a request handler that calls \var{handler} on its
argument if \var{path-prefix} (a string) is the first element of the
requested path; it calls \var{handler} on the rest of the path and
the original request. Otherwise, the handler acts like
\var{default-handler}.
\end{desc}
\defun{alist-path-dispatcher}{handler-alist default-handler}{request-handler}
\begin{desc}
This procedure takes as arguments an alist mapping strings to path
handlers, and a default request handler, and returns a handler that
dispatches on its path argument. When the new request handler is
applied to a path
\begin{verbatim}
("foo" "bar" "baz")
\end{verbatim}
it uses the
first element of the path---\ex{foo}---to index into the
alist. If it finds an associated request handler in the alist, it
hands the request off to that handler, passing it the tail of the
path, in this case
\begin{verbatim}
("bar" "baz")
\end{verbatim}
%
On the other hand, if the path is
empty, or the alist search does not yield a hit, we hand off to the
default path handler, passing it the entire original path,
\begin{verbatim}
("foo" "bar" "baz")
\end{verbatim}
%
This procedure is how you say: ``If the first element of the URL's
path is `foo', do X; if it's `bar', do Y; otherwise, do Z.''
The slash-delimited URI path structure implies an associated tree of
names. The request-handler system and the alist dispatcher allow you to
procedurally define the server's response to any arbitrary subtree
of the path space.
Example: A typical top-level request handler is
\begin{alltt}
(define ph
(alist-path-dispatcher
`(("h" . ,(home-dir-handler "public\_html"))
("cgi-bin" . ,(cgi-handler "/usr/local/etc/httpd/cgi-bin"))
("seval" . ,seval-handler))
(rooted-file-handler "/usr/local/etc/httpd/htdocs")))
\end{alltt}
This means:
\begin{itemize}
\item If the path looks like \ex{("h"\ob{} "shivers"\ob{}
"code"\ob{} "web.\ob{}tar.\ob{}gz")}, pass the path
\ex{("shivers"\ob{} "code"\ob{} "web.\ob{}tar.\ob{}gz")} to a
home-directory request handler.
\item If the path looks like \ex{("cgi-\ob{}bin"\ob{} "calendar")},
pass ("calendar") off to the CGI request handler.
\item If the path looks like \ex{("seval"\ob{} \ldots)}, the tail
of the path is passed off to the code-uploading \ex{seval} path
handler.
\item Otherwise, the whole path is passed to a rooted file handler,
who will convert it into a filename, rooted at
\ex{/usr/\ob{}lo\ob{}cal/\ob{}etc/\ob{}httpd/\ob{}htdocs},
and serve that file.
\end{itemize}
\end{desc}
\subsection{Static Content Request Handlers}
The request handlers described in this section are for serving static
content off directory trees in the file system. They live in the
\ex{httpd-file-directory-handlers} structure.
The request handlers in this section eventually call an internal
procedure named \ex{file\=serve} for serving files which implements a
simple directory-generation service using the following rules:
\begin{itemize}
\item If the filename has the form of a directory (i.e., it ends with
a slash), then \ex{file\=serve} actually looks for a file named
\ex{index.html} in that directory.
\item If the filename names a directory, but is not in directory form
(i.e., it doesn't end in a slash, as in
``\ex{/usr\ob{}in\ob{}clu\ob{}de}'' or ``\ex{/usr\ob{}raj}''),
then \ex{file\=serve} sends back a ``301 moved permanently''
message, redirecting the client to a slash-terminated version of the
original URL. For example, the URL
\ex{http://\ob{}clark.\ob{}lcs.\ob{}mit.\ob{}edu/\ob{}~shi\ob{}vers}
would be redirected to
\ex{http://\ob{}clark.\ob{}lcs.\ob{}mit.\ob{}edu/\ob{}~shi\ob{}vers/}
\item If the filename names a regular file, it is served to the
client.
\end{itemize}
%
The \ex{httpd-file-directory-handlers} all take an options value as an
argument, similar to the options for \ex{httpd} itself.
The \var{options} argument can be constructed through a number of procedures
with names of the form \texttt{with-\ldots}. Each of these procedures
either creates a fresh options value or adds a configuration parameter
to an old options argument. The configuration parameter value is
always the first argument, the (old) options value the optional second
one. Here they are:
\defun{with-file-name->content-type}{proc [options]}{options}
\begin{desc}
This specifies a procedure for determining the MIME content type
(``\ex{text/html},'' ``\ex{application/octet-stream}'' etc.)
from a file name. \var{Proc} takes a file name as an argument and
must return a string. (This is relevant in directory listings.) The default is a procedure able to handle the
more common file extensions.
\end{desc}
\defun{with-file-name->content-encoding}{proc [options]}{options}
\begin{desc}
This specifies a procedure for determining the MIME content encoding
(if the file is compressed, gzipped, etc.) from a file name.
(This is relevant in directory listings.)
\var{Proc} takes a file name as an argument and must return two
values: the equivalent, unencoded file name (i.e., without the
trailing \ex{.Z} or \ex{.gz}) and a string representing the content
encoding.
\end{desc}
\defun{with-file-name->icon-url}{proc [options]}{options}
\begin{desc}
This specifies a procedure for determining the icon to be displayed
next to a file name in a directory listing.
\var{Proc} takes a file name as an argument and must return a URL
for the corresponding icon or \sharpf.
\end{desc}
\defun{with-blank-icon-url}{file-name-or-\sharpf{} [options]}{options}
\begin{desc}
This specifies a file name (or its absence) for the special icon
that must be as wide as the icons returned by the previous procedure
but that is blank.
\end{desc}
\defun{with-back-icon-url}{file-name-or-\sharpf{} [options]}{options}
\begin{desc}
This specifies a file name (or its absence) for the special icon
that is displayed next to the ``parent directory'' link in directory
listings.
\end{desc}
\defun{with-unknown-icon-url}{file-name-or-\sharpf{}
[options]}{options}
\begin{desc}
This specifies a file name (or its absence) for the special icon
that is displayed next to the unknown entries in directory listings.
\end{desc}
The \ex{make-file-directory-options} procedure eases the construction
of the options argument:
\defun{make-file-directory-options}{transformer value \ldots}{options}
\begin{desc}
This constructs an options value from an argument list of parameter
transformers and parameter values. The arguments come in pairs,
each an option transformer from the list above, and a value for that
parameter. \ex{Make-file-directory-options} returns the resulting
options value.
\end{desc}
%
Here are procedure for constructing static content request handlers:
%
\defun{rooted-file-handler}{root [options]}{request-handler}
\begin{desc}
This returns a request handler that serves files from a particular
root in the file system. Only the \ex{GET} operation is provided.
The path argument passed to the handler is converted into a
filename, and appended to \var{root}. The file name is checked for
\ex{..} components, and the transaction is aborted if it does.
Otherwise, the file is served to the client.
\end{desc}
\defun{rooted-file-or-directory-handler}{root [options]}{request-handler}
\begin{desc}
Dito, but also serve directory indices for directories without
\ex{index.html}.
\end{desc}
\defun{home-dir-handler}{subdir [options]}{request-handler}
\begin{desc}
This procedure builds a request handler that does basic file serving
out of home directories. If the resulting \var{request-handler} is
passed a path of the form \ex{(\var{user} . \var{file-path})}, then it serves the file
\ex{\var{subdir}/\var{file-path}} inside the user's home directory.
The request handler only handles GET requests; the filename is not
allowed to contain \ex{..} elements.
\end{desc}
\defun{tilde-home-dir-handler}{subdir default-request-handler [options]}{request-handler}
\begin{desc}
This returns request handler that examines the car of the path. If
it is a string beginning with a tilde, e.g., \ex{"~ziggy"}, then the
string is taken to mean a home directory, and the request is served
similarly to a home-dir-handler request handler. Otherwise, the
request is passed off in its entirety to the
\var{default-request-handler}.
\end{desc}
\section{CGI Server}
The procedure(s) described here live in the \ex{httpd-cgi-handlers}
structure.
\defun{cgi-handler}{bin-dir [cgi-bin-path]}{request-handler}
\begin{desc}
Returns a request handler for CGI scripts located in
\var{bin-dir}. \var{Cgi-bin-dir} specifies the value of the
\ex{PATH} variable of the environment the CGI scripts run in. It defaults
to
\begin{verbatim}
/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin
\end{verbatim}
The CGI scripts are called as specified by CGI/1.1\footnote{see
\url{http://hoohoo.ncsa.uiuc.edu/cgi/interface.html} for a sort of
specification.}.
Note that the CGI handler looks at the name of the CGI script to
determine how it should be handled:
\begin{itemize}
\item If the name of the script starts with `\ex{nph-}', its reply
is read, the RFC~822-fields like \ex{Content-Type} and \ex{Status}
are parsed and the client is sent back a real HTTP reply,
containing the rest of the script's output.
\item If the name of the script doesn't start with `\ex{nph-}',
its output is sent back to the client directly. If its return code
is not zero, an error message is generated.
\end{itemize}
\end{desc}
\section{Scheme-Evaluating Request Handlers}
The \ex{httpd-seval-handlers} structure contains a handler which
demonstrates how to safely evaluate Scheme code uploaded from the
client to the server.
\defvar{seval-handler}{request-handler}
\begin{desc}
This request handler is suitable for receiving code entered into an
HTML text form. The Scheme code being uploaded is being \ex{POST}ed
to the server (from a form). The code should be URI-encoded in the
URL as \texttt{program=}$\left<\mathrm{stuff}\right>$.
$\mathrm{stuff}$ must be an (URI-encoded) Scheme expression which
the handler evaluates in a separate subprocess. (It waits for 10
seconds for a result, then kills the subprocess.) The handler then
prints the return values of the Scheme code.
\end{desc}
The following structures define environments that are \RnRS without
features that could examine or effect the file system. You can also
use them as models of how to execute code in other protected
environments in \scm.
\subsection{The \protect{\texttt{loser}} structure}
The \ex{loser} package exports only one procedure:
\begin{defundesc}{loser}{name}{nothing}
Raises an error like ``Illegal call \var{name}''.
\end{defundesc}
\subsection{The \protect{\texttt{toothless}} structure}
The \ex{toothless} structure contains everything of \RnRS except
that following procedure cause an error if called:
\begin{itemize}
\item \ex{call-with-input-file}
\item \ex{call-with-output-file}
\item \ex{load}
\item \ex{open-input-file}
\item \ex{open-output-file}
\item \ex{transcript-on}
\item \ex{with-input-from-file}
\item \ex{with-input-to-file}
\item \ex{eval}
\item \ex{interaction-environment}
\item \ex{scheme-report-environment}
\end{itemize}
\subsection{The \protect{\texttt{toothless-eval}} structure}
\begin{defundesc}{eval-safely} {expression} {any result}
Creates a brand-new structure, imports the \ex{toothless} structure,
and evaluates \semvar{expression} in it. When the evaluation is
done, the environment is thrown away, so \semvar{expression}'s
side-effects don't persist from one \ex{eval\=safely} call to the
next. If \semvar{expression} raises an error exception,
\ex{eval-safely} returns \sharpf.
\end{defundesc}
\section{Writing Request Handlers}
\subsection{Parsing HTML Forms}
In HTML forms, field data are turned into a single string, of the form
\texttt{\synvar{name}=\synvar{val}\&\synvar{name}=\synvar{val}\ldots}.
The \ex{parse-html-forms} structure provides simple functionality to
parse these strings.
\defun{parse-html-form-query}{string}{alist}
\begin{desc}
This parses \verb|"foo=x&bar=y"| into \verb|(("foo" . "x") ("bar" .
"y"))|. Substrings are plus-decoded (i.-e.\ plus characters are
turned into spaces) and then URI-decoded.
This implementation is
slightly sleazy as it will successfully parse a string like
\verb|"a&b=c&d=f"| into \verb|(("a&b" . "c") ("d" . "f"))| without
a complaint.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+112
View File
@@ -0,0 +1,112 @@
\chapter*{}
\thispagestyle{empty}
Of course, there is no Underground---or Untergrund, as those German
new-age kids like to call the movement whose orders they
have sworn to follow. The age we all remember---the cliff-green
turbocharged convertibles, cigarettes hanging loose in the corners of
our mouths, and those trigger-happy fingers always ready for the quick
hack---is long gone.
In retrospect, it all seems like a candy-colored dream, and it may
very well be---after all, there was never any proof that the
Untergrund ever existed, and even if it did, we can be sure the
obedient followers of the shadowy movement leaders have long burned
the papers, subjected the hard drives and diskettes to interminable
sessions of the junkyard magnet, and eradicated all shreds of
memory from the brains of those who might have talked through long
sessions of Tcl hacking to the sounds of Celine Dion records.
Yet there are those who still covet membership in that secret
cult---to gain access to its powerful lore, to usurp invidious and
powerful superiors, or simply to impress their girlfriends. For those
lost souls of the modern age, I have a few words of advice:
It's not a question of ``membership''---silly merchandise and
ridiculous certificates. If you are truly meant to be part of the
Untergrund, you will know. \emph{The Untergrund will find you.}
Alas, probably not.
\medskip
\hfill April, 2003
\chapter{Overview}\label{sec:intro}
The Scheme Untergrund Networking Package (\textit{SUnet}, for short)
is a collection of applications and libraries for Internet hacking in
Scheme. It runs under Scsh, the Scheme shell. SUnet includes the
following components:
%
\begin{description}
\item[The SUnet Web server]
This is a highly configurable HTTP 1.0 server in Scheme.
The server is accompanied by some libraries which may also
be used separately:
\begin{itemize}
\item URI and URL parsers and unparsers
\item a library for writing CGI scripts in Scheme
\item server extensions for interfacing to CGI scripts
\item server extensions for uploading Scheme code
\item simple structured HTML output library
\end{itemize}
The server also ships with a sophisticated interface for writing
server-side Web applications called "SUrflets".
\item[The SUnet ftp server]
This is a complete anonymous ftp server in Scheme.
\item[ftp client library] This library allows you to access ftp
servers programmatically.
\item[netrc library] This library parses authentication information
contained in \verb|~/.netrc|.
\item[SMTP client library] This library allows you to forge mail from
the comfort of your own Scheme process.
\item[POP3 client library]
This library allows you to access your POP3 mailbox from inside scsh.
\item[RFC822 header library] This library parses email-style headers.
\item[Daytime and Time protocol client libraries]
These libraries lets you find out what time it is without paying for a
Rolex.
\item[DNS client library] This is a complete, multithreaded DNS
library.
\item[An \texttt{ls} clone] This library displays Unix-style directory
listings without running \texttt{ls}.
\end{description}
\section{Obtaining the system}
The SUnet code is available
\urlhd{http://www.scsh.net/resources/sunet.html}{here}{from
\url{http://www.scsh.net/resources/sunet.html}}. To run the code, you need
version 0.6.4 or later of \urlhd{http://www.scsh.net/}{scsh}{scsh from
\url{http://www.scsh.net/}}.
\section{How to use the packages}
Untar the SUnet distribution somewhere. Fire up scsh and load the
SUnet \texttt{packages.scm} file into the configuration package.
After that, all structures defined by SUnet are available:
%
\begin{alltt}
atari-2600[72] scsh
Welcome to scsh 0.6.4 (...)
Type ,? for help.
> ,config ,load packages.scm
modules.scm
> ,open ftp
Load structure ftp (y/n)? y
[netrc netrc.scm]
[ftp ftp.scm]
> \textit{call library code}
> ,exit
atari-2600[73]
\end{alltt}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+1
View File
@@ -0,0 +1 @@
../html
+133
View File
@@ -0,0 +1,133 @@
% man.t2p
% Dorai Sitaram
% Feb 6, 2000
% This file contains the tex2page macros needed to process
% the scsh LaTeX document scsh-n.n.n/doc/scsh-manual/man.tex.
% Copy (or link) this file alongside man.tex and run
%
% tex2page man
\input css.t2p
\htmlmathstyle{no-image}
\let\pagebreak\relax
\let\small\relax
%\let\PRIMtableofcontents\tableofcontents
%\def\tableofcontents{\chapter*{Contents}\PRIMtableofcontents}
\def\subtitle#1{\def\savesubtitle{#1}}
\def\maketitle{
\subject{\TIIPtitle}
{\bf \hr}
\rightline{\savesubtitle}
\bigskip\bigskip
\bigskip\bigskip
{\bf\TIIPauthor}
{\bf\hr}
}
\let\PRIMdocument\document
\def\document{\PRIMdocument
\let\ttchars\relax
\let\ttt\tt
%\def\~{\rawhtml~\endrawhtml}
\def\~{\char`\~}
\def\cd#1{{\tt\def\\{\char`\\}\defcsactive\${\char`\$}\defcsactive\~{\char`\~}\defcsactive\&{\char`\&}#1}}
\def\cddollar{\undefcsactive\$}
\def\cdmath{\undefcsactive\$}
\def\codeallowbreaks{\relax}
\def\defvarx#1#2{\index{#1}\leftline{{\tt #1} \qquad #2}}
\let\PRIMflushright\flushright
\def\flushright{\PRIMflushright\TIIPtabularborder=0 }
\let\PRIMfigure\figure
\let\PRIMendfigure\endfigure
\def\figure{\par\hrule\PRIMfigure}
\def\endfigure{\PRIMendfigure\hrule\par}
\let\PRIMtable\table
\let\PRIMendtable\endtable
\def\table{\par\hrule\PRIMtable}
\def\endtable{\PRIMendtable\hrule\par}
\imgdef\vdots{\bf.\par.\par.}
%\evalh{
%
%(define all-blanks?
% (lambda (s)
% (andmap
% char-whitespace?
% (string->list s))))
%
%}
%
%
%\def\spaceifnotempty{\evalh{
%
%(let ((x (ungroup (get-token))))
% (unless (all-blanks? x)
% (emit #\space)))
%
%}}
\def\spaceifnotempty#1{%
\def\TEMP{#1}%
\ifx\TEMP\empty\else\ \fi}
\def\dfnix#1#2#3#4{\leftline{{\tt(#1\spaceifnotempty{#2}{\it#2})} \quad $\longrightarrow$ \quad {\it #3} \qquad (#4)} \index}
%\def\ex#1{{\tt #1}}
%\let\ex\texttt
\def\l#1{lambda (#1)}
\def\lx#1{lambda {#1}}
%\def\notenum#1{}
%\def\project#1{}
%\def\var#1{{\it #1\/}}
%\let\var\textit
%\def\vari#1#2{\mbox{{\it #1\/}\undefcsactive\$$_{#2}$}}
%\def\vari#1#2{\textit{#1}$_{#2}$}
\renewenvironment{boxedfigure}{\def\srecomment#1{\\#1\\}%
\begin{figure}\pagestyle}{\end{figure}}
\newenvironment{centercode}{\begin{code}}{\end{code}}
\def\setupcode{\tt%
\def\\{\char`\\}%
\defcsactive\${\$}%
\def\evalto{==> }%
\defcsactive\%{\%}\obeywhitespace}
\newenvironment{code}{\begin{quote}\setupcode\GOBBLEOPTARG}
{\end{quote}}
\newenvironment{codebox}{\begin{tableplain}\bgroup\setupcode\GOBBLEOPTARG}
{\egroup\end{tableplain}}
\renewenvironment{desc}{\begin{quote}}{\end{quote}}
\renewenvironment{exampletable}{%
\def\header#1{\\\leftline{#1}\\}%
\def\splitline#1#2{\\\leftline{#1}\\\leftline{#2}}%
\begin{tabular}{}}{\end{tabular}}
\newenvironment{tightcode}{\begin{code}}{\end{code}}
\renewenvironment{widecode}{\begin{code}}{\end{code}}
\renewenvironment{inset}{\begin{quote}}{\end{quote}}
\renewenvironment{leftinset}{\begin{quote}}{\end{quote}}
\renewenvironment{tightinset}{\begin{quote}}{\end{quote}}
\renewenvironment{tightleftinset}{\begin{quote}}{\end{quote}}
}
+79
View File
@@ -0,0 +1,79 @@
% -*- latex -*-
% This is the reference manual for the Scheme Untergrund Networking Package.
\documentclass[twoside]{report}
\usepackage{code,boxedminipage,makeidx,palatino,ct,
headings,mantitle,array,matter,mysize10,tex2page}
\usepackage[latin1]{inputenc}
\usepackage{alltt}
\usepackage{xspace}
\usepackage{tabularx,theorem,ulem,float,afterpage} % need url
\normalem % usually, don't use ulem
\texonly
% tex2page defines \url and hyperref loads the package url
% but setting \url to \relax satisfies \newcommand
\let\url\relax
\input{pdfcond}
\ifpdf
\usepackage[pdftex,hyperindex,
pdftitle={sunet manual, release 2.1},
pdfauthor={Olin Shivers, Mike Sperber, Martin Gasbichler, Eric Marsden
and Andreas Bernauer}
colorlinks=true,linkcolor=blue,pagecolor=blue,urlcolor=blue,
pdfstartview=FitH,pdfview=FitH]{hyperref}
\usepackage{thumbpdf}
\usepackage{tocbibind}
\else
\usepackage[dvipdfm,hyperindex,hypertex,
pdftitle={sunet manual, release 2.1},
pdfauthor={Olin Shivers, Mike Sperber, Martin Gasbichler, Eric Marsden
and Andreas Bernauer}
colorlinks=true,linkcolor=blue,pagecolor=blue,urlcolor=blue,
pdfstartview=FitH,pdfview=FitH]{hyperref}
\fi
\endtexonly
% Style issues
\parskip = 3pt plus 3pt
\sloppy
\input{decls}
\makeindex
%%% End preamble
\begin{document}
\frontmatter
\title{SUnet Reference Manual}
\subtitle{For SUnet release 2.1}
\author{Dr. S\raisebox{1ex}{2}, Martin Gasbichler, Eric Marsden, Andreas Bernauer}
\date{April 2004}
\mainmatter
\maketitle
\tableofcontents
\include{intro}
\include{httpd}
\include{uri}
\include{url}
\include{cgi-script}
\include{surflets}
\include{ftpd}
\include{ftp}
\include{netrc}
\include{rfc822}
\include{nettime}
\include{smtp}
\include{pop3}
\include{dns}
\backmatter
\printindex
\end{document}
+76
View File
@@ -0,0 +1,76 @@
% This is the title page style stolen from the Texinfo design,
% and expressed as a LaTeX style option. It is useful for manuals.
%
% Note that I play some *really* revolting games here to override
% the vertical and horizontal margins temporarily for the title page.
% The layout assumes you have 8.5" x 11" paper. You'd have to redo this
% for A4 or another size.
% -Olin 7/94
% Fonts for title page:
\DeclareFixedFont{\titlefont}%
{\encodingdefault}{\familydefault}{bx}{\shapedefault}{20.5pt}
\DeclareFixedFont{\authorfnt}%
{\encodingdefault}{\familydefault}{bx}{\shapedefault}{14.4pt}
\DeclareFixedFont{\subtitlefnt}%
{\encodingdefault}{\familydefault}{m}{\shapedefault}{11}
%\def\authorrm{\normalfont\selectfont\fontseries{bx}\fontsize{14.4}{14.4}}
%\def\subtitlefnt{\normalfont\selectfont\fontsize{11}{11}}
\newskip\titlepagetopglue \titlepagetopglue = 2.5in
\newlength{\widewidth}
\setlength{\widewidth}{6.5in}
\newlength{\negwidemargin}
\setlength{\negwidemargin}{-\oddsidemargin} % Reset the margin
\addtolength{\negwidemargin}{-1in} % to edge of page
\addtolength{\negwidemargin}{1in} % Then move right one inch.
%\def\wideline#1{\hbox to 0pt{\hspace\negwidemargin\hbox to\widewidth{#1}}}
\def\wideline#1{\hbox{\makebox[0pt][l]{\hspace\negwidemargin\hbox to\widewidth{#1}}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\maketitle{\begin{titlepage}
\thispagestyle{empty}
\let\footnotesize\small \let\footnoterule\relax
\null
\parindent=0pt
\def\subtitlefont{\normalbaselineskip = 13pt \normalbaselines \subtitlefnt}%
\def\authorfont{\normalbaselineskip = 16pt \normalbaselines \authorfnt}%
%
% Leave some space at the very top of the page.
\vspace*{-1in}\vspace*{-\topmargin}\vspace*{-\headheight}\vspace*{-\headsep}
\vglue\titlepagetopglue
%
\wideline{\titlefont \@title \hfill} % title
% \vskip4pt
\vskip -0.3\baselineskip
\wideline{\leaders\hrule height 4pt\hfill}
\wideline{\hfill\subtitlefont\begin{tabular}[t]{@{}r@{}}\@subtitle%
\\\@date%
\end{tabular}} % subtitle
%
% author
\vskip 0pt plus 1filll
\wideline{\authorfont \begin{tabular}[t]{@{}c@{}}\@author
\end{tabular}\hfill}
%
% \vskip4pt
\vskip -0.3\baselineskip
\wideline{\leaders\hrule height 2pt\hfill}
% This weirdness puts the bottom line 2.75 in from the bottom of
% an 11in page.
\vskip \textheight \vskip \headsep \vskip \headheight
\vskip \topmargin \vskip 1in \vskip -11in \vskip 2.75in
\gdef\@author{}\gdef\@title{}\gdef\@subtitle{}\let\maketitle\relax
\end{titlepage}
\setcounter{page}{2}
}
\def\subtitle#1{\gdef\@subtitle{#1}}
\def\@subtitle{}
+16
View File
@@ -0,0 +1,16 @@
%&latex -*- latex -*-
% Implement the \frontmatter, \mainmatter, and \backmatter macros,
% so I can use them in reports, not just books.
\newif\if@mainmatter \@mainmattertrue
\newcommand\frontmatter{%
\cleardoublepage\@mainmatterfalse\pagenumbering{roman}}
\newcommand\mainmatter{%
\cleardoublepage\@mainmattertrue%
\pagenumbering{arabic}\setcounter{page}{1}}
\newcommand\backmatter{%
\if@openright\cleardoublepage\else\clearpage\fi%
\@mainmatterfalse}
+22
View File
@@ -0,0 +1,22 @@
%&latex -*- latex -*-
\if@twoside
\oddsidemargin 44pt
\evensidemargin 82pt
\marginparwidth 107pt
\else
\oddsidemargin 63pt
\evensidemargin 63pt
\marginparwidth 90pt
\fi
\marginparsep 11pt
\topmargin 27pt
\headheight 12pt
\headsep 25pt
\topskip = 10pt
\footskip 30pt
\textheight = 43\baselineskip
\advance\textheight by \topskip
\textwidth 345pt
\endinput
+61
View File
@@ -0,0 +1,61 @@
\chapter{Parsing Netrc Files}\label{cha:netrc}
%
The \ex{netrc} structures provides procedures to parse authentication
information contained in \ex{~/.netrc}.
On Unix systems the netrc file may contain information allowing
automatic login to remote hosts. The format of the file is defined in
the \ex{ftp(1)} manual page. Example lines are
%
\begin{verbatim}
machine ondine.cict.fr login marsden password secret
default login anonymous password user@site
\end{verbatim}
%
The netrc file should be protected by appropriate permissions, and
(like \ex{/usr/bin/ftp}) this library will refuse to read the file if it is
badly protected. (unlike \ex{ftp} this library will always refuse
to read the file----\ex{ftp} refuses it only if the password is
given for a non-default account). Appropriate permissions are set if
only the user has permissions on the file.
\defun{netrc-machine-entry}{host accept-default? [file-name]}{netrc-entry-or-\sharpf}
\begin{desc}
This procedure looks for the entry related to given host in the
user's netrc file. The host is specified in \var{host}.
\var{Accept-default?} specifies whether \ex{netrc-machine-entry}
should fall back to the default entry if there is no macht for
\var{host} in the netrc file. If specified, \var{file-name}
specifies an alternate file name for the netrc data. It defaults to
\ex{.netrc} in the current user's home directory.
\ex{Netrc-machine-entry} returns a netrc entry (see below) if it was
able to find the requested information; if not, it returns \sharpf.
If the netrc file had inappropriate permissions, \ex{netrc-machine-entry}
raises an error.
\end{desc}
\defun{netrc-entry?}{thing}{boolean}
\defunx{netrc-entry-machine}{netrc-entry}{string}
\defunx{netrc-entry-login}{netrc-entry}{string-or-\sharpf}
\defunx{netrc-entry-password}{netrc-entry}{string-or-\sharpf}
\defunx{netrc-entry-account}{netrc-entry}{string-or-\sharpf}
\begin{desc}
\ex{Netrc-entry?} is the predicate for netrc entries. The other
procedures are selectors for netrc entries as returned by
\ex{netrc-machine-entry}. They return \sharpf{} if the netrc file
didn't contain a binding for the corresponding field.
\end{desc}
\defun{netrc-macro-definitions}{[file-name]}{alist}
\begin{desc}
This returns the macro definitions from the netrc files, represented
as an alist mapping macro names---represented as strings---to
definitions---represented as lists of strings.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+57
View File
@@ -0,0 +1,57 @@
\chapter{Time and Daytime}\label{cha:ntp}
Many Unix hosts provide a RFC~867 Daytime service which sends the
current date and time as a human-readable character string. The
daytime service is typically served on port 13 as both TCP and UDP.
The RFC~868 Time protocol provides a site-independent, machine
readable date and time. The Time service is typically served
on port 37 as TCP and UDP. The idea is that you can confirm your
system's idea of the time by polling several independent sites on the
network.
\section{Daytime}
The \ex{rfc867} structure contains an interface to Daytime protocol.
\defun{rfc867-daytime/tcp}{host}{string}
\defunx{rfc867-daytime/udp}{host [timeout-or-\sharpf]}{string-or-\sharpf}
\begin{desc}
These procedures asks \var{host} about the current daytime and
return the host's answer (e.g., ``Thursday, April 4,
2'').
\ex{Rfc867-daytime/tcp} uses the TCP variant of the protocol.
\ex{Rfc867-daytime/udp} uses UDP and sends a single request to the
server. It allows the specification of an optional timeout; if not
specified or \sharpf{}, \ex{Rfc867-daytime/udp} will wait
indefinitely for an answer. If the answer from the server doesn't
arrive within the specified time, \ex{rfc867-daytime/udp} returns
\sharpf.
\end{desc}
\section{Time}
The \ex{rfc868} structure contains an interface to the Time protocol.
\defun{rfc868-time/tcp}{host}{string}
\defunx{rfc868-time/udp}{host [timeout-or-\sharpf]}{string-or-\sharpf}
\begin{desc}
These procedures asks \var{host} about the current time and return
the host's answer. This is the number of second since 1970, just as
with scsh's \texttt{time} procedure.
\ex{rfc868-time/tcp} uses the TCP variant of the protocol.
\ex{rfc868-time/udp} uses UDP and sends a single request to the
server. It allows the specification of an optional timeout; if not
specified or \sharpf{}, \ex{rfc868-time/udp} will wait
indefinitely for an answer. If the answer from the server doesn't
arrive within the specified time, \ex{rfc868-time/udp} returns
\sharpf.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+14
View File
@@ -0,0 +1,14 @@
\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse % we are not running PDFLaTeX
\else
\pdfoutput=1 % we are running PDFLaTeX
\pdftrue
\fi
% Then use your new variable \ifpdf
% \ifpdf
% \usepackage[pdftex]{graphicx}
% \pdfcompresslevel=9
% \else
% \usepackage{graphicx}
% \fi
+99
View File
@@ -0,0 +1,99 @@
\chapter{POP3 Client}\label{cha:pop3}
%
The \ex{pop3} structure provides a client for the POP3 protocol that
allows access to email on a maildrop server. It is often used in
configurations where users connect from a client machine which doesn't
have a permanent network connection or isn't always turned on,
situations which make local SMTP delivery impossible. It is the most
common form of email access provided by ISPs.
Two types of authentication are commonly used. The first, most basic
type involves sending a user's password in clear over the network, and
should be avoided. (Unfortunately, many POP3 clients only implement this
basic authentication.) The digest authentication system involves the
server sending the client a ``challenge'' token; the client encodes
this token with the pass phrase and sends the coded information to the
server. This method avoids sending sensitive information over the
network. Both methods are implemented by \ex{pop3}.
Once connected, a client may request information about the number and
size of the messages waiting on the server, download selected messages
(either their headers or the entire content), and delete selected
messages.
The procedures defined here raise an error detectable via
\ex{pop3-error?} upon protocol errors with the POP3 server.
\defun{pop3-connect}{[host-or-\sharpf] [login-or-\sharpf]
[password-or-\sharpf] [log-port]}{connection}
\begin{desc}
This procedure connects to the maildrop server named \var{host},
and logs in using the provided login name and password. Any of
these can be omitted or \sharpf, in which case the procedure uses
defaults: \ex{MAILHOST} for the host, and \ex{~/.netrc}-provided
values for login and password. If \var{log-port} is provided, the
conversation to the server is logged to the specified output port.
\ex{Pop3-connect} returns a value representing the connection to the
POP3 server, to be used in the procedures below.
\end{desc}
\defun{pop3-stat}{connection}{number bytes}
\begin{desc}
This returns the number of messages and the number of bytes waiting in the
maildrop.
\end{desc}
Most of the following procedures accept a \var{msgid} argument which
specifies a message number, which ranges from 1 for the first message
to the number returned by \ex{pop3-stat}.
\defun{pop3-retrieve-message}{connection msgid}{headers message}
\begin{desc}
This downloads message number \var{msgid} from the mailhost.
It returns the headers as an alist of field names and bodies; the
names are symbols, the bodies are strings. (These are obtained
using the \ex{rfc822} structure, see Section~\ref{cha:rfc822}.)
The message is returned as a list of strings, each string
representing a line of the message.
\end{desc}
\defun{pop3-retrieve-headers}{connection msgid}{headers}
\begin{desc}
This downloads the headers of message number \var{msgid}. It
returns the headers in the same format as \ex{pop3-retrieve-message}.
\end{desc}
\defun{pop3-last}{connection}{msgid}
\begin{desc}
This returns the highest accessed message-id number for the current
session. (This isn't in the RFC, but seems to be supported by several
servers.)
\end{desc}
\defun{pop3-delete}{connection msgid}{undefined}
\begin{desc}
This mark message number \var{msgid} for deletion. The message will
not be deleted until the client logs out.
\end{desc}
\defun{pop3-reset}{connection}{undefined}
\begin{desc}
This marks any messages which have been marked for deletion.
\end{desc}
\defun{pop3-quit}{connection}{undefined}
\begin{desc}
This closes the connection with the mailhost.
\end{desc}
\defun{pop3-error?}{thing}{boolean}
\begin{desc}
This returns \sharpt{} if \var{thing} is a \ex{pop3-error} object,
otherwise \sharpf.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+107
View File
@@ -0,0 +1,107 @@
\chapter{RFC~822 Library}\label{cha:rfc822}
%
The \ex{rfc822} structure provides rudimentary support for parsing
headers according to RFC~822 \textit{Standard for the format of ARPA
Internet text messages}. These headers show up in SMTP messages,
HTTP headers, etc.
An RFC~822 header field consists of a \textit{field name} and a
\textit{field body}, like so:
%
\begin{verbatim}
Subject: RFC 822 can format itself in the ARPA
\end{verbatim}
%
Here, the field name is `\ex{Subject}', and the field name is `\ex{
RFC 822 can format itself in the ARPA}' (note the leading space).
The field body can be spread over several lines:
%
\begin{verbatim}
Subject: RFC 822 can format itself
in the ARPA
\end{verbatim}
%
In this case, RFC~822 specifies that the meaning of the field body is
actually all the lines of the body concatenated, without the
intervening line breaks.
The \ex{rfc822} structure provides two sets of parsing
procedures---one represents field bodies in the RFC-822-specified
meaning, as a single string, the other (with \ex{-with-line-breaks}
appended to the names) reflects the line breaks and represents the
bodies as a list of string, one for each line. The latter set only
marginally useful---mainly for code that needs to output headers in
the same form as they were originally provided.
\defun{read-rfc822-field}{[port] [read-line]}{name body}
\defun{read-rfc822-field-with-line-breaks}{[port] [read-line]}{name body-lines}
\begin{desc}
Read one field from the port, and return two values:
%
\begin{description}
\item[\var{name}] This is a symbol describing the field
name, such as \ex{subject} or \ex{to}. The symbol consists of all
lower-case letters.\footnote{In fact, it \ex{read-rfc822-field}
uses the preferred case for symbols of the underlying Scheme
implementation which, in the case of scsh, happens to be lower-case.}
\item[\var{body} or \var{body-lines}] This is the field body.
\var{Body} is a single string, \var{body-lines} is a list of
strings, one for each line of the body. In each case,
the terminating \ex{cr}/\ex{lf}'s (but nothing else) are
trimmed from each string.
\end{description}
%
When there are no more fields---EOF or a blank line has terminated
the header section---then both procedures returns [\sharpf\
\sharpf].
\var{Port} is an optional input port to read from---it defaults to
the value of \ex{(current-input-port)}.
\var{Read-line} is an optional parameter specifying a procedure of
one argument (the input port) used to read the raw header lines.
The default used by these procedures terminates lines with
either \ex{cr}/\ex{lf} or just \ex{lf}, and it trims the terminator
from the line. This procedure should trim the terminator of the
line, so an empty line is returned as an empty string.
The procedure raises an error if the syntax of the read field (the
line returned by the read-line-function) is illegal according to
RFC~822.
\end{desc}
\defun{read-rfc822-headers} {[port] [read-line]} {alist}
\defunx{read-rfc822-headers-with-line-breaks} {[port] [read-line]} {alist}
\begin{desc}
This procedure reads in and parses a section of text that looks like
the header portion of an RFC~822 message. It returns an association
list mapping field names (a symbol such as \ex{date} or \ex{subject}) to
field bodies. The representation of the field bodies is as with
\ex{read-rfc822-field} and \ex{read-rfc822-field-with-line-breaks}.
These procedures preserve the order of the header fields. Note that
several header fields might share the same field name---in that
case, the returned alist will contain several entries with the same
\ex{car}.
\var{Port} and \var{read-line} are as with \ex{read-rfc822-field}
and \ex{read-rfc822-field-with-line-breaks}.
\end{desc}
\defun{rfc822-time->string}{time}{string}
\begin{desc}
This formats a time value (as returned by scsh's \ex{time})
according to the requirements of the RFC~822 \ex{Date} header
field. The format looks like this:
%
\begin{verbatim}
Sun, 06 Nov 1994 08:49:37 GMT
\end{verbatim}
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+8
View File
@@ -0,0 +1,8 @@
\section{Section-Title}
%
\begin{description}
\item[Used files:]
\item[Name of the package:]
\end{description}
%
Not implemented yet.
+123
View File
@@ -0,0 +1,123 @@
\chapter{SMTP Client}\label{cha:smtp}
%
The \ex{smtp} structure provides an client library for the Simple Mail
Transfer Protocol, commonly used for sending email on the Internet.
This library provides a simple wrapper for sending complete emails as
well as procedures for composing custom SMTP transactions.
Some of the procedures described here return an SMTP reply code. For
details, see RFC~821.
\defun{smtp-send-mail}{from to-list headers body [host]}{undefined}
\defunx{smtp-error?}{thing}{boolean}
\defunx{smtp-recipients-rejected-error?}{thing}{boolean}
\begin{desc}
This emails message \var{body} with headers \var{headers} to
recipients in list \var{to-list}, using a sender address \var{from}.
The email is handed off to the SMTP server running on \var{host};
default is the local host. \var{Body} is either a list of strings
representing the lines of the message body or an input port which is
exhausted to determine the message body. \var{Headers} is an
association lists, mapping symbols representing RFC~822 field names
to strings representing field bodies.
If some transaction-related error happens, \ex{smtp-send-mail}
signals an \ex{smtp-error} condition with predicate
\ex{smtp-error?}. More specifically, it raises an
\ex{smtp-recipients-rejected-error} (a subtype of \ex{smtp-error})
if some recipients were rejected. For \ex{smtp-error}, the
arguments to the \ex{signal} call are the error code and the error
message, represented as a list of lines. For
\ex{smtp-recipients-rejected-error}, the arguments are reply code
700 and an association list whose elements are of the form
\ex{(\var{loser-recipient} \var{code} . \var{text})}---that is, for
each recipient refused by the server, you get the error data sent
back for that guy. The success check is \ex{(< code 400)}.
\end{desc}
\defun{smtp-expand}{name host}{code text}
\defunx{smtp-verify}{name host}{code text}
\defunx{smtp-get-help}{host [details]}{code text-list}
\begin{desc}
These three are simple queries of the server as stated in the
RFC~821: \ex{smtp-expann} asks the server to confirm that the
argument identifies a mailing list, and if so, to return the
membership of that list. The full name of the users (if known) and
the fully specified mailboxes are returned in a multiline reply.
\ex{Smtp-verify} asks the receiver to confirm that the argument
identifies a user. If it is a user name, the full name of the user
(if known) and the fully specified mailbox are returned.
\ex{Smtp-get-help} causes the server to send helpful information.
The command may take an argument (\var{details}) (e.g., any command
name) and return more specific information as a response.
\end{desc}
\defun{smtp-connect}{host [port]}{smtp-connection}
\begin{desc}
\ex{Smtp-connect} returns an SMTP connection value that represents
a connection to the SMTP server.
\end{desc}
\defun{smtp-transactions}{smtp-connection transaction1 ...}{code text-list}
\defunx{smtp-transactions/no-close}{smtp-connection transaction1 ...}{code text-list}
\begin{desc}
These procedures make it easy to do simple sequences of SMTP
commands. \var{Smtp-connection} must be an SMTP connection as
returned by \ex{smtp-connect}. The \var{transaction} arguments must
be transactions as returned by the procedures below.
\ex{Smtp-transactions} and \ex{smtp-transactions/no-close} execute
the transactions specified by the arguments.
For each transaction,
\begin{itemize}
\item If the transaction's reply code is 221 or 421 (meaning the socket has
been closed), then the transaction sequence is aborted, and
\ex{smtp-transactions}/\ex{smtp-transactions/no-close} return the
reply code and text from that transaction.
\item If the reply code is an error code (in the four- or five-hundred range),
the transaction sequence is aborted, and the fatal transaction's code
and text values are returned. \ex{Smtp-transactions} will additionally
close the socket for you; \ex{smtp-transactions/no-close} will not.
\item If the transaction is the last in the transaction sequence,
its reply code and text are returned.
\item Otherwise, we throw away the current reply code and text, and
proceed to the next transaction.
\end{itemize}
%
\ex{Smtp-transactions} closes the socket after the transaction. (The
\ex{smtp-quit} transaction, when executed, also closes the transaction.)
If the socket should be kept open in the case of an abort, use
\ex{Smtp-transactions/no-close}.
\end{desc}
\defunx{smtp-helo}{local-host-name}{smtp-transaction}
\defunx{smtp-mail}{sender-address}{smtp-transaction}
\defunx{smtp-rcpt}{destination-address}{smtp-transaction}
\defunx{smtp-data}{socket message}{smtp-transaction}
\defunx{smtp-send}{sender-address}{smtp-transaction}
\defunx{smtp-soml}{sender-address}{smtp-transaction}
\defunx{smtp-saml}{sender-address}{smtp-transaction}
\defvarx{smtp-rset}{smtp-transaction}
\defunx{smtp-vrfy}{user}{smtp-transaction}
\defunx{smtp-expn}{user}{smtp-transaction}
\defunx{smtp-help}{details}{smtp-transaction}
\defvarx{smtp-noop}{smtp-transaction}
\defvarx{smtp-quit}{smtp-transaction}
\defvarx{smtp-turn}{smtp-transaction}
\begin{desc}
These transactions represent the commands of the SMTP protocol for
use in \ex{smtp-transactions} and \ex{smtp-transactions/no-close},
i.e.\ they send the corresponding command along with the argument(s),
if any. For details, consult RFC~821.
The \ex{smtp-quit} transaction, in addition to sending a \ex{QUIT}
command to the SMTP server, also closes the socket of its SMTP
connection.
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
\chapter{SUrflet server}
\newcommand{\typew}[1]{\texttt{#1}}
The \surflet server enables you to write server side scripted web
programs in Scheme. Currently, there is only the howto available.
The complete API is supposed to come soon. There are lot of example
files in \typew{httpd/surflet/webserver/root/surflets} from which you
can copy freely.
\input{surflethowto}
+50
View File
@@ -0,0 +1,50 @@
\chapter{Processing URIs}\label{cha:uri}
The \ex{uri} module contains library functions for dealing with URIs.
\section{Notes on URI Syntax}
The generic syntax of URI (Uniform Resource Identifier) is defined in
RFC 2396; see Appendix A for a collected BNF of URI.
Within URI non-printable Ascii characters are represented by an
\emph{escape encoding}. \emph{Reserved} characters used as
delimiters indicating the different parts of a URI also must be
\emph{escaped} if they are to be regular data of a URI component. The
set of characters actually \emph{reserved} within any given URI
component is defined by that component. Therefore
\emph{escaping} can only be done when the URI is being created from
its component parts; likewise, a URI must be separated into its
component parts before \emph{unescaping} can be done.
Escape sequences are of the following scheme: \verb|%| \var{h}\var{h}
where \var{h}\var{h} are the two hexadecimal digits representing the octet code. For
example \verb|%20| is the escaped encoding for the US-ASCII space character.
\section{Procedures}
\defun{unescape}{string}{string}
\begin{desc}
\ex{Unescape} unescapes a string.
\end{desc}
%
This procedure may only be used \emph{after} the URI was parsed into
its component parts (see above).
\defun{escape} {string regexp} {string}
\begin{desc}
\ex{Escape} replaces reserved or excluded characters in \var{string}
by their escaped representation. \var{regexp} defines which
characters are reserved or excluded within the particular URI component
being escaped.
\end{desc}
This procedure may only be used on a URI \emph{component part}, not on a
complete URI made up of several component parts (see above). Use it to
write specialized escape-procedures for the respective component
parts. (See the \ex{url} module for examples).
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+77
View File
@@ -0,0 +1,77 @@
\chapter{Parsing and Processing URLs}\label{cha:url}
%
The \ex{url} module contains procedures to parse and unparse HTTP 1.1 Request-URIs.
\defun{url-string->http-url}{string}{http-url}
\begin{desc}
\ex{Url-string->http-url} parses the Request-URI \var{string} into a
\ex{http-url} record.
\end{desc}
\defun{http-url?}{thing}{boolean}
\begin{desc}
\ex{http-url?} is the predicate for the \ex{http-url} record.
\end{desc}
\defun{http-url-host}{http-url}{string or \sharpf}
\defunx{http-url-port}{http-url}{integer or \sharpf}
\defunx{http-url-path}{http-url}{list}
\defunx{http-url-query}{http-url}{string or \sharpf}
\begin{desc}
\ex{http-url-host}, \ex{http-url-port}, \ex{http-url-path} and
\ex{http-url-query} are the selectors for the \ex{http-url} record.
The \var{host} slot is a non-empty string or \sharpf.
The \var{port} slot is an integer or \sharpf.
The \var{path} slot is a list of strings containing the
Request-URI's path split at slashes and \emph{unescaped}.If the
Request-URI's path ends with a slash, an empty string is inserted as
the last element of the list.
The \var{query} slot is an non-empty-string, still in its
\emph{escaped} representation, or \sharpf.
\end{desc}
%
Examples for Request-URI strings and the slots of the corresponding
http-url record: \nopagebreak
\begin{alltt}
"http://foo.bar.org:7777///foo%20foo//bar.htm?bulb%20bulb"
\(\Rightarrow\) "foo.bar.org" 7777 '("foo foo" "bar.htm") "bulb%20bulb"
"http://foo.bar.org"
\(\Rightarrow\) "foo.bar.org" #f '() #f
"http://foo.bar.org//"
\(\Rightarrow\) "foo.bar.org" #f '("") #f
"/foo%20foo//bar.htm?bulb%20bulb"
\(\Rightarrow\) #f #f '("foo foo" "bar.htm") "bulb%20bulb"
"/foo%20foo//?bulb%20bulb"
\(\Rightarrow\) #f #f '("foo foo" "") "bulb%20bulb"
"/"
\(\Rightarrow\) #f #f '("") #f
\end{alltt}
\defun{http-url->url-string}{http-url}{string}
\begin{desc}
\ex{http-url->url-string} unparses a \ex{http-url} record and returns the
Request-URI \ex{string} of the original HTTP Request.
\end{desc}
\defun{http-url-path->path-string}{http-url-path}{string}
\begin{desc}
\ex{http-url-path->url-string} unparses the \ex{http-url-path} field of
an http-url record into its corresponding part of the Request-URI
\ex{string} of the original HTTP Request (re-escaping the path).
\end{desc}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "man"
%%% End:
+30
View File
@@ -0,0 +1,30 @@
(define-package "sunet" (2 1)
((install-lib-version (1 0))
(options (with-surflets "Install with SUrflets (requires SSAX)" "<yes/no>" #t #t #t
,parse-boolean ,show-boolean)))
(let ((surflets? (get-option-value 'with-surflets)))
(install-directory-contents "scheme" 'scheme)
(install-directory "web-server" 'misc-shared)
(install-file "start-web-server" 'misc-shared "web-server")
(install-file "start-extended-web-server" 'misc-shared "web-server")
(if surflets?
(install-file "start-surflet-server" 'misc-shared "web-server"))
(install-directory-contents "doc" 'doc)
(let ((doc-dir (get-directory 'doc #t))
(misc-shared-dir (get-directory 'misc-shared #t)))
(create-symlink (string-append doc-dir "/html")
(string-append misc-shared-dir
"/web-server/root/htdocs/sunet-manual")))
(let ((scheme-dir (get-directory 'scheme #t)))
(write-to-load-script
`((user)
(config)
(load ,(string-append scheme-dir "/packages.scm"))
,@(if surflets?
`((load ,(string-append scheme-dir "/httpd/surflets/packages.scm")))
'())
(user)))))
)
+1385
View File
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
;;; http server in the Scheme Shell -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1996 by Mike Sperber. <sperber@informatik.uni-tuebingen.de>
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; This code is very rudimentary at the moment and up for some expansion.
;;; Right now, it is primarily useful for running the server through a
;;; web accelerator
(define (access-denier . hosts)
(lambda (info)
(and (any (lambda (host)
(host-matches? info host))
hosts)
'deny)))
(define (access-allower . hosts)
(lambda (info)
(and (any (lambda (host)
(host-matches? info host))
hosts)
'allow)))
(define (access-controller . controls)
(lambda (info)
(let loop ((controls controls))
(and (pair? controls)
(or ((car controls) info)
(loop (cdr controls)))))))
(define (access-controlled-handler control ph)
(lambda (path req)
(if (eq?
(control (host-info (socket-remote-address (request-socket req))))
'deny)
(http-error (status-code forbidden) req)
(ph path req))))
(define (address->list address)
(list (arithmetic-shift (bitwise-and address #xff000000) -24)
(arithmetic-shift (bitwise-and address #xff0000) -16)
(arithmetic-shift (bitwise-and address #xff00) -8)
(bitwise-and address #xff)))
(define (host-matches? info host)
(cond
((list? host)
(let ((len (length host)))
(any (lambda (address)
(equal? (take len (address->list address)) host))
(host-info:addresses info))))
(else ; (string? host)
(any (lambda (name)
(string-match host (string-map char-downcase name)))
(cons (host-info:name info)
(host-info:aliases info))))))
(define normalize-host
(let ((split (infix-splitter (make-regexp "\\.")))
(number (make-regexp "[0-9]+")))
(lambda (host)
(let ((components (split host)))
(if (every (lambda (component)
(regexp-exec number component))
components)
(map string->number components)
host)))))
(define (take n l)
(let loop ((n n) (l l) (r '()))
(if (zero? n)
(reverse r)
(loop (- n 1) (cdr l) (cons (car l) r)))))
+298
View File
@@ -0,0 +1,298 @@
;;; Server support for NCSA's WWW Common Gateway Interface -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1995 by Olin Shivers.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; See http://hoohoo.ncsa.uiuc.edu/cgi/interface.html for a sort of "spec".
;;; PROBLEMS:
;;; - The handlers could be made -- closed over their parameters
;;; (e.g., root vars, etc.)
;;; This code provides a request handler for the HTTP server that implements
;;; a CGI interface to external programs for doing HTTP transactions.
;;; About HTML forms
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This info is in fact independent of CGI, but important to know about,
;;; as many CGI scripts are written for responding to forms-entry in
;;; HTML browsers.
;;;
;;; The form's field data are turned into a single string, of the form
;;; name=val&name=val
;;; where the <name> and <val> parts are URI encoded to hide their
;;; &, =, and + chars, among other things. After URI encoding, the
;;; space chars are converted to + chars, just for fun. It is important
;;; to encode the spaces this way, because the perfectly general %xx escape
;;; mechanism might be insufficiently confusing. This variant encoding is
;;; called "form-url encoding."
;;;
;;; If the form's method is POST,
;;; Browser sends the form's field data in the entity block, e.g.,
;;; "button=on&ans=yes". The request's Content-type: is application/
;;; x-www-form-urlencoded, and the request's Content-length: is the
;;; number of bytes in the form data.
;;;
;;; If the form's method is GET,
;;; Browser sends the form's field data in the URL's <search> part.
;;; (So the server will pass to the CGI script as $QUERY_STRING,
;;; and perhaps also on in argv[]).
;;;
;;; In either case, the data is "form-url encoded" (as described above).
;;; ISINDEX queries:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (Likewise for ISINDEX URL queries from browsers.)
;;; Browser url-form encodes the query (see above), which then becomes the
;;; ?<search> part of the URI. (Hence the CGI script will split the individual
;;; fields into argv[].)
;;; CGI interface:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; - The URL's <search> part is assigned to env var $QUERY_STRING, undecoded.
;;; - If it contains no raw "=" chars, it is split at "+" chars. The
;;; substrings are URI decoded, and become the elts of argv[].
;;; - The CGI script is run with stdin hooked up to the socket. If it's going
;;; to read the entity, it should read $CONTENT_LENGTH bytes worth.
;;; - A bunch of env vars are set; see below.
;;; - If the script begins with "nph-" its output is the entire response.
;;; Otherwise, it replies to the server, we peel off a little header
;;; that is used to construct the real header for the response.
;;; See the "spec" for further details. (URL above).
;;;
;;; The "spec" also talks about PUT, but when I tried this on a dummy script,
;;; the NSCA httpd server generated buggy output. So I am only implementing
;;; the POST and GET ops; any other op generates a "405 Method not allowed"
;;; response.
;;; Parameters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; path for scripts
(define cgi-default-bin-path "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin")
;;; The request handler for CGI scripts. (car path) is the script to run.
;;; cgi-bin-path is used, if PATH-variable isn't defined
(define (cgi-handler bin-dir . maybe-cgi-bin-path)
(let-optionals
maybe-cgi-bin-path
((cgi-bin-path cgi-default-bin-path))
(let ((request-invariant-cgi-env ; environment variables that never change
`(("PATH" . ,cgi-bin-path)
("SERVER_SOFTWARE" . ,sunet-version-identifier)
("SERVER_NAME" . ,(host-info:name (host-info (system-name))))
("GATEWAY_INTERFACE" . "CGI/1.1"))))
(lambda (path req)
(if (pair? path) ; Got to have at least one elt.
(compute-cgi path req bin-dir request-invariant-cgi-env)
(make-error-response (status-code bad-request) req "Empty CGI script"))))))
(define (compute-cgi path req bin-dir request-invariant-cgi-env)
(let* ((prog (car path))
(filename (or (dotdot-check bin-dir (list prog))
(http-error (status-code bad-request) req
"CGI scripts may not contain \"..\" elements.")))
(nph? (string-prefix? "nph-" prog)) ; PROG starts with "nph-" ?
; why did we had (string-suffix? "-nph" prog) here?
(search (http-url-query (request-url req))) ; Compute the
(argv (if (and search (not (string-index search #\=))) ; argv list.
(split-and-decode-search-spec search)
'()))
(env (cgi-env req bin-dir (cdr path) request-invariant-cgi-env))
(doit (lambda ()
(dup->inport (socket:inport (request-socket req)) 0)
(dup->outport (current-output-port) 1)
(dup 1 2)
(apply exec/env filename env argv))))
(http-syslog (syslog-level debug) "[cgi-server] search: ~s, argv: ~s~%" search argv)
(let ((request-method (request-method req)))
(cond
((or (string=? request-method "GET")
(string=? request-method "POST")) ; Could do others also.
(case (file-not-executable? filename)
((search-denied permission)
(make-error-response (status-code forbidden) req
"No permission to search directory."))
((no-directory nonexistent)
(make-error-response (status-code not-found) req))
(else
(if nph?
(cgi-make-nph-response (run/port* doit))
(cgi-make-response (run/port* doit) path req)))))
((string=? request-method "HEAD")
(make-error-response (status-code method-not-allowed) req "GET, POST"))
(else
(make-error-response (status-code not-implemented) req))))))
(define (split-and-decode-search-spec s)
(let recur ((i 0))
(cond
((string-index s #\+ i) => (lambda (j) (cons (unescape s i j)
(recur (+ j 1)))))
(else (list (unescape s i (string-length s)))))))
;;; Compute the CGI scripts' process environment by adding the standard CGI
;;; environment var bindings to the current process env -- return result
;;; as an alist.
;;;
;;; You are also supposed to add the headers as env vars in a particular
;;; format, but are allowed to bag it if the environment var storage
;;; requirements might overload the OS. I don't know what you can rely upon
;;; in Unix, so I am just bagging it, period.
;;;
;;; Suppose the URL is
;;; //machine/cgi-bin/test-script/foo/bar?quux%20a+b=c
;;; then:
;; PATH_INFO -- extra info after the script-name path prefix. "/foo/bar"
;;; PATH_TRANSLATED -- non-virtual version of above. "/u/Web/foo/bar/"
;;; SCRIPT_NAME virtual path to script "/cgi-bin/test-script"
;;; QUERY_STRING -- not decoded "quux%20a+b=c"
;;; The first three of these vars are *not* encoded, so information is lost
;;; if the URL's path elements contain encoded /'s (%2F). CGI loses.
(define (cgi-env req bin-dir path-suffix request-invariant-cgi-env)
(let* ((sock (request-socket req))
(raddr (socket-remote-address sock))
(headers (request-headers req))
;; Compute the $PATH_INFO and $PATH_TRANSLATED strings.
(path-info (string-join path-suffix "/")) ; No encode or .. check.
(path-translated (path-list->file-name path-info bin-dir))
;; Compute the $SCRIPT_PATH string.
(url-path (http-url-path (request-url req)))
(script-path (take (- (length url-path) (length path-suffix))
url-path))
(script-name (string-join script-path "/")))
(receive (rhost rport)
(socket-address->internet-address raddr)
(receive (lhost lport)
(socket-address->internet-address (socket-local-address sock))
`(("SERVER_PROTOCOL" . ,(version->string (request-version req)))
("SERVER_PORT" . ,(number->string lport))
("REQUEST_METHOD" . ,(request-method req))
("PATH_INFO" . ,path-info)
("PATH_TRANSLATED" . ,path-translated)
("SCRIPT_NAME" . ,script-name)
("REMOTE_ADDR" . ,(format-internet-host-address rhost))
;; ("AUTH_TYPE" . xx) ; Random authentication
;; ("REMOTE_USER" . xx) ; features I don't understand.
;; ("REMOTE_IDENT" . xx)
,@request-invariant-cgi-env ; Stuff that never changes (see cgi-handler).
,@(cond ((http-url-query (request-url req)) =>
(lambda (srch) `(("QUERY_STRING" . ,srch))))
(else '()))
,@(cond ((get-header headers 'content-type) =>
(lambda (ct) `(("CONTENT_TYPE" . ,ct))))
(else '()))
,@(cond ((get-header headers 'content-length) =>
(lambda (cl) ; Skip initial whitespace (& other non-digits).
(let ((first-digit (string-index cl char-set:digit))
(cl-len (string-length cl)))
(if first-digit
`(("CONTENT_LENGTH" . ,(substring cl first-digit cl-len)))
(http-error (status-code bad-request) req
"Illegal `Content-length:' header.")))))
(else '()))
. ,(env->alist))))))
(define (take n lis)
(if (zero? n) '()
(cons (car lis) (take (- n 1) (cdr lis)))))
(define (drop n lis)
(if (zero? n) lis
(drop (- n 1) (cdr lis))))
;;; Script's output for request REQ is available on SCRIPT-PORT.
;;; The script isn't an "nph-" script, so we read the response, and mutate
;;; it into a real HTTP response, which we then send back to the HTTP client.
(define (cgi-make-response script-port path req)
(set-port-buffering script-port bufpol/block 4096)
(let* ((headers (read-rfc822-headers script-port))
(ctype (get-header headers 'content-type))
(loc (get-header headers 'location))
(stat (cond ((get-header headers 'status)
=> (lambda (code.text)
(extract-status-code-and-text code.text
req)))
(else
(http-syslog (syslog-level notice)
"CGI script didn't generate status header.")
(cons 200 "OK"))))
(extra-headers (delete-headers (delete-headers (delete-headers headers
'content-type)
'location)
'status)))
(http-syslog (syslog-level debug) "[cgi-server] headers: ~s~%" headers)
(http-syslog (syslog-level debug) "[cgi-server] request-method=~a~%"
(request-method req))
(if loc
(if (absolute-url? (url-string->http-url (string-trim loc)))
(make-error-response (status-code moved-perm) req loc)
(make-redirect-response (string-trim loc)))
;; Send the response header back to the client
(make-response ;code message seconds mime extras body
(number->status-code (car stat))
(cdr stat) ; text
(time)
(or ctype "text/html")
extra-headers
(make-writer-body
(lambda (out options)
(copy-inport->outport script-port out 4096)
(close-input-port script-port)))))))
(define (delete-headers headers tag)
(alist-delete tag headers))
(define (cgi-make-nph-response script-port)
(make-nph-response
(make-writer-body (lambda (out options)
(copy-inport->outport script-port out)))))
(define (extract-status-code-and-text status req)
(with-fatal-error-handler*
(lambda (c d)
(http-error (status-code bad-gateway) req
"CGI script generated an invalid status header."
status c))
(lambda ()
(let ((status (string-trim status)))
(cons (string->number (substring status 0 3)) ; number
(substring/shared status 4)))))) ; text
+345
View File
@@ -0,0 +1,345 @@
;;; http server in the Scheme Shell -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; This file implements the core of an HTTP server: code to establish
;;; net connections, read and parse requests, and handler errors.
;;; It does not have the code to actually handle requests. That's up
;;; to other modules, and could vary from server to server. To build
;;; a complete server, you need to define request handlers (see below) --
;;; they determine how requests are to be handled.
;;;
;;; See RFC 2616 for the specification of the HTTP/1.1 protocol.
;;;
;;; The server is compatible with previous versions of HTTP in the way
;;; described in RFC 2616 19.6. See RFC 1945 for the specification of
;;; HTTP/1.0 and 0.9.
(define (httpd options)
(let ((port (httpd-options-port options))
(root-dir (httpd-options-root-directory options))
(rate-limiter
(cond
((httpd-options-simultaneous-requests options)
=> make-rate-limiter)
(else #f))))
(let-thread-fluid
logging
(make-logging)
(lambda ()
(init-http-log! options)
(with-syslog-destination
"httpd" #f #f #f
(lambda ()
(with-cwd
root-dir
(bind-prepare-listen-accept-loop
protocol-family/internet
(lambda ()
(cond ((httpd-options-post-bind-thunk options)
=> (lambda (thunk)
(thunk)))))
(lambda (sock addr)
(if rate-limiter
(begin
(rate-limit-block rate-limiter)
(rate-limit-open rate-limiter)))
(with-fatal-error-handler
(lambda (c decline)
(http-syslog (syslog-level notice) "error during connection negotiation~%")
(if rate-limiter
(rate-limit-close rate-limiter)))
(call-with-values
(lambda ()
(socket-address->internet-address (socket-remote-address sock)))
(lambda (host-address service-port)
(if (and rate-limiter (http-syslog?))
(http-syslog (syslog-level info) "<~a>~a: concurrent request #~a~%"
(pid)
(format-internet-host-address host-address)
(rate-limiter-current-requests rate-limiter)))
(set-port-buffering (socket:outport sock) bufpol/block 4096)
(fork-thread
(lambda ()
;; If there is buffering for the input,
;; CGI scripts don't get the full request
(set-port-buffering (socket:inport sock) bufpol/none)
(process-toplevel-request sock host-address options)
(if (http-syslog?)
(http-syslog (syslog-level debug) "<~a>~a [closing]~%"
(pid)
(format-internet-host-address host-address)))
(with-fatal-error-handler
(lambda (c decline)
(if (http-syslog?)
(http-syslog (syslog-level notice) "<~a>~a [error closing (~a)]~%"
(pid)
(format-internet-host-address host-address)
c)))
(close-socket sock))
(if rate-limiter
(rate-limit-close rate-limiter))
(if (http-syslog?)
(http-syslog (syslog-level info) "<~a>~a [closed]~%"
(pid)
(format-internet-host-address host-address)))))))))
port))))))))
;;; Top-level http request processor
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Read, parse, and handle a single http request. The only thing that makes
;;; this complicated is handling errors -- as a server, we can't just let the
;;; standard error handlers toss us into a breakpoint. We have to catch the
;;; error, send an error response back to the client if we can, and then keep
;;; on trucking. This means using the S48's condition system to catch and
;;; handle the various errors, which introduces a major point of R5RS
;;; incompatibiliy -- R5RS has no exception system. So if you were to port
;;; this code to some other Scheme, you'd really have to sit down and think
;;; about this issue for a minute.
(define (process-toplevel-request sock host-address options)
;; This top-level error-handler catches *all* uncaught errors and warnings.
;; If the error condition is a reportable HTTP error, we send a response back
;; to the client. In any event, we abort the transaction, and return from
;; PROCESS-TOPLEVEL-REQUEST.
;;
;; We *oughta* map non-http-errors into replies anyway.
(with-fatal-error-handler*
(lambda (c decline)
(http-syslog (syslog-level notice) "<~a>~a: error: ~s~%"
(pid)
(format-internet-host-address host-address)
c)
(with-fatal-error-handler*
(lambda (c decline)
(http-syslog (syslog-level notice) "<~a>~a [error shutting down: ~s]~%"
(pid)
(format-internet-host-address host-address)
c))
(lambda ()
(shutdown-socket sock shutdown/sends+receives)
(http-syslog (syslog-level info) "<~a>~a [shut down]~%"
(pid)
(format-internet-host-address host-address)))))
(lambda ()
(call-with-values
(lambda ()
(with-fatal-error-handler*
(lambda (c decline)
(http-syslog (syslog-level notice) "<~a>~a: error: ~s~%"
(pid)
(format-internet-host-address host-address)
c)
(cond
((http-error? c)
(apply (lambda (status-code req . args)
(values req
(apply make-error-response
status-code req
args)))
(condition-stuff c)))
((fatal-syntax-error? c)
(values #f
(apply make-error-response (status-code bad-request)
#f ; No request yet.
(condition-stuff c))))
((not (and (exception? c)
(eq? (exception-reason c);;?? ->
(enum exception os-error))));;?? ->
;;which cases is this supposed to catch excactly? broken
;;connection to client? If so, does it work?
(values #f
(apply make-error-response (status-code internal-error)
#f ; don't know
c)))
(else
(decline))))
(lambda ()
(let ((initial-req (parse-http-request sock options)))
(check-major-http-version initial-req)
(check-host-header initial-req)
(let redirect-loop ((req initial-req))
(let response-loop ((response ((httpd-options-request-handler options)
(http-url-path (request-url req))
req)))
(cond
((input-response? response)
(response-loop
((input-response-body-maker response)
(socket:inport sock))))
((nph-response? response)
(values req response))
((eq? (response-code response) (status-code redirect));internal redirect
(redirect-loop (redirect-request req response sock options)))
(else
(values req response)))))))))
(lambda (req response)
(send-http-response req response
(socket:inport sock)
(socket:outport sock)
options)
)))))
;;; REDIRECT-REQUEST relies on that nothing is read out from SOCKET.
(define (redirect-request req response socket options)
(let* ((new-location-uri (redirect-body-location (response-body response)))
(url (with-fatal-error-handler*
(lambda (c decline)
(if (fatal-syntax-error? c)
(http-error (status-code internal-error) req
(format #f "Bad redirection out from CGI program: ~%~a"
(cdr c)))
(decline c)))
(lambda ()
;; (future) NOTE: With this, a redirection may change the
;; protocol in use (currently, the server only supports one of
;; it). This might be inapplicable.
(url-string->http-url new-location-uri)))))
(make-request "GET"
new-location-uri
url
(request-version req) ; did not change
'() ; no rfc822 headers
(request-socket req))))
;;; Read and parse an http request from INPORT.
(define (parse-http-request sock options)
(let ((line (read-crlf-line (socket:inport sock))))
;; Blat out some logging info.
(if (http-syslog?)
(call-with-values
(lambda ()
(socket-address->internet-address (socket-remote-address sock)))
(lambda (host-address service-port)
(http-syslog (syslog-level info) "<~a>~a: ~a~%"
(pid)
(format-internet-host-address host-address)
line))))
(if (eof-object? line)
(fatal-syntax-error "EOF while parsing request.")
(let* ((elts (string->words line)) ; Split at white-space.
(version (case (length elts)
((2) '(0 . 9))
((3) (parse-http-version (caddr elts)))
(else (fatal-syntax-error "Bad Request Line."))))
(meth (car elts))
(request-uri (cadr elts))
(url (url-string->http-url request-uri))
(headers (if (equal? version '(0 . 9))
'()
(with-fatal-error-handler
(lambda (c decline)
(fatal-syntax-error "Illegal RFC 822 field syntax of request headers"))
(read-rfc822-headers (socket:inport sock))))))
(make-request meth request-uri url version headers sock)))))
(define parse-http-version
(let ((re (make-regexp "^HTTP/([0-9]+)\\.([0-9]+)$"))
(lose (lambda (s) (fatal-syntax-error "Bad HTTP version" s))))
(lambda (vstring)
(let ((m (regexp-exec re vstring)))
(if m
(cons (or (string->number (match:substring m 1) 10) (lose vstring))
(or (string->number (match:substring m 2) 10) (lose vstring)))
(lose vstring))))))
;;; check whether the request's major HTTP version is greater than the
;;; server's major HTTP version; if so, send 505 (Version not supported).
(define (check-major-http-version req)
(if (> (car (request-version req)) (car http-version))
(http-error (status-code version-not-supp) req)))
(define (check-host-header req)
(if (not (version< (request-version req) '(1 . 1)))
(or (get-header (request-headers req) 'host)
(http-error (status-code bad-request) req "Missing Host header"))))
;;; Split string into a list of whitespace-separated strings.
;;; This could have been trivially defined in scsh as (field-splitter " \t\n")
;;; but I hand-coded it because it's short, and I didn't want invoke the
;;; regexp machinery for something so simple.
(define non-whitespace (char-set-complement char-set:whitespace))
(define (string->words s)
(let recur ((start 0))
(cond ((string-index s non-whitespace start) =>
(lambda (start)
(cond ((string-index s char-set:whitespace start) =>
(lambda (end)
(cons (substring s start end)
(recur end))))
(else (list (substring s start (string-length s)))))))
(else '()))))
(define (send-http-headers response port)
(display (version->string http-version) port)
(write-char #\space port)
(display (status-code-number (response-code response)) port)
(write-char #\space port)
(display (or (response-message response)
(status-code-message (response-code response)))
port)
(write-crlf port)
(send-http-header-fields
(list (cons 'server (string-append "Scheme Untergrund " sunet-version-identifier))
(cons 'content-type (response-mime response))
(cons 'date (rfc822-time->string (response-seconds response)))
(cons 'connection "close"))
port)
(send-http-header-fields (response-extras response) port)
(write-crlf port))
(define (send-http-response request response input-port output-port options)
(cond
;;if request-record could not be built (i.e. either
;;fatal-syntax-error was called because of an erroneous request
;;line, or an server-internal error (not an os-error) occurred)
;;and therefore HTTP-version of request is not known, answer
;;with HTTP/1.0
((not request)
(send-http-headers response output-port)
(display-http-body (response-body response) input-port output-port options))
;;no CLF-logging)
((nph-response? response)
(display-http-body (nph-response-body response) input-port output-port options)
(http-log request (status-code ok))); guess the status code
(else
(if (not (v0.9-request? request))
(send-http-headers response output-port))
(if (not (or (string=? (request-method request) "HEAD")
(no-body? (response-body response)))) ;; response messages which MUST NOT include a message-body
(display-http-body (response-body response) input-port output-port options))
(http-log request (response-code response)))))
(define (send-http-header-fields headers port)
(for-each (lambda (pair)
(display (car pair) port)
(write-char #\: port)
(display (cdr pair) port)
(write-crlf port))
headers))
+58
View File
@@ -0,0 +1,58 @@
;;; Error stuff for the http server. -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; An http error condition is a data structure with the following pieces:
;;; (error-code request message . irritants)
;;; You recognise one with HTTP-ERROR?, and retrieve the pieces with
;;; CONDITION-STUFF.
;;;
;;; HTTP error condition
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Define a sub-type of the S48 error condition, the HTTP error condition.
;;; An HTTP error is one that corresponds to one of the HTTP error response
;;; codes, so you can reliably use an HTTP error condition to construct an
;;; error response message to send back to the HTTP client.
(define-condition-type 'http-error '(error))
(define http-error? (condition-predicate 'http-error))
;; See make-error-response for what you have to stuff into args for
;; each status-code. (All http-errors will be caught by the top-level
;; error-handler of process-toplevel-request, and will be turned into
;; calls of make-error-response).
(define (http-error status-code req . args)
(apply signal 'http-error status-code req args))
;;; Syntax error condition
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Scheme 48 has a "syntax error" error condition, but it isn't an error
;;; condition! It's a warning condition. I don't understand this.
;;; We define a *fatal* syntax error here for the parsers to use.
;; fatal-syntax-error isn't really a different type of error - it's
;; just an abbreviated notation:
;; (fatal-syntax-error msg irritants)
;; is equivalent to
;; (http-error (status-code bad-request) #f msg irritants)
;; -> use fatal-syntax-error where the client request cannot be parsed
;; because of bad syntax
(define-condition-type 'fatal-syntax-error '(error))
(define fatal-syntax-error? (condition-predicate 'fatal-syntax-error))
;; as with http-errors fatal-syntax-errors will be caught by the
;; top-level error-handler of process-toplevel-request and turned into
;; calls of make-error-response
(define (fatal-syntax-error msg . irritants)
(apply signal 'fatal-syntax-error msg irritants))
+551
View File
@@ -0,0 +1,551 @@
;;; http server in the Scheme Shell -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1994 by Brian D. Carlstrom and Olin Shivers.
;;; Copyright (c) 1996-2003 by Mike Sperber.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
(define server/buffer-size 8192) ; WTF
(define-record-type file-directory-options :file-directory-options
(really-make-file-directory-options file-name->content-type
file-name->content-encoding
file-name->icon-url
directory-icon-url
blank-icon-url
back-icon-url
unknown-icon-url)
file-directory-options?
(file-name->content-type file-directory-options-file-name->content-type
set-file-directory-options-file-name->content-type!)
(file-name->content-encoding file-directory-options-file-name->content-encoding
set-file-directory-options-file-name->content-encoding!)
(file-name->icon-url file-directory-options-file-name->icon-url
set-file-directory-options-file-name->icon-url!)
(directory-icon-url file-directory-options-directory-icon-url
set-file-directory-options-directory-icon-url!)
(blank-icon-url file-directory-options-blank-icon-url
set-file-directory-options-blank-icon-url!)
(back-icon-url file-directory-options-back-icon-url
set-file-directory-options-back-icon-url!)
(unknown-icon-url file-directory-options-unknown-icon-url
set-file-directory-options-unknown-icon-url!))
(define (make-default-file-directory-options)
(really-make-file-directory-options default-file-name->content-type
default-file-name->content-encoding
default-file-name->icon-url
#f #f #f #f))
(define (copy-file-directory-options options)
(let ((new-options (make-default-file-directory-options)))
(set-file-directory-options-file-name->content-type!
new-options
(file-directory-options-file-name->content-type options))
(set-file-directory-options-file-name->content-encoding!
new-options
(file-directory-options-file-name->content-encoding options))
(set-file-directory-options-file-name->icon-url!
new-options
(file-directory-options-file-name->icon-url options))
(set-file-directory-options-directory-icon-url!
new-options
(file-directory-options-directory-icon-url options))
(set-file-directory-options-blank-icon-url!
new-options
(file-directory-options-blank-icon-url options))
(set-file-directory-options-back-icon-url!
new-options
(file-directory-options-back-icon-url options))
(set-file-directory-options-unknown-icon-url!
new-options
(file-directory-options-unknown-icon-url options))
new-options))
(define (make-file-directory-options-transformer set-option!)
(lambda (new-value . stuff)
(let ((new-options (if (not (null? stuff))
(copy-file-directory-options (car stuff))
(make-default-file-directory-options))))
(set-option! new-options new-value)
new-options)))
(define with-file-name->content-type
(make-file-directory-options-transformer
set-file-directory-options-file-name->content-type!))
(define with-file-name->content-encoding
(make-file-directory-options-transformer
set-file-directory-options-file-name->content-encoding!))
(define with-file-name->icon-url
(make-file-directory-options-transformer
set-file-directory-options-file-name->icon-url!))
(define with-blank-icon-url
(make-file-directory-options-transformer
set-file-directory-options-blank-icon-url!))
(define with-back-icon-url
(make-file-directory-options-transformer
set-file-directory-options-back-icon-url!))
(define with-unknown-icon-url
(make-file-directory-options-transformer
set-file-directory-options-unknown-icon-url!))
(define (make-file-directory-options . stuff)
(let loop ((options (make-default-file-directory-options))
(stuff stuff))
(if (null? stuff)
options
(let* ((transformer (car stuff))
(value (cadr stuff)))
(loop (transformer value options)
(cddr stuff))))))
;;; (home-dir-handler user-public-dir) -> handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Return a request handler that looks things up in a specific directory
;;; in the user's home directory. If ph = (home-dir-handler "public_html")
;;; then ph is a request handler that serves files out of peoples' public_html
;;; subdirectory. So
;;; (ph '("shivers" "hk.html") req)
;;; will serve the file
;;; ~shivers/public_html/hk.html
;;; The request handler treats the URL path as (<user> . <file-path>),
;;; serving
;;; ~<user>/<user-public-dir>/<file-path>
(define (home-dir-handler user-public-dir . maybe-options)
(let-optionals maybe-options ((options (make-default-file-directory-options)))
(lambda (path req)
(if (null? path)
(make-error-response (status-code bad-request)
req
"Path contains no home directory.")
(make-rooted-file-path-response (string-append (http-homedir (car path) req)
"/"
user-public-dir)
(cdr path)
file-serve-response
req
options)))))
;;; (tilde-home-dir-handler user-public-dir default-request-handler)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; If the car of the path is a tilde-marked home directory (e.g., "~kgk"),
;;; do home-directory service as in HOME-DIR-HANDLER, otherwise punt to the
;;; default handler.
(define (tilde-home-dir? path req)
(and (not (null? path))
(let ((head (car path))) ; home-directory path?
(and (> (string-length head) 0)
(char=? (string-ref head 0) #\~)))))
(define (tilde-home-dir-handler user-public-dir default-handler . maybe-options)
(let-optionals maybe-options ((options (make-default-file-directory-options)))
(make-predicate-handler
tilde-home-dir?
(lambda (path req)
(let* ((tilde-home (car path)) ; Yes.
(slen (string-length tilde-home))
(subdir (string-append
(http-homedir (substring tilde-home 1 slen) req)
"/"
user-public-dir)))
(make-rooted-file-path-response subdir (cdr path) file-serve-response req
options)))
default-handler)))
;;; Make a handler that serves files relative to a particular root
;;; in the file system. You may follow symlinks, but you can't back up
;;; past ROOT with ..'s.
(define (rooted-file-handler root . maybe-options)
(let-optionals maybe-options ((options (make-default-file-directory-options)))
(lambda (path req)
(make-rooted-file-path-response root path file-serve-response req options))))
;;; Dito, but also serve directory indices for directories without
;;; index.html.
(define (rooted-file-or-directory-handler root . maybe-options)
(let-optionals maybe-options ((options (make-default-file-directory-options)))
(lambda (path req)
(make-rooted-file-path-response root path
file-serve-and-dir-response
req
options))))
;;;; Support procs for the path handlers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (MAKE-ROOTED-FILE-PATH-RESPONSE root file-path req options)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Do a request for a file. The file-name is determined by appending the
;;; the FILE-PATH list the string ROOT. E.g., if
;;; ROOT = "/usr/shivers" FILE-PATH = ("a" "b" "c" "foo.html")
;;; then we serve file
;;; /usr/shivers/a/b/c/foo.html
;;; Elements of FILE-PATH are *not allowed* to contain .. elements.
;;; (N.B.: Although the ..'s can appear in relative URI's, /foo/../ path
;;; sequences are processed away by the browser when the URI is converted
;;; to an absolute URI before it is sent off to the server.)
;;; It is possible to sneak a .. past this kind of front-end resolving by
;;; encoding it (e.g., "foo%2F%2E%2E" for "foo/.."). If the client tries
;;; this, MAKE-ROOTED-FILE-PATH-RESPONSE will catch it, and abort the transaction.
;;; So you cannot make the reference back up past ROOT. E.g., this is
;;; not allowed:
;;; FILE-PATH = ("a" "../.." "c" "foo.html")
;;;
;;; Only GET and HEAD ops are provided.
;;; The URL's <search> component must be #f.
;;; The file is served if the server has read or stat(2) access to it,
;;; respectively. If the server is run as root, this might be a problem.
;;;
;;; FILE-SERVE is a procedure which gets passed the file name, the
;;; path, and the HTTP request to serve the file propert after the
;;; security checks. Look in ROOTED-FILE-HANDLER and
;;; ROOTED-FILE-OR-DIRECTORY-HANDLER for examples on how to feed this.
(define (make-rooted-file-path-response root file-path file-serve-response req options)
(if (http-url-query (request-url req))
(make-error-response (status-code bad-request) req
"Indexed search not provided for this URL.")
(cond ((dotdot-check root file-path) =>
(lambda (fname)
(file-serve-response fname file-path req options)))
(else
(make-error-response (status-code bad-request) req
"URL contains unresolvable ..'s.")))))
;; Just (file-info fname) with error handling.
(define (stat-carefully fname req)
(with-errno-handler
((errno packet)
((errno/noent)
(http-error (status-code not-found) req))
((errno/acces)
(http-error (status-code forbidden) req)))
(file-info fname #t)))
;;; A basic file request handler -- ship the dude the file. No fancy path
;;; checking. That has presumably been taken care of. This handler only
;;; takes care of GET and HEAD methods.
(define (file-serve-or-dir-response fname file-path req directory-serve-response options)
(if (file-name-directory? fname) ; Simple index generation.
(directory-serve-response fname file-path req options)
(let ((request-method (request-method req)))
(cond
((or (string=? request-method "GET")
(string=? request-method "HEAD")) ; Absolutely.
(let ((info (stat-carefully fname req)))
(case (file-info:type info)
((regular fifo socket)
(send-file-response fname info req options))
((directory) ; Send back a redirection "foo" -> "foo/"
(let* ((url (request-url req))
(url-string (http-url->url-string url))
(location-prefix
(if (absolute-url? url)
url-string
(string-append
"http://" (get-socket-host-string req) url-string))) ;we don't support virtual hosts yet!
(location (string-append location-prefix "/")))
(make-error-response
(status-code moved-perm) req location)))
(else (make-error-response (status-code forbidden) req)))))
((string=? request-method "POST")
(make-error-response (status-code method-not-allowed) req
"GET, HEAD"))
(else
(make-error-response (status-code not-implemented) req))))))
(define (directory-index-serve-response fname file-path req options)
(file-serve-response (string-append fname "index.html") file-path req options))
(define (file-serve-response fname file-path req options)
(file-serve-or-dir-response fname file-path req
directory-index-serve-response
options))
(define (default-file-name->icon-url fname)
#f)
(define (time->directory-index-date-string time)
(format-date "~d-~b-~y ~H:~M:~S GMT" (date time 0)))
(define (read-max-lines fname max)
(call-with-input-file
fname
(lambda (port)
(let loop ((r "") (i max))
(if (zero? i)
r
(let ((line (read-line port)))
(if (eof-object? line)
r
(loop (string-append r " " line) (- i 1)))))))))
(define (string-cut s n)
(if (>= (string-length s) n)
(substring s 0 n)
s))
(define html-file-header
(let ((title-tag-regexp (make-regexp "<[Tt][Ii][Tt][Ll][Ee]>"))
(title-close-tag-regexp (make-regexp "</[Tt][Ii][Tt][Ll][Ee]>")))
(lambda (fname n)
(let ((stuff (read-max-lines fname 10)))
(cond
((regexp-exec title-tag-regexp stuff)
=> (lambda (open-match)
(cond
((regexp-exec title-close-tag-regexp stuff
(match:end open-match 0))
=> (lambda (close-match)
(string-cut (substring stuff
(match:end open-match 0)
(match:start close-match 0))
n)))
(else (string-cut (substring stuff
(match:end open-match 0)
(string-length stuff))
n)))))
(else ""))))))
(define (file-documentation fname n options)
(cond
(((file-directory-options-file-name->content-type options) fname)
=> (lambda (content-type)
(if (and (string=? content-type "text/html" )
(file-readable? fname))
(html-file-header fname n)
"")))
(else "")))
(define (directory-index req dir port options)
(define (pad-file-name file)
(write-string (make-string (max (- 21 (string-length file))
1)
#\space)
port))
(define (emit-file-name file)
(let ((l (string-length file)))
(if (<= l 20)
(emit-text file port)
(emit-text (substring file 0 20) port))))
(define (index-entry file)
(let* ((fname (directory-as-file-name (string-append dir file)))
(info (file-info fname #t))
(type (file-info:type info))
(size (file-info:size info))
(icon-name
(case type
((regular fifo socket)
((file-directory-options-file-name->icon-url options)
fname))
((directory)
(file-directory-options-directory-icon-url options))
(else
(file-directory-options-unknown-icon-url options))))
(tag-name
(case type
((regular fifo socket) "[FILE]")
((directory) "[DIR ]")
(else "[????]"))))
(if icon-name
(emit-empty-tag port 'img
(cons 'src icon-name)
(cons 'alt tag-name))
(display tag-name port))
(with-tag port a ((href file))
(emit-file-name file))
(pad-file-name file)
(emit-text (time->directory-index-date-string (file-info:mtime info)) port)
(if size
(let* ((size-string
(string-append (number->string (quotient size 1024))
"K"))
(size-string
(if (<= (string-length size-string) 7)
size-string
(string-append (number->string (quotient size (* 1024 1024)))
"M")))
(size-string
(if (<= (string-length size-string) 8)
(string-append
(make-string (- 8 (string-length size-string)) #\space)
size-string)
size-string)))
(write-string size-string port))
(write-string (make-string 8 #\space) port))
(write-char #\space port)
(emit-text (file-documentation fname 24 options) port)
(write-crlf port)))
(let ((files (directory-files dir)))
(for-each index-entry files)
(length files)))
(define (directory-serve-response fname file-path req options)
(let ((request-method (request-method req)))
(cond
((or (string=? request-method "GET")
(string=? request-method "HEAD"))
(if (not (eq? 'directory
(file-info:type (file-info fname #t))))
(make-error-response (status-code forbidden) req)
(make-response
(status-code ok)
#f
(time)
"text/html"
'()
(make-writer-body
(lambda (port httpd-options)
(let ((back-icon
(file-directory-options-back-icon-url options))
(blank-icon
(file-directory-options-blank-icon-url options)))
(emit-prolog port)
(with-tag port html (xmlnsdecl-attr)
(let ((title (string-append "Index of /"
(string-join file-path "/"))))
(with-tag port head ()
(emit-title port title))
(with-tag port body ()
(emit-header port 1 title)
(with-tag port pre ()
(if blank-icon
(display "[ ]" port)
(emit-empty-tag port 'img
(cons 'src blank-icon)
(cons 'alt " ")))
(write-string "Name " port)
(write-string "Last modified " port)
(write-string "Size " port)
(write-string "Description" port)
(emit-empty-tag port 'hr)
(if back-icon
(emit-empty-tag port 'img
(cons 'src back-icon)
(cons 'alt "[UP ]"))
(display "[UP ]" port))
(if (not (null? file-path))
(begin
(with-tag port a ((href ".."))
(write-string "Parent directory" port))
(write-crlf port)))
(let ((n-files (directory-index req fname port options)))
(emit-empty-tag port 'hr)
(format port "~d files" n-files))))))))))))
((string=? request-method "POST")
(make-error-response (status-code method-not-allowed) req
"GET, HEAD"))
(else
(make-error-response (status-code not-implemented) req)))))
(define (index-or-directory-serve-response fname file-path req options)
(let ((index-fname (string-append fname "index.html")))
(if (file-readable? index-fname)
(file-serve-response index-fname file-path req options)
(directory-serve-response fname file-path req options))))
(define (file-serve-and-dir-response fname file-path req options)
(file-serve-or-dir-response fname file-path req
index-or-directory-serve-response
options))
;;; Look up user's home directory, generating an HTTP error response if you lose.
(define (http-homedir username req)
(with-fatal-error-handler (lambda (c decline)
(apply http-error (status-code bad-request) req
"Couldn't find user's home directory."
(condition-stuff c)))
(home-dir username)))
(define (send-file-response filename info req options)
(if (file-not-readable? filename) ; #### double stats are no good
(make-error-response (status-code not-found) req)
(receive (stripped-filename content-encoding)
((file-directory-options-file-name->content-encoding options) filename)
(make-response (status-code ok)
#f
(time)
((file-directory-options-file-name->content-type options)
stripped-filename)
(append (if content-encoding
(list (cons 'content-encoding content-encoding))
'())
(list
(cons 'last-modified
(rfc822-time->string
(file-info:mtime info)))
(cons 'content-length (file-info:size info))))
(make-writer-body
(lambda (port options)
(call-with-input-file filename
(lambda (in)
(copy-inport->outport in port)))))))))
(define (default-file-name->content-type fname)
(let ((ext (file-name-extension fname)))
(cond
((string-ci=? ext ".htm") "text/html")
((string-ci=? ext ".html") "text/html")
((string-ci=? ext ".txt") "text/plain")
((string-ci=? ext ".css") "text/css")
((string-ci=? ext ".doc") "application/msword")
((string-ci=? ext ".gif") "image/gif")
((string-ci=? ext ".png") "image/png")
((string-ci=? ext ".bmp") "image/bmp")
((or (string-ci=? ext ".jpg")
(string-ci=? ext ".jpeg")) "image/jpeg")
((or (string-ci=? ext ".tiff")
(string-ci=? ext ".tif")) "image/tif")
((string-ci=? ext ".rtf") "text/rtf")
((or (string-ci=? ext ".mpeg")
(string-ci=? ext ".mpg")) "video/mpeg")
((or (string-ci=? ext ".au")
(string-ci=? ext ".snd")) "audio/basic")
((string-ci=? ext ".wav") "audio/x-wav")
((string-ci=? ext ".dvi") "application/x-dvi")
((or (string-ci=? ext ".tex")
(string-ci=? ext ".latex")) "application/latex")
((string-ci=? ext ".zip") "application/zip")
((string-ci=? ext ".tar") "application/tar")
((string-ci=? ext ".hqx") "application/mac-binhex40")
((string-ci=? ext ".ps") "application/postscript")
((string-ci=? ext ".pdf") "application/pdf")
(else "application/octet-stream"))))
(define (default-file-name->content-encoding fname)
(cond
((let ((ext (file-name-extension fname)))
(cond
((string-ci=? ext ".Z") "x-compress")
((string-ci=? ext ".gz") "x-gzip")
(else #f)))
=> (lambda (encoding)
(values (file-name-sans-extension fname) encoding)))
(else (values fname #f))))
+195
View File
@@ -0,0 +1,195 @@
;;; A library of procs for request handlers.
;;; This file is part of the Scheme Untergrund Networking package.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Reading in the message body of a request.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Read in the message body of an HTTP message and return it as a string.
;;;
;;; READ-MESSAGE-BODY handles ordinary message bodies as well as
;;; message bodies to which the transfer coding "chunked" has been
;;; applied.
;;;
;;; Note: all request handlers should use READ-MESSAGE-BODY, and should not
;;; read in message bodies by themselves: READ-MESSAGE-BODY implements
;;; the correct order in which a message body's length is determined.
;;; (See RFC 2616, 4.4 for precedence of Transfer-encoding header over Content-length header.)
(define (read-message-body req)
(let ((inport (socket:inport (request-socket req))))
(if (chunked-transfer-coding? req)
(read-chunked-body inport)
(read-ordinary-body inport req))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Reading in ordinary bodies (no transfer coding applied)
;;; Read in the message body, return it as a string.
(define (read-ordinary-body inport req)
(let* ((body-length (get-body-length-from-content-length req)) ;make sure we have a valid Content-length header in request
(maybe-body (read-string body-length inport)))
(or maybe-body
(fatal-syntax-error "EOF while reading in message body"))))
;;Get length of the request's message body from Content-length header or
;;throw fatal-syntax-error if no such header
(define (get-body-length-from-content-length req)
(let
;;try to get field value of first Content-length header (RFC 2616 allows only one Content-length: header)
((maybe-length (get-numeric-field-value req 'content-length)))
(or maybe-length
(fatal-syntax-error "No Content-Length header in request"))))
;; GET-NUMERIC-FIELD-VALUE
;; generalized function to get a field value of the form 1*DIGIT
;; req is a request record, field-name a symbol
;; check wether a header-field with name field-name is contained in req;
;; if not, return #f,
;; else, take the first such header field and check wether its field-content conforms to
;; field-content = *LWS 1*DIGIT *LWS
;; if so, return digit as a number
(define (get-numeric-field-value req field-name)
(let
;;try to get first "field-name" header
((field-content (get-header (request-headers req) field-name)))
(if field-content ;; request contained "field-name" header
(let ;;see * below
((field-value (string->number (string-trim-both field-content char-set:blank)))) ;;char-set:blank = Space + Tab = LWS from RFC2616 after folding
(if (and field-value (>= field-value 0)) ;;yes, field value contained only digits.
field-value
(fatal-syntax-error
(format #f
"~A header contained only whitespace, or characters other than digits, or whitespace between digits"
field-name))))
#f)))
;;* RFC 2616, 4.2: The field-content does not include any leading or
;;trailing LWS: linear white space occurring before the first
;;non-whitespace character of the field-value or after the last
;;non-whitespace character of the field-value. Such leading or
;;trailing LWS MAY be removed without changing the semantics of the
;;field value.
;;(probably read-rfc822-headers in rfc822.scm should do the job of skipping leading and trailing whitespace?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Decoding chunked entity bodies: "chunked transfer-coding"
;;; Is the request's entity body sent in chunked transfer-encoding?
;;; (See RFC 2616, 14.41 and 3.6 for syntax and semantics of Transfer-Encoding header.)
(define (chunked-transfer-coding? req)
(let ((field-value (get-header (request-headers req) 'transfer-encoding)))
(if (not field-value)
#f
; the field value is a comma-separated list of transfer-codings (3.6),
; extract the last transfer-coding in the list
(let* ((reversed-field-value (string-reverse field-value))
(index ; does the list contain more than one element?
(string-contains reversed-field-value " ,"))
(last-transfer-coding
(if index
(string-trim (string-reverse (string-take reversed-field-value index)))
(string-trim field-value))))
; the first token of the (extracted last) transfer-coding must be "chunked" to indicate chunked transfer coding
(string-prefix? "chunked" last-transfer-coding)))))
;;; Read in the chunked entity body, return it as a string.
;;; (See RFC 2616, 3.6.1 and 19.4.6 for the composition of chunked entity bodies.)
(define (read-chunked-body inport)
(let read-chunks ((chunk-size (get-chunk-size inport))
(res ""))
(if (= 0 chunk-size) ;last-chunk
(begin (discard-trailer inport); see comment *1
res)
(let ((maybe-chunk-data (read-string chunk-size inport)))
(if maybe-chunk-data
(begin (discard-line-terminator inport)
(read-chunks (get-chunk-size inport) (string-append res maybe-chunk-data)))
(fatal-syntax-error "EOF while reading in chunk-data in chunked entity body"))))))
;comment *1:
;
;This is were we don't achieve conditional compliance: we ought to read
;in the entity-headers in the trailer and incorporate them into the
;request record. Within our current scheme (where reading in the
;entity-body is the request-handlers job - while the request-handler
;is only called _after_ the request record has been built) this is not
;possible.
;
;Note that in their current state (04/2005) the handlers actually
;disregard most request headers anyway (even the request headers
;parsed into the request record).
;
;Alternatively we could check the request for a Trailer header and
;respond with 500 if we find one. Problem here: the clients "SHOULD
;include a Trailer header field in a message using chunked
;transfer-coding with a non-empty trailer" (14.40) - they are not
;obliged to! So even if we check for a Trailer header we may still
;silently disregard a trailer.
;;;Read in a chunk-size line within a chunked entity body; return the chunk-size as an integer.
;;; (See RFC 2616, 3.6.1 and 19.4.6 for the composition of chunked entity bodies.)
(define (get-chunk-size inport)
(let ((chunk-size-line (read-crlf-line inport)))
(if (eof-object? chunk-size-line)
(fatal-syntax-error "EOF while reading in chunk-size in chunked entity body")
(let* ((chunk-extensions-index (string-contains chunk-size-line "; "))
(hex-string (if chunk-extensions-index
(string-take chunk-size-line chunk-extensions-index)
chunk-size-line))
(chunk-size-int (string->number (string-trim-both hex-string char-set:blank) 16)))
(if (and chunk-size-int (>= chunk-size-int 0)) ; yes, chunk-size contained only hex chars
chunk-size-int
(fatal-syntax-error "Chunk-size within chunked entity body is incorrect or syntactically faulty"))))))
(define (discard-trailer inport)
(with-fatal-error-handler
(lambda (c decline)
(fatal-syntax-error "Illegal RFC 822 field syntax within trailer of entity message body"))
(read-rfc822-headers inport)))
(define (discard-line-terminator inport)
(read-char inport) (read-char inport)) ;;assuming the line terminator is CRLF as required by RFC 2616
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Misc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; interpolate host info from our request's net connection.
;; return string. Example: "134.2.12.72:7777"
(define (get-socket-host-string req)
(let ((addr (socket-local-address (request-socket req))))
(call-with-values
(lambda ()(socket-address->internet-address addr))
(lambda (ipaddr portnum)
(string-append (format-internet-host-address ipaddr) ":" (number->string portnum))))))
+93
View File
@@ -0,0 +1,93 @@
;;; http server in the Scheme Shell -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1995 by Olin Shivers.
;;; Copyright (c) 1996-2002 by Mike Sperber.
;;; Copyright (c) 2002 by Andreas Bernauer.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; Path handlers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Path handlers are the guys that actually perform the requested operation
;;; on the URL. The handler interface is
;;; (handler path-list request)
;;; The path-list is a URL path list that is a suffix of REQUEST's url's
;;; path-list. Path handlers can decide how to handle an operation by
;;; recursively keying off of the elements in path-list.
;;;
;;; The object-oriented view:
;;; One way to look at this is to think of the request's METHOD as a
;;; generic operation on the URL. Recursive request handlers do method
;;; lookup to determine how to implement a given operation on a particular
;;; path.
;;;
;;; The REQUEST is a request record, as defined in request.scm, containing
;;; the details of the client request.
;; general request handler combinator:
;; predicate: path x request --> boolean
;; if #t, handler is called
;; if #f, default-handler is called
(define (make-predicate-handler predicate handler default-handler)
(lambda (path req)
(if (predicate path req)
(handler path req)
(default-handler path req))))
;; same as MAKE-PREDICATE-HANDLER except that the predicate is only
;; called with the path:
;; predicate: path --> boolean
(define (make-path-predicate-handler predicate handler default-handler)
(make-predicate-handler
(lambda (path req) (predicate path)) handler default-handler))
;; selects handler according to host-field of http-request
(define (make-host-name-handler hostname handler default-handler)
(make-predicate-handler
(lambda (path req)
;; we expect only one host-header-field
(let ((maybe-val (get-header (request-headers req) 'host)))
(if maybe-val
(let ((val (string-trim maybe-val)))
(or (string-ci=? hostname val)
(string-prefix-ci? (string-append hostname ":") val)))
(http-error (status-code bad-request) req "No Host: header"))))
handler default-handler))
;; selects handler according to path-prefix
;; if path-prefix matches, handler is called without the path-prefix
(define (make-path-prefix-handler path-prefix handler default-handler)
(lambda (path req)
(if (and (pair? path) (string=? path-prefix (car path)))
(handler (cdr path) req)
(default-handler path req))))
;;; (alist-path-dispatcher handler-alist default-handler) -> handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This function creates a table-driven request handler that dispatches off
;;; of the car of the request path. The handler uses the car to index into
;;; a request handler alist. If it finds a hit, it recurses using the table's
;;; request handler. If no hits, it handles the path with a default handler.
;;; An alist handler is passed the tail of the original path; the
;;; default handler gets the entire original path.
;;;
;;; This procedure is how you say: "If the first element of the URL's
;;; path is 'foo', do X; if it's 'bar', do Y; otherwise, do Z."
(define (alist-path-dispatcher handler-alist default-handler)
(fold-right
(lambda (handler-pair default-handler)
(make-path-prefix-handler
(car handler-pair)
(cdr handler-pair)
default-handler))
default-handler
handler-alist))
;;; The null request handler -- handles nothing, sends back an error response.
;;; Can be useful as the default in table-driven request handlers.
(define (null-request-handler path req)
(make-error-response (status-code not-found) req))
+663
View File
@@ -0,0 +1,663 @@
;;; GNU info -> HTML gateway for the SU web server. -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1996 by Mike Sperber.
;;; based on code with the same purpose by Gaebe Engelhart
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; (info-handler parse-info reference find-icon address) -> handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This function creates a request handler that converts GNU info pages
;;; on-the-fly. It is highly parameterizable to accomodate a wide
;;; range of environments. The parameters specify how to find the
;;; source code for the info pages, and how to generate certain
;;; elements of the generated HTML output.
;;;
;;; PARSE-INFO specifies how to parse the URLs that end up in the
;;; handler.
;;; It can be:
;;;
;;; * a procedure which is called with the URL as its parameters.
;;; It is expected to return with two values, FIND-ENTRY and
;;; NODE-NAME. FIND-ENTRY, in turn, can be either a procedure
;;; which gets passed the file name of an info node and is
;;; supposed to return with an absolute name of same. If it is a
;;; list, that list is taken as a list of directories in which to
;;; search for the info files. NODE-NAME is supposed to be the
;;; name of an info node of the form (<file>)<node>, extracted
;;; from the URL.
;;;
;;; * a list, in which case that is taken as a list of
;;; directories in which to search for the info files. The node
;;; name of a node is extracted from the URL by just taking the
;;; search component of the URL.
;;;
;;; * #f in which case the info path is taken from the environment
;;; variable INFOPATH, and the node name extraction works as
;;; above.
;;;
;;; REFERENCE specifies how to generate cross-references to other info
;;; nodes. It can be:
;;;
;;; * a procedure which gets called with the URL of the info page
;;; which contains the reference, and the node name of the node
;;; to be referenced. The procedure is expected to return the
;;; text for a link.
;;;
;;; * a string, in which case that is to be a prefix to which the
;;; node name is simply appended to yield the new link.
;;;
;;; * #f in which case all references have the form
;;; info?<node-name>.
;;;
;;; FIND-ICON specifies to to find the various icons used to decorate
;;; info pages. It can be:
;;;
;;; * a procedure which gets passed one of the tags in
;;; DEFAULT-ICON-ALIST and is supposed to return a link for the
;;; appropriate icon (or #f if no icon is to be used)
;;;
;;; * a string which is taken as a prefix to which one of the
;;; appropriate icon name from DEFAULT-ICON-ALIST is appended.
;;; (Note that these icon names were stolen from the
;;; cern-httpd-3.0 distribution at
;;; http://www.w3.org/pub/WWW/Daemon/.)
;;;
;;; * a list which is taken as an alist of the same format as
;;; DEFAULT-ICON-ALIST.
;;;
;;; * #f in which case no icons are used.
;;;
;;; ADDRESS a string to be appended at the bottom of all info pages
;;;
;;; To install a vanilla info handler for a prefix "info?" that looks
;;; in the environment variable INFOPATH, just use something like
;;; (info-handler #f #f #f "Generated by info-gateway")
;;; TODO: write a CGI version of this
(define-condition-type 'info-gateway-error '(error))
(define info-gateway-error? (condition-predicate 'info-gateway-error))
(define (info-gateway-error msg . irritants)
(apply signal 'info-gateway-error msg irritants))
(define default-icon-alist
'((info . "infodoc.gif")
(up . "up.gif")
(next . "next.gif")
(previous . "prev.gif")
(menu . "menu.gif")))
(define (info-handler parse-info reference find-icon address)
(let ((icon-name
(cond
((procedure? find-icon) find-icon)
((string? find-icon)
(let ((alist
(map (lambda (entry)
(cons (car entry)
(string-append find-icon (cdr entry))))
default-icon-alist)))
(lambda (tag)
(cond ((assq tag alist) => cdr)
(else #f)))))
((list? find-icon)
(lambda (tag)
(cond ((assq tag find-icon) => cdr)
(else #f))))
(else (lambda (tag) #f))))
(parse-info-url
(cond
((procedure? parse-info) parse-info)
((list? parse-info) ; it's an info path
(lambda (url)
(values parse-info
(unescape (http-url-query url)))))
(else
(let ((info-path
((infix-splitter ":")
(or (getenv "INFOPATH")
(begin
(format (current-error-port)
"~%Warning: environment variable INFOPATH is unset.~%")
"")))))
(lambda (url)
(values info-path
(unescape (http-url-query url))))))))
(make-reference
(cond
((procedure? reference) reference)
((string? reference)
(lambda (url node-name)
(string-append reference node-name)))
(else
(lambda (url node-name)
(string-append "info?" node-name))))))
(lambda (path req)
(let ((request-method (request-method req)))
(cond
((string=? request-method "GET")
(with-fatal-error-handler
(lambda (c decline)
(cond
((info-gateway-error? c)
(apply http-error (status-code bad-gateway) req
(condition-stuff c)))
((http-error? c)
(apply http-error (car (condition-stuff c)) req
(cddr (condition-stuff c))))
(else
(decline))))
(make-response
(status-code ok)
#f
(time)
"text/html"
'()
(make-writer-body
(lambda (out options)
(emit-prolog out)
(receive (find-entry node-name) (parse-info-url (request-url req))
(display-node node-name
(file-finder find-entry)
(referencer make-reference (request-url req) out)
icon-name
out))
(with-tag out address ();; this is outside the html element?
(write-string address out)))))))
((or (string=? request-method "HEAD")
(string=? request-method "POST"))
(make-error-response (status-code method-not-allowed) req
"GET"))
(else
(make-error-response (status-code not-implemented) req)))))))
(define split-header-line
(let ((split (infix-splitter (make-regexp "(, *)|( +)|( *\t *)")))
(split-field (infix-splitter (make-regexp ": *"))))
(lambda (l)
(let ((fields (map split-field (split l))))
(define (search-field regexp)
(cond
((find (lambda (field)
(string-match regexp (car field)))
fields)
=> cadr)
(else #f)))
(values (search-field "[F|f]ile")
(search-field "[N|n]ode")
(search-field "[U|u]p")
(search-field "[P|p]rev(ious)?")
(search-field "[N|n]ext"))))))
(define (replace-if-empty-string s v)
(if (zero? (string-length s))
v
s))
(define (string-newline->space s)
(string-map (lambda (c)
(if (char=? c #\newline)
#\space
c))
s))
(define (parse-node-name node-name)
(cond
((string-match "^\\((.*)\\)(.*)$" (string-newline->space node-name))
=> (lambda (match)
(values
(replace-if-empty-string (match:substring match 1) #f)
(replace-if-empty-string (match:substring match 2) "Top"))))
(else (values #f (string-newline->space node-name)))))
(define (unparse-node-name file node)
(let* ((ext (file-name-extension file))
(file (if (string=? ext ".info")
(file-name-sans-extension file)
file)))
(receive (file node) (if (and (string=? "dir" file)
(not (string=? "" node))
(not (string=? "Top" node)))
(values node "Top")
(values file node))
(string-append "(" file ")" node))))
(define (display-icon file alt out)
(emit-empty-tag out 'img
(cons 'src file)
(cons 'alt alt)
(cons 'align "bottom")))
(define (referencer make-reference old-entry out)
(lambda (file node-name label . maybe-icon)
(receive (node-file node) (parse-node-name node-name)
(let ((file (or node-file file)))
(with-tag out a ((href (make-reference
old-entry
(escape-not-unreserved-chars (unparse-node-name file node)))))
(if (and (not (null? maybe-icon))
(car maybe-icon))
(display-icon (car maybe-icon) (cadr maybe-icon) out))
(emit-text label out))))))
(define node-prologue (ascii->char 31))
(define node-epilogue-regexp
(make-regexp
(string-append (regexp-quote (string node-prologue))
"|"
(regexp-quote (string (ascii->char 12))))))
(define (string-starts-with-char? s c)
(and (not (zero? (string-length s)))
(char=? c (string-ref s 0))))
(define (node-prologue? s)
(string-starts-with-char? s node-prologue))
(define (node-epilogue? s)
(regexp-exec node-epilogue-regexp s))
;; Document title
(define (display-title file node up previous next
display-reference icon-name out)
(define (maybe-display-header header icon alt)
(if header
(begin
(newline out)
(with-tag out b ()
(display-reference file header header icon alt)))))
(emit-title out (string-append "Info Node: "
(unparse-node-name file node)))
(with-tag out h1 ()
(emit-empty-tag out 'img
(cons 'src (icon-name 'info))
(cons 'alt "Info Node")
(cons 'align 'bottom))
(write-string (unparse-node-name file node) out))
(emit-empty-tag out 'hr)
(maybe-display-header next (icon-name 'next) "[Next]")
(maybe-display-header previous (icon-name 'previous) "[Previous]")
(maybe-display-header up (icon-name 'up) "[Up]")
(if (or next previous up)
(emit-empty-tag out 'hr)))
;; Text
;; Dealing with cross references
;; info sucks
(define xref-marker-regexp (make-regexp "\\*[Nn]ote([ \n]|$)"))
(define xref-regexp (make-regexp "\\*[Nn]ote *([^:]*): *([^\t\n,.;:?!]*)"))
(define max-xref-lines 3)
(define complete-line
(let ((split-xref-markers (field-splitter xref-marker-regexp))
(split-xrefs (field-splitter xref-regexp))
(cr (string #\newline)))
(lambda (line port)
(let loop ((line line) (count max-xref-lines))
(let ((xref-markers (split-xref-markers line))
(xrefs (split-xrefs line)))
(if (= (length xref-markers) (length xrefs))
line
(if (zero? count)
(info-gateway-error "invalid cross reference")
(let ((new-line (read-line port)))
(if (eof-object? new-line)
(info-gateway-error
"unexpected end of info file inside cross reference"))
(loop (string-append line cr new-line) (- count 1))))))))))
(define (display-xref xref file display-reference out)
(let* ((match (regexp-exec xref-regexp xref))
(note (match:substring match 1))
(node-name (match:substring match 2))
(node-name (if (string=? "" node-name) note node-name))
(node-name (substring node-name
(string-skip node-name char-set:whitespace)
(string-length node-name))))
(emit-text "See " out)
(display-reference file node-name note)))
(define display-text
(let ((split-xrefs (infix-splitter xref-regexp #f 'split)))
(lambda (line port file display-reference out)
(let* ((line (complete-line line port))
(components (split-xrefs line)))
;; in components, every 2nd element is a cross reference
;; also, it always has odd length or length zero
(if (not (null? components))
(let loop ((components components))
(emit-text (car components) out)
(if (not (null? (cdr components)))
(begin
(display-xref (cadr components) file display-reference out)
(loop (cddr components))))))
(newline out)))))
;; Menus
(define menu-regexp (make-regexp "^\\* +Menu:"))
(define menu-item-regexp (make-regexp "^\\* +"))
(define (char-splitter c)
(lambda (s)
(cond ((string-index s c)
=> (lambda (i)
(values (substring s 0 i)
(substring s (+ 1 i) (string-length s)))))
(else (values s "")))))
(define colon-split (char-splitter #\:))
(define (display-menu-item-header line port file display-reference icon-name out)
(let ((menu-line-split (infix-splitter menu-item-regexp)))
(receive (note rest) (colon-split (cadr (menu-line-split line)))
(receive (node-name text)
(cond
((string-match ": *(.*)" rest)
=> (lambda (match)
(values note (match:substring match 1))))
((string-match "^ *([^.]*)\\.? *(.*)" rest)
=> (lambda (match)
(values (match:substring match 1)
(match:substring match 2))))
(else
(info-gateway-error "invalid menu item")))
(emit-tag out 'dt)
(display-reference file node-name note (icon-name 'menu) "*")
(newline out)
(if (and (not (string=? "" text))
(not (string=? "." text)))
(begin
(emit-tag out 'dd)
(display-text text port file display-reference out)))))))
(define (display-menu line port file display-reference icon-name out)
(emit-close-tag out 'pre)
(with-tag out dl ()
(let loop ((line line))
(if (eof-object? line)
(info-gateway-error "unexpected end of info file"))
(display-menu-item-header line port file display-reference icon-name out)
(let finish-item-loop ()
(if (eof-object? line)
(info-gateway-error "unexpected end of info file"))
(let ((line (read-line port)))
(cond
((or (eof-object? line)
(node-epilogue? line)
(string=? "" line))
(emit-tag out 'pre)
(dispatch-line line port file display-reference icon-name out))
((regexp-exec menu-item-regexp line)
(loop line))
(else
(display-text line port file display-reference out)
(finish-item-loop))))))))
;; Central dispatch
(define (dispatch-line line port file display-reference icon-name out)
(cond
((or (eof-object? line) (node-epilogue? line)) #f)
((string=? "" line) (emit-p out) #t)
((regexp-exec menu-regexp line) #t) ;; this should probably be expanded
((regexp-exec menu-item-regexp line)
(display-menu line port file display-reference icon-name out))
(else
(display-text line port file display-reference out) #t)))
(define (display-body port file display-reference icon-name out)
(let loop ()
(let ((line (read-line port)))
(if (dispatch-line line port file display-reference icon-name out)
(loop)))))
(define (display-node node-name find-file display-reference icon-name out)
(receive (file node) (parse-node-name node-name)
(receive (port file-header node-header up-header prev-header next-header)
(find-node file node find-file)
(with-tag out html (xmlnsdecl-attr)
(with-tag out head ()
(display-title file node-header up-header
prev-header next-header
display-reference icon-name
out))
(with-tag out body ()
(with-tag out pre ()
(display-body port file display-reference icon-name out))))
(close-input-port port))))
;; Finding nodes
(define (ensure-node-prologue port msg)
(let ((line (read-line port)))
(if (or (eof-object? line)
(not (node-prologue line)))
(info-gateway-error "invalid info file" msg))))
(define (ensure-regexp-line port regexp msg)
(let ((line (read-line port)))
(if (or (eof-object? line)
(not (string-match regexp line)))
(info-gateway-error "invalid info file" msg))))
(define (ensure-tag-table-node port)
(ensure-regexp-line port "^Tag Table:" "no tag table"))
(define (ensure-indirect-tag-table-header port)
(ensure-regexp-line port "^\\(Indirect\\)" "no indirect tag"))
(define split-indirection (infix-splitter (make-regexp " *: *")))
(define (parse-indirection line)
(let ((l (split-indirection line)))
(if (null? (cdr l))
(info-gateway-error "invalid indirection entry in info file")
(let ((file (car l))
(seek-pos (string->number (cadr l))))
(if (not seek-pos)
(info-gateway-error "invalid indirection entry in info file"))
(cons file seek-pos)))))
(define (read-indirection-table port)
(let loop ((table '()))
(let ((line (read-line port)))
(if (eof-object? line)
(info-gateway-error "invalid info file"))
(if (node-epilogue? line)
(reverse table)
(loop (cons (parse-indirection line) table))))))
(define tag-seek-separator (ascii->char 127))
(define parse-tag
(let ((split (infix-splitter (make-regexp ", *")))
(split-field (infix-splitter ": "))
(split-node-info
(infix-splitter (string tag-seek-separator))))
(define (barf)
(info-gateway-error "invalid tag entry in info file"))
(lambda (line)
(let* ((fields (map split-field (split line)))
(file (cond
((assoc "File" fields)
=> (lambda (p)
(if (null? (cdr p)) (barf))
(cadr p)))
(else #f))))
(cond
((assoc "Node" fields)
=> (lambda (p)
(if (null? (cdr p)) (barf))
(let ((s (split-node-info (cadr p))))
(if (null? (cdr p)) (barf))
(let* ((node (car s))
(seek (string->number (cadr s))))
(if (not seek) (barf))
(values node file seek)))))
(else (barf)))))))
(define (find-tag node port)
(let loop ()
(let ((line (read-line port)))
(if (eof-object? line)
(info-gateway-error "invalid info file"))
(if (regexp-exec node-epilogue-regexp line)
(http-error (status-code not-found) #f "node not found"))
(receive (entry-node file seek) (parse-tag line)
(if (string=? node entry-node)
(cons file seek)
(loop))))))
(define (find-indirection-entry seek-pos indirection-table)
(let loop ((table indirection-table))
(if (null? table)
(http-error (status-code not-found) #f "node not found"))
(let* ((entry (car table))
(pos (cdr entry)))
(if (and (>= seek-pos pos)
(or (null? (cdr table))
(let* ((next-entry (cadr table))
(next-pos (cdr next-entry)))
(< seek-pos next-pos))))
entry
(loop (cdr table))))))
(define (file-finder with)
(cond ((procedure? with) with)
((list? with)
(lambda (file)
(find-info-file file with)))))
(define (find-node-port-with-tag-entry node tag-entry ? find-file)
(let* ((port (if (input-port? ?) ? #f))
(indirection-table (if port #f ?))
(seek-pos (cdr tag-entry))
(indirection-entry
(and indirection-table
(find-indirection-entry seek-pos indirection-table)))
(seek-pos (if indirection-entry
(- seek-pos (cdr indirection-entry))
seek-pos))
;; that's what the documentation says ...
(seek-pos (if (>= seek-pos 1000)
(- seek-pos 1000)
0))
(file (or (car tag-entry)
(and indirection-entry
(car indirection-entry))))
(port (if file
(begin
(if port (close-input-port port))
(open-input-file (find-file file)))
port)))
(seek port seek-pos)
port))
(define (find-node file node find-file)
(if (not file)
(http-error (status-code not-found) #f
"no file in info node specification"))
(let* ((fname (find-file file))
(port (open-input-file fname)))
(let loop ((port port))
(let ((line (read-line port)))
(if (eof-object? line)
(http-error (status-code not-found) #f "info node not found"))
(if (node-prologue? line)
(let ((header (read-line port)))
(if (eof-object? header)
(info-gateway-error "invalid info file"))
(cond
((string-match "^Indirect:" header)
(let ((indirection-table
(read-indirection-table port)))
(ensure-tag-table-node port)
(ensure-indirect-tag-table-header port)
(let ((tag-entry (find-tag node port)))
(close-input-port port)
(loop (find-node-port-with-tag-entry
node tag-entry indirection-table find-file)))))
((string-match "^Tag Table:" header)
(let ((tag-entry (find-tag node port)))
(loop (find-node-port-with-tag-entry
node tag-entry port find-file))))
((string-match "^File:" header)
(receive
(file-header node-header up-header prev-header next-header)
(split-header-line header)
(if (string=? node-header node)
(values port
file-header node-header
up-header prev-header next-header)
(loop port))))
(else (loop port))))
(loop port))))))
;; Finding files
(define (info-file-alternative-names file)
(receive (dir base ext) (parse-file-name file)
(let* ((base
(cond ((string-match "(.*)-info$" base)
=> (lambda (match)
(match:substring match 1)))
(else base)))
(base-ci (string-map char-downcase base))
(alts-1 (if (string=? base base-ci)
(list base)
(list base base-ci)))
(alts (append alts-1
(map (lambda (base)
(string-append base ".info"))
alts-1)))
(alts (append alts
(map (lambda (base)
(string-append base "-info"))
alts-1)))
(alts (map (lambda (f) (string-append dir f)) alts))
(alts (cons file alts)))
alts)))
(define (find-info-file file info-path)
(let ((alts (info-file-alternative-names file)))
(let path-loop ((path info-path))
(if (null? path)
(http-error (status-code not-found) #f "info file not found"))
(let alt-loop ((alts alts))
(if (null? alts)
(path-loop (cdr path))
(let ((try (string-append (file-name-as-directory (car path))
(car alts))))
(if (file-exists? try)
try
(alt-loop (cdr alts)))))))))
+206
View File
@@ -0,0 +1,206 @@
;;; logging.scm
;;; logging functionality for web server
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 2002 by Martin Gasbichler.
;;; Copyright (c) 2002 by Andreas Bernauer.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
(define do-nothing-proc (lambda a #f))
(define-record-type logging :logging
(really-make-logging log-port log-proc
syslog? syslog-proc
dns-lookup?)
logging?
;; port to perform CLF-logging
(log-port logging-log-port set-logging-log-port!)
;; proc to run for CLF-logging (req status-code)
(log-proc logging-log-proc set-logging-log-proc!)
;; do syslogging?
(syslog? logging-syslog? set-logging-syslog?!)
;; proc to run for syslog (level fmt . args)
(syslog-proc logging-syslog-proc set-logging-syslog-proc!)
;; perform dns lookups?
(dns-lookup? logging-dns-lookup? set-logging-dns-lookup?!))
(define (make-logging)
(really-make-logging #f
do-nothing-proc
#f
do-nothing-proc
#f))
(define logging (make-preserved-thread-fluid #f))
(define (make-fluid-selector selector)
(lambda () (selector (thread-fluid logging))))
(define (make-fluid-setter setter)
(lambda (value)
(setter (thread-fluid logging) value)))
(define logging-http-log-proc (make-fluid-selector logging-log-proc))
(define logging-http-syslog-proc (make-fluid-selector logging-syslog-proc))
(define logging-http-syslog? (make-fluid-selector logging-syslog?))
(define logging-http-log-port (make-fluid-selector logging-log-port))
(define logging-dns-lookup? (make-fluid-selector logging-dns-lookup?))
(define set-logging-http-log-proc (make-fluid-setter set-logging-log-proc!))
(define set-logging-http-syslog-proc (make-fluid-setter set-logging-syslog-proc!))
(define set-logging-http-syslog? (make-fluid-setter set-logging-syslog?!))
(define set-logging-http-log-port (make-fluid-setter set-logging-log-port!))
(define set-logging-dns-lookup? (make-fluid-setter set-logging-dns-lookup?!))
(define http-syslog
(lambda a
(apply (logging-http-syslog-proc) a)))
(define http-log
(lambda a
(apply (logging-http-log-proc) a)))
(define (http-syslog?)
(logging-http-syslog?))
(define (init-http-log! options)
;; syslog has to be initialized before CLF-logging
;; because the latter may generate syslog-messages
(init-http-syslog! (httpd-options-syslog? options))
(init-http-port-log! (httpd-options-log-file options))
(if (httpd-options-resolve-ips? options)
(set-logging-dns-lookup? #t)
(set-logging-dns-lookup? #f)))
(define (init-http-syslog! syslog?)
(if syslog?
(let ((http-syslog-lock (make-lock)))
(set-logging-http-syslog? #t)
(set-logging-http-syslog-proc
(lambda (level fmt . args)
(with-lock http-syslog-lock
(lambda ()
(syslog level
(apply format #f fmt args)))))))
(begin
(set-logging-http-syslog? #f)
(set-logging-http-syslog-proc do-nothing-proc))))
(define (init-http-port-log! log-file)
(let ((logport
(cond
((string? log-file) ; try to open log-file for appending (output)
(open-log-file log-file))
((output-port? log-file) ; we were given an output port, so let's use it
log-file)
((eq? log-file #f) ; no logging demanded
#f)
; unexpected value of log-file;
(else
(http-syslog
(syslog-level warning)
"[httpd] Warning: Log-File was not specified correctly (given: ~S).~% No CLF logging."
log-file)
(make-null-output-port)))))
(if log-file ; if logging was specified, set up the logger
(let ((http-log-lock (make-lock)))
(set-logging-http-log-port logport)
(if (string? log-file)
(spawn (make-log-file-rotator log-file http-log-lock)))
(set-logging-http-log-proc (make-http-log-proc http-log-lock))))))
(define (make-http-log-proc http-log-lock)
(lambda (req status-code)
(if req
(with-lock http-log-lock
(lambda ()
(display (make-CLF
(receive (host-address _)
(socket-address->internet-address
(socket-remote-address (request-socket req)))
(format-internet-host-address host-address))
(request-method req) ; request method
(http-url-path->path-string
(http-url-path (request-url req))) ; requested file (escaped as it was in original request)
(version->string (request-version req)) ; protocol version
(status-code-number status-code)
23 ; filesize (unknown)
(get-header (request-headers req) 'referer)
(get-header (request-headers req) 'user-agent))
(logging-http-log-port))
(force-output (logging-http-log-port)))))))
(define (get-header headers tag)
(cond
((assq tag headers) => cdr)
(else #f)))
;; does the log-file rotation on signal USR1
(define (make-log-file-rotator log-file http-log-lock)
(set-interrupt-handler interrupt/usr1 #f)
(lambda ()
(on-interrupt
interrupt/usr1
(lambda ()
(with-lock http-log-lock
(lambda ()
(close-output-port (logging-http-log-port))
(set-logging-http-log-port (open-log-file log-file))))))))
(define (open-log-file log-file)
(with-errno-handler*
(lambda (errno packet)
(http-syslog (syslog-level warning)
"[httpd] Warning: An error occured while opening ~S for writing (~A).~%Send signal USR1 when the problem is fixed.~%"
log-file
(car packet))
(make-null-output-port))
(lambda ()
(open-output-file log-file
(bitwise-ior open/create open/append)))))
; returns a string for a CLF entry (Common Log Format)
; note: till now, we do not log the user's time zone code
(define (make-CLF remote-ip request-type requested-file protocol http-code filesize referer user-agent)
(format #f "~A - - ~A ~S ~A ~A ~S ~S~%"
(or (maybe-dns-lookup remote-ip) "-")
(format-date "[~d/~b/~Y:~H:~M:~S +0000]" (date)) ; +0000 as we don't know
(string-join (list request-type
requested-file
protocol))
; Unfortunately, we first split the request line into
; method/request-type etc. and put it together here.
; Files conform to CLF are expected to print the original line.
; --> Shouldn't be a problem: the original request
; line is reconstructed almost completely:
; requested-file (i.e. http-url->url-string url) is
; exactly the original Request_URI (apart from
; multiple slashes, which are thrown away),
; request-type and protocol are the original.
; --> Only number of slashes in Request_URI and
; whitespace between parts of Request-Line can differ.
(or http-code "-")
(or filesize "-")
(if (string? referer) (string-trim referer) '-)
(if (string? user-agent)
(string-trim user-agent char-set:whitespace)
'-)))
(define (maybe-dns-lookup remote-ip)
(if (logging-dns-lookup?)
(or (with-fatal-error-handler*
(lambda (condition decline)
(http-syslog (syslog-level debug)
"An error occured while resolving IP ~A: ~A"
remote-ip condition)
remote-ip)
(lambda ()
(dns-lookup-ip remote-ip)))
remote-ip)
remote-ip))
+131
View File
@@ -0,0 +1,131 @@
;;; http server in the Scheme Shell -*- Scheme -*-
;;; 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.
;;; 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
request-handler
server-admin
simultaneous-requests
log-file
syslog?
resolve-ips?
post-bind-thunk)
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!)
(request-handler httpd-options-request-handler
set-httpd-options-request-handler!)
(server-admin httpd-options-server-admin
set-httpd-options-server-admin!)
(simultaneous-requests httpd-options-simultaneous-requests
set-httpd-options-simultaneous-requests!)
(log-file httpd-options-log-file set-httpd-options-log-file!)
(syslog? httpd-options-syslog? set-httpd-options-syslog?!)
(resolve-ips? httpd-options-resolve-ips? set-httpd-options-resolve-ips?!)
(post-bind-thunk httpd-options-post-bind-thunk set-httpd-options-post-bind-thunk!))
; default httpd-options generation
(define (make-default-httpd-options)
(really-make-httpd-options 80 ; port
"/" ; root-directory
#f ; fqdn
#f ; reported-port
#f ; request-handler
#f ; server-admin
#f ; simultaneous-requests
#f
; string: filename of log-file (directory must exist)
; output-port: log to this port (e.g. (current-error-port))
; #f: no logging
#t ; Do syslogging?
#t ; Write host names instead of IPs in log-files?
#f)) ; post-bind-thunk
; creates a copy of a given httpd-option
(define (copy-httpd-options options)
(let ((new-options (make-default-httpd-options)))
(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))
(set-httpd-options-request-handler! new-options
(httpd-options-request-handler options))
(set-httpd-options-server-admin! new-options
(httpd-options-server-admin options))
(set-httpd-options-simultaneous-requests!
new-options
(httpd-options-simultaneous-requests options))
(set-httpd-options-log-file! new-options (httpd-options-log-file options))
(set-httpd-options-syslog?! new-options (httpd-options-syslog? options))
(set-httpd-options-resolve-ips?! new-options (httpd-options-resolve-ips? options))
(set-httpd-options-post-bind-thunk! new-options
(httpd-options-post-bind-thunk options))
new-options))
; (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
(define (make-httpd-options-transformer set-option!)
(lambda (new-value . stuff)
(let ((new-options (if (not (null? stuff))
(copy-httpd-options (car stuff))
(make-default-httpd-options))))
(set-option! new-options new-value)
new-options)))
; several transformers for port, root-directory, etc.
(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!))
(define with-request-handler
(make-httpd-options-transformer set-httpd-options-request-handler!))
(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!))
(define with-log-file
(make-httpd-options-transformer set-httpd-options-log-file!))
(define with-syslog?
(make-httpd-options-transformer set-httpd-options-syslog?!))
(define with-resolve-ips?
(make-httpd-options-transformer set-httpd-options-resolve-ips?!))
(define with-post-bind-thunk
(make-httpd-options-transformer set-httpd-options-post-bind-thunk!))
(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))))))
+48
View File
@@ -0,0 +1,48 @@
;;;; HTTP request
;;; This file is part of the Scheme Untergrund Networking package.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;;; This code defines the http REQUEST data structure
(define-record-type request :request
(make-request method uri url version headers socket)
request?
(method request-method) ; A string such as "GET", "POST", etc.
(uri request-uri) ; The escaped URI string as read from request line.
(url request-url) ; An http URL record (see url.scm).
(version request-version) ; A (major . minor) integer pair.
(headers request-headers) ; An rfc822 header alist (see rfc822.scm).
(socket request-socket)) ; The socket connected to the client.
(define-record-discloser :request
(lambda (req)
(list 'request
(request-method req)
(request-uri req)
(request-url req)
(request-version req)
(request-headers req)
(request-socket req))))
;;; A http protocol version is an integer pair: (major . minor).
(define (version< v1 v2)
(or (< (car v1) (car v2))
(and (= (car v1) (car v2))
(< (cdr v1) (cdr v2)))))
(define (version<= v1 v2) (not (version< v2 v1)))
(define (v0.9-request? req)
(version<= (request-version req) '(0 . 9)))
(define (version->string v)
(string-append "HTTP/"
(number->string (car v))
"."
(number->string (cdr v))))
+360
View File
@@ -0,0 +1,360 @@
;;; This file is part of the Scheme Untergrund Networking package.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
(define http-version '(1 . 1));server's HTTP-version is only hardcoded here!
(define-record-type http-response :http-response
(make-response code message seconds mime extras body)
response?
(code response-code) ;;HTTP status code
(message response-message);;reason phrase: textual description of
;;status-code, or #f (-> server sends
;;default reason phrase)
(seconds response-seconds);;time the content was created
(mime response-mime);;string indicating the MIME type of the response
(extras response-extras);;assoc list with extra headers to be
;;added to the response; its elements are
;;pairs, each of which consists of a symbol
;;representing the field name and a string
;;representing the field value.
(body response-body));; message-body
;;TODO: mime shouldn't be a field in http-response, because it needn't be present for
;;responses which don't include a message-body.
;;Instead treat mime-type like any other header.
;;(Not urgent, as RFC 2616 doesn't prohibit presence of Content-Type header field
;;in body-less responses).
;; This is mainly for nph-... CGI scripts.
;; This means that the body will output the entire MIME message, not
;; just the part after the headers.
(define-record-type http-nph-response :http-nph-response
(make-nph-response body)
nph-response?
(body nph-response-body))
(define-record-type http-input-response :http-input-response
(make-input-response body-maker)
input-response?
(body-maker input-response-body-maker))
(define-record-type http-writer-body :http-writer-body
(make-writer-body proc)
writer-body?
(proc writer-body-proc))
;; the concept of http-reader-writer-body doesn't work: status-line
;; and headers of the response (i.e. the whole http-response record)
;; have to be built _before_ we have seen the entity-body of the
;; request. (Not until display-http-body hands over the iport to
;; reader-writer-body the entity-body can be read in). If the
;; entity-body is erroneous or if we encounter a server internal error
;; while reading in the entity-body we are not able to send an
;; appropriate response. (At that point of time we already sent
;; status-line and response-headers!)
(define-record-type http-reader-writer-body :http-reader-writer-body
(make-reader-writer-body proc)
reader-writer-body?
(proc reader-writer-body-proc))
(define-record-type http-redirect-body :http-redirect-body
(make-redirect-body location)
redirect-body?
(location redirect-body-location))
;; type for responses which MUST NOT include a body (101, 204, 304)
(define-enumerated-type no-body :no-body
no-body?
no-body-elements
no-body-name
no-body-index
(none))
(define (display-http-body body iport oport options)
(cond
((writer-body? body)
((writer-body-proc body) oport options))
((reader-writer-body? body)
((reader-writer-body-proc body) iport oport options))))
(define-finite-type status-code :http-status-code
(number message)
status-code?
status-codes
status-code-name
status-code-index
(number status-code-number)
(message status-code-message)
(
(continue 100 "Continue")
(switch-protocol 101 "Switching Protocols")
(ok 200 "OK")
(created 201 "Created")
(accepted 202 "Accepted")
(non-author-info 203 "Non-Authoritative Information")
(no-content 204 "No Content")
(reset-content 205 "Reset Content")
(partial-content 206 "Partial Content")
(mult-choice 300 "Multiple Choices")
(moved-perm 301 "Moved Permanently")
(found 302 "Found");;use 303 or 307 for unambiguity;
;;use 302 for compatibility with
;;pre-1.1-clients
(see-other 303 "See other");;client is expected to
;;perform a GET on new URI
(not-mod 304 "Not Modified")
(use-proxy 305 "Use Proxy")
(temp-redirect 307 "Temporary Redirect");;analogous to "302
;;Moved Temporarily"
;;in RFC1945
(bad-request 400 "Bad Request")
(unauthorized 401 "Unauthorized")
(payment-required 402 "Payment Required")
(forbidden 403 "Forbidden")
(not-found 404 "Not Found")
(method-not-allowed 405 "Method Not Allowed")
(not-acceptable 406 "Not Acceptable")
(proxy-auth-required 407 "Proxy Authentication Required")
(timeout 408 "Request Timeout")
(conflict 409 "Conflict")
(gone 410 "Gone")
(length-required 411 "Length Required")
(precon-failed 412 "Precondition Failed")
(req-ent-too-large 413 "Request Entity Too Large")
(req-uri-too-large 414 "Request URI Too Large")
(unsupp-media-type 415 "Unsupported Media Type")
(req-range-not-sat 416 "Requested Range Not Satisfiable")
(expectation-failed 417 "Expectation Failed")
(internal-error 500 "Internal Server Error")
(not-implemented 501 "Not Implemented")
(bad-gateway 502 "Bad Gateway")
(service-unavailable 503 "Service Unavailable")
(gateway-timeout 504 "Gateway Timeout")
(version-not-supp 505 "HTTP Version Not Supported")
(redirect -301 "Internal redirect")))
(define (name->status-code name)
(if (not (symbol? name))
(call-error name->status-code (list name))
(let loop ((i 0))
(cond ((= i (vector-length status-codes))
#f)
((eq? name
(status-code-name (vector-ref status-codes i)))
(vector-ref status-codes i))
(else
(loop (+ i 1)))))))
(define (number->status-code number)
(if (not (number? number))
(call-error number->status-code (list number))
(let loop ((i 0))
(cond ((= i (vector-length status-codes))
#f)
((= number
(status-code-number (vector-ref status-codes i)))
(vector-ref status-codes i))
(else
(loop (+ i 1)))))))
;;; (make-error-response status-code req [extras])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; As a special case, request REQ is allowed to be #f, meaning we haven't
;;; even had a chance to parse and construct the request. This can be the case for
;;; internal-error, bad-request, (possibly bad-gateway and ...?)
(define (make-error-response code req . extras)
(let*
;;catch server internal errors coming off by calls of make-error-response with too few arguments
((assert (lambda (n)
(if (< (length extras) n)
(make-error-response (status-code internal-error) req
"Too few arguments to make-error-response"))))
(generic-title (lambda (port)
(title-html port
(status-code-message code))))
(close-html (lambda (port args)
(if (not (null? args))
(format port "<br/>~%Further Information:~%"))
(for-each (lambda (x) (format port "<br/>~%~A~%" x)) args)
(format port "</p>~%</body>~%</html>~%")))
(create-response
(lambda (headers body)
(make-response code
#f
(time)
"text/html"
headers
body)))
(create-writer-body-response
(lambda (headers writer-proc)
(create-response headers (make-writer-body writer-proc))))
(create-no-body-response
(lambda (headers)
(create-response headers (no-body none)))))
(cond
;;this response requires one arg:
;;the value of the Upgrade field header,
;;which must be a string listing the protocols which are being switched
;;for example "HTTP/2.0, IRC/6.9"
((eq? code (status-code switch-protocol));; server currently doesn't have ability to switch protocols
(assert 1)
(create-no-body-response
(list (cons 'upgrade (car extras))
(cons 'connection "upgrade")))) ;; need this, because Upgrade header field only applies to immediate connection
((eq? code (status-code no-content))
(create-no-body-response '()))
;; This error response requires one arg:
;; the value of the Location field header,
;; which must be a single absolute URI
((or (eq? code (status-code found));302
(eq? code (status-code see-other));303
(eq? code (status-code temp-redirect));307
(eq? code (status-code moved-perm)));301
(assert 1)
(create-writer-body-response
(list (cons 'location (car extras)))
(lambda (port options)
(title-html port "Document moved")
(format port
"The requested resource has moved ~A to a <a href=\"~A\">new location</a>.~%"
(if (eq? code (status-code moved-perm))
"permanently"
"temporarily")
(car extras))
(close-html port (cdr extras)))))
((eq? code (status-code not-mod))
(create-no-body-response '())) ;;see RCF 2616 10.3.5: this is only a valid answer if the server never sends
;;any of the headers Expires, Cache-Control, Vary for this resource
((eq? code (status-code bad-request))
(create-writer-body-response
'()
(lambda (port options)
(generic-title port)
(format port "The request the client sent could not be understood by this server due to malformed syntax.~% Report to client maintainer.~%")
(close-html port extras))))
;; This error response requires one arg:
;; the value of the Allow field header,
;; which must be a string listing the valid methods for the requested resource
;; Ex.: "GET, HEAD, POST"
((eq? code (status-code method-not-allowed))
(assert 1)
(create-writer-body-response
(list (cons 'allow (car extras)))
(lambda (port options)
(generic-title port)
(format port "The method ~A is not allowed on the requested resource ~A.~%"
(request-method req) (http-url->url-string (request-url req)))
(close-html port (cdr extras)))))
;; This error response requires one arg:
;; the value of the WWW-Authenticate header field,
;; which must be a challenge (as described in RFC 2617)
((eq? code (status-code unauthorized))
(assert 1)
(create-writer-body-response
(list (cons 'WWW-Authenticate (car extras)))
(lambda (port options)
(title-html port "Authentication Required")
(format port "Client not authentication-capable or authentication failed.~%")
(close-html port (cdr extras)))))
((eq? code (status-code forbidden))
(create-writer-body-response
'()
(lambda (port options)
(title-html port "Request not allowed.")
(format port "The request the client sent is not allowed.~% Retrying won't help.~%")
(close-html port extras))))
((eq? code (status-code not-found))
(create-writer-body-response
'()
(lambda (port options)
(title-html port "Resource not found")
(format port "The requested resource ~A was not found on this server.~%"
(http-url->url-string (request-url req)))
(close-html port extras))))
((eq? code (status-code internal-error))
(create-writer-body-response
'()
(lambda (port options)
(generic-title port)
(format port "This server encountered an internal error or misconfiguration and was unable to complete your request.~%<br/>~%Please inform the server administrator ~A of the circumstances leading to the error, and the time it occured.~%"
(or (httpd-options-server-admin options)
"[no mail address available]"))
(close-html port extras))))
((eq? code (status-code not-implemented))
(create-writer-body-response
'()
(lambda (port options)
(generic-title port)
(format port "This server does not recognize or does not implement the requested method ~A.~%"
(request-method req))
(close-html port extras))))
((eq? code (status-code bad-gateway))
(create-writer-body-response
'()
(lambda (port options)
(generic-title port)
(format port "This server received an invalid response from the upstream server it accessed in attempting to fulfill the request.~%")
(close-html port extras))))
((eq? code (status-code version-not-supp))
(create-writer-body-response
'()
(lambda (port options)
(generic-title port)
(format port "This server does not support the requested HTTP major version ~D.~%The highest HTTP major version supported is 1.~%"
(car (request-version req)))
; (format port "This server does not support the requested HTTP major version ~D.~%The highest HTTP major version supported is ~D.~%"
; (car (request-version req))
; (car http-version))
(close-html port extras)))))))
(define (title-html out message)
;;produce valid XHTML 1.0 Strict
(emit-prolog out)
(emit-tag out 'html xmlnsdecl-attr)
(format out "~%<head>~%<title>~%~A~%</title>~%</head>~%" message)
(format out "<body>~%<h1>~A</h1>~%<p>~%" message))
;; Creates a redirect response. The server will serve the new file
;; indicated by NEW-LOCATION. NEW-LOCATION must be uri-encoded and
;; begin with a slash. This is intended for CGI scripts. Note that
;; the browser won't notice the redirect. Thus, it will keep the
;; original URL. For "real" redirections, use
;; (make-error-response (status-code moved-perm) req
;; "new-location").
(define (make-redirect-response new-location)
(make-response
(status-code redirect)
#f
(time)
""
'()
(make-redirect-body new-location)))
+201
View File
@@ -0,0 +1,201 @@
;;; man page -> HTML gateway for the SU web server. -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1996-2003 by Mike Sperber.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; This uses RosettaMan
;;; (based at ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z)
(define (rman-handler man-binary
nroff-binary
rman-binary
gzcat-binary
finder referencer address . maybe-man)
(let ((parse-man-url
(cond
((procedure? finder) finder)
((list? finder)
(lambda (url)
(values finder
(unescape (http-url-query url))
'())))
(else
(let ((man-path
((infix-splitter ":")
(or (getenv "MANPATH")
(begin
(format (current-error-port)
"~%Warning: environment variable MANPATH is unset.~%")
"")))))
(lambda (url)
(values man-path
(unescape (http-url-query url))
'()))))))
(reference-template
(cond
((procedure? referencer) referencer)
((string? referencer) (lambda (entry section) referencer))
(else (lambda (entry section) "man?%s(%s)"))))
(man (:optional maybe-man man)))
(lambda (path req)
(let ((request-method (request-method req)))
(cond
((string=? request-method "GET")
(with-fatal-error-handler
(lambda (c decline)
(cond
((http-error? c)
(apply http-error (car (condition-stuff c)) req
(cddr (condition-stuff c))))
(else
(decline))))
(make-response
(status-code ok)
#f
(time)
"text/html"
'()
(make-writer-body
(lambda (out options)
(emit-prolog out)
(receive (man-path entry and-then)
(parse-man-url (request-url req))
(emit-man-page man-binary nroff-binary rman-binary
gzcat-binary
entry man man-path and-then reference-template out))
(with-tag out address () ;;außerhalb des html elements?
(display address out)))))))
((or (string=? request-method "HEAD")
(string=? request-method "POST"))
(make-error-response (status-code method-not-allowed) req
"GET"))
(else
(make-error-response (status-code not-implemented) req)))))))
(define (cat-man-page key section out)
(let ((title (if section
(format #f "~a(~a) manual page" key section)
(format #f "~a manual page" key))))
(emit-title out title)
(emit-header out 1 title)
(newline out)
(with-tag out body ()
(with-tag out pre ()
(copy-inport->outport (current-input-port)
out)))))
(define (emit-man-page man-binary nroff-binary rman-binary
gzcat-binary
entry man man-path and-then reference-template out)
(receive (key section) (parse-man-entry entry)
(let ((status
(cond
((procedure? and-then)
(run (| (begin (man man-binary nroff-binary gzcat-binary
section key man-path))
(begin (and-then key section out)))
(= 1 ,out)
(= 2 ,out)))
(else
(run (| (begin (man man-binary nroff-binary gzcat-binary
section key man-path))
(,rman-binary "-fHTML"
,@and-then
"-r" ,(reference-template entry section)))
(= 1 ,out)
(= 2 ,out))))))
(if (not (zero? status))
(error "internal error emitting man page")))))
(define parse-man-entry
(let ((entry-regexp (make-regexp "(.*)\\((.)\\)")))
(lambda (s)
(cond
((regexp-exec entry-regexp s)
=> (lambda (match)
(values (match:substring match 1)
(match:substring match 2))))
(else (values s #f))))))
(define (man man-binary nroff-binary gzcat-binary section key man-path)
(cond
((procedure? man-path) (man-path))
((find-man-file key section "cat" man-path) =>
(lambda (file)
(cat-n-decode gzcat-binary file)))
((find-man-file key section "man" man-path) =>
(lambda (file)
(nroff-n-decode nroff-binary gzcat-binary file)))
(else
(if (not (zero?
(with-env (("MANPATH" . ,(string-join man-path ":")))
(run (,man-binary "-man" ,@(if section `(,section) '()) ,key)
stdports))))
(http-error (status-code not-found) #f "man page not found")))))
(define man-default-sections
'("1" "2" "3" "4" "5" "6" "7" "8" "9" "o" "l" "n" "p"))
(define (find-man-file name section cat-man man-path . maybe-sections)
(define (section-dir section)
(lambda (dir)
(file-name-as-directory
(string-append (file-name-as-directory dir)
cat-man
section))))
(let* ((prefix (if section
(string-append name "." section)
(string-append name ".")))
(pattern (string-append (glob-quote prefix) "*"))
(sections (:optional maybe-sections man-default-sections))
(path (if section
(map (section-dir section) man-path)
(apply append
(map (lambda (dir)
(map (lambda (section)
((section-dir section) dir))
sections))
man-path)))))
(let loop ((path path))
(and (not (null? path))
(let ((matches (glob (string-append (car path) pattern))))
(if (not (null? matches))
(car matches)
(loop (cdr path))))))))
(define (file->man-directory file)
(path-list->file-name
(reverse
(cdr
(reverse
(split-file-name
(file-name-directory file)))))))
(define (cat-n-decode gzcat-binary file)
(let ((ext (file-name-extension file)))
(cond
((string=? ".gz" ext) (run (,gzcat-binary ,file) stdports))
((string=? ".Z" ext) (run (,gzcat-binary ,file) stdports))
(else (call-with-input-file
file
(lambda (port)
(copy-inport->outport port (current-output-port))))))))
(define (nroff-n-decode nroff-binary gzcat-binary file)
(if (not (zero? (run (| (begin (cat-n-decode gzcat-binary file))
(begin
(with-cwd (file->man-directory file)
(exec-epf (,nroff-binary "-man")))))
stdports)))
(http-error (status-code not-found) #f "man page not found")))
+50
View File
@@ -0,0 +1,50 @@
#!/bin/sh
IFS=" "
exec scsh -lm ../packages.scm -dm -o http-top -e top -s "$0" "$@"
!#
;;; Scheme Underground Web Server -*- Scheme -*-
;;; Olin Shivers
;;; To compile as a heap-image:
;;; ,open http-top
;;; (dump-scsh-program top "server")
;;; then insert a #! trigger.
(define-structure http-top (export top)
(open httpd-core
httpd-make-options
httpd-cgi-server
httpd-basic-handlers
httpd-seval-handlers
scheme-with-scsh)
(begin
;; Kitchen-sink request handler.
(define rh
(alist-path-dispatcher
`(("h" . ,(home-dir-handler "public_html"))
("seval" . ,seval-handler)
("cgi-bin" . ,(cgi-handler "/usr/local/etc/httpd/cgi-bin")))
(tilde-home-dir-handler "public_html"
(rooted-file-handler "/usr/local/etc/httpd/htdocs"))))
;; crank up a server on port 8001, first resetting our identity to
;; user "nobody". Initialise the request-invariant part of the CGI
;; env before starting.
(define (top args)
(display "We be jammin, now.\n") (force-output)
(cond ((zero? (user-uid))
(set-gid (->gid "nobody"))
(set-uid (->uid "nobody"))))
;; invariant environment is know initilialized by cgi-handler itself
;; (initialise-request-invariant-cgi-env)
(httpd (with-request-handler
rh
(with-port
8001
(with-root-directory "/usr/local/etc/httpd")))))))
+110
View File
@@ -0,0 +1,110 @@
;;; Path handler for uploading Scheme code to the SU web server -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1995 by Olin Shivers.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; This is really just an handler example demonstrating how to upload code
;;; into the server.
;;; (do/timeout secs thunk)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Run THUNK, and gun it down if it hasn't finished in SECS seconds.
;;; Returns nothing useful, and THUNK gets executed in a subprocess,
;;; so its side-effects are invisible, as well. This is a clever kludge --
;;; it uses three subprocesses -- but I don't have interrupts, so I'm hosed.
(define (do/timeout* secs thunk)
(run (begin (let ((timer (fork (lambda () (sleep secs))))
(worker (fork thunk)))
(receive (process status) (wait-any)
(ignore-errors
(lambda ()
(signal-process (proc:pid (if (eq? worker process)
timer
worker))
signal/kill))))))))
(define-syntax do/timeout
(syntax-rules ()
((do/timeout secs body ...) (do/timeout* secs (lambda () body ...)))))
;;; The request handler for seval ops.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (seval-handler path req)
(let ((request-method (request-method req)))
(cond
((string=? request-method "POST") ; Could do others also.
(seval path req))
((or (string=? request-method "HEAD")
(string=? request-method "GET"))
(make-error-response (status-code method-not-allowed) req
"POST"))
(else
(make-error-response (status-code not-implemented) req)))))
(define (seval path req)
(let* ((message-body (read-message-body req))
(sexp (parse-request-sexp message-body)))
(make-response
(status-code ok)
#f
(time)
"text/html"
'()
(make-writer-body
(lambda (oport options)
(http-syslog (syslog-level debug) "read sexp: ~a" sexp)
(emit-prolog oport)
(with-tag oport html (xmlnsdecl-attr)
(newline oport)
(with-tag oport head ()
(newline oport)
(emit-title oport "Scheme program output")
(newline oport))
(newline oport)
(with-tag oport body ()
(newline oport)
(do/timeout
10
(receive vals
;; Do the computation.
(begin (emit-header oport 1 "Output from execution")
(newline oport)
(with-tag oport pre ()
(newline oport)
(force-output oport); In case we're gunned down.
(with-current-output-port oport
(eval-safely sexp))))
;; Pretty-print the returned value(s).;; hier noch mal newline rausschreiben?
(emit-header oport 1 "Return value(s)")
(with-tag oport pre ()
(for-each (lambda (val) (p val oport))
vals)))))))))))
;;; Parse the request's message body.
;;; We assume, that the entity is "form-url encoded" data (see
;;; parse-forms.scm for a description of this encoding). This
;;; assumption is rather strange - it may safely be made only if
;;; there's a "Content-type: application/x-www-form-urlencoded" header.
;;; Pull out the program=<stuff> string, extract <stuff>,
;;; parse that into an s-expression, and return it.
(define (parse-request-sexp body)
(let* ((parsed-html-form-query (parse-html-form-query body))
(program (cond ((assoc "program" parsed-html-form-query) => cdr)
(else (fatal-syntax-error "No program was found in request's message body.")))))
(http-syslog (syslog-level debug)
"Seval sexp: ~s" program)
(with-fatal-error-handler
(lambda (c decline)
(fatal-syntax-error "The program in the request's message body isn't a valid s-expression"))
(read (make-string-input-port program))))) ;; return first sexp, discard others
+8
View File
@@ -0,0 +1,8 @@
TODO
inspecting-packages.scm
inspecting-surflet-handler.scm
load-inspecting-surflet-server.scm
*.aux
*.log
*.dvi
+11
View File
@@ -0,0 +1,11 @@
--- SSAX-old/lib/packages.scm Sun Apr 14 07:35:07 2002
+++ SSAX/lib/packages.scm Mon Oct 6 12:05:58 2003
@@ -55,7 +55,7 @@
(export SXML->HTML
enattr
entag
- string->goodhtml))
+ string->goodHTML))
(define-interface sxml-to-html-ext-interface
(export make-header
+10
View File
@@ -0,0 +1,10 @@
* alias for extract-single-binding (extract/single) and extract-bindings
(extract)?
* send error 411 "Length required" in get-content-length (bindings.scm)
if the content-length-header is missing.
* use internal-error, if surflet fails, not bad gateway
* don't let callback-functions return.
* use another name for callback-functor.
* tell in howto how to start in cygwin environment.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Wins\Parameters
+68
View File
@@ -0,0 +1,68 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; return address
;; generates an unique return-address
;; may be used like
;; (let ((address (make-address)))
;; (send-html/suspend
;; (lambda (new-url)
;; ...
;; (url (address new-url) "Click here to get more")...)
(define-record-type address :address
(make-address-record name annotated? annotations)
(name address-name)
(annotated? address-annotated?)
(annotations address-annotations set-address-annotations!))
(define (really-make-address name annotated?)
(if annotated?
(make-address-record name annotated? #f)
(make-address-record name annotated? '())))
(define (address-add-annotation! address annotation)
(let ((index (generate-unique-name "val")))
(set-address-annotations! address
(cons (cons index annotation)
(address-annotations address)))
index))
(define (address-annotation address index)
(cond
((assoc index (address-annotations address)) => cdr)
(else #f)))
(define (make-address)
(let ((address (really-make-address
(generate-unique-name "return") #f)))
(lambda (message)
(cond
((string? message)
(string-append message "?" (address-name address) "="))
((eq? message 'address)
address)
(else
(error "address: unknown message/bad argument"
message (address-name address)))))))
(define (make-annotated-address)
(let ((address (really-make-address
(generate-unique-name "return")
#t)))
(lambda (message . annotation)
(cond
((and (string? message)
(<= (length annotation) 1))
(let ((index (if (null? annotation)
(address-add-annotation! address "")
(address-add-annotation! address (car annotation)))))
(string-append message "?" (address-name address)
"=" index)))
((eq? message 'address)
address)
(else
(error "annotated-address: unknown message/bad argument(s)"
message (address-name address)))))))
+104
View File
@@ -0,0 +1,104 @@
;; Copyright 2002, 2003 Andreas Bernauer
;; Bindings of POST requests can be read only once, since they are
;; read from an input port. So we have to cache them, for the case of
;; a later GET-BINDINGS call on the same POST request. The requests
;; are referenced by a weak pointer. Thread-safe as all threads use
;; the same lock.
(define *POST-bindings-cache* '())
(define *cache-lock* (make-lock))
(define (get-bindings surflet-request)
(let ((request-method (surflet-request-method surflet-request))
(content-type (assoc "content-type"
(surflet-request-headers surflet-request))))
;; Check if we the content-type is the one we support. If there's
;; no content-type, assume the default (this is the one we
;; support).
(if (and content-type
;; Have to string-trim now, because the (buggy?) rfc822
;; implementation leaves the leading whitespace of the
;; header value.
(not (string=? (string-trim (cdr content-type))
"application/x-www-form-urlencoded")))
(error "get-bindings currently only supports
'application/x-www-form-urlencoded' as content-type"))
(cond
((string=? request-method "GET")
(form-query-list (http-url-query
(surflet-request-url surflet-request))))
((string=? request-method "POST")
(or (cached-bindings surflet-request)
(let* ((content-length (get-content-length
(surflet-request-headers surflet-request)))
(input-port (surflet-request-input-port surflet-request))
(form-data (read-string content-length input-port))
(form-bindings (form-query-list form-data)))
(obtain-lock *cache-lock*)
(set! *POST-bindings-cache*
(cons (cons (make-weak-pointer surflet-request)
form-bindings)
*POST-bindings-cache*))
(release-lock *cache-lock*)
form-bindings)))
(else
(error "unsupported request type")))))
;; Looking up, if we have cached this request. While going through the
;; list, we remove entries to request objects, that are no longer
;; valid. Expecting a call for an uncached request every now and then,
;; it is guaranteed, that the list is cleaned up every now and
;; then. The cache is a list of pairs
;;; (surflet-request . computed-binding)
(define (cached-bindings surflet-request)
(obtain-lock *cache-lock*)
(let ((result
(let loop ((cache *POST-bindings-cache*))
(if (null? cache)
#f ; no such request cached
(let* ((head (car cache))
(s-req (weak-pointer-ref (car head))))
(if s-req
(if (eq? s-req surflet-request)
(cdar cache) ; request is cached
(loop (cdr cache))) ; request isn't cached
(begin
;; request object is gone ==> remove it from list
(set! cache (cdr cache))
(loop cache))))))))
(release-lock *cache-lock*)
result))
;; Will be needed when we handle POST requests.
(define (get-content-length headers)
(cond ((get-header headers 'content-length) =>
;; adopted from httpd/cgi-server.scm
(lambda (content-length) ; Skip initial whitespace (& other non-digits).
(let ((first-digit (string-index content-length char-set:digit))
(content-length-len (string-length content-length)))
(if first-digit
(string->number (substring content-length first-digit
content-length-len))
;; (status-code bad-request) req
(error "Illegal `Content-length:' header.")))))
(else
(error "No Content-length specified for POST data."))))
(define (extract-bindings key bindings)
(let ((key (if (symbol? key) (symbol->string key) key)))
(map cdr
(filter (lambda (binding)
(equal? (car binding) key))
bindings))))
(define (extract-single-binding key bindings)
(let ((key-bindings (extract-bindings key bindings)))
(if (= 1 (length key-bindings))
(car key-bindings)
(error "extract-one-binding: more than one or zero bindings found"
(length key-bindings)
key bindings))))
+37
View File
@@ -0,0 +1,37 @@
;; Copyright 2002, 2003 Andreas Bernauer
;; With callbacks you can create special links that are associated
;; with a function. If the user clicks on the special callback link,
;; the send-html/suspend won't return, but the function will be called
;; instead.
;; NOTE: It is not sensible to create callbacks on top level, as they
;; contain continuations. You have to create a new callback every time
;; you want to use it (inside a function).
(define (make-callback function)
(call-with-current-continuation
(lambda (exit)
(let* ((req (send/suspend (lambda (new-url)
(exit new-url)))))
(function req)))))
(define (make-annotated-callback function)
(let* ((annotated-address (make-annotated-address))
(dispatch
(lambda (req)
(let ((bindings (get-bindings req)))
(cond
((returned-via annotated-address bindings) =>
(lambda (args)
(apply function (cons req args))))
(else
(error "annotated-callback:
unexpected return values from website"))))))
(callback (make-callback dispatch)))
(lambda args
(annotated-address callback args))))
(define callback-function
(lambda (req proc . args)
(apply proc (cons req args))))
+24
View File
@@ -0,0 +1,24 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Error-Handler
;;
;; Adopted from WITH-FATAL-ERROR-HANDLER, but handles everything that
;; is catchable. We must catch everything because we also want
;; exceptions (and warnings) to be catched (e.g. when the surflet is
;; loaded.)
(define (with-fatal-handler* handler thunk)
(call-with-current-continuation
(lambda (accept)
((call-with-current-continuation
(lambda (k)
(with-handler (lambda (condition more)
(call-with-current-continuation
(lambda (decline)
(k (lambda () (handler condition decline)))))
(more)) ; Keep looking for a handler.
(lambda () (call-with-values thunk accept)))))))))
(define-syntax with-fatal-handler
(syntax-rules ()
((with-fatal-handler handler body ...)
(with-fatal-handler* handler
(lambda () body ...)))))
+19
View File
@@ -0,0 +1,19 @@
(define (surflet-file-name req)
(last (http-url-path (surflet-request-url req))))
;; This works for all requests except for the initial one. For the
;; initial one (main's arg) think about using instance-session-id.
(define (my-session-id req)
(resume-url-session-id (surflet-file-name req)))
;; This works for all requests except for the initial one: we don't
;; have a continuation at this time.
(define (my-continuation-id req)
(resume-url-continuation-id (surflet-file-name req)))
;; Returns two values: session-id and continuation-id. The
;; restrictions from my-session-id and my-continuation-id apply here
;; as well.
(define (my-ids req)
(resume-url-ids (surflet-file-name req)))
+159
View File
@@ -0,0 +1,159 @@
;;; Copyright 2002, 2003 Andreas Bernauer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; input-fields
;;; defines input-fields for surflets
;;; Globals
(define *input-field-trigger* `*input-field*)
(define generate-input-field-name generate-unique-name)
;;; Data structure for real-input-field
;; MULTI?: Transformer will get all bindings of request, not only the
;; one concerning the input-field.
(define-record-type real-input-field :real-input-field
(make-real-input-field name type transformer
attributes html-tree-maker
html-tree multi?)
real-input-field?
(name real-input-field-name)
(type real-input-field-type)
(transformer real-input-field-transformer)
(attributes real-input-field-attributes set-real-input-field-attributes!)
(html-tree-maker real-input-field-html-tree-maker)
(html-tree real-input-field-html-tree set-real-input-field-html-tree!)
(multi? real-input-field-multi?))
(define-record-discloser :real-input-field
(lambda (input-field)
(list 'real-input-field
(real-input-field-type input-field)
(real-input-field-name input-field))))
;;; Fake input-field record. This is necessary, as the trigger in SXML
;;; may only be symbols, not arbitrary values. Thus, our input-fields
;;; must be preceeded by a trigger symbol to get recognized by the
;;; SXML transforming routines like sxml->html.
;; Constructors: make-input-field, make-multi-input-field
;; Predicates: input-field?
;; Selectors: input-field-name, input-field-type,
;; input-field-transformer, input-field-attributes,
;; input-field-html-tree-maker, input-field-html-tree,
;; input-field-multi?
;; Mutators: set-input-field-attributes!, touch-input-field!
;;; Constructors for input-field / multi-input-field
(define (make-input-field name type transformer attributes
html-tree-maker)
(make-sxml-input-field
(make-real-input-field name type transformer
attributes html-tree-maker #f #f)))
(define (make-multi-input-field name type transformer attributes
html-tree-maker)
(make-sxml-input-field
(make-real-input-field name type transformer
attributes html-tree-maker #f #t)))
(define (make-sxml-input-field real-input-field)
(list *input-field-trigger* real-input-field))
(define input-field-real-input-field cadr)
(define (input-field? input-field)
(and (pair? input-field)
(eq? *input-field-trigger* (car input-field))
(real-input-field? (input-field-real-input-field input-field))))
(define (make-input-field-selector selector)
(lambda (input-field)
(selector (input-field-real-input-field input-field))))
(define (make-input-field-setter setter reset?)
(lambda (input-field value)
(let ((real-input-field (input-field-real-input-field input-field)))
(if reset?
(set-real-input-field-html-tree! real-input-field #f))
(setter real-input-field value))))
(define input-field-name (make-input-field-selector real-input-field-name))
(define input-field-type (make-input-field-selector real-input-field-type))
(define input-field-transformer
(make-input-field-selector real-input-field-transformer))
(define input-field-attributes
(make-input-field-selector real-input-field-attributes))
(define input-field-html-tree-maker
(make-input-field-selector real-input-field-html-tree-maker))
(define (input-field-html-tree input-field)
(let ((real-input-field (input-field-real-input-field input-field)))
(cond
((real-input-field-html-tree real-input-field)
=> identity)
(else
(let ((html-tree ((real-input-field-html-tree-maker real-input-field)
input-field)))
(set-real-input-field-html-tree! real-input-field html-tree)
html-tree)))))
(define input-field-multi?
(make-input-field-selector real-input-field-multi?))
(define set-input-field-attributes!
(make-input-field-setter set-real-input-field-attributes! #t))
;; not exported:
(define set-input-field-html-tree!
(make-input-field-setter set-real-input-field-html-tree! #f))
;; A touched input-field's html-tree will be recalculated if
;; neccessary.
(define (touch-input-field! input-field)
(set-input-field-html-tree! input-field #f))
;; <input-field>: '(input-field <real-input-field>)
;; <real-input-field>: #{Real-input-field "name"}
(define (raw-input-field-value input-field bindings)
(let ((real-input-field (input-field-real-input-field input-field)))
(cond
((real-input-field-multi? real-input-field)
((real-input-field-transformer real-input-field) input-field bindings))
((real-input-field-binding real-input-field bindings) =>
(lambda (binding)
((real-input-field-transformer real-input-field) (cdr binding))))
(else
(error "no such input-field" input-field bindings)))))
;; Trys to get a value for INPUT-FIELD in BINDINGS. If this fails
;; (i.e. RAW-INPUT-FIELD-VALUE returns an error), the default-value is
;; returned. The default-value defaults to #f. NOTE: If you do this
;; with input-fields whose valid values may be the same as the default
;; value, you cannot determine by the result if there was such a value
;; or not. Keep in mind, that RAW-INPUT-FIELD-VALUE returns also an
;; error, if there was not such an input field. This makes
;; INPUT-FIELD-VALUE working with checkbox input fields because they
;; miss if they are not checked.
(define (input-field-value input-field bindings . maybe-default)
(let ((default (:optional maybe-default #f)))
(with-fatal-error-handler
(lambda (condition more)
; (format #t "hit error condition: ~s~%" condition)
default)
(raw-input-field-value input-field bindings))))
(define (real-input-field-binding input-field bindings)
(assoc (real-input-field-name input-field) bindings))
;; Returns the binding of the input-field in bindings by the
;; input-field's name. If your input-field will have another name in
;; the bindings than it was created with, use a multi-input-field.
(define (input-field-binding input-field bindings)
(real-input-field-binding (input-field-real-input-field input-field)
bindings))
;;EOF
+12 -5
View File
@@ -9,14 +9,21 @@
\input{../../../doc/latex/decls}
\newcommand{\attrib}[1]{\textsf{#1}}
\newcommand{\ovar}[1]{\mbox{\textnormal{[}\frenchspacing\it{#1}\textnormal{]}}}
%FIXME-command: types out the desired FIXME
\newcommand{\FIXME}[1]%
{\typeout{}\typeout{****** FIXME ***** #1}\typeout{}%
\textsf{[#1]}}
\begin{document}
\maketitle
\begin{abstract}
\noindent The Scheme Untergrund Network Package (\textit{SUnet} for
short) comes along with a modular web server. The SUrflet handler
described here extends it by the capability of writing programs in
Scheme, that yield an HTML page.
\noindent [THIS FILE IS NOT AT ALL UP TO DATE. However, some specs
are still true. See the sources and the example SUrflets for up to
date info.]\\ \noindent The Scheme Untergrund Network Package
(\textit{SUnet} for short) comes along with a modular web
server. The SUrflet handler described here extends it by the
capability of writing programs in Scheme, that yield an HTML page.
Suspending of SUrflet computation.
Using Oleg's SXML.
@@ -264,7 +271,7 @@ See the examples for further informations.
\defun{input-field-binding}{input-field bindings}{binding}
\defunx{raw-input-field-value}{input-field bindings}{value}
\defunx{input-field-value}{input-field bindings \opt{default}}{value}
\defunx{input-field-value}{input-field bindings \ovar{default}}{value}
\begin{desc}
\ex{input-field-binding} returns the binding for
\semvar{input-field} in \semvar{bindings}.
@@ -10,22 +10,22 @@
(in 'scsh `(run (string-append
(or (getenv "SUNETHOME")
,*ASSUMED-SUNET-HOME*)
"/packages.scm"))))
"/scheme/packages.scm"))))
(define *SSAX-PACKAGE*
(in 'scsh `(run (string-append
(or (getenv "SSAXPATH")
(string-append ,*ASSUMED-SUNET-HOME* "/SSAX"))
(string-append ,*ASSUMED-SUNET-HOME* "/../SSAX"))
"/lib/packages.scm"))))
(define *SURFLET-PACKAGE*
(in 'scsh `(run (string-append
(or (getenv "SUNETHOME")
,*ASSUMED-SUNET-HOME*)
"/httpd/surflets/packages.scm"))))
"/scheme/httpd/surflets/packages.scm"))))
(define *SURFLET-SERVER*
(in 'scsh `(run (string-append
(or (getenv "SUNETHOME")
,*ASSUMED-SUNET-HOME*)
"/httpd/surflets/start-surflet-server"))))
"/start-surflet-server"))))
(config `(load ,*SUNET-PACKAGE*))
(config `(load ,*SSAX-PACKAGE*))
(config `(load ,*SURFLET-PACKAGE*))
+33
View File
@@ -0,0 +1,33 @@
;;; Copyright 2002, 2003 Andreas Bernauer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; outdater
(define-record-type outdater :outdater
(real-make-outdater outdated?)
outdater?
(outdated? outdater-outdated? set-outdater-outdated?!))
(define (make-outdater)
(real-make-outdater #f))
(define-syntax if-outdated
(syntax-rules ()
((if-outdated outdater consequence alternative)
(if (outdater-outdated? outdater)
consequence
(begin
(set-outdater-outdated?! outdater #t)
alternative)))))
(define (show-outdated url)
(send-html
`(html (title "Outdated Data")
(body (h1 "Outdated Data")
(p "The page or action you requested relies on outdated data.")
,(if url
`(p "Try to "
(url ,url "reload")
" the page to get current data.")
'())))))
+667 -222
View File
@@ -1,8 +1,260 @@
;; Structures and interfaces for surflets.
;; NOTE: SSAX/lib/packages.scm must be loaded before you can use this
;; downloadable from http://sourceforge.net/project/showfiles.php?group_id=30687
;; (take the r5rs compliant version (ssax-sr5rs-plt200-4.9.tar.gz))
;;; Copyright 2002, 2003 Andreas Bernauer
;;; Copyright 2002 Martin Gasbichler
;;; NOTE: SSAX/lib/packages.scm must be loaded before you can use this
;;; downloadable from
;;; http://sourceforge.net/project/showfiles.php?group_id=30687 (take
;;; the r5rs compliant version (ssax-sr5rs-plt200-4.9.tar.gz); and
;;; patch string->goodhtml in packages.scm to string->goodHTML)
;;; Interfaces
;; Surflet Handler
(define-interface surflet-handler-interface
(export surflet-handler))
;; Responses from SUrflets
(define-interface surflet-handler/responses-interface
(export make-surflet-response
valid-surflet-response-data?
surflet-response?
surflet-response-status
surflet-response-content-type
surflet-response-headers
surflet-response-data))
;; SUrflet-requests as expected from the surflet handler
(define-interface surflet-handler/requests-interface
(export make-surflet-request ;FIXME? unusable for user
surflet-request?
surflet-request-request
surflet-request-input-port
surflet-request-method
surflet-request-uri
surflet-request-url
surflet-request-version
surflet-request-headers
surflet-request-socket))
(define-interface surflets/error-interface
(export send-error ;send error response
(status-code :syntax))) ;from httpd-responses
;; Use for SUrflets
(define-interface surflet-handler/primitives-interface
(compound-interface
surflet-handler/responses-interface
surflet-handler/requests-interface
surflets/error-interface
(export send/suspend ;send and suspend
send/finish ;send and finish
send ;just send (no finish, no suspend)
)))
;; Send HTML-Strings (for advanced user)
(define-interface surflets/send-html-string-interface
(export send-html-string/suspend
send-html-string/finish
send-html-string))
;; Extensions/Exports to/from Olegs SSAX library
(define-interface surflets/sxml-interface
(export display-low-level-sxml
sxml->low-level-sxml ;direct map to pre-post-order
sxml->string
sxml->string/internal
sxml-attribute?
sxml-attribute-attributes
default-rule
text-rule
attribute-rule))
;; SUrflets' extensions to SXML
(define-interface surflets/surflet-sxml-interface
(export surflet-sxml->low-level-sxml
surflet-sxml-rules
surflet-form-rule
default-rules
plain-html-rule
nbsp-rule
url-rule))
;; Use for advanced users: make your own conversion rules.
(define-interface surflets/my-sxml-interface
(compound-interface
surflets/send-html-string-interface
surflets/sxml-interface
surflets/surflet-sxml-interface))
(define-interface surflets/continuations-interface
(export get-continuations
delete-continuation!
continuation-id))
;; Access to session-id and continuation-id
(define-interface surflets/ids-interface
(export my-session-id
my-continuation-id
my-ids
instance-session-id))
(define-interface surflets/session-data-interface
(export get-session-data
set-session-data!))
;; Use for advanced users: access to your sessions and continuations
;; (currently you get access to all sessions; this should and will be
;; restricted in the future)
(define-interface surflets/my-sessions-interface
(compound-interface
surflets/ids-interface
surflets/continuations-interface
surflets/session-data-interface
(export get-session
;; That would be too much:
;; get-sessions
delete-session!
instance-session-id
session-adjust-timeout!
adjust-timeout!
session-alive?
session-surflet-name
session-session-id
options-surflet-path
options-session-lifetime
options-cache-surflets?
options-make-session-timeout-text)))
(define-interface surflets/sessions-interface
(compound-interface
surflets/session-data-interface
(export get-session
get-sessions
delete-session!
instance-session-id
set-session-lifetime!
adjust-timeout!
session-adjust-timeout!
session-alive?
session-surflet-name
session-session-id ;faked
;; FIXME: This is too much and should be restricted:
session-continuation-table
session-continuation-table-lock
session-continuation-counter)))
(define-interface surflet-handler/surflets-interface
(export get-loaded-surflets
unload-surflet))
(define-interface surflet-handler/options-interface
(export make-surflet-options
with-surflet-path
with-session-lifetime
with-cache-surflets?
with-make-session-timeout-text
options-surflet-path
options-session-lifetime
options-cache-surflets?
options-make-session-timeout-text
set-options-surflet-path!
set-options-session-lifetime!
set-options-cache-surflets?!
set-options-make-session-timeout-text))
(define-interface surflet-handler/resume-url-interface
(export resume-url?
resume-url-ids
resume-url-session-id
resume-url-continuation-id))
;; Use for adminstration of the Surflet Handler
(define-interface surflet-handler/admin-interface
(compound-interface
surflet-handler/surflets-interface
surflets/sessions-interface
surflets/continuations-interface
surflet-handler/resume-url-interface
surflet-handler/options-interface
))
;; THE interface that SUrflets use.
(define-interface surflet-interface
(export main)) ; MAIN gets one parameter, the REQUEST
;; Simple Surflet API as known from PLT
(define-interface simple-surflet-api-interface
(export single-query
queries
form-query
inform
final-page
make-password
make-number
make-boolean
make-radio
make-yes-no
extract/single
extract))
;; shift-reset
(define-interface shift-reset-interface
(export (reset :syntax)
(shift :syntax)))
;; For memory profiling
(define-interface profiling-interface
(export profile-space
profile-result
profile-results
write-gnuplot-data-file
space-info-pair space-info-symbol
space-info-vector space-info-closure
space-info-location space-info-cell
space-info-channel space-info-port
space-info-ratnum space-info-record
space-info-continuation space-info-extended-number
space-info-template space-info-weak-pointer
space-info-shared-binding space-info-unused-d-header1
space-info-unused-d-header2 space-info-string
space-info-byte-vector space-info-double
space-info-bignum space-info-total
set-space-info-pair! set-space-info-symbol!
set-space-info-vector! set-space-info-closure!
set-space-info-location! set-space-info-cell!
set-space-info-channel! set-space-info-port!
set-space-info-ratnum! set-space-info-record!
set-space-info-continuation! set-space-info-extended-number!
set-space-info-template! set-space-info-weak-pointer!
set-space-info-shared-binding! set-space-info-unused-d-header1!
set-space-info-unused-d-header2! set-space-info-string!
set-space-info-byte-vector! set-space-info-double!
set-space-info-bignum! set-space-info-total!
pure-count pure-bytes
impure-count impure-bytes
total-count total-bytes
))
;; Handling every condition
(define-interface handle-fatal-interface
(export with-fatal-handler*
(with-fatal-handler :syntax)))
;; Thread-safe counter
(define-interface thread-safe-counter-interface
(export make-thread-safe-counter
thread-safe-counter-value
thread-safe-counter-next!
thread-safe-counter?))
;; These two are from Martin Gasbichler:
(define-interface rt-module-language-interface
(export ((lambda-interface
with-names-from-rt-structure)
@@ -19,6 +271,411 @@
rt-structure-binding
load-structure))
(define-interface with-locks-interface
(export with-lock*
(with-lock :syntax)))
;; Input-fields as Scheme-Objects
(define-interface surflets/input-field-value-interface
(export input-field?
raw-input-field-value
input-field-value
input-field-binding))
;; For advanced users: creating your own input-fields
(define-interface surflets/my-input-fields-interface
(compound-interface
surflets/input-field-value-interface
(export generate-input-field-name
make-input-field
make-multi-input-field
input-field-name
input-field-type
input-field-transformer
input-field-attributes
input-field-html-tree-maker
input-field-html-tree
input-field-multi?
set-input-field-attributes!
touch-input-field!)))
;; For internal use: special exports to create
;; SXL-rules for input-fields
(define-interface surflets/internal-input-fields-interface
(export *input-field-trigger*
make-sxml-input-field))
(define-interface surflets/surflet-input-fields-interface
(compound-interface
surflets/input-field-value-interface
(export make-text-field
set-text-field-value!
make-number-field
set-number-field-value!
make-hidden-field
set-hidden-field-value!
make-password-field
set-password-field-value!
make-textarea
set-textarea-value!
make-select
make-annotated-select
make-simple-select-option
make-annotated-select-option
select-option?
select-select-option!
unselect-select-option!
add-select-option!
delete-select-option!
set-select-option-selected?!
make-radio-group
make-annotated-radio-group
make-radios
check-radio!
uncheck-radio!
set-radio-checked?!
make-checkbox
make-annotated-checkbox
check-checkbox!
uncheck-checkbox!
set-checkbox-checked?!
make-submit-button
make-reset-button
make-image-button)))
;; Some utilities
(define-interface surflets/utilities-interface
(export form-query-list
rev-append
generate-unique-number
generate-unique-name
identity))
;; Intelligent Addresses
(define-interface surflets/addresses-interface
(export make-address
make-annotated-address
address-name
address-annotated?
; address-add-annotation!
address-annotation))
(define-interface surflets/callbacks-interface
(export make-callback
make-annotated-callback
callback-function))
;; Returned-via (dispatcher for input-fields and intelligent
;; addresses)
(define-interface surflets/returned-via-interface
(export returned-via
returned-via?
(case-returned-via :syntax)))
;; Outdater denies access to outdated object
(define-interface surflets/outdaters-interface
(export make-outdater
(if-outdated :syntax)
show-outdated))
;; Access to form bindings in URL
(define-interface surflets/bindings-interface
(export get-bindings
get-content-length
extract-bindings
extract-single-binding))
;; HTML-Extensions to send/suspend et al. (for basic user)
(define-interface surflets/send-html-interface
(export send-html/suspend
send-html/finish
send-html))
;; Helping functions for surflets (for basic user)
(define-interface surflets-interface
(compound-interface
; surflet-handler/surflets-interface;
; surflets/sxml-interface
; surflets/surflet-sxml-interface
surflets/send-html-interface
surflets/surflet-input-fields-interface
surflets/addresses-interface
surflets/returned-via-interface
surflets/bindings-interface
surflets/session-data-interface))
;;; Structures
;; structures from SUrflet Handler
(define-structures
((surflet-handler surflet-handler-interface)
(surflet-handler/surflets surflet-handler/surflets-interface)
(surflet-handler/options surflet-handler/options-interface)
(surflet-handler/resume-url surflet-handler/resume-url-interface)
(surflet-handler/admin surflet-handler/admin-interface)
(surflet-handler/primitives surflet-handler/primitives-interface)
(surflets/sessions surflets/sessions-interface)
(surflets/continuations surflets/continuations-interface)
(surflets/error surflets/error-interface)
(surflets/session-data surflets/session-data-interface))
(open define-record-types ;DEFINE-RECORD-TYPE
handle-fatal ;WITH-FATAL-ERROR-HANDLER* et al.
handle-fatal-error
httpd-errors ;errors for httpd
httpd-logging ;HTTP-SYSLOG
httpd-requests ;requests from httpd
httpd-responses ;replies for httpd
let-opt ;:OPTIONAL
locks ;MAKE-LOCK et al.
profiling ;PROFILE-SPACE
rt-module-language ;get structures dynamically
scheme-with-scsh ;regexp et al.
search-trees
shift-reset ;SHIFT and RESET
(subset srfi-1 (alist-cons alist-delete!))
srfi-6 ;string-ports
(subset srfi-13 (string-join))
srfi-14 ;CHAR-SET:DIGIT
srfi-27 ;random numbers
surflet-requests ;requests for surflets
surflet-responses ;responses from surflets
sxml-to-html ;SXML->HTML
tables ;HASH-TABLES
thread-cells ;THREAD-CELL et al.
thread-fluids ;FORK-THREAD
thread-safe-counter
threads ;SLEEP
uri ;URI-PATH-LIST->PATH
with-locks ;WITH-LOCK
)
(files surflet-handler))
;; SUrflets library of helping functions
(define-structure surflets surflets-interface
(open surflets/session-data
surflets/send-html ;send-html/suspend...
surflets/surflet-input-fields
surflets/addresses ;annotated-address...
surflets/returned-via
surflets/bindings))
;; SUrflets library for advanced users: make and use your own
;; conversion rules.
(define-structure surflets/my-sxml surflets/my-sxml-interface
(open surflets/send-html-string
surflets/sxml
surflets/surflet-sxml))
;; SUrflets librarary for advanced users: access to session and
;; continuations and stuff.
(define-structure surflets/my-sessions surflets/my-sessions-interface
(open surflets/ids
surflets/continuations
surflets/session-data
surflet-handler/surflets
surflets/sessions
surflet-handler/options))
;; Shift-Reset
(define-structure shift-reset shift-reset-interface
(open scheme
signals
escapes
thread-cells)
(files shift-reset))
;; Measuring memory usage.
(define-structure profiling profiling-interface
(open let-opt
define-record-types
spatial
srfi-13
srfi-1
locks
scheme-with-scsh)
(files profile))
;; Simple Surflet API as known from PLT.
(define-structure simple-surflet-api simple-surflet-api-interface
(open scheme-with-scsh
define-record-types
let-opt
surflets
surflets/surflet-input-fields
(subset srfi-1 (zip filter find make-list))
handle-fatal-error
)
(files simple-surflet-api))
;; Handling every condition
(define-structure handle-fatal handle-fatal-interface
(open scheme conditions handle)
(files handle-fatal))
;; Thread-safe counter
(define-structure thread-safe-counter thread-safe-counter-interface
(open scheme
locks
define-record-types)
(files thread-safe-counter))
;; SUrflet-requests as expected from the SUrflet handler
;;; We have two names for the same thing to ease the use of structure
;;; names: requests seem to be part of the surflet-handler, but are
;;; actually seperate files. If you know everything about SUrflets,
;;; you use `surflet-requests'.
(define-structures
((surflet-handler/requests surflet-handler/requests-interface)
(surflet-requests surflet-handler/requests-interface))
(open scheme
define-record-types
httpd-requests)
(files surflet-request))
(define-structures
((surflet-handler/responses surflet-handler/responses-interface)
(surflet-responses surflet-handler/responses-interface))
(open scheme-with-scsh
define-record-types)
(files surflet-response))
;; Extensions to Olegs SSAX library
(define-structure surflets/sxml surflets/sxml-interface
(open scheme-with-scsh ;string-ports
(subset sxml-to-html (string->goodHTML entag))
(subset sxml-tree-trans (pre-post-order)))
(files sxml))
;; Input fields as Scheme objects
(define-structures
((surflets/input-field-value surflets/input-field-value-interface)
(surflets/my-input-fields surflets/my-input-fields-interface)
(surflets/internal-input-fields surflets/internal-input-fields-interface))
(open scheme-with-scsh ;error, format
(subset let-opt (:optional))
handle-fatal-error
define-record-types
surflets/sxml
surflets/utilities
)
(files input-fields))
(define-structure surlfets/input-fields surflets/my-input-fields)
(define-structure surflets/surflet-input-fields
surflets/surflet-input-fields-interface
(open scheme-with-scsh ;error, format
;; avoid name collision for member
(modify srfi-1 (rename (member member/srfi-1)))
define-record-types
let-opt
surflets/my-input-fields
surflets/utilities ;generate-unique-number
surflets/sxml
tables ;make-integer-table
)
(files surflet-input-fields))
;; Extensions to SXML for surflets
(define-structure surflets/surflet-sxml surflets/surflet-sxml-interface
(open scheme-with-scsh ;error,receive
(subset surflets/my-input-fields (input-field-html-tree))
(subset surflets/internal-input-fields
(*input-field-trigger*
make-sxml-input-field))
surflets/utilities
(subset srfi-1 (make-list))
surflets/sxml)
(files surflet-sxml))
;; Access to session-id and continuation-id
(define-structure surflets/ids surflets/ids-interface
(open scheme
(subset surflet-requests (surflet-request-url))
(subset srfi-1 (last))
(subset surflet-handler/admin
(instance-session-id
resume-url-session-id
resume-url-continuation-id
resume-url-ids))
(subset url (http-url-path)))
(files ids))
;; Some utilities
(define-structure surflets/utilities surflets/utilities-interface
(open scheme
parse-html-forms)
(files utilities))
;; Intelligent Addresses
(define-structure surflets/addresses surflets/addresses-interface
(open scheme
srfi-23 ;error
define-record-types
(subset surflets/utilities (generate-unique-name)))
(files addresses))
(define-structure surflets/callbacks surflets/callbacks-interface
(open scheme
srfi-23 ;error
surflets/addresses
(subset surflet-handler/primitives (send/suspend))
surflets/bindings
surflets/returned-via)
(files callbacks))
(define-structure surflets/returned-via surflets/returned-via-interface
(open scheme
surflets/input-field-value
surflets/addresses
(subset uri (unescape)))
(files returned-via))
(define-structure surflets/outdaters surflets/outdaters-interface
(open scheme
define-record-types
surflets/send-html)
(files outdater))
(define-structure surflets/bindings surflets/bindings-interface
(open scheme-with-scsh ;read-string,error
locks
weak ;weak pointers
surflets/utilities ;form-query-list
surflet-requests
(subset url (http-url-query))
(subset srfi-14 (char-set:digit))
(subset srfi-13 (string-index string-trim))
(subset srfi-1 (filter))
(subset sunet-utilities (get-header)))
(files bindings))
(define-structures
((surflets/send-html surflets/send-html-interface)
(surflets/send-html-string surflets/send-html-string-interface))
(open scheme
surflet-handler/primitives
surflets/sxml
surflets/surflet-sxml)
(files send-html))
;; These two are from Martin Gasbichler:
(define-structure rt-module-language rt-module-language-interface
(open scheme
rt-modules)
@@ -65,224 +722,12 @@
package-commands-internal)
(files rt-module))
(define-interface surflet-handler-interface
(export surflet-handler))
(define-interface surflet-handler/surflet-interface
(export send/suspend ;send and suspend
send/finish ;send and finish
send ;just send (no finish, no suspend)
set-surflet-data!
get-surflet-data
adjust-timeout ;adjusts timeout of current session
;Without `!' because PLT
;doesn't have it.
))
(define-interface surflet-handler/admin-interface
(export get-loaded-surflets
unload-surflet
set-options-session-lifetime
options-session-lifetime
set-options-cache-surflets?
options-cache-surflets?
options-surflet-path
options-surflet-prefix
get-sessions
session-surflet-name
session-memo
session-continuation-table
session-continuation-table-lock
session-continuation-counter
delete-session!
session-adjust-timeout!
adjust-timeout
get-continuations
delete-continuation!
instance-session-id
resume-url?
resume-url-ids
resume-url-session-id
resume-url-continuation-id))
(define-structures
((surflet-handler surflet-handler-interface)
(surflet-handler/surflet surflet-handler/surflet-interface)
(surflet-handler/admin surflet-handler/admin-interface))
(open httpd-responses
httpd-requests
httpd-errors
uri ;URI-PATH-LIST->PATH
tables ;HASH-TABLES
define-record-types ;DEFINE-RECORD-TYPE
rt-module-language ;get structures dynamically
; srfi-13 ;string
srfi-14 ;CHAR-SET:DIGIT
handle-fatal-error ;WITH-FATAL-ERROR-HANDLER* et al.
srfi-27 ;random numbers
locks ;MAKE-LOCK et al.
thread-cells ;THREAD-CELL et al.
profiling ;PROFILE-SPACE
httpd-logging ;HTTP-SYSLOG
shift-reset ;SHIFT and RESET
conditions ;exception
threads ;SLEEP
thread-fluids ;FORK-THREAD
sxml-to-html ;SXML->HTML
scsh ;regexp et al.
; httpd-file-directory-handlers ;send-file-response
srfi-6 ;string-ports
handle
scheme
)
(files surflet-handler))
(define-interface surflets-interface
(export send/suspend
send/finish
send
send-html/suspend
send-html/finish
send-html
form-query
get-bindings
extract-bindings
extract-single-binding
adjust-timeout
make-outdater
(if-outdated :syntax)
show-outdated
generate-input-field-name
make-input-field
make-higher-input-field
make-text-input-field
make-hidden-input-field
make-password-input-field
make-number-input-field
make-textarea-input-field
make-select-input-field
make-checkbox-input-field
make-radio-input-fields
make-submit-button
make-reset-button
make-image-button
input-field-value
raw-input-field-value
input-field-binding
make-address
returned-via?
make-callback
set-surflet-data!
get-surflet-data))
(define-structure surflets surflets-interface
(open surflet-handler/surflet
httpd-responses
httpd-requests ; HTTP-URL:SEARCH
url ; REQUEST:URL
parse-html-forms
sxml-to-html ; SXML->HTML
srfi-1 ; FILTER
(subset srfi-13 (string-index))
sxml-tree-trans
url
define-record-types
weak ;MAKE-WEAK-POINTER
locks
let-opt ;:OPTIONAL
handle-fatal-error
scsh
scheme)
(files surflets))
(define-interface surflet-interface
(export main)) ; MAIN gets one parameter, the REQUEST
(define-interface shift-reset-interface
(export (reset :syntax)
(shift :syntax)))
(define-structure shift-reset shift-reset-interface
(define-structure with-locks with-locks-interface
(open scheme
signals
escapes
thread-cells)
(files shift-reset))
locks)
(files with-locks))
(define-interface profiling-interface
(export profile-space
profile-result
profile-results
write-gnuplot-data-file
space-info-pair space-info-symbol
space-info-vector space-info-closure
space-info-location space-info-cell
space-info-channel space-info-port
space-info-ratnum space-info-record
space-info-continuation space-info-extended-number
space-info-template space-info-weak-pointer
space-info-shared-binding space-info-unused-d-header1
space-info-unused-d-header2 space-info-string
space-info-byte-vector space-info-double
space-info-bignum space-info-total
set-space-info-pair! set-space-info-symbol!
set-space-info-vector! set-space-info-closure!
set-space-info-location! set-space-info-cell!
set-space-info-channel! set-space-info-port!
set-space-info-ratnum! set-space-info-record!
set-space-info-continuation! set-space-info-extended-number!
set-space-info-template! set-space-info-weak-pointer!
set-space-info-shared-binding! set-space-info-unused-d-header1!
set-space-info-unused-d-header2! set-space-info-string!
set-space-info-byte-vector! set-space-info-double!
set-space-info-bignum! set-space-info-total!
pure-count pure-bytes
impure-count impure-bytes
total-count total-bytes
))
(define-structure profiling profiling-interface
(open let-opt
define-record-types
spatial
srfi-13
srfi-1
locks
scsh
scheme)
(files profile))
(define-interface simple-surflet-api-interface
(export single-query
queries
form-query
inform
final-page
make-password
make-number
make-boolean
make-radio
make-yes-no
extract/single
extract))
(define-structure simple-surflet-api simple-surflet-api-interface
(open scsh
scheme
define-record-types
let-opt
surflets
(subset srfi-1 (zip filter find make-list))
handle-fatal-error
)
(files simple-surflet-api))
;;; EOF
;;; Local Variables:
;;; buffer-tag-table: "../../TAGS"
;;; End::
+47
View File
@@ -0,0 +1,47 @@
(define (returned-via return-object bindings)
(if (input-field? return-object)
(input-field-value return-object bindings)
;; We assume we have a return-address-object instead.
(let ((address (return-object 'address)))
(cond
((assoc (address-name address) bindings) =>
(lambda (pair)
(if (address-annotated? address)
(address-annotation address (cdr pair))
#t)))
(else #f)))))
;; It depends on the object, if returned-via returns only boolean
;; values or string values as well. So let us have both names.
(define returned-via? returned-via)
;; This is from Martin Gasbichler
(define-syntax case-returned-via
(syntax-rules (else =>)
((case-returned-via (%bindings ...) clauses ...)
(let ((bindings (%bindings ...)))
(case-returned-via bindings clauses ...)))
((case-returned-via bindings (else body ...))
(begin body ...))
((case-returned-via bindings
((%return-object ...) => %proc))
(cond ((or (returned-via %return-object bindings) ...)
=> %proc)))
((case-returned-via bindings
((%return-object ...) %body ...))
(if (or (returned-via? %return-object bindings) ...)
(begin %body ...)))
((case-returned-via bindings
((%return-object ...) => %proc)
%clause %clauses ...)
(cond ((or (returned-via %return-object bindings) ...)
=> %proc)
(else
(case-returned-via bindings %clause %clauses ...))))
((case-returned-via bindings
((%return-object ...) %body ...)
%clause %clauses ...)
(if (or (returned-via? %return-object bindings) ...)
(begin %body ...)
(case-returned-via bindings %clause %clauses ...)))))
+50
View File
@@ -0,0 +1,50 @@
;;; Allows sending of HTML represented in Oleg-like SXML-list instead
;;; of pure string.
;;; Copyright 2002,2003, Andreas Bernauer
;; Send surflet-sxml lists as HTML
(define (send-html/suspend html-tree-maker)
(send/suspend
(lambda (new-url)
(make-usual-html-response
(sxml->string (html-tree-maker new-url)
surflet-sxml-rules)))))
(define (send-html/finish html-tree)
(do-html-sending send/finish html-tree))
(define (send-html html-tree)
(do-html-sending send html-tree))
;; Semd strings as HTML
(define (send-html-string/suspend html-string-maker)
(send/suspend
(lambda (new-url)
(make-usual-html-response
(html-string-maker new-url)))))
(define (send-html-string/finish html-string)
(do-html-string-sending send/finish html-string))
(define (send-html-string html-string)
(do-html-string-sending send html-string))
;; Helping functions
(define (do-html-sending sender html-tree)
(do-html-string-sending
sender
(sxml->string html-tree surflet-sxml-rules)))
(define (do-html-string-sending sender html-string)
(sender (make-usual-html-response html-string)))
;; This is not for public, as we add the no-cache header that is
;; needed for SUrflets.
(define (make-usual-html-response html-string)
(make-surflet-response
(status-code ok)
"text/html"
'(("Cache-Control" . "no-cache"))
html-string))
+9 -7
View File
@@ -66,7 +66,7 @@
(br)
(p ,@text)
(br)
(URL ,url "Continue"))))))
(url ,url "Continue"))))))
;; Post some information on a Web page, shut down the surflet and all
;; its continuations.
@@ -116,16 +116,16 @@
(else (no-method message)))))
(define (make-text text)
(standard-query text (make-text-input-field) "No bad input possible"))
(standard-query text (make-text-field) "No bad input possible"))
(define (make-password text)
(standard-query text (make-password-input-field) "No bad input possible"))
(standard-query text (make-password-field) "No bad input possible"))
(define (make-number text)
(standard-query text (make-number-input-field) "Please respond with a valid number"))
(standard-query text (make-number-field) "Please respond with a valid number"))
(define (make-boolean text)
(let* ((input-field (make-checkbox-input-field))
(let* ((input-field (make-checkbox))
(standard (standard-query text input-field "No bad input possible")))
(lambda (message)
(case message
@@ -139,7 +139,7 @@
(define (make-radio text choices . maybe-insist)
(let* ((insist (:optional maybe-insist ""))
(radios (make-radio-input-fields choices))
(radios (make-radios choices))
(standard (standard-query text (car radios)
(string-append "Please respond" insist))))
(lambda (message)
@@ -150,7 +150,9 @@
`(tr (td ,text)
(td (table (tr
,@(map (lambda (radio choice)
`((td ,radio) (td ,choice)))
`((td ,radio ,choice
;; Add some distance
(nbsp)(nbsp))))
radios
choices)))))))
(else
-210
View File
@@ -1,210 +0,0 @@
#!/bin/sh
echo "Loading..."
fullpath=`which $0`
# $sunet is either $SUNETHOME or created out of fullpath
# Kind of a hack, I know.
sunet=${SUNETHOME:-`dirname $fullpath`/../..}
ssax=${SSAXPATH:-$sunet/SSAX} # path to SSAX
exec scsh -lm $sunet/packages.scm -lm $ssax/lib/packages.scm -lm $sunet/httpd/surflets/packages.scm -dm -o surflet-server -e main -s "$0" "$@"
!#
(define-structure surflet-server
(export main ; sh jump entry point
server) ; scsh entry point
(open httpd-core
httpd-make-options
httpd-basic-handlers
httpd-file-directory-handlers
; cgi-server
; seval-handler
; rman-gateway
; info-gateway
surflet-handler
let-opt
scsh
scheme)
(begin
(define (usage)
(format #f
"Usage: start-surflet-server [-h htdocs-dir] [-s surflet-dir] [-i images-dir]
[-p port] [-l log-file-name]
[-r requests] [--help]
with
htdocs-dir directory of html files (default: ./web-server/root/htdocs)
surflet-dir directory of SUrflet files (default: ./web-server/root/surflets)
images-dir directory of images files (default: ./web-server/root/img)
port port server is listening to (default: 8080)
log-file-name directory where to store the logfile in CLF
(default: ./web-server/httpd.log)
requests maximal amount of simultaneous requests (default 5)
--help show this help
NOTE: This is the SUrflet-server. It does not support cgi-bin.
"
))
(define htdocs-dir #f)
(define images-dir #f)
; (define cgi-bin-dir #f)
(define port #f)
(define log-file-name #f)
(define root #f)
(define surflet-dir #f)
(define simultaneous-requests #f)
(define (init)
(set! htdocs-dir "./web-server/root/htdocs")
(set! images-dir "./web-server/root/img")
; (set! cgi-bin-dir "./web-server/root/cgi-bin")
(set! port "8088")
(set! log-file-name "./web-server/httpd.log")
(set! root "./web-server/root")
(set! surflet-dir "./web-server/root/surflets")
(set! simultaneous-requests "5"))
(define (normalize-options)
(set! htdocs-dir (absolute-file-name htdocs-dir))
(set! images-dir (absolute-file-name images-dir))
(set! log-file-name (absolute-file-name log-file-name))
; (set! cgi-bin-dir (absolute-file-name cgi-bin-dir))
(set! port (string->number port))
(set! surflet-dir (absolute-file-name surflet-dir))
(set! simultaneous-requests (string->number simultaneous-requests)))
(define get-options
(let* ((unknown-option-error
(lambda (option)
(format (error-output-port)
"unknown option `~A'~%try `surflet-server --help'~%"
option)
(exit 1)))
(missing-argument-error
(lambda (option)
(format (error-output-port)
"option `~A' requires an argument~%try `surflet-server --help'~%"
option)
(exit 1))))
(lambda (options)
(let loop ((options options))
(if (null? options)
(normalize-options)
(cond
((string=? (car options) "-h")
(if (null? (cdr options))
(missing-argument-error (car options))
(set! htdocs-dir (cadr options)))
(loop (cddr options)))
((string=? (car options) "-i")
(if (null? (cdr options))
(missing-argument-error (car options))
(set! images-dir (cadr options)))
(loop (cddr options)))
((string=? (car options) "-c")
(format (error-output-port)
"This is the SUrflet server. It does not support cgi.~%")
; (if (null? (cdr options))
; (missing-argument-error (car options))
; (set! cgi-bin-dir (cadr options)))
(loop (cddr options)))
((string=? (car options) "-p")
(if (null? (cdr options))
(missing-argument-error (car options))
(set! port (cadr options)))
(loop (cddr options)))
((string=? (car options) "-l")
(if (null? (cdr options))
(missing-argument-error (car options))
(set! log-file-name (cadr options)))
(loop (cddr options)))
((string=? (car options) "-s")
(if (null? (cdr options))
(missing-argument-error (car options))
(set! surflet-dir (cadr options)))
(loop (cddr options)))
((string=? (car options) "-r")
(if (null? (cdr options))
(missing-argument-error (car options))
(set! simultaneous-requests (cadr options)))
(loop (cddr options)))
((string=? (car options) "--help")
(display (usage))
(exit 0))
((string=? (car options) "--dump")
(let ((image-name (if (null? (cdr options))
"surflet-server"
(cadr options))))
(dump-scsh-program main image-name))
(exit 0))
(else
(unknown-option-error (car options)))))))))
(define (server . args)
(if (pair? args)
(main `(main ,@(car args)))
(main '(main))))
(define (main args)
(init)
(format #t "reading options: ~s~%" (cdr args))
(get-options (cdr args))
(cond ((zero? (user-uid))
(set-gid (->gid "nobody"))
(set-uid (->uid "nobody"))))
(format #t "Going to run SUrflet server with:
htdocs-dir: ~a
surflet-dir: ~a
images-dir: ~a
port: ~a
log-file-name: ~a
a maximum of ~a simultaneous requests, syslogging activated,
and home-dir-handler (public_html) activated.
NOTE: This is the SUrflet server. It does not support cgi.
"
htdocs-dir
surflet-dir
images-dir
port
log-file-name
simultaneous-requests)
(httpd (with-port port
(with-root-directory (cwd)
(with-simultaneous-requests simultaneous-requests
(with-syslog? #t
(with-logfile log-file-name
;; The following settings are made to avoid dns lookups.
(with-reported-port port
(with-fqdn "localhost"
(with-resolve-ips? #f
(with-request-handler
(alist-path-dispatcher
(list (cons "h" (home-dir-handler "public_html"))
; (cons "seval" seval-handler)
; (cons "man" (rman-handler #f "man?%s(%s)"
; "Generated by rman-gateway"))
; (cons "info" (info-handler #f #f #f
; "Generated by info-gateway"))
; (cons "cgi-bin" (cgi-handler cgi-bin-dir))
;; Browsers cannot handle .SCM files: Opera shows
;; it as HTML, Netscape asks for a program to
;; view it. ROOTED-FILE-OR-DIRECTORY-HANDLER
;; should serve .SCM files as text/plain (I did
;; not want to write a handler just for this file
;; type.)
(cons "source" (rooted-file-or-directory-handler surflet-dir))
(cons "img" (rooted-file-handler images-dir))
(cons "surflet" (surflet-handler surflet-dir)))
(rooted-file-or-directory-handler htdocs-dir)))))))))))
))
))
;; EOF
;;; Local Variables:
;;; mode:scheme
;;; End:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,506 @@
;;; SUrflets' input fields
;;; Copyright 2002, 2003 Andreas Bernauer
;;; With additions from Eric Knauel (2003)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions to create simple input fields
;; The interface for input-fields does not prescribe what the type of
;; attributes has to be. We choose a record here.
(define-record-type field-attributes :field-attributes
(make-field-attributes default others)
field-attributes?
(default field-attributes-default set-field-attributes-default!)
(others field-attributes-others set-field-attributes-others!))
;; A simple input-field is a prototype for other input-fields.
;; REPORTED-TYPE is the type of the input-field in HTML, TYPE the
;; internal referenced type and TRANSFORMER the function that
;; translates the HTTP-string of the request into a scheme value.
(define (simple-field-maker reported-type type default-pred transformer)
(lambda maybe-further-attributes
(let ((name (generate-input-field-name type)))
(let-optionals maybe-further-attributes
((default "" default-pred)
(attributes '() sxml-attribute?))
(make-input-field name type
transformer
(make-field-attributes
(and default `(value ,default))
(sxml-attribute-attributes attributes))
(simple-html-tree-maker reported-type))))))
(define (simple-html-tree-maker reported-type)
(lambda (input-field)
(let ((attributes (input-field-attributes input-field)))
`(input (@ (type ,reported-type)
(name ,(input-field-name input-field))
,(field-attributes-default attributes)
,(field-attributes-others attributes))))))
(define (make-simple-default-setter default-pred?)
(lambda (input-field value)
(if (default-pred? value)
(set-field-attributes-default!
(input-field-attributes input-field)
`(value ,value))
(error "Default value must be a number or a string or a symbol."
value))
(touch-input-field! input-field)))
(define (string-or-symbol? thing)
(or (string? thing) (symbol? thing)))
(define simple-default? string-or-symbol?)
(define set-simple-field-default!
(make-simple-default-setter simple-default?))
;;;;;;;;;;;;;;;;;;;;
;;; Text input field
(define make-text-field
(simple-field-maker "text" "text" simple-default? identity))
(define set-text-field-value! set-simple-field-default!)
;;;;;;;;;;;;;;;;;;;;;;
;;; Number input field
(define (number-field-default? value)
(or (number? value)
(simple-default? value)))
(define (number-field-transformer string)
(or (string->number string)
(error "wrong type")))
(define make-number-field
(simple-field-maker "text" "number"
number-field-default? number-field-transformer))
(define set-number-field-value!
(make-simple-default-setter number-field-default?))
;;;;;;;;;;;;;;;;;;;;;;
;;; hidden input-field
;; The programmer should supply a default value for this input-field
;; as it is hidden.
(define make-hidden-field
(simple-field-maker "hidden" "hidden"
simple-default? identity))
(define set-hidden-field-value! set-simple-field-default!)
;;;;;;;;;;;;;;;;;;;;;;;;
;;; Password input field
(define make-password-field
(simple-field-maker "password" "password"
simple-default? identity))
(define set-password-field-value! set-simple-field-default!)
;;; That's it for simple input fields.
;;;;;;;;;;;;;;;;;;;;;;;;
;;; Textarea input field
(define (make-textarea . maybe-further-attributes)
(let-optionals maybe-further-attributes
((default-text "" simple-default?)
(rows 5 number?)
(cols 20 number?)
(readonly #f boolean?)
(attributes '() sxml-attribute?))
(let ((name (generate-input-field-name "textarea"))
(all-attributes `((cols ,cols)
(rows ,rows)
,@(if readonly '(readonly) '())
,@(sxml-attribute-attributes attributes))))
(make-input-field
name "textarea"
identity
(make-field-attributes (and default-text)
all-attributes)
make-textarea-html-tree))))
(define (make-textarea-html-tree textarea)
(let ((attributes (input-field-attributes textarea)))
`(textarea (@ (type "textarea")
(name ,(input-field-name textarea))
,(field-attributes-others attributes))
,(field-attributes-default attributes))))
(define (set-textarea-value! textarea value)
(if (simple-default? value)
(set-field-attributes-default!
(input-field-attributes textarea)
value)
(error "Default value must be a string or a symbol." value))
(touch-input-field! textarea))
;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Select input field
;(make-select '("this" "that" "those") '(@ ((id "sushi"))))
;(make-select '("this" ("that" '(@ (selected))) "those"))
;; dropdown: (size 1)
;;; A select input field shows a list of options that can be
;;; selected. For this purpose, we introduce an select-option record,
;;; that contains all the information for each option. This is
;;; justified by the fact, that the options list is seperated in HTML,
;;; too. The TAG is the string that is displayed in the website, the
;;; VALUE is the value that is returned by input-field-value, if this
;;; option was selected. TAG is assumed to be unique by some functions
;;; (e.g. select and unselect) SELECTED? tells us, if this option is
;;; preselected.
(define-record-type select-option :select-option
(really-make-select-option tag value selected? attributes)
select-option?
(tag select-option-tag)
(value select-option-value)
(selected? select-option-selected? really-set-select-option-selected?!)
(attributes select-option-attributes set-select-option-attributes!))
;; No check of attributes as this is done by calling function. (This
;; function isn't exported.
(define (make-select-option tag value selected? attributes)
(if (string? tag)
(really-make-select-option tag value selected?
(sxml-attribute-attributes attributes))
(error "Select-option's tag must be a string." tag)))
;; Constructor for valued select input-field option.
(define (make-annotated-select-option tag value . maybe-attributes)
(let-optionals maybe-attributes
((selected? #f boolean?)
(attributes '() sxml-attribute?))
(make-select-option tag value selected? attributes)))
;; Constructor for a simple select input-field option (not annotated).
(define (make-simple-select-option tag . maybe-attributes)
(let-optionals maybe-attributes
((selected? #f boolean?)
(attributes '() sxml-attribute?))
(make-select-option tag tag selected? attributes)))
(define-record-discloser :select-option
(lambda (select-option)
(list 'select-option
(select-option-tag select-option)
(select-option-value select-option)
(select-option-selected? select-option)
(select-option-attributes select-option)
)))
;; Selecting / Unselecting of an option in an select input-field,
;; chosen by tag.
(define (select-select-option! tag select)
(set-select-option-selected?! tag select #t))
(define (unselect-select-option! tag select)
(set-select-option-selected?! tag select #f))
(define (set-select-option-selected?! tag select selected?)
(let ((options (field-attributes-default
(input-field-attributes select))))
(if (number? tag) ; is tag an index?
(really-set-select-option-selected?! (list-ref options tag)
selected?)
(let lp ((options options))
(if (null? options)
(error "No such option" tag select)
(if (tag=select-option? tag (car options))
(really-set-select-option-selected?! (car options)
selected?)
(lp (cdr options))))))
(touch-input-field! select)))
;; Find select-option in a list by its tag.
(define (tag=select-option? tag select-option)
(string=? tag (select-option-tag select-option)))
(define (find-select-option tag select-options)
(cond ((member/srfi-1 tag select-options tag=select-option?)
=> car)
;; MEMBER/SRFI-1 returns the sublist that starts with the
;; searched element.
(else #f)))
(define (find-select-option-value tag select-options)
(cond ((find-select-option tag select-options)
=> select-option-value)
(else #f)))
(define (add-select-option! select select-option)
(let ((attributes (input-field-attributes select)))
(set-field-attributes-default!
attributes
(cons select-option
(field-attributes-default attributes)))
(touch-input-field! select)))
(define (delete-select-option! select select-option)
(let* ((attributes (input-field-attributes select))
(select-options (field-attributes-default attributes)))
(if (select-option? select-option)
(set-field-attributes-default!
attributes
(delete select-option select-options))
(let ((tag select-option))
(set-field-attributes-default!
attributes
(delete tag select-options tag=select-option?))))
(touch-input-field! select)))
;; To be compatible with previous versions of MAKE-SELECT-INPUT-FIELD,
;; we accept also a simple list as an option-list. New programs should
;; use select-options-list (easily createable with
;; (map make-simple-select-option option-list))
(define (simple-options select-options)
(if (and (list? select-options)
(every select-option? select-options))
select-options
(map make-simple-select-option select-options)))
(define (make-select select-options . maybe-further-attributes)
(let ((real-select-options (simple-options select-options)))
(let-optionals maybe-further-attributes
((multiple? #f boolean?)
(attributes '() sxml-attribute?))
(let ((name (generate-input-field-name "select")))
(if multiple?
(make-multiple-select name real-select-options attributes)
(make-single-select name real-select-options
attributes))))))
;; deprecated: Does not introduce further functionality.
(define make-annotated-select make-select)
;; internal
(define (make-multiple-select name select-options attributes)
(make-multi-input-field name "mult-select"
multiple-select-transformer
(make-field-attributes
select-options
`((multiple)
,@(sxml-attribute-attributes attributes)))
make-select-html-tree))
;; internal
(define (make-single-select name select-options attributes)
(make-input-field name "select"
(lambda (tag)
(cond ((find-select-option-value tag select-options)
=> identity)
(else (error "no such option." tag))))
(make-field-attributes
select-options
(sxml-attribute-attributes attributes))
make-select-html-tree))
(define (multiple-select-transformer select bindings)
(let ((name (input-field-name select))
(select-options (field-attributes-default
(input-field-attributes select))))
(let* ((my-bindings (filter (lambda (binding)
(equal? (car binding) name))
bindings))
(tags (map cdr my-bindings)))
(filter-map (lambda (tag)
(find-select-option-value tag select-options))
tags))))
(define (make-select-html-tree select)
(let ((attributes (input-field-attributes select)))
`(select (@ (name ,(input-field-name select))
,(field-attributes-others attributes))
#\newline
,@(make-select-options-html-tree
(field-attributes-default attributes)))))
(define (make-select-options-html-tree select-options)
(map (lambda (select-option)
`(option (@ ,(and (select-option-selected? select-option) '(selected))
,(select-option-attributes select-option))
,(select-option-tag select-option)))
select-options))
;;;;;;;;;;;;;;;;;;;;;;
;;; radio input-fields
;; Because grouped radio input-fields must use the same name, we
;; cannot just return one radio input-field object, but we must
;; generate several ones with the same name.
(define (make-radio-group)
(let ((name (generate-input-field-name "radio")))
(lambda (value-string . maybe-further-attributes)
(let-optionals maybe-further-attributes
((checked? #f boolean?)
(attributes '() sxml-attribute?))
(make-input-field name "radio"
identity
(make-field-attributes
(and checked? '(checked))
`((value ,value-string)
,@(sxml-attribute-attributes attributes)))
radio-html-tree-maker)))))
(define (make-annotated-radio-group)
(let* ((name (generate-input-field-name "radio"))
(value-table (make-integer-table))
(transformer (make-radio-transformer value-table)))
(lambda (value . maybe-further-attributes)
(let-optionals maybe-further-attributes
((checked? #f boolean?)
(attributes '() sxml-attribute?))
(let ((number (generate-unique-number)))
(table-set! value-table number value)
(make-input-field name "radio"
transformer
(make-field-attributes
(and checked? '(checked))
`((value ,(number->string number))
,@(sxml-attribute-attributes attributes)))
radio-html-tree-maker))))))
(define (make-radios values . maybe-further-attributes)
(let-optionals maybe-further-attributes
((attributes '() sxml-attribute?))
(let ((radio-gen (make-annotated-radio-group)))
(map (lambda (value)
(if attributes
(radio-gen value attributes)
(radio-gen value)))
values))))
(define (make-radio-transformer value-table)
(lambda (tag)
(cond
((string->number tag) =>
(lambda (number)
(let ((value (table-ref value-table number)))
(if value
value
(error "Unknown tag number for radio input-field" tag)))))
(else
(error "Unknown tag number for radio input-field" tag)))))
(define (radio-html-tree-maker radio)
(let* ((attributes (input-field-attributes radio)))
`(input (@ ((type "radio")
(name ,(input-field-name radio))
,(field-attributes-default attributes)
,(field-attributes-others attributes))))))
(define (set-input-field-checked?! input-field checked?)
(let ((attributes (input-field-attributes input-field)))
(set-field-attributes-default!
attributes
(if checked? '(checked) #f))
(touch-input-field! input-field)))
(define set-radio-checked?! set-input-field-checked?!)
(define (check-radio! radio) (set-radio-checked?! radio #t))
(define (uncheck-radio! radio) (set-radio-checked?! radio #f))
;;;;;;;;;;;;;;;;;;;;;;;;
;;; checkbox input-field
(define (make-checkbox . maybe-further-attributes)
(really-make-checkbox #t
checkbox-transformer
maybe-further-attributes))
(define (make-annotated-checkbox value . maybe-further-attributes)
(really-make-checkbox value
(make-checkbox-transformer value)
maybe-further-attributes))
(define (really-make-checkbox value transformer attributes)
(let ((name (generate-input-field-name "checkbox")))
(let-optionals attributes
((checked? #f boolean?)
(attributes '() sxml-attribute?))
(make-input-field name "checkbox"
transformer
(make-field-attributes
(and checked? '(checked))
(sxml-attribute-attributes attributes))
checkbox-html-tree-maker))))
(define (make-checkbox-transformer value)
(lambda (tag)
(if (string=? tag "on")
value
#f)))
(define checkbox-transformer (make-checkbox-transformer #t))
(define (checkbox-html-tree-maker checkbox)
(let ((attributes (input-field-attributes checkbox)))
`(input (@ ((type "checkbox")
(name ,(input-field-name checkbox))
,(field-attributes-default attributes)
,(field-attributes-others attributes))))))
(define set-checkbox-checked?! set-input-field-checked?!)
(define (check-checkbox! checkbox) (set-checkbox-checked?! checkbox #t))
(define (uncheck-checkbox! checkbox) (set-checkbox-checked?! checkbox #f))
;;;;;;;;;;;;;;;;;;;;;;
;; button input-fields
(define (make-button type name button-caption attributes)
(make-input-field name type
identity
(make-field-attributes
(and button-caption `(value ,button-caption))
(sxml-attribute-attributes attributes))
make-button-html-tree))
(define (make-button-html-tree button)
(let ((attributes (input-field-attributes button)))
`(input (@ (type ,(input-field-type button))
(name ,(input-field-name button))
,(field-attributes-default attributes)
,(field-attributes-others attributes)))))
(define (make-submit-button . maybe-further-attributes)
(let-optionals maybe-further-attributes
((button-caption #f string?)
(attributes '() sxml-attribute?))
(make-button "submit" (generate-input-field-name "submit")
button-caption attributes)))
(define (make-reset-button . maybe-further-attributes)
(let-optionals maybe-further-attributes
((button-caption #f string?)
(attributes '() sxml-attribute?))
(make-button "reset" (generate-input-field-name "reset")
button-caption attributes)))
;; Image buttons cannot be simple buttons, as the browser does not
;; send their simple name, but the coordinates where the user clicked
;; into. Thanks to Eric Knauel for reporting this bug.
(define (make-image-button image-source . maybe-further-attributes)
(let-optionals maybe-further-attributes
((attributes '() sxml-attribute?))
(make-multi-input-field (generate-input-field-name "imgbtn")
"image"
image-button-transformer
(make-field-attributes
`(src ,image-source)
(sxml-attribute-attributes attributes))
make-button-html-tree)))
;; The following two functions are from Eric Knauel's fix for the
;; image-button bug:
(define (image-button-transformer image-button bindings)
(let ((x (find-image-button-coordinate image-button bindings ".x"))
(y (find-image-button-coordinate image-button bindings ".y")))
(let ((x-number (string->number x))
(y-number (string->number y)))
(and x y
(if (and x-number y-number)
(cons x-number y-number)
(error "Image button coordinates aren't numbers. " x y))))))
(define (find-image-button-coordinate image-button bindings suffix)
(let* ((name (input-field-name image-button)))
(cond
((assoc (string-append name suffix) bindings)
=> cdr)
(else #f))))
;;EOF
+19
View File
@@ -0,0 +1,19 @@
;; Copyright Andras Bernauer (2003)
;; somehow `extend' httpd-request
(define-record-type surflet-request :surflet-request
(make-surflet-request request input-port)
surflet-request?
(request surflet-request-request)
(input-port surflet-request-input-port))
(define (make-fake-selector request-selector)
(lambda (surflet-request)
(request-selector (surflet-request-request surflet-request))))
(define surflet-request-method (make-fake-selector request-method))
(define surflet-request-uri (make-fake-selector request-uri))
(define surflet-request-url (make-fake-selector request-url))
(define surflet-request-version (make-fake-selector request-version))
(define surflet-request-headers (make-fake-selector request-headers))
(define surflet-request-socket (make-fake-selector request-socket))
@@ -0,0 +1,31 @@
;;; SURFLET-RESPONSE: Surflets are expected to return this object type.
;;; STATUS is the status code, an exact integer. See httpd/response.scm
;;; e.g. (status-code ok)
;;; CONTENT-TYPE is a string, most probably "text/html".
;;; HEADERS is a (maybe empty) list of pairs of (string or symbol);
;;; Additional headers to send, e.g. '(("Cache-Control" . "no-cache")) or
;;; '((Cache-Control . "no-cache")) etc.
;;; DATA is either
;;; * a string
;;; * a list of strings
;;; This list maybe extended to vectors later.
(define-record-type surflet-response :surflet-response
(make-surflet-response status content-type headers data)
surflet-response?
(status surflet-response-status)
(content-type surflet-response-content-type)
(headers surflet-response-headers)
(data surflet-response-data))
;; Allowed type for the data field.
(define (valid-surflet-response-data? data)
(or (string? data) (list? data)))
;; For debug purposes
(define (surflet-response->string surflet-response)
(format #f "#{SUrflet-response Status: ~a Content-Type: ~s Headers: ~s~%~s~%"
(surflet-response-status surflet-response)
(surflet-response-content-type surflet-response)
(surflet-response-headers surflet-response)
(surflet-response-data surflet-response)))
+114
View File
@@ -0,0 +1,114 @@
(define url-rule
`(url *preorder*
. ,(lambda (tag uri . maybe-text)
(surflet-sxml->low-level-sxml
`(a (@ (href ,uri))
,(if (null? maybe-text)
uri
maybe-text))))))
(define plain-html-rule
`(plain-html
*preorder*
. ,(lambda (tag . text) text)))
(define nbsp-rule
`(nbsp . ,(lambda (_) "&nbsp;")))
(define comment-rule
`(*COMMENT* *preorder*
. ,(lambda (tag . elems)
`("<!-- " ,@elems "-->"))))
(define default-rules
`(,attribute-rule
,default-rule
,text-rule
,comment-rule
,url-rule
,plain-html-rule
,nbsp-rule))
(define surflet-form-rule
`(surflet-form
;; Must do something to prevent the k-url string to be HTML
;; escaped.
*preorder*
. ,(lambda (trigger k-url . args)
(receive (parameters elems)
(optionals-first (list symbol? sxml-attribute?) args)
(make-surflet-form k-url ; k-url
(car parameters) ; POST, GET or #f=GET
(cadr parameters); attributes
elems)))))
(define (make-surflet-form k-url method attributes elems)
(let ((real-method (case method
((get GET) "GET")
((post POST) "POST")
((#f) "GET")
(else
(error "invalid method type" method)))))
(surflet-sxml->low-level-sxml
`(form (@ ((method ,real-method)
(action ,k-url)
,@(if attributes (cdr attributes) '())))
,@elems))))
(define input-field-rule
`(,*input-field-trigger*
*preorder*
. ,(lambda input-field
(surflet-sxml->low-level-sxml
(input-field-html-tree input-field)))))
(define surflet-sxml-rules
`(,@default-rules
;; form contents:
,input-field-rule
,surflet-form-rule))
;; Low-Level-SXML is a list that can be understood by
;; display-low-level-sxml. In contains only characters, strings, and
;; thunks.
(define (surflet-sxml->low-level-sxml sxml-tree)
(sxml->low-level-sxml sxml-tree surflet-sxml-rules))
;;; Helping funtion for surflet-sxml-rule
;; PRED-LIST contains list of predicates that recognizes optional
;; leading parameters. FURTHER-ATTRIBUTES is the optional parameter
;; list as got by procedure call. TYPED-OPTIONALS returns two values:
;; a list of the same length as PRED-LIST and a list containing the
;; left arguments that did not fit the predicates.
;;
;; With the help of OPTIONALS-FIRST you can define a function
;; like `make-submit-button [string] [further-attributes]' this way:
;; (define (make-submit-button . args)
;; (receive (params rest-args)
;; (prefix-optionals (list string? xml-attribute?) args)
;; (if (pair? rest-args)
;; (error "too many arguments to make-submit-button))
;; (let ((value (first params))
;; (attributes (second params)))
;; ...))))
;;
(define (optionals-first pred-list args)
(let loop ((results '())
(pred-list pred-list)
(args args))
(cond
((null? pred-list)
(values (reverse results) args))
((null? args)
(values (rev-append results (make-list (length pred-list) #f)) '()))
(((car pred-list) (car args))
(loop (cons (car args) results)
(cdr pred-list)
(cdr args)))
(else
(loop (cons #f results)
(cdr pred-list)
args)))))
@@ -0,0 +1,194 @@
We have three basic layers of structures: -*- Outline -*-
* Overview
(a) Basic User surflets, simple-surflet-api
(b) Advanced User surflets/my-sxml, surflets/my-sessions,
surflets/my-input-fields, surflets/primitives
(c) Administrative User surflet-handler/admin, profiling
The fourth layer:
(d) Various surflets/outdaters, surflets/utilities
Finally, there is a HOWTO added, that describes how you can use your
own rules.
* (a) Basic User
** structures: (1) surflets
provides: . sending of html represented by surflet-sxml
. using special tags in its surflet-sxml:
url, plain-html, surflet-form
. input-fields: input-field-value,
input-field-binding, ...
. get-bindings, extract-bindings, ...
. make-address, make-annotated-address, ...
. returned-via?, case-returned-via, ...
. get-session-data, set-session-data!
surflets contains of several parts, that can
be loaded independently from each other.
** structures: (2) simple-surflet-api
provides: . PLT like generation of simple web pages:
. single-query, form-query, inform-page,
final-page
. make-password, make-number...
* (b) Advanced User
** structures: (1) surflets/my-sxml
provides: . generating and sending of own sxml,
see HOWTO below
. send-html-string/suspend...
. sxml-rules...
. sxml->string
. surflet-sxml-rules...
. surflet-sxml->low-level-sxml
** structures: (2) surflets/my-sessions
provides: . Everything needed to administrate your own
sessions and continuations.
(This represents the access to the sessions of
one surflet. However, you currently have
access to all sessions. This will be
restricted in the future.)
. my-session-id, my-continuation-id,
instance-session-id
. get-session, delete-session!
. get-continuation, delete-continuation!
. session-adjust-timeout!, adjust-timeout!
. session-alive?, session-surflet-name
. access to options: options-session-lifetime,
options-cache-surflets?
** structures: (3) surflets/my-input-fields
provides: . Access to the primitives of input-fields:
. Constructor, selector, mutators, predicate
** structures: (4) surflet-handler/primitives
provides: . Access to the primitives of the
surflet handler:
. send/suspend, ... that send surflet responses
. send-error (sending Webserver error message)
. make-surflet-response, ... status-code:
surflet responses with own status-code, own
content-type, own headers and own content
(string or list of strings)
. surflet-requests...
* (c) Administrative User
** structures: (1) surflet-handler/admin
provides: . Access to all internal structures of the
handler
. surflets: get-loaded-surflets, unload-surflet
. sessions: get-session, get-sessions,
session-data, instance-session-id,
adjust-timeout..., session-record selectors
. continuations: get-continuations,
delete-continuations!
. resume-urls: resume-url?, resume-url-ids...
. options: options-session-lifetime...
set-options...!
surflet-handler/admin is splitted in several
parts, that can be loaded independently from
each other.
** structures: (2) profiling
provides: . Access to memory usage of the whole scsh session
. profile-space, profile-results,
with-gnuplot-data-file, space-info-pair,
space-info-symbol...
* (d) Various
** structures: (1) surflets/outdaters
provides: . Data structure to prevent call for outdated
links. This is useful if in some places of your
session the user should not go back and recall
another continuation.
. make-outdater, if-outdated, show-outdated
** structures: (2) surflets/utilities
provides: . Various utilities that didn't fit in another
package but were too small for an own one.
. form-query-list: url-query->alist
. rev-append
. make-callback enables you to place a callback
below a link. If the user clicks the link, an
arbitrary function is called.
. generate-unique-name generates name from a
prefix that are highest probable unique with
this prefix. For example this is used to
generate the names of the input fields.
* HOWTO use your own conversion rules:
** (i) Create your own conversion rules:
(trigger [*preorder*] . function)
- TRIGGER is the symbol that trigger the rule
- FUNCTION will get the trigger and the rest of the list, that
triggered the rule as arguments. Thus, if you know, you will
only get (at least x) arguments, FUNCTION must accept (at
least) x+1 arguments. FUNCTION must return a list
containing only characters or strings or, recursively, lists
of this type. (Well, there may be others also, but this is
too advanced.)
- If *PREORDER* misses, the rules will be first applied to all
arguments, before the are passed to function.
*** Examples:
MY-HEAD will take no args and creates my heading:
(define my-head-rule
`(my-head . (lambda (trigger)
(list "<head><title>My Page</title></head"))))
MY-TITLE-HEAD takes one argument, the title:
(define my-title-head-rul
`(my-title-head . (lambda (trigger title)
(list "<head><title>"
title
"</title></head"))))
*** SXML->STRING/INTERNAL
MY-ATTRIBUTED-HEAD takes attributes as well. As we don't want
to reformat this on our own, we use SXML->STRING/INTERNAL,
assuming that MY-RULES contains *all* the rules we use for
this sublist. As we do everything for the rest of the tree
ourselves, we use *preorder*:
(define my-attributed-head
`(my-attributed-head *preorder* .
,(lambda (trigger attributes title)
(sxml->string/internal `(head ,attributes (title ,title))
my-rules))))
** (ii) Create your own rule set.
A rule set is a list of conversion rules.
*** Example:
(define my-rules
(list default-rule
attribute-rule
text-rule
my-head-rule
my-title-head
my-attributed-head))
*** Note:
If you want to use SXML->STRING/INTERNAL with the same
rule set that entered the rule, you have to define them
either on top level with define or with letrec like
(letrec ((my-rules
(cons my-attributed-head-rule default-rules))
(my-attributed-head-rule
`(my-attributed-head *preorder* .
,(lambda (trigger attributes title)
(sxml->string/internal `(head ,attributes (title ,title))
my-rules)))))
my-rules)
-636
View File
@@ -1,636 +0,0 @@
;; utilities for surflet
;; Copyright 2002, Andreas Bernauer
(define (send-html/suspend html-tree-maker)
(send/suspend
(lambda (new-url)
(make-usual-html-response
(lambda (out options)
(display (surflet-XML->HTML #f (html-tree-maker new-url)) out))))))
(define (send-html/finish html-tree)
(do-sending send/finish html-tree))
(define (send-html html-tree)
(do-sending send html-tree))
(define (do-sending send html-tree)
(let ((html-page (surflet-XML->HTML #f html-tree)))
(send (make-usual-html-response
(lambda (out options)
(display html-page out))))))
(define (make-usual-html-response writer-proc)
(make-response
(status-code ok)
#f
(time)
"text/html"
'(("Cache-Control" . "no-cache"))
(make-writer-body writer-proc)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; from cgi-script:
;;; Return the form data as an alist of decoded strings.
;;; So a query string like "button=on&reply=Oh,%20yes" becomes alist
;;; (("button" . "on") ("reply" . "Oh, yes"))
;;; This works only for GET and POST methods.
(define form-query parse-html-form-query)
;; Bindings of POST requests can be read only once, since they are
;; read from an input port. So we have to cache them, for the case of
;; a later GET-BINDINGS call on the same POST request. The request are
;; referenced by a weak pointer.
(define *POST-bindings-cache* '())
(define *cache-lock* (make-lock))
(define (get-bindings request)
(let ((request-method (request-method request)))
(cond
((string=? request-method "GET")
(form-query (http-url-search (request-url request))))
((string=? request-method "POST")
(or (cached-bindings request)
(let* ((content-length (get-content-length (request-headers request)))
(input-port (socket:inport (request-socket request)))
(form-data (read-string content-length input-port)))
(let ((form-bindings (form-query form-data)))
(obtain-lock *cache-lock*)
(set! *POST-bindings-cache* (cons (cons (make-weak-pointer request)
form-bindings)
*POST-bindings-cache*))
(release-lock *cache-lock*)
form-bindings))))
(else
(error "unsupported request type")))))
;; Looking up, if we have cached this request. While going through the
;; list, we remove entries to request objects, that are no longer
;; valid. Expecting a call for an uncached request every now and then,
;; it is guaranteed, that the list is cleaned up every now and then.
(define (cached-bindings request)
(obtain-lock *cache-lock*)
(let ((result
(let loop ((cache *POST-bindings-cache*))
(if (null? cache)
#f ; no such request cached
(let* ((head (car cache))
(req (weak-pointer-ref (car head))))
(if req
(if (eq? req request)
(cdar cache) ; request is cached
(loop (cdr cache))) ; request isn't cached
(begin
;; request object is gone ==> remove it from list
(set! cache (cdr cache))
(loop cache))))))))
(release-lock *cache-lock*)
result))
(define get-header assoc)
;; Will be needed when we handle POST requests.
(define (get-content-length headers)
(cond ((get-header headers 'content-length) =>
;; adopted from httpd/cgi-server.scm
(lambda (content-length) ; Skip initial whitespace (& other non-digits).
(let ((first-digit (string-index content-length char-set:digit))
(content-length-len (string-length content-length)))
(if first-digit
(string->number (substring content-length first-digit
content-length-len))
;; (status-code bad-request) req
`(error "Illegal `Content-length:' header.")))))
(else
(error "No Content-length specified for POST data."))))
(define (extract-bindings key bindings)
(let ((key (if (symbol? key) (symbol->string key) key)))
(map cdr
(filter (lambda (binding)
(equal? (car binding) key))
bindings))))
(define (extract-single-binding key bindings)
(let ((key-bindings (extract-bindings key bindings)))
(if (= 1 (length key-bindings))
(car key-bindings)
(error "extract-one-binding: more than one or zero bindings found"
(length key-bindings)
key bindings))))
;; adapted from Oleg's SXML-tree-trans.scm
;; extended by port argument
;; #t: current-output-port
;; #f: string
;; port: port
;; else: error
(define (formated-reply port . fragments)
(cond
((not port)
(call-with-string-output-port
(lambda (port)
(real-formated-reply port fragments))))
((eq? port #t)
(real-formated-reply (current-output-port) fragments))
((output-port? port)
(real-formated-reply port fragments))
(else
(error "invalid port argument to FORMATED-REPLY" port))))
(define (real-formated-reply port fragments)
(let loop ((fragments fragments) (result #f))
(cond
((null? fragments) result)
((not (car fragments)) (loop (cdr fragments) result))
((null? (car fragments)) (loop (cdr fragments) result))
((pair? (car fragments))
(loop (cdr fragments) (loop (car fragments) result)))
((procedure? (car fragments))
((car fragments))
(loop (cdr fragments) #t))
(else
(display (car fragments) port)
(loop (cdr fragments) #t)))))
;; adapted from Oleg's SXML-to-HTML.scm
;; extended by additional port argument
(define (surflet-XML->HTML out html-tree)
(formated-reply out
(reformat html-tree)))
(define (reformat html-tree)
(pre-post-order
html-tree
`(
;; Universal transformation rules. Works for every HTML,
;; present and future
,@default-rules
(input-field
*preorder*
. ,(lambda (trigger input-field)
(reformat (input-field-HTML-tree input-field))))
(surflet-form
;; Must do something to prevent the callback-function string to
;; be HTML escaped.
*preorder*
. ,(lambda (trigger call-back-function . args)
(receive (parameters elems)
(typed-optionals (list symbol? XML-attribute?) args)
(make-surflet-form call-back-function
(car parameters)
(cadr parameters)
elems)))))
))
(define (make-surflet-form call-back-function method attributes elems)
(let ((real-method (case method
((get GET) "GET")
((post POST) "POST")
((#f) "GET")
(else
(error "invalid method type" method)))))
`("<form" ,@(map (lambda (attribute-value)
((enattr (car attribute-value)) (cadr attribute-value)))
`((method ,real-method)
(action ,call-back-function)
;; We have to divide attributes explicitly.
,@(if attributes (cdr attributes) '())))
#\> #\newline
,(reformat elems)
"</form>")))
(define (XML-attribute? thing)
(and (pair? thing)
(eq? '@ (car thing))))
(define attribute-rule
`(@ ; local override for attributes
((*default*
. ,(lambda (attr-key . value) ((enattr attr-key) value))))
. ,(lambda (trigger . value) (list '@ value))))
(define text-rule
`(*text*
. ,(lambda (trigger str)
(if (string? str) (string->goodHTML str) str))))
(define URL-rule
(cons 'URL
(lambda (tag URI . maybe-text) (list "<a href=\"" URI "\">"
(if (pair? maybe-text)
maybe-text
URI)"</a>"))))
(define plain-html-rule
`(plain-html
*preorder*
. ,(lambda (tag . text) text)))
(define default-rules
`(,attribute-rule
(*default*
. ,(lambda (tag . elems) (apply (entag tag) elems)))
,text-rule
,URL-rule
,plain-html-rule))
(define (make-callback function)
(call-with-current-continuation
(lambda (exit)
(let* ((req (send/suspend (lambda (new-url)
(exit new-url)))))
(function req)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; outdater
(define-record-type outdater :outdater
(real-make-outdater outdated?)
outdater?
(outdated? outdater-outdated? set-outdater-outdated?!))
(define (make-outdater)
(real-make-outdater #f))
(define-syntax if-outdated
(syntax-rules ()
((if-outdated outdater consequence alternative)
(if (outdater-outdated? outdater)
consequence
(begin
(set-outdater-outdated?! outdater #t)
alternative)))))
(define (show-outdated url)
(send-html
`(html (title "Outdated Data")
(body (h1 "Outdated Data")
(p "The page or action you requested relies on outdated data")
,(if url
`(p "Try to "
(URL ,url "reload")
" the page to get current data.")
'())))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; input-fields
;;; defines input-fields for surflets
(define-record-type input-field :input-field
(real-make-input-field name transformer HTML-tree get-bindings?)
input-field?
(name input-field-name)
(transformer input-field-transformer)
(attributes input-field-attributes)
(HTML-tree input-field-HTML-tree)
(get-bindings? input-field-get-bindings?))
(define-record-discloser :input-field
(lambda (input-field)
(list 'input-field
(input-field-name input-field))))
;; FIXME: consider creating small names
(define generate-unique-name
(let ((id 0))
(lambda (type-string)
(set! id (+ 1 id))
(string-append type-string (number->string id)))))
(define generate-input-field-name generate-unique-name)
(define identity (lambda (a) a))
(define (make-input-field name transformer HTML-tree)
(list 'input-field (real-make-input-field name transformer HTML-tree #f)))
(define (make-higher-input-field transformer HTML-tree)
(list 'input-field (real-make-input-field #f transformer HTML-tree #t)))
;; PRED-LIST contains list of predicates that recognizes optional
;; leading parameters. FURTHER-ATTRIBUTES is the optional parameter
;; list as got by procedure call. TYPED-OPTIONALS returns two values:
;; a list of the same length as PRED-LIST and a list containing the
;; left arguments that did not fit the predicates.
;;
;; With the help of TYPED-OPTIONALS you can define a function
;; like `make-submit-button [string] [further-attributes]' this way:
;; (define (make-submit-button . args)
;; (receive (params rest-args)
;; (prefix-optionals (list string? XML-attribute?) args)
;; (if (pair? rest-args)
;; (error "too many arguments to make-submit-button))
;; (let ((value (first params))
;; (attributes (second params)))
;; ...))))
;;
(define (typed-optionals pred-list args)
(let loop ((results '())
(pred-list pred-list)
(args args))
(cond
((null? pred-list)
(values (reverse results) args))
((null? args)
(values (rev-append results (make-list (length pred-list) #f)) '()))
(((car pred-list) (car args))
(loop (cons (car args) results)
(cdr pred-list)
(cdr args)))
(else
(loop (cons #f results)
(cdr pred-list)
args)))))
(define-syntax optionals
(lambda (exp rename compare)
(let ((%receive (rename 'receive))
(%typed-optionals (rename 'typed-optionals))
(%list (rename 'list))
(%if (rename 'if))
(%pair? (rename 'pair?))
(%error (rename 'error))
(%let (rename 'let))
(%list-ref (rename 'list-ref))
(args (cadr exp))
(var-list (caddr exp))
(body (cadddr exp)))
`(,%receive (params rest-args)
(,%typed-optionals (,%list ,@(map cadr var-list)) ,args)
(,%if (pair? rest-args)
(,%error "optionals: too many arguments and/or argument type mismatch")
(,%let (,@(let loop ((counter 0)
(var-list var-list))
(if (null? var-list)
'()
(cons (cons (caar var-list) `((,%list-ref params ,counter)))
(loop (+ 1 counter)
(cdr var-list))))))
,body))))))
;; from uri.scm
(define (rev-append a b) ; (append (reverse a) b)
(let rev-app ((a a) (b b)) ; Should be defined in a list-proc
(if (pair? a) ; package, not here.
(rev-app (cdr a) (cons (car a) b))
b)))
(define (make-text-input-field . maybe-further-attributes)
(let ((name (generate-input-field-name "text")))
(optionals maybe-further-attributes
((default-text string?)
(attributes XML-attribute?))
(make-input-field name
identity
`(input (@ (type "text")
(name ,name)
,(and default-text `(value ,default-text))
;; this will insert a list, but
;; XML->HTML doesn't care about it
,(and attributes (cdr attributes))
))))))
(define make-number-input-field
(let ((number-input-field-transformer
(lambda (string)
(or (string->number string)
(error "wrong type")))
))
(lambda maybe-further-attributes
(let ((name (generate-input-field-name "number")))
(optionals maybe-further-attributes
((default (lambda (a) (or (number? a)
(string-or-symbol? a))))
(attributes XML-attribute?))
(make-input-field
name
number-input-field-transformer
`(input (@ (type "text")
(name ,name)
,(and default `(value ,default))
,(and attributes (cdr attributes))))))))))
(define (make-password-input-field . maybe-further-attributes)
(let ((name (generate-input-field-name "password")))
(optionals maybe-further-attributes
((attributes XML-attribute?))
(make-input-field
name
identity
`(input (@ (type "password")
(name ,name)
,(and attributes (cdr attributes))))))))
(define (make-textarea-input-field . maybe-further-attributes)
(let ((name (generate-input-field-name "textarea")))
(optionals maybe-further-attributes
((default-text string?)
(attributes XML-attribute?))
(make-input-field
name
identity
`(textarea (@ (type "textarea")
(name ,name)
,(and attributes (cdr attributes)))
,(and default-text))))))
;(make-select-input-fields '("this" "that" "those") '(@ ((id "sushi"))))
;(make-select-input-fields '("this" ("that" '(@ (selected))) "those"))
;; dropdown: (size 1)
;; multiple choice: (multiple)
;; preselected option: (selected)
;; changed return value: (value new-value)
;; returns a select input field with several options
(define make-select-input-field
(let ((make-multiple-transformer
(lambda (name)
(lambda (bindings)
(map cdr
(filter (lambda (binding)
(equal? (car binding) name))
bindings))))))
(lambda (options . maybe-further-attributes)
(optionals maybe-further-attributes
((multiple? boolean?)
(attributes XML-attribute?))
(let* ((name (generate-input-field-name "select"))
(SXML-options
(map (lambda (option)
(cond
((string-or-symbol? option)
(list 'option option))
((list? option)
(cond
((null? (cdr option))
`(option ,option))
((XML-attribute? (cdr option)) ; w/attribs?
`(option ,(cdr option) ,(car option)))
(else
(error "not an attribute" (cdr option)))))
(else
(error "not an option" option))))
options))
(SXML `(select (@ ((name ,name)
,(if multiple? '(multiple) '())
,(and attributes (cdr attributes))))
#\newline
,SXML-options)))
(if multiple?
(make-higher-input-field (make-multiple-transformer name) SXML)
(make-input-field name identity SXML)))))))
;; returns a *list* of radio buttons
(define (make-radio-input-fields values . maybe-further-attributes)
(let ((name (generate-input-field-name "radio")))
(optionals maybe-further-attributes
((attributes XML-attribute?))
(map (lambda (value)
(let ((value-value (if (pair? value) (car value) value))
(value-attributes (if (pair? value)
(if (XML-attribute? (cdr value))
(cddr value)
(error "not an attribute" cdr value))
#f)))
(make-input-field
name
(lambda (select)
select)
`(input (@ ((type "radio")
(name ,name)
(value ,value-value)
,(and value-attributes)
,(and attributes (cdr attributes))))))))
values))))
;; returns a checkbox input field
(define (make-checkbox-input-field . maybe-further-attributes)
(let* ((name (generate-input-field-name "checkbox")))
(optionals maybe-further-attributes
((checked? boolean?)
(value (lambda (a) (or (string? a)
(number? a)
(symbol? a))))
(attributes XML-attribute?))
(make-input-field
name
identity
`(input (@ ((type "checkbox")
(name ,name)
,(if value `(value ,value) '())
,(if checked? '(checked) '())
,(and attributes (cdr attributes)))))))))
(define (make-hidden-input-field value . maybe-further-attributes)
(let ((name (generate-input-field-name "hidden")))
(optionals maybe-further-attributes
((attributes XML-attribute?))
(make-input-field name
identity
`(input (@ (type "hidden")
(name ,name)
(value ,value)
,(and attributes (cdr attributes))))))))
(define (make-button type name button-caption attributes)
(make-input-field name
identity
`(input (@ (type ,type)
(name ,name)
,(and button-caption `(value ,button-caption))
,(and attributes (cdr attributes))))))
(define (string-or-symbol? a)
(or (string? a)
(symbol? a)))
(define (make-submit-button . maybe-further-attributes)
(optionals maybe-further-attributes
((button-caption string-or-symbol?)
(attributes XML-attribute?))
(make-button "submit" (generate-input-field-name "submit")
button-caption attributes)))
(define (make-reset-button . maybe-further-attributes)
(optionals maybe-further-attributes
((button-caption string-or-symbol?)
(attributes XML-attribute?))
(make-button "reset" (generate-input-field-name "reset")
button-caption attributes)))
(define (make-image-button image-source . maybe-further-attributes)
(optionals maybe-further-attributes
((attributes XML-attribute?))
(make-button "image" (generate-input-field-name "imgbtn")
#f `(@ (src ,image-source)
,@(if attributes (cdr attributes) '())))))
;; <input-field>: '(input-field . <real-input-field>)
;; <real-input-field>: #{Input-field "name"}
(define (raw-input-field-value input-field bindings)
(let ((input-field (cadr input-field)))
(cond
((input-field-get-bindings? input-field)
((input-field-transformer input-field) bindings))
((real-input-field-binding input-field bindings) =>
(lambda (binding)
((input-field-transformer input-field) (cdr binding))))
(else
(error "no such input-field" input-field bindings)))))
;; Trys to get a value for INPUT-FIELD in BINDINGS. If this fails
;; (i.e. RAW-INPUT-FIELD-VALUE returns an error), the default-value is
;; returned. The default-value defaults to #f. NOTE: If you do this
;; with input-fields whose valid values may be the same as the default
;; value, you cannot determine by the result if there was such a value
;; or not. Keep in mind, that RAW-INPUT-FIELD-VALUE returns also an
;; error, if there was not such an input field. This makes
;; INPUT-FIELD-VALUE working with checkbox input fields because they
;; miss if they are not checked.
(define (input-field-value input-field bindings . maybe-default)
(let ((default (:optional maybe-default #f)))
(with-fatal-error-handler
(lambda (condition more)
default)
(raw-input-field-value input-field bindings))))
(define (real-input-field-binding input-field bindings)
(assoc (input-field-name input-field) bindings))
(define (input-field-binding input-field bindings)
(real-input-field-binding (cadr input-field) bindings))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; return address
;; generates an unique return-addres
;; may be used like
;; (let ((address (make-address)))
;; (send-html/suspend
;; (lambda (new-url)
;; ...
;; (URL (address new-url) "Click here to get more")...)
(define (make-address)
(let ((name (generate-unique-name "return")))
(lambda (message)
(cond
((string? message)
(string-append message "?" name "="))
((eq? message 'name)
name)
(else ;maybe we want more later...
(error "unknown message" message name))))))
(define (returned-via? return-address bindings)
(assoc (return-address 'name) bindings))
+77
View File
@@ -0,0 +1,77 @@
;;; Copyright 2002, 2003 Andreas Bernauer
;;; adapted from Oleg's SXML-tree-trans.scm SRV:send-reply
;;; extended by port argument
;;; #t: current-output-port
;;; #f: string
;;; port: port
;;; else: error
;; Displays low-level-sxml on the port. Low-level-sxml contains only
;; strings, characters and thunks. '() and #f are ignored.
(define (display-low-level-sxml fragments port)
(let loop ((fragments fragments) (result #f))
(cond
((null? fragments) result)
((not (car fragments)) (loop (cdr fragments) result))
((null? (car fragments)) (loop (cdr fragments) result))
((pair? (car fragments))
(loop (cdr fragments) (loop (car fragments) result)))
((procedure? (car fragments))
((car fragments))
(loop (cdr fragments) #t))
(else
(display (car fragments) port)
(loop (cdr fragments) #t)))))
(define sxml->low-level-sxml pre-post-order)
;; Gives you a string representing the HTML of the already reformatted
;; SXML-TREE.
(define (sxml->string sxml-tree rules)
(call-with-string-output-port
(lambda (port)
(display-low-level-sxml
(pre-post-order sxml-tree rules)
port))))
(define (sxml->string/internal sxml-tree rules)
(list (sxml->string sxml-tree rules)))
;; Predicate for attributes in sxml.
(define (sxml-attribute? thing)
(and (pair? thing)
(eq? '@ (car thing))))
;; Returns the attribute list after the initial '@. For our
;; convenience, it ignores values that are not sxml-attributes.
(define (sxml-attribute-attributes thing)
(if (sxml-attribute? thing)
(cdr thing)
'()))
;; Default rule: Creates leading and trailing tag and encloses the
;; attributes.
(define default-rule
`(*default*
. ,(lambda (tag . elems) (apply (entag tag) elems))))
;; Just displays the string, except that some characters are escaped.
(define text-rule
`(*text*
. ,(lambda (trigger str)
(if (string? str) (string->goodHTML str) str))))
;; Rule for attribution: creates an attribute like "selected" or
;; "color="red""
(define attribute-rule
`(@ ; local override for attributes
((*default*
. ,(lambda (attr-key . value) (enattr attr-key value))))
. ,(lambda (trigger . value) (list '@ value))))
;; Create attribution-value pair for inside of tags
;; If the attribute has no value, value must be '()
(define (enattr attr-key attr-value)
(if (null? attr-value)
(list #\space attr-key)
(list #\space attr-key "=\"" attr-value #\")))
@@ -0,0 +1,26 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; thread-safe counter
(define-record-type counter :counter
(really-make-counter counter lock)
thread-safe-counter?
(counter counter-counter set-counter-counter!)
(lock counter-lock))
(define (make-thread-safe-counter)
(really-make-counter 0 (make-lock)))
;;; read current value
(define (thread-safe-counter-value counter)
(obtain-lock (counter-lock counter))
(let ((result (counter-counter counter)))
(release-lock (counter-lock counter))
result))
;;; make next value and return it
(define (thread-safe-counter-next! counter)
(obtain-lock (counter-lock counter))
(let ((result (+ 1 (counter-counter counter))))
(set-counter-counter! counter result)
(release-lock (counter-lock counter))
result))
+35
View File
@@ -0,0 +1,35 @@
;; utilities for surflets
;; Copyright 2002, 2003 Andreas Bernauer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; from parse-html-forms (cgi-script)
;;; Return the form data as an alist of decoded strings.
;;; So a query string like "button=on&reply=Oh,%20yes" becomes alist
;;; (("button" . "on") ("reply" . "Oh, yes"))
;;; This works only for GET and POST methods.
(define (form-query-list q)
(if q
(parse-html-form-query q)
'()))
;; from uri.scm
(define (rev-append a b) ; (append (reverse a) b)
(let rev-app ((a a) (b b)) ; Should be defined in a list-proc
(if (pair? a) ; package, not here.
(rev-app (cdr a) (cons (car a) b))
b)))
;; Every call will surely return another number.
(define generate-unique-number
(let ((id 0))
(lambda ()
(set! id (+ 1 id))
id)))
;; FIXME: consider creating small names
(define (generate-unique-name type-string)
(string-append type-string
(number->string (generate-unique-number))))
(define identity (lambda (a) a))
Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

@@ -1,54 +0,0 @@
(define-structure surflet surflet-interface
(open surflets
httpd-requests
url
handle-fatal-error
let-opt
scheme-with-scsh)
(begin
(define number-input-field (make-number-input-field))
(define (get-number title input-text)
(let* ((result
(send-html/suspend
(lambda (new-url)
`(html (title ,title)
(body
(h2 ,title)
(p
(surflet-form ,new-url
,input-text " "
,number-input-field
,(make-submit-button)))
(hr)
(p (URL "/" "Return to main menu.") (br)
(URL "add2.scm" "Start new calculation."))))))))
(if result
(or (input-field-value number-input-field
(form-query (http-url-search (request-url result))))
(get-number title "Please enter a valid number."))
(get-number title "Please enter a number."))))
(define (get-number1)
(get-number "Calculation - Step one" "First number:"))
(define (get-number2)
(get-number "Calculation - Step two" "Second number:"))
(define (main req)
(let ((number1 (get-number1))
(number2 (get-number2)))
(send-html
`(html (title "Result")
(body (h2 "Result")
(p ,(number->string (+ number1 number2)))
(hr)
(p (URL "add2.scm" "Make new calculation.") (br)
(URL "javascript:history.go(-2)" "New calculation (same session)")
(br)
(URL "/" "Return to main menu.")))))
"this string will never be evaluated"))
))
@@ -1,337 +0,0 @@
(define-structure surflet surflet-interface
(open scheme-with-scsh
surflets
surflet-handler/admin
httpd-responses
httpd-requests
url
handle-fatal-error
let-opt
srfi-1 ;filter-map, last
sort
)
(begin
(define remove-surflet-path
(let ((regexp (rx ,(file-name-as-directory (options-surflet-path))
(submatch (* any)))))
(lambda (file-name)
(let ((match (regexp-search regexp file-name)))
(if match
(match:substring match 1)
file-name)))))
;; returns two values: an action to perform out of ACTIONS and a
;; list of selected elements out of TABLE-ELEMENTS.
(define (select-table title header header-row
table-elements selector actions footer)
(let* ((checkboxes (map (lambda (_)
(make-checkbox-input-field))
table-elements))
(action-title "Choose an action")
(select (make-select-input-field (cons action-title actions)
'(@ (size 1))))
(req
(send-html/suspend
(lambda (new-url)
`(html
(title ,title)
(body
,header
(surflet-form
,new-url
POST
(table
,@(cons '(th) header-row)
,@(map (lambda (checkbox table-element)
`(tr
(td ,checkbox)
,@(selector table-element)))
checkboxes
table-elements))
(p ,select
,(make-submit-button "Do it")))
,footer)))))
(bindings (get-bindings req))
(action (input-field-value select bindings)))
(if (string=? action action-title)
(values #f #f req)
(values action
(filter-map (lambda (checkbox table-element)
(if (input-field-value checkbox bindings)
table-element
#f))
checkboxes
table-elements)
req))))
(define (unload-surflets outdated? surflet-names)
(if-outdated outdated?
(show-outdated (make-callback show-surflets))
(for-each unload-surflet surflet-names)))
(define (no-surflets)
`(p "Currently, there are no SUrflets loaded "
(URL ,(make-callback show-surflets) "(reload)")
", but there may be "
(URL ,(make-callback show-sessions) "sessions")
" you want to administer."))
(define (show-surflets req . maybe-update-text)
(let* ((update-text (:optional maybe-update-text ""))
(loaded-surflets (sort-list! (get-loaded-surflets) string<?))
(outdated? (make-outdater))
(title "SUrflet-Administration -- SUrflets")
(header `((h1 "SUrflet Administration")
(h2 "SUrflets")
(p (font (@ (color "red")) ,update-text))))
(footer `((hr)
(URL ,(make-callback return-to-main-page) "Return to administration menu.")
(br)
(URL "/" "Return to main menu.")))
(actions '("unload" "unload all")))
(if (null? loaded-surflets)
(send-html `(html (title ,title) (body ,header ,(no-surflets) ,footer)))
(receive (action selected-surflets req)
(select-table title ; title
header ; header
'((th "Name")) ; table-header
loaded-surflets ; list of elements
(lambda (surflet) ; selector
`((td
,(remove-surflet-path surflet))))
actions ; actions to perform
(cons ; footer
`(p "Note that unloading the SUrflets does not imply "
"the unloading of sessions of this SUrflet. " (br)
"This can be done on the "
(URL ,(make-callback show-sessions)
"sessions adminstration page."))
footer))
(if (not action)
(show-surflets 'no-req "Choose an action.")
(if (and (null? selected-surflets)
(not (string=? action "unload all")))
(show-surflets 'no-req "You must choose at least one element.")
(cond
((string=? action "unload")
(unload-surflets outdated? selected-surflets)
(show-surflets 'no-req "SUrflets unloaded."))
((string=? action "unload all")
(unload-surflets outdated? loaded-surflets)
(show-surflets 'no-req "SUrflets unloaded."))
(else
(error "unknown action" action)))))))))
(define (session-surflet-name<? entry1 entry2)
(let ((name1 (session-surflet-name (cdr entry1)))
(name2 (session-surflet-name (cdr entry2))))
;; handle multiple session names
(if (string=? name1 name2)
(session-id<? entry1 entry2)
(string<? name1 name2))))
(define (session-id<? entry1 entry2)
;; there are no multiple session-ids
(< (car entry1) (car entry2)))
(define (session-id>? entry1 entry2)
(session-id<? entry2 entry1))
(define (session-surflet-name>? entry1 entry2)
(session-surflet-name<? entry2 entry1))
(define (no-current-sessions)
;; Avoid using send/suspend in this context as there
;; are no sessions available any more.
'(p "Currently, there are no sessions, "
"i.e. the administration SUrflet is no longer running. "
;; Can't use callback here, as there are no valid sessions left.
(URL "admin.scm" "Go back to main page.")))
(define (show-sessions req . maybe-update-text)
(let* ((update-text (:optional maybe-update-text ""))
(current-sessions (sort-list! (get-sessions) session-surflet-name<?)))
(real-sessions current-sessions update-text
(resume-url-session-id
(last (http-url-path (request-url req)))))))
(define (real-sessions current-sessions update-text this-session-id)
(let ((outdated? (make-outdater))
(title "SUrflet Adminstration - Sessions")
(header `((h1 "SUrflet Administration")
(h2 "Sessions")
(p (font (@ (color "red")) ,update-text))))
(footer `(,(if (not (null? current-sessions))
`(p "Be careful not to kill this adminstration's "
"session (id: " ,this-session-id ").")
#f)
(hr)
(URL ,(make-callback show-surflets) "Return to SUrflets menu.") (br)
(URL ,(make-callback return-to-main-page) "Return to administration menu.")
(br)
(URL "/" "Return to main menu.")))
(actions '("kill"
"adjust timeout"
"view continuations"))
(sessions-callback (make-callback show-sessions)))
(if (null? current-sessions)
(send-html `(html (title ,title)
(body ,@header ,(no-current-sessions) ,footer)))
(receive (action selected-sessions req)
(select-table title
header
`((th "SUrflet Name") (th "Session-Id"))
current-sessions
(lambda (session-pair)
(let ((session-id (car session-pair))
(session-entry (cdr session-pair)))
`((td ,(session-surflet-name session-entry))
(td (@ (align "right")) ,session-id))))
actions
footer)
(if (not action)
(show-sessions current-sessions "Choose an action.")
(let ((new-update-text
(cond
((string=? action "kill")
(if-outdated outdated?
(show-outdated sessions-callback)
(for-each delete-session!
(map car selected-sessions)))
"Sessions killed.")
((string=? action "adjust timeout")
(if-outdated outdated?
(show-outdated sessions-callback)
(for-each session-adjust-timeout!
(map car selected-sessions)))
"Timeout adjusted.")
((string=? action "view continuations")
(if-outdated outdated?
(show-outdated sessions-callback)
(if (zero? (length selected-sessions))
"You must choose at least one session."
;; this does not return
(show-continuations selected-sessions req))))
(else
(error "unknown action" action)))))
(show-sessions current-sessions new-update-text)))))))
(define (no-current-continuations session req)
`((p "Currently, there are no continuations for this session. ")
(p "You may " (URL ,(make-callback
(lambda (req) (show-continuations (list session) req)))
"reload")
" this page or go back to the "
(URL ,(make-callback show-sessions) "session table overview."))))
(define (no-more-than-one-session title header1 sessions req)
(send-html
`(html (title ,title)
(body (h1 "SUrflet Administration")
(p "Currently, you may only view the continuations of "
"one session at a time. This will be changed in "
"future revisions. Sorry for any inconvenience.")
(p "You may choose to go back to the "
(URL ,(make-callback show-sessions)
"sessions administration page")
" where you can select one session"
" or select one session from your chosen sessions:" (br)
(ul
,@(map (lambda (session)
`(li (URL ,(make-callback
(lambda (req)
(show-continuations (list session) req)))
,(session-surflet-name (cdr session))
" (" ,(car session) ")")))
sessions)))))))
(define (continuation-id<? entry1 entry2)
(< (car entry1) (car entry2)))
(define (show-continuations sessions req . maybe-update-text)
(let ((title "SUrflet Adminstration - Continuations")
(header1 '(h1 "SUrflet Administration")))
(if (not (= 1 (length sessions)))
(no-more-than-one-session title header1 sessions req)
(let* ((session-pair (car sessions))
(session-id (car session-pair))
(session-entry (cdr session-pair))
(this-continuation-id (resume-url-continuation-id
(last (http-url-path (request-url req)))))
(update-text (:optional maybe-update-text "")))
(let* ((current-continuations
(sort-list! (get-continuations session-id)
continuation-id<?))
(outdated? (make-outdater))
(header (cons header1
`((h2 "Continuations of " ,session-id)
(p "(belongs to the SUrflet '"
,(session-surflet-name session-entry) "')")
(p (font (@ (color "red")) ,update-text)))))
(footer
`(,(if (not (null? current-continuations))
`(p "Be careful not to delete this adminstration's "
"continuation (id: " ,this-continuation-id ").")
#f)
(hr)
(URL ,(make-callback show-surflets) "Return to SUrflets menu.") (br)
(URL ,(make-callback show-sessions) "Return to sessions menu.") (br)
(URL ,(make-callback return-to-main-page) "Return to administration menu.")
(br)
(URL "/" "Return to main menu.")))
(actions '("delete" "delete all"))
(continuations-callback
(make-callback (lambda (req)
(show-continuations sessions req)))))
(if (null? current-continuations)
(send-html `(html (title ,title)
(body ,header
,(no-current-continuations session-pair req)
,footer)))
(receive (action selected-continuations req)
(select-table title
header
'((th "Continuation-Id"))
current-continuations
(lambda (continuation-pair)
(let ((continuation-id (car continuation-pair)))
`((td (@ (align "right")) ,continuation-id))))
actions
footer)
(if (not action)
(show-continuations sessions req
"Choose an action.")
(begin
(cond
((string=? action "delete")
(delete-continuations outdated? continuations-callback
session-id selected-continuations))
((string=? action "delete all")
(delete-continuations outdated? continuations-callback
session-id current-continuations))
(else
(error "unknown action" action)))
(show-continuations sessions req
"Deleted."))))))))))
(define (delete-continuations outdated? continuations-callback
session-id continuations)
(if-outdated outdated?
(show-outdated continuations-callback)
;; Do it this way to easily expand to more sessions in the
;; future.
(for-each delete-continuation!
(make-list (length continuations)
session-id)
(map car continuations))))
(define (return-to-main-page req)
(send/finish (make-error-response (status-code moved-perm) req
"admin.scm" "admin.scm")))
(define (main req)
(show-surflets req))
))
@@ -0,0 +1,37 @@
(define-structure surflet surflet-interface
(open surflets
handle-fatal-error
surflets/error
scheme-with-scsh)
(begin
(define (main req)
(let* ((select-input-field
(make-select
(map make-annotated-select-option
'("Icecream" "Chocolate" "Candy")
'(1.5 2.0 0.5))))
(req (send-html/suspend
(lambda (k-url)
`(html
(head (title "Sweet Store"))
(body
(h1 "Your choice")
(surflet-form
,k-url
(p "Select the sweet you want:"
,select-input-field)
,(make-submit-button)))))))
(bindings (get-bindings req))
(cost (with-fatal-error-handler
(lambda (condition decline)
(send-error (status-code bad-request)
req
"No such option or internal error.
Please try again.") )
(raw-input-field-value select-input-field bindings))))
(send-html/finish
`(html (head (title "Receipt"))
(body
(h2 "Your receipt:")
(p "This costs you $" ,cost "."))))))
))
@@ -0,0 +1,29 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(let* ((select-input-field
(make-select
(map make-annotated-select-option
'("Icecream" "Chocolate" "Candy")
'(1.5 2.0 0.5))))
(req (send-html/suspend
(lambda (k-url)
`(html
(head (title "Sweet Store"))
(body
(h1 "Your choice")
(surflet-form
,k-url
(p "Select the sweet you want:"
,select-input-field)
,(make-submit-button)))))))
(bindings (get-bindings req))
(cost (input-field-value select-input-field bindings)))
(send-html/finish
`(html (head (title "Receipt"))
(body
(h2 "Your receipt:")
(p "This costs you $" ,cost "."))))))
))
@@ -0,0 +1,28 @@
(define-structure surflet surflet-interface
(open surflets
surflets/callbacks
scheme-with-scsh)
(begin
(define (main req)
(let ((language (make-annotated-callback result-page)))
(send-html
`(html
(head (title "Multi-lingual"))
(body
(h2 "Select your language:")
(ul
(li (url ,(language "Hello, how are you?")
"English")
(li (url ,(language "Hallo, wie geht es Ihnen?")
"Deutsch")))))))))
(define (result-page req text)
(send-html/finish
`(html
(head (title "Greeting"))
(body
(h2 ,text)))))
))
@@ -0,0 +1,31 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(let* ((language (make-annotated-address))
(req (send-html/suspend
(lambda (k-url)
`(html
(head (title "Multi-lingual"))
(body
(h2 "Select your language:")
(ul
(li (url ,(language k-url "Hello, how are you?")
"English")
(li (url ,(language k-url "Hallo, wie geht es Ihnen?")
"Deutsch")))))))))
(bindings (get-bindings req)))
(case-returned-via bindings
((language) => result-page))))
(define (result-page text)
(send-html/finish
`(html
(head (title "Greeting"))
(body
(h2 ,text)))))
))
@@ -0,0 +1,31 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(let* ((english (make-address))
(german (make-address))
(req (send-html/suspend
(lambda (k-url)
`(html
(head (title "Multi-lingual"))
(body
(h2 "Select your language:")
(ul
(li (url ,(english k-url) "English")
(li (url ,(german k-url) "Deutsch")))))))))
(bindings (get-bindings req)))
(case-returned-via bindings
((english) (result-page "Hello, how are you?"))
((german) (result-page "Hallo, wie geht es Ihnen?")))))
(define (result-page text)
(send-html/finish
`(html
(head (title "Greeting"))
(body
(h2 ,text)))))
))
@@ -0,0 +1,12 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(send-html/finish
`(html (body (h1 "Hello, world!")
(p "The current date and time is "
,(format-date "~H:~M:~S ~p ~m/~d/~Y" (date)))))))
))
@@ -0,0 +1,15 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(send-html/suspend
(lambda (k-url)
`(html (body (h1 "Hello, world!")
(p (a (@ (href ,k-url)) "Next page -->"))))))
(send-html/finish
'(html (body (h1 "Hello, again!")))))
))
@@ -0,0 +1,10 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(send-html/finish
'(html (body (h1 "Hello, world!")))))
))
@@ -0,0 +1,46 @@
(define-structure surflet surflet-interface
(open surflets
surflets/my-input-fields
scheme-with-scsh)
(begin
(define (make-nibble-input-fields)
(let ((checkboxes (list (make-annotated-checkbox 8)
(make-annotated-checkbox 4)
(make-annotated-checkbox 2)
(make-annotated-checkbox 1))))
(make-multi-input-field
#f "nibble-input"
(lambda (input-field bindings)
(let loop ((sum 0)
(checkboxes checkboxes))
(if (null? checkboxes)
sum
(loop (+ sum (or (input-field-value (car checkboxes)
bindings)
0))
(cdr checkboxes)))))
'()
(lambda (ignore)
checkboxes))))
(define nibble-input-field (make-nibble-input-fields))
(define (main req)
(let* ((req (send-html/suspend
(lambda (new-url)
`(html (title "Nibble Input Widget")
(body
(h1 "Nibble Input Widget")
(p "Enter your nibble (msb left):")
(surflet-form ,new-url
,nibble-input-field
,(make-submit-button)))))))
(bindings (get-bindings req))
(number (input-field-value nibble-input-field bindings)))
(send-html
`(html (title "Result")
(body
(h2 "Result")
(p "You've entered " ,number "."))))))
))
@@ -0,0 +1,23 @@
(define-structure surflet surflet-interface
(open surflets
scheme-with-scsh)
(begin
(define (main req)
(let* ((text-input (make-text-field))
(submit-button (make-submit-button))
(req (send-html/suspend
(lambda (k-url)
`(html
(body
(h1 "Echo")
(surflet-form ,k-url
(p "Please enter something:"
,text-input
,submit-button)))))))
(bindings (get-bindings req))
(user-input (input-field-value text-input bindings)))
(send-html/finish
`(html (body
(h1 "Echo result")
(p "You've entered: '" ,user-input "'."))))))
))
@@ -1,49 +0,0 @@
(define-structure surflet surflet-interface
(open scheme-with-scsh
surflets
httpd-responses)
(begin
(define select (make-select-input-field '("a" "b" "c") #t '(@ (size 2))))
(define (main req)
(let ((req (send-html/suspend
(lambda (new-url)
`(html (body (h1 "This is from SUrflet")
(surflet-form
,new-url
POST
,select
,(make-submit-button))
(hr)
(p (URL "/" "Return to main menu."))
)))))
(save-k #f)
(done? #f))
(call-with-current-continuation
(lambda (k)
(set! save-k k)
13))
(if (not done?)
(begin
(send-html/suspend
(lambda (continue)
`(html (body (h1 "Result")
,(format #f "~s" (get-bindings req)) (br)
(URL ,continue "show results again")
(hr)
(p (URL "test.scm" "Test again.") (br)
(URL "/" "Return to main menu."))))))
(set! done? #t)
(save-k 13))
(send-html/finish
`(html (body (h1 "Result 2")
,(format #f "~s" (get-bindings req))
(hr)
(p (URL "test.scm" "Test again.") (br)
(URL "/" "Return to main menu."))))))))
))
+15
View File
@@ -0,0 +1,15 @@
;; From sunterlib
(define (with-lock* lock thunk)
(dynamic-wind
(lambda ()
(obtain-lock lock))
thunk
(lambda ()
(release-lock lock))))
(define-syntax with-lock
(syntax-rules ()
((with-lock lock body ...)
(with-lock* lock (lambda () body ...)))))
+51
View File
@@ -0,0 +1,51 @@
;;; NCSA's WWW Common Gateway Interface -- script-side code -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1995 by Olin Shivers.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; See http://hoohoo.ncsa.uiuc.edu/cgi/interface.html for a sort of "spec".
;;; This file provides routines to help you write programs in Scheme
;;; that can interface to HTTP servers using the CGI program interface
;;; to carry out HTTP transactions.
;;; ISINDEX queries:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (Likewise for ISINDEX URL queries from browsers.)
;;; Browser url-form encodes the query (see above), which then becomes the
;;; ?<search> part of the URI. (Hence the CGI script will split the individual
;;; fields into argv[].)
;;; CGI interface:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; - The URL's <search> part is assigned to env var $QUERY_STRING, undecoded.
;;; - If it contains no raw "=" chars, it is split at "+" chars. The
;;; substrings are URI decoded, and become the elts of argv[]. You aren't
;;; supposed to rely on this unless you are replying to ISINDEX queries.
;;; - The CGI script is run with stdin hooked up to the socket. If it's going
;;; to read the entity, it should read $CONTENT_LENGTH bytes worth.
;;; - A bunch of env vars are set with useful values.
;;; - Entity block is passed to script on stdin;
;;; script writes reply to stdout.
;;; - If the script begins with "nph-" its output is the entire reply.
;;; Otherwise, when it replies to the server, it sends back a special
;;; little header that tells the server how to construct the real header
;;; for the reply.
;;; See the "spec" for further details. (URL above)
(define (cgi-form-query)
(let ((request-method (getenv "REQUEST_METHOD")))
(cond
((string=? request-method "GET")
(parse-html-form-query (getenv "QUERY_STRING")))
((string=? request-method "POST")
(let ((nchars (string->number (getenv "CONTENT_LENGTH"))))
(parse-html-form-query (read-string nchars))))
(else (error "Method not handled."))))) ; Don't be calling me.
+50
View File
@@ -0,0 +1,50 @@
;;; Read cr/lf and lf terminated lines. -*- Scheme -*-
;;; This file is part of the Scheme Untergrund Networking package.
;;; Copyright (c) 1995 by Olin Shivers. <shivers@lcs.mit.edu>
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;;; (read-crlf-line [fd/port retain-crlf?]) -> string or EOF object
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Read a line terminated by either line-feed or EOF. If RETAIN-CRLF? is #f
;;; (the default), a terminating cr/lf or lf sequence is trimmed from the
;;; returned string.
;;;
;;; This is simple and inefficient. It would be save one copy if we didn't
;;; use READ-LINE, but replicated its implementation instead.
(define (read-crlf-line . args)
(let-optionals args ((fd/port (current-input-port))
(retain-crlf? #f))
(let ((ln (read-line fd/port retain-crlf?)))
(if (or retain-crlf? (eof-object? ln))
ln
(let ((slen (string-length ln))) ; Trim a trailing cr, if any.
(if (or (zero? slen)
(not (char=? (string-ref ln (- slen 1)) cr)))
ln
(substring ln 0 (- slen 1))))))))
(define cr (ascii->char 13))
(define (write-crlf port)
(write-string "\r\n" port)
(force-output port))
(define (read-crlf-line-timeout . args)
(let-optionals args ((fd/port (current-input-port))
(retain-crlf? #f)
(timeout 8000)
(max-interval 500))
(let loop ((waited 0) (interval 100))
(cond ((> waited timeout)
'timeout)
((char-ready? fd/port)
(read-crlf-line fd/port retain-crlf?))
(else (sleep interval)
(loop (+ waited interval) (min (* interval 2)
max-interval)))))))

Some files were not shown because too many files have changed in this diff Show More