Index: formdat.scm ================================================================== --- formdat.scm +++ formdat.scm @@ -7,10 +7,11 @@ ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. (declare (unit formdat)) (use regex) +(require-extension srfi-69) (define formdat:*debug* #f) ;; Old data format was something like this. BUT! ;; Forms do not have names so the hierarcy is @@ -24,11 +25,11 @@ ;; New data format is only the portion from above ;; (define-class () ;; (form-data ;; )) -(define (make-formdat:formdat)(make-vector (hash-table))) +(define (make-formdat:formdat)(vector (make-hash-table))) (define-inline (formdat:formdat-get-data vec) (vector-ref vec 0)) (define-inline (formdat:formdat-set-data! vec val)(vector-set! vec 0 val)) (define (formdat:initialize self) (formdat:formdat-set-data! self (make-hash-table))) Index: html-filter.scm ================================================================== --- html-filter.scm +++ html-filter.scm @@ -6,10 +6,11 @@ ;; This program is distributed WITHOUT ANY WARRANTY; without even the ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. (declare (unit html-filter)) +(require-extension regex) ;; (define (s:split-string strng delim) (if (eq? (string-length strng) 0) (list strng) (let loop ((head (make-string 1 (car (string->list strng)))) Index: modules/twiki/twiki-mod.scm ================================================================== --- modules/twiki/twiki-mod.scm +++ modules/twiki/twiki-mod.scm @@ -7,10 +7,11 @@ ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. ;; twiki module (require-extension sqlite3 regex posix md5 base64) +(import (prefix base64 base64:)) ;; TODO ;; ;; * Inline tiddlers [inline[TiddlerName]] ;; * Pics [pic X Y[picname.jpg]] @@ -32,11 +33,11 @@ ;; (define (twiki:open-db key . create-not-ok) ;; (s:log "Got to twiki:open-db with key: " key) (let* ((create-ok (if (null? create-not-ok) #t (car create-not-ok))) (fdat (twiki:key->fname key)) - (basepath (slot-ref s:session 'twikidir)) + (basepath (sdat-get-twikidir s:session)) (fpath (car fdat)) (fname (cadr fdat)) (fullname (conc basepath "/" fpath "/" fname)) (fexists (file-exists? fullname)) (db (if fexists (dbi:open 'sqlite3 (list (cons 'dbname fullname))) #f))) @@ -47,10 +48,13 @@ (if (not fexists) (begin ;; (print "fullname: " fullname) (twiki:register-wiki key fullname) (system (conc "mkdir -p " fpath)) ;; create the path + (if (file-exists? fpath) + (s:log "OK: dir " fpath " has been made") + (s:log "ERROR: Failed to make the path for the twiki")) (set! db (dbi:open 'sqlite3 (list (cons 'dbname fullname)))) (for-each (lambda (sqry) ;; (print sqry) (dbi:exec db sqry)) @@ -75,11 +79,11 @@ "CREATE TABLE meta (id INTEGER PRIMARY KEY,key TEXT,val TEXT);" ;; need to create an entry for *this* twiki (conc "INSERT INTO wikis (id,name,created_on) VALUES (1,'main'," (current-seconds) ");"))) ;; (conc "INSERT INTO tiddlers (wiki_id,name,created_on) VALUES(1,'MainMenu'," (current-seconds) ");"))))) (twiki:save-tiddler db "MainMenu" "[[FirstTiddler]]" "" 1 1))) - (sqlite3:set-busy-timeout!(dbi:db-conn db) 1000000) + ;; (sqlite3:set-busy-timeout!(dbi:db-conn db) 1000000) db)))) ;;====================================================================== ;; twikis (db naming, sqlite vs postgresql, keys etc. ;;====================================================================== @@ -99,11 +103,11 @@ (p3 (substring keypath (* delta 2) (* delta 3)))) ;; 16 24)) (list (string-intersperse (list "twikis" p1 p2 p3) "/") keypath))) ;; look up the wid based on the keys, this is used for sub wikis only. I.e. a wiki instantiated inside another wiki ;; giving a separate namespace to all the tiddlers -(define (twiki:name->wid db name) ;; (slot-ref s:session 'conn) +(define (twiki:name->wid db name) (let ((wid (dbi:get-one db "SELECT id FROM wikis WHERE name=?;" name))) (if wid wid (begin (dbi:exec db "INSERT INTO wikis (name,created_on) VALUES(?,?);" name (current-seconds)) (twiki:name->wid db name))))) @@ -173,11 +177,11 @@ ;;====================================================================== ;; these can be overridden by end user (just create a new routine by the same name) (define (twiki:open-registry) - (let* ((basepath (slot-ref s:session 'sroot)) + (let* ((basepath (sdat-get-sroot s:session)) (regfile (conc basepath "/twikis/registry.db")) (regexists (file-exists? regfile)) (db (dbi:open 'sqlite3 (list (cons 'dbname regfile))))) (if regexists db @@ -293,11 +297,11 @@ (s:textarea-preserve 'type "textarea" 'name "twiki_body" 'rows "10" 'cols "65") (s:p "Tags" (s:input-preserve 'type "text" 'name "twiki_tags" 'size "55" 'maxlength "150"))))) ;; save a tiddler to the db for the twiki twik, getting data from the INPUT (define (twiki:save-curr-tiddler tdb wid) - (formdat:printall (slot-ref s:session 'formdat) s:log) + (formdat:printall (sdat-get-formdat s:session) s:log) (let* ((heading (s:get-input 'twiki_title)) (body (s:get-input 'twiki_body)) (tags (s:get-input 'twiki_tags)) (uid (twiki:get-id))) ;; (s:log "twiki:save-curr-tiddler heading: " heading " body: " body " tags: " tags) @@ -349,11 +353,11 @@ #t) ;; success #f)) ;; non-success ;; text=0, jpg=1, png=2 (define (twiki:save-dat db dat type) - (let* ((md5sum (md5:digest dat)) + (let* ((md5sum (md5-digest dat)) (datid (twiki:dat-exists? db md5sum type)) (datblob (if (string? dat) (string->blob dat) dat))) (if datid @@ -479,22 +483,22 @@ ;; this one sets up the Content type, puts the data into page-dat and is done (define (twiki:return-image-dat tdb wid pic-id) (let ((dat (twiki:get-pic-dat tdb wid pic-id))) (s:log "twiki:return-image-dat dat is: " dat " of size: " (if (blob? dat)(blob-size dat) "[not a blob]")) - (slot-set! s:session 'page-type 'image) - (slot-set! s:session 'content-type "image/jpeg") - (slot-set! s:session 'alt-page-dat dat))) + (sdat-set-page-type! s:session 'image) + (sdat-set-content-type! s:session "image/jpeg") + (sdat-set-alt-page-dat! s:session dat))) ;; (session:alt-out s:session))) ;; this one sets up the Content type, puts the data into page-dat and is done (define (twiki:return-thumb-dat tdb wid pic-id) (let ((dat (twiki:get-thumb-dat tdb wid pic-id))) (s:log "twiki:return-image-dat dat is: " dat " of size: " (if (blob? dat)(blob-size dat) "[not a blob]")) - (slot-set! s:session 'page-type 'image) - (slot-set! s:session 'content-type "image/jpeg") - (slot-set! s:session 'alt-page-dat dat))) + (sdat-set-page-type! s:session 'image) + (sdat-set-content-type! s:session "image/jpeg") + (sdat-set-alt-page-dat! s:session dat))) ;; (session:alt-out s:session))) (define (twiki:make-thumbnail tdb pic-id wid) (let ((indat (twiki:get-pic-dat tdb wid pic-id))) ;; (outdat (open-output-string))) @@ -697,11 +701,11 @@ ;; should do a single more efficient query but this is good enough (define (twiki:get-tiddlers db wid tnames) (apply twiki:get-tiddlers-by-name db wid tnames)) ;; (let* ((tdlrs '()) -;; ;; (conn (slot-ref s:session 'conn)) +;; ;; (conn (sdat-get-conn s:session)) ;; (namelst (conc "('" (string-intersperse (map conc tnames) "','") "')")) ;; (qry (conc twiki:tiddler-selector " WHERE t.wiki_id=? AND t.id IN " namelst ";"))) ;; ;; (print qry) ;; (dbi:for-each-row ;; (lambda (row) @@ -715,12 +719,10 @@ ;; select where created_on < somedate order by created_on desc limit 1 (let* ((tdlrs '()) (tlststr (string-intersperse (map number->string tlst) ",")) (already-got (make-hash-table)) (qry (conc twiki:tiddler-selector " WHERE t.wiki_id=? AND t.id IN (" tlststr ") ORDER BY created_on DESC;"))) - ;; (conn (slot-ref s:session 'conn)) - ;; (print "qry: " qry) (dbi:for-each-row (lambda (row) (let ((tname (twiki:tiddler-get-name row))) (if (not (hash-table-ref/default already-got tname #f)) (begin @@ -775,14 +777,14 @@ (define twiki:tr s:tr) (define twiki:table s:table) (define twiki:div s:div) (define (twiki:web64enc str) - (string-substitute "=" "_" (base64:encode str) #t)) + (string-substitute "=" "_" (base64:base64-encode str) #t)) (define (twiki:web64dec str) - (base64:decode (string-substitute "_" "=" str #t))) + (base64:base64-decode (string-substitute "_" "=" str #t))) (define (twiki:make-tlink text tiddlername) (s:a text 'href (s:link-to (twiki:get-link-back-to-current) 'view_tiddler (twiki:web64enc tiddlername)))) (define (twiki:pic pic-name size wiki) Index: session.scm ================================================================== --- session.scm +++ session.scm @@ -7,11 +7,11 @@ ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. (declare (unit session)) (require-library dbi) -(use regex) +(require-extension regex) (declare (uses cookie)) ;; sessions table ;; id session_id session_key ;; create table sessions (id serial not null,session-key text); @@ -163,16 +163,18 @@ (sroot (s:find-param 'sroot configdat)) (logfile (s:find-param 'logfile configdat)) (dbtype (s:find-param 'dbtype configdat)) (dbinit (s:find-param 'dbinit configdat)) (domain (s:find-param 'domain configdat)) + (twikidir (s:find-param 'twikidir configdat)) (page-dir (s:find-param 'page-dir-style configdat))) - (if sroot (sdat-set-sroot! self sroot)) - (if logfile (sdat-set-logfile! self logfile)) - (if dbtype (sdat-set-dbtype! self dbtype)) - (if dbinit (sdat-set-dbinit! self dbinit)) - (if domain (sdat-set-domain! self domain)) + (if sroot (sdat-set-sroot! self sroot)) + (if logfile (sdat-set-logfile! self logfile)) + (if dbtype (sdat-set-dbtype! self dbtype)) + (if dbinit (sdat-set-dbinit! self dbinit)) + (if domain (sdat-set-domain! self domain)) + (if twikidir (sdat-set-twikidir! self twikidir)) (sdat-set-page-dir-style! self page-dir) ;; (print "configdat: ")(pp configdat) ;;(session:log self "sroot: " sroot " logfile: " logfile " dbtype: " dbtype ;; " dbinit: " dbinit " domain: " domain " page-dir-style: " page-dir) ) @@ -379,16 +381,16 @@ ;; 2. values are always a string conversion is the responsibility of the ;; consuming function (at least for now, I'd like to change this) ;; set a session var for the current page ;; -(define (session:set! self key value) +(define (session:curr-page-set! self key value) (hash-table-set! (sdat-get-pagevars self) (s:any->string key) (s:any->string value))) ;; del a var for the current page ;; -(define (session:del! self key) +(define (session:page-var-del! self key) (hash-table-delete! (sdat-get-pagevars self) (s:any->string key))) ;; get the appropriate hash given a page "*sessionvars*, *globalvars* or page ;; (define (session:get-page-hash self page) @@ -404,11 +406,11 @@ (let ((ht (session:get-page-hash self page))) (hash-table-set! ht (s:any->string key) (s:any->string value)))) ;; get session vars for the current page ;; -(define (session:get self key) +(define (session:page-get self key) (hash-table-ref/default (sdat-get-pagevars self) key #f)) ;; get session vars for a specified page ;; (define (session:get self page key) @@ -706,11 +708,11 @@ ;; 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 (eq? (class-of formdat) ) + (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 ") #f)) (session:log self "ERROR: bad key " key))))) Index: setup.scm ================================================================== --- setup.scm +++ setup.scm @@ -7,10 +7,12 @@ ;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. (declare (unit setup)) (declare (uses session)) +(require-extension srfi-69) +(require-extension regex) ;; (define s:session (make-sdat)) (session:initialize s:session) @@ -58,20 +60,20 @@ (define (s:get-param key) (session:get-param s:session key)) ;; these are page local (define (s:get key) - (session:get s:session key)) + (session:page-get s:session key)) (define (s:set! key val) - (session:set! s:session key val)) + (session:curr-page-set! s:session key val)) (define (s:del! key) - (session:del! s:session key)) + (session:page-var-del! s:session key)) (define (s:get-n-del! key) - (let ((val (session:get s:session key))) + (let ((val (session:page-get s:session key))) (session:del! s:session key) val)) ;; these are session wide (define (s:session-var-get key) @@ -79,11 +81,11 @@ (define (s:session-var-set! key val) (session:set! s:session "*sessionvars*" key val)) (define (s:session-var-get-n-del! key) - (let ((val (session:get s:session key))) + (let ((val (session:page-get s:session key))) (session:del! s:session "*sessionvars*" key) val)) (define (s:session-var-del! key) (session:del! s:session "*sessionvars*" key)) Index: stml.scm ================================================================== --- stml.scm +++ stml.scm @@ -129,11 +129,11 @@ ;; function (let* ((action (let ((v (s:find-param 'action args))) (if v v "default"))) (id (let ((i (s:find-param 'id args))) (if i i #f))) - (page (let ((p (slot-ref s:session 'page))) + (page (let ((p (sdat-get-page s:session))) (if p p "home"))) ;; (link (session:link-to s:session page (if id ;; (list 'action action 'id id) ;; (list 'action action))))) (link (if (string=? (substring action 0 5) "http:") ;; if first part of string is http: Index: stmlrun.scm ================================================================== --- stmlrun.scm +++ stmlrun.scm @@ -13,11 +13,11 @@ ;; (declare (run-time-macros)) (require-library dbi) (include "requirements.scm") -(include "cookie.scm") +(declare (uses cookie)) (declare (uses html-filter)) (declare (uses misc-stml)) (declare (uses formdat)) (declare (uses stml)) (declare (uses session))