Comment: | first steps in refactoring to a module |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | stml2 |
Files: | files | file ages | folders |
SHA1: |
8b66fa08e7a915e4b460703c3b72381d |
User & Date: | matt on 2018-07-29 22:04:26 |
Other Links: | branch diff | manifest | tags |
2018-09-08
| ||
19:46 | Moved everything into a single module for a more easy transition check-in: de72dc8d9f user: matt tags: stml2 | |
2018-07-29
| ||
22:04 | first steps in refactoring to a module check-in: 8b66fa08e7 user: matt tags: stml2 | |
2017-11-10
| ||
21:26 | Ensure force-ssl is initiallized to #f check-in: cb3c5f2532 user: matt tags: trunk | |
Added .fossil-settings/ignore-glob version [56afbbd51c].
|
Modified Makefile from [865dfc8355] to [0ba4186b5a].
︙ | |||
9 10 11 12 13 14 15 | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | - + - + | # # Following needed on bluehost (maybe on all 64bit?) # # CSC_OPTIONS='-C "-fPIC"' make # include install.cfg |
︙ | |||
70 71 72 73 74 75 76 | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | - + | # Cookie is a special case for now. Make a loadable so for test # Complile it in by include (see dependencies above). cookie.so : cookie.scm csc i$(CSCOPTS) -s cookie.scm clean : |
Modified cookie.scm from [49ca0d00a6] to [d78a525a3a].
︙ | |||
38 39 40 41 42 43 44 | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | - + + + + + + + | ;; <ftp://ftp.isi.edu/in-notes/rfc2965.txt> ;; See also ;; RFC 2964 Use of HTTP state management ;; <ftp://ftp.isi.edu/in-notes/rfc2964.txt> ;; The parser also supports the old Netscape spec ;; <http://www.netscape.com/newsref/std/cookie_spec.html> |
︙ | |||
251 252 253 254 255 256 257 | 257 258 259 260 261 262 263 264 | + | ;;;; Added support functions from my utils, split this out (define (string-search-after r s #!optional (start 0)) (and-let* ((match-indices (string-search-positions r s start)) (right-match (second (first match-indices)))) (substring s right-match))) ) |
Modified formdat.scm from [e7bfc732dd] to [427854d910].
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - + + + + + + + + | ;; 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. |
︙ | |||
343 344 345 346 347 348 349 | 350 351 352 353 354 355 356 357 358 | + + | ;; (formdat:printall formdat (lambda (x)(write-line x debugp))) #| (define inp (open-input-file "/tmp/stmlrun/delme-33.log.keep-for-ref")) (define dat (read-string #f inp)) (close-input-port inp) |# ) |
Modified html-filter.scm from [7dc1b6a3b0] to [1c2965ad32].
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - + + + + + + + + | ;; 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. |
︙ | |||
193 194 195 196 197 198 199 | 200 201 202 203 204 205 206 207 | + | "" (s:decode-str (cadr xy))))) (s:divy-up-cgi-str instr))) ;; for testing -- deletme ;; (define blah "post_title=%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2Bhello-------------+++++++++++%26%26%26%26%26%26%26%26%26%40%40%40%40%40%40%40%40%40&post_body=%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2Bhello-------------+++++++++++%26%26%26%26%26%26%26%26%26%40%40%40%40%40%40%40%40%40%0D%0A%0D%0A%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2Bhello-------------+++++++++++%26%26%26%26%26%26%26%26%26%40%40%40%40%40%40%40%40%40%0D%0A%0D%0A%0D%0A%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2Bhello-------------+++++++++++%26%26%26%26%26%26%26%26%26%40%40%40%40%40%40%40%40%40&new_post=Submit") ;; (define blah2 "post_title=5%25&post_body=and+10%25&new_post=Submit") ) |
Modified keystore.scm from [1e4a5aef9c] to [ab856615aa].
︙ | |||
8 9 10 11 12 13 14 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | - + + + + + + + + + | ;; PURPOSE. ;;====================================================================== ;; The meta data key store, just a general dumping ground for values ;; only used occasionally ;;====================================================================== |
Modified misc-stml.scm from [116e590e88] to [7dbf69d08d].
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | - + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + + + + - - + - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - | ;; 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. ;;====================================================================== ;; dumbobj helpers ;;====================================================================== |
︙ | |||
101 102 103 104 105 106 107 | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | - - - - - - - - - | (loop (car tail) (cdr tail) newresult (car argtail) (cdr argtail))))))))) |
︙ | |||
138 139 140 141 142 143 144 | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | (let loop ((res "") (n 1)) (let ((char-num (random num-chars))) (if (> n len) res (loop (string-append res (substring seed-string char-num (+ char-num 1))) (+ n 1))))))) |
︙ | |||
306 307 308 309 310 311 312 | 233 234 235 236 237 238 239 240 | + | (if (string-match r1 head) (if (null? tail) result (loop (car tail)(cdr tail) result)) (let ((newlst (cons head result))) (if (null? tail) newlst (loop (car tail)(cdr tail) newlst)))))))) ) |
Modified session.scm from [2b15eaba58] to [464fa3c6e4].
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - - + + + + + + + + - + | ;; 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. |
︙ | |||
761 762 763 764 765 766 767 768 769 770 771 772 773 774 | 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 | + + + + + + + + + + + | "\r") "\\r") res)) ;; should return #f if not a string and can't escape it? (else (if (string? res) (s:html-filter->string res '()) res))))) #;(define (session:get-param-from params key) (let ((r1 (regexp (conc "^" (s:any->string key) "=(.*)$")))) (if (null? params) #f (let loop ((head (car params)) (tail (cdr params))) (let ((match (string-match r1 head))) (if match (list-ref match 1) (if (null? tail) #f (loop (car tail)(cdr tail))))))))) ;; params are stored as list of key=val ;; (define (session:get-param self key type-params) ;; (session:log s:session "params=" (slot-ref s:session 'params)) (let* ((params (sdat-get-params self)) (res (session:get-param-from params key))) (session:apply-type-preference res type-params))) |
︙ | |||
866 867 868 869 870 871 872 | 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | + + + + + + + | (print "Content-Length: " (if (blob? dat) (blob-size dat) 0)) (print "Keep-Alive: timeout=15, max=100") (print "Connection: Keep-Alive") (print "") (write-string (blob->string dat) #f (current-output-port)))) ;; was in setup ;; (define (s:log . msg) (apply session:log s:session msg)) ) |
Modified setup.scm from [1b8611c4ba] to [e8c4330f90].
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | + + + + + - - + + - - - | ;; 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. (module setup * (import chicken scheme data-structures extras srfi-13 ports posix) (uses session misc-stml) |
︙ | |||
210 211 212 213 214 215 216 | 212 213 214 215 216 217 218 219 | + | (define (s:never-called-page? page) (session:never-called-page? s:session page)) ;; find out if we are in debugmode (define (s:debug-mode?) (sdat-get-debugmode s:session)) ) |
Modified sqltbl.scm from [29093c83c7] to [80d836633e].
︙ | |||
13 14 15 16 17 18 19 | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | + + + + + - + | ;; query-params ;; list of params for the query ;; conn ;; connection to db ;; num-rows ;; whatever ;; curr-row-ptr ;; number of the current row ;; curr-row ;; the current row vector (?? do we really want this ??) ;; )) (module sqltbl * (import chicken scheme data-structures extras srfi-13 ports ) |
︙ | |||
107 108 109 110 111 112 113 | 112 113 114 115 116 117 118 119 | + | ;; runs proc on each row and returns the resulting list (define (sqltbl:map self proc) (map (lambda (row) (proc (sqltbl:vector->hash self row))) (sqltbl:tbl-get-rows self))) ) |
Name change from stml.meta to stml2.meta.
︙ |
Renamed and modified stml.scm [5df99c79b1] to stml2.scm [4a50517b51].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | - - - + + + + + + + + + + + | ;; 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. ;; stml is a list of html strings |
︙ | |||
245 246 247 248 249 250 251 | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | + + - + - + - + + + | ((list? x) (s:print (+ indent 1) x)) (else ;; (print "ERROR: Bad input 01") ;; why do anything with junk? ))) inlst)) ;; Moved to misc-stml ;; |
Renamed and modified stml.setup [b663e1c0bf] to stml2.setup [a0a6e63869].
︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | + + + + + + + + + + + - + | ;;;; margs.setup ;; compile the code into a dynamically loadable shared object ;; (will generate margs.so) ;; (compile -s margs.scm) ;; Install as extension library (standard-extension 'cookie "0.5") (standard-extension 'misc-stml "0.5") ;; moved to stmlcommon.scm (standard-extension 'html-filter "0.5") (standard-extension 'formdat "0.5") (standard-extension 'session "0.5") (standard-extension 'setup "0.5") (standard-extension 'sqltbl "0.5") (standard-extension 'keystore "0.5") (standard-extension 'stmlcommon "0.5") (standard-extension 'stml2 "0.5") |
Modified stmlcommon.scm from [c37d1e8589] to [40942140f1].
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | + + + + + + + + - - - - - - - - - + + + + + + + + + | ;; 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. ;; (require-extension syntax-case) ;; (declare (run-time-macros)) (module stmlcommon * (import chicken scheme data-structures extras srfi-13 ports ) (use cookie misc-stml formdat session sqltbl keystore) (include "requirements.scm") |
︙ | |||
89 90 91 92 93 94 95 | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | ;; (get-environment-variables)) ;; (print "</table>") (print "</body></html>"))) (if proc (proc s:session) (stml:cgi-session s:session)) ;; (raise-error) ;; (exit) )) ;; given a list of symbols give the count of the matching symbol ;; l => '(a b c) (dumobj:indx a 'b) => 1 (define (s:get-fieldnum lst field-name) (let loop ((head (car lst)) (tail (cdr lst)) (fnum 0)) (if (eq? head field-name) fnum (if (null? tail) #f (loop (car tail)(cdr tail)(+ fnum 1)))))) (define (s:fields->string lst) (string-join (map symbol->string lst) ",")) (define (s:vector-get-field vec field field-list) (vector-ref vec (s:get-fieldnum field-list field))) ;;====================================================================== ;; ;;====================================================================== ;; moved to misc-stml ;; #;(define (err:log . msg) (with-output-to-port (current-error-port) ;; (slot-ref self 'logpt) (lambda () (apply print msg)))) (define (s:tidy-url url) (if url (let ((r1 (regexp "^http:\\/\\/")) (r2 (regexp "^[ \\t]*$"))) ;; blank (if (string-match r1 url) url (if (string-match r2 url) #f ;; convert a blank to #f (conc "http://" url)))) url)) (define (s:lazy->num num) (if (number? num) num (if (string->number num) (string->number num) (if num 1 0)))) ;; wierd eh! yep, #f=>0 #t=>1 ;;====================================================================== ;; D B ;;====================================================================== ;; convert values to appropriate strings ;; #;(define (s:sqlparam-val->string val) (cond ((list? val)(string-join (map symbol->string val) ",")) ;; (a b c) => a,b,c ((string? val)(conc "'" (dbi:escape-string val) "'")) ((number? val)(number->string val)) ((symbol? val)(dbi:escape-string (symbol->string val))) ((boolean? val) (if val "TRUE" "FALSE")) ;; should this be "TRUE" or 1? ;; should this be "FALSE" or 0 or NULL? (else (err:log "sqlparam: unknown type for value: " val) ""))) ;; (sqlparam "INSERT INTO foo(name,age) VALUES(?,?);" "bob" 20) ;; NB// 1. values only!! ;; 2. terminating semicolon required (used as part of logic) ;; ;; a=? 1 (number) => a=1 ;; a=? 1 (string) => a='1' ;; a=? #f => a=FALSE ;; a=? a (symbol) => a=a ;; #;(define (s:sqlparam query . args) (let* ((query-parts (string-split query "?")) (num-parts (length query-parts)) (num-args (length args))) (if (not (= (+ num-args 1) num-parts)) (err:log "ERROR, sqlparam: wrong number of arguments or missing semicolon, " num-args " for query " query) (if (= num-args 0) query (let loop ((section (car query-parts)) (tail (cdr query-parts)) (result "") (arg (car args)) (argtail (cdr args))) (let* ((valstr (s:sqlparam-val->string arg)) (newresult (conc result section valstr))) (if (null? argtail) ;; we are done (conc newresult (car tail)) (loop (car tail) (cdr tail) newresult (car argtail) (cdr argtail))))))))) ;;====================================================================== ;; M I S C S T R I N G S T U F F ;;====================================================================== (define (s:string-downcase str) (if (string? str) (string-translate str "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz") str)) ;; (define session:valid-chars "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") #;(define session:valid-chars "abcdefghijklmnopqrstuvwxyz0123456789") ;; cookies are case insensitive. #;(define session:num-valid-chars (string-length session:valid-chars)) #;(define (session:get-nth-char nth) (substring session:valid-chars nth (+ nth 1))) #;(define (session:get-rand-char) (session:get-nth-char (random session:num-valid-chars))) #;(define (session:make-rand-string len) (let loop ((res "") (n 1)) (if (> n len) res (loop (string-append res (session:get-rand-char)) (+ n 1))))) ;; maybe replace above make-rand-string with this someday? ;; #;(define (session:generic-make-rand-string len seed-string) (let ((num-chars (string-length seed-string))) (let loop ((res "") (n 1)) (let ((char-num (random num-chars))) (if (> n len) res (loop (string-append res (substring seed-string char-num (+ char-num 1))) (+ n 1))))))) ;; Rely on crypt egg's default settings being secure enough, accept ;; backwards-compatible OpenSSL crypt passwords too. ;; (define (s:crypt-passwd pw s) (c:crypt pw (or s (c:crypt-gensalt)))) (define (s:password-match? password crypted) (let* ((salt (substring crypted 0 2)) (pcrypted (s:crypt-passwd password salt))) ;; (s:log "INFO: pcrypted=" pcrypted " crypted=" crypted) (and (string? password) (string? pcrypted) (string=? pcrypted crypted)))) ;; (read-line (open-input-pipe "echo foo | mkpasswd -S ab -s")) (define (s:error-page . err) (s:cgi-out (cons "Content-type: text/html; charset=iso-8859-1\n\n" (s:html (s:head (s:title err) (s:body (s:h1 "ERROR") (s:p err))))))) ;; BUG: The regex implements a rule, but what rule? AH! usaztempe, get rid of this? No, this also looks for &key=value ... (define (s:validate-uri) (let ((uri (get-environment-variable "REQUEST_URI")) (qrs (get-environment-variable "QUERY_STRING"))) (if (not uri) (set! uri qrs)) (if uri (string-match (regexp "^(/[a-z\\-\\._:0-9]*)*(|\\?([A-Za-z0-9_\\-\\+]+=[A-Za-z0-9_\\-\\.\\+]*&{0,1})*)$") uri) (begin (s:log "REQUEST URI NOT AVAILABLE!") (let ((p (open-input-pipe "env"))) (let loop ((l (read-line p)) (res '())) (if (eof-object? l) (s:log res) (loop (read-line p)(cons (list l "<BR>") res))))) #t)))) (define (s:validate-inputs) (if (not (s:validate-uri)) (begin (s:error-page "Bad URI" (let ((ref (get-environment-variable "HTTP_REFERER"))) (if ref (list "referred from" ref) ""))) (exit)))) ;; moved to misc-stml ;; ;; anything except a list is converted to a string!!! #;(define (s:any->string val) (cond ((string? val) val) ((number? val) (number->string val)) ((symbol? val) (symbol->string val)) ((eq? val #f) "") ((eq? val #t) "TRUE") ((list? val) val) (else (let ((ostr (open-output-string))) (with-output-to-port ostr (lambda () (display val))) (get-output-string ostr))))) #;(define (s:any->number val) (cond ((number? val) val) ((string? val) (string->number val)) ((symbol? val) (string->number (symbol->string val))) (else #f))) ;; NB// this is *illegal* pgint (define (s:illegal-pgint val) (cond ((> val 2147483647) 1) ((< val -2147483648) -1) (else #f))) (define (s:any->pgint val) (let ((n (s:any->number val))) (if n (if (s:illegal-pgint n) #f n) n))) ;; string is a string and non-zero length (define (misc:non-zero-string str) (if (and (string? str) (> (string-length str) 0)) str #f)) ) |