Index: formdat.scm ================================================================== --- formdat.scm +++ formdat.scm @@ -107,20 +107,23 @@ (remdat (read-string #f datstr))) (close-input-port datstr) (list result remdat))))) ;; inp is port to read data from, maxsize is max data allowed to read (total) -(define (formdat:dat->list inp maxsize) +(define (formdat:dat->list inp maxsize #!key (debug-port #f)) ;; read 1Meg chunks from the input port. If a block is not complete ;; tack on the next 1Meg chunk as needed. Set up so the header is always ;; at the beginning of the chunk ;;-----------------------------29932024411502323332136214973 ;;Content-Disposition: form-data; name="input-picture"; filename="breadfruit.jpg" ;;Content-Type: image/jpeg (let loop ((dat (read-string 1000000 inp)) (res '()) (siz 0)) + (if debug-port (format debug-port "dat: ~A\n" dat)) + (if debug-port (format debug-port "eof: ~A\n" (eof-object? (read inp)))) + (if (> siz maxsize) (begin (print "DATA TOO BIG") res) (let* ((datstr (open-input-string dat)) @@ -162,20 +165,23 @@ (string=? request-method "POST")) (formdat:load-all-port (current-input-port))))) ;; (s:process-cgi-input (caaar dat)) (define (formdat:load-all-port inp) - (let* ((formdat (make-formdat:formdat))) -;; (debugp (open-output-file (conc (slot-ref s:session 'sroot) "/delme-" (current-user-id) ".log")))) - ;; (write-string (read-string #f inp) #f debugp) + (let* ((formdat (make-formdat:formdat)) + (debugp #f)) + ;; (open-output-file (conc "/tmp/delme-" (current-user-id) ".log")))) + ;; (write-string (read-string #f inp) #f debugp) ;; destroys all data! (formdat:initialize formdat) - (let ((alldats (formdat:dat->list inp 10e6))) + (let ((alldats (formdat:dat->list inp 10e6 debug-port: debugp))) - ;; (format debugp "formdat : alldats: ~A\n" alldats) + (if debugp (format debugp "formdat : alldats: ~A\n" alldats)) + (let ((firstitem (car alldats)) (multipass #f)) - (if (not (null? firstitem)) + (if (and (not (null? firstitem)) + (not (null? (car firstitem)))) (if (string-match formdat:delim-patt-rex (caar firstitem)) (set! multipass #t))) (if multipass ;; handle multi-part form (for-each (lambda (datlst) @@ -201,13 +207,16 @@ ;; (if (and (string? name) ;; (string=? name "")) ;; this is the short form input I guess ;; (let* ((datstr (caar datlst)) ;; (munged (s:process-cgi-input datstr))) ;; (print "datstr: " datstr " munged: " munged) - (formdat:load formdat (s:process-cgi-input (caaar alldats)))) ;; munged)) + (if (and (not (null? alldats)) + (not (null? (car alldats))) + (not (null? (caar alldats)))) + (formdat:load formdat (s:process-cgi-input (caaar alldats))))) ;; munged)) ;; (format debugp "formdat : name: ~A content: ~A\n" name content) - ;; (close-output-port debugp) + (if debugp (close-output-port debugp)) formdat)))) #| (define inp (open-input-file "tests/example.post.in")) (define dat (read-string #f inp)) Index: html-filter.scm ================================================================== --- html-filter.scm +++ html-filter.scm @@ -179,10 +179,15 @@ ;; (print "head: " head " num: " num " ch: |" ch "| chstr: " chstr) (if (null? tail) newres (loop (car tail)(cdr tail) newres)))))))) +;; probably a bug: +;; +;; (s:process-cgi-input "=bar") +;; => ((bar "")) +;; (define (s:process-cgi-input instr) (map (lambda (xy) (list (string->symbol (s:decode-str (car xy))) (if (eq? (length xy) 1) "" Index: setup.scm ================================================================== --- setup.scm +++ setup.scm @@ -79,10 +79,12 @@ (session:del! s:session "*sessionvars*" key) val)) (define (s:session-var-del! key) (session:del! s:session "*sessionvars*" key)) + +(define s:session-var-delete! s:session-var-del!) ;; utility to get all vars as hash table (define (s:session-get-sessionvars) (sdat-get-sessionvars s:session))