1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
;; Copyright 2007-2011, Matthew Welland.
;;
;; This program is made available under the GNU GPL version 2.0 or
;; greater. See the accompanying file COPYING for details.
;;
;; This program is distributed WITHOUT ANY WARRANTY; without even the
;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE.
(declare (unit session))
(require-library dbi)
(require-extension regex)
(declare (uses cookie))
;; sessions table
;; id session_id session_key
;; create table sessions (id serial not null,session-key text);
|
|
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
;; Copyright 2007-2011, Matthew Welland.
;;
;; This program is made available under the GNU GPL version 2.0 or
;; greater. See the accompanying file COPYING for details.
;;
;; This program is distributed WITHOUT ANY WARRANTY; without even the
;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE.
(declare (unit session))
;; (require-library dbi)
(use dbi)
(import (prefix dbi dbi:))
(require-extension regex)
(declare (uses cookie))
;; sessions table
;; id session_id session_key
;; create table sessions (id serial not null,session-key text);
|
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
|
(define (session:get-param self key)
;; (session:log s:session "params=" (slot-ref s:session 'params))
(let ((params (sdat-get-params self)))
(session:get-param-from params key)))
;; This one will get the first value found regardless of form
(define (session:get-input self key)
(let* ((formdat (sdat-get-formdat self)))
(if (not formdat) #f
(if (or (string? key)(number? key)(symbol? key))
(if (and (vector? formdat)(eq? (vector-length formdat) 1)(hash-table? (vector-ref formdat 0)))
(formdat:get formdat key)
(begin
(session:log self "ERROR: formdat: " formdat " is not of class <formdat>")
#f))
(session:log self "ERROR: bad key " key)))))
;; This one will get the first value found regardless of form
(define (session:get-input-keys self)
(let* ((formdat (sdat-get-formdat self)))
(if (not formdat) #f
(if (and (vector? formdat)(eq? (vector-length formdat) 1)(hash-table? (vector-ref formdat 0)))
(formdat:keys formdat)
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
|
|
|
|
|
|
|
>
|
>
>
>
>
>
>
|
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
(define (session:get-param self key)
;; (session:log s:session "params=" (slot-ref s:session 'params))
(let ((params (sdat-get-params self)))
(session:get-param-from params key)))
;; This one will get the first value found regardless of form
;; param: (dtype [tag1 tag2 ...])
;; dtype:
;; 'raw : do no conversion
;; 'number : convert to number, return #f if fails
;; 'escaped : use html-escape to protect the input
;;
(define (session:get-input self key params)
(let* ((dtype (if (null? params)
'escaped
(car params)))
(tags (if (null? params)
'()
(cdr params)))
(formdat (sdat-get-formdat self))
(res (if (not formdat) #f
(if (or (string? key)(number? key)(symbol? key))
(if (and (vector? formdat)(eq? (vector-length formdat) 1)(hash-table? (vector-ref formdat 0)))
(formdat:get formdat key)
(begin
(session:log self "ERROR: formdat: " formdat " is not of class <formdat>")
#f))
(begin
(session:log self "ERROR: bad key " key)
#f)))))
(case dtype
((raw) res)
((number) (if (string? res)(string->number res) #f))
((escaped) (s:html-filter res tags))
(else (s:html-filter res '())))))
;; This one will get the first value found regardless of form
(define (session:get-input-keys self)
(let* ((formdat (sdat-get-formdat self)))
(if (not formdat) #f
(if (and (vector? formdat)(eq? (vector-length formdat) 1)(hash-table? (vector-ref formdat 0)))
(formdat:keys formdat)
|