r5484: *** empty log message ***
[wol.git] / uri.lisp
index e3b631d49302409a67935df1ef8c2d85208199c4..1f2e22467d476acc74bef7a907befbeb8a4e6ced 100644 (file)
--- a/uri.lisp
+++ b/uri.lisp
@@ -1,4 +1,4 @@
-;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: wol  -*-
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: wol  -*-
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
@@ -7,28 +7,62 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: uri.lisp,v 1.5 2003/08/08 09:03:45 kevin Exp $
+;;;; $Id: uri.lisp,v 1.8 2003/08/10 05:16:52 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
 
 (in-package #:wol)
 
-
-(defun request-decompile-uri (req ent)
-  "returns (VALUE PAGE PLIST QUERY-ALIST)"
-  (multiple-value-bind (page plists query) 
-      (decode-url (puri:uri-path (request-raw-uri req)))
-    (when page
-      (setf (request-page req) (base-page-name page ent)))
-    (when plists
-      (setf (request-plist req) (car plists))
-      (setf (request-next-plists req) (cdr plists))
-      (when (null page)
-       (awhen (getf (request-plist req) :page)
-              (setf (request-page req) it))))
-    (setf (request-uri-query req) query))
-  req)
+(defun req-recode-uri-sans-session-id (req)
+  (let ((ppath (puri:uri-parsed-path (request-uri req))))
+    (when (is-raw-session-id (second ppath))
+      (let ((new-path (list* (car ppath) (cddr ppath))))
+       (setf (uri-parsed-path (request-uri req)) new-path)
+       (setf (uri-parsed-path (request-raw-uri req)) new-path))
+      (setf (request-decoded-uri-path req)
+       (uridecode-string (uri-path (request-raw-uri req))))
+      (raw-session-id->session-id (second ppath)))))
+
+(defun request-cookies (req)
+  (aif (aserve-request req)
+       (net.aserve:get-cookie-values it)
+       (loop for h in (request-headers req)
+          when (eq :cookie (car h))
+          collect (cdr h))))
+
+(defun header-lines-matching (key headers)
+  (loop for hdr in headers
+      when (eq key (car hdr))
+      collect (cdr hdr)))
+
+(defun set-cookies-in-headers (headers)
+  (header-lines-matching :set-cookie headers))
+
+(defun cookies-in-headers (headers)
+  (header-lines-matching :cookie headers))
+
+(defun cookie-session-key (ent cookies)
+  "Return the session key from the alist of cookies"
+  (let ((name (project-name (entity-project ent))))
+    (cdr (assoc name cookies :test #'string-equal))))
+
+(defun compute-uris (req ent)
+  "Compute URI's of a request"
+  (let ((url-session-id (req-recode-uri-sans-session-id req)))
+    (compute-session req ent url-session-id)
+    
+    (multiple-value-bind (page plists query) 
+       (decode-url (puri:uri-path (request-raw-uri req)))
+      (when page
+       (setf (request-page req) (base-page-name page ent)))
+      (when plists
+       (setf (request-plist req) (car plists))
+       (setf (request-next-plists req) (cdr plists))
+       (when (null page)
+         (awhen (getf (request-plist req) :page)
+                (setf (request-page req) it))))
+      (setf (request-uri-query req) query))))
 
 
 ;;; URI Functions
 
 
 
-#+ignore
-(defun make-html-url (page ent &optional query-args)
-  (make-url (concatenate 'string page ".html")
-           :base-dir (project-prefix 
-                      (entity-project ent))
-           :vars query-args :format :xhtml))
-
-
-(defun make-wol-url (page ent &optional plist)
-  (let ((url-plist (append (list :page page) plist))
+(defun make-wol-url (page req ent &optional plist)
+  (let ((session (websession-from-req req))
+       (url-plist (append (list :page page) plist))
        (prefix (project-prefix (entity-project ent))))
-    (if (null plist)
-       (concatenate 'string prefix page ".lsp")
-      (concatenate 'string
-       prefix
-       +asp-header+
-       (concatenate 'string +plist-header+ 
-                    (plist-to-url-string url-plist))))))
+    (concatenate 'string
+      prefix
+      (if (and session
+                (websession-key session)
+                (not (eq :cookies (websession-method session))))
+         (format nil "~~~A~~/" (websession-key session))
+       "")
+      (if (null plist)
+       (concatenate 'string page ".html")
+       (concatenate 'string
+         +asp-header+
+         (concatenate 'string +plist-header+ 
+                      (plist-to-url-string url-plist)))))))
 
 
 ;; Property lists
   (let ((str (plist-to-compressed-string plist)))
     (if base64
        (string-to-base64-string str :uri t)
-       (escape-uri-field str))))
+       (uriencode-string str))))
 
 (defun url-string-to-plist (str &key (base64 t))
   (let ((decode (if base64
                    (base64-string-to-string str :uri t)
-                   (unescape-uri-field str))))
+                   (uridecode-string str))))
     (when decode
       (ignore-errors (compressed-string-to-plist decode)))))