| 1 |
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CHUNGA; Base: 10 -*- |
|---|
| 2 |
;;; $Header: /usr/local/cvsrep/chunga/known-words.lisp,v 1.3 2008/05/29 22:21:09 edi Exp $ |
|---|
| 3 |
|
|---|
| 4 |
;;; Copyright (c) 2006-2008, Dr. Edmund Weitz. All rights reserved. |
|---|
| 5 |
|
|---|
| 6 |
;;; Redistribution and use in source and binary forms, with or without |
|---|
| 7 |
;;; modification, are permitted provided that the following conditions |
|---|
| 8 |
;;; are met: |
|---|
| 9 |
|
|---|
| 10 |
;;; * Redistributions of source code must retain the above copyright |
|---|
| 11 |
;;; notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
|
|---|
| 13 |
;;; * Redistributions in binary form must reproduce the above |
|---|
| 14 |
;;; copyright notice, this list of conditions and the following |
|---|
| 15 |
;;; disclaimer in the documentation and/or other materials |
|---|
| 16 |
;;; provided with the distribution. |
|---|
| 17 |
|
|---|
| 18 |
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED |
|---|
| 19 |
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 20 |
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 21 |
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|---|
| 22 |
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 23 |
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|---|
| 24 |
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 25 |
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 26 |
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 27 |
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 28 |
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 29 |
|
|---|
| 30 |
(in-package :chunga) |
|---|
| 31 |
|
|---|
| 32 |
(eval-when (:compile-toplevel :load-toplevel :execute) |
|---|
| 33 |
(define-constant +known-words+ |
|---|
| 34 |
'(;; headers including WebDAV and some de facto standard headers |
|---|
| 35 |
"Accept" |
|---|
| 36 |
"Accept-Charset" |
|---|
| 37 |
"Accept-Encoding" |
|---|
| 38 |
"Accept-Language" |
|---|
| 39 |
"Accept-Ranges" |
|---|
| 40 |
"Age" |
|---|
| 41 |
"Allow" |
|---|
| 42 |
"Authorization" |
|---|
| 43 |
"Cache-Control" |
|---|
| 44 |
"Connection" |
|---|
| 45 |
"Content-Encoding" |
|---|
| 46 |
"Content-Language" |
|---|
| 47 |
"Content-Length" |
|---|
| 48 |
"Content-Location" |
|---|
| 49 |
"Content-MD5" |
|---|
| 50 |
"Content-Range" |
|---|
| 51 |
"Content-Type" |
|---|
| 52 |
"DAV" |
|---|
| 53 |
"Date" |
|---|
| 54 |
"Depth" |
|---|
| 55 |
"Destination" |
|---|
| 56 |
"ETag" |
|---|
| 57 |
"Expect" |
|---|
| 58 |
"Expires" |
|---|
| 59 |
"From" |
|---|
| 60 |
"Host" |
|---|
| 61 |
"If" |
|---|
| 62 |
"If-Match" |
|---|
| 63 |
"If-Modified-Since" |
|---|
| 64 |
"If-None-Match" |
|---|
| 65 |
"If-Range" |
|---|
| 66 |
"If-Unmodified-Since" |
|---|
| 67 |
"Last-Modified" |
|---|
| 68 |
"Location" |
|---|
| 69 |
"Lock-Token" |
|---|
| 70 |
"Max-Forwards" |
|---|
| 71 |
"Overwrite" |
|---|
| 72 |
"Pragma" |
|---|
| 73 |
"Proxy-Authenticate" |
|---|
| 74 |
"Proxy-Authorization" |
|---|
| 75 |
"Range" |
|---|
| 76 |
"Referer" |
|---|
| 77 |
"Retry-After" |
|---|
| 78 |
"Server" |
|---|
| 79 |
"TE" |
|---|
| 80 |
"TimeOut" |
|---|
| 81 |
"Trailer" |
|---|
| 82 |
"Transfer-Encoding" |
|---|
| 83 |
"Upgrade" |
|---|
| 84 |
"User-Agent" |
|---|
| 85 |
"Vary" |
|---|
| 86 |
"Via" |
|---|
| 87 |
"WWW-Authenticate" |
|---|
| 88 |
"Warning" |
|---|
| 89 |
;; methods including WebDAV |
|---|
| 90 |
"CONNECT" |
|---|
| 91 |
"COPY" |
|---|
| 92 |
"DELETE" |
|---|
| 93 |
"GET" |
|---|
| 94 |
"HEAD" |
|---|
| 95 |
"LOCK" |
|---|
| 96 |
"MKCOL" |
|---|
| 97 |
"MOVE" |
|---|
| 98 |
"OPTIONS" |
|---|
| 99 |
"POST" |
|---|
| 100 |
"PROPFIND" |
|---|
| 101 |
"PROPPATCH" |
|---|
| 102 |
"PUT" |
|---|
| 103 |
"TRACE" |
|---|
| 104 |
"UNLOCK" |
|---|
| 105 |
;; protocols |
|---|
| 106 |
"HTTP/1.1" |
|---|
| 107 |
"HTTP/1.0" |
|---|
| 108 |
;; only a few and only the "preferred MIME names" - see |
|---|
| 109 |
;; <http://www.iana.org/assignments/character-sets> for a |
|---|
| 110 |
;; complete list |
|---|
| 111 |
"US-ASCII" |
|---|
| 112 |
"ISO-8859-1" |
|---|
| 113 |
"UTF-8" |
|---|
| 114 |
"UTF-16" |
|---|
| 115 |
"UTF-32BE" |
|---|
| 116 |
"UTF-32LE") |
|---|
| 117 |
"A list of words \(headers, methods, protocols, character sets) |
|---|
| 118 |
that are typically seen in HTTP communication. Mostly from RFC 2616, |
|---|
| 119 |
but includes WebDAV stuff and other things as well.")) |
|---|
| 120 |
|
|---|
| 121 |
(define-constant +string-to-keyword-hash+ |
|---|
| 122 |
(let ((hash (make-hash-table :test 'equal :size (length +known-words+)))) |
|---|
| 123 |
(loop for word in +known-words+ |
|---|
| 124 |
do (setf (gethash word hash) (make-keyword word nil))) |
|---|
| 125 |
hash) |
|---|
| 126 |
"A hash table which case-insensitively maps the strings from |
|---|
| 127 |
+KNOWN-WORDS+ to keywords.") |
|---|
| 128 |
|
|---|
| 129 |
(define-constant +keyword-to-string-hash+ |
|---|
| 130 |
(let ((hash (make-hash-table :test 'eq :size (length +known-words+)))) |
|---|
| 131 |
(loop for word in +known-words+ |
|---|
| 132 |
do (setf (gethash (make-keyword word nil) hash) |
|---|
| 133 |
(string-capitalize word))) |
|---|
| 134 |
hash) |
|---|
| 135 |
"A hash table which maps keywords derived from +KNOWN-WORDS+ to |
|---|
| 136 |
capitalized strings.") |
|---|
| 137 |
|
|---|
| 138 |
(defun as-keyword (string &key (destructivep t)) |
|---|
| 139 |
"Converts the string STRING to a keyword where all characters are |
|---|
| 140 |
uppercase or lowercase, taking into account the current readtable |
|---|
| 141 |
case. Might destructively modify STRING if DESTRUCTIVEP is true which |
|---|
| 142 |
is the default. \"Knows\" several HTTP header names and methods and |
|---|
| 143 |
is optimized to not call INTERN for these." |
|---|
| 144 |
(or (gethash string +string-to-keyword-hash+) |
|---|
| 145 |
(make-keyword string destructivep))) |
|---|
| 146 |
|
|---|
| 147 |
(defun as-capitalized-string (keyword) |
|---|
| 148 |
"Kind of the inverse of AS-KEYWORD. Has essentially the same effect |
|---|
| 149 |
as STRING-CAPITALIZE but is optimized for \"known\" keywords like |
|---|
| 150 |
:CONTENT-LENGTH or :GET." |
|---|
| 151 |
(or (gethash keyword +keyword-to-string-hash+) |
|---|
| 152 |
(string-capitalize keyword))) |
|---|