Revision: 4212 Author: edi URL: http://bknr.net/trac/changeset/4212
Conditions
U trunk/thirdparty/chunga/CHANGELOG.txt U trunk/thirdparty/chunga/chunga.asd U trunk/thirdparty/chunga/doc/index.html U trunk/thirdparty/chunga/packages.lisp U trunk/thirdparty/chunga/read.lisp U trunk/thirdparty/chunga/streams.lisp
Modified: trunk/thirdparty/chunga/CHANGELOG.txt =================================================================== --- trunk/thirdparty/chunga/CHANGELOG.txt 2009-02-09 14:16:22 UTC (rev 4211) +++ trunk/thirdparty/chunga/CHANGELOG.txt 2009-02-09 14:50:22 UTC (rev 4212) @@ -1,6 +1,7 @@ Version 1.0.0 2009-02-10 Switched to binary streams underneath and got rid of FLEXI-STREAMS dependency +Added conditions Exported (an improved version of) AS-KEYWORD Added WITH-CHARACTER-STREAM-SEMANTICS
Modified: trunk/thirdparty/chunga/chunga.asd =================================================================== --- trunk/thirdparty/chunga/chunga.asd 2009-02-09 14:16:22 UTC (rev 4211) +++ trunk/thirdparty/chunga/chunga.asd 2009-02-09 14:50:22 UTC (rev 4212) @@ -35,6 +35,7 @@ (:file "specials") (:file "util") (:file "known-words") + (:file "conditions") (:file "read") (:file "streams") (:file "input")
Modified: trunk/thirdparty/chunga/doc/index.html =================================================================== --- trunk/thirdparty/chunga/doc/index.html 2009-02-09 14:16:22 UTC (rev 4211) +++ trunk/thirdparty/chunga/doc/index.html 2009-02-09 14:50:22 UTC (rev 4212) @@ -72,6 +72,11 @@ </ol> <li><a href="#conditions">Conditions</a> <ol> + <li><a href="#chunga-condition"><code>chunga-condition</code></a> + <li><a href="#chunga-error"><code>chunga-error</code></a> + <li><a href="#chunga-warning"><code>chunga-warning</code></a> + <li><a href="#syntax-error"><code>syntax-error</code></a> + <li><a href="#parameter-error"><code>parameter-error</code></a> <li><a href="#input-chunking-body-corrupted"><code>input-chunking-body-corrupted</code></a> <li><a href="#input-chunking-unexpected-end-of-file"><code>input-chunking-unexpected-end-of-file</code></a> </ol> @@ -342,9 +347,69 @@
<h4><a name="conditions" class=none>Conditions</a></h4>
-Here are two conditions which might be signaled if something bad -happens while reading from a chunked stream: +Here are conditions which might be signalled if something bad happens +with a chunked stream.
+<!-- Entry for CHUNGA-CONDITION --> + +<p><br>[Condition] +<br><a class=none name="chunga-condition"><b>chunga-condition</b></a> + +<blockquote><br> +All conditions signalled by Chunga are of this type. This is a subtype of <a href="http://www.lispworks.com/documentation/HyperSpec/Body/e_cnd.htm"><code>CONDITION</code></a>. +</blockquote> + +<!-- End of entry for CHUNGA-CONDITION --> + +<!-- Entry for CHUNGA-ERROR --> + +<p><br>[Error] +<br><a class=none name="chunga-error"><b>chunga-error</b></a> + +<blockquote><br> +All errors signalled by Chunga are of this type. This is a subtype of <a href="#chunga-condition"><code>CHUNGA-CONDITION</code></a> and of +<a href="http://www.lispworks.com/documentation/HyperSpec/Body/e_stm_er.htm"><code>STREAM-ERROR</code></a>, +so <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stm_er.htm"><code>STREAM-ERROR-STREAM</code></a> +can be used to access the offending stream. +</blockquote> + +<!-- End of entry for CHUNGA-ERROR --> + +<!-- Entry for CHUNGA-WARNING --> + +<p><br>[Warning] +<br><a class=none name="chunga-warning"><b>chunga-warning</b></a> + +<blockquote><br> +All warnings signalled by Chunga are of this type. This is a subtype of <a href="#chunga-condition"><code>CHUNGA-CONDITION</code></a> and of <a href="http://www.lispworks.com/documentation/HyperSpec/Body/e_warnin.htm"><code>WARNING</code></a>. +</blockquote> + +<!-- End of entry for CHUNGA-WARNING --> + +<!-- Entry for SYNTAX-ERROR --> + +<p><br>[Error] +<br><a class=none name="syntax-error"><b>syntax-error</b></a> + +<blockquote><br> An error of this type is signalled if Chunga +encounters wrong or unknown syntax when reading data. This is a +subtype of <a href="#chunga-error"><code>CHUNGA-ERROR</code></a>. +</blockquote> + +<!-- End of entry for SYNTAX-ERROR --> + +<!-- Entry for PARAMETER-ERROR --> + +<p><br>[Error] +<br><a class=none name="parameter-error"><b>parameter-error</b></a> + +<blockquote><br> An error of this type is signalled if a function was +called with inconsistent or illegal parameters. This is a subtype +of <a href="#chunga-error"><code>CHUNGA-ERROR</code></a>. +</blockquote> + +<!-- End of entry for PARAMETER-ERROR --> + <!-- Entry for INPUT-CHUNKING-BODY-CORRUPTED -->
<p><br>[Condition type]<br><a class=none name='input-chunking-body-corrupted'><b>input-chunking-body-corrupted</b></a> @@ -353,11 +418,7 @@ A condition of this type is signaled if an unexpected character (octet) is read while reading from a <a href="#stream">chunked stream</a> with input chunking enabled. This is a subtype of -<a -href="http://www.lispworks.com/documentation/HyperSpec/Body/e_stm_er.htm%22%3E<code>STREAM-ERROR</code></a>, -so <a -href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stm_er.htm%22%3E<code>STREAM-ERROR-STREAM</code></a> -can be used to access the offending stream. +<a href="#chunga-error"><code>CHUNGA-ERROR</code></a>.
</blockquote>
@@ -372,11 +433,7 @@ A condition of this type is signaled if we reach an unexpected EOF on a <a href="#stream">chunked stream</a> with input chunking enabled. This is a subtype of -<a -href="http://www.lispworks.com/documentation/HyperSpec/Body/e_stm_er.htm%22%3E<code>STREAM-ERROR</code></a>, -so <a -href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stm_er.htm%22%3E<code>STREAM-ERROR-STREAM</code></a> -can be used to access the offending stream. +<a href="#chunga-error"><code>CHUNGA-ERROR</code></a>.
</blockquote>
Modified: trunk/thirdparty/chunga/packages.lisp =================================================================== --- trunk/thirdparty/chunga/packages.lisp 2009-02-09 14:16:22 UTC (rev 4211) +++ trunk/thirdparty/chunga/packages.lisp 2009-02-09 14:50:22 UTC (rev 4212) @@ -39,6 +39,8 @@ :assert-char :as-keyword :as-capitalized-string + :chunga-error + :chunga-warning :chunked-input-stream :chunked-input-stream-extensions :chunked-input-stream-trailers @@ -58,6 +60,7 @@ :read-name-value-pairs :read-token :skip-whitespace + :syntax-error :trim-whitespace :with-character-stream-semantics))
Modified: trunk/thirdparty/chunga/read.lisp =================================================================== --- trunk/thirdparty/chunga/read.lisp 2009-02-09 14:16:22 UTC (rev 4211) +++ trunk/thirdparty/chunga/read.lisp 2009-02-09 14:50:22 UTC (rev 4212) @@ -29,17 +29,23 @@
(in-package :chunga)
-(defun signal-unexpected-chars (last-char expected-chars) +(defun signal-unexpected-chars (stream last-char expected-chars) "Signals an error that LAST-CHAR was read although one of -EXPECTED-CHARS was expected. (Note that EXPECTED-CHARS, -despites its name, can also be a single character instead of a -list). Uses *CURRENT-ERROR-MESSAGE* if it's not NIL, or calls -*CURRENT-ERROR-FUNCTION* otherwise." +EXPECTED-CHARS was expected. (Note that EXPECTED-CHARS, despites its +name, can also be a single character instead of a list). Calls +*CURRENT-ERROR-FUNCTION* if it's not NIL, or uses +*CURRENT-ERROR-MESSAGE* otherwise." (cond (*current-error-function* (funcall *current-error-function* last-char expected-chars)) - (*current-error-message* - (error "~@[~A~%~]~:[End of file~;Read character ~:*~S~], but expected ~:[a member of ~S~;~S~]." - *current-error-message* last-char (atom expected-chars) expected-chars)))) + (t + (error 'syntax-error + :stream stream + :format-control "~@[~A~%~]~:[End of file~;Read character ~:*~S~], ~ +but expected ~:[a member of ~S~;~S~]." + :format-arguments (list *current-error-message* + last-char + (atom expected-chars) + expected-chars)))))
(defun charp (char) "Returns true if the Lisp character CHAR is a CHAR according to RFC 2616." @@ -73,7 +79,7 @@ character EXPECTED-CHAR. Signals an error otherwise." (let ((char (read-char* stream))) (unless (and char (char= char expected-char)) - (signal-unexpected-chars char expected-char)) + (signal-unexpected-chars stream char expected-char)) char))
(defun assert-crlf (stream) @@ -170,7 +176,10 @@ Returns NIL if LINE consists solely of whitespace." (unless (zerop (length (trim-whitespace line))) (let ((colon-pos (or (position #: line :test #'char=) - (error "Couldn't find colon in header line ~S." line)))) + (error 'syntax-error + :stream stream + :format-control "Couldn't find colon in header line ~S." + :format-arguments (list line))))) (cons (as-keyword (subseq line 0 colon-pos)) (trim-whitespace (subseq line (1+ colon-pos))))))) (add-header (pair) @@ -231,7 +240,7 @@ (#\Return (assert-char stream #\Linefeed) (let ((char (read-char* stream))) (unless (whitespacep char) - (signal-unexpected-chars char '(#\Space #\Tab))))) + (signal-unexpected-chars stream char '(#\Space #\Tab))))) (otherwise (write-char char out))))))
(defun read-cookie-value (stream &key name separators)
Modified: trunk/thirdparty/chunga/streams.lisp =================================================================== --- trunk/thirdparty/chunga/streams.lisp 2009-02-09 14:16:22 UTC (rev 4211) +++ trunk/thirdparty/chunga/streams.lisp 2009-02-09 14:50:22 UTC (rev 4212) @@ -110,40 +110,16 @@ (close real-stream :abort abort)) (t nil))))
-(define-condition input-chunking-unexpected-end-of-file (stream-error) - () - (:documentation "A condition of this type is signaled if we -reach an unexpected EOF on a chunked stream with input chunking -enabled. This is a subtype of STREAM-ERROR, so -STREAM-ERROR-STREAM can be used to access the offending -stream.")) - -(define-condition input-chunking-body-corrupted (stream-error) - ((last-char :initarg :last-char - :documentation "The (unexpected) character which was read.") - (expected-chars :initarg :expected-chars - :documentation "The characters which were -expected. A list of characters or one single character.")) - (:report (lambda (condition stream) - (with-slots (last-char expected-chars) - condition - (format stream "Chunked stream ~S seems to be corrupted. -Read character ~S, but expected ~:[a member of ~S~;~S~]." - (stream-error-stream condition) - last-char (atom expected-chars) expected-chars)))) - (:documentation "A condition of this type is signaled if an -unexpected character (octet) is read while reading from a -chunked stream with input chunking enabled. This is a subtype of -STREAM-ERROR, so STREAM-ERROR-STREAM can be used to access the -offending stream.")) - (defun make-chunked-stream (stream) "Creates and returns a chunked stream (a stream of type CHUNKED-STREAM) which wraps STREAM. STREAM must be an open binary stream." (unless (and (streamp stream) (open-stream-p stream)) - (error "~S should have been an open stream." stream)) + (error 'parameter-error + :stream stream + :format-control "~S should have been an open stream." + :format-arguments (list stream))) (make-instance ;; actual type depends on STREAM (cond ((and (input-stream-p stream) (output-stream-p stream))