projects
/
cl-modlisp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
r7061: initial property settings
[cl-modlisp.git]
/
utils.lisp
diff --git
a/utils.lisp
b/utils.lisp
index 9964122fd2323b4bca740a717b98955b98103eb5..9caf7d0b72cc722bbe955981f119b8f7d33b1375 100644
(file)
--- a/
utils.lisp
+++ b/
utils.lisp
@@
-7,7
+7,7
@@
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Dec 2002
;;;;
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Dec 2002
;;;;
-;;;; $Id
: utils.lisp,v 1.4 2003/07/08 08:34:23 kevin Exp
$
+;;;; $Id$
;;;; *************************************************************************
(in-package #:modlisp)
;;;; *************************************************************************
(in-package #:modlisp)
@@
-19,60
+19,68
@@
(:text "text/plain")
(otherwise fmt)))
(:text "text/plain")
(otherwise fmt)))
-(defmacro with-ml-page ((&key (format :html) (precompute t)) &body body)
- (let ((fmt (gensym))
- (precomp (gensym))
- (result (gensym))
- (outstr (gensym))
- (stream (gensym)))
+(defmacro with-ml-page ((&key (format :html) (precompute t) headers)
+ &body body)
+ (let ((fmt (gensym "FMT-"))
+ (precomp (gensym "PRE-"))
+ (result (gensym "RES-"))
+ (outstr (gensym "STR-"))
+ (stream (gensym "STRM-"))
+ (hdr (gensym "HDR-")))
`(let ((,fmt ,format)
(,precomp ,precompute)
`(let ((,fmt ,format)
(,precomp ,precompute)
- ,result ,outstr)
+ ,result ,outstr ,stream)
+ (declare (ignorable ,stream))
(write-header-line "Status" "200 OK")
(write-header-line "Content-Type" (format-string ,fmt))
(write-header-line "Status" "200 OK")
(write-header-line "Content-Type" (format-string ,fmt))
+ (dolist (,hdr ,headers)
+ (write-header-line (car ,hdr) (cdr ,hdr)))
(unless ,precomp
(unless ,precomp
- (write-string "end" *
apache
-socket*)
- (write-char #\NewLine *
apache
-socket*))
+ (write-string "end" *
modlisp
-socket*)
+ (write-char #\NewLine *
modlisp
-socket*))
(setq ,outstr
(with-output-to-string (,stream)
(setq ,outstr
(with-output-to-string (,stream)
- (let ((*
apache
-socket* (if ,precomp
+ (let ((*
modlisp
-socket* (if ,precomp
,stream
,stream
- *
apache
-socket*)))
+ *
modlisp
-socket*)))
(setq ,result (progn ,@body)))))
(cond
(,precomp
(write-header-line "Content-Length"
(write-to-string (length ,outstr)))
(write-header-line "Keep-Socket" "1")
(setq ,result (progn ,@body)))))
(cond
(,precomp
(write-header-line "Content-Length"
(write-to-string (length ,outstr)))
(write-header-line "Keep-Socket" "1")
- (write-header-line "Keep-Alive" "timeout=15, max=99")
(write-header-line "Connection" "Keep-Alive")
(write-header-line "Connection" "Keep-Alive")
- (write-string "end" *
apache
-socket*)
- (write-char #\NewLine *
apache
-socket*)
- (write-string ,outstr *
apache
-socket*)
- (f
orce-output *apache
-socket*)
- (set
-close-apache-socket
nil))
+ (write-string "end" *
modlisp
-socket*)
+ (write-char #\NewLine *
modlisp
-socket*)
+ (write-string ,outstr *
modlisp
-socket*)
+ (f
inish-output *modlisp
-socket*)
+ (set
q *close-modlisp-socket*
nil))
(t
(t
- (
set-close-apache-socket t
)
- (
finish-output *apache-socket*
)))
+ (
finish-output *modlisp-socket*
)
+ (
setq *close-modlisp-socket* t
)))
,result)))
(defun redirect-to-location (url)
,result)))
(defun redirect-to-location (url)
- (write-header-line "Status" "30
2
Redirect")
+ (write-header-line "Status" "30
7 Temporary
Redirect")
(write-header-line "Location" url)
(write-header-line "Location" url)
- (write-char #\NewLine *apache-socket*)
- (set-close-apache-socket t))
+ ;;(write-header-line "Keep-Socket" "1")
+ ;;(write-header-line "Connection" "Keep-Alive")
+ (write-string "end" *modlisp-socket*)
+ (write-char #\NewLine *modlisp-socket*)
+ (force-output *modlisp-socket*)
+ (setq *close-modlisp-socket* t))
(defun output-ml-page (format html)
(write-header-line "Status" "200 OK")
(write-header-line "Content-Type" (format-string format))
(write-header-line "Content-Length" (format nil "~d" (length html)))
(write-header-line "Keep-Socket" "1")
(defun output-ml-page (format html)
(write-header-line "Status" "200 OK")
(write-header-line "Content-Type" (format-string format))
(write-header-line "Content-Length" (format nil "~d" (length html)))
(write-header-line "Keep-Socket" "1")
- (write-header-line "Keep-Alive" "timeout=15, max=99")
(write-header-line "Connection" "Keep-Alive")
(write-header-line "Connection" "Keep-Alive")
- (write-string "end" *apache-socket*)
- (write-char #\NewLine *apache-socket*)
- (write-string html *apache-socket*)
- (set-close-apache-socket nil))
+ (write-string "end" *modlisp-socket*)
+ (write-char #\NewLine *modlisp-socket*)
+ (write-string html *modlisp-socket*)
+ (force-output *modlisp-socket*)
+ (setq *close-modlisp-socket* nil))
(defun output-html-page (str)
(output-ml-page :html str))
(defun output-html-page (str)
(output-ml-page :html str))
@@
-80,20
+88,23
@@
(defun output-xml-page (str)
(output-ml-page :xml str))
(defun output-xml-page (str)
(output-ml-page :xml str))
-(defun posted-to-alist (posted-string)
- "Converts a posted string to an assoc list of variable names and values"
+;; Utility functions for library users
+
+(defun query-to-alist (posted-string &key (keyword t))
+ "Converts a posted string to an assoc list of keyword names and values,
+\"a=1&bc=demo\" => ((:a . \"1\") (:bc . \"demo\"))"
(when posted-string
(let ((alist '()))
(dolist (name=val (kmrcl:delimited-string-to-list posted-string #\&)
(nreverse alist))
(let ((name-val-list (kmrcl:delimited-string-to-list name=val #\=)))
(when posted-string
(let ((alist '()))
(dolist (name=val (kmrcl:delimited-string-to-list posted-string #\&)
(nreverse alist))
(let ((name-val-list (kmrcl:delimited-string-to-list name=val #\=)))
- (
when
(= 2 (length name-val-list))
+ (
if
(= 2 (length name-val-list))
(destructuring-bind (name val) name-val-list
(destructuring-bind (name val) name-val-list
- (push (cons (kmrcl:ensure-keyword name)
+ (push (cons (if keyword
+ (kmrcl:ensure-keyword name)
+ name)
(kmrcl:decode-uri-query-string val))
(kmrcl:decode-uri-query-string val))
- alist))))))))
-
-
-
+ alist))
+ (cmsg-c :debug "Invalid number of #\= in ~S" name-val-list)))))))