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.
This commit is contained in:
interp 2003-04-13 21:31:41 +00:00
parent e9d126847d
commit cdbed4fa49
4 changed files with 62 additions and 38 deletions

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; return address ;; return address
;; generates an unique return-addres ;; generates an unique return-address
;; may be used like ;; may be used like
;; (let ((address (make-address))) ;; (let ((address (make-address)))
;; (send-html/suspend ;; (send-html/suspend
@ -10,9 +10,27 @@
;; (url (address new-url) "Click here to get more")...) ;; (url (address new-url) "Click here to get more")...)
(define-record-type address :address (define-record-type address :address
(really-make-address name annotated?) (make-address-constructor name annotated? annotations)
(name real-address-name) (name address-name)
(annotated? real-address-annotated?)) (annotated? address-annotated?)
(annotations address-annotations set-address-annotations!))
(define (really-make-address name annotated?)
(if annotated?
(make-address-constructor name annotated? #f)
(make-address-constructor 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) (define (make-address)
(let ((address (really-make-address (let ((address (really-make-address
@ -20,12 +38,12 @@
(lambda (message) (lambda (message)
(cond (cond
((string? message) ((string? message)
(string-append message "?" (real-address-name address) "=")) (string-append message "?" (address-name address) "="))
((eq? message 'address) ((eq? message 'address)
address) address)
(else (else
(error "address: unknown message/bad argument" (error "address: unknown message/bad argument"
message (real-address-name address))))))) message (address-name address)))))))
(define (make-annotated-address) (define (make-annotated-address)
(let ((address (really-make-address (let ((address (really-make-address
@ -35,14 +53,13 @@
(cond (cond
((and (string? message) ((and (string? message)
(<= (length annotation) 1)) (<= (length annotation) 1))
(let ((escaped-annotation (let ((index (if (null? annotation)
(if (null? annotation) (address-add-annotation! address "")
"" (address-add-annotation! address (car annotation)))))
(escape-uri (car annotation))))) (string-append message "?" (address-name address)
(string-append message "?" (real-address-name address) "=" index)))
"=" escaped-annotation)))
((eq? message 'address) ((eq? message 'address)
address) address)
(else (else
(error "annotated-address: unknown message/bad argument(s)" (error "annotated-address: unknown message/bad argument(s)"
message (real-address-name address))))))) message (address-name address)))))))

View File

@ -314,8 +314,10 @@
(define-interface surflets/addresses-interface (define-interface surflets/addresses-interface
(export make-address (export make-address
make-annotated-address make-annotated-address
real-address-name address-name
real-address-annotated?)) address-annotated?
; address-add-annotation!
address-annotation))
;; Returned-via (dispatcher for input-fields and intelligent ;; Returned-via (dispatcher for input-fields and intelligent
;; addresses) ;; addresses)

View File

@ -5,10 +5,10 @@
;; We assume we have a return-address-object instead. ;; We assume we have a return-address-object instead.
(let ((address (return-object 'address))) (let ((address (return-object 'address)))
(cond (cond
((assoc (real-address-name address) bindings) => ((assoc (address-name address) bindings) =>
(lambda (pair) (lambda (pair)
(if (real-address-annotated? address) (if (address-annotated? address)
(unescape-uri (cdr pair)) (address-annotation address (cdr pair))
#t))) #t)))
(else #f))))) (else #f)))))

View File

@ -226,9 +226,13 @@
(url ,(make-callback show-sessions) "session table overview.")))) (url ,(make-callback show-sessions) "session table overview."))))
(define (no-more-than-one-session title header1 sessions req) (define (no-more-than-one-session title header1 sessions req)
(send-html (let* ((address (make-annotated-address))
`(html (title ,title) (req (send-html/suspend
(body (h1 "SUrflet Administration") (lambda (k-url)
`(html
(title ,title)
(body
(h1 "SUrflet Administration")
(p "Currently, you may only view the continuations of " (p "Currently, you may only view the continuations of "
"one session at a time. This will be changed in " "one session at a time. This will be changed in "
"future revisions. Sorry for any inconvenience.") "future revisions. Sorry for any inconvenience.")
@ -239,12 +243,13 @@
" or select one session from your chosen sessions:" (br) " or select one session from your chosen sessions:" (br)
(ul (ul
,@(map (lambda (session) ,@(map (lambda (session)
`(li (url ,(make-callback `(li (url ,(address k-url session)
(lambda (req)
(show-continuations (list session) req)))
,(session-surflet-name (cdr session)) ,(session-surflet-name (cdr session))
" (" ,(car session) ")"))) " (" ,(car session) ")")))
sessions))))))) sessions))))))))
(bindings (get-bindings req))
(chosen-session (returned-via address bindings)))
(show-continuations (list chosen-session) req)))
(define (continuation-id<? entry1 entry2) (define (continuation-id<? entry1 entry2)
(< (car entry1) (car entry2))) (< (car entry1) (car entry2)))