+ 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 11:29:32 -05:00
|
|
|
;; 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.
|
2004-09-24 09:49:05 -04:00
|
|
|
(define *POST-bindings-cache* '())
|
+ 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 11:29:32 -05:00
|
|
|
(define *cache-lock* (make-lock))
|
|
|
|
|
|
|
|
(define (get-bindings surflet-request)
|
2003-06-03 03:36:48 -04:00
|
|
|
(let ((request-method (surflet-request-method surflet-request))
|
2004-07-21 14:56:03 -04:00
|
|
|
(content-type (assoc 'content-type
|
2003-06-03 03:36:48 -04:00
|
|
|
(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"))
|
+ 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 11:29:32 -05:00
|
|
|
(cond
|
|
|
|
((string=? request-method "GET")
|
|
|
|
(form-query-list (http-url-search
|
|
|
|
(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))
|
2003-07-06 04:58:39 -04:00
|
|
|
(form-data (read-string content-length input-port))
|
2003-07-06 05:00:36 -04:00
|
|
|
(form-bindings (form-query-list form-data)))
|
2003-07-06 04:58:39 -04:00
|
|
|
(obtain-lock *cache-lock*)
|
|
|
|
(set! *POST-bindings-cache*
|
|
|
|
(cons (cons (make-weak-pointer surflet-request)
|
|
|
|
form-bindings)
|
|
|
|
*POST-bindings-cache*))
|
+ 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 11:29:32 -05:00
|
|
|
(release-lock *cache-lock*)
|
2003-07-06 04:58:39 -04:00
|
|
|
form-bindings)))
|
+ 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 11:29:32 -05:00
|
|
|
(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
|
2004-09-24 09:49:05 -04:00
|
|
|
(let loop ((predecessor #f)
|
|
|
|
(cache *POST-bindings-cache*))
|
|
|
|
(if (null? cache)
|
2004-09-24 07:28:49 -04:00
|
|
|
#f ; no such request cached
|
2004-09-24 09:49:05 -04:00
|
|
|
(let* ((head (car cache))
|
2004-09-24 07:28:49 -04:00
|
|
|
(s-req (weak-pointer-ref (car head))))
|
|
|
|
(if s-req
|
|
|
|
(if (eq? s-req surflet-request)
|
|
|
|
(cdr head) ; request is cached
|
2004-09-24 09:49:05 -04:00
|
|
|
(loop (if predecessor
|
|
|
|
(cdr predecessor)
|
|
|
|
cache)
|
|
|
|
(cdr cache))) ; request isn't cached
|
2004-09-24 07:28:49 -04:00
|
|
|
(begin ;; request object is gone ==> remove
|
2004-09-24 09:49:05 -04:00
|
|
|
;; it from list
|
|
|
|
(if predecessor
|
|
|
|
(set-cdr! predecessor (cdr cache))
|
|
|
|
(set! *POST-bindings-cache* (cdr cache)))
|
|
|
|
(loop predecessor
|
|
|
|
(cdr predecessor)))))))))
|
+ 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 11:29:32 -05:00
|
|
|
(release-lock *cache-lock*)
|
|
|
|
result))
|
|
|
|
|
2004-09-24 07:28:49 -04:00
|
|
|
|
+ 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 11:29:32 -05:00
|
|
|
;; 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))))
|
|
|
|
|
|
|
|
|