X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=web-utils.lisp;h=40cb04018bed71dfd1883a0c09880261a7eda2f3;hp=1614fe4fa33703501a03bdf859596db8b5474159;hb=19bee416d52c52d58261faf3d459c45572563149;hpb=4a5b626f01db51b02f969adb33ddad6aa9ee303a diff --git a/web-utils.lisp b/web-utils.lisp index 1614fe4..40cb040 100644 --- a/web-utils.lisp +++ b/web-utils.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: web-utils.lisp,v 1.10 2003/06/06 21:59:30 kevin Exp $ +;;;; $Id$ ;;;; ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -22,22 +22,22 @@ ;;; HTML/XML constants (defvar *standard-xml-header* - #.(format nil "~%~%~%")) + #.(format nil "~%")) (defvar *standard-html-header* "") (defvar *standard-xhtml-header* - #.(format nil "~%")) + #.(format nil "~%")) ;;; User agent functions (defun user-agent-ie-p (agent) "Takes a user-agent string and returns T for Internet Explorer." - (when (or (string-equal "Microsoft" (subseq agent 0 (length "Microsoft"))) - (string-equal "Internet Explore" (subseq agent 0 (length "Internet Explore"))) - (search "MSIE" agent)) - t)) + (or (string-starts-with "Microsoft" agent) + (string-starts-with "Internet Explore" agent) + (search "Safari" agent) + (search "MSIE" agent))) ;;; URL Functions @@ -83,3 +83,41 @@ amp (car var) "=" (cadr var)))) (rest vars)))) "")))) + +(defun decode-uri-query-string (s) + "Decode a URI query string field" + (declare (simple-string s) + (optimize (speed 3) (safety 0) (space 0))) + (do* ((old-len (length s)) + (new-len (- old-len (* 2 (the fixnum (count-string-char s #\%))))) + (new (make-string new-len)) + (p-old 0) + (p-new 0 (1+ p-new))) + ((= p-new new-len) new) + (declare (simple-string new) + (fixnum p-old p-new old-len new-len)) + (let ((c (schar s p-old))) + (when (char= c #\+) + (setq c #\space)) + (case c + (#\% + (unless (>= old-len (+ p-old 3)) + (error "#\% not followed by enough characters")) + (setf (schar new p-new) + (code-char + (parse-integer (subseq s (1+ p-old) (+ p-old 3)) + :radix 16))) + (incf p-old 3)) + (t + (setf (schar new p-new) c) + (incf p-old)))))) + +(defun split-uri-query-string (s) + (mapcar + (lambda (pair) + (let ((pos (position #\= pair))) + (when pos + (cons (subseq pair 0 pos) + (when (> (length pair) pos) + (decode-uri-query-string (subseq pair (1+ pos)))))))) + (delimited-string-to-list s #\&)))