X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=project.lisp;h=346ccd31b302744946e6ba62d18290a75fbff7e5;hb=b2a8ce33193d1621e9232521e779adf6a7d872f3;hp=a0d40610b561d6468cbab955cccd534747701b3f;hpb=b02132b356f13c6e1d04fde727eb86ac1ee0b3ce;p=wol.git diff --git a/project.lisp b/project.lisp index a0d4061..346ccd3 100644 --- a/project.lisp +++ b/project.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: July 2003 ;;;; -;;;; $Id: project.lisp,v 1.4 2003/07/19 20:32:48 kevin Exp $ +;;;; $Id: project.lisp,v 1.7 2003/08/08 09:03:45 kevin Exp $ ;;;; ;;;; This file and Wol are Copyright (c) 2001-2003 by Kevin M. Rosenberg ;;;; ************************************************************************* @@ -18,7 +18,6 @@ (sessions t) (session-lifetime 18000) (reap-interval 300) server (connector :modlisp)) - (unless server (setq server (ecase connector @@ -112,8 +111,14 @@ (let ((req (make-instance 'http-request :host (header-value command :host) - :raw-uri (puri:intern-uri (header-value command :url)) - :uri (puri:intern-uri (command->uri command)) + :raw-uri (aif (ignore-errors + (puri:intern-uri (header-value command :url))) + it + (header-value command :url)) + :uri (aif (ignore-errors + (puri:intern-uri (command->uri command))) + it + (command->uri command)) :protocol (ensure-keyword (header-value command :server-protocol)) :protocol-string (header-value command :server-protocol) @@ -130,23 +135,33 @@ (defun command->uri (command) (format nil "http://~A:~D~A" (header-value command :host) - (awhen (header-value - command :server-ip-port) - (parse-integer it)) + (header-value command :server-ip-port) (header-value command :url))) (defun is-index-request (req ent) (string= (puri:uri-path (request-raw-uri req)) (project-prefix (entity-project ent)))) -(defun redirect-entity (page ent) - (redirect-to-location - (format nil "~A~A" (project-prefix (entity-project ent)) page))) +(defun redirect-entity (page req ent &optional plist) + (let ((proj (entity-project ent)) + (url (make-wol-url page ent plist))) + (ecase (project-connector proj) + (:aserve + (net.aserve:with-http-response + ((aserve-request req) + (entity-aserve-entity ent) + :response net.aserve:*response-moved-permanently*) + (net.aserve:with-http-body + ((aserve-request req) + (entity-aserve-entity ent) + :headers `((:location . ,url)))))) + (:modlisp + (redirect-to-location url))))) (defun dispatch-request (req ent) (let ((proj (entity-project ent))) (if (is-index-request req ent) - (redirect-entity (project-index proj) ent) + (redirect-entity (project-index proj) req ent) (progn (request-decompile-uri req ent) (compute-session req ent) @@ -194,7 +209,9 @@ (let ((next-page (funcall handler req ent))) (typecase next-page (string - (redirect-entity next-page ent)) + (redirect-entity next-page req ent)) + (cons + (redirect-entity (car next-page) req ent (cadr next-page))) (null t) (t @@ -211,20 +228,33 @@ (defun wol-version-string () (format nil "~{~D~^.~}" *wol-version*)) - + +(defun alist-key->keyword (alist) + (loop for a in alist + collect (cons (kmrcl:ensure-keyword (car a)) (cdr a)))) + (defun request-query (req &key (uri t) (post t)) - (append - (when (and uri (request-uri-query req)) - (aif (request-query-alist req) - it - (setf (request-query-alist req) - (query-to-alist (request-uri-query req))))) - (when (and post (request-posted-content req)) - (query-to-alist (request-posted-content req))))) + (aif (aserve-request req) + (alist-key->keyword + (net.aserve:request-query it :uri uri :post post)) + (let ((desired (cons uri post))) + (if (equal desired (request-desired-query req)) + ;; Same desired as cached + (request-query-alist req) + (progn + (setf (request-desired-query req) desired) + (setf (request-query-alist req) + (append + (when (and uri (request-uri-query req)) + (query-to-alist (request-uri-query req))) + (when (and post (request-posted-content req)) + (query-to-alist (request-posted-content req)))))))))) (defun request-query-value (key req &key (uri t) (post t)) - (cdr (assoc key (request-query req :uri uri :post post) - :test 'equal))) + (aif (aserve-request req) + (net.aserve:request-query-value (string key) it :uri uri :post post) + (cdr (assoc key (request-query req :uri uri :post post) + :test 'equal)))) (defun websession-variable (ws name) (when ws @@ -236,8 +266,30 @@ (defmacro with-wol-page ((req ent + &key (format :html) (precompute t) headers) + &body body) + `(ecase (project-connector (entity-project ,ent)) + (:aserve + (net.aserve:with-http-response + ((aserve-request ,req) + (entity-aserve-entity ,ent) + :content-type (ml::format-string ,format)) + (net.aserve:with-http-body + ((aserve-request ,req) + (entity-aserve-entity ,ent) + :headers ,headers) + (let ((*html-stream* net.html.generator:*html-stream*)) + ,@body)))) + (:modlisp + (%with-wol-page (,req ,ent :format ,format :precompute ,precompute + :headers ,headers) + ,@body)))) + + +(defmacro %with-wol-page ((req ent &key (format :html) (precompute t) headers) &body body) + (declare (ignore req ent)) (let ((fmt (gensym "FMT-")) (precomp (gensym "PRE-")) (result (gensym "RES-")) @@ -290,7 +342,7 @@ (:body (:h1 "Not Found") (:p "The request for " - (:b (:write-string (request-uri req))) + (:b (:write-string (render-uri (request-uri req) nil))) " was not found on this server.") (:hr) (:div (:i "WOL "